diff options
| author | fvdl <fvdl@NetBSD.org> | 2003-01-05 01:03:44 +0000 |
|---|---|---|
| committer | fvdl <fvdl@NetBSD.org> | 2003-01-05 01:03:44 +0000 |
| commit | eff9b6d311dce08bb2c180f49a19ba283cb01fa1 (patch) | |
| tree | ef954867a0cfd593c795b6504fddcefb85511dd4 /sys/dev | |
| parent | 1106d42424088f04e77445ccca8cb3f4e1b7751e (diff) | |
Add some code to deal with the MADT.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/acpi/acpi_madt.c | 253 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_madt.h | 155 | ||||
| -rw-r--r-- | sys/dev/acpi/files.acpi | 3 |
3 files changed, 410 insertions, 1 deletions
diff --git a/sys/dev/acpi/acpi_madt.c b/sys/dev/acpi/acpi_madt.c new file mode 100644 index 00000000000..327570789a4 --- /dev/null +++ b/sys/dev/acpi/acpi_madt.c @@ -0,0 +1,253 @@ +/* $NetBSD: acpi_madt.c,v 1.1 2003/01/05 01:03:44 fvdl Exp $ */ + +/* + * Copyright (c) 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/ioctl.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/errno.h> +#include <sys/malloc.h> + +#include <dev/acpi/acpica.h> +#include <dev/acpi/acpireg.h> +#include <dev/acpi/acpivar.h> +#include <dev/acpi/acpi_osd.h> +#include <dev/acpi/acpica/Subsystem/actables.h> +#include <dev/acpi/acpica/Subsystem/acnamesp.h> +#include <dev/acpi/acpi_madt.h> + +/* #define ACPI_MADT_DEBUG */ + +#ifdef ACPI_MADT_DEBUG +static void acpi_madt_print(void); +static ACPI_STATUS acpi_madt_print_entry(APIC_HEADER *); +static void acpi_print_apic_proc(PROCESSOR_APIC *); +static void acpi_print_ioapic(IO_APIC *); +static void acpi_print_intsrc_ovr(INT_SOURCE_OVERRIDE *); +static void acpi_print_intsrc_nmi(INT_IOAPIC_SOURCE_NMI *); +static void acpi_print_lapic_nmi(INT_LAPIC_SOURCE_NMI *); +static void acpi_print_lapic_addr_ovr(LAPIC_ADDR_OVR *); +static void acpi_print_iosapic(IO_SAPIC *); +static void acpi_print_local_sapic(LOCAL_SAPIC *); +static void acpi_print_platint(INT_PLATFORM *); +#endif + +ACPI_TABLE_HEADER *AcpiGbl_MADT; + +ACPI_STATUS +acpi_madt_map(void) +{ + ACPI_TABLE_HEADER *hdrp, header; + XSDT_DESCRIPTOR *xp; + ACPI_POINTER Address; + ACPI_STATUS Status = AE_OK; + int i, len; + + if (AcpiGbl_XSDT == NULL) + return AE_NO_ACPI_TABLES; + + xp = AcpiGbl_XSDT; + hdrp = &AcpiGbl_XSDT->Header; + + Address.PointerType = AcpiGbl_TableFlags | ACPI_LOGICAL_ADDRESSING; + + len = (hdrp->Length - sizeof (ACPI_TABLE_HEADER)) + / sizeof (xp->TableOffsetEntry[0]); + + for (i = 0; i < len; i++) { + Address.Pointer.Value = + ACPI_GET_ADDRESS(AcpiGbl_XSDT->TableOffsetEntry[i]); + Status = AcpiTbGetTableHeader(&Address, &header); + if (ACPI_FAILURE (Status)) + return Status; + if (!strncmp(header.Signature, APIC_SIG, 4)) { + Status = AcpiOsMapMemory(Address.Pointer.Value, + (ACPI_SIZE)header.Length, (void **)&AcpiGbl_MADT); + if (ACPI_FAILURE (Status)) + return Status; + } + } +#ifdef ACPI_MADT_DEBUG + acpi_madt_print(); +#endif + return AE_OK; +} + +void +acpi_madt_unmap(void) +{ + AcpiOsUnmapMemory(AcpiGbl_MADT, AcpiGbl_MADT->Length); +} + +#ifdef ACPI_MADT_DEBUG + +static void +acpi_print_apic_proc(PROCESSOR_APIC *p) +{ + printf("processor: id %u apid %u enabled: %s\n", + p->ProcessorApicId, p->LocalApicId, + p->ProcessorEnabled ? "yes" : "no"); +} + +static void +acpi_print_ioapic(IO_APIC *p) +{ + printf("ioapic: apid %u address %x vector base %x\n", + p->IoApicId, p->IoApicAddress, p->Vector); +} + +static void +acpi_print_intsrc_ovr(INT_SOURCE_OVERRIDE *p) +{ + printf("int override: bus %u irq %u int %u\n", + p->Bus, p->Source, p->GlobalInt); +} + +static void +acpi_print_intsrc_nmi(INT_IOAPIC_SOURCE_NMI *p) +{ + printf("ioapic NMI: int %u\n", p->GlobalInt); +} + +static void +acpi_print_lapic_nmi(INT_LAPIC_SOURCE_NMI *p) +{ + printf("lapic NMI: apid %u input %u\n", p->ApicId, p->Lint); +} + +static void +acpi_print_lapic_addr_ovr(LAPIC_ADDR_OVR *p) +{ + printf("lapic addr override: %llx\n", p->LocalApicAddress); +} + +static void +acpi_print_iosapic(IO_SAPIC *p) +{ + printf("iosapic: sapid %u address %llx vector base %x\n", + p->IoSapicId, p->IoSapicAddress, p->Vector); +} + +static void +acpi_print_local_sapic(LOCAL_SAPIC *p) +{ + printf("local sapic: cpu %u sapid %u sapeid %u enabled: %s\n", + p->ProcessorApicId, p->LocalSapicId, p->LocalSapicEid, + p->ProcessorEnabled ? "yes" : "no"); +} + +static void +acpi_print_platint(INT_PLATFORM *p) +{ + printf("platform int: type %u apid %u apeid %u\n", + p->Type, p->ProcessorId, p->ProcessorEid); +} + +#endif + +void +acpi_madt_walk(ACPI_STATUS (*func)(APIC_HEADER *)) +{ + char *madtend, *where; + APIC_HEADER *hdrp; + APIC_TABLE *ap; + + ap = (APIC_TABLE *)AcpiGbl_MADT; + madtend = (char *)AcpiGbl_MADT + AcpiGbl_MADT->Length; + where = (char *)AcpiGbl_MADT + sizeof (APIC_TABLE); + while (where < madtend) { + hdrp = (APIC_HEADER *)where; + if (func(hdrp) != AE_OK) + break; + where += hdrp->Length; + } +} + +#ifdef ACPI_MADT_DEBUG +void +acpi_madt_print(void) +{ + APIC_TABLE *ap; + + ap = (APIC_TABLE *)AcpiGbl_MADT; + printf("\n\nACPI MADT table:\n"); + printf("default local APIC address: %x\n", ap->LocalApicAddress); + printf("system dual 8259%s present\n", + ap->PCATCompat ? "" : " not"); + printf("entries:\n"); + + acpi_madt_walk(acpi_madt_print_entry); +} + +static ACPI_STATUS +acpi_madt_print_entry(APIC_HEADER *hdrp) +{ + switch (hdrp->Type) { + case APIC_PROC: + acpi_print_apic_proc((void *)hdrp); + break; + case APIC_IO: + acpi_print_ioapic((void *)hdrp); + break; + case APIC_INTSRC_OVR: + acpi_print_intsrc_ovr((void *)hdrp); + break; + case APIC_INTSRC_NMI: + acpi_print_intsrc_nmi((void *)hdrp); + break; + case APIC_LAPIC_NMI: + acpi_print_lapic_nmi((void *)hdrp); + break; + case APIC_ADDR_OVR: + acpi_print_lapic_addr_ovr((void *)hdrp); + break; + case APIC_IOSAPIC: + acpi_print_iosapic((void *)hdrp); + break; + case APIC_LOCAL_SAPIC: + acpi_print_local_sapic((void *)hdrp); + break; + case APIC_PLAT_INTSRC: + acpi_print_platint((void *)hdrp); + break; + default: + printf("Unknown MADT entry type %d\n", hdrp->Type); + break; + } + return AE_OK; +} +#endif diff --git a/sys/dev/acpi/acpi_madt.h b/sys/dev/acpi/acpi_madt.h new file mode 100644 index 00000000000..357e6d35967 --- /dev/null +++ b/sys/dev/acpi/acpi_madt.h @@ -0,0 +1,155 @@ +/* $NetBSD: acpi_madt.h,v 1.1 2003/01/05 01:03:44 fvdl Exp $ */ + +/* + * Copyright (c) 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * MADT entry types not defined in actbl.h + */ +#define APIC_INTSRC_OVR 2 +#define APIC_INTSRC_NMI 3 +#define APIC_LAPIC_NMI 4 +#define APIC_ADDR_OVR 5 +#define APIC_IOSAPIC 6 +#define APIC_LOCAL_SAPIC 7 +#define APIC_PLAT_INTSRC 8 + +#pragma pack(1) + +/* + * MADT entry structures not defined in actbl.h + */ + +/* + * Interrupt source override. + */ +typedef struct +{ + APIC_HEADER Header; + UINT8 Bus; /* 0 (ISA) */ + UINT8 Source; /* Legacy IRQ */ + UINT32 GlobalInt; /* Glocal IO APIC int */ + UINT32_BIT Polarity:2; /* See MPS_INTPO* in mpbiosreg.h */ + UINT32_BIT Trigger:2; /* See MPS_INTTR* in mpbiosreg.h */ + UINT32_BIT Reserved:12; /* Must be zero */ +} INT_SOURCE_OVERRIDE; + +/* + * I/O APIC NMI source structure. + */ +typedef struct +{ + APIC_HEADER Header; + UINT32_BIT Polarity:2; /* See above */ + UINT32_BIT Trigger:2; /* See above */ + UINT32_BIT Reserved:12; + UINT32 GlobalInt; +} INT_IOAPIC_SOURCE_NMI; + +/* + * Local APIC NMI mapping. + */ +typedef struct +{ + APIC_HEADER Header; + UINT8 ApicId; /* Local APIC Id */ + UINT32_BIT Polarity:2; /* See above */ + UINT32_BIT Trigger:2; /* See above */ + UINT32_BIT Reserved:12; + UINT8 Lint; /* Local APIC input */ +} INT_LAPIC_SOURCE_NMI; + +/* + * 64-bit local APIC address override. + */ +typedef struct +{ + APIC_HEADER Header; + UINT16 Reserved; /* Must be zero */ + UINT64 LocalApicAddress; /* Phys addr of local APIC */ +} LAPIC_ADDR_OVR; + +/* + * I/O SAPIC. + */ +typedef struct +{ + APIC_HEADER Header; + UINT8 IoSapicId; + UINT8 Reserved; + UINT32 Vector; /* Vectors start at this off */ + UINT64 IoSapicAddress; /* Phys addr of SAPIC */ +} IO_SAPIC; + +/* + * Local SAPIC. + */ +typedef struct +{ + APIC_HEADER Header; + UINT8 ProcessorApicId; + UINT8 LocalSapicId; + UINT8 LocalSapicEid; + UINT8 Reserved[3]; + UINT32_BIT ProcessorEnabled:1; + UINT32_BIT Reserved1:31; +} LOCAL_SAPIC; + +/* + * Platform interrupt source. + */ +typedef struct +{ + APIC_HEADER Header; + UINT32_BIT Polarity:2; /* See above */ + UINT32_BIT Trigger:2; /* See above */ + UINT32_BIT Reserved:12; + UINT8 Type; /* See below */ + UINT8 ProcessorId; + UINT8 ProcessorEid; + UINT8 IoSapicVector; + UINT32 GlobalInt; + UINT32 Reserved1; +} INT_PLATFORM; + +#define ACPI_PLATFORM_INT_PMI 1 +#define ACPI_PLATFORM_INT_INIT 2 +#define ACPI_PLATFORM_INT_CERR 3 + +extern ACPI_TABLE_HEADER *AcpiGbl_MADT; + +ACPI_STATUS acpi_madt_map(void); +void acpi_madt_unmap(void); +void acpi_madt_walk(ACPI_STATUS (*)(APIC_HEADER *)); diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index 3e23ba544f3..241abc5bb34 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $NetBSD: files.acpi,v 1.13 2003/01/04 05:36:03 jmcneill Exp $ +# $NetBSD: files.acpi,v 1.14 2003/01/05 01:03:45 fvdl Exp $ include "dev/acpi/acpica/files.acpica" @@ -8,6 +8,7 @@ device acpi { } attach acpi at acpibus file dev/acpi/acpi.c acpi needs-flag file dev/acpi/acpi_resource.c acpi +file dev/acpi/acpi_madt.c acpi # ACPI Embedded Controller device acpiec |
