blob: 58df21d076801099b2a3a63a1365817498e3b55a [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"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01009#include "spinlock.h"
10
11struct vcpu {
Wedson Almeida Filho87009642018-07-02 10:20:07 +010012 struct spinlock lock;
13 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010014 struct arch_regs regs;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010015 struct vm *vm;
16};
17
18/* TODO: Update alignment such that cpus are in different cache lines. */
19struct cpu {
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010020 struct vcpu *current;
21
Andrew Scull020ae692018-07-19 16:20:14 +010022 /* CPU identifier. Doesn't have to be contiguous. */
23 size_t id;
24
25 /* Pointer to bottom of the stack. */
26 void *stack_bottom;
27
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010028 /*
29 * Enabling/disabling irqs are counted per-cpu. They are enabled when
30 * the count is zero, and disabled when it's non-zero.
31 */
32 uint32_t irq_disable_count;
33
Andrew Scull020ae692018-07-19 16:20:14 +010034 struct spinlock lock;
35
Wedson Almeida Filho87009642018-07-02 10:20:07 +010036 /* Determines whether or not the cpu is currently on. */
37 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010038};
39
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010040void cpu_module_init(void);
41
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010042void cpu_init(struct cpu *c);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010043size_t cpu_index(struct cpu *c);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010044void cpu_irq_enable(struct cpu *c);
45void cpu_irq_disable(struct cpu *c);
Wedson Almeida Filho87009642018-07-02 10:20:07 +010046bool cpu_on(struct cpu *c);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010047void cpu_off(struct cpu *c);
48
Wedson Almeida Filho87009642018-07-02 10:20:07 +010049void vcpu_init(struct vcpu *vcpu, struct vm *vm);
Andrew Scull020ae692018-07-19 16:20:14 +010050void vcpu_on(struct vcpu *vcpu);
51void vcpu_off(struct vcpu *vcpu);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010052
Andrew Scull4f170f52018-07-19 12:58:20 +010053#endif /* _CPU_H */