diff --git a/paw/stos/arch/amd64/platform/irqchip.c b/paw/stos/arch/amd64/platform/irqchip.c index 034a80b..a6b900a 100644 --- a/paw/stos/arch/amd64/platform/irqchip.c +++ b/paw/stos/arch/amd64/platform/irqchip.c @@ -6,8 +6,6 @@ * Author: Chloe M. */ -#include -#include #include #include #include @@ -23,10 +21,50 @@ /* Set if dual i8259 is present */ #define MADT_PCAT_COMPAT BIT(0) +/* Local APIC list */ +static ACPI_LOCAL_APIC *LapicList[LAPIC_MAX]; +static USIZE LapicCount = 0; + +/* + * Append a Local APIC descriptor + * + * @Lapic: LAPIC to append + */ +static VOID +AppendLapic(ACPI_LOCAL_APIC *Lapic) +{ + if (Lapic == NULL) { + return; + } + + if (LapicCount >= LAPIC_MAX) { + return; + } + + if (LapicCount < 4) { + DTRACE("lapic%d at cpu%d\n", Lapic->ApicId, Lapic->ProcessorId); + } + + LapicList[LapicCount++] = Lapic; +} + +ACPI_LOCAL_APIC * +MdLapicByIndex(USIZE Index) +{ + if (Index >= LapicCount) { + return NULL; + } + + return LapicList[Index]; +} + VOID MdIrqChipInit(VOID) { ACPI_MADT *Madt; + ACPI_APIC_HEADER *ApicHdr; + ACPI_LOCAL_APIC *Lapic; + UCHAR *MadtCur, *MadtEnd; Madt = AcpiQuery("APIC"); if (Madt == NULL) { @@ -46,4 +84,20 @@ MdIrqChipInit(VOID) MdOutb(PIC_MASTER_DATA, 0xFF); MdOutb(PIC_SLAVE_DATA, 0xFF); } + + MadtCur = (UCHAR *)(Madt + 1); + MadtEnd = (UCHAR *)Madt + Madt->Header.Length; + + while (MadtCur < MadtEnd) { + ApicHdr = (ACPI_APIC_HEADER *)MadtCur; + + switch (ApicHdr->Type) { + case APIC_TYPE_LOCAL_APIC: + Lapic = (ACPI_LOCAL_APIC *)ApicHdr; + AppendLapic(Lapic); + break; + } + + MadtCur += ApicHdr->Length; + } } diff --git a/paw/stos/head/arch/amd64/irqchip.h b/paw/stos/head/arch/amd64/irqchip.h index 594b29f..afceb57 100644 --- a/paw/stos/head/arch/amd64/irqchip.h +++ b/paw/stos/head/arch/amd64/irqchip.h @@ -9,11 +9,23 @@ #ifndef _MACHINE_IRQCHIP_H_ #define _MACHINE_IRQCHIP_H_ 1 +#include +#include #include +/* Max IRQ chips values */ +#define LAPIC_MAX 64 + /* * Enumerate and save all platform IRQ chips */ VOID MdIrqChipInit(VOID); +/* + * Obtain a Local APIC descriptor by index + * + * @Index: Index of LAPIC descriptor to obtain + */ +ACPI_LOCAL_APIC *MdLapicByIndex(USIZE Index); + #endif /* !_MACHINE_IRQCHIP_H_ */