PatchworkOS
Loading...
Searching...
No Matches
apic.h
Go to the documentation of this file.
1#pragma once
2
5#include <kernel/defs.h>
6
7#include <stdint.h>
8
9typedef struct cpu cpu_t;
10
25
33
38typedef enum
39{
42 APIC_TIMER_ONE_SHOT = 0x00000
44
57
62typedef enum
63{
65 LAPIC_MSR_BSP = 0x100
67
101
105#define LAPIC_REG_ICR1_ID_OFFSET 24
106
111typedef enum
112{
114 LAPIC_LVT_MASKED = (1 << 16)
116
121typedef enum
122{
123 LAPIC_ICR_FIXED = (0 << 8),
125 LAPIC_ICR_SMI = (2 << 8),
126 LAPIC_ICR_NMI = (4 << 8),
127 LAPIC_ICR_INIT = (5 << 8),
128 LAPIC_ICR_STARTUP = (6 << 8)
130
135typedef enum
136{
139
149
154typedef enum
155{
156 IOAPIC_REG_VERSION = 0x01
158
169#define IOAPIC_REG_REDIRECTION(pin, high) (0x10 + (pin) * 2 + (high))
170
176#define APIC_TIMER_TICKS_FIXED_POINT_OFFSET 32
177
184typedef struct PACKED
185{
186 union {
188 struct PACKED
189 {
194 };
195 };
197
211
221
231
241
268
278void apic_timer_one_shot(interrupt_t vector, uint32_t ticks);
279
290
294void lapic_cpu_init(void);
295
302
309void lapic_write(lapic_register_t reg, uint32_t value);
310
318
328
338void lapic_send_sipi(lapic_id_t id, void* entryPoint);
339
348void lapic_send_ipi(lapic_id_t id, interrupt_t vector);
349
355void lapic_eoi(void);
356
365
373void ioapic_write(ioapic_t* ioapic, ioapic_register_t reg, uint32_t value);
374
382
390
410 ioapic_polarity_t polarity, ioapic_trigger_mode_t triggerMode, cpu_t* cpu, bool enable);
411
interrupt_t
CPU vector identifiers.
Definition interrupt.h:97
#define PACKED
GCC packed attribute.
Definition defs.h:32
lapic_flags_t
Local APIC Flags.
Definition apic.h:112
ioapic_delivery_mode_t
IO APIC Delivery Modes.
Definition apic.h:203
ioapic_register_t
IO APIC Registers.
Definition apic.h:155
apic_timer_mode_t
APIC Timer Modes.
Definition apic.h:39
lapic_msr_flags_t
Local APIC MSR Flags.
Definition apic.h:63
void ioapic_write(ioapic_t *ioapic, ioapic_register_t reg, uint32_t value)
Write to an IOAPIC register.
Definition apic.c:258
uint64_t apic_timer_ticks_per_ns(void)
Apic timer ticks per nanosecond.
Definition apic.c:119
ioapic_polarity_t
IO APIC Polarity Modes.
Definition apic.h:237
void lapic_cpu_init(void)
Initialize the local apic for the current cpu.
Definition apic.c:147
void lapic_eoi(void)
Send an End Of Interrupt (EOI) signal to the local apic.
Definition apic.c:236
void ioapic_set_redirect(interrupt_t vector, ioapic_gsi_t gsi, ioapic_delivery_mode_t deliveryMode, ioapic_polarity_t polarity, ioapic_trigger_mode_t triggerMode, cpu_t *cpu, bool enable)
Set an IOAPIC redirection entry.
Definition apic.c:307
void apic_timer_one_shot(interrupt_t vector, uint32_t ticks)
Configure the apic timer in one-shot mode.
Definition apic.c:105
apic_timer_divider_t
APIC Timer Divider Values.
Definition apic.h:50
void lapic_send_init(lapic_id_t id)
Send an INIT IPI to a local apic.
Definition apic.c:201
uint32_t ioapic_gsi_t
IO APIC Global System Interrupt type.
Definition apic.h:32
ioapic_mmio_register_t
IO APIC Memory Mapped Registers.
Definition apic.h:145
void lapic_send_sipi(lapic_id_t id, void *entryPoint)
Send a Startup IPI to a local apic.
Definition apic.c:212
ioapic_version_t ioapic_get_version(ioapic_t *ioapic)
Get the IOAPIC version.
Definition apic.c:270
lapic_icr_flags_t
Local APIC ICR Flags.
Definition apic.h:136
lapic_id_t lapic_self_id(void)
Get the lapic id of the current cpu.
Definition apic.c:171
uint32_t ioapic_read(ioapic_t *ioapic, ioapic_register_t reg)
Read from an IOAPIC register.
Definition apic.c:246
ioapic_trigger_mode_t
IO APIC Trigger Modes.
Definition apic.h:227
ioapic_destination_mode_t
IO APIC Destination Modes.
Definition apic.h:217
uint8_t lapic_id_t
Local APIC ID type.
Definition apic.h:24
void lapic_send_ipi(lapic_id_t id, interrupt_t vector)
Send an Inter-Processor Interrupt (IPI) to a local apic.
Definition apic.c:225
ioapic_t * ioapic_from_gsi(ioapic_gsi_t gsi)
Get the IOAPIC id responsible for a given GSI.
Definition apic.c:282
lapic_register_t
Local APIC Registers.
Definition apic.h:73
uint32_t lapic_read(lapic_register_t reg)
Read from a local apic register.
Definition apic.c:191
lapic_icr_delivery_mode_t
Local APIC ICR Delivery Modes.
Definition apic.h:122
void lapic_write(lapic_register_t reg, uint32_t value)
Write to a local apic register.
Definition apic.c:181
@ LAPIC_LVT_MASKED
Definition apic.h:114
@ LAPIC_SPURIOUS_ENABLE
Definition apic.h:113
@ IOAPIC_DELIVERY_EXTERNAL
Definition apic.h:209
@ IOAPIC_DELIVERY_LOW_PRIO
Definition apic.h:205
@ IOAPIC_DELIVERY_NMI
Definition apic.h:207
@ IOAPIC_DELIVERY_SMI
Definition apic.h:206
@ IOAPIC_DELIVERY_INIT
Definition apic.h:208
@ IOAPIC_DELIVERY_NORMAL
Definition apic.h:204
@ IOAPIC_REG_VERSION
Definition apic.h:156
@ APIC_TIMER_ONE_SHOT
Definition apic.h:42
@ APIC_TIMER_PERIODIC
Definition apic.h:41
@ APIC_TIMER_MASKED
Timer is masked (disabled)
Definition apic.h:40
@ LAPIC_MSR_BSP
Definition apic.h:65
@ LAPIC_MSR_ENABLE
Definition apic.h:64
@ IOAPIC_POLARITY_LOW
Definition apic.h:239
@ IOAPIC_POLARITY_HIGH
Definition apic.h:238
@ APIC_TIMER_DIV_64
Definition apic.h:53
@ APIC_TIMER_DIV_128
Definition apic.h:54
@ APIC_TIMER_DIV_16
Definition apic.h:51
@ APIC_TIMER_DIV_DEFAULT
Definition apic.h:55
@ APIC_TIMER_DIV_32
Definition apic.h:52
@ IOAPIC_MMIO_REG_DATA
Definition apic.h:147
@ IOAPIC_MMIO_REG_SELECT
Definition apic.h:146
@ LAPIC_ICR_CLEAR_INIT_LEVEL
Definition apic.h:137
@ IOAPIC_TRIGGER_LEVEL
Definition apic.h:229
@ IOAPIC_TRIGGER_EDGE
Definition apic.h:228
@ IOAPIC_DESTINATION_PHYSICAL
Definition apic.h:218
@ IOAPIC_DESTINATION_LOGICAL
Definition apic.h:219
@ LAPIC_REG_TASK_PRIORITY
Definition apic.h:76
@ LAPIC_REG_TIMER_CURRENT_COUNT
Definition apic.h:98
@ LAPIC_REG_TIMER_INITIAL_COUNT
Definition apic.h:97
@ LAPIC_REG_LVT_CMCI
Definition apic.h:88
@ LAPIC_REG_REMOTE_READ
Definition apic.h:80
@ LAPIC_REG_LOGICAL_DEST
Definition apic.h:81
@ LAPIC_REG_LVT_PERFCTR
Definition apic.h:93
@ LAPIC_REG_ERROR_STATUS
Definition apic.h:87
@ LAPIC_REG_TIMER_DIVIDER
Definition apic.h:99
@ LAPIC_REG_LVT_THERMAL
Definition apic.h:92
@ LAPIC_REG_LVT_LINT0
Definition apic.h:94
@ LAPIC_REG_IRR_BASE
Definition apic.h:86
@ LAPIC_REG_VERSION
Definition apic.h:75
@ LAPIC_REG_PROCESSOR_PRIORITY
Definition apic.h:78
@ LAPIC_REG_ID
Definition apic.h:74
@ LAPIC_REG_LVT_ERROR
Definition apic.h:96
@ LAPIC_REG_ISR_BASE
Definition apic.h:84
@ LAPIC_REG_ICR1
Definition apic.h:90
@ LAPIC_REG_TMR_BASE
Definition apic.h:85
@ LAPIC_REG_EOI
Definition apic.h:79
@ LAPIC_REG_DEST_FORMAT
Definition apic.h:82
@ LAPIC_REG_ARBITRATION_PRIORITY
Definition apic.h:77
@ LAPIC_REG_LVT_LINT1
Definition apic.h:95
@ LAPIC_REG_SPURIOUS
Definition apic.h:83
@ LAPIC_REG_ICR0
Definition apic.h:89
@ LAPIC_REG_LVT_TIMER
Definition apic.h:91
@ LAPIC_ICR_SMI
Definition apic.h:125
@ LAPIC_ICR_STARTUP
Definition apic.h:128
@ LAPIC_ICR_LOWEST_PRIORITY
Definition apic.h:124
@ LAPIC_ICR_FIXED
Definition apic.h:123
@ LAPIC_ICR_NMI
Definition apic.h:126
@ LAPIC_ICR_INIT
Definition apic.h:127
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
CPU structure.
Definition cpu.h:42
Definition apic.h:250
uint8_t mask
Definition apic.h:258
uint8_t triggerMode
Definition apic.h:257
uint8_t deliveryMode
Definition apic.h:252
uint8_t destinationMode
Definition apic.h:253
uint32_t high
Definition apic.h:265
uint32_t low
Definition apic.h:264
uint8_t vector
Definition apic.h:251
uint8_t destination
Definition apic.h:260
uint64_t reserved
Definition apic.h:259
uint8_t remoteIRR
Definition apic.h:256
uint8_t deliveryStatus
Definition apic.h:254
uint8_t polarity
Definition apic.h:255
IO APIC.
Definition tables.h:167
IO APIC Version Structure.
Definition apic.h:185
uint8_t version
Definition apic.h:190
uint32_t raw
Definition apic.h:187
uint8_t reserved2
Definition apic.h:193
uint8_t reserved
Definition apic.h:191
uint8_t maxRedirs
Definition apic.h:192
IO APIC Redirection Entry Structure.
Definition apic.h:248