The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
apic.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* @file apic.h
5
* @brief the local APIC and the I/O APIC.
6
*
7
* the kernel starts with the 8259 PICs. apic_init changes to the APICs if
8
* the ACPI MADT describes them: the 8259s are masked, the I/O APIC sends
9
* the ISA IRQs to the same vectors as before (PIC_REMAP_OFFSET + irq), and
10
* the local APIC timer gives the scheduler tick on the vector of IRQ 0.
11
* without a MADT the kernel stays on the 8259s.
12
*/
13
14
#include "
common/stdint.h
"
15
16
/** the vector of the local APIC timer on the cores other than the boot core (as in Linux) */
17
#define LOCAL_TIMER_VECTOR 0xEC
18
19
/** the vector of the IPI that asks a core to flush its TLB (Linux's CALL_FUNCTION_VECTOR) */
20
#define TLB_FLUSH_VECTOR 0xFC
21
22
/** the vector of the IPI that wakes a core to run a process or act on a signal (as in Linux) */
23
#define RESCHEDULE_VECTOR 0xFD
24
25
/**
26
* change from the 8259 PICs to the APICs. call with interrupts off, after
27
* acpi_init (it needs the MADT) and mmio_init.
28
* @param timer_hz the tick rate for the local APIC timer.
29
* @return true if the APICs are in use.
30
*/
31
bool
apic_init
(
uint32_t
timer_hz);
32
33
/**
34
* true after a successful apic_init.
35
*/
36
bool
apic_active
(
void
);
37
38
/**
39
* end of interrupt to the local APIC.
40
*/
41
void
apic_eoi
(
void
);
42
43
/**
44
* mask or unmask the I/O APIC entry of an ISA IRQ (0 to 15).
45
*/
46
void
apic_set_irq_masked
(
uint32_t
irq,
bool
masked);
47
48
/**
49
* the id of the local APIC of the boot core, for the destination of MSI
50
* messages and the I/O APIC entries.
51
*/
52
uint8_t
apic_id
(
void
);
53
54
/**
55
* make the I/O APIC entry of an ISA IRQ level-triggered (a PCI interrupt
56
* line routed to it). the polarity stays as the MADT gives it.
57
*/
58
void
apic_set_irq_level
(
uint32_t
irq);
59
60
/**
61
* send the I/O APIC entry of an ISA IRQ to a local APIC (physical
62
* destination mode).
63
* @param irq the ISA IRQ (0 to 15).
64
* @param lapic_id the id of the local APIC of the core.
65
* @return false if the IRQ has no I/O APIC entry.
66
*/
67
bool
apic_set_irq_dest
(
uint32_t
irq,
uint8_t
lapic_id);
68
69
/**
70
* set up the local APIC of a core other than the boot core: turn it on,
71
* mask LINT0, LINT1 and the error interrupt, and start its timer on
72
* LOCAL_TIMER_VECTOR at the rate the boot core measured (if the boot core
73
* uses its timer). call it on that core, after apic_init on the boot core.
74
* @return true if the timer of the core runs.
75
*/
76
bool
apic_init_ap
(
void
);
77
78
/**
79
* send INIT to a core: it stops and waits for a startup IPI.
80
* @param target the local APIC id of the core.
81
* @return false if the local APIC could not send the IPI.
82
*/
83
bool
apic_send_init
(
uint8_t
target);
84
85
/**
86
* send a startup IPI (SIPI) to a core that waits after INIT. the core
87
* starts in real mode at page_address (CS = page_address / 16, IP = 0).
88
* @param target the local APIC id of the core.
89
* @param page_address a page-aligned physical address below 1 MiB.
90
* @return false if the local APIC could not send the IPI.
91
*/
92
bool
apic_send_startup
(
uint8_t
target,
uint32_t
page_address);
93
94
/**
95
* send an interrupt to another core (an IPI) on a vector, with fixed
96
* delivery. interrupts are off on this core while the IPI goes out.
97
* @param target the local APIC id of the core.
98
* @param vector the vector the core receives.
99
*/
100
void
apic_send_ipi
(
uint8_t
target,
uint8_t
vector);
101
102
/**
103
* send a non-maskable interrupt (NMI, vector 2) to another core. it comes
104
* also when interrupts are off on that core.
105
* @param target the local APIC id of the core.
106
*/
107
void
apic_send_nmi
(
uint8_t
target);
apic_send_startup
bool apic_send_startup(uint8_t target, uint32_t page_address)
send a startup IPI (SIPI) to a core that waits after INIT.
Definition
apic.c:538
apic_set_irq_dest
bool apic_set_irq_dest(uint32_t irq, uint8_t lapic_id)
send the I/O APIC entry of an ISA IRQ to a local APIC (physical destination mode).
Definition
apic.c:469
apic_send_ipi
void apic_send_ipi(uint8_t target, uint8_t vector)
send an interrupt to another core (an IPI) on a vector, with fixed delivery.
Definition
apic.c:543
apic_set_irq_level
void apic_set_irq_level(uint32_t irq)
make the I/O APIC entry of an ISA IRQ level-triggered (a PCI interrupt line routed to it).
Definition
apic.c:455
apic_eoi
void apic_eoi(void)
end of interrupt to the local APIC.
Definition
apic.c:423
apic_init
bool apic_init(uint32_t timer_hz)
change from the 8259 PICs to the APICs.
Definition
apic.c:350
apic_init_ap
bool apic_init_ap(void)
set up the local APIC of a core other than the boot core: turn it on, mask LINT0, LINT1 and the error...
Definition
apic.c:486
apic_send_init
bool apic_send_init(uint8_t target)
send INIT to a core: it stops and waits for a startup IPI.
Definition
apic.c:529
apic_send_nmi
void apic_send_nmi(uint8_t target)
send a non-maskable interrupt (NMI, vector 2) to another core.
Definition
apic.c:552
apic_active
bool apic_active(void)
true after a successful apic_init.
Definition
apic.c:418
apic_set_irq_masked
void apic_set_irq_masked(uint32_t irq, bool masked)
mask or unmask the I/O APIC entry of an ISA IRQ (0 to 15).
Definition
apic.c:428
apic_id
uint8_t apic_id(void)
the id of the local APIC of the boot core, for the destination of MSI messages and the I/O APIC entri...
Definition
apic.c:450
stdint.h
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
src
arch
x86
cpu
apic.h
Generated by
1.18.0