blob: 43bd356e244b6be40cf696ac1ec2acfba25c5eda [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 {
20 struct spinlock lock;
21
22 struct vcpu *current;
23
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010024 /*
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 Filho87009642018-07-02 10:20:07 +010030 /* Determines whether or not the cpu is currently on. */
31 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010032
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
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);
50void vcpu_on(struct vcpu *v);
51void vcpu_off(struct vcpu *v);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010052
53#endif /* _CPU_H */