From 6fa3db464e3bbe60232169195713902113900806 Mon Sep 17 00:00:00 2001 From: sigsegv7 Date: Thu, 14 Sep 2023 03:37:37 -0400 Subject: kernel: acpi: Add IRQ to GSI function Signed-off-by: sigsegv7 --- sys/firmware/acpi/acpi_madt.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'sys/firmware') diff --git a/sys/firmware/acpi/acpi_madt.c b/sys/firmware/acpi/acpi_madt.c index fde5dde..bf3007b 100644 --- a/sys/firmware/acpi/acpi_madt.c +++ b/sys/firmware/acpi/acpi_madt.c @@ -84,6 +84,40 @@ do_parse(void) } } +/* + * Converts IRQ numbers to its corresponding + * Global System Interrupt (GSI) number. + * + * @irq: IRQ number. + */ +uint32_t +irq_to_gsi(uint8_t irq) +{ + struct apic_header *hdr = NULL; + struct interrupt_override *override = NULL; + uint8_t *cur = NULL; + uint8_t *end = NULL; + + cur = (uint8_t *)(madt + 1); + end = (uint8_t *)madt + madt->hdr.length; + + while (cur < end) { + hdr = (void *)cur; + + switch (hdr->type) { + case APIC_TYPE_INTERRUPT_OVERRIDE: + override = (struct interrupt_override *)cur; + if (override->source == irq) { + return override->interrupt; + } + } + + cur += hdr->length; + } + + return irq; +} + void acpi_parse_madt(void) { -- cgit v1.2.3