Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 1 | #ifndef _CPU_H |
| 2 | #define _CPU_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | #include "arch_cpu.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 9 | #include "spinlock.h" |
| 10 | |
| 11 | struct vcpu { |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame^] | 12 | struct spinlock lock; |
| 13 | bool is_on; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 14 | struct arch_regs regs; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 15 | struct vm *vm; |
| 16 | }; |
| 17 | |
| 18 | /* TODO: Update alignment such that cpus are in different cache lines. */ |
| 19 | struct cpu { |
| 20 | struct spinlock lock; |
| 21 | |
| 22 | struct vcpu *current; |
| 23 | |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 24 | /* |
| 25 | * Enabling/disabling irqs are counted per-cpu. They are enabled when |
| 26 | * the count is zero, and disabled when it's non-zero. |
| 27 | */ |
| 28 | uint32_t irq_disable_count; |
| 29 | |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame^] | 30 | /* Determines whether or not the cpu is currently on. */ |
| 31 | bool is_on; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 32 | |
| 33 | /* CPU identifier. Doesn't have to be contiguous. */ |
| 34 | size_t id; |
| 35 | |
| 36 | /* Pointer to bottom of the stack. */ |
| 37 | void *stack_bottom; |
| 38 | }; |
| 39 | |
| 40 | void cpu_init(struct cpu *c); |
| 41 | void cpu_irq_enable(struct cpu *c); |
| 42 | void cpu_irq_disable(struct cpu *c); |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame^] | 43 | bool cpu_on(struct cpu *c); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 44 | void cpu_off(struct cpu *c); |
| 45 | |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame^] | 46 | void vcpu_init(struct vcpu *vcpu, struct vm *vm); |
| 47 | void vcpu_on(struct vcpu *v); |
| 48 | void vcpu_off(struct vcpu *v); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 49 | |
| 50 | #endif /* _CPU_H */ |