stos/amd64: irqchip: Detect and disable i8259s

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-27 04:45:57 +00:00
parent 1bebf4d37b
commit 55e12ce62d
3 changed files with 73 additions and 0 deletions
+5
View File
@@ -8,9 +8,14 @@
#include <hal/board.h>
#include <machine/hpet.h>
#include <machine/irqchip.h>
VOID
HalBoardInit(VOID)
{
/* Initialize HPET */
MdHpetInit();
/* Initialize IRQ chips */
MdIrqChipInit();
}
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: IRQ chip management
* 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>
#include <ex/trace.h>
/* PIC data ports */
#define PIC_MASTER_DATA 0x21
#define PIC_SLAVE_DATA 0xA1
#define DTRACE(Fmt, ...) \
TRACE("[ IRQCHIP ]: " Fmt, ##__VA_ARGS__)
/* Set if dual i8259 is present */
#define MADT_PCAT_COMPAT BIT(0)
VOID
MdIrqChipInit(VOID)
{
ACPI_MADT *Madt;
Madt = AcpiQuery("APIC");
if (Madt == NULL) {
KeKnot(
KNOT_UNBOUND_RSRC,
"could not locate ACPI MADT\n"
);
}
/*
* If we have a dual-i8259 configuration present on the
* machine, we'll want to disable it so it doesn't mess
* up Local APIC operation and such.
*/
if (ISSET(Madt->Flags, MADT_PCAT_COMPAT)) {
DTRACE("detected dual i8259; disabling...\n");
MdOutb(PIC_MASTER_DATA, 0xFF);
MdOutb(PIC_SLAVE_DATA, 0xFF);
}
}