|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "apic.h"#include "arch/arch.h"#include "idt.h"#include "io.h"#include "isr.h"#include "pic.h"#include "irq.h"#include "kernel/acpi/acpi.h"#include "kernel/memory/tlb.h"#include "kernel/process/process.h"#include "kernel/scheduler/scheduler.h"#include "kernel/klog/klog.h"#include "kernel/memory/mmio.h"#include "kernel/sync/spinlock.h"Macros | |
| #define | LAPIC_ID 0x020 |
| the local APIC and the I/O APIC (Intel SDM volume 3, chapter 11; the 82093AA I/O APIC datasheet). | |
| #define | LAPIC_TPR 0x080 |
| #define | LAPIC_EOI 0x0B0 |
| #define | LAPIC_SVR 0x0F0 |
| #define | LAPIC_ICR_LOW 0x300 |
| #define | LAPIC_ICR_HIGH 0x310 |
| #define | LAPIC_LVT_TIMER 0x320 |
| #define | LAPIC_LVT_LINT0 0x350 |
| #define | LAPIC_LVT_LINT1 0x360 |
| #define | LAPIC_LVT_ERROR 0x370 |
| #define | LAPIC_TIMER_INIT 0x380 |
| #define | LAPIC_TIMER_COUNT 0x390 |
| #define | LAPIC_TIMER_DIV 0x3E0 |
| #define | LAPIC_SVR_ENABLE 0x100u |
| #define | LVT_MASKED 0x10000u |
| #define | LVT_TIMER_PERIODIC 0x20000u |
| #define | LVT_DELIVERY_EXTINT 0x700u |
| #define | LVT_DELIVERY_NMI 0x400u |
| #define | TIMER_DIVIDE_16 0x3u |
| #define | ICR_INIT 0x500u |
| #define | ICR_STARTUP 0x600u |
| #define | ICR_NMI 0x400u |
| #define | ICR_PENDING 0x1000u |
| #define | ICR_ASSERT 0x4000u |
| #define | ICR_LEVEL 0x8000u |
| #define | ICR_SEND_SPINS 1000000u |
| #define | SPURIOUS_VECTOR 0xFF |
| #define | MSR_APIC_BASE 0x1Bu |
| #define | APIC_BASE_ENABLE (1u << 11) |
| #define | APIC_DEFAULT_ADDRESS 0xFEE00000u |
| #define | IOAPIC_REGSEL 0x00 |
| #define | IOAPIC_WIN 0x10 |
| #define | IOAPIC_VERSION 0x01 |
| #define | IOAPIC_REDTBL 0x10 |
| #define | REDIR_ACTIVE_LOW 0x2000u |
| #define | REDIR_LEVEL 0x8000u |
| #define | REDIR_MASKED 0x10000u |
| #define | PIT_CLOCK_HZ 1193182u |
| #define | CALIBRATE_MS 10u |
Functions | |
| bool | apic_init (uint32_t timer_hz) |
| change from the 8259 PICs to the APICs. | |
| bool | apic_active (void) |
| true after a successful apic_init. | |
| void | apic_eoi (void) |
| end of interrupt to the local APIC. | |
| 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). | |
| 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 entries. | |
| 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). | |
| 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). | |
| 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 interrupt, and start its timer on LOCAL_TIMER_VECTOR at the rate the boot core measured (if the boot core uses its timer). | |
| bool | apic_send_init (uint8_t target) |
| send INIT to a core: it stops and waits for a startup IPI. | |
| bool | apic_send_startup (uint8_t target, uint32_t page_address) |
| send a startup IPI (SIPI) to a core that waits after INIT. | |
| void | apic_send_ipi (uint8_t target, uint8_t vector) |
| send an interrupt to another core (an IPI) on a vector, with fixed delivery. | |
| void | apic_send_nmi (uint8_t target) |
| send a non-maskable interrupt (NMI, vector 2) to another core. | |
| #define LAPIC_ID 0x020 |
the local APIC and the I/O APIC (Intel SDM volume 3, chapter 11; the 82093AA I/O APIC datasheet).
the local APIC registers are 32 bits wide, 16 bytes apart, at the address from the MADT. the I/O APIC has two registers: IOREGSEL selects a register, IOWIN reads or writes it. its redirection table has one 64-bit entry per global system interrupt (GSI).
the boot core routes the I/O APIC interrupts to itself; irq_spread() moves them to the other cores after they start. each other core sets up its own local APIC when it starts (apic_init_ap), with a timer on LOCAL_TIMER_VECTOR at the rate the boot core measured.
| #define LAPIC_TPR 0x080 |
| #define LAPIC_EOI 0x0B0 |
| #define LAPIC_SVR 0x0F0 |
| #define LAPIC_ICR_LOW 0x300 |
| #define LAPIC_ICR_HIGH 0x310 |
| #define LAPIC_LVT_TIMER 0x320 |
| #define LAPIC_LVT_LINT0 0x350 |
| #define LAPIC_LVT_LINT1 0x360 |
| #define LAPIC_LVT_ERROR 0x370 |
| #define LAPIC_TIMER_INIT 0x380 |
| #define LAPIC_TIMER_COUNT 0x390 |
| #define LAPIC_TIMER_DIV 0x3E0 |
| #define LAPIC_SVR_ENABLE 0x100u |
| #define LVT_MASKED 0x10000u |
| #define LVT_TIMER_PERIODIC 0x20000u |
| #define LVT_DELIVERY_EXTINT 0x700u |
| #define LVT_DELIVERY_NMI 0x400u |
| #define TIMER_DIVIDE_16 0x3u |
| #define ICR_INIT 0x500u |
| #define ICR_STARTUP 0x600u |
| #define ICR_NMI 0x400u |
| #define ICR_PENDING 0x1000u |
| #define ICR_ASSERT 0x4000u |
| #define ICR_LEVEL 0x8000u |
| #define ICR_SEND_SPINS 1000000u |
| #define SPURIOUS_VECTOR 0xFF |
| #define MSR_APIC_BASE 0x1Bu |
| #define APIC_BASE_ENABLE (1u << 11) |
| #define APIC_DEFAULT_ADDRESS 0xFEE00000u |
| #define IOAPIC_REGSEL 0x00 |
| #define IOAPIC_WIN 0x10 |
| #define IOAPIC_VERSION 0x01 |
| #define IOAPIC_REDTBL 0x10 |
| #define REDIR_ACTIVE_LOW 0x2000u |
| #define REDIR_LEVEL 0x8000u |
| #define REDIR_MASKED 0x10000u |
| #define PIT_CLOCK_HZ 1193182u |
| #define CALIBRATE_MS 10u |
change from the 8259 PICs to the APICs.
call with interrupts off, after acpi_init (it needs the MADT) and mmio_init.
| timer_hz | the tick rate for the local APIC timer. |
| bool apic_active | ( | void | ) |
true after a successful apic_init.
| void apic_eoi | ( | void | ) |
end of interrupt to the local APIC.
mask or unmask the I/O APIC entry of an ISA IRQ (0 to 15).
| 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 entries.
| 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).
the polarity stays as the MADT gives it.
send the I/O APIC entry of an ISA IRQ to a local APIC (physical destination mode).
| irq | the ISA IRQ (0 to 15). |
| lapic_id | the id of the local APIC of the core. |
| 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 interrupt, and start its timer on LOCAL_TIMER_VECTOR at the rate the boot core measured (if the boot core uses its timer).
call it on that core, after apic_init on the boot core.
send INIT to a core: it stops and waits for a startup IPI.
| target | the local APIC id of the core. |
send a startup IPI (SIPI) to a core that waits after INIT.
the core starts in real mode at page_address (CS = page_address / 16, IP = 0).
| target | the local APIC id of the core. |
| page_address | a page-aligned physical address below 1 MiB. |
send an interrupt to another core (an IPI) on a vector, with fixed delivery.
interrupts are off on this core while the IPI goes out.
| target | the local APIC id of the core. |
| vector | the vector the core receives. |
| void apic_send_nmi | ( | uint8_t | target | ) |
send a non-maskable interrupt (NMI, vector 2) to another core.
it comes also when interrupts are off on that core.
| target | the local APIC id of the core. |