blob: 6eb90abe78e5cf0e8d033e685de116a96b6da682 [file] [log] [blame]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01001#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"
9#include "list.h"
10#include "spinlock.h"
11
12struct vcpu {
13 struct list_entry links;
14 bool is_runnable;
15 bool interrupt;
16 struct arch_regs regs;
17 struct cpu *cpu;
18 struct vm *vm;
19};
20
21/* TODO: Update alignment such that cpus are in different cache lines. */
22struct cpu {
23 struct spinlock lock;
24
25 struct vcpu *current;
26
27 struct list_entry ready_queue;
28
29 /*
30 * Enabling/disabling irqs are counted per-cpu. They are enabled when
31 * the count is zero, and disabled when it's non-zero.
32 */
33 uint32_t irq_disable_count;
34
35 /*
36 * The number of VMs that have turned this CPU on. CPUs are off when
37 * this count is zero, and on when this count is ono-zero.
38 */
39 uint32_t cpu_on_count;
40
41 bool (*timer_cb)(void *context);
42 void *timer_context;
43
44 /* CPU identifier. Doesn't have to be contiguous. */
45 size_t id;
46
47 /* Pointer to bottom of the stack. */
48 void *stack_bottom;
49};
50
51void cpu_init(struct cpu *c);
52void cpu_irq_enable(struct cpu *c);
53void cpu_irq_disable(struct cpu *c);
54void cpu_on(struct cpu *c);
55void cpu_off(struct cpu *c);
56
57void vcpu_init(struct vcpu *vcpu, struct cpu *cpu, struct vm *vm);
58void vcpu_ready(struct vcpu *v);
59void vcpu_unready(struct vcpu *v);
60
61#endif /* _CPU_H */