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); 488e6a8737SNate Lawson static void acpi_handle_fadt(struct FADTbody *fadt); 49945137d9SNate Lawson static void acpi_print_cpu(u_char cpu_id); 50945137d9SNate Lawson static void acpi_print_local_apic(u_char cpu_id, u_char apic_id, 51945137d9SNate Lawson u_int32_t flags); 52945137d9SNate Lawson static void acpi_print_io_apic(u_char apic_id, u_int32_t int_base, 53945137d9SNate Lawson u_int64_t apic_addr); 54945137d9SNate Lawson static void acpi_print_mps_flags(u_int16_t flags); 55945137d9SNate Lawson static void acpi_print_intr(u_int32_t intr, u_int16_t mps_flags); 56945137d9SNate Lawson static void acpi_print_apic(struct MADT_APIC *mp); 57945137d9SNate Lawson static void acpi_handle_apic(struct ACPIsdt *sdp); 58945137d9SNate Lawson static void acpi_handle_hpet(struct ACPIsdt *sdp); 59773b6454SNate Lawson static void acpi_print_sdt(struct ACPIsdt *sdp); 608e6a8737SNate Lawson static void acpi_print_fadt(struct FADTbody *fadt); 618e6a8737SNate Lawson static void acpi_print_facs(struct FACSbody *facs); 62945137d9SNate Lawson static void acpi_print_dsdt(struct ACPIsdt *dsdp); 63a74172abSNate Lawson static struct ACPIsdt *acpi_map_sdt(vm_offset_t pa); 64945137d9SNate Lawson static void acpi_print_rsd_ptr(struct ACPIrsdp *rp); 65945137d9SNate Lawson static void acpi_handle_rsdt(struct ACPIsdt *rsdp); 66c62f1cccSMitsuru IWASAKI 67773b6454SNate Lawson /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */ 68a74172abSNate Lawson static int addr_size; 69a74172abSNate Lawson 70e1e9a4bfSMitsuru IWASAKI static void 71e1e9a4bfSMitsuru IWASAKI acpi_print_string(char *s, size_t length) 72e1e9a4bfSMitsuru IWASAKI { 73e1e9a4bfSMitsuru IWASAKI int c; 74e1e9a4bfSMitsuru IWASAKI 75e1e9a4bfSMitsuru IWASAKI /* Trim trailing spaces and NULLs */ 76e1e9a4bfSMitsuru IWASAKI while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) 77e1e9a4bfSMitsuru IWASAKI length--; 78e1e9a4bfSMitsuru IWASAKI 79e1e9a4bfSMitsuru IWASAKI while (length--) { 80e1e9a4bfSMitsuru IWASAKI c = *s++; 81e1e9a4bfSMitsuru IWASAKI putchar(c); 82e1e9a4bfSMitsuru IWASAKI } 83e1e9a4bfSMitsuru IWASAKI } 84e1e9a4bfSMitsuru IWASAKI 85e1e9a4bfSMitsuru IWASAKI static void 868e6a8737SNate Lawson acpi_print_gas(struct ACPIgas *gas) 878e6a8737SNate Lawson { 888e6a8737SNate Lawson switch(gas->address_space_id) { 898e6a8737SNate Lawson case ACPI_GAS_MEMORY: 90773b6454SNate Lawson printf("0x%08lx:%u[%u] (Memory)", (u_long)gas->address, 918e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 928e6a8737SNate Lawson break; 938e6a8737SNate Lawson case ACPI_GAS_IO: 94773b6454SNate Lawson printf("0x%08lx:%u[%u] (IO)", (u_long)gas->address, 958e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 968e6a8737SNate Lawson break; 978e6a8737SNate Lawson case ACPI_GAS_PCI: 98773b6454SNate Lawson printf("%x:%x+%#x (PCI)", (uint16_t)(gas->address >> 32), 998e6a8737SNate Lawson (uint16_t)((gas->address >> 16) & 0xffff), 1008e6a8737SNate Lawson (uint16_t)gas->address); 1018e6a8737SNate Lawson break; 1028e6a8737SNate Lawson /* XXX How to handle these below? */ 1038e6a8737SNate Lawson case ACPI_GAS_EMBEDDED: 104773b6454SNate Lawson printf("0x%#x:%u[%u] (EC)", (uint16_t)gas->address, 1058e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 1068e6a8737SNate Lawson break; 1078e6a8737SNate Lawson case ACPI_GAS_SMBUS: 108773b6454SNate Lawson printf("0x%#x:%u[%u] (SMBus)", (uint16_t)gas->address, 1098e6a8737SNate Lawson gas->bit_offset, gas->bit_width); 1108e6a8737SNate Lawson break; 1118e6a8737SNate Lawson case ACPI_GAS_FIXED: 1128e6a8737SNate Lawson default: 113773b6454SNate Lawson printf("0x%08lx (?)", (u_long)gas->address); 1148e6a8737SNate Lawson break; 1158e6a8737SNate Lawson } 1168e6a8737SNate Lawson } 1178e6a8737SNate Lawson 1188e6a8737SNate Lawson static void 1198e6a8737SNate Lawson acpi_handle_fadt(struct FADTbody *fadt) 120e1e9a4bfSMitsuru IWASAKI { 121e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *dsdp; 1228e6a8737SNate Lawson struct FACSbody *facs; 123e1e9a4bfSMitsuru IWASAKI 1248e6a8737SNate Lawson acpi_print_fadt(fadt); 1258e6a8737SNate Lawson 126773b6454SNate Lawson /* 127773b6454SNate Lawson * My T23 is revision 2 but the 64 bit addresses are invalid. 128773b6454SNate Lawson * If revision 2 and the 32 bit address is non-zero but the 32 129773b6454SNate Lawson * and 64 bit versions don't match, prefer the 32 bit version. 130773b6454SNate Lawson */ 131773b6454SNate Lawson if (addr_size == 4 || 132773b6454SNate Lawson (addr_size == 8 && fadt->facs_ptr != 0 && 133773b6454SNate Lawson (fadt->x_facs_ptr & 0xffffffff) != fadt->facs_ptr)) 1348e6a8737SNate Lawson facs = (struct FACSbody *)acpi_map_sdt(fadt->facs_ptr); 135773b6454SNate Lawson else 136773b6454SNate Lawson facs = (struct FACSbody *)acpi_map_sdt(fadt->x_facs_ptr); 1378e6a8737SNate Lawson if (memcmp(facs->signature, "FACS", 4) != 0 || facs->len < 64) 1388e6a8737SNate Lawson errx(1, "FACS is corrupt"); 1398e6a8737SNate Lawson acpi_print_facs(facs); 1408e6a8737SNate Lawson 141773b6454SNate Lawson if (addr_size == 4 || 142773b6454SNate Lawson (addr_size == 8 && fadt->dsdt_ptr != 0 && 143773b6454SNate Lawson (fadt->x_dsdt_ptr & 0xffffffff) != fadt->dsdt_ptr)) 1448e6a8737SNate Lawson dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 145773b6454SNate Lawson else 146773b6454SNate Lawson dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr); 147e1e9a4bfSMitsuru IWASAKI if (acpi_checksum(dsdp, dsdp->len)) 148945137d9SNate Lawson errx(1, "DSDT is corrupt"); 149945137d9SNate Lawson acpi_print_dsdt(dsdp); 150c62f1cccSMitsuru IWASAKI } 151c62f1cccSMitsuru IWASAKI 152c62f1cccSMitsuru IWASAKI static void 1530a473124SJohn Baldwin acpi_print_cpu(u_char cpu_id) 1540a473124SJohn Baldwin { 1550a473124SJohn Baldwin 1560a473124SJohn Baldwin printf("\tACPI CPU="); 1570a473124SJohn Baldwin if (cpu_id == 0xff) 1580a473124SJohn Baldwin printf("ALL\n"); 1590a473124SJohn Baldwin else 1600a473124SJohn Baldwin printf("%d\n", (u_int)cpu_id); 1610a473124SJohn Baldwin } 1620a473124SJohn Baldwin 1630a473124SJohn Baldwin static void 1640a473124SJohn Baldwin acpi_print_local_apic(u_char cpu_id, u_char apic_id, u_int32_t flags) 1650a473124SJohn Baldwin { 1660a473124SJohn Baldwin acpi_print_cpu(cpu_id); 1670a473124SJohn Baldwin printf("\tFlags={"); 1680a473124SJohn Baldwin if (flags & ACPI_MADT_APIC_LOCAL_FLAG_ENABLED) 1690a473124SJohn Baldwin printf("ENABLED"); 1700a473124SJohn Baldwin else 1710a473124SJohn Baldwin printf("DISABLED"); 1720a473124SJohn Baldwin printf("}\n"); 1730a473124SJohn Baldwin printf("\tAPIC ID=%d\n", (u_int)apic_id); 1740a473124SJohn Baldwin } 1750a473124SJohn Baldwin 1760a473124SJohn Baldwin static void 1770a473124SJohn Baldwin acpi_print_io_apic(u_char apic_id, u_int32_t int_base, u_int64_t apic_addr) 1780a473124SJohn Baldwin { 1790a473124SJohn Baldwin printf("\tAPIC ID=%d\n", (u_int)apic_id); 1800a473124SJohn Baldwin printf("\tINT BASE=%d\n", int_base); 181945137d9SNate Lawson printf("\tADDR=0x%016jx\n", apic_addr); 1820a473124SJohn Baldwin } 1830a473124SJohn Baldwin 1840a473124SJohn Baldwin static void 1850a473124SJohn Baldwin acpi_print_mps_flags(u_int16_t flags) 1860a473124SJohn Baldwin { 1870a473124SJohn Baldwin 1880a473124SJohn Baldwin printf("\tFlags={Polarity="); 1890a473124SJohn Baldwin switch (flags & MPS_INT_FLAG_POLARITY_MASK) { 1900a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_CONFORM: 1910a473124SJohn Baldwin printf("conforming"); 1920a473124SJohn Baldwin break; 1930a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_HIGH: 1940a473124SJohn Baldwin printf("active-hi"); 1950a473124SJohn Baldwin break; 1960a473124SJohn Baldwin case MPS_INT_FLAG_POLARITY_LOW: 1970a473124SJohn Baldwin printf("active-lo"); 1980a473124SJohn Baldwin break; 1990a473124SJohn Baldwin default: 2000a473124SJohn Baldwin printf("0x%x", flags & MPS_INT_FLAG_POLARITY_MASK); 2010a473124SJohn Baldwin break; 2020a473124SJohn Baldwin } 2030a473124SJohn Baldwin printf(", Trigger="); 2040a473124SJohn Baldwin switch (flags & MPS_INT_FLAG_TRIGGER_MASK) { 2050a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_CONFORM: 2060a473124SJohn Baldwin printf("conforming"); 2070a473124SJohn Baldwin break; 2080a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_EDGE: 2090a473124SJohn Baldwin printf("edge"); 2100a473124SJohn Baldwin break; 2110a473124SJohn Baldwin case MPS_INT_FLAG_TRIGGER_LEVEL: 2120a473124SJohn Baldwin printf("level"); 2130a473124SJohn Baldwin break; 2140a473124SJohn Baldwin default: 2150a473124SJohn Baldwin printf("0x%x", (flags & MPS_INT_FLAG_TRIGGER_MASK) >> 2); 2160a473124SJohn Baldwin } 2170a473124SJohn Baldwin printf("}\n"); 2180a473124SJohn Baldwin } 2190a473124SJohn Baldwin 2200a473124SJohn Baldwin static void 2210a473124SJohn Baldwin acpi_print_intr(u_int32_t intr, u_int16_t mps_flags) 2220a473124SJohn Baldwin { 2230a473124SJohn Baldwin 2240a473124SJohn Baldwin printf("\tINTR=%d\n", (u_int)intr); 2250a473124SJohn Baldwin acpi_print_mps_flags(mps_flags); 2260a473124SJohn Baldwin } 2270a473124SJohn Baldwin 2280a473124SJohn Baldwin const char *apic_types[] = { "Local APIC", "IO APIC", "INT Override", "NMI", 2290a473124SJohn Baldwin "Local NMI", "Local APIC Override", "IO SAPIC", 2300a473124SJohn Baldwin "Local SAPIC", "Platform Interrupt" }; 2310a473124SJohn Baldwin const char *platform_int_types[] = { "PMI", "INIT", 2320a473124SJohn Baldwin "Corrected Platform Error" }; 2330a473124SJohn Baldwin 2340a473124SJohn Baldwin static void 2350a473124SJohn Baldwin acpi_print_apic(struct MADT_APIC *mp) 2360a473124SJohn Baldwin { 2370a473124SJohn Baldwin 2380a473124SJohn Baldwin printf("\tType=%s\n", apic_types[mp->type]); 2390a473124SJohn Baldwin switch (mp->type) { 2400a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_APIC: 2410a473124SJohn Baldwin acpi_print_local_apic(mp->body.local_apic.cpu_id, 2420a473124SJohn Baldwin mp->body.local_apic.apic_id, mp->body.local_apic.flags); 2430a473124SJohn Baldwin break; 2440a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_IO_APIC: 2450a473124SJohn Baldwin acpi_print_io_apic(mp->body.io_apic.apic_id, 2460a473124SJohn Baldwin mp->body.io_apic.int_base, 2470a473124SJohn Baldwin mp->body.io_apic.apic_addr); 2480a473124SJohn Baldwin break; 2490a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_INT_OVERRIDE: 2500a473124SJohn Baldwin printf("\tBUS=%d\n", (u_int)mp->body.int_override.bus); 2510a473124SJohn Baldwin printf("\tIRQ=%d\n", (u_int)mp->body.int_override.source); 2520a473124SJohn Baldwin acpi_print_intr(mp->body.int_override.intr, 2530a473124SJohn Baldwin mp->body.int_override.mps_flags); 2540a473124SJohn Baldwin break; 2550a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_NMI: 2560a473124SJohn Baldwin acpi_print_intr(mp->body.nmi.intr, mp->body.nmi.mps_flags); 2570a473124SJohn Baldwin break; 2580a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_NMI: 2590a473124SJohn Baldwin acpi_print_cpu(mp->body.local_nmi.cpu_id); 2600a473124SJohn Baldwin printf("\tLINT Pin=%d\n", mp->body.local_nmi.lintpin); 2610a473124SJohn Baldwin acpi_print_mps_flags(mp->body.local_nmi.mps_flags); 2620a473124SJohn Baldwin break; 2630a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE: 264945137d9SNate Lawson printf("\tLocal APIC ADDR=0x%016jx\n", 265945137d9SNate Lawson mp->body.local_apic_override.apic_addr); 2660a473124SJohn Baldwin break; 2670a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_IO_SAPIC: 2680a473124SJohn Baldwin acpi_print_io_apic(mp->body.io_sapic.apic_id, 2690a473124SJohn Baldwin mp->body.io_sapic.int_base, 2700a473124SJohn Baldwin mp->body.io_sapic.apic_addr); 2710a473124SJohn Baldwin break; 2720a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_LOCAL_SAPIC: 2730a473124SJohn Baldwin acpi_print_local_apic(mp->body.local_sapic.cpu_id, 2740a473124SJohn Baldwin mp->body.local_sapic.apic_id, mp->body.local_sapic.flags); 2750a473124SJohn Baldwin printf("\tAPIC EID=%d\n", (u_int)mp->body.local_sapic.apic_eid); 2760a473124SJohn Baldwin break; 2770a473124SJohn Baldwin case ACPI_MADT_APIC_TYPE_INT_SRC: 2780a473124SJohn Baldwin printf("\tType=%s\n", 2790a473124SJohn Baldwin platform_int_types[mp->body.int_src.type]); 2800a473124SJohn Baldwin printf("\tCPU ID=%d\n", (u_int)mp->body.int_src.cpu_id); 2810a473124SJohn Baldwin printf("\tCPU EID=%d\n", (u_int)mp->body.int_src.cpu_id); 2820a473124SJohn Baldwin printf("\tSAPIC Vector=%d\n", 2830a473124SJohn Baldwin (u_int)mp->body.int_src.sapic_vector); 2840a473124SJohn Baldwin acpi_print_intr(mp->body.int_src.intr, 2850a473124SJohn Baldwin mp->body.int_src.mps_flags); 2860a473124SJohn Baldwin break; 2870a473124SJohn Baldwin default: 2880a473124SJohn Baldwin printf("\tUnknown type %d\n", (u_int)mp->type); 289945137d9SNate Lawson break; 2900a473124SJohn Baldwin } 2910a473124SJohn Baldwin } 2920a473124SJohn Baldwin 2930a473124SJohn Baldwin static void 2940a473124SJohn Baldwin acpi_handle_apic(struct ACPIsdt *sdp) 2950a473124SJohn Baldwin { 2960a473124SJohn Baldwin struct MADTbody *madtp; 2970a473124SJohn Baldwin struct MADT_APIC *madt_apicp; 2980a473124SJohn Baldwin 299773b6454SNate Lawson printf(BEGIN_COMMENT); 300773b6454SNate Lawson acpi_print_sdt(sdp); 3010a473124SJohn Baldwin madtp = (struct MADTbody *) sdp->body; 3020a473124SJohn Baldwin printf("\tLocal APIC ADDR=0x%08x\n", madtp->lapic_addr); 3030a473124SJohn Baldwin printf("\tFlags={"); 3040a473124SJohn Baldwin if (madtp->flags & ACPI_APIC_FLAG_PCAT_COMPAT) 3050a473124SJohn Baldwin printf("PC-AT"); 3060a473124SJohn Baldwin printf("}\n"); 3070a473124SJohn Baldwin madt_apicp = (struct MADT_APIC *)madtp->body; 3080a473124SJohn Baldwin while (((uintptr_t)madt_apicp) - ((uintptr_t)sdp) < sdp->len) { 3090a473124SJohn Baldwin printf("\n"); 3100a473124SJohn Baldwin acpi_print_apic(madt_apicp); 3110a473124SJohn Baldwin madt_apicp = (struct MADT_APIC *) ((char *)madt_apicp + 3120a473124SJohn Baldwin madt_apicp->len); 3130a473124SJohn Baldwin } 3140a473124SJohn Baldwin printf(END_COMMENT); 3150a473124SJohn Baldwin } 3160a473124SJohn Baldwin 3170a473124SJohn Baldwin static void 31879d7565cSPeter Wemm acpi_handle_hpet(struct ACPIsdt *sdp) 31979d7565cSPeter Wemm { 32079d7565cSPeter Wemm struct HPETbody *hpetp; 32179d7565cSPeter Wemm 322773b6454SNate Lawson printf(BEGIN_COMMENT); 323773b6454SNate Lawson acpi_print_sdt(sdp); 32479d7565cSPeter Wemm hpetp = (struct HPETbody *) sdp->body; 32579d7565cSPeter Wemm printf("\tHPET Number=%d\n", hpetp->hpet_number); 32679d7565cSPeter Wemm printf("\tADDR=0x%08x\n", hpetp->base_addr); 32779d7565cSPeter Wemm printf("\tHW Rev=0x%x\n", hpetp->block_hwrev); 32879d7565cSPeter Wemm printf("\tComparitors=%d\n", hpetp->block_comparitors); 32979d7565cSPeter Wemm printf("\tCounter Size=%d\n", hpetp->block_counter_size); 33079d7565cSPeter Wemm printf("\tLegacy IRQ routing capable={"); 33179d7565cSPeter Wemm if (hpetp->block_legacy_capable) 33279d7565cSPeter Wemm printf("TRUE}\n"); 33379d7565cSPeter Wemm else 33479d7565cSPeter Wemm printf("FALSE}\n"); 33579d7565cSPeter Wemm printf("\tPCI Vendor ID=0x%04x\n", hpetp->block_pcivendor); 33655da3c73SPeter Wemm printf("\tMinimal Tick=%d\n", hpetp->clock_tick); 33779d7565cSPeter Wemm printf(END_COMMENT); 33879d7565cSPeter Wemm } 33979d7565cSPeter Wemm 34079d7565cSPeter Wemm static void 341773b6454SNate Lawson acpi_print_sdt(struct ACPIsdt *sdp) 342c62f1cccSMitsuru IWASAKI { 343773b6454SNate Lawson printf(" "); 344e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->signature, 4); 345c62f1cccSMitsuru IWASAKI printf(": Length=%d, Revision=%d, Checksum=%d,\n", 346e1e9a4bfSMitsuru IWASAKI sdp->len, sdp->rev, sdp->check); 347e1e9a4bfSMitsuru IWASAKI printf("\tOEMID="); 348e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemid, 6); 349e1e9a4bfSMitsuru IWASAKI printf(", OEM Table ID="); 350e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->oemtblid, 8); 351e1e9a4bfSMitsuru IWASAKI printf(", OEM Revision=0x%x,\n", sdp->oemrev); 352e1e9a4bfSMitsuru IWASAKI printf("\tCreator ID="); 353e1e9a4bfSMitsuru IWASAKI acpi_print_string(sdp->creator, 4); 354e1e9a4bfSMitsuru IWASAKI printf(", Creator Revision=0x%x\n", sdp->crerev); 355e1e9a4bfSMitsuru IWASAKI } 356e1e9a4bfSMitsuru IWASAKI 357945137d9SNate Lawson static void 358e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(struct ACPIsdt *rsdp) 359e1e9a4bfSMitsuru IWASAKI { 360e1e9a4bfSMitsuru IWASAKI int i, entries; 361a74172abSNate Lawson u_long addr; 362e1e9a4bfSMitsuru IWASAKI 363773b6454SNate Lawson printf(BEGIN_COMMENT); 364773b6454SNate Lawson acpi_print_sdt(rsdp); 365a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 366e1e9a4bfSMitsuru IWASAKI printf("\tEntries={ "); 367e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 368e1e9a4bfSMitsuru IWASAKI if (i > 0) 369e1e9a4bfSMitsuru IWASAKI printf(", "); 370a74172abSNate Lawson switch (addr_size) { 371a74172abSNate Lawson case 4: 372a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 373a74172abSNate Lawson break; 374a74172abSNate Lawson case 8: 375a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 376a74172abSNate Lawson break; 377a74172abSNate Lawson default: 378a74172abSNate Lawson addr = 0; 379a74172abSNate Lawson } 380a74172abSNate Lawson assert(addr != 0); 381a74172abSNate Lawson printf("0x%08lx", addr); 382e1e9a4bfSMitsuru IWASAKI } 383e1e9a4bfSMitsuru IWASAKI printf(" }\n"); 384c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 385e1e9a4bfSMitsuru IWASAKI } 386e1e9a4bfSMitsuru IWASAKI 3878e6a8737SNate Lawson static const char *acpi_pm_profiles[] = { 3888e6a8737SNate Lawson "Unspecified", "Desktop", "Mobile", "Workstation", 3898e6a8737SNate Lawson "Enterprise Server", "SOHO Server", "Appliance PC" 3908e6a8737SNate Lawson }; 3918e6a8737SNate Lawson 392945137d9SNate Lawson static void 3938e6a8737SNate Lawson acpi_print_fadt(struct FADTbody *fadt) 394e1e9a4bfSMitsuru IWASAKI { 3958e6a8737SNate Lawson const char *pm; 396e1e9a4bfSMitsuru IWASAKI char sep; 397e1e9a4bfSMitsuru IWASAKI 398c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 3998e6a8737SNate Lawson printf(" FADT:\tFACS=0x%x, DSDT=0x%x\n", fadt->facs_ptr, 4008e6a8737SNate Lawson fadt->dsdt_ptr); 4018e6a8737SNate Lawson printf("\tINT_MODEL=%s\n", fadt->int_model ? "APIC" : "PIC"); 4028e6a8737SNate Lawson if (fadt->pm_profile >= sizeof(acpi_pm_profiles) / sizeof(char *)) 4038e6a8737SNate Lawson pm = "Reserved"; 4048e6a8737SNate Lawson else 4058e6a8737SNate Lawson pm = acpi_pm_profiles[fadt->pm_profile]; 4068e6a8737SNate Lawson printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->pm_profile); 4078e6a8737SNate Lawson printf("\tSCI_INT=%d\n", fadt->sci_int); 4088e6a8737SNate Lawson printf("\tSMI_CMD=0x%x, ", fadt->smi_cmd); 4098e6a8737SNate Lawson printf("ACPI_ENABLE=0x%x, ", fadt->acpi_enable); 4108e6a8737SNate Lawson printf("ACPI_DISABLE=0x%x, ", fadt->acpi_disable); 4118e6a8737SNate Lawson printf("S4BIOS_REQ=0x%x\n", fadt->s4biosreq); 4128e6a8737SNate Lawson printf("\tPSTATE_CNT=0x%x\n", fadt->pstate_cnt); 4138e6a8737SNate Lawson if (fadt->pm1a_evt_blk != 0) 414e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", 4158e6a8737SNate Lawson fadt->pm1a_evt_blk, 4168e6a8737SNate Lawson fadt->pm1a_evt_blk + fadt->pm1_evt_len - 1); 4178e6a8737SNate Lawson if (fadt->pm1b_evt_blk != 0) 418e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", 4198e6a8737SNate Lawson fadt->pm1b_evt_blk, 4208e6a8737SNate Lawson fadt->pm1b_evt_blk + fadt->pm1_evt_len - 1); 4218e6a8737SNate Lawson if (fadt->pm1a_cnt_blk != 0) 422e1e9a4bfSMitsuru IWASAKI printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", 4238e6a8737SNate Lawson fadt->pm1a_cnt_blk, 4248e6a8737SNate Lawson fadt->pm1a_cnt_blk + fadt->pm1_cnt_len - 1); 4258e6a8737SNate Lawson if (fadt->pm1b_cnt_blk != 0) 426e1e9a4bfSMitsuru IWASAKI printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", 4278e6a8737SNate Lawson fadt->pm1b_cnt_blk, 4288e6a8737SNate Lawson fadt->pm1b_cnt_blk + fadt->pm1_cnt_len - 1); 4298e6a8737SNate Lawson if (fadt->pm2_cnt_blk != 0) 430e1e9a4bfSMitsuru IWASAKI printf("\tPM2_CNT_BLK=0x%x-0x%x\n", 4318e6a8737SNate Lawson fadt->pm2_cnt_blk, 4328e6a8737SNate Lawson fadt->pm2_cnt_blk + fadt->pm2_cnt_len - 1); 4338e6a8737SNate Lawson if (fadt->pm_tmr_blk != 0) 434e1e9a4bfSMitsuru IWASAKI printf("\tPM2_TMR_BLK=0x%x-0x%x\n", 4358e6a8737SNate Lawson fadt->pm_tmr_blk, 4368e6a8737SNate Lawson fadt->pm_tmr_blk + fadt->pm_tmr_len - 1); 4378e6a8737SNate Lawson if (fadt->gpe0_blk != 0) 4388e6a8737SNate Lawson printf("\tGPE0_BLK=0x%x-0x%x\n", 4398e6a8737SNate Lawson fadt->gpe0_blk, 4408e6a8737SNate Lawson fadt->gpe0_blk + fadt->gpe0_len - 1); 4418e6a8737SNate Lawson if (fadt->gpe1_blk != 0) 4428e6a8737SNate Lawson printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", 4438e6a8737SNate Lawson fadt->gpe1_blk, 4448e6a8737SNate Lawson fadt->gpe1_blk + fadt->gpe1_len - 1, 4458e6a8737SNate Lawson fadt->gpe1_base); 4468e6a8737SNate Lawson if (fadt->cst_cnt != 0) 4478e6a8737SNate Lawson printf("\tCST_CNT=0x%x\n", fadt->cst_cnt); 448e1e9a4bfSMitsuru IWASAKI printf("\tP_LVL2_LAT=%dms, P_LVL3_LAT=%dms\n", 4498e6a8737SNate Lawson fadt->p_lvl2_lat, fadt->p_lvl3_lat); 450e1e9a4bfSMitsuru IWASAKI printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", 4518e6a8737SNate Lawson fadt->flush_size, fadt->flush_stride); 452e1e9a4bfSMitsuru IWASAKI printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", 4538e6a8737SNate Lawson fadt->duty_off, fadt->duty_width); 454e1e9a4bfSMitsuru IWASAKI printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", 4558e6a8737SNate Lawson fadt->day_alrm, fadt->mon_alrm, fadt->century); 456e1e9a4bfSMitsuru IWASAKI 4578e6a8737SNate Lawson #define PRINTFLAG(var, flag) do { \ 4588e6a8737SNate Lawson if ((var) & FADT_FLAG_## flag) { \ 4598e6a8737SNate Lawson printf("%c%s", sep, #flag); sep = ','; \ 460e1e9a4bfSMitsuru IWASAKI } \ 461e1e9a4bfSMitsuru IWASAKI } while (0) 462e1e9a4bfSMitsuru IWASAKI 4638e6a8737SNate Lawson printf("\tIAPC_BOOT_ARCH="); 4648e6a8737SNate Lawson sep = '{'; 4658e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, LEGACY_DEV); 4668e6a8737SNate Lawson PRINTFLAG(fadt->iapc_boot_arch, 8042); 4678e6a8737SNate Lawson printf("}\n"); 4688e6a8737SNate Lawson 4698e6a8737SNate Lawson printf("\tFlags="); 4708e6a8737SNate Lawson sep = '{'; 4718e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD); 4728e6a8737SNate Lawson PRINTFLAG(fadt->flags, WBINVD_FLUSH); 4738e6a8737SNate Lawson PRINTFLAG(fadt->flags, PROC_C1); 4748e6a8737SNate Lawson PRINTFLAG(fadt->flags, P_LVL2_UP); 4758e6a8737SNate Lawson PRINTFLAG(fadt->flags, PWR_BUTTON); 4768e6a8737SNate Lawson PRINTFLAG(fadt->flags, SLP_BUTTON); 4778e6a8737SNate Lawson PRINTFLAG(fadt->flags, FIX_RTC); 4788e6a8737SNate Lawson PRINTFLAG(fadt->flags, RTC_S4); 4798e6a8737SNate Lawson PRINTFLAG(fadt->flags, TMR_VAL_EXT); 4808e6a8737SNate Lawson PRINTFLAG(fadt->flags, DCK_CAP); 4818e6a8737SNate Lawson PRINTFLAG(fadt->flags, RESET_REG); 4828e6a8737SNate Lawson PRINTFLAG(fadt->flags, SEALED_CASE); 4838e6a8737SNate Lawson PRINTFLAG(fadt->flags, HEADLESS); 4848e6a8737SNate Lawson PRINTFLAG(fadt->flags, CPU_SW_SLP); 4858e6a8737SNate Lawson printf("}\n"); 486e1e9a4bfSMitsuru IWASAKI 487e1e9a4bfSMitsuru IWASAKI #undef PRINTFLAG 488e1e9a4bfSMitsuru IWASAKI 4898e6a8737SNate Lawson if (fadt->flags & FADT_FLAG_RESET_REG) { 4908e6a8737SNate Lawson printf("\tRESET_REG="); 4918e6a8737SNate Lawson acpi_print_gas(&fadt->reset_reg); 4928e6a8737SNate Lawson printf(", RESET_VALUE=%#x\n", fadt->reset_value); 4938e6a8737SNate Lawson } 494773b6454SNate Lawson if (addr_size == 8) { 495773b6454SNate Lawson printf("\tX_FACS=0x%08lx, ", (u_long)fadt->x_facs_ptr); 496773b6454SNate Lawson printf("X_DSDT=0x%08lx\n", (u_long)fadt->x_dsdt_ptr); 497773b6454SNate Lawson printf("\tX_PM1A_EVT_BLK="); 498773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_evt_blk); 499773b6454SNate Lawson printf("\n\tX_PM1B_EVT_BLK="); 500773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_evt_blk); 501773b6454SNate Lawson printf("\n\tX_PM1A_CNT_BLK="); 502773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1a_cnt_blk); 503773b6454SNate Lawson printf("\n\tX_PM1B_CNT_BLK="); 504773b6454SNate Lawson acpi_print_gas(&fadt->x_pm1b_cnt_blk); 505773b6454SNate Lawson printf("\n\tX_PM2_CNT_BLK="); 506773b6454SNate Lawson acpi_print_gas(&fadt->x_pm2_cnt_blk); 507773b6454SNate Lawson printf("\n\tX_PM_TMR_BLK="); 508773b6454SNate Lawson acpi_print_gas(&fadt->x_pm_tmr_blk); 509773b6454SNate Lawson printf("\n\tX_GPE0_BLK="); 510773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe0_blk); 511773b6454SNate Lawson printf("\n\tX_GPE1_BLK="); 512773b6454SNate Lawson acpi_print_gas(&fadt->x_gpe1_blk); 513773b6454SNate Lawson printf("\n"); 514773b6454SNate Lawson } 5158e6a8737SNate Lawson 5168e6a8737SNate Lawson printf(END_COMMENT); 5178e6a8737SNate Lawson } 5188e6a8737SNate Lawson 5198e6a8737SNate Lawson static void 5208e6a8737SNate Lawson acpi_print_facs(struct FACSbody *facs) 5218e6a8737SNate Lawson { 5228e6a8737SNate Lawson printf(BEGIN_COMMENT); 5238e6a8737SNate Lawson printf(" FACS:\tLength=%u, ", facs->len); 5248e6a8737SNate Lawson printf("HwSig=0x%08x, ", facs->hw_sig); 5258e6a8737SNate Lawson printf("Firm_Wake_Vec=0x%08x\n", facs->firm_wake_vec); 5268e6a8737SNate Lawson 527773b6454SNate Lawson printf("\tGlobal_Lock="); 5288e6a8737SNate Lawson if (facs->global_lock != 0) { 5298e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_PENDING) 5308e6a8737SNate Lawson printf("PENDING,"); 5318e6a8737SNate Lawson if (facs->global_lock & FACS_FLAG_LOCK_OWNED) 5328e6a8737SNate Lawson printf("OWNED"); 5338e6a8737SNate Lawson } 534773b6454SNate Lawson printf("\n"); 5358e6a8737SNate Lawson 536773b6454SNate Lawson printf("\tFlags="); 5378e6a8737SNate Lawson if (facs->flags & FACS_FLAG_S4BIOS_F) 5388e6a8737SNate Lawson printf("S4BIOS"); 539773b6454SNate Lawson printf("\n"); 5408e6a8737SNate Lawson 5418e6a8737SNate Lawson if (facs->x_firm_wake_vec != 0) { 5428e6a8737SNate Lawson printf("\tX_Firm_Wake_Vec=%08lx\n", 5438e6a8737SNate Lawson (u_long)facs->x_firm_wake_vec); 5448e6a8737SNate Lawson } 545773b6454SNate Lawson printf("\tVersion=%u\n", facs->version); 5468e6a8737SNate Lawson 547c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 548e1e9a4bfSMitsuru IWASAKI } 549e1e9a4bfSMitsuru IWASAKI 550945137d9SNate Lawson static void 551e1e9a4bfSMitsuru IWASAKI acpi_print_dsdt(struct ACPIsdt *dsdp) 552e1e9a4bfSMitsuru IWASAKI { 553773b6454SNate Lawson printf(BEGIN_COMMENT); 554773b6454SNate Lawson acpi_print_sdt(dsdp); 555773b6454SNate Lawson printf(END_COMMENT); 556e1e9a4bfSMitsuru IWASAKI } 557e1e9a4bfSMitsuru IWASAKI 558e1e9a4bfSMitsuru IWASAKI int 559e1e9a4bfSMitsuru IWASAKI acpi_checksum(void *p, size_t length) 560e1e9a4bfSMitsuru IWASAKI { 561e1e9a4bfSMitsuru IWASAKI u_int8_t *bp; 562e1e9a4bfSMitsuru IWASAKI u_int8_t sum; 563e1e9a4bfSMitsuru IWASAKI 564e1e9a4bfSMitsuru IWASAKI bp = p; 565e1e9a4bfSMitsuru IWASAKI sum = 0; 566e1e9a4bfSMitsuru IWASAKI while (length--) 567e1e9a4bfSMitsuru IWASAKI sum += *bp++; 568e1e9a4bfSMitsuru IWASAKI 569e1e9a4bfSMitsuru IWASAKI return (sum); 570e1e9a4bfSMitsuru IWASAKI } 571e1e9a4bfSMitsuru IWASAKI 572945137d9SNate Lawson static struct ACPIsdt * 573e1e9a4bfSMitsuru IWASAKI acpi_map_sdt(vm_offset_t pa) 574e1e9a4bfSMitsuru IWASAKI { 575e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sp; 576e1e9a4bfSMitsuru IWASAKI 577e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); 578e1e9a4bfSMitsuru IWASAKI sp = acpi_map_physical(pa, sp->len); 579e1e9a4bfSMitsuru IWASAKI return (sp); 580e1e9a4bfSMitsuru IWASAKI } 581e1e9a4bfSMitsuru IWASAKI 582945137d9SNate Lawson static void 583e1e9a4bfSMitsuru IWASAKI acpi_print_rsd_ptr(struct ACPIrsdp *rp) 584e1e9a4bfSMitsuru IWASAKI { 585c62f1cccSMitsuru IWASAKI printf(BEGIN_COMMENT); 586a74172abSNate Lawson printf(" RSD PTR: OEM="); 587e1e9a4bfSMitsuru IWASAKI acpi_print_string(rp->oem, 6); 588773b6454SNate Lawson printf(", ACPI_Rev=%s (%d)\n", rp->revision < 2 ? "1.0x" : "2.0x", 589a74172abSNate Lawson rp->revision); 590a74172abSNate Lawson if (rp->revision < 2) { 591a74172abSNate Lawson printf("\tRSDT=0x%08x, cksum=%u\n", rp->rsdt_addr, rp->sum); 592a74172abSNate Lawson } else { 593a74172abSNate Lawson printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", 594a74172abSNate Lawson (u_long)rp->xsdt_addr, rp->length, rp->xsum); 595a74172abSNate Lawson } 596c62f1cccSMitsuru IWASAKI printf(END_COMMENT); 597e1e9a4bfSMitsuru IWASAKI } 598e1e9a4bfSMitsuru IWASAKI 599945137d9SNate Lawson static void 600e1e9a4bfSMitsuru IWASAKI acpi_handle_rsdt(struct ACPIsdt *rsdp) 601e1e9a4bfSMitsuru IWASAKI { 602e1e9a4bfSMitsuru IWASAKI struct ACPIsdt *sdp; 603a74172abSNate Lawson vm_offset_t addr; 604a74172abSNate Lawson int entries, i; 605e1e9a4bfSMitsuru IWASAKI 606e1e9a4bfSMitsuru IWASAKI acpi_print_rsdt(rsdp); 607a74172abSNate Lawson entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size; 608e1e9a4bfSMitsuru IWASAKI for (i = 0; i < entries; i++) { 609a74172abSNate Lawson switch (addr_size) { 610a74172abSNate Lawson case 4: 611a74172abSNate Lawson addr = le32dec((char*)rsdp->body + i * addr_size); 612a74172abSNate Lawson break; 613a74172abSNate Lawson case 8: 614a74172abSNate Lawson addr = le64dec((char*)rsdp->body + i * addr_size); 615a74172abSNate Lawson break; 616a74172abSNate Lawson default: 617a74172abSNate Lawson assert((addr = 0)); 618a74172abSNate Lawson } 619a74172abSNate Lawson 620a74172abSNate Lawson sdp = (struct ACPIsdt *)acpi_map_sdt(addr); 621e1e9a4bfSMitsuru IWASAKI if (acpi_checksum(sdp, sdp->len)) 622945137d9SNate Lawson errx(1, "RSDT entry %d is corrupt", i); 623945137d9SNate Lawson if (!memcmp(sdp->signature, "FACP", 4)) 6248e6a8737SNate Lawson acpi_handle_fadt((struct FADTbody *) sdp->body); 625945137d9SNate Lawson else if (!memcmp(sdp->signature, "APIC", 4)) 6260a473124SJohn Baldwin acpi_handle_apic(sdp); 627945137d9SNate Lawson else if (!memcmp(sdp->signature, "HPET", 4)) 62879d7565cSPeter Wemm acpi_handle_hpet(sdp); 629773b6454SNate Lawson else { 630773b6454SNate Lawson printf(BEGIN_COMMENT); 631773b6454SNate Lawson acpi_print_sdt(sdp); 632773b6454SNate Lawson printf(END_COMMENT); 633773b6454SNate Lawson } 634e1e9a4bfSMitsuru IWASAKI } 635e1e9a4bfSMitsuru IWASAKI } 636c62f1cccSMitsuru IWASAKI 637945137d9SNate Lawson struct ACPIsdt * 638945137d9SNate Lawson sdt_load_devmem() 639945137d9SNate Lawson { 640945137d9SNate Lawson struct ACPIrsdp *rp; 641945137d9SNate Lawson struct ACPIsdt *rsdp; 642945137d9SNate Lawson 643945137d9SNate Lawson rp = acpi_find_rsd_ptr(); 644945137d9SNate Lawson if (!rp) 645945137d9SNate Lawson errx(1, "Can't find ACPI information"); 646945137d9SNate Lawson 647945137d9SNate Lawson if (tflag) 648945137d9SNate Lawson acpi_print_rsd_ptr(rp); 649a74172abSNate Lawson if (rp->revision < 2) { 650945137d9SNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->rsdt_addr); 651945137d9SNate Lawson if (memcmp(rsdp->signature, "RSDT", 4) != 0 || 652945137d9SNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 653945137d9SNate Lawson errx(1, "RSDT is corrupted"); 654a74172abSNate Lawson addr_size = sizeof(uint32_t); 655a74172abSNate Lawson } else { 656a74172abSNate Lawson rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->xsdt_addr); 657a74172abSNate Lawson if (memcmp(rsdp->signature, "XSDT", 4) != 0 || 658a74172abSNate Lawson acpi_checksum(rsdp, rsdp->len) != 0) 659a74172abSNate Lawson errx(1, "XSDT is corrupted"); 660a74172abSNate Lawson addr_size = sizeof(uint64_t); 661a74172abSNate Lawson } 662945137d9SNate Lawson return (rsdp); 663945137d9SNate Lawson } 664c62f1cccSMitsuru IWASAKI 665c62f1cccSMitsuru IWASAKI void 666945137d9SNate Lawson dsdt_save_file(char *outfile, struct ACPIsdt *dsdp) 667c62f1cccSMitsuru IWASAKI { 668945137d9SNate Lawson int fd; 669945137d9SNate Lawson mode_t mode; 670945137d9SNate Lawson 671945137d9SNate Lawson assert(outfile != NULL); 672945137d9SNate Lawson mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 673945137d9SNate Lawson fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); 674945137d9SNate Lawson if (fd == -1) { 675945137d9SNate Lawson perror("dsdt_save_file"); 676945137d9SNate Lawson return; 677945137d9SNate Lawson } 678945137d9SNate Lawson write(fd, dsdp, SIZEOF_SDT_HDR); 679945137d9SNate Lawson write(fd, dsdp->body, dsdp->len - SIZEOF_SDT_HDR); 680945137d9SNate Lawson close(fd); 681c62f1cccSMitsuru IWASAKI } 682c62f1cccSMitsuru IWASAKI 683945137d9SNate Lawson void 684945137d9SNate Lawson aml_disassemble(struct ACPIsdt *dsdp) 685c62f1cccSMitsuru IWASAKI { 686945137d9SNate Lawson char tmpstr[32], buf[256]; 687945137d9SNate Lawson FILE *fp; 688945137d9SNate Lawson int fd, len; 689945137d9SNate Lawson 690945137d9SNate Lawson strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); 691945137d9SNate Lawson fd = mkstemp(tmpstr); 692945137d9SNate Lawson if (fd < 0) { 693945137d9SNate Lawson perror("iasl tmp file"); 694945137d9SNate Lawson return; 695c62f1cccSMitsuru IWASAKI } 696c62f1cccSMitsuru IWASAKI 697945137d9SNate Lawson /* Dump DSDT to the temp file */ 698945137d9SNate Lawson write(fd, dsdp, SIZEOF_SDT_HDR); 699945137d9SNate Lawson write(fd, dsdp->body, dsdp->len - SIZEOF_SDT_HDR); 700945137d9SNate Lawson close(fd); 701945137d9SNate Lawson 702945137d9SNate Lawson /* Run iasl -d on the temp file */ 703945137d9SNate Lawson if (fork() == 0) { 704945137d9SNate Lawson close(STDOUT_FILENO); 705945137d9SNate Lawson if (vflag == 0) 706945137d9SNate Lawson close(STDERR_FILENO); 707945137d9SNate Lawson execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, 0); 708945137d9SNate Lawson err(1, "exec"); 709c62f1cccSMitsuru IWASAKI } 710c62f1cccSMitsuru IWASAKI 711945137d9SNate Lawson wait(NULL); 712945137d9SNate Lawson unlink(tmpstr); 713945137d9SNate Lawson 714945137d9SNate Lawson /* Dump iasl's output to stdout */ 715945137d9SNate Lawson fp = fopen("acpidump.dsl", "r"); 716945137d9SNate Lawson unlink("acpidump.dsl"); 717945137d9SNate Lawson if (fp == NULL) { 718945137d9SNate Lawson perror("iasl tmp file (read)"); 719945137d9SNate Lawson return; 720945137d9SNate Lawson } 721945137d9SNate Lawson while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 722945137d9SNate Lawson fwrite(buf, 1, len, stdout); 723945137d9SNate Lawson fclose(fp); 724c62f1cccSMitsuru IWASAKI } 725c62f1cccSMitsuru IWASAKI 726945137d9SNate Lawson void 727945137d9SNate Lawson sdt_print_all(struct ACPIsdt *rsdp) 728c62f1cccSMitsuru IWASAKI { 729945137d9SNate Lawson acpi_handle_rsdt(rsdp); 730c62f1cccSMitsuru IWASAKI } 731c62f1cccSMitsuru IWASAKI 732945137d9SNate Lawson /* Fetch a table matching the given signature via the RSDT */ 733945137d9SNate Lawson struct ACPIsdt * 734945137d9SNate Lawson sdt_from_rsdt(struct ACPIsdt *rsdt, const char *sig) 735c62f1cccSMitsuru IWASAKI { 736945137d9SNate Lawson struct ACPIsdt *sdt; 737a74172abSNate Lawson vm_offset_t addr; 738a74172abSNate Lawson int entries, i; 739945137d9SNate Lawson 740a74172abSNate Lawson entries = (rsdt->len - SIZEOF_SDT_HDR) / addr_size; 741945137d9SNate Lawson for (i = 0; i < entries; i++) { 742a74172abSNate Lawson switch (addr_size) { 743a74172abSNate Lawson case 4: 744a74172abSNate Lawson addr = le32dec((char*)rsdt->body + i * addr_size); 745a74172abSNate Lawson break; 746a74172abSNate Lawson case 8: 747a74172abSNate Lawson addr = le64dec((char*)rsdt->body + i * addr_size); 748a74172abSNate Lawson break; 749a74172abSNate Lawson default: 750a74172abSNate Lawson assert((addr = 0)); 751a74172abSNate Lawson } 752a74172abSNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(addr); 753a74172abSNate Lawson if (memcmp(sdt->signature, sig, strlen(sig))) 754a74172abSNate Lawson continue; 755945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 756945137d9SNate Lawson errx(1, "RSDT entry %d is corrupt", i); 757945137d9SNate Lawson return (sdt); 758c62f1cccSMitsuru IWASAKI } 759c62f1cccSMitsuru IWASAKI 760945137d9SNate Lawson return (NULL); 761c62f1cccSMitsuru IWASAKI } 762c62f1cccSMitsuru IWASAKI 763945137d9SNate Lawson struct ACPIsdt * 7648e6a8737SNate Lawson dsdt_from_fadt(struct FADTbody *fadt) 765c62f1cccSMitsuru IWASAKI { 766945137d9SNate Lawson struct ACPIsdt *sdt; 767c62f1cccSMitsuru IWASAKI 7688e6a8737SNate Lawson sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr); 769945137d9SNate Lawson if (acpi_checksum(sdt, sdt->len)) 770945137d9SNate Lawson errx(1, "DSDT is corrupt\n"); 771945137d9SNate Lawson return (sdt); 772c62f1cccSMitsuru IWASAKI } 773