stos/amd64: irqchip: Save LAPIC descriptors
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <drivers/acpi/tables.h>
|
||||
#include <drivers/acpi/acpi.h>
|
||||
#include <machine/irqchip.h>
|
||||
#include <machine/pio.h>
|
||||
#include <ke/knot.h>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,23 @@
|
||||
#ifndef _MACHINE_IRQCHIP_H_
|
||||
#define _MACHINE_IRQCHIP_H_ 1
|
||||
|
||||
#include <drivers/acpi/tables.h>
|
||||
#include <drivers/acpi/acpi.h>
|
||||
#include <stdef.h>
|
||||
|
||||
/* 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_ */
|
||||
|
||||
Reference in New Issue
Block a user