PatchworkOS
Loading...
Searching...
No Matches
smp.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/cpu/cpu_id.h>
5#include <kernel/cpu/regs.h>
6#include <kernel/defs.h>
7
8#include <stdint.h>
9
10typedef struct cpu cpu_t;
11
26extern cpu_t* _cpus[CPU_MAX];
27
31extern uint16_t _cpuAmount;
32
41
47void smp_bootstrap_init(void);
48
54void smp_others_init(void);
55
59void smp_halt_others(void);
60
66static inline uint16_t smp_cpu_amount(void)
67{
68 return _cpuAmount;
69}
70
77static inline cpu_t* smp_cpu(cpuid_t id)
78{
79 return _cpus[id];
80}
81
90static inline cpu_t* smp_self_unsafe(void)
91{
92 return _cpus[msr_read(MSR_CPU_ID)];
93}
94
102static inline cpuid_t smp_self_id_unsafe(void)
103{
104 return (cpuid_t)msr_read(MSR_CPU_ID);
105}
106
115static inline cpu_t* smp_self(void)
116{
118
119 return _cpus[msr_read(MSR_CPU_ID)];
120}
121
125static inline void smp_put(void)
126{
128}
129
static char id[MAX_NAME]
Definition dwm.c:20
void interrupt_disable(void)
Disable interrupts and increment the disableDepth.
Definition interrupt.c:26
void interrupt_enable(void)
Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously en...
Definition interrupt.c:38
static cpu_t * smp_cpu(cpuid_t id)
Returns a pointer to the cpu_t structure of the CPU with the given id.
Definition smp.h:77
void smp_bootstrap_init(void)
Initializes the bootstrap CPU structure.
Definition smp.c:31
static cpu_t * smp_self_unsafe(void)
Returns a pointer to the cpu_t structure of the current CPU.
Definition smp.h:90
void smp_bootstrap_init_early(void)
Early initialization of the bootstrap CPU.
Definition smp.c:26
cpu_t * _cpus[CPU_MAX]
Array of pointers to cpu_t structures for each CPU.
Definition smp.c:21
void smp_others_init(void)
Initializes the other CPUs.
Definition smp.c:40
static cpu_t * smp_self(void)
Returns a pointer to the cpu_t structure of the current CPU.
Definition smp.h:115
static uint16_t smp_cpu_amount(void)
Returns the number of CPUs currently identified.
Definition smp.h:66
static cpuid_t smp_self_id_unsafe(void)
Returns the id of the current CPU.
Definition smp.h:102
static void smp_put(void)
Re-enables interrupts after a call to smp_self().
Definition smp.h:125
uint16_t _cpuAmount
The number of CPUs currently identified.
Definition smp.c:22
void smp_halt_others(void)
Halts all CPUs except the current one.
Definition smp.c:102
#define CPU_MAX
Maximum number of CPUs supported.
Definition cpu_id.h:14
uint16_t cpuid_t
Type used to identify a CPU.
Definition cpu_id.h:29
#define MSR_CPU_ID
Definition regs.h:13
static uint64_t msr_read(uint32_t msr)
Definition regs.h:63
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
CPU structure.
Definition cpu.h:42