From fb6283f788226daa183c9e168a415a3ef750d1e3 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Sat, 17 Oct 2020 21:07:32 +0200 Subject: [PATCH] acpi: add detection and dumping of MADT entry types Detect presence and dump content of MADT table entries for: - IOAPIC Structure - Interrupt Source Override Structure - NMI Source Structure - Local APIC NMI Structure - Local APIC Override Structure - IOSAPIC Structure Signed-off-by: Pawel Wieczorkiewicz --- common/acpi.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++--- include/acpi.h | 64 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 133 insertions(+), 5 deletions(-) diff --git a/common/acpi.c b/common/acpi.c index ea69b841..9ac61862 100644 --- a/common/acpi.c +++ b/common/acpi.c @@ -202,6 +202,24 @@ static inline void acpi_dump_tables(void) { acpi_dump_table(acpi_tables[i], &acpi_tables[i]->header); } +static const char *madt_int_bus_names[] = { + [ACPI_MADT_INT_BUS_ISA] = "ISA", +}; + +static const char *madt_int_polarity_names[] = { + [ACPI_MADT_INT_POLARITY_BS] = "Bus Spec", + [ACPI_MADT_INT_POLARITY_AH] = "Active High", + [ACPI_MADT_INT_POLARITY_RSVD] = "Reserved", + [ACPI_MADT_INT_POLARITY_AL] = "Active Low", +}; + +static const char *madt_int_trigger_names[] = { + [ACPI_MADT_INT_TRIGGER_BS] = "Bus Spec", + [ACPI_MADT_INT_TRIGGER_ET] = "Edge", + [ACPI_MADT_INT_TRIGGER_RSVD] = "Reserved", + [ACPI_MADT_INT_TRIGGER_LT] = "Level", +}; + static int process_madt_entries(void) { acpi_madt_t *madt = (acpi_madt_t *) acpi_find_table(MADT_SIGNATURE); acpi_madt_entry_t *entry; @@ -235,11 +253,59 @@ static int process_madt_entries(void) { madt_cpu->apic_proc_id, madt_cpu->apic_id, madt_cpu->flags); break; } - case ACPI_MADT_TYPE_IOAPIC: - case ACPI_MADT_TYPE_IRQ_SRC: - case ACPI_MADT_TYPE_NMI: - case ACPI_MADT_TYPE_LAPIC_ADDR: + case ACPI_MADT_TYPE_IOAPIC: { + acpi_madt_ioapic_t *madt_ioapic = (acpi_madt_ioapic_t *) entry->data; + + printk("ACPI: [MADT] IOAPIC ID: %u, Base Address: 0x%08x, GSI Base: 0x%08x\n", + madt_ioapic->ioapic_id, madt_ioapic->base_address, + madt_ioapic->gsi_base); + break; + } + case ACPI_MADT_TYPE_IRQ_SRC: { + acpi_madt_irq_src_t *madt_irq_src = (acpi_madt_irq_src_t *) entry->data; + + printk("ACPI: [MADT] IRQ Src Override: Bus: %3s, IRQ: 0x%02x, GSI: 0x%08x, " + "Polarity: %11s, Trigger: %9s\n", + madt_int_bus_names[madt_irq_src->bus], madt_irq_src->irq_src, + madt_irq_src->gsi, madt_int_polarity_names[madt_irq_src->polarity], + madt_int_trigger_names[madt_irq_src->trigger_mode]); + break; + } + case ACPI_MADT_TYPE_NMI_SRC: { + acpi_madt_nmi_src_t *madt_nmi_src = (acpi_madt_nmi_src_t *) entry->data; + + printk("ACPI: [MADT] NMI Src: GSI: 0x%08x, Polarity: %11s, Trigger: %9s\n", + madt_nmi_src->gsi, madt_int_polarity_names[madt_nmi_src->polarity], + madt_int_trigger_names[madt_nmi_src->trigger_mode]); + break; + } + case ACPI_MADT_TYPE_LAPIC_NMI: { + acpi_madt_lapic_nmi_t *madt_lapic_nmi = (acpi_madt_lapic_nmi_t *) entry->data; + + printk("ACPI: [MADT] Local APIC NMI LINT#: CPU UID: %02x, Polarity: %11s, " + "Trigger: %9s, LINT#: 0x%02x\n", + madt_lapic_nmi->cpu_uid, + madt_int_polarity_names[madt_lapic_nmi->polarity], + madt_int_trigger_names[madt_lapic_nmi->trigger_mode], + madt_lapic_nmi->lapic_lint); + break; + } + case ACPI_MADT_TYPE_LAPIC_ADDR: { + acpi_madt_lapic_addr_t *madt_lapic_addr = + (acpi_madt_lapic_addr_t *) entry->data; + + printk("ACPI: [MADT] Local APIC Address: 0x%016lx\n", + madt_lapic_addr->lapic_addr); + break; + } + case ACPI_MADT_TYPE_IOSAPIC: { + acpi_madt_iosapic_t *madt_iosapic = (acpi_madt_iosapic_t *) entry->data; + + printk("ACPI: [MADT] IOSAPIC ID: %u, Base Address: %p, GSI Base: 0x%08x\n", + madt_iosapic->ioapic_id, _ptr(madt_iosapic->base_address), + madt_iosapic->gsi_base); break; + } default: panic("Unknown ACPI MADT entry type: %u\n", entry->type); } diff --git a/include/acpi.h b/include/acpi.h index 320e52e1..f3acd1f6 100644 --- a/include/acpi.h +++ b/include/acpi.h @@ -164,8 +164,10 @@ enum acpi_madt_type { ACPI_MADT_TYPE_LAPIC = 0, ACPI_MADT_TYPE_IOAPIC = 1, ACPI_MADT_TYPE_IRQ_SRC = 2, - ACPI_MADT_TYPE_NMI = 4, + ACPI_MADT_TYPE_NMI_SRC = 3, + ACPI_MADT_TYPE_LAPIC_NMI = 4, ACPI_MADT_TYPE_LAPIC_ADDR = 5, + ACPI_MADT_TYPE_IOSAPIC = 6, }; typedef enum acpi_madt_type acpi_madt_type_t; @@ -176,6 +178,66 @@ struct acpi_madt_processor { } __packed; typedef struct acpi_madt_processor acpi_madt_processor_t; +struct acpi_madt_ioapic { + uint8_t ioapic_id; + uint8_t rsvd; + uint32_t base_address; + uint32_t gsi_base; +} __packed; +typedef struct acpi_madt_ioapic acpi_madt_ioapic_t; + +struct acpi_madt_iosapic { + uint8_t ioapic_id; + uint8_t rsvd; + uint32_t gsi_base; + uint64_t base_address; +} __packed; +typedef struct acpi_madt_iosapic acpi_madt_iosapic_t; + +#define ACPI_MADT_INT_BUS_ISA 0x00 + +#define ACPI_MADT_IRQ_TYPE_INT 0 +#define ACPI_MADT_IRQ_TYPE_NMI 1 + +#define ACPI_MADT_IRQ_DST_UNKNOWN 0xFF + +#define ACPI_MADT_INT_POLARITY_BS 0x00 +#define ACPI_MADT_INT_POLARITY_AH 0x01 +#define ACPI_MADT_INT_POLARITY_RSVD 0x02 +#define ACPI_MADT_INT_POLARITY_AL 0x03 + +#define ACPI_MADT_INT_TRIGGER_BS 0x00 +#define ACPI_MADT_INT_TRIGGER_ET 0x01 +#define ACPI_MADT_INT_TRIGGER_RSVD 0x02 +#define ACPI_MADT_INT_TRIGGER_LT 0x03 + +struct acpi_madt_irq_src { + uint8_t bus; /* Constant 0x0, ISA */ + uint8_t irq_src; + uint32_t gsi; + uint16_t polarity : 2, trigger_mode : 2, rsvd : 12; +} __packed; +typedef struct acpi_madt_irq_src acpi_madt_irq_src_t; + +struct acpi_madt_nmi_src { + uint16_t polarity : 2, trigger_mode : 2, rsvd : 12; + uint32_t gsi; +} __packed; +typedef struct acpi_madt_nmi_src acpi_madt_nmi_src_t; + +struct acpi_madt_lapic_nmi { + uint8_t cpu_uid; + uint16_t polarity : 2, trigger_mode : 2, rsvd : 12; + uint8_t lapic_lint; +} __packed; +typedef struct acpi_madt_lapic_nmi acpi_madt_lapic_nmi_t; + +struct acpi_madt_lapic_addr { + uint16_t rsvd; + uint64_t lapic_addr; +} __packed; +typedef struct acpi_madt_lapic_addr acpi_madt_lapic_addr_t; + struct acpi_madt { acpi_table_hdr_t header; uint32_t lapic_addr;