1e1e9a4bfSMitsuru IWASAKI /*- 2e1e9a4bfSMitsuru IWASAKI * Copyright (c) 1998 Doug Rabson 3e1e9a4bfSMitsuru IWASAKI * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 4e1e9a4bfSMitsuru IWASAKI * All rights reserved. 5e1e9a4bfSMitsuru IWASAKI * 6e1e9a4bfSMitsuru IWASAKI * Redistribution and use in source and binary forms, with or without 7e1e9a4bfSMitsuru IWASAKI * modification, are permitted provided that the following conditions 8e1e9a4bfSMitsuru IWASAKI * are met: 9e1e9a4bfSMitsuru IWASAKI * 1. Redistributions of source code must retain the above copyright 10e1e9a4bfSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer. 11e1e9a4bfSMitsuru IWASAKI * 2. Redistributions in binary form must reproduce the above copyright 12e1e9a4bfSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer in the 13e1e9a4bfSMitsuru IWASAKI * documentation and/or other materials provided with the distribution. 14e1e9a4bfSMitsuru IWASAKI * 15e1e9a4bfSMitsuru IWASAKI * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16e1e9a4bfSMitsuru IWASAKI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17e1e9a4bfSMitsuru IWASAKI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18e1e9a4bfSMitsuru IWASAKI * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19e1e9a4bfSMitsuru IWASAKI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20e1e9a4bfSMitsuru IWASAKI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21e1e9a4bfSMitsuru IWASAKI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22e1e9a4bfSMitsuru IWASAKI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23e1e9a4bfSMitsuru IWASAKI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24e1e9a4bfSMitsuru IWASAKI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25e1e9a4bfSMitsuru IWASAKI * SUCH DAMAGE. 26e1e9a4bfSMitsuru IWASAKI * 27e1e9a4bfSMitsuru IWASAKI * $FreeBSD$ 28e1e9a4bfSMitsuru IWASAKI */ 29e1e9a4bfSMitsuru IWASAKI 30e1e9a4bfSMitsuru IWASAKI #include <sys/param.h> 31a74172abSNate Lawson #include <sys/endian.h> 32e1e9a4bfSMitsuru IWASAKI #include <sys/stat.h> 33945137d9SNate Lawson #include <sys/wait.h> 34e1e9a4bfSMitsuru IWASAKI #include <assert.h> 35e1e9a4bfSMitsuru IWASAKI #include <err.h> 36e1e9a4bfSMitsuru IWASAKI #include <fcntl.h> 37e1e9a4bfSMitsuru IWASAKI #include <stdio.h> 38945137d9SNate Lawson #include <string.h> 39e1e9a4bfSMitsuru IWASAKI #include <unistd.h> 40e1e9a4bfSMitsuru IWASAKI 41e1e9a4bfSMitsuru IWASAKI #include "acpidump.h" 42e1e9a4bfSMitsuru IWASAKI 43c62f1cccSMitsuru IWASAKI #define BEGIN_COMMENT "/*\n" 44c62f1cccSMitsuru IWASAKI #define END_COMMENT " */\n" 45c62f1cccSMitsuru IWASAKI 46945137d9SNate Lawson static void acpi_print_string(char *s, size_t length); 478e6a8737SNate Lawson static void acpi_print_gas(struct ACPIgas *gas); 48c2962974SNate Lawson static int acpi_get_fadt_revision(struct FADTbody *fadt); 492177d4e6SNate Lawson static void acpi_handle_fadt(struct ACPIsdt *fadt); 50945137d9SNate Lawson static void acpi_print_cpu(u_char cpu_id); 51945137d9SNate Lawson static void acpi_print_local_apic(u_char cpu_id, u_char apic_id, 52945137d9SNate Lawson u_int32_t flags); 53945137d9SNate Lawson static void acpi_print_io_apic(u_char apic_id, u_int32_t int_base, 54945137d9SNate Lawson u_int64_t apic_addr); 55945137d9SNate Lawson static void acpi_print_mps_flags(u_int16_t flags); 56945137d9SNate Lawson static void acpi_print_intr(u_int32_t intr, u_int16_t mps_flags); 57945137d9SNate Lawson static void acpi_print_apic(struct MADT_APIC *mp); 58945137d9SNate Lawson static void acpi_handle_apic(struct ACPIsdt *sdp); 59945137d9SNate Lawson static void acpi_handle_hpet(struct ACPIsdt *sdp); 60773b6454SNate Lawson static void acpi_print_sdt(struct ACPIsdt *sdp); 612177d4e6SNate Lawson static void acpi_print_fadt(struct ACPIsdt *sdp); 628e6a8737SNate Lawson static void acpi_print_facs(struct FACSbody *facs); 63945137d9SNate Lawson static void acpi_print_dsdt(struct ACPIsdt *dsdp); 64a74172abSNate Lawson static struct ACPIsdt *acpi_map_sdt(vm_offset_t pa); 65945137d9SNate Lawson static void acpi_print_rsd_ptr(struct ACPIrsdp *rp); 66945137d9SNate Lawson static void acpi_handle_rsdt(struct ACPIsdt *rsdp); 67c62f1cccSMitsuru IWASAKI 68773b6454SNate Lawson /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */ 69a74172abSNate Lawson static int addr_size; 70a74172abSNate Lawson 71e1e9a4bfSMitsuru IWASAKI static void 72e1e9a4bfSMitsuru IWASAKI acpi_print_string(char *s, size_t length) 73e1e9a4bfSMitsuru IWASAKI { 74e1e9a4bfSMitsuru IWASAKI int c; 75e1e9a4bfSMitsuru IWASAKI 76e1e9a4bfSMitsuru IWASAKI /* Trim trailing spaces and NULLs */ 77e1e9a4bfSMitsuru IWASAKI while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) 78e1e9a4bfSMitsuru IWASAKI length--; 79e1e9a4bfSMitsuru IWASAKI 80e1e9a4bfSMitsuru IWASAKI while (length--) { 81e1e9a4bfSMitsuru IWASAKI c = *s++; 82e1e9a4bfSMitsuru IWASAKI putchar(c); 83e1e9a4bfSMitsuru IWASAKI } 84e1e9a4bfSMitsuru IWASAKI } 85e1e9a4bfSMitsuru IWASAKI 86e1e9a4bfSMitsuru IWASAKI static void 878e6a8737SNate Lawson acpi_print_gas(struct ACPIgas *gas) 888e6a8737SNate Lawson { 898e6a8737SNate Lawson switch(gas->address_space_id) { 908e6a8737SNate Lawson case ACPI_GAS_MEMORY: 91773b6454SNate Lawson printf("0x%08lx:%u[%u] (Memory)", (u_long)gas->address, 928e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 938e6a8737SNate Lawson break; 948e6a8737SNate Lawson case ACPI_GAS_IO: 95e47f1780SNate Lawson printf("0x%02lx:%u[%u] (IO)", (u_long)gas->address, 968e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 978e6a8737SNate Lawson break; 988e6a8737SNate Lawson case ACPI_GAS_PCI: 99e47f1780SNate Lawson printf("%x:%x+0x%x (PCI)", (uint16_t)(gas->address >> 32), 1008e6a8737SNate Lawson (uint16_t)((gas->address >> 16) & 0xffff), 1018e6a8737SNate Lawson (uint16_t)gas->address); 1028e6a8737SNate Lawson break; 1038e6a8737SNate Lawson /* XXX How to handle these below? */ 1048e6a8737SNate Lawson case ACPI_GAS_EMBEDDED: 105e47f1780SNate Lawson printf("0x%x:%u[%u] (EC)", (uint16_t)gas->address, 1068e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 1078e6a8737SNate Lawson break; 1088e6a8737SNate Lawson case ACPI_GAS_SMBUS: 109e47f1780SNate Lawson printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->address, 1108e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 1118e6a8737SNate Lawson break; 1128e6a8737SNate Lawson case ACPI_GAS_FIXED: 1138e6a8737SNate Lawson default: 114773b6454SNate Lawson printf("0x%08lx (?)", (u_long)gas->address); 1158e6a8737SNate Lawson break; 1168e6a8737SNate Lawson } 1178e6a8737SNate Lawson } 1188e6a8737SNate Lawson 119c2962974SNate Lawson /* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */ 120c2962974SNate Lawson static int 121c2962974SNate Lawson acpi_get_fadt_revision(struct FADTbody *fadt) 122e1e9a4bfSMitsuru IWASAKI { 123c2962974SNate Lawson int fadt_revision; 124e1e9a4bfSMitsuru IWASAKI 125c83f0f99SNate Lawson /* Set the FADT revision separately from the RSDP version. */ 126c83f0f99SNate Lawson if (addr_size == 8) { 127c83f0f99SNate Lawson fadt_revision = 2; 1288e6a8737SNate Lawson 129773b6454SNate Lawson /* 130c83f0f99SNate Lawson * A few systems (e.g., IBM T23) have an RSDP that claims 131c83f0f99SNate Lawson * revision 2 but the 64 bit addresses are invalid. If 132c83f0f99SNate Lawson * revision 2 and the 32 bit address is non-zero but the 133c83f0f99SNate Lawson * 32 and 64 bit versions don't match, prefer the 32 bit 134c83f0f99SNate Lawson * version for all subsequent tables. 135773b6454SNate Lawson */ 136c83f0f99SNate Lawson if (fadt->facs_ptr != 0 && 137c83f0f99SNate Lawson (fadt->x_facs_ptr & 0xffffffff) != fadt->facs_ptr) 138c83f0f99SNate Lawson fadt_revision = 1; 139c2962974SNate Lawson } else 140c83f0f99SNate Lawson fadt_revision = 1; 141c2962974SNate Lawson return (fadt_revision); 142c83f0f99SNate Lawson } 143c2962974SNate Lawson 144c2962974SNate Lawson static void 1452177d4e6SNate Lawson acpi_handle_fadt(struct ACPIsdt *sdp) 146c2962974SNate Lawson { 147c2962974SNate Lawson struct ACPIsdt *dsdp; 148c2962974SNate Lawson struct FACSbody *facs; 1492177d4e6SNate Lawson struct FADTbody *fadt; 150c2962974SNate Lawson int fadt_revision; 151c2962974SNate Lawson 1522177d4e6SNate Lawson fadt = (struct FADTbody *)sdp->body; 1532177d4e6SNate Lawson acpi_print_fadt(sdp); 154c83f0f99SNate Lawson 155c2962974SNate Lawson fadt_revision = acpi_get_fadt_revision(fadt); 156c83f0f99SNate Lawson if (fadt_revision == 1) 1578e6a8737SNate Lawson facs = (struct FACSbody *)acpi_map_sdt(fadt->facs_ptr); 158773b6454SNate Lawson else 159773b6454SNate Lawson facs = (struct FACSbody *)acpi_map_sdt(fadt->x_facs_ptr); 1608e6a8737SNate Lawson if (memcmp(facs->signature, "FACS", 4) != 0 || facs->len < 64) 1618e6a8737SNate Lawson errx(1, "FACS is corrupt"); 1628e6a8737SNate Lawson acpi_print_facs(facs); 1638e6a8737SNate Lawson 164c83f0f99SNate Lawson if (fadt_revision == 1) 1658e6a8737SNate Lawson dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 166773b6454SNate Lawson else 167773b6454SNate Lawson dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr); 168e1e9a4bfSMitsuru IWASAKI if (acpi_checksum(dsdp, dsdp->len)) 169945137d9SNate Lawson errx(1, "DSDT is corrupt"); 170945137d9SNate Lawson acpi_print_dsdt(dsdp); 171c62f1cccSMitsuru IWASAKI } 172c62f1cccSMitsuru IWASAKI 173c62f1cccSMitsuru IWASAKI static void 1740a473124SJohn Baldwin acpi_print_cpu(u_char cpu_id) 1750a473124SJohn Baldwin { 1760a473124SJohn Baldwin 1770a473124SJohn Baldwin printf("\tACPI CPU="); 1780a473124SJohn Baldwin if (cpu_id == 0xff) 1790a473124SJohn Baldwin printf("ALL\n"); 1800a473124SJohn Baldwin else 1810a473124SJohn Baldwin printf("%d\n", (u_int)cpu_id); 1820a473124SJohn Baldwin } 1830a473124SJohn Baldwin 1840a473124SJohn Baldwin static void 1850a473124SJohn Baldwin acpi_print_local_apic(u_char cpu_id, u_char apic_id, u_int32_t flags) 1860a473124SJohn Baldwin { 1870a473124SJohn Baldwin acpi_print_cpu(cpu_id); 1880a473124SJohn Baldwin printf("\tFlags={"); 1890a473124SJohn Baldwin if (flags & ACPI_MADT_APIC_LOCAL_FLAG_ENABLED) 1900a473124SJohn Baldwin printf("ENABLED"); 1910a473124SJohn Baldwin else 1920a473124SJohn Baldwin printf("DISABLED"); 1930a473124SJohn Baldwin printf("}\n"); 1940a473124SJohn Baldwin printf("\tAPIC ID=%d\n", (u_int)apic_id); 1950a473124SJohn Baldwin } 1960a473124SJohn Baldwin 1970a473124SJohn Baldwin static void 1980a473124SJohn Baldwin acpi_print_io_apic(u_char apic_id, u_int32_t int_base, u_int64_t apic_addr) 1990a473124SJohn Baldwin { 2000a473124SJohn Baldwin printf("\tAPIC ID=%d\n", (u_int)apic_id); 2010a473124SJohn Baldwin printf("\tINT BASE=%d\n", int_base); 202945137d9SNate Lawson printf("\tADDR=0x%016jx\n", apic_addr); 2030a473124SJohn Baldwin } 2040a473124SJohn Baldwin 2050a473124SJohn Baldwin static void 2060a473124SJohn Baldwin acpi_print_mps_flags(u_int16_t flags) 2070a473124SJohn Baldwin { 2080a473124SJohn Baldwin 2090a473124SJohn Baldwin printf("\tFlags={Polarity="); 2100a473124SJohn Baldwin switch (flags & MPS_INT_FLAG_POLARITY_MASK) { 2110a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_CONFORM: 2120a473124SJohn Baldwin printf("conforming"); 2130a473124SJohn Baldwin break; 2140a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_HIGH: 2150a473124SJohn Baldwin printf("active-hi"); 2160a473124SJohn Baldwin break; 2170a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_LOW: 2180a473124SJohn Baldwin printf("active-lo"); 2190a473124SJohn Baldwin break; 2200a473124SJohn Baldwin default: 2210a473124SJohn Baldwin printf("0x%x", flags & MPS_INT_FLAG_POLARITY_MASK); 2220a473124SJohn Baldwin break; 2230a473124SJohn Baldwin } 2240a473124SJohn Baldwin printf(", Trigger="); 2250a473124SJohn Baldwin switch (flags & MPS_INT_FLAG_TRIGGER_MASK) { 2260a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_CONFORM: 2270a473124SJohn Baldwin printf("conforming"); 2280a473124SJohn Baldwin break; 2290a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_EDGE: 2300a473124SJohn Baldwin printf("edge"); 2310a473124SJohn Baldwin break; 2320a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_LEVEL: 2330a473124SJohn Baldwin printf("level"); 2340a473124SJohn Baldwin break; 2350a473124SJohn Baldwin default: 2360a473124SJohn Baldwin printf("0x%x", (flags & MPS_INT_FLAG_TRIGGER_MASK) >> 2); 2370a473124SJohn Baldwin } 2380a473124SJohn Baldwin printf("}\n"); 2390a473124SJohn Baldwin } 2400a473124SJohn Baldwin 2410a473124SJohn Baldwin static void 2420a473124SJohn Baldwin acpi_print_intr(u_int32_t intr, u_int16_t mps_flags) 2430a473124SJohn Baldwin { 2440a473124SJohn Baldwin 2450a473124SJohn Baldwin printf("\tINTR=%d\n", (u_int)intr); 2460a473124SJohn Baldwin acpi_print_mps_flags(mps_flags); 2470a473124SJohn Baldwin } 2480a473124SJohn Baldwin 2490a473124SJohn Baldwin const char *apic_types[] = { "Local APIC", "IO APIC", "INT Override", "NMI", 2500a473124SJohn Baldwin "Local NMI", "Local APIC Override", "IO SAPIC", 2510a473124SJohn Baldwin "Local SAPIC", "Platform Interrupt" }; 2520a473124SJohn Baldwin const char *platform_int_types[] = { "PMI", "INIT", 2530a473124SJohn Baldwin "Corrected Platform Error" }; 2540a473124SJohn Baldwin 2550a473124SJohn Baldwin static void 2560a473124SJohn Baldwin acpi_print_apic(struct MADT_APIC *mp) 2570a473124SJohn Baldwin { 2580a473124SJohn Baldwin 2590a473124SJohn Baldwin printf("\tType=%s\n", apic_types[mp->type]); 2600a473124SJohn Baldwin switch (mp->type) { 2610a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_APIC: 2620a473124SJohn Baldwin acpi_print_local_apic(mp->body.local_apic.cpu_id, 2630a473124SJohn Baldwin mp->body.local_apic.apic_id, mp->body.local_apic.flags); 2640a473124SJohn Baldwin break; 2650a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_IO_APIC: 2660a473124SJohn Baldwin acpi_print_io_apic(mp->body.io_apic.apic_id, 2670a473124SJohn Baldwin mp->body.io_apic.int_base, 2680a473124SJohn Baldwin mp->body.io_apic.apic_addr); 2690a473124SJohn Baldwin break; 2700a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_INT_OVERRIDE: 2710a473124SJohn Baldwin printf("\tBUS=%d\n", (u_int)mp->body.int_override.bus); 2720a473124SJohn Baldwin printf("\tIRQ=%d\n", (u_int)mp->body.int_override.source); 2730a473124SJohn Baldwin acpi_print_intr(mp->body.int_override.intr, 2740a473124SJohn Baldwin mp->body.int_override.mps_flags); 2750a473124SJohn Baldwin break; 2760a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_NMI: 2770a473124SJohn Baldwin acpi_print_intr(mp->body.nmi.intr, mp->body.nmi.mps_flags); 2780a473124SJohn Baldwin break; 2790a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_NMI: 2800a473124SJohn Baldwin acpi_print_cpu(mp->body.local_nmi.cpu_id); 2810a473124SJohn Baldwin printf("\tLINT Pin=%d\n", mp->body.local_nmi.lintpin); 2820a473124SJohn Baldwin acpi_print_mps_flags(mp->body.local_nmi.mps_flags); 2830a473124SJohn Baldwin break; 2840a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE: 285945137d9SNate Lawson printf("\tLocal APIC ADDR=0x%016jx\n", 286945137d9SNate Lawson mp->body.local_apic_override.apic_addr); 2870a473124SJohn Baldwin break; 2880a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_IO_SAPIC: 2890a473124SJohn Baldwin acpi_print_io_apic(mp->body.io_sapic.apic_id, 2900a473124SJohn Baldwin mp->body.io_sapic.int_base, 2910a473124SJohn Baldwin mp->body.io_sapic.apic_addr); 2920a473124SJohn Baldwin break; 2930a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_SAPIC: 2940a473124SJohn Baldwin acpi_print_local_apic(mp->body.local_sapic.cpu_id, 2950a473124SJohn Baldwin mp->body.local_sapic.apic_id, mp->body.local_sapic.flags); 2960a473124SJohn Baldwin printf("\tAPIC EID=%d\n", (u_int)mp->body.local_sapic.apic_eid); 2970a473124SJohn Baldwin break; 2980a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_INT_SRC: 2990a473124SJohn Baldwin printf("\tType=%s\n", 3000a473124SJohn Baldwin platform_int_types[mp->body.int_src.type]); 3010a473124SJohn Baldwin printf("\tCPU ID=%d\n", (u_int)mp->body.int_src.cpu_id); 3020a473124SJohn Baldwin printf("\tCPU EID=%d\n", (u_int)mp->body.int_src.cpu_id); 3030a473124SJohn Baldwin printf("\tSAPIC Vector=%d\n", 3040a473124SJohn Baldwin (u_int)mp->body.int_src.sapic_vector); 3050a473124SJohn Baldwin acpi_print_intr(mp->body.int_src.intr, 3060a473124SJohn Baldwin mp->body.int_src.mps_flags); 3070a473124SJohn Baldwin break; 3080a473124SJohn Baldwin default: 3090a473124SJohn Baldwin printf("\tUnknown type %d\n", (u_int)mp->type); 310945137d9SNate Lawson break; 3110a473124SJohn Baldwin } 3120a473124SJohn Baldwin } 3130a473124SJohn Baldwin 3140a473124SJohn Baldwin static void 3150a473124SJohn Baldwin acpi_handle_apic(struct ACPIsdt *sdp) 3160a473124SJohn Baldwin { 3170a473124SJohn Baldwin struct MADTbody *madtp; 3180a473124SJohn Baldwin struct MADT_APIC *madt_apicp; 3190a473124SJohn Baldwin 320773b6454SNate Lawson printf(BEGIN_COMMENT); 321773b6454SNate Lawson acpi_print_sdt(sdp); 3220a473124SJohn Baldwin madtp = (struct MADTbody *) sdp->body; 3230a473124SJohn Baldwin printf("\tLocal APIC ADDR=0x%08x\n", madtp->lapic_addr); 3240a473124SJohn Baldwin printf("\tFlags={"); 3250a473124SJohn Baldwin if (madtp->flags & ACPI_APIC_FLAG_PCAT_COMPAT) 3260a473124SJohn Baldwin printf("PC-AT"); 3270a473124SJohn Baldwin printf("}\n"); 3280a473124SJohn Baldwin madt_apicp = (struct MADT_APIC *)madtp->body; 3290a473124SJohn Baldwin while (((uintptr_t)madt_apicp) - ((uintptr_t)sdp) < sdp->len) { 3300a473124SJohn Baldwin printf("\n"); 3310a473124SJohn Baldwin acpi_print_apic(madt_apicp); 3320a473124SJohn Baldwin madt_apicp = (struct MADT_APIC *) ((char *)madt_apicp + 3330a473124SJohn Baldwin madt_apicp->len); 3340a473124SJohn Baldwin } 3350a473124SJohn Baldwin printf(END_COMMENT); 3360a473124SJohn Baldwin } 3370a473124SJohn Baldwin 3380a473124SJohn Baldwin static void 33979d7565cSPeter Wemm acpi_handle_hpet(struct ACPIsdt *sdp) 34079d7565cSPeter Wemm { 34179d7565cSPeter Wemm struct HPETbody *hpetp; 34279d7565cSPeter Wemm 343773b6454SNate Lawson printf(BEGIN_COMMENT); 344773b6454SNate Lawson acpi_print_sdt(sdp); 34579d7565cSPeter Wemm hpetp = (struct HPETbody *) sdp->body; 34679d7565cSPeter Wemm printf("\tHPET Number=%d\n", hpetp->hpet_number); 34779d7565cSPeter Wemm printf("\tADDR=0x%08x\n", hpetp->base_addr); 34879d7565cSPeter Wemm printf("\tHW Rev=0x%x\n", hpetp->block_hwrev); 34979d7565cSPeter Wemm printf("\tComparitors=%d\n", hpetp->block_comparitors); 35079d7565cSPeter Wemm printf("\tCounter Size=%d\n", hpetp->block_counter_size); 35179d7565cSPeter Wemm printf("\tLegacy IRQ routing capable={"); 35279d7565cSPeter Wemm if (hpetp->block_legacy_capable) 35379d7565cSPeter Wemm printf("TRUE}\n"); 35479d7565cSPeter Wemm else 35579d7565cSPeter Wemm printf("FALSE}\n"); 35679d7565cSPeter Wemm printf("\tPCI Vendor ID=0x%04x\n", hpetp->block_pcivendor); 35755da3c73SPeter Wemm printf("\tMinimal Tick=%d\n", hpetp->clock_tick); 35879d7565cSPeter Wemm printf(END_COMMENT); 35979d7565cSPeter Wemm } 36079d7565cSPeter Wemm 36179d7565cSPeter Wemm static void 36255d7ff9eSNate Lawson acpi_handle_ecdt(struct ACPIsdt *sdp) 36355d7ff9eSNate Lawson { 36455d7ff9eSNate Lawson struct ECDTbody *ecdt; 36555d7ff9eSNate Lawson 36655d7ff9eSNate Lawson printf(BEGIN_COMMENT); 36755d7ff9eSNate Lawson acpi_print_sdt(sdp); 36855d7ff9eSNate Lawson ecdt = (struct ECDTbody *) sdp->body; 36955d7ff9eSNate Lawson printf("\tEC_CONTROL="); 37055d7ff9eSNate Lawson acpi_print_gas(&ecdt->ec_control); 37155d7ff9eSNate Lawson printf("\n\tEC_DATA="); 37255d7ff9eSNate Lawson acpi_print_gas(&ecdt->ec_data); 37355d7ff9eSNate Lawson printf("\n\tUID=%#x, ", ecdt->uid); 37455d7ff9eSNate Lawson printf("GPE_BIT=%#x\n", ecdt->gpe_bit); 37555d7ff9eSNate Lawson printf("\tEC_ID=%s\n", ecdt->ec_id); 37655d7ff9eSNate Lawson printf(END_COMMENT); 37755d7ff9eSNate Lawson } 37855d7ff9eSNate Lawson 37955d7ff9eSNate Lawson static void 380a47e681bSScott Long acpi_handle_mcfg(struct ACPIsdt *sdp) 381a47e681bSScott Long { 382a47e681bSScott Long struct MCFGbody *mcfg; 383a47e681bSScott Long u_int i, e; 384a47e681bSScott Long 385a47e681bSScott Long printf(BEGIN_COMMENT); 386a47e681bSScott Long acpi_print_sdt(sdp); 387a47e681bSScott Long mcfg = (struct MCFGbody *) sdp->body; 388a47e681bSScott Long 389a47e681bSScott Long e = (sdp->len - ((caddr_t)&mcfg->s[0] - (caddr_t)sdp)) / 390a47e681bSScott Long sizeof(*mcfg->s); 391a47e681bSScott Long for (i = 0; i < e; i++, mcfg++) { 392a47e681bSScott Long printf("\n"); 393a47e681bSScott Long printf("\tBase Address= 0x%016jx\n", mcfg->s[i].baseaddr); 394a47e681bSScott Long printf("\tSegment Group= 0x%04x\n", mcfg->s[i].seg_grp); 395a47e681bSScott Long printf("\tStart Bus= %d\n", mcfg->s[i].start); 396a47e681bSScott Long printf("\tEnd Bus= %d\n", mcfg->s[i].end); 397a47e681bSScott Long } 398a47e681bSScott Long printf(END_COMMENT); 399a47e681bSScott Long } 400a47e681bSScott Long 401a47e681bSScott Long static void 402773b6454SNate Lawson acpi_print_sdt(struct ACPIsdt *sdp) 403c62f1cccSMitsuru IWASAKI { 404773b6454SNate Lawson printf(" "); 405e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->signature, 4); 406c62f1cccSMitsuru IWASAKI printf(": Length=%d, Revision=%d, Checksum=%d,\n", 407e1e9a4bfSMitsuru IWASAKI sdp->len, sdp->rev, sdp->check); 408e1e9a4bfSMitsuru IWASAKI printf("\tOEMID="); 409e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemid, 6); 410e1e9a4bfSMitsuru IWASAKI printf(", OEM Table ID="); 411e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemtblid, 8); 412e1e9a4bfSMitsuru IWASAKI printf(", OEM Revision=0x%x,\n", sdp->oemrev); 413e1e9a4bfSMitsuru IWASAKI printf("\tCreator ID="); 414e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->creator, 4); 415e1e9a4bfSMitsuru IWASAKI printf(", Creator Revision=0x%x\n", sdp->crerev); 416e1e9a4bfSMitsuru IWASAKI } 417e1e9a4bfSMitsuru IWASAKI 418945137d9SNate Lawson static void 419e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(struct ACPIsdt *rsdp) 420e1e9a4bfSMitsuru IWASAKI { 421e1e9a4bfSMitsuru IWASAKI int i, entries; 422a74172abSNate Lawson u_long addr; 423e1e9a4bfSMitsuru IWASAKI 424773b6454SNate Lawson printf(BEGIN_COMMENT); 425773b6454SNate Lawson acpi_print_sdt(rsdp); 426a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 427e1e9a4bfSMitsuru IWASAKI printf("\tEntries={ "); 428e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 429e1e9a4bfSMitsuru IWASAKI if (i > 0) 430e1e9a4bfSMitsuru IWASAKI printf(", "); 431a74172abSNate Lawson switch (addr_size) { 432a74172abSNate Lawson case 4: 433a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 434a74172abSNate Lawson break; 435a74172abSNate Lawson case 8: 436a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 437a74172abSNate Lawson break; 438a74172abSNate Lawson default: 439a74172abSNate Lawson addr = 0; 440a74172abSNate Lawson } 441a74172abSNate Lawson assert(addr != 0); 442a74172abSNate Lawson printf("0x%08lx", addr); 443e1e9a4bfSMitsuru IWASAKI } 444e1e9a4bfSMitsuru IWASAKI printf(" }\n"); 445c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 446e1e9a4bfSMitsuru IWASAKI } 447e1e9a4bfSMitsuru IWASAKI 4488e6a8737SNate Lawson static const char *acpi_pm_profiles[] = { 4498e6a8737SNate Lawson "Unspecified", "Desktop", "Mobile", "Workstation", 4508e6a8737SNate Lawson "Enterprise Server", "SOHO Server", "Appliance PC" 4518e6a8737SNate Lawson }; 4528e6a8737SNate Lawson 453945137d9SNate Lawson static void 4542177d4e6SNate Lawson acpi_print_fadt(struct ACPIsdt *sdp) 455e1e9a4bfSMitsuru IWASAKI { 4562177d4e6SNate Lawson struct FADTbody *fadt; 4578e6a8737SNate Lawson const char *pm; 458e1e9a4bfSMitsuru IWASAKI char sep; 459e1e9a4bfSMitsuru IWASAKI 4602177d4e6SNate Lawson fadt = (struct FADTbody *)sdp->body; 461c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 4622177d4e6SNate Lawson acpi_print_sdt(sdp); 4632177d4e6SNate Lawson printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->facs_ptr, 4648e6a8737SNate Lawson fadt->dsdt_ptr); 4658e6a8737SNate Lawson printf("\tINT_MODEL=%s\n", fadt->int_model ? "APIC" : "PIC"); 4668e6a8737SNate Lawson if (fadt->pm_profile >= sizeof(acpi_pm_profiles) / sizeof(char *)) 4678e6a8737SNate Lawson pm = "Reserved"; 4688e6a8737SNate Lawson else 4698e6a8737SNate Lawson pm = acpi_pm_profiles[fadt->pm_profile]; 4708e6a8737SNate Lawson printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->pm_profile); 4718e6a8737SNate Lawson printf("\tSCI_INT=%d\n", fadt->sci_int); 4728e6a8737SNate Lawson printf("\tSMI_CMD=0x%x, ", fadt->smi_cmd); 4738e6a8737SNate Lawson printf("ACPI_ENABLE=0x%x, ", fadt->acpi_enable); 4748e6a8737SNate Lawson printf("ACPI_DISABLE=0x%x, ", fadt->acpi_disable); 4758e6a8737SNate Lawson printf("S4BIOS_REQ=0x%x\n", fadt->s4biosreq); 4768e6a8737SNate Lawson printf("\tPSTATE_CNT=0x%x\n", fadt->pstate_cnt); 477e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", 4788e6a8737SNate Lawson fadt->pm1a_evt_blk, 4798e6a8737SNate Lawson fadt->pm1a_evt_blk + fadt->pm1_evt_len - 1); 4808e6a8737SNate Lawson if (fadt->pm1b_evt_blk != 0) 481e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", 4828e6a8737SNate Lawson fadt->pm1b_evt_blk, 4838e6a8737SNate Lawson fadt->pm1b_evt_blk + fadt->pm1_evt_len - 1); 484e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", 4858e6a8737SNate Lawson fadt->pm1a_cnt_blk, 4868e6a8737SNate Lawson fadt->pm1a_cnt_blk + fadt->pm1_cnt_len - 1); 4878e6a8737SNate Lawson if (fadt->pm1b_cnt_blk != 0) 488e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", 4898e6a8737SNate Lawson fadt->pm1b_cnt_blk, 4908e6a8737SNate Lawson fadt->pm1b_cnt_blk + fadt->pm1_cnt_len - 1); 4918e6a8737SNate Lawson if (fadt->pm2_cnt_blk != 0) 492e1e9a4bfSMitsuru IWASAKI printf("\tPM2_CNT_BLK=0x%x-0x%x\n", 4938e6a8737SNate Lawson fadt->pm2_cnt_blk, 4948e6a8737SNate Lawson fadt->pm2_cnt_blk + fadt->pm2_cnt_len - 1); 495c08c4e81SNate Lawson printf("\tPM_TMR_BLK=0x%x-0x%x\n", 4968e6a8737SNate Lawson fadt->pm_tmr_blk, 4978e6a8737SNate Lawson fadt->pm_tmr_blk + fadt->pm_tmr_len - 1); 4988e6a8737SNate Lawson if (fadt->gpe0_blk != 0) 4998e6a8737SNate Lawson printf("\tGPE0_BLK=0x%x-0x%x\n", 5008e6a8737SNate Lawson fadt->gpe0_blk, 5018e6a8737SNate Lawson fadt->gpe0_blk + fadt->gpe0_len - 1); 5028e6a8737SNate Lawson if (fadt->gpe1_blk != 0) 5038e6a8737SNate Lawson printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", 5048e6a8737SNate Lawson fadt->gpe1_blk, 5058e6a8737SNate Lawson fadt->gpe1_blk + fadt->gpe1_len - 1, 5068e6a8737SNate Lawson fadt->gpe1_base); 5078e6a8737SNate Lawson if (fadt->cst_cnt != 0) 5088e6a8737SNate Lawson printf("\tCST_CNT=0x%x\n", fadt->cst_cnt); 50951c1824fSNate Lawson printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", 5108e6a8737SNate Lawson fadt->p_lvl2_lat, fadt->p_lvl3_lat); 511e1e9a4bfSMitsuru IWASAKI printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", 5128e6a8737SNate Lawson fadt->flush_size, fadt->flush_stride); 513e1e9a4bfSMitsuru IWASAKI printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", 5148e6a8737SNate Lawson fadt->duty_off, fadt->duty_width); 515e1e9a4bfSMitsuru IWASAKI printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", 5168e6a8737SNate Lawson fadt->day_alrm, fadt->mon_alrm, fadt->century); 517e1e9a4bfSMitsuru IWASAKI 5188e6a8737SNate Lawson #define PRINTFLAG(var, flag) do { \ 5198e6a8737SNate Lawson if ((var) & FADT_FLAG_## flag) { \ 5208e6a8737SNate Lawson printf("%c%s", sep, #flag); sep = ','; \ 521e1e9a4bfSMitsuru IWASAKI } \ 522e1e9a4bfSMitsuru IWASAKI } while (0) 523e1e9a4bfSMitsuru IWASAKI 5248e6a8737SNate Lawson printf("\tIAPC_BOOT_ARCH="); 5258e6a8737SNate Lawson sep = '{'; 5268e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, LEGACY_DEV); 5278e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, 8042); 52869a9febdSNate Lawson if (fadt->iapc_boot_arch != 0) 5294e36f5a1SNate Lawson printf("}"); 5304e36f5a1SNate Lawson printf("\n"); 5318e6a8737SNate Lawson 5328e6a8737SNate Lawson printf("\tFlags="); 5338e6a8737SNate Lawson sep = '{'; 5348e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD); 5358e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD_FLUSH); 5368e6a8737SNate Lawson PRINTFLAG(fadt->flags, PROC_C1); 5378e6a8737SNate Lawson PRINTFLAG(fadt->flags, P_LVL2_UP); 5388e6a8737SNate Lawson PRINTFLAG(fadt->flags, PWR_BUTTON); 5398e6a8737SNate Lawson PRINTFLAG(fadt->flags, SLP_BUTTON); 5408e6a8737SNate Lawson PRINTFLAG(fadt->flags, FIX_RTC); 5418e6a8737SNate Lawson PRINTFLAG(fadt->flags, RTC_S4); 5428e6a8737SNate Lawson PRINTFLAG(fadt->flags, TMR_VAL_EXT); 5438e6a8737SNate Lawson PRINTFLAG(fadt->flags, DCK_CAP); 5448e6a8737SNate Lawson PRINTFLAG(fadt->flags, RESET_REG); 5458e6a8737SNate Lawson PRINTFLAG(fadt->flags, SEALED_CASE); 5468e6a8737SNate Lawson PRINTFLAG(fadt->flags, HEADLESS); 5478e6a8737SNate Lawson PRINTFLAG(fadt->flags, CPU_SW_SLP); 54869a9febdSNate Lawson if (fadt->flags != 0) 5498e6a8737SNate Lawson printf("}\n"); 550e1e9a4bfSMitsuru IWASAKI 551e1e9a4bfSMitsuru IWASAKI #undef PRINTFLAG 552e1e9a4bfSMitsuru IWASAKI 5538e6a8737SNate Lawson if (fadt->flags & FADT_FLAG_RESET_REG) { 5548e6a8737SNate Lawson printf("\tRESET_REG="); 5558e6a8737SNate Lawson acpi_print_gas(&fadt->reset_reg); 5568e6a8737SNate Lawson printf(", RESET_VALUE=%#x\n", fadt->reset_value); 5578e6a8737SNate Lawson } 558c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) > 1) { 559773b6454SNate Lawson printf("\tX_FACS=0x%08lx, ", (u_long)fadt->x_facs_ptr); 560773b6454SNate Lawson printf("X_DSDT=0x%08lx\n", (u_long)fadt->x_dsdt_ptr); 561c08c4e81SNate Lawson printf("\tX_PM1a_EVT_BLK="); 562773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_evt_blk); 563c08c4e81SNate Lawson if (fadt->x_pm1b_evt_blk.address != 0) { 564c08c4e81SNate Lawson printf("\n\tX_PM1b_EVT_BLK="); 565773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_evt_blk); 566c08c4e81SNate Lawson } 567c08c4e81SNate Lawson printf("\n\tX_PM1a_CNT_BLK="); 568773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_cnt_blk); 569c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 570c08c4e81SNate Lawson printf("\n\tX_PM1b_CNT_BLK="); 571773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_cnt_blk); 572c08c4e81SNate Lawson } 573c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 574773b6454SNate Lawson printf("\n\tX_PM2_CNT_BLK="); 575773b6454SNate Lawson acpi_print_gas(&fadt->x_pm2_cnt_blk); 576c08c4e81SNate Lawson } 577773b6454SNate Lawson printf("\n\tX_PM_TMR_BLK="); 578773b6454SNate Lawson acpi_print_gas(&fadt->x_pm_tmr_blk); 579c08c4e81SNate Lawson if (fadt->x_gpe0_blk.address != 0) { 580773b6454SNate Lawson printf("\n\tX_GPE0_BLK="); 581773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe0_blk); 582c08c4e81SNate Lawson } 583c08c4e81SNate Lawson if (fadt->x_gpe1_blk.address != 0) { 584773b6454SNate Lawson printf("\n\tX_GPE1_BLK="); 585773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe1_blk); 586c08c4e81SNate Lawson } 587773b6454SNate Lawson printf("\n"); 588773b6454SNate Lawson } 5898e6a8737SNate Lawson 5908e6a8737SNate Lawson printf(END_COMMENT); 5918e6a8737SNate Lawson } 5928e6a8737SNate Lawson 5938e6a8737SNate Lawson static void 5948e6a8737SNate Lawson acpi_print_facs(struct FACSbody *facs) 5958e6a8737SNate Lawson { 5968e6a8737SNate Lawson printf(BEGIN_COMMENT); 5978e6a8737SNate Lawson printf(" FACS:\tLength=%u, ", facs->len); 5988e6a8737SNate Lawson printf("HwSig=0x%08x, ", facs->hw_sig); 5998e6a8737SNate Lawson printf("Firm_Wake_Vec=0x%08x\n", facs->firm_wake_vec); 6008e6a8737SNate Lawson 601773b6454SNate Lawson printf("\tGlobal_Lock="); 6028e6a8737SNate Lawson if (facs->global_lock != 0) { 6038e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_PENDING) 6048e6a8737SNate Lawson printf("PENDING,"); 6058e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_OWNED) 6068e6a8737SNate Lawson printf("OWNED"); 6078e6a8737SNate Lawson } 608773b6454SNate Lawson printf("\n"); 6098e6a8737SNate Lawson 610773b6454SNate Lawson printf("\tFlags="); 6118e6a8737SNate Lawson if (facs->flags & FACS_FLAG_S4BIOS_F) 6128e6a8737SNate Lawson printf("S4BIOS"); 613773b6454SNate Lawson printf("\n"); 6148e6a8737SNate Lawson 6158e6a8737SNate Lawson if (facs->x_firm_wake_vec != 0) { 6168e6a8737SNate Lawson printf("\tX_Firm_Wake_Vec=%08lx\n", 6178e6a8737SNate Lawson (u_long)facs->x_firm_wake_vec); 6188e6a8737SNate Lawson } 619773b6454SNate Lawson printf("\tVersion=%u\n", facs->version); 6208e6a8737SNate Lawson 621c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 622e1e9a4bfSMitsuru IWASAKI } 623e1e9a4bfSMitsuru IWASAKI 624945137d9SNate Lawson static void 625e1e9a4bfSMitsuru IWASAKI acpi_print_dsdt(struct ACPIsdt *dsdp) 626e1e9a4bfSMitsuru IWASAKI { 627773b6454SNate Lawson printf(BEGIN_COMMENT); 628773b6454SNate Lawson acpi_print_sdt(dsdp); 629773b6454SNate Lawson printf(END_COMMENT); 630e1e9a4bfSMitsuru IWASAKI } 631e1e9a4bfSMitsuru IWASAKI 632e1e9a4bfSMitsuru IWASAKI int 633e1e9a4bfSMitsuru IWASAKI acpi_checksum(void *p, size_t length) 634e1e9a4bfSMitsuru IWASAKI { 635e1e9a4bfSMitsuru IWASAKI u_int8_t *bp; 636e1e9a4bfSMitsuru IWASAKI u_int8_t sum; 637e1e9a4bfSMitsuru IWASAKI 638e1e9a4bfSMitsuru IWASAKI bp = p; 639e1e9a4bfSMitsuru IWASAKI sum = 0; 640e1e9a4bfSMitsuru IWASAKI while (length--) 641e1e9a4bfSMitsuru IWASAKI sum += *bp++; 642e1e9a4bfSMitsuru IWASAKI 643e1e9a4bfSMitsuru IWASAKI return (sum); 644e1e9a4bfSMitsuru IWASAKI } 645e1e9a4bfSMitsuru IWASAKI 646945137d9SNate Lawson static struct ACPIsdt * 647e1e9a4bfSMitsuru IWASAKI acpi_map_sdt(vm_offset_t pa) 648e1e9a4bfSMitsuru IWASAKI { 649e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sp; 650e1e9a4bfSMitsuru IWASAKI 651e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); 652e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sp->len); 653e1e9a4bfSMitsuru IWASAKI return (sp); 654e1e9a4bfSMitsuru IWASAKI } 655e1e9a4bfSMitsuru IWASAKI 656945137d9SNate Lawson static void 657e1e9a4bfSMitsuru IWASAKI acpi_print_rsd_ptr(struct ACPIrsdp *rp) 658e1e9a4bfSMitsuru IWASAKI { 659c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 660a74172abSNate Lawson printf(" RSD PTR: OEM="); 661e1e9a4bfSMitsuru IWASAKI acpi_print_string(rp->oem, 6); 662773b6454SNate Lawson printf(", ACPI_Rev=%s (%d)\n", rp->revision < 2 ? "1.0x" : "2.0x", 663a74172abSNate Lawson rp->revision); 664a74172abSNate Lawson if (rp->revision < 2) { 665a74172abSNate Lawson printf("\tRSDT=0x%08x, cksum=%u\n", rp->rsdt_addr, rp->sum); 666a74172abSNate Lawson } else { 667a74172abSNate Lawson printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", 668a74172abSNate Lawson (u_long)rp->xsdt_addr, rp->length, rp->xsum); 669a74172abSNate Lawson } 670c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 671e1e9a4bfSMitsuru IWASAKI } 672e1e9a4bfSMitsuru IWASAKI 673945137d9SNate Lawson static void 674e1e9a4bfSMitsuru IWASAKI acpi_handle_rsdt(struct ACPIsdt *rsdp) 675e1e9a4bfSMitsuru IWASAKI { 676e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sdp; 677a74172abSNate Lawson vm_offset_t addr; 678a74172abSNate Lawson int entries, i; 679e1e9a4bfSMitsuru IWASAKI 680e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(rsdp); 681a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 682e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 683a74172abSNate Lawson switch (addr_size) { 684a74172abSNate Lawson case 4: 685a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 686a74172abSNate Lawson break; 687a74172abSNate Lawson case 8: 688a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 689a74172abSNate Lawson break; 690a74172abSNate Lawson default: 691a74172abSNate Lawson assert((addr = 0)); 692a74172abSNate Lawson } 693a74172abSNate Lawson 694a74172abSNate Lawson sdp = (struct ACPIsdt *)acpi_map_sdt(addr); 6955cf6d493SNate Lawson if (acpi_checksum(sdp, sdp->len)) { 6965cf6d493SNate Lawson warnx("RSDT entry %d (sig %.4s) is corrupt", i, 6975cf6d493SNate Lawson sdp->signature); 6985cf6d493SNate Lawson continue; 6995cf6d493SNate Lawson } 700945137d9SNate Lawson if (!memcmp(sdp->signature, "FACP", 4)) 7012177d4e6SNate Lawson acpi_handle_fadt(sdp); 702945137d9SNate Lawson else if (!memcmp(sdp->signature, "APIC", 4)) 7030a473124SJohn Baldwin acpi_handle_apic(sdp); 704945137d9SNate Lawson else if (!memcmp(sdp->signature, "HPET", 4)) 70579d7565cSPeter Wemm acpi_handle_hpet(sdp); 70655d7ff9eSNate Lawson else if (!memcmp(sdp->signature, "ECDT", 4)) 70755d7ff9eSNate Lawson acpi_handle_ecdt(sdp); 708a47e681bSScott Long else if (!memcmp(sdp->signature, "MCFG", 4)) 709a47e681bSScott Long acpi_handle_mcfg(sdp); 710773b6454SNate Lawson else { 711773b6454SNate Lawson printf(BEGIN_COMMENT); 712773b6454SNate Lawson acpi_print_sdt(sdp); 713773b6454SNate Lawson printf(END_COMMENT); 714773b6454SNate Lawson } 715e1e9a4bfSMitsuru IWASAKI } 716e1e9a4bfSMitsuru IWASAKI } 717c62f1cccSMitsuru IWASAKI 718945137d9SNate Lawson struct ACPIsdt * 719476daaecSDag-Erling Smørgrav sdt_load_devmem(void) 720945137d9SNate Lawson { 721945137d9SNate Lawson struct ACPIrsdp *rp; 722945137d9SNate Lawson struct ACPIsdt *rsdp; 723945137d9SNate Lawson 724945137d9SNate Lawson rp = acpi_find_rsd_ptr(); 725945137d9SNate Lawson if (!rp) 726945137d9SNate Lawson errx(1, "Can't find ACPI information"); 727945137d9SNate Lawson 728945137d9SNate Lawson if (tflag) 729945137d9SNate Lawson acpi_print_rsd_ptr(rp); 730a74172abSNate Lawson if (rp->revision < 2) { 731945137d9SNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->rsdt_addr); 732945137d9SNate Lawson if (memcmp(rsdp->signature, "RSDT", 4) != 0 || 733945137d9SNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 734945137d9SNate Lawson errx(1, "RSDT is corrupted"); 735a74172abSNate Lawson addr_size = sizeof(uint32_t); 736a74172abSNate Lawson } else { 737a74172abSNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->xsdt_addr); 738a74172abSNate Lawson if (memcmp(rsdp->signature, "XSDT", 4) != 0 || 739a74172abSNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 740a74172abSNate Lawson errx(1, "XSDT is corrupted"); 741a74172abSNate Lawson addr_size = sizeof(uint64_t); 742a74172abSNate Lawson } 743945137d9SNate Lawson return (rsdp); 744945137d9SNate Lawson } 745c62f1cccSMitsuru IWASAKI 74662c7bde1SNate Lawson /* Write the DSDT to a file, concatenating any SSDTs (if present). */ 747bfa3f012SMarcel Moolenaar static int 748bfa3f012SMarcel Moolenaar write_dsdt(int fd, struct ACPIsdt *rsdt, struct ACPIsdt *dsdt) 749bfa3f012SMarcel Moolenaar { 750bfa3f012SMarcel Moolenaar struct ACPIsdt sdt; 751bfa3f012SMarcel Moolenaar struct ACPIsdt *ssdt; 752bfa3f012SMarcel Moolenaar uint8_t sum; 753bfa3f012SMarcel Moolenaar 75462c7bde1SNate Lawson /* Create a new checksum to account for the DSDT and any SSDTs. */ 755bfa3f012SMarcel Moolenaar sdt = *dsdt; 756bfa3f012SMarcel Moolenaar if (rsdt != NULL) { 757bfa3f012SMarcel Moolenaar sdt.check = 0; 758bfa3f012SMarcel Moolenaar sum = acpi_checksum(dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 759bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 760f7675a56SNate Lawson while (ssdt != NULL) { 761bfa3f012SMarcel Moolenaar sdt.len += ssdt->len - SIZEOF_SDT_HDR; 762bfa3f012SMarcel Moolenaar sum += acpi_checksum(ssdt->body, 763bfa3f012SMarcel Moolenaar ssdt->len - SIZEOF_SDT_HDR); 764bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 765bfa3f012SMarcel Moolenaar } 766bfa3f012SMarcel Moolenaar sum += acpi_checksum(&sdt, SIZEOF_SDT_HDR); 767bfa3f012SMarcel Moolenaar sdt.check -= sum; 768bfa3f012SMarcel Moolenaar } 76962c7bde1SNate Lawson 77062c7bde1SNate Lawson /* Write out the DSDT header and body. */ 771bfa3f012SMarcel Moolenaar write(fd, &sdt, SIZEOF_SDT_HDR); 772bfa3f012SMarcel Moolenaar write(fd, dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 77362c7bde1SNate Lawson 774b64e1b67SNate Lawson /* Write out any SSDTs (if present.) */ 775f7675a56SNate Lawson if (rsdt != NULL) { 776bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 777bfa3f012SMarcel Moolenaar while (ssdt != NULL) { 778bfa3f012SMarcel Moolenaar write(fd, ssdt->body, ssdt->len - SIZEOF_SDT_HDR); 779bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 780bfa3f012SMarcel Moolenaar } 781bfa3f012SMarcel Moolenaar } 782bfa3f012SMarcel Moolenaar return (0); 783bfa3f012SMarcel Moolenaar } 784bfa3f012SMarcel Moolenaar 785c62f1cccSMitsuru IWASAKI void 786bfa3f012SMarcel Moolenaar dsdt_save_file(char *outfile, struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 787c62f1cccSMitsuru IWASAKI { 788945137d9SNate Lawson int fd; 789945137d9SNate Lawson mode_t mode; 790945137d9SNate Lawson 791945137d9SNate Lawson assert(outfile != NULL); 792945137d9SNate Lawson mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 793945137d9SNate Lawson fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); 794945137d9SNate Lawson if (fd == -1) { 795945137d9SNate Lawson perror("dsdt_save_file"); 796945137d9SNate Lawson return; 797945137d9SNate Lawson } 798bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 799945137d9SNate Lawson close(fd); 800c62f1cccSMitsuru IWASAKI } 801c62f1cccSMitsuru IWASAKI 802945137d9SNate Lawson void 803bfa3f012SMarcel Moolenaar aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 804c62f1cccSMitsuru IWASAKI { 805945137d9SNate Lawson char tmpstr[32], buf[256]; 806945137d9SNate Lawson FILE *fp; 807945137d9SNate Lawson int fd, len; 808945137d9SNate Lawson 809945137d9SNate Lawson strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); 810945137d9SNate Lawson fd = mkstemp(tmpstr); 811945137d9SNate Lawson if (fd < 0) { 812945137d9SNate Lawson perror("iasl tmp file"); 813945137d9SNate Lawson return; 814c62f1cccSMitsuru IWASAKI } 815bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 816945137d9SNate Lawson close(fd); 817945137d9SNate Lawson 818945137d9SNate Lawson /* Run iasl -d on the temp file */ 819945137d9SNate Lawson if (fork() == 0) { 820945137d9SNate Lawson close(STDOUT_FILENO); 821945137d9SNate Lawson if (vflag == 0) 822945137d9SNate Lawson close(STDERR_FILENO); 823945137d9SNate Lawson execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, 0); 824945137d9SNate Lawson err(1, "exec"); 825c62f1cccSMitsuru IWASAKI } 826c62f1cccSMitsuru IWASAKI 827945137d9SNate Lawson wait(NULL); 828945137d9SNate Lawson unlink(tmpstr); 829945137d9SNate Lawson 830945137d9SNate Lawson /* Dump iasl's output to stdout */ 831945137d9SNate Lawson fp = fopen("acpidump.dsl", "r"); 832945137d9SNate Lawson unlink("acpidump.dsl"); 833945137d9SNate Lawson if (fp == NULL) { 834945137d9SNate Lawson perror("iasl tmp file (read)"); 835945137d9SNate Lawson return; 836945137d9SNate Lawson } 837945137d9SNate Lawson while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 838945137d9SNate Lawson fwrite(buf, 1, len, stdout); 839945137d9SNate Lawson fclose(fp); 840c62f1cccSMitsuru IWASAKI } 841c62f1cccSMitsuru IWASAKI 842945137d9SNate Lawson void 843945137d9SNate Lawson sdt_print_all(struct ACPIsdt *rsdp) 844c62f1cccSMitsuru IWASAKI { 845945137d9SNate Lawson acpi_handle_rsdt(rsdp); 846c62f1cccSMitsuru IWASAKI } 847c62f1cccSMitsuru IWASAKI 848bfa3f012SMarcel Moolenaar /* Fetch a table matching the given signature via the RSDT. */ 849945137d9SNate Lawson struct ACPIsdt * 850bfa3f012SMarcel Moolenaar sdt_from_rsdt(struct ACPIsdt *rsdt, const char *sig, struct ACPIsdt *last) 851c62f1cccSMitsuru IWASAKI { 852945137d9SNate Lawson struct ACPIsdt *sdt; 853a74172abSNate Lawson vm_offset_t addr; 854a74172abSNate Lawson int entries, i; 855945137d9SNate Lawson 856a74172abSNate Lawson entries = (rsdt->len - SIZEOF_SDT_HDR) / addr_size; 857945137d9SNate Lawson for (i = 0; i < entries; i++) { 858a74172abSNate Lawson switch (addr_size) { 859a74172abSNate Lawson case 4: 860a74172abSNate Lawson addr = le32dec((char*)rsdt->body + i * addr_size); 861a74172abSNate Lawson break; 862a74172abSNate Lawson case 8: 863a74172abSNate Lawson addr = le64dec((char*)rsdt->body + i * addr_size); 864a74172abSNate Lawson break; 865a74172abSNate Lawson default: 866a74172abSNate Lawson assert((addr = 0)); 867a74172abSNate Lawson } 868a74172abSNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(addr); 869bfa3f012SMarcel Moolenaar if (last != NULL) { 870bfa3f012SMarcel Moolenaar if (sdt == last) 871bfa3f012SMarcel Moolenaar last = NULL; 872bfa3f012SMarcel Moolenaar continue; 873bfa3f012SMarcel Moolenaar } 874a74172abSNate Lawson if (memcmp(sdt->signature, sig, strlen(sig))) 875a74172abSNate Lawson continue; 876945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 877945137d9SNate Lawson errx(1, "RSDT entry %d is corrupt", i); 878945137d9SNate Lawson return (sdt); 879c62f1cccSMitsuru IWASAKI } 880c62f1cccSMitsuru IWASAKI 881945137d9SNate Lawson return (NULL); 882c62f1cccSMitsuru IWASAKI } 883c62f1cccSMitsuru IWASAKI 884945137d9SNate Lawson struct ACPIsdt * 8858e6a8737SNate Lawson dsdt_from_fadt(struct FADTbody *fadt) 886c62f1cccSMitsuru IWASAKI { 887945137d9SNate Lawson struct ACPIsdt *sdt; 888c62f1cccSMitsuru IWASAKI 889c83f0f99SNate Lawson /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */ 890c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) == 1) 8918e6a8737SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 8922e71eb12SNate Lawson else 8932e71eb12SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr); 894945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 895945137d9SNate Lawson errx(1, "DSDT is corrupt\n"); 896945137d9SNate Lawson return (sdt); 897c62f1cccSMitsuru IWASAKI } 898