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); 34787f9f09aSTakanori Watanabe printf("\tADDR="); 34887f9f09aSTakanori Watanabe acpi_print_gas(&hpetp->genaddr); 34979d7565cSPeter Wemm printf("\tHW Rev=0x%x\n", hpetp->block_hwrev); 35079d7565cSPeter Wemm printf("\tComparitors=%d\n", hpetp->block_comparitors); 35179d7565cSPeter Wemm printf("\tCounter Size=%d\n", hpetp->block_counter_size); 35279d7565cSPeter Wemm printf("\tLegacy IRQ routing capable={"); 35379d7565cSPeter Wemm if (hpetp->block_legacy_capable) 35479d7565cSPeter Wemm printf("TRUE}\n"); 35579d7565cSPeter Wemm else 35679d7565cSPeter Wemm printf("FALSE}\n"); 35779d7565cSPeter Wemm printf("\tPCI Vendor ID=0x%04x\n", hpetp->block_pcivendor); 35855da3c73SPeter Wemm printf("\tMinimal Tick=%d\n", hpetp->clock_tick); 35979d7565cSPeter Wemm printf(END_COMMENT); 36079d7565cSPeter Wemm } 36179d7565cSPeter Wemm 36279d7565cSPeter Wemm static void 36355d7ff9eSNate Lawson acpi_handle_ecdt(struct ACPIsdt *sdp) 36455d7ff9eSNate Lawson { 36555d7ff9eSNate Lawson struct ECDTbody *ecdt; 36655d7ff9eSNate Lawson 36755d7ff9eSNate Lawson printf(BEGIN_COMMENT); 36855d7ff9eSNate Lawson acpi_print_sdt(sdp); 36955d7ff9eSNate Lawson ecdt = (struct ECDTbody *) sdp->body; 37055d7ff9eSNate Lawson printf("\tEC_CONTROL="); 37155d7ff9eSNate Lawson acpi_print_gas(&ecdt->ec_control); 37255d7ff9eSNate Lawson printf("\n\tEC_DATA="); 37355d7ff9eSNate Lawson acpi_print_gas(&ecdt->ec_data); 37455d7ff9eSNate Lawson printf("\n\tUID=%#x, ", ecdt->uid); 37555d7ff9eSNate Lawson printf("GPE_BIT=%#x\n", ecdt->gpe_bit); 37655d7ff9eSNate Lawson printf("\tEC_ID=%s\n", ecdt->ec_id); 37755d7ff9eSNate Lawson printf(END_COMMENT); 37855d7ff9eSNate Lawson } 37955d7ff9eSNate Lawson 38055d7ff9eSNate Lawson static void 381a47e681bSScott Long acpi_handle_mcfg(struct ACPIsdt *sdp) 382a47e681bSScott Long { 383a47e681bSScott Long struct MCFGbody *mcfg; 384a47e681bSScott Long u_int i, e; 385a47e681bSScott Long 386a47e681bSScott Long printf(BEGIN_COMMENT); 387a47e681bSScott Long acpi_print_sdt(sdp); 388a47e681bSScott Long mcfg = (struct MCFGbody *) sdp->body; 389a47e681bSScott Long 390a47e681bSScott Long e = (sdp->len - ((caddr_t)&mcfg->s[0] - (caddr_t)sdp)) / 391a47e681bSScott Long sizeof(*mcfg->s); 392a47e681bSScott Long for (i = 0; i < e; i++, mcfg++) { 393a47e681bSScott Long printf("\n"); 394a47e681bSScott Long printf("\tBase Address= 0x%016jx\n", mcfg->s[i].baseaddr); 395a47e681bSScott Long printf("\tSegment Group= 0x%04x\n", mcfg->s[i].seg_grp); 396a47e681bSScott Long printf("\tStart Bus= %d\n", mcfg->s[i].start); 397a47e681bSScott Long printf("\tEnd Bus= %d\n", mcfg->s[i].end); 398a47e681bSScott Long } 399a47e681bSScott Long printf(END_COMMENT); 400a47e681bSScott Long } 401a47e681bSScott Long 402a47e681bSScott Long static void 403773b6454SNate Lawson acpi_print_sdt(struct ACPIsdt *sdp) 404c62f1cccSMitsuru IWASAKI { 405773b6454SNate Lawson printf(" "); 406e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->signature, 4); 407c62f1cccSMitsuru IWASAKI printf(": Length=%d, Revision=%d, Checksum=%d,\n", 408e1e9a4bfSMitsuru IWASAKI sdp->len, sdp->rev, sdp->check); 409e1e9a4bfSMitsuru IWASAKI printf("\tOEMID="); 410e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemid, 6); 411e1e9a4bfSMitsuru IWASAKI printf(", OEM Table ID="); 412e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemtblid, 8); 413e1e9a4bfSMitsuru IWASAKI printf(", OEM Revision=0x%x,\n", sdp->oemrev); 414e1e9a4bfSMitsuru IWASAKI printf("\tCreator ID="); 415e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->creator, 4); 416e1e9a4bfSMitsuru IWASAKI printf(", Creator Revision=0x%x\n", sdp->crerev); 417e1e9a4bfSMitsuru IWASAKI } 418e1e9a4bfSMitsuru IWASAKI 419945137d9SNate Lawson static void 420e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(struct ACPIsdt *rsdp) 421e1e9a4bfSMitsuru IWASAKI { 422e1e9a4bfSMitsuru IWASAKI int i, entries; 423a74172abSNate Lawson u_long addr; 424e1e9a4bfSMitsuru IWASAKI 425773b6454SNate Lawson printf(BEGIN_COMMENT); 426773b6454SNate Lawson acpi_print_sdt(rsdp); 427a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 428e1e9a4bfSMitsuru IWASAKI printf("\tEntries={ "); 429e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 430e1e9a4bfSMitsuru IWASAKI if (i > 0) 431e1e9a4bfSMitsuru IWASAKI printf(", "); 432a74172abSNate Lawson switch (addr_size) { 433a74172abSNate Lawson case 4: 434a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 435a74172abSNate Lawson break; 436a74172abSNate Lawson case 8: 437a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 438a74172abSNate Lawson break; 439a74172abSNate Lawson default: 440a74172abSNate Lawson addr = 0; 441a74172abSNate Lawson } 442a74172abSNate Lawson assert(addr != 0); 443a74172abSNate Lawson printf("0x%08lx", addr); 444e1e9a4bfSMitsuru IWASAKI } 445e1e9a4bfSMitsuru IWASAKI printf(" }\n"); 446c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 447e1e9a4bfSMitsuru IWASAKI } 448e1e9a4bfSMitsuru IWASAKI 4498e6a8737SNate Lawson static const char *acpi_pm_profiles[] = { 4508e6a8737SNate Lawson "Unspecified", "Desktop", "Mobile", "Workstation", 4518e6a8737SNate Lawson "Enterprise Server", "SOHO Server", "Appliance PC" 4528e6a8737SNate Lawson }; 4538e6a8737SNate Lawson 454945137d9SNate Lawson static void 4552177d4e6SNate Lawson acpi_print_fadt(struct ACPIsdt *sdp) 456e1e9a4bfSMitsuru IWASAKI { 4572177d4e6SNate Lawson struct FADTbody *fadt; 4588e6a8737SNate Lawson const char *pm; 459e1e9a4bfSMitsuru IWASAKI char sep; 460e1e9a4bfSMitsuru IWASAKI 4612177d4e6SNate Lawson fadt = (struct FADTbody *)sdp->body; 462c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 4632177d4e6SNate Lawson acpi_print_sdt(sdp); 4642177d4e6SNate Lawson printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->facs_ptr, 4658e6a8737SNate Lawson fadt->dsdt_ptr); 4668e6a8737SNate Lawson printf("\tINT_MODEL=%s\n", fadt->int_model ? "APIC" : "PIC"); 4678e6a8737SNate Lawson if (fadt->pm_profile >= sizeof(acpi_pm_profiles) / sizeof(char *)) 4688e6a8737SNate Lawson pm = "Reserved"; 4698e6a8737SNate Lawson else 4708e6a8737SNate Lawson pm = acpi_pm_profiles[fadt->pm_profile]; 4718e6a8737SNate Lawson printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->pm_profile); 4728e6a8737SNate Lawson printf("\tSCI_INT=%d\n", fadt->sci_int); 4738e6a8737SNate Lawson printf("\tSMI_CMD=0x%x, ", fadt->smi_cmd); 4748e6a8737SNate Lawson printf("ACPI_ENABLE=0x%x, ", fadt->acpi_enable); 4758e6a8737SNate Lawson printf("ACPI_DISABLE=0x%x, ", fadt->acpi_disable); 4768e6a8737SNate Lawson printf("S4BIOS_REQ=0x%x\n", fadt->s4biosreq); 4778e6a8737SNate Lawson printf("\tPSTATE_CNT=0x%x\n", fadt->pstate_cnt); 478e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", 4798e6a8737SNate Lawson fadt->pm1a_evt_blk, 4808e6a8737SNate Lawson fadt->pm1a_evt_blk + fadt->pm1_evt_len - 1); 4818e6a8737SNate Lawson if (fadt->pm1b_evt_blk != 0) 482e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", 4838e6a8737SNate Lawson fadt->pm1b_evt_blk, 4848e6a8737SNate Lawson fadt->pm1b_evt_blk + fadt->pm1_evt_len - 1); 485e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", 4868e6a8737SNate Lawson fadt->pm1a_cnt_blk, 4878e6a8737SNate Lawson fadt->pm1a_cnt_blk + fadt->pm1_cnt_len - 1); 4888e6a8737SNate Lawson if (fadt->pm1b_cnt_blk != 0) 489e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", 4908e6a8737SNate Lawson fadt->pm1b_cnt_blk, 4918e6a8737SNate Lawson fadt->pm1b_cnt_blk + fadt->pm1_cnt_len - 1); 4928e6a8737SNate Lawson if (fadt->pm2_cnt_blk != 0) 493e1e9a4bfSMitsuru IWASAKI printf("\tPM2_CNT_BLK=0x%x-0x%x\n", 4948e6a8737SNate Lawson fadt->pm2_cnt_blk, 4958e6a8737SNate Lawson fadt->pm2_cnt_blk + fadt->pm2_cnt_len - 1); 496c08c4e81SNate Lawson printf("\tPM_TMR_BLK=0x%x-0x%x\n", 4978e6a8737SNate Lawson fadt->pm_tmr_blk, 4988e6a8737SNate Lawson fadt->pm_tmr_blk + fadt->pm_tmr_len - 1); 4998e6a8737SNate Lawson if (fadt->gpe0_blk != 0) 5008e6a8737SNate Lawson printf("\tGPE0_BLK=0x%x-0x%x\n", 5018e6a8737SNate Lawson fadt->gpe0_blk, 5028e6a8737SNate Lawson fadt->gpe0_blk + fadt->gpe0_len - 1); 5038e6a8737SNate Lawson if (fadt->gpe1_blk != 0) 5048e6a8737SNate Lawson printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", 5058e6a8737SNate Lawson fadt->gpe1_blk, 5068e6a8737SNate Lawson fadt->gpe1_blk + fadt->gpe1_len - 1, 5078e6a8737SNate Lawson fadt->gpe1_base); 5088e6a8737SNate Lawson if (fadt->cst_cnt != 0) 5098e6a8737SNate Lawson printf("\tCST_CNT=0x%x\n", fadt->cst_cnt); 51051c1824fSNate Lawson printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", 5118e6a8737SNate Lawson fadt->p_lvl2_lat, fadt->p_lvl3_lat); 512e1e9a4bfSMitsuru IWASAKI printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", 5138e6a8737SNate Lawson fadt->flush_size, fadt->flush_stride); 514e1e9a4bfSMitsuru IWASAKI printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", 5158e6a8737SNate Lawson fadt->duty_off, fadt->duty_width); 516e1e9a4bfSMitsuru IWASAKI printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", 5178e6a8737SNate Lawson fadt->day_alrm, fadt->mon_alrm, fadt->century); 518e1e9a4bfSMitsuru IWASAKI 5198e6a8737SNate Lawson #define PRINTFLAG(var, flag) do { \ 5208e6a8737SNate Lawson if ((var) & FADT_FLAG_## flag) { \ 5218e6a8737SNate Lawson printf("%c%s", sep, #flag); sep = ','; \ 522e1e9a4bfSMitsuru IWASAKI } \ 523e1e9a4bfSMitsuru IWASAKI } while (0) 524e1e9a4bfSMitsuru IWASAKI 5258e6a8737SNate Lawson printf("\tIAPC_BOOT_ARCH="); 5268e6a8737SNate Lawson sep = '{'; 5278e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, LEGACY_DEV); 5288e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, 8042); 52969a9febdSNate Lawson if (fadt->iapc_boot_arch != 0) 5304e36f5a1SNate Lawson printf("}"); 5314e36f5a1SNate Lawson printf("\n"); 5328e6a8737SNate Lawson 5338e6a8737SNate Lawson printf("\tFlags="); 5348e6a8737SNate Lawson sep = '{'; 5358e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD); 5368e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD_FLUSH); 5378e6a8737SNate Lawson PRINTFLAG(fadt->flags, PROC_C1); 5388e6a8737SNate Lawson PRINTFLAG(fadt->flags, P_LVL2_UP); 5398e6a8737SNate Lawson PRINTFLAG(fadt->flags, PWR_BUTTON); 5408e6a8737SNate Lawson PRINTFLAG(fadt->flags, SLP_BUTTON); 5418e6a8737SNate Lawson PRINTFLAG(fadt->flags, FIX_RTC); 5428e6a8737SNate Lawson PRINTFLAG(fadt->flags, RTC_S4); 5438e6a8737SNate Lawson PRINTFLAG(fadt->flags, TMR_VAL_EXT); 5448e6a8737SNate Lawson PRINTFLAG(fadt->flags, DCK_CAP); 5458e6a8737SNate Lawson PRINTFLAG(fadt->flags, RESET_REG); 5468e6a8737SNate Lawson PRINTFLAG(fadt->flags, SEALED_CASE); 5478e6a8737SNate Lawson PRINTFLAG(fadt->flags, HEADLESS); 5488e6a8737SNate Lawson PRINTFLAG(fadt->flags, CPU_SW_SLP); 54969a9febdSNate Lawson if (fadt->flags != 0) 5508e6a8737SNate Lawson printf("}\n"); 551e1e9a4bfSMitsuru IWASAKI 552e1e9a4bfSMitsuru IWASAKI #undef PRINTFLAG 553e1e9a4bfSMitsuru IWASAKI 5548e6a8737SNate Lawson if (fadt->flags & FADT_FLAG_RESET_REG) { 5558e6a8737SNate Lawson printf("\tRESET_REG="); 5568e6a8737SNate Lawson acpi_print_gas(&fadt->reset_reg); 5578e6a8737SNate Lawson printf(", RESET_VALUE=%#x\n", fadt->reset_value); 5588e6a8737SNate Lawson } 559c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) > 1) { 560773b6454SNate Lawson printf("\tX_FACS=0x%08lx, ", (u_long)fadt->x_facs_ptr); 561773b6454SNate Lawson printf("X_DSDT=0x%08lx\n", (u_long)fadt->x_dsdt_ptr); 562c08c4e81SNate Lawson printf("\tX_PM1a_EVT_BLK="); 563773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_evt_blk); 564c08c4e81SNate Lawson if (fadt->x_pm1b_evt_blk.address != 0) { 565c08c4e81SNate Lawson printf("\n\tX_PM1b_EVT_BLK="); 566773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_evt_blk); 567c08c4e81SNate Lawson } 568c08c4e81SNate Lawson printf("\n\tX_PM1a_CNT_BLK="); 569773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_cnt_blk); 570c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 571c08c4e81SNate Lawson printf("\n\tX_PM1b_CNT_BLK="); 572773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_cnt_blk); 573c08c4e81SNate Lawson } 574c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 575773b6454SNate Lawson printf("\n\tX_PM2_CNT_BLK="); 576773b6454SNate Lawson acpi_print_gas(&fadt->x_pm2_cnt_blk); 577c08c4e81SNate Lawson } 578773b6454SNate Lawson printf("\n\tX_PM_TMR_BLK="); 579773b6454SNate Lawson acpi_print_gas(&fadt->x_pm_tmr_blk); 580c08c4e81SNate Lawson if (fadt->x_gpe0_blk.address != 0) { 581773b6454SNate Lawson printf("\n\tX_GPE0_BLK="); 582773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe0_blk); 583c08c4e81SNate Lawson } 584c08c4e81SNate Lawson if (fadt->x_gpe1_blk.address != 0) { 585773b6454SNate Lawson printf("\n\tX_GPE1_BLK="); 586773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe1_blk); 587c08c4e81SNate Lawson } 588773b6454SNate Lawson printf("\n"); 589773b6454SNate Lawson } 5908e6a8737SNate Lawson 5918e6a8737SNate Lawson printf(END_COMMENT); 5928e6a8737SNate Lawson } 5938e6a8737SNate Lawson 5948e6a8737SNate Lawson static void 5958e6a8737SNate Lawson acpi_print_facs(struct FACSbody *facs) 5968e6a8737SNate Lawson { 5978e6a8737SNate Lawson printf(BEGIN_COMMENT); 5988e6a8737SNate Lawson printf(" FACS:\tLength=%u, ", facs->len); 5998e6a8737SNate Lawson printf("HwSig=0x%08x, ", facs->hw_sig); 6008e6a8737SNate Lawson printf("Firm_Wake_Vec=0x%08x\n", facs->firm_wake_vec); 6018e6a8737SNate Lawson 602773b6454SNate Lawson printf("\tGlobal_Lock="); 6038e6a8737SNate Lawson if (facs->global_lock != 0) { 6048e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_PENDING) 6058e6a8737SNate Lawson printf("PENDING,"); 6068e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_OWNED) 6078e6a8737SNate Lawson printf("OWNED"); 6088e6a8737SNate Lawson } 609773b6454SNate Lawson printf("\n"); 6108e6a8737SNate Lawson 611773b6454SNate Lawson printf("\tFlags="); 6128e6a8737SNate Lawson if (facs->flags & FACS_FLAG_S4BIOS_F) 6138e6a8737SNate Lawson printf("S4BIOS"); 614773b6454SNate Lawson printf("\n"); 6158e6a8737SNate Lawson 6168e6a8737SNate Lawson if (facs->x_firm_wake_vec != 0) { 6178e6a8737SNate Lawson printf("\tX_Firm_Wake_Vec=%08lx\n", 6188e6a8737SNate Lawson (u_long)facs->x_firm_wake_vec); 6198e6a8737SNate Lawson } 620773b6454SNate Lawson printf("\tVersion=%u\n", facs->version); 6218e6a8737SNate Lawson 622c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 623e1e9a4bfSMitsuru IWASAKI } 624e1e9a4bfSMitsuru IWASAKI 625945137d9SNate Lawson static void 626e1e9a4bfSMitsuru IWASAKI acpi_print_dsdt(struct ACPIsdt *dsdp) 627e1e9a4bfSMitsuru IWASAKI { 628773b6454SNate Lawson printf(BEGIN_COMMENT); 629773b6454SNate Lawson acpi_print_sdt(dsdp); 630773b6454SNate Lawson printf(END_COMMENT); 631e1e9a4bfSMitsuru IWASAKI } 632e1e9a4bfSMitsuru IWASAKI 633e1e9a4bfSMitsuru IWASAKI int 634e1e9a4bfSMitsuru IWASAKI acpi_checksum(void *p, size_t length) 635e1e9a4bfSMitsuru IWASAKI { 636e1e9a4bfSMitsuru IWASAKI u_int8_t *bp; 637e1e9a4bfSMitsuru IWASAKI u_int8_t sum; 638e1e9a4bfSMitsuru IWASAKI 639e1e9a4bfSMitsuru IWASAKI bp = p; 640e1e9a4bfSMitsuru IWASAKI sum = 0; 641e1e9a4bfSMitsuru IWASAKI while (length--) 642e1e9a4bfSMitsuru IWASAKI sum += *bp++; 643e1e9a4bfSMitsuru IWASAKI 644e1e9a4bfSMitsuru IWASAKI return (sum); 645e1e9a4bfSMitsuru IWASAKI } 646e1e9a4bfSMitsuru IWASAKI 647945137d9SNate Lawson static struct ACPIsdt * 648e1e9a4bfSMitsuru IWASAKI acpi_map_sdt(vm_offset_t pa) 649e1e9a4bfSMitsuru IWASAKI { 650e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sp; 651e1e9a4bfSMitsuru IWASAKI 652e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); 653e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sp->len); 654e1e9a4bfSMitsuru IWASAKI return (sp); 655e1e9a4bfSMitsuru IWASAKI } 656e1e9a4bfSMitsuru IWASAKI 657945137d9SNate Lawson static void 658e1e9a4bfSMitsuru IWASAKI acpi_print_rsd_ptr(struct ACPIrsdp *rp) 659e1e9a4bfSMitsuru IWASAKI { 660c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 661a74172abSNate Lawson printf(" RSD PTR: OEM="); 662e1e9a4bfSMitsuru IWASAKI acpi_print_string(rp->oem, 6); 663773b6454SNate Lawson printf(", ACPI_Rev=%s (%d)\n", rp->revision < 2 ? "1.0x" : "2.0x", 664a74172abSNate Lawson rp->revision); 665a74172abSNate Lawson if (rp->revision < 2) { 666a74172abSNate Lawson printf("\tRSDT=0x%08x, cksum=%u\n", rp->rsdt_addr, rp->sum); 667a74172abSNate Lawson } else { 668a74172abSNate Lawson printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", 669a74172abSNate Lawson (u_long)rp->xsdt_addr, rp->length, rp->xsum); 670a74172abSNate Lawson } 671c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 672e1e9a4bfSMitsuru IWASAKI } 673e1e9a4bfSMitsuru IWASAKI 674945137d9SNate Lawson static void 675e1e9a4bfSMitsuru IWASAKI acpi_handle_rsdt(struct ACPIsdt *rsdp) 676e1e9a4bfSMitsuru IWASAKI { 677e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sdp; 678a74172abSNate Lawson vm_offset_t addr; 679a74172abSNate Lawson int entries, i; 680e1e9a4bfSMitsuru IWASAKI 681e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(rsdp); 682a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 683e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 684a74172abSNate Lawson switch (addr_size) { 685a74172abSNate Lawson case 4: 686a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 687a74172abSNate Lawson break; 688a74172abSNate Lawson case 8: 689a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 690a74172abSNate Lawson break; 691a74172abSNate Lawson default: 692a74172abSNate Lawson assert((addr = 0)); 693a74172abSNate Lawson } 694a74172abSNate Lawson 695a74172abSNate Lawson sdp = (struct ACPIsdt *)acpi_map_sdt(addr); 6965cf6d493SNate Lawson if (acpi_checksum(sdp, sdp->len)) { 6975cf6d493SNate Lawson warnx("RSDT entry %d (sig %.4s) is corrupt", i, 6985cf6d493SNate Lawson sdp->signature); 6995cf6d493SNate Lawson continue; 7005cf6d493SNate Lawson } 701945137d9SNate Lawson if (!memcmp(sdp->signature, "FACP", 4)) 7022177d4e6SNate Lawson acpi_handle_fadt(sdp); 703945137d9SNate Lawson else if (!memcmp(sdp->signature, "APIC", 4)) 7040a473124SJohn Baldwin acpi_handle_apic(sdp); 705945137d9SNate Lawson else if (!memcmp(sdp->signature, "HPET", 4)) 70679d7565cSPeter Wemm acpi_handle_hpet(sdp); 70755d7ff9eSNate Lawson else if (!memcmp(sdp->signature, "ECDT", 4)) 70855d7ff9eSNate Lawson acpi_handle_ecdt(sdp); 709a47e681bSScott Long else if (!memcmp(sdp->signature, "MCFG", 4)) 710a47e681bSScott Long acpi_handle_mcfg(sdp); 711773b6454SNate Lawson else { 712773b6454SNate Lawson printf(BEGIN_COMMENT); 713773b6454SNate Lawson acpi_print_sdt(sdp); 714773b6454SNate Lawson printf(END_COMMENT); 715773b6454SNate Lawson } 716e1e9a4bfSMitsuru IWASAKI } 717e1e9a4bfSMitsuru IWASAKI } 718c62f1cccSMitsuru IWASAKI 719945137d9SNate Lawson struct ACPIsdt * 720476daaecSDag-Erling Smørgrav sdt_load_devmem(void) 721945137d9SNate Lawson { 722945137d9SNate Lawson struct ACPIrsdp *rp; 723945137d9SNate Lawson struct ACPIsdt *rsdp; 724945137d9SNate Lawson 725945137d9SNate Lawson rp = acpi_find_rsd_ptr(); 726945137d9SNate Lawson if (!rp) 727945137d9SNate Lawson errx(1, "Can't find ACPI information"); 728945137d9SNate Lawson 729945137d9SNate Lawson if (tflag) 730945137d9SNate Lawson acpi_print_rsd_ptr(rp); 731a74172abSNate Lawson if (rp->revision < 2) { 732945137d9SNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->rsdt_addr); 733945137d9SNate Lawson if (memcmp(rsdp->signature, "RSDT", 4) != 0 || 734945137d9SNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 735945137d9SNate Lawson errx(1, "RSDT is corrupted"); 736a74172abSNate Lawson addr_size = sizeof(uint32_t); 737a74172abSNate Lawson } else { 738a74172abSNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->xsdt_addr); 739a74172abSNate Lawson if (memcmp(rsdp->signature, "XSDT", 4) != 0 || 740a74172abSNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 741a74172abSNate Lawson errx(1, "XSDT is corrupted"); 742a74172abSNate Lawson addr_size = sizeof(uint64_t); 743a74172abSNate Lawson } 744945137d9SNate Lawson return (rsdp); 745945137d9SNate Lawson } 746c62f1cccSMitsuru IWASAKI 74762c7bde1SNate Lawson /* Write the DSDT to a file, concatenating any SSDTs (if present). */ 748bfa3f012SMarcel Moolenaar static int 749bfa3f012SMarcel Moolenaar write_dsdt(int fd, struct ACPIsdt *rsdt, struct ACPIsdt *dsdt) 750bfa3f012SMarcel Moolenaar { 751bfa3f012SMarcel Moolenaar struct ACPIsdt sdt; 752bfa3f012SMarcel Moolenaar struct ACPIsdt *ssdt; 753bfa3f012SMarcel Moolenaar uint8_t sum; 754bfa3f012SMarcel Moolenaar 75562c7bde1SNate Lawson /* Create a new checksum to account for the DSDT and any SSDTs. */ 756bfa3f012SMarcel Moolenaar sdt = *dsdt; 757bfa3f012SMarcel Moolenaar if (rsdt != NULL) { 758bfa3f012SMarcel Moolenaar sdt.check = 0; 759bfa3f012SMarcel Moolenaar sum = acpi_checksum(dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 760bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 761f7675a56SNate Lawson while (ssdt != NULL) { 762bfa3f012SMarcel Moolenaar sdt.len += ssdt->len - SIZEOF_SDT_HDR; 763bfa3f012SMarcel Moolenaar sum += acpi_checksum(ssdt->body, 764bfa3f012SMarcel Moolenaar ssdt->len - SIZEOF_SDT_HDR); 765bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 766bfa3f012SMarcel Moolenaar } 767bfa3f012SMarcel Moolenaar sum += acpi_checksum(&sdt, SIZEOF_SDT_HDR); 768bfa3f012SMarcel Moolenaar sdt.check -= sum; 769bfa3f012SMarcel Moolenaar } 77062c7bde1SNate Lawson 77162c7bde1SNate Lawson /* Write out the DSDT header and body. */ 772bfa3f012SMarcel Moolenaar write(fd, &sdt, SIZEOF_SDT_HDR); 773bfa3f012SMarcel Moolenaar write(fd, dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 77462c7bde1SNate Lawson 775b64e1b67SNate Lawson /* Write out any SSDTs (if present.) */ 776f7675a56SNate Lawson if (rsdt != NULL) { 777bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 778bfa3f012SMarcel Moolenaar while (ssdt != NULL) { 779bfa3f012SMarcel Moolenaar write(fd, ssdt->body, ssdt->len - SIZEOF_SDT_HDR); 780bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 781bfa3f012SMarcel Moolenaar } 782bfa3f012SMarcel Moolenaar } 783bfa3f012SMarcel Moolenaar return (0); 784bfa3f012SMarcel Moolenaar } 785bfa3f012SMarcel Moolenaar 786c62f1cccSMitsuru IWASAKI void 787bfa3f012SMarcel Moolenaar dsdt_save_file(char *outfile, struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 788c62f1cccSMitsuru IWASAKI { 789945137d9SNate Lawson int fd; 790945137d9SNate Lawson mode_t mode; 791945137d9SNate Lawson 792945137d9SNate Lawson assert(outfile != NULL); 793945137d9SNate Lawson mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 794945137d9SNate Lawson fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); 795945137d9SNate Lawson if (fd == -1) { 796945137d9SNate Lawson perror("dsdt_save_file"); 797945137d9SNate Lawson return; 798945137d9SNate Lawson } 799bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 800945137d9SNate Lawson close(fd); 801c62f1cccSMitsuru IWASAKI } 802c62f1cccSMitsuru IWASAKI 803945137d9SNate Lawson void 804bfa3f012SMarcel Moolenaar aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 805c62f1cccSMitsuru IWASAKI { 806945137d9SNate Lawson char tmpstr[32], buf[256]; 807945137d9SNate Lawson FILE *fp; 808945137d9SNate Lawson int fd, len; 809945137d9SNate Lawson 810945137d9SNate Lawson strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); 811945137d9SNate Lawson fd = mkstemp(tmpstr); 812945137d9SNate Lawson if (fd < 0) { 813945137d9SNate Lawson perror("iasl tmp file"); 814945137d9SNate Lawson return; 815c62f1cccSMitsuru IWASAKI } 816bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 817945137d9SNate Lawson close(fd); 818945137d9SNate Lawson 819945137d9SNate Lawson /* Run iasl -d on the temp file */ 820945137d9SNate Lawson if (fork() == 0) { 821945137d9SNate Lawson close(STDOUT_FILENO); 822945137d9SNate Lawson if (vflag == 0) 823945137d9SNate Lawson close(STDERR_FILENO); 824945137d9SNate Lawson execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, 0); 825945137d9SNate Lawson err(1, "exec"); 826c62f1cccSMitsuru IWASAKI } 827c62f1cccSMitsuru IWASAKI 828945137d9SNate Lawson wait(NULL); 829945137d9SNate Lawson unlink(tmpstr); 830945137d9SNate Lawson 831945137d9SNate Lawson /* Dump iasl's output to stdout */ 832945137d9SNate Lawson fp = fopen("acpidump.dsl", "r"); 833945137d9SNate Lawson unlink("acpidump.dsl"); 834945137d9SNate Lawson if (fp == NULL) { 835945137d9SNate Lawson perror("iasl tmp file (read)"); 836945137d9SNate Lawson return; 837945137d9SNate Lawson } 838945137d9SNate Lawson while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 839945137d9SNate Lawson fwrite(buf, 1, len, stdout); 840945137d9SNate Lawson fclose(fp); 841c62f1cccSMitsuru IWASAKI } 842c62f1cccSMitsuru IWASAKI 843945137d9SNate Lawson void 844945137d9SNate Lawson sdt_print_all(struct ACPIsdt *rsdp) 845c62f1cccSMitsuru IWASAKI { 846945137d9SNate Lawson acpi_handle_rsdt(rsdp); 847c62f1cccSMitsuru IWASAKI } 848c62f1cccSMitsuru IWASAKI 849bfa3f012SMarcel Moolenaar /* Fetch a table matching the given signature via the RSDT. */ 850945137d9SNate Lawson struct ACPIsdt * 851bfa3f012SMarcel Moolenaar sdt_from_rsdt(struct ACPIsdt *rsdt, const char *sig, struct ACPIsdt *last) 852c62f1cccSMitsuru IWASAKI { 853945137d9SNate Lawson struct ACPIsdt *sdt; 854a74172abSNate Lawson vm_offset_t addr; 855a74172abSNate Lawson int entries, i; 856945137d9SNate Lawson 857a74172abSNate Lawson entries = (rsdt->len - SIZEOF_SDT_HDR) / addr_size; 858945137d9SNate Lawson for (i = 0; i < entries; i++) { 859a74172abSNate Lawson switch (addr_size) { 860a74172abSNate Lawson case 4: 861a74172abSNate Lawson addr = le32dec((char*)rsdt->body + i * addr_size); 862a74172abSNate Lawson break; 863a74172abSNate Lawson case 8: 864a74172abSNate Lawson addr = le64dec((char*)rsdt->body + i * addr_size); 865a74172abSNate Lawson break; 866a74172abSNate Lawson default: 867a74172abSNate Lawson assert((addr = 0)); 868a74172abSNate Lawson } 869a74172abSNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(addr); 870bfa3f012SMarcel Moolenaar if (last != NULL) { 871bfa3f012SMarcel Moolenaar if (sdt == last) 872bfa3f012SMarcel Moolenaar last = NULL; 873bfa3f012SMarcel Moolenaar continue; 874bfa3f012SMarcel Moolenaar } 875a74172abSNate Lawson if (memcmp(sdt->signature, sig, strlen(sig))) 876a74172abSNate Lawson continue; 877945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 878945137d9SNate Lawson errx(1, "RSDT entry %d is corrupt", i); 879945137d9SNate Lawson return (sdt); 880c62f1cccSMitsuru IWASAKI } 881c62f1cccSMitsuru IWASAKI 882945137d9SNate Lawson return (NULL); 883c62f1cccSMitsuru IWASAKI } 884c62f1cccSMitsuru IWASAKI 885945137d9SNate Lawson struct ACPIsdt * 8868e6a8737SNate Lawson dsdt_from_fadt(struct FADTbody *fadt) 887c62f1cccSMitsuru IWASAKI { 888945137d9SNate Lawson struct ACPIsdt *sdt; 889c62f1cccSMitsuru IWASAKI 890c83f0f99SNate Lawson /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */ 891c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) == 1) 8928e6a8737SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 8932e71eb12SNate Lawson else 8942e71eb12SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr); 895945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 896945137d9SNate Lawson errx(1, "DSDT is corrupt\n"); 897945137d9SNate Lawson return (sdt); 898c62f1cccSMitsuru IWASAKI } 899