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 380773b6454SNate Lawson acpi_print_sdt(struct ACPIsdt *sdp) 381c62f1cccSMitsuru IWASAKI { 382773b6454SNate Lawson printf(" "); 383e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->signature, 4); 384c62f1cccSMitsuru IWASAKI printf(": Length=%d, Revision=%d, Checksum=%d,\n", 385e1e9a4bfSMitsuru IWASAKI sdp->len, sdp->rev, sdp->check); 386e1e9a4bfSMitsuru IWASAKI printf("\tOEMID="); 387e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemid, 6); 388e1e9a4bfSMitsuru IWASAKI printf(", OEM Table ID="); 389e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemtblid, 8); 390e1e9a4bfSMitsuru IWASAKI printf(", OEM Revision=0x%x,\n", sdp->oemrev); 391e1e9a4bfSMitsuru IWASAKI printf("\tCreator ID="); 392e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->creator, 4); 393e1e9a4bfSMitsuru IWASAKI printf(", Creator Revision=0x%x\n", sdp->crerev); 394e1e9a4bfSMitsuru IWASAKI } 395e1e9a4bfSMitsuru IWASAKI 396945137d9SNate Lawson static void 397e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(struct ACPIsdt *rsdp) 398e1e9a4bfSMitsuru IWASAKI { 399e1e9a4bfSMitsuru IWASAKI int i, entries; 400a74172abSNate Lawson u_long addr; 401e1e9a4bfSMitsuru IWASAKI 402773b6454SNate Lawson printf(BEGIN_COMMENT); 403773b6454SNate Lawson acpi_print_sdt(rsdp); 404a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 405e1e9a4bfSMitsuru IWASAKI printf("\tEntries={ "); 406e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 407e1e9a4bfSMitsuru IWASAKI if (i > 0) 408e1e9a4bfSMitsuru IWASAKI printf(", "); 409a74172abSNate Lawson switch (addr_size) { 410a74172abSNate Lawson case 4: 411a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 412a74172abSNate Lawson break; 413a74172abSNate Lawson case 8: 414a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 415a74172abSNate Lawson break; 416a74172abSNate Lawson default: 417a74172abSNate Lawson addr = 0; 418a74172abSNate Lawson } 419a74172abSNate Lawson assert(addr != 0); 420a74172abSNate Lawson printf("0x%08lx", addr); 421e1e9a4bfSMitsuru IWASAKI } 422e1e9a4bfSMitsuru IWASAKI printf(" }\n"); 423c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 424e1e9a4bfSMitsuru IWASAKI } 425e1e9a4bfSMitsuru IWASAKI 4268e6a8737SNate Lawson static const char *acpi_pm_profiles[] = { 4278e6a8737SNate Lawson "Unspecified", "Desktop", "Mobile", "Workstation", 4288e6a8737SNate Lawson "Enterprise Server", "SOHO Server", "Appliance PC" 4298e6a8737SNate Lawson }; 4308e6a8737SNate Lawson 431945137d9SNate Lawson static void 4322177d4e6SNate Lawson acpi_print_fadt(struct ACPIsdt *sdp) 433e1e9a4bfSMitsuru IWASAKI { 4342177d4e6SNate Lawson struct FADTbody *fadt; 4358e6a8737SNate Lawson const char *pm; 436e1e9a4bfSMitsuru IWASAKI char sep; 437e1e9a4bfSMitsuru IWASAKI 4382177d4e6SNate Lawson fadt = (struct FADTbody *)sdp->body; 439c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 4402177d4e6SNate Lawson acpi_print_sdt(sdp); 4412177d4e6SNate Lawson printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->facs_ptr, 4428e6a8737SNate Lawson fadt->dsdt_ptr); 4438e6a8737SNate Lawson printf("\tINT_MODEL=%s\n", fadt->int_model ? "APIC" : "PIC"); 4448e6a8737SNate Lawson if (fadt->pm_profile >= sizeof(acpi_pm_profiles) / sizeof(char *)) 4458e6a8737SNate Lawson pm = "Reserved"; 4468e6a8737SNate Lawson else 4478e6a8737SNate Lawson pm = acpi_pm_profiles[fadt->pm_profile]; 4488e6a8737SNate Lawson printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->pm_profile); 4498e6a8737SNate Lawson printf("\tSCI_INT=%d\n", fadt->sci_int); 4508e6a8737SNate Lawson printf("\tSMI_CMD=0x%x, ", fadt->smi_cmd); 4518e6a8737SNate Lawson printf("ACPI_ENABLE=0x%x, ", fadt->acpi_enable); 4528e6a8737SNate Lawson printf("ACPI_DISABLE=0x%x, ", fadt->acpi_disable); 4538e6a8737SNate Lawson printf("S4BIOS_REQ=0x%x\n", fadt->s4biosreq); 4548e6a8737SNate Lawson printf("\tPSTATE_CNT=0x%x\n", fadt->pstate_cnt); 455e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", 4568e6a8737SNate Lawson fadt->pm1a_evt_blk, 4578e6a8737SNate Lawson fadt->pm1a_evt_blk + fadt->pm1_evt_len - 1); 4588e6a8737SNate Lawson if (fadt->pm1b_evt_blk != 0) 459e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", 4608e6a8737SNate Lawson fadt->pm1b_evt_blk, 4618e6a8737SNate Lawson fadt->pm1b_evt_blk + fadt->pm1_evt_len - 1); 462e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", 4638e6a8737SNate Lawson fadt->pm1a_cnt_blk, 4648e6a8737SNate Lawson fadt->pm1a_cnt_blk + fadt->pm1_cnt_len - 1); 4658e6a8737SNate Lawson if (fadt->pm1b_cnt_blk != 0) 466e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", 4678e6a8737SNate Lawson fadt->pm1b_cnt_blk, 4688e6a8737SNate Lawson fadt->pm1b_cnt_blk + fadt->pm1_cnt_len - 1); 4698e6a8737SNate Lawson if (fadt->pm2_cnt_blk != 0) 470e1e9a4bfSMitsuru IWASAKI printf("\tPM2_CNT_BLK=0x%x-0x%x\n", 4718e6a8737SNate Lawson fadt->pm2_cnt_blk, 4728e6a8737SNate Lawson fadt->pm2_cnt_blk + fadt->pm2_cnt_len - 1); 473c08c4e81SNate Lawson printf("\tPM_TMR_BLK=0x%x-0x%x\n", 4748e6a8737SNate Lawson fadt->pm_tmr_blk, 4758e6a8737SNate Lawson fadt->pm_tmr_blk + fadt->pm_tmr_len - 1); 4768e6a8737SNate Lawson if (fadt->gpe0_blk != 0) 4778e6a8737SNate Lawson printf("\tGPE0_BLK=0x%x-0x%x\n", 4788e6a8737SNate Lawson fadt->gpe0_blk, 4798e6a8737SNate Lawson fadt->gpe0_blk + fadt->gpe0_len - 1); 4808e6a8737SNate Lawson if (fadt->gpe1_blk != 0) 4818e6a8737SNate Lawson printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", 4828e6a8737SNate Lawson fadt->gpe1_blk, 4838e6a8737SNate Lawson fadt->gpe1_blk + fadt->gpe1_len - 1, 4848e6a8737SNate Lawson fadt->gpe1_base); 4858e6a8737SNate Lawson if (fadt->cst_cnt != 0) 4868e6a8737SNate Lawson printf("\tCST_CNT=0x%x\n", fadt->cst_cnt); 48751c1824fSNate Lawson printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", 4888e6a8737SNate Lawson fadt->p_lvl2_lat, fadt->p_lvl3_lat); 489e1e9a4bfSMitsuru IWASAKI printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", 4908e6a8737SNate Lawson fadt->flush_size, fadt->flush_stride); 491e1e9a4bfSMitsuru IWASAKI printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", 4928e6a8737SNate Lawson fadt->duty_off, fadt->duty_width); 493e1e9a4bfSMitsuru IWASAKI printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", 4948e6a8737SNate Lawson fadt->day_alrm, fadt->mon_alrm, fadt->century); 495e1e9a4bfSMitsuru IWASAKI 4968e6a8737SNate Lawson #define PRINTFLAG(var, flag) do { \ 4978e6a8737SNate Lawson if ((var) & FADT_FLAG_## flag) { \ 4988e6a8737SNate Lawson printf("%c%s", sep, #flag); sep = ','; \ 499e1e9a4bfSMitsuru IWASAKI } \ 500e1e9a4bfSMitsuru IWASAKI } while (0) 501e1e9a4bfSMitsuru IWASAKI 5028e6a8737SNate Lawson printf("\tIAPC_BOOT_ARCH="); 5038e6a8737SNate Lawson sep = '{'; 5048e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, LEGACY_DEV); 5058e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, 8042); 50669a9febdSNate Lawson if (fadt->iapc_boot_arch != 0) 5074e36f5a1SNate Lawson printf("}"); 5084e36f5a1SNate Lawson printf("\n"); 5098e6a8737SNate Lawson 5108e6a8737SNate Lawson printf("\tFlags="); 5118e6a8737SNate Lawson sep = '{'; 5128e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD); 5138e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD_FLUSH); 5148e6a8737SNate Lawson PRINTFLAG(fadt->flags, PROC_C1); 5158e6a8737SNate Lawson PRINTFLAG(fadt->flags, P_LVL2_UP); 5168e6a8737SNate Lawson PRINTFLAG(fadt->flags, PWR_BUTTON); 5178e6a8737SNate Lawson PRINTFLAG(fadt->flags, SLP_BUTTON); 5188e6a8737SNate Lawson PRINTFLAG(fadt->flags, FIX_RTC); 5198e6a8737SNate Lawson PRINTFLAG(fadt->flags, RTC_S4); 5208e6a8737SNate Lawson PRINTFLAG(fadt->flags, TMR_VAL_EXT); 5218e6a8737SNate Lawson PRINTFLAG(fadt->flags, DCK_CAP); 5228e6a8737SNate Lawson PRINTFLAG(fadt->flags, RESET_REG); 5238e6a8737SNate Lawson PRINTFLAG(fadt->flags, SEALED_CASE); 5248e6a8737SNate Lawson PRINTFLAG(fadt->flags, HEADLESS); 5258e6a8737SNate Lawson PRINTFLAG(fadt->flags, CPU_SW_SLP); 52669a9febdSNate Lawson if (fadt->flags != 0) 5278e6a8737SNate Lawson printf("}\n"); 528e1e9a4bfSMitsuru IWASAKI 529e1e9a4bfSMitsuru IWASAKI #undef PRINTFLAG 530e1e9a4bfSMitsuru IWASAKI 5318e6a8737SNate Lawson if (fadt->flags & FADT_FLAG_RESET_REG) { 5328e6a8737SNate Lawson printf("\tRESET_REG="); 5338e6a8737SNate Lawson acpi_print_gas(&fadt->reset_reg); 5348e6a8737SNate Lawson printf(", RESET_VALUE=%#x\n", fadt->reset_value); 5358e6a8737SNate Lawson } 536c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) > 1) { 537773b6454SNate Lawson printf("\tX_FACS=0x%08lx, ", (u_long)fadt->x_facs_ptr); 538773b6454SNate Lawson printf("X_DSDT=0x%08lx\n", (u_long)fadt->x_dsdt_ptr); 539c08c4e81SNate Lawson printf("\tX_PM1a_EVT_BLK="); 540773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_evt_blk); 541c08c4e81SNate Lawson if (fadt->x_pm1b_evt_blk.address != 0) { 542c08c4e81SNate Lawson printf("\n\tX_PM1b_EVT_BLK="); 543773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_evt_blk); 544c08c4e81SNate Lawson } 545c08c4e81SNate Lawson printf("\n\tX_PM1a_CNT_BLK="); 546773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_cnt_blk); 547c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 548c08c4e81SNate Lawson printf("\n\tX_PM1b_CNT_BLK="); 549773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_cnt_blk); 550c08c4e81SNate Lawson } 551c08c4e81SNate Lawson if (fadt->x_pm1b_cnt_blk.address != 0) { 552773b6454SNate Lawson printf("\n\tX_PM2_CNT_BLK="); 553773b6454SNate Lawson acpi_print_gas(&fadt->x_pm2_cnt_blk); 554c08c4e81SNate Lawson } 555773b6454SNate Lawson printf("\n\tX_PM_TMR_BLK="); 556773b6454SNate Lawson acpi_print_gas(&fadt->x_pm_tmr_blk); 557c08c4e81SNate Lawson if (fadt->x_gpe0_blk.address != 0) { 558773b6454SNate Lawson printf("\n\tX_GPE0_BLK="); 559773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe0_blk); 560c08c4e81SNate Lawson } 561c08c4e81SNate Lawson if (fadt->x_gpe1_blk.address != 0) { 562773b6454SNate Lawson printf("\n\tX_GPE1_BLK="); 563773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe1_blk); 564c08c4e81SNate Lawson } 565773b6454SNate Lawson printf("\n"); 566773b6454SNate Lawson } 5678e6a8737SNate Lawson 5688e6a8737SNate Lawson printf(END_COMMENT); 5698e6a8737SNate Lawson } 5708e6a8737SNate Lawson 5718e6a8737SNate Lawson static void 5728e6a8737SNate Lawson acpi_print_facs(struct FACSbody *facs) 5738e6a8737SNate Lawson { 5748e6a8737SNate Lawson printf(BEGIN_COMMENT); 5758e6a8737SNate Lawson printf(" FACS:\tLength=%u, ", facs->len); 5768e6a8737SNate Lawson printf("HwSig=0x%08x, ", facs->hw_sig); 5778e6a8737SNate Lawson printf("Firm_Wake_Vec=0x%08x\n", facs->firm_wake_vec); 5788e6a8737SNate Lawson 579773b6454SNate Lawson printf("\tGlobal_Lock="); 5808e6a8737SNate Lawson if (facs->global_lock != 0) { 5818e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_PENDING) 5828e6a8737SNate Lawson printf("PENDING,"); 5838e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_OWNED) 5848e6a8737SNate Lawson printf("OWNED"); 5858e6a8737SNate Lawson } 586773b6454SNate Lawson printf("\n"); 5878e6a8737SNate Lawson 588773b6454SNate Lawson printf("\tFlags="); 5898e6a8737SNate Lawson if (facs->flags & FACS_FLAG_S4BIOS_F) 5908e6a8737SNate Lawson printf("S4BIOS"); 591773b6454SNate Lawson printf("\n"); 5928e6a8737SNate Lawson 5938e6a8737SNate Lawson if (facs->x_firm_wake_vec != 0) { 5948e6a8737SNate Lawson printf("\tX_Firm_Wake_Vec=%08lx\n", 5958e6a8737SNate Lawson (u_long)facs->x_firm_wake_vec); 5968e6a8737SNate Lawson } 597773b6454SNate Lawson printf("\tVersion=%u\n", facs->version); 5988e6a8737SNate Lawson 599c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 600e1e9a4bfSMitsuru IWASAKI } 601e1e9a4bfSMitsuru IWASAKI 602945137d9SNate Lawson static void 603e1e9a4bfSMitsuru IWASAKI acpi_print_dsdt(struct ACPIsdt *dsdp) 604e1e9a4bfSMitsuru IWASAKI { 605773b6454SNate Lawson printf(BEGIN_COMMENT); 606773b6454SNate Lawson acpi_print_sdt(dsdp); 607773b6454SNate Lawson printf(END_COMMENT); 608e1e9a4bfSMitsuru IWASAKI } 609e1e9a4bfSMitsuru IWASAKI 610e1e9a4bfSMitsuru IWASAKI int 611e1e9a4bfSMitsuru IWASAKI acpi_checksum(void *p, size_t length) 612e1e9a4bfSMitsuru IWASAKI { 613e1e9a4bfSMitsuru IWASAKI u_int8_t *bp; 614e1e9a4bfSMitsuru IWASAKI u_int8_t sum; 615e1e9a4bfSMitsuru IWASAKI 616e1e9a4bfSMitsuru IWASAKI bp = p; 617e1e9a4bfSMitsuru IWASAKI sum = 0; 618e1e9a4bfSMitsuru IWASAKI while (length--) 619e1e9a4bfSMitsuru IWASAKI sum += *bp++; 620e1e9a4bfSMitsuru IWASAKI 621e1e9a4bfSMitsuru IWASAKI return (sum); 622e1e9a4bfSMitsuru IWASAKI } 623e1e9a4bfSMitsuru IWASAKI 624945137d9SNate Lawson static struct ACPIsdt * 625e1e9a4bfSMitsuru IWASAKI acpi_map_sdt(vm_offset_t pa) 626e1e9a4bfSMitsuru IWASAKI { 627e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sp; 628e1e9a4bfSMitsuru IWASAKI 629e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); 630e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sp->len); 631e1e9a4bfSMitsuru IWASAKI return (sp); 632e1e9a4bfSMitsuru IWASAKI } 633e1e9a4bfSMitsuru IWASAKI 634945137d9SNate Lawson static void 635e1e9a4bfSMitsuru IWASAKI acpi_print_rsd_ptr(struct ACPIrsdp *rp) 636e1e9a4bfSMitsuru IWASAKI { 637c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 638a74172abSNate Lawson printf(" RSD PTR: OEM="); 639e1e9a4bfSMitsuru IWASAKI acpi_print_string(rp->oem, 6); 640773b6454SNate Lawson printf(", ACPI_Rev=%s (%d)\n", rp->revision < 2 ? "1.0x" : "2.0x", 641a74172abSNate Lawson rp->revision); 642a74172abSNate Lawson if (rp->revision < 2) { 643a74172abSNate Lawson printf("\tRSDT=0x%08x, cksum=%u\n", rp->rsdt_addr, rp->sum); 644a74172abSNate Lawson } else { 645a74172abSNate Lawson printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", 646a74172abSNate Lawson (u_long)rp->xsdt_addr, rp->length, rp->xsum); 647a74172abSNate Lawson } 648c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 649e1e9a4bfSMitsuru IWASAKI } 650e1e9a4bfSMitsuru IWASAKI 651945137d9SNate Lawson static void 652e1e9a4bfSMitsuru IWASAKI acpi_handle_rsdt(struct ACPIsdt *rsdp) 653e1e9a4bfSMitsuru IWASAKI { 654e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sdp; 655a74172abSNate Lawson vm_offset_t addr; 656a74172abSNate Lawson int entries, i; 657e1e9a4bfSMitsuru IWASAKI 658e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(rsdp); 659a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 660e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 661a74172abSNate Lawson switch (addr_size) { 662a74172abSNate Lawson case 4: 663a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 664a74172abSNate Lawson break; 665a74172abSNate Lawson case 8: 666a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 667a74172abSNate Lawson break; 668a74172abSNate Lawson default: 669a74172abSNate Lawson assert((addr = 0)); 670a74172abSNate Lawson } 671a74172abSNate Lawson 672a74172abSNate Lawson sdp = (struct ACPIsdt *)acpi_map_sdt(addr); 6735cf6d493SNate Lawson if (acpi_checksum(sdp, sdp->len)) { 6745cf6d493SNate Lawson warnx("RSDT entry %d (sig %.4s) is corrupt", i, 6755cf6d493SNate Lawson sdp->signature); 6765cf6d493SNate Lawson continue; 6775cf6d493SNate Lawson } 678945137d9SNate Lawson if (!memcmp(sdp->signature, "FACP", 4)) 6792177d4e6SNate Lawson acpi_handle_fadt(sdp); 680945137d9SNate Lawson else if (!memcmp(sdp->signature, "APIC", 4)) 6810a473124SJohn Baldwin acpi_handle_apic(sdp); 682945137d9SNate Lawson else if (!memcmp(sdp->signature, "HPET", 4)) 68379d7565cSPeter Wemm acpi_handle_hpet(sdp); 68455d7ff9eSNate Lawson else if (!memcmp(sdp->signature, "ECDT", 4)) 68555d7ff9eSNate Lawson acpi_handle_ecdt(sdp); 686773b6454SNate Lawson else { 687773b6454SNate Lawson printf(BEGIN_COMMENT); 688773b6454SNate Lawson acpi_print_sdt(sdp); 689773b6454SNate Lawson printf(END_COMMENT); 690773b6454SNate Lawson } 691e1e9a4bfSMitsuru IWASAKI } 692e1e9a4bfSMitsuru IWASAKI } 693c62f1cccSMitsuru IWASAKI 694945137d9SNate Lawson struct ACPIsdt * 695476daaecSDag-Erling Smørgrav sdt_load_devmem(void) 696945137d9SNate Lawson { 697945137d9SNate Lawson struct ACPIrsdp *rp; 698945137d9SNate Lawson struct ACPIsdt *rsdp; 699945137d9SNate Lawson 700945137d9SNate Lawson rp = acpi_find_rsd_ptr(); 701945137d9SNate Lawson if (!rp) 702945137d9SNate Lawson errx(1, "Can't find ACPI information"); 703945137d9SNate Lawson 704945137d9SNate Lawson if (tflag) 705945137d9SNate Lawson acpi_print_rsd_ptr(rp); 706a74172abSNate Lawson if (rp->revision < 2) { 707945137d9SNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->rsdt_addr); 708945137d9SNate Lawson if (memcmp(rsdp->signature, "RSDT", 4) != 0 || 709945137d9SNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 710945137d9SNate Lawson errx(1, "RSDT is corrupted"); 711a74172abSNate Lawson addr_size = sizeof(uint32_t); 712a74172abSNate Lawson } else { 713a74172abSNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->xsdt_addr); 714a74172abSNate Lawson if (memcmp(rsdp->signature, "XSDT", 4) != 0 || 715a74172abSNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 716a74172abSNate Lawson errx(1, "XSDT is corrupted"); 717a74172abSNate Lawson addr_size = sizeof(uint64_t); 718a74172abSNate Lawson } 719945137d9SNate Lawson return (rsdp); 720945137d9SNate Lawson } 721c62f1cccSMitsuru IWASAKI 72262c7bde1SNate Lawson /* Write the DSDT to a file, concatenating any SSDTs (if present). */ 723bfa3f012SMarcel Moolenaar static int 724bfa3f012SMarcel Moolenaar write_dsdt(int fd, struct ACPIsdt *rsdt, struct ACPIsdt *dsdt) 725bfa3f012SMarcel Moolenaar { 726bfa3f012SMarcel Moolenaar struct ACPIsdt sdt; 727bfa3f012SMarcel Moolenaar struct ACPIsdt *ssdt; 728bfa3f012SMarcel Moolenaar uint8_t sum; 729bfa3f012SMarcel Moolenaar 73062c7bde1SNate Lawson /* Create a new checksum to account for the DSDT and any SSDTs. */ 731bfa3f012SMarcel Moolenaar sdt = *dsdt; 732bfa3f012SMarcel Moolenaar if (rsdt != NULL) { 733bfa3f012SMarcel Moolenaar sdt.check = 0; 734bfa3f012SMarcel Moolenaar sum = acpi_checksum(dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 735bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 736f7675a56SNate Lawson while (ssdt != NULL) { 737bfa3f012SMarcel Moolenaar sdt.len += ssdt->len - SIZEOF_SDT_HDR; 738bfa3f012SMarcel Moolenaar sum += acpi_checksum(ssdt->body, 739bfa3f012SMarcel Moolenaar ssdt->len - SIZEOF_SDT_HDR); 740bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 741bfa3f012SMarcel Moolenaar } 742bfa3f012SMarcel Moolenaar sum += acpi_checksum(&sdt, SIZEOF_SDT_HDR); 743bfa3f012SMarcel Moolenaar sdt.check -= sum; 744bfa3f012SMarcel Moolenaar } 74562c7bde1SNate Lawson 74662c7bde1SNate Lawson /* Write out the DSDT header and body. */ 747bfa3f012SMarcel Moolenaar write(fd, &sdt, SIZEOF_SDT_HDR); 748bfa3f012SMarcel Moolenaar write(fd, dsdt->body, dsdt->len - SIZEOF_SDT_HDR); 74962c7bde1SNate Lawson 75062c7bde1SNate Lawson /* Write out any SSDTs (if present and the user requested this.) */ 751f7675a56SNate Lawson if (rsdt != NULL) { 752bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 753bfa3f012SMarcel Moolenaar while (ssdt != NULL) { 754bfa3f012SMarcel Moolenaar write(fd, ssdt->body, ssdt->len - SIZEOF_SDT_HDR); 755bfa3f012SMarcel Moolenaar ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 756bfa3f012SMarcel Moolenaar } 757bfa3f012SMarcel Moolenaar } 758bfa3f012SMarcel Moolenaar return (0); 759bfa3f012SMarcel Moolenaar } 760bfa3f012SMarcel Moolenaar 761c62f1cccSMitsuru IWASAKI void 762bfa3f012SMarcel Moolenaar dsdt_save_file(char *outfile, struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 763c62f1cccSMitsuru IWASAKI { 764945137d9SNate Lawson int fd; 765945137d9SNate Lawson mode_t mode; 766945137d9SNate Lawson 767945137d9SNate Lawson assert(outfile != NULL); 768945137d9SNate Lawson mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 769945137d9SNate Lawson fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); 770945137d9SNate Lawson if (fd == -1) { 771945137d9SNate Lawson perror("dsdt_save_file"); 772945137d9SNate Lawson return; 773945137d9SNate Lawson } 774bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 775945137d9SNate Lawson close(fd); 776c62f1cccSMitsuru IWASAKI } 777c62f1cccSMitsuru IWASAKI 778945137d9SNate Lawson void 779bfa3f012SMarcel Moolenaar aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 780c62f1cccSMitsuru IWASAKI { 781945137d9SNate Lawson char tmpstr[32], buf[256]; 782945137d9SNate Lawson FILE *fp; 783945137d9SNate Lawson int fd, len; 784945137d9SNate Lawson 785945137d9SNate Lawson strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); 786945137d9SNate Lawson fd = mkstemp(tmpstr); 787945137d9SNate Lawson if (fd < 0) { 788945137d9SNate Lawson perror("iasl tmp file"); 789945137d9SNate Lawson return; 790c62f1cccSMitsuru IWASAKI } 791bfa3f012SMarcel Moolenaar write_dsdt(fd, rsdt, dsdp); 792945137d9SNate Lawson close(fd); 793945137d9SNate Lawson 794945137d9SNate Lawson /* Run iasl -d on the temp file */ 795945137d9SNate Lawson if (fork() == 0) { 796945137d9SNate Lawson close(STDOUT_FILENO); 797945137d9SNate Lawson if (vflag == 0) 798945137d9SNate Lawson close(STDERR_FILENO); 799945137d9SNate Lawson execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, 0); 800945137d9SNate Lawson err(1, "exec"); 801c62f1cccSMitsuru IWASAKI } 802c62f1cccSMitsuru IWASAKI 803945137d9SNate Lawson wait(NULL); 804945137d9SNate Lawson unlink(tmpstr); 805945137d9SNate Lawson 806945137d9SNate Lawson /* Dump iasl's output to stdout */ 807945137d9SNate Lawson fp = fopen("acpidump.dsl", "r"); 808945137d9SNate Lawson unlink("acpidump.dsl"); 809945137d9SNate Lawson if (fp == NULL) { 810945137d9SNate Lawson perror("iasl tmp file (read)"); 811945137d9SNate Lawson return; 812945137d9SNate Lawson } 813945137d9SNate Lawson while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 814945137d9SNate Lawson fwrite(buf, 1, len, stdout); 815945137d9SNate Lawson fclose(fp); 816c62f1cccSMitsuru IWASAKI } 817c62f1cccSMitsuru IWASAKI 818945137d9SNate Lawson void 819945137d9SNate Lawson sdt_print_all(struct ACPIsdt *rsdp) 820c62f1cccSMitsuru IWASAKI { 821945137d9SNate Lawson acpi_handle_rsdt(rsdp); 822c62f1cccSMitsuru IWASAKI } 823c62f1cccSMitsuru IWASAKI 824bfa3f012SMarcel Moolenaar /* Fetch a table matching the given signature via the RSDT. */ 825945137d9SNate Lawson struct ACPIsdt * 826bfa3f012SMarcel Moolenaar sdt_from_rsdt(struct ACPIsdt *rsdt, const char *sig, struct ACPIsdt *last) 827c62f1cccSMitsuru IWASAKI { 828945137d9SNate Lawson struct ACPIsdt *sdt; 829a74172abSNate Lawson vm_offset_t addr; 830a74172abSNate Lawson int entries, i; 831945137d9SNate Lawson 832a74172abSNate Lawson entries = (rsdt->len - SIZEOF_SDT_HDR) / addr_size; 833945137d9SNate Lawson for (i = 0; i < entries; i++) { 834a74172abSNate Lawson switch (addr_size) { 835a74172abSNate Lawson case 4: 836a74172abSNate Lawson addr = le32dec((char*)rsdt->body + i * addr_size); 837a74172abSNate Lawson break; 838a74172abSNate Lawson case 8: 839a74172abSNate Lawson addr = le64dec((char*)rsdt->body + i * addr_size); 840a74172abSNate Lawson break; 841a74172abSNate Lawson default: 842a74172abSNate Lawson assert((addr = 0)); 843a74172abSNate Lawson } 844a74172abSNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(addr); 845bfa3f012SMarcel Moolenaar if (last != NULL) { 846bfa3f012SMarcel Moolenaar if (sdt == last) 847bfa3f012SMarcel Moolenaar last = NULL; 848bfa3f012SMarcel Moolenaar continue; 849bfa3f012SMarcel Moolenaar } 850a74172abSNate Lawson if (memcmp(sdt->signature, sig, strlen(sig))) 851a74172abSNate Lawson continue; 852945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 853945137d9SNate Lawson errx(1, "RSDT entry %d is corrupt", i); 854945137d9SNate Lawson return (sdt); 855c62f1cccSMitsuru IWASAKI } 856c62f1cccSMitsuru IWASAKI 857945137d9SNate Lawson return (NULL); 858c62f1cccSMitsuru IWASAKI } 859c62f1cccSMitsuru IWASAKI 860945137d9SNate Lawson struct ACPIsdt * 8618e6a8737SNate Lawson dsdt_from_fadt(struct FADTbody *fadt) 862c62f1cccSMitsuru IWASAKI { 863945137d9SNate Lawson struct ACPIsdt *sdt; 864c62f1cccSMitsuru IWASAKI 865c83f0f99SNate Lawson /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */ 866c2962974SNate Lawson if (acpi_get_fadt_revision(fadt) == 1) 8678e6a8737SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 8682e71eb12SNate Lawson else 8692e71eb12SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr); 870945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 871945137d9SNate Lawson errx(1, "DSDT is corrupt\n"); 872945137d9SNate Lawson return (sdt); 873c62f1cccSMitsuru IWASAKI } 874