From: marco Date: Thu, 5 Aug 2010 17:30:28 +0000 (+0000) Subject: kill kill kill the aml parser, kill kill kill it until it is dead X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1279320419ceac0e7d13b56223a29900ec77e073;p=openbsd kill kill kill the aml parser, kill kill kill it until it is dead ok deraadt --- diff --git a/usr.sbin/acpidump/Makefile b/usr.sbin/acpidump/Makefile index 4700686d6af..d30a2ecd765 100644 --- a/usr.sbin/acpidump/Makefile +++ b/usr.sbin/acpidump/Makefile @@ -1,15 +1,13 @@ -# $OpenBSD: Makefile,v 1.3 2005/06/04 02:25:53 cloder Exp $ +# $OpenBSD: Makefile,v 1.4 2010/08/05 17:30:28 marco Exp $ .if (${MACHINE} == "i386") || (${MACHINE} == "amd64") -PROG= acpidump -SRCS= acpi.c acpi_user.c asl_dump.c aml_dump.c acpidump.c -SRCS+= aml_name.c aml_parse.c aml_amlmem.c aml_memman.c aml_obj.c -SRCS+= aml_common.c aml_evalobj.c aml_store.c +PROG= acpidump +SRCS= acpidump.c .else -NOPROG= yes +NOPROG= yes .endif -MAN= acpidump.8 +MAN= acpidump.8 VPATH=${.CURDIR}/aml CFLAGS+=-I${.CURDIR} diff --git a/usr.sbin/acpidump/acpi.c b/usr.sbin/acpidump/acpi.c deleted file mode 100644 index 86d397b6798..00000000000 --- a/usr.sbin/acpidump/acpi.c +++ /dev/null @@ -1,443 +0,0 @@ -/* $OpenBSD: acpi.c,v 1.7 2009/08/07 00:04:15 martynas Exp $ */ -/*- - * Copyright (c) 1998 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: acpi.c,v 1.7 2009/08/07 00:04:15 martynas Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/acpi.c,v 1.3 2000/11/08 02:37:00 iwasaki Exp $ - */ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "acpidump.h" - -#include "aml/aml_env.h" -#include "aml/aml_common.h" -#include "aml/aml_parse.h" - -#define BEGIN_COMMENT "/*\n" -#define END_COMMENT " */\n" - -struct ACPIsdt dsdt_header = { - "DSDT", 0, 1, 0, "OEMID", "OEMTBLID", 0x12345678, "CRTR", 0x12345678 -}; - -static void -acpi_trim_string(char *s, size_t length) -{ - - /* Trim trailing spaces and NULLs */ - while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) - s[length-- - 1] = '\0'; -} - -static void -acpi_print_dsdt_definition(void) -{ - char oemid[6 + 1]; - char oemtblid[8 + 1]; - - acpi_trim_string(dsdt_header.oemid, 6); - acpi_trim_string(dsdt_header.oemtblid, 8); - strncpy(oemid, dsdt_header.oemid, 6); - oemid[6] = '\0'; - strncpy(oemtblid, dsdt_header.oemtblid, 8); - oemtblid[8] = '\0'; - - printf("DefinitionBlock (\n" - "\"acpi_dsdt.aml\",\t//Output filename\n" - "\"DSDT\",\t\t\t//Signature\n" - "0x%x,\t\t\t//DSDT Revision\n" - "\"%s\",\t\t\t//OEMID\n" - "\"%s\",\t\t//TABLE ID\n" - "0x%x\t\t\t//OEM Revision\n)\n", - dsdt_header.rev, oemid, oemtblid, dsdt_header.oemrev); -} - -static void -acpi_print_string(char *s, size_t length) -{ - int c; - - /* Trim trailing spaces and NULLs */ - while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) - length--; - - while (length--) { - c = *s++; - putchar(c); - } -} - -static void -acpi_handle_dsdt(struct ACPIsdt *dsdp) -{ - u_int8_t *dp; - u_int8_t *end; - - acpi_print_dsdt(dsdp); - - dp = (u_int8_t *)dsdp->body; - end = (u_int8_t *)dsdp + dsdp->len; - - if (aml_dumpfile == NULL) - acpi_dump_dsdt(dp, end); -} - -static void -acpi_handle_facp(struct FACPbody *facp) -{ - struct ACPIsdt *dsdp; - - acpi_print_facp(facp); - dsdp = (struct ACPIsdt *) acpi_map_sdt(facp->dsdt_ptr); - if (acpi_checksum(dsdp, dsdp->len)) - errx(1, "DSDT is corrupt"); - acpi_handle_dsdt(dsdp); - aml_dump(dsdp); -} - -static void -init_namespace() -{ - struct aml_environ env; - struct aml_name *newname; - - aml_new_name_group(AML_NAME_GROUP_OS_DEFINED); - env.curname = aml_get_rootname(); - newname = aml_create_name(&env, "\\_OS_"); - newname->property = aml_alloc_object(aml_t_string, NULL); - newname->property->str.needfree = 0; - newname->property->str.string = "Microsoft Windows NT"; -} - -/* - * Public interfaces - */ - -void -acpi_dump_dsdt(u_int8_t *dp, u_int8_t *end) -{ - extern struct aml_environ asl_env; - - acpi_print_dsdt_definition(); - - /* 1st stage: parse only w/o printing */ - init_namespace(); - aml_new_name_group((long)dp); - bzero(&asl_env, sizeof(asl_env)); - - asl_env.dp = dp; - asl_env.end = end; - asl_env.curname = aml_get_rootname(); - - aml_local_stack_push(aml_local_stack_create()); - aml_parse_objectlist(&asl_env, 0); - aml_local_stack_delete(aml_local_stack_pop()); - - assert(asl_env.dp == asl_env.end); - asl_env.dp = dp; - - /* 2nd stage: dump whole object list */ - printf("\n{\n"); - asl_dump_objectlist(&dp, end, 0); - printf("\n}\n"); - assert(dp == end); -} - -void -acpi_print_sdt(struct ACPIsdt *sdp) -{ - - printf(BEGIN_COMMENT); - acpi_print_string(sdp->signature, 4); - printf(": Length=%d, Revision=%d, Checksum=%d,\n", - sdp->len, sdp->rev, sdp->check); - printf("\tOEMID="); - acpi_print_string(sdp->oemid, 6); - printf(", OEM Table ID="); - acpi_print_string(sdp->oemtblid, 8); - printf(", OEM Revision=0x%x,\n", sdp->oemrev); - printf("\tCreator ID="); - acpi_print_string(sdp->creator, 4); - printf(", Creator Revision=0x%x\n", sdp->crerev); - printf(END_COMMENT); - if (!memcmp(sdp->signature, "DSDT", 4)) { - memcpy(&dsdt_header, sdp, sizeof(dsdt_header)); - } -} - -void -acpi_print_rsdt(struct ACPIsdt *rsdp) -{ - int i, entries; - - acpi_print_sdt(rsdp); - entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); - printf(BEGIN_COMMENT); - printf("\tEntries={ "); - for (i = 0; i < entries; i++) { - if (i > 0) - printf(", "); - printf("0x%08x", rsdp->body[i]); - } - printf(" }\n"); - printf(END_COMMENT); -} - -void -acpi_print_facp(struct FACPbody *facp) -{ - char sep; - - printf(BEGIN_COMMENT); - printf("\tDSDT=0x%x\n", facp->dsdt_ptr); - printf("\tINT_MODEL=%s\n", facp->int_model ? "APIC" : "PIC"); - printf("\tSCI_INT=%d\n", facp->sci_int); - printf("\tSMI_CMD=0x%x, ", facp->smi_cmd); - printf("ACPI_ENABLE=0x%x, ", facp->acpi_enable); - printf("ACPI_DISABLE=0x%x, ", facp->acpi_disable); - printf("S4BIOS_REQ=0x%x\n", facp->s4biosreq); - if (facp->pm1a_evt_blk) - printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", - facp->pm1a_evt_blk, - facp->pm1a_evt_blk + facp->pm1_evt_len - 1); - if (facp->pm1b_evt_blk) - printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", - facp->pm1b_evt_blk, - facp->pm1b_evt_blk + facp->pm1_evt_len - 1); - if (facp->pm1a_cnt_blk) - printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", - facp->pm1a_cnt_blk, - facp->pm1a_cnt_blk + facp->pm1_cnt_len - 1); - if (facp->pm1b_cnt_blk) - printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", - facp->pm1b_cnt_blk, - facp->pm1b_cnt_blk + facp->pm1_cnt_len - 1); - if (facp->pm2_cnt_blk) - printf("\tPM2_CNT_BLK=0x%x-0x%x\n", - facp->pm2_cnt_blk, - facp->pm2_cnt_blk + facp->pm2_cnt_len - 1); - if (facp->pm_tmr_blk) - printf("\tPM2_TMR_BLK=0x%x-0x%x\n", - facp->pm_tmr_blk, - facp->pm_tmr_blk + facp->pm_tmr_len - 1); - if (facp->gpe0_blk) - printf("\tPM2_GPE0_BLK=0x%x-0x%x\n", - facp->gpe0_blk, - facp->gpe0_blk + facp->gpe0_len - 1); - if (facp->gpe1_blk) - printf("\tPM2_GPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", - facp->gpe1_blk, - facp->gpe1_blk + facp->gpe1_len - 1, - facp->gpe1_base); - printf("\tP_LVL2_LAT=%dms, P_LVL3_LAT=%dms\n", - facp->p_lvl2_lat, facp->p_lvl3_lat); - printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", - facp->flush_size, facp->flush_stride); - printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", - facp->duty_off, facp->duty_width); - printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", - facp->day_alrm, facp->mon_alrm, facp->century); - printf("\tFlags="); - sep = '{'; - -#define PRINTFLAG(xx) do { \ - if (facp->flags & ACPI_FACP_FLAG_## xx) { \ - printf("%c%s", sep, #xx); sep = ','; \ - } \ -} while (0) - - PRINTFLAG(WBINVD); - PRINTFLAG(WBINVD_FLUSH); - PRINTFLAG(PROC_C1); - PRINTFLAG(P_LVL2_UP); - PRINTFLAG(PWR_BUTTON); - PRINTFLAG(SLP_BUTTON); - PRINTFLAG(FIX_RTC); - PRINTFLAG(RTC_S4); - PRINTFLAG(TMR_VAL_EXT); - PRINTFLAG(DCK_CAP); - -#undef PRINTFLAG - - printf("}\n"); - printf(END_COMMENT); -} - -void -acpi_print_dsdt(struct ACPIsdt *dsdp) -{ - - acpi_print_sdt(dsdp); -} - -int -acpi_checksum(void *p, size_t length) -{ - u_int8_t *bp; - u_int8_t sum; - - bp = p; - sum = 0; - while (length--) - sum += *bp++; - - return (sum); -} - -struct ACPIsdt * -acpi_map_sdt(vm_offset_t pa) -{ - struct ACPIsdt *sp; - - sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); - sp = acpi_map_physical(pa, sp->len); - return (sp); -} - -void -acpi_print_rsd_ptr(struct ACPIrsdp *rp) -{ - - printf(BEGIN_COMMENT); - printf("RSD PTR: Checksum=%d, OEMID=", rp->sum); - acpi_print_string(rp->oem, 6); - printf(", RsdtAddress=0x%08x\n", rp->addr); - printf(END_COMMENT); -} - -void -acpi_handle_rsdt(struct ACPIsdt *rsdp) -{ - int i; - int entries; - struct ACPIsdt *sdp; - - aml_dump(rsdp); - entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); - acpi_print_rsdt(rsdp); - for (i = 0; i < entries; i++) { - sdp = (struct ACPIsdt *) acpi_map_sdt(rsdp->body[i]); - if (acpi_checksum(sdp, sdp->len)) - errx(1, "RSDT entry %d is corrupt", i); - aml_dump(sdp); - if (!memcmp(sdp->signature, "FACP", 4)) { - acpi_handle_facp((struct FACPbody *) sdp->body); - } else { - acpi_print_sdt(sdp); - } - } -} - -/* - * Dummy functions - */ - -void -aml_dbgr(struct aml_environ *env1, struct aml_environ *env2) -{ - /* do nothing */ -} - -int -aml_region_read_simple(struct aml_region_handle *h, vm_offset_t offset, - u_int32_t *valuep) -{ - return (0); -} - -int -aml_region_write_simple(struct aml_region_handle *h, vm_offset_t offset, - u_int32_t value) -{ - return (0); -} - -u_int32_t -aml_region_prompt_read(struct aml_region_handle *h, u_int32_t value) -{ - return (0); -} - -u_int32_t -aml_region_prompt_write(struct aml_region_handle *h, u_int32_t value) -{ - return (0); -} - -int -aml_region_prompt_update_value(u_int32_t orgval, u_int32_t value, - struct aml_region_handle *h) -{ - return (0); -} - -u_int32_t -aml_region_read(struct aml_environ *env, int regtype, u_int32_t flags, - u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen) -{ - return (0); -} - -int -aml_region_write(struct aml_environ *env, int regtype, u_int32_t flags, - u_int32_t value, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen) -{ - return (0); -} - -int -aml_region_write_from_buffer(struct aml_environ *env, int regtype, - u_int32_t flags, u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset, - u_int32_t bitlen) -{ - return (0); -} - -int -aml_region_bcopy(struct aml_environ *env, int regtype, u_int32_t flags, - u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen, - u_int32_t dflags, u_int32_t daddr, - u_int32_t dbitoffset, u_int32_t dbitlen) -{ - return (0); -} - -int -aml_region_read_into_buffer(struct aml_environ *env, int regtype, - u_int32_t flags, u_int32_t addr, u_int32_t bitoffset, - u_int32_t bitlen, u_int8_t *buffer) -{ - return (0); -} - diff --git a/usr.sbin/acpidump/acpi_user.c b/usr.sbin/acpidump/acpi_user.c deleted file mode 100644 index 3fbe4901051..00000000000 --- a/usr.sbin/acpidump/acpi_user.c +++ /dev/null @@ -1,167 +0,0 @@ -/* $OpenBSD: acpi_user.c,v 1.6 2008/06/06 10:16:03 marco Exp $ */ -/*- - * Copyright (c) 1999 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: acpi_user.c,v 1.6 2008/06/06 10:16:03 marco Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/acpi_user.c,v 1.3 2000/11/08 02:37:00 iwasaki Exp $ - */ -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "acpidump.h" - -#define vm_page_size sysconf(_SC_PAGESIZE) - -static int acpi_mem_fd = -1; - -struct acpi_user_mapping { - LIST_ENTRY(acpi_user_mapping) link; - vm_offset_t pa; - caddr_t va; - size_t size; -}; - -LIST_HEAD(acpi_user_mapping_list, acpi_user_mapping) maplist; - -static void -acpi_user_init() -{ - - if (acpi_mem_fd == -1) { - acpi_mem_fd = open("/dev/mem", O_RDONLY); - if (acpi_mem_fd == -1) - err(1, "opening /dev/mem"); - LIST_INIT(&maplist); - } -} - -static struct acpi_user_mapping * -acpi_user_find_mapping(vm_offset_t pa, size_t size) -{ - struct acpi_user_mapping *map; - - /* First search for an existing mapping */ - for (map = LIST_FIRST(&maplist); map; map = LIST_NEXT(map, link)) { - if (map->pa <= pa && map->size >= pa + size - map->pa) - return (map); - } - - /* Then create a new one */ - size = round_page(pa + size) - trunc_page(pa); - pa = trunc_page(pa); - map = malloc(sizeof(struct acpi_user_mapping)); - if (!map) - errx(1, "out of memory"); - map->pa = pa; - map->va = mmap(0, size, PROT_READ, MAP_SHARED, acpi_mem_fd, pa); - map->size = size; - if (map->va == MAP_FAILED) - err(1, "can't map address"); - LIST_INSERT_HEAD(&maplist, map, link); - - return (map); -} - -/* - * Public interfaces - */ - -struct ACPIrsdp * -acpi_find_rsd_ptr() -{ - int i; - u_int8_t buf[sizeof(struct ACPIrsdp)]; - - acpi_user_init(); - for (i = 0; i < 1024 * 1024; i += 16) { - lseek(acpi_mem_fd, i, SEEK_SET); - read(acpi_mem_fd, buf, 16); - if (!memcmp(buf, "RSD PTR ", 8)) { - /* Read the rest of the structure */ - read(acpi_mem_fd, buf + 16, sizeof(struct ACPIrsdp) - 16); - - /* Verify checksum before accepting it. */ - if (acpi_checksum(buf, sizeof(struct ACPIrsdp))) - continue; - - return (acpi_map_physical(i, sizeof(struct ACPIrsdp))); - } - } - - return (0); -} - -void * -acpi_map_physical(vm_offset_t pa, size_t size) -{ - struct acpi_user_mapping *map; - - map = acpi_user_find_mapping(pa, size); - return (map->va + (pa - map->pa)); -} - -void -acpi_load_dsdt(char *dumpfile, u_int8_t **dpp, u_int8_t **endp) -{ - u_int8_t *dp; - u_int8_t *end; - struct stat sb; - - if ((acpi_mem_fd = open(dumpfile, O_RDONLY)) == -1) { - errx(1, "opening %s", dumpfile); - } - - LIST_INIT(&maplist); - - if (fstat(acpi_mem_fd, &sb) == -1) { - errx(1, "fstat %s", dumpfile); - } - - dp = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, acpi_mem_fd, 0); - if (dp == MAP_FAILED) { - errx(1, "mmap %s", dumpfile); - } - - if (sb.st_size >= SIZEOF_SDT_HDR && strncmp(dp, "DSDT", 4) == 0) { - memcpy(&dsdt_header, dp, SIZEOF_SDT_HDR); - dp += SIZEOF_SDT_HDR; - sb.st_size -= SIZEOF_SDT_HDR; - } - - end = (u_int8_t *) dp + sb.st_size; - *dpp = dp; - *endp = end; -} diff --git a/usr.sbin/acpidump/acpidump.8 b/usr.sbin/acpidump/acpidump.8 index 9ec7888e29f..b303b842feb 100644 --- a/usr.sbin/acpidump/acpidump.8 +++ b/usr.sbin/acpidump/acpidump.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: acpidump.8,v 1.9 2008/10/30 22:08:57 sobrado Exp $ +.\" $OpenBSD: acpidump.8,v 1.10 2010/08/05 17:30:28 marco Exp $ .\" .\" Copyright (c) 1999 Doug Rabson .\" Copyright (c) 2000 Mitsuru IWASAKI @@ -29,7 +29,7 @@ .\" .\" $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.8,v 1.9 2001/09/05 19:21:25 dd Exp $ .\" -.Dd $Mdocdate: October 30 2008 $ +.Dd $Mdocdate: August 5 2010 $ .Dt ACPIDUMP 8 .Os .Sh NAME @@ -37,37 +37,8 @@ .Nd dump ACPI tables .Sh SYNOPSIS .Nm -.Op Fl f Ar dsdt_file_for_input -.Nm .Op Fl o Ar prefix_for_output .Sh DESCRIPTION -The -.Nm -command analyzes ACPI tables in physical memory and dumps them to standard output. -In addition, -.Nm -can disassemble some contents of the tables in AML -(ACPI Machine Language) -and dump them in ASL -(ACPI Source Language). -.Pp -ACPI tables have an notably essential data block called DSDT -(Differentiated System Description Table), -that includes information used on the kernel side such as -detailed information about PnP hardware, procedures for controlling -power management support, and so on. -.Nm -can extract a DSDT data block from physical memory and store it into -a DSDT data file, and can also generate an output in ASL -from a given DSDT data file. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl f Ar dsdt_file_for_input -Interpret AML data in DSDT from a file specified in -.Ar dsdt_file_for_input -and dumps them in ASL to standard output. -.It Fl o Ar prefix_for_output Store ACPI tables from physical memory into files specified by .Ar prefix_for_output . The files generated will @@ -76,93 +47,16 @@ be of the form ... is the signature of the ACPI Table; .Dq id is unique for each table. -.Pp -The following are common table signatures (there may be others): -RSDP, FACP, DSDT, SSDT, HPET, MCFG, SPMI, APIC, SPCR, SRAT, XSDT. -.El -.Pp -When -.Nm -is invoked with no options, it will search ACPI tables from physical -memory via a special file -.Pa /dev/mem -and dump them. -First, it searches Root System Description Pointer, -that has a signature -.Qq RSD PTR\ \& , -and then gets RSDT -(Root System Description Table), -which includes a list of pointers to physical memory addresses -for other tables. -RSDT itself and all other tables linked from RSDT are generically -called SDT -(System Description Table) -and their header has the common format which consists of items -such as Signature, Length, Revision, Checksum, OEMID, OEM Table ID, -OEM Revision, Creator ID, and Creator Revision. -.Nm -dumps the contents of these SDTs. -For further information about the formats of each table, -see chapter 5: ACPI Software Programming Model, -.Dq Advanced Configuration and Power Interface Specification Revision 1.0b -from Intel/Microsoft/Toshiba. -.Pp -There is always a pointer to a physical memory address in RSDT for FACP -(Fixed ACPI Description Table). -FACP defines static system information about power management support -(ACPI Hardware Register Implementation) -such as interrupt mode -(INT_MODEL), -SCI interrupt number, SMI command port -(SMI_CMD), -and the location of ACPI registers. -FACP also has a pointer to a physical memory address for DSDT, -which includes information used on the kernel side such as -PnP, power management support, and so on. -While the other tables are described in a fixed format, -DSDT consists of AML data which is compiled from sources -written in free formatted ASL, a description language for ACPI. -When -.Nm -outputs DSDT, it disassembles the AML data and -translates them into ASL. +Additionally a file called .headers will be created that contains +additional human readable information pertaining to this specific dump. .Sh FILES .Bl -tag -width /dev/mem .It Pa /dev/mem .El .Sh SEE ALSO -.\" .Xr acpi 4 , .Xr mem 4 -.\" .Xr acpiconf 8 , -.\" Xr amldb 8 -.Rs -.%T Advanced Configuration and Power Interface Specification -.%A Intel -.%A Microsoft -.%A Toshiba -.%R Revision 1.0b -.Re .Sh HISTORY The .Nm command first appeared in .Ox 3.8 . -.Sh AUTHORS -.An Doug Rabson Aq dfr@FreeBSD.org -.An Mitsuru IWASAKI Aq iwasaki@FreeBSD.org -.An Yasuo YOKOYAMA Aq yokoyama@jp.FreeBSD.org -.Pp -Some contributions made by: -.An Chitoshi Ohsawa Aq ohsawa@catv1.ccn-net.ne.jp , -.An Takayasu IWANASHI Aq takayasu@wendy.a.perfect-liberty.or.jp , -.An Yoshihiko SARUMARU Aq mistral@imasy.or.jp , -.An Hiroki Sato Aq hrs@FreeBSD.org , -.An Jordan Hargrave Aq jordan@openbsd.org -and -.An Michael Lucas Aq mwlucas@blackhelicopters.org . -.Sh BUGS -In the current implementation, -.Nm -doesn't dump any information of Firmware ACPI Control Structure -(FACS) -specified by a pointer in FACP. diff --git a/usr.sbin/acpidump/acpidump.c b/usr.sbin/acpidump/acpidump.c index a67179d24ea..e8c73c1defb 100644 --- a/usr.sbin/acpidump/acpidump.c +++ b/usr.sbin/acpidump/acpidump.c @@ -1,5 +1,5 @@ -/* $OpenBSD: acpidump.c,v 1.5 2008/09/10 14:59:51 miod Exp $ */ -/*- +/* $OpenBSD: acpidump.c,v 1.6 2010/08/05 17:30:28 marco Exp $ */ +/* * Copyright (c) 2000 Mitsuru IWASAKI * All rights reserved. * @@ -24,40 +24,481 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: acpidump.c,v 1.5 2008/09/10 14:59:51 miod Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.c,v 1.3 2000/11/08 02:37:00 iwasaki Exp $ */ #include #include #include +#include #include +#include #include #include -#include "acpidump.h" +#include +#include +#include +#include +#include + +#include + +#define vm_page_size sysconf(_SC_PAGESIZE) +#define PRINTFLAG(xx) \ + do { \ + if (facp->flags & ACPI_FACP_FLAG_## xx) { \ + fprintf(fhdr, "%c%s", sep, #xx); sep = ','; \ + } \ + } while (0) + + +typedef unsigned long vm_offset_t; + +struct ACPIrsdp { + u_char signature[8]; + u_char sum; + u_char oem[6]; + u_char res; + u_int32_t addr; +} __packed; + +struct ACPIsdt { + u_char signature[4]; + u_int32_t len; + u_char rev; + u_char check; + u_char oemid[6]; + u_char oemtblid[8]; + u_int32_t oemrev; + u_char creator[4]; + u_int32_t crerev; +#define SIZEOF_SDT_HDR 36 /* struct size except body */ + u_int32_t body[1];/* This member should be casted */ +} __packed; + +struct ACPIgas { + u_int8_t address_space_id; +#define ACPI_GAS_MEMORY 0 +#define ACPI_GAS_IO 1 +#define ACPI_GAS_PCI 2 +#define ACPI_GAS_EMBEDDED 3 +#define ACPI_GAS_SMBUS 4 +#define ACPI_GAS_FIXED 0x7f + u_int8_t register_bit_width; + u_int8_t register_bit_offset; + u_int8_t res; + u_int64_t address; +} __packed; + +struct FACPbody { + u_int32_t facs_ptr; + u_int32_t dsdt_ptr; + u_int8_t int_model; +#define ACPI_FACP_INTMODEL_PIC 0 /* Standard PC-AT PIC */ +#define ACPI_FACP_INTMODEL_APIC 1 /* Multiple APIC */ + u_char reserved1; + u_int16_t sci_int; + u_int32_t smi_cmd; + u_int8_t acpi_enable; + u_int8_t acpi_disable; + u_int8_t s4biosreq; + u_int8_t reserved2; + u_int32_t pm1a_evt_blk; + u_int32_t pm1b_evt_blk; + u_int32_t pm1a_cnt_blk; + u_int32_t pm1b_cnt_blk; + u_int32_t pm2_cnt_blk; + u_int32_t pm_tmr_blk; + u_int32_t gpe0_blk; + u_int32_t gpe1_blk; + u_int8_t pm1_evt_len; + u_int8_t pm1_cnt_len; + u_int8_t pm2_cnt_len; + u_int8_t pm_tmr_len; + u_int8_t gpe0_len; + u_int8_t gpe1_len; + u_int8_t gpe1_base; + u_int8_t reserved3; + u_int16_t p_lvl2_lat; + u_int16_t p_lvl3_lat; + u_int16_t flush_size; + u_int16_t flush_stride; + u_int8_t duty_off; + u_int8_t duty_width; + u_int8_t day_alrm; + u_int8_t mon_alrm; + u_int8_t century; + u_int16_t iapc_boot_arch; + u_char reserved4[1]; + u_int32_t flags; +#define ACPI_FACP_FLAG_WBINVD 1 /* WBINVD is correctly supported */ +#define ACPI_FACP_FLAG_WBINVD_FLUSH 2 /* WBINVD flushes caches */ +#define ACPI_FACP_FLAG_PROC_C1 4 /* C1 power state supported */ +#define ACPI_FACP_FLAG_P_LVL2_UP 8 /* C2 power state works on SMP */ +#define ACPI_FACP_FLAG_PWR_BUTTON 16 /* Power button uses control method */ +#define ACPI_FACP_FLAG_SLP_BUTTON 32 /* Sleep button uses control method */ +#define ACPI_FACP_FLAG_FIX_RTC 64 /* RTC wakeup not supported */ +#define ACPI_FACP_FLAG_RTC_S4 128 /* RTC can wakeup from S4 state */ +#define ACPI_FACP_FLAG_TMR_VAL_EXT 256 /* TMR_VAL is 32bit */ +#define ACPI_FACP_FLAG_DCK_CAP 512 /* Can support docking */ + struct ACPIgas reset_reg; + u_int8_t reset_value; + u_int8_t reserved5[3]; + u_int64_t x_firmware_ctrl; + u_int64_t x_dsdt; + struct ACPIgas x_pm1a_evt_blk; + struct ACPIgas x_pm1b_evt_blk; + struct ACPIgas x_pm1a_cnt_blk; + struct ACPIgas x_pm1b_cnt_blk; + struct ACPIgas x_pm2_cnt_blk; + struct ACPIgas x_pm_tmr_blk; + struct ACPIgas x_gpe0_blk; + struct ACPIgas x_gpe1_blk; +} __packed; + +struct acpi_user_mapping { + LIST_ENTRY(acpi_user_mapping) link; + vm_offset_t pa; + caddr_t va; + size_t size; +}; + +LIST_HEAD(acpi_user_mapping_list, acpi_user_mapping) maplist; + +int acpi_mem_fd = -1; +char *aml_dumpfile; +FILE *fhdr; + +struct ACPIsdt dsdt_header = { + "DSDT", 0, 1, 0, "OEMID", "OEMTBLID", 0x12345678, "CRTR", 0x12345678 +}; -static void -asl_dump_from_file(char *file) +int +acpi_checksum(void *p, size_t length) +{ + u_int8_t *bp; + u_int8_t sum; + + bp = p; + sum = 0; + while (length--) + sum += *bp++; + + return (sum); +} + +struct acpi_user_mapping * +acpi_user_find_mapping(vm_offset_t pa, size_t size) +{ + struct acpi_user_mapping *map; + + /* First search for an existing mapping */ + for (map = LIST_FIRST(&maplist); map; map = LIST_NEXT(map, link)) { + if (map->pa <= pa && map->size >= pa + size - map->pa) + return (map); + } + + /* Then create a new one */ + size = round_page(pa + size) - trunc_page(pa); + pa = trunc_page(pa); + map = malloc(sizeof(struct acpi_user_mapping)); + if (!map) + errx(1, "out of memory"); + map->pa = pa; + map->va = mmap(0, size, PROT_READ, MAP_SHARED, acpi_mem_fd, pa); + map->size = size; + if (map->va == MAP_FAILED) + err(1, "can't map address"); + LIST_INSERT_HEAD(&maplist, map, link); + + return (map); +} + +void * +acpi_map_physical(vm_offset_t pa, size_t size) +{ + struct acpi_user_mapping *map; + + map = acpi_user_find_mapping(pa, size); + return (map->va + (pa - map->pa)); +} + +void +acpi_user_init(void) +{ + if (acpi_mem_fd == -1) { + acpi_mem_fd = open("/dev/mem", O_RDONLY); + if (acpi_mem_fd == -1) + err(1, "opening /dev/mem"); + LIST_INIT(&maplist); + } +} + +struct ACPIrsdp * +acpi_find_rsd_ptr() +{ + int i; + u_int8_t buf[sizeof(struct ACPIrsdp)]; + + acpi_user_init(); + for (i = 0; i < 1024 * 1024; i += 16) { + lseek(acpi_mem_fd, i, SEEK_SET); + read(acpi_mem_fd, buf, 16); + if (!memcmp(buf, "RSD PTR ", 8)) { + /* Read the rest of the structure */ + read(acpi_mem_fd, buf + 16, sizeof(struct ACPIrsdp) - 16); + + /* Verify checksum before accepting it. */ + if (acpi_checksum(buf, sizeof(struct ACPIrsdp))) + continue; + + return (acpi_map_physical(i, sizeof(struct ACPIrsdp))); + } + } + + return (0); +} + +void +acpi_print_string(char *s, size_t length) +{ + int c; + + /* Trim trailing spaces and NULLs */ + while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) + length--; + + while (length--) { + c = *s++; + fputc(c, fhdr); + } +} + +void +acpi_print_rsd_ptr(struct ACPIrsdp *rp) +{ + fprintf(fhdr, "\n"); + fprintf(fhdr, "RSD PTR: Checksum=%d, OEMID=", rp->sum); + acpi_print_string(rp->oem, 6); + fprintf(fhdr, ", RsdtAddress=0x%08x\n", rp->addr); + fprintf(fhdr, "\n"); +} + +struct ACPIsdt * +acpi_map_sdt(vm_offset_t pa) +{ + struct ACPIsdt *sp; + + sp = acpi_map_physical(pa, sizeof(struct ACPIsdt)); + sp = acpi_map_physical(pa, sp->len); + return (sp); +} + +void +aml_dump(struct ACPIsdt *hdr) +{ + static int hdr_index; + char name[PATH_MAX]; + int fd; + mode_t mode; + + snprintf(name, sizeof(name), "%s.%c%c%c%c.%d", + aml_dumpfile, hdr->signature[0], hdr->signature[1], + hdr->signature[2], hdr->signature[3], + hdr_index++); + + mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, mode); + if (fd == -1) + err(1, "aml_dump"); + + write(fd, hdr, SIZEOF_SDT_HDR); + write(fd, hdr->body, hdr->len - SIZEOF_SDT_HDR); + close(fd); +} + +void +acpi_print_sdt(struct ACPIsdt *sdp) +{ + fprintf(fhdr, "\n"); + acpi_print_string(sdp->signature, 4); + fprintf(fhdr, ": Length=%d, Revision=%d, Checksum=%d,\n", + sdp->len, sdp->rev, sdp->check); + fprintf(fhdr, "\tOEMID="); + acpi_print_string(sdp->oemid, 6); + fprintf(fhdr, ", OEM Table ID="); + acpi_print_string(sdp->oemtblid, 8); + fprintf(fhdr, ", OEM Revision=0x%x,\n", sdp->oemrev); + fprintf(fhdr, "\tCreator ID="); + acpi_print_string(sdp->creator, 4); + fprintf(fhdr, ", Creator Revision=0x%x\n", sdp->crerev); + fprintf(fhdr, "\n"); + if (!memcmp(sdp->signature, "DSDT", 4)) + memcpy(&dsdt_header, sdp, sizeof(dsdt_header)); +} + +void +acpi_print_rsdt(struct ACPIsdt *rsdp) +{ + int i, entries; + + acpi_print_sdt(rsdp); + entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); + fprintf(fhdr, "\n"); + fprintf(fhdr, "\tEntries={ "); + for (i = 0; i < entries; i++) { + if (i > 0) + fprintf(fhdr, ", "); + fprintf(fhdr, "0x%08x", rsdp->body[i]); + } + fprintf(fhdr, " }\n"); + fprintf(fhdr, "\n"); +} + +void +acpi_print_facp(struct FACPbody *facp) +{ + char sep; + + fprintf(fhdr, "\n"); + fprintf(fhdr, "\tDSDT=0x%x\n", facp->dsdt_ptr); + fprintf(fhdr, "\tINT_MODEL=%s\n", facp->int_model ? "APIC" : "PIC"); + fprintf(fhdr, "\tSCI_INT=%d\n", facp->sci_int); + fprintf(fhdr, "\tSMI_CMD=0x%x, ", facp->smi_cmd); + fprintf(fhdr, "ACPI_ENABLE=0x%x, ", facp->acpi_enable); + fprintf(fhdr, "ACPI_DISABLE=0x%x, ", facp->acpi_disable); + fprintf(fhdr, "S4BIOS_REQ=0x%x\n", facp->s4biosreq); + if (facp->pm1a_evt_blk) + fprintf(fhdr, "\tPM1a_EVT_BLK=0x%x-0x%x\n", + facp->pm1a_evt_blk, + facp->pm1a_evt_blk + facp->pm1_evt_len - 1); + if (facp->pm1b_evt_blk) + fprintf(fhdr, "\tPM1b_EVT_BLK=0x%x-0x%x\n", + facp->pm1b_evt_blk, + facp->pm1b_evt_blk + facp->pm1_evt_len - 1); + if (facp->pm1a_cnt_blk) + fprintf(fhdr, "\tPM1a_CNT_BLK=0x%x-0x%x\n", + facp->pm1a_cnt_blk, + facp->pm1a_cnt_blk + facp->pm1_cnt_len - 1); + if (facp->pm1b_cnt_blk) + fprintf(fhdr, "\tPM1b_CNT_BLK=0x%x-0x%x\n", + facp->pm1b_cnt_blk, + facp->pm1b_cnt_blk + facp->pm1_cnt_len - 1); + if (facp->pm2_cnt_blk) + fprintf(fhdr, "\tPM2_CNT_BLK=0x%x-0x%x\n", + facp->pm2_cnt_blk, + facp->pm2_cnt_blk + facp->pm2_cnt_len - 1); + if (facp->pm_tmr_blk) + fprintf(fhdr, "\tPM2_TMR_BLK=0x%x-0x%x\n", + facp->pm_tmr_blk, + facp->pm_tmr_blk + facp->pm_tmr_len - 1); + if (facp->gpe0_blk) + fprintf(fhdr, "\tPM2_GPE0_BLK=0x%x-0x%x\n", + facp->gpe0_blk, + facp->gpe0_blk + facp->gpe0_len - 1); + if (facp->gpe1_blk) + fprintf(fhdr, "\tPM2_GPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", + facp->gpe1_blk, + facp->gpe1_blk + facp->gpe1_len - 1, + facp->gpe1_base); + fprintf(fhdr, "\tP_LVL2_LAT=%dms, P_LVL3_LAT=%dms\n", + facp->p_lvl2_lat, facp->p_lvl3_lat); + fprintf(fhdr, "\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", + facp->flush_size, facp->flush_stride); + fprintf(fhdr, "\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", + facp->duty_off, facp->duty_width); + fprintf(fhdr, "\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", + facp->day_alrm, facp->mon_alrm, facp->century); + fprintf(fhdr, "\tFlags="); + sep = '{'; + + PRINTFLAG(WBINVD); + PRINTFLAG(WBINVD_FLUSH); + PRINTFLAG(PROC_C1); + PRINTFLAG(P_LVL2_UP); + PRINTFLAG(PWR_BUTTON); + PRINTFLAG(SLP_BUTTON); + PRINTFLAG(FIX_RTC); + PRINTFLAG(RTC_S4); + PRINTFLAG(TMR_VAL_EXT); + PRINTFLAG(DCK_CAP); + + fprintf(fhdr, "}\n"); + fprintf(fhdr, "\n"); +} + +void +acpi_print_dsdt(struct ACPIsdt *dsdp) +{ + acpi_print_sdt(dsdp); +} + +void +acpi_handle_dsdt(struct ACPIsdt *dsdp) { u_int8_t *dp; u_int8_t *end; - acpi_load_dsdt(file, &dp, &end); - acpi_dump_dsdt(dp, end); + acpi_print_dsdt(dsdp); + + dp = (u_int8_t *)dsdp->body; + end = (u_int8_t *)dsdp + dsdp->len; +} + +void +acpi_handle_facp(struct FACPbody *facp) +{ + struct ACPIsdt *dsdp; + + acpi_print_facp(facp); + dsdp = (struct ACPIsdt *) acpi_map_sdt(facp->dsdt_ptr); + if (acpi_checksum(dsdp, dsdp->len)) + errx(1, "DSDT is corrupt"); + acpi_handle_dsdt(dsdp); + aml_dump(dsdp); } -static void -asl_dump_from_devmem() +void +acpi_handle_rsdt(struct ACPIsdt *rsdp) { - struct ACPIrsdp *rp; - struct ACPIsdt *rsdp; + int i; + int entries; + struct ACPIsdt *sdp; + + aml_dump(rsdp); + entries = (rsdp->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t); + acpi_print_rsdt(rsdp); + for (i = 0; i < entries; i++) { + sdp = (struct ACPIsdt *) acpi_map_sdt(rsdp->body[i]); + if (acpi_checksum(sdp, sdp->len)) + errx(1, "RSDT entry %d is corrupt", i); + aml_dump(sdp); + if (!memcmp(sdp->signature, "FACP", 4)) { + acpi_handle_facp((struct FACPbody *) sdp->body); + } else { + acpi_print_sdt(sdp); + } + } +} + +void +asl_dump_from_devmem(void) +{ + struct ACPIrsdp *rp; + struct ACPIsdt *rsdp; + char name[PATH_MAX]; + + snprintf(name, sizeof(name), "%s.headers", aml_dumpfile); rp = acpi_find_rsd_ptr(); if (!rp) errx(1, "Can't find ACPI information"); + fhdr = fopen(name, "w"); + if (fhdr == NULL) + err(1, "asl_dump_from_devmem"); + acpi_print_rsd_ptr(rp); rsdp = (struct ACPIsdt *) acpi_map_sdt(rp->addr); if (memcmp(rsdp->signature, "RSDT", 4) || @@ -65,35 +506,35 @@ asl_dump_from_devmem() errx(1, "RSDT is corrupted"); acpi_handle_rsdt(rsdp); + + fclose(fhdr); } -static void +void usage(void) { + extern char *__progname; - printf("usage: acpidump [-o dsdt_file_for_output]\n"); - printf(" acpidump [-f dsdt_file_for_input]\n"); + fprintf(stderr, "%s [-o prefix_for_output]\n", __progname); exit(1); } int main(int argc, char *argv[]) { - char c; + char c; - while ((c = getopt(argc, argv, "f:o:")) != -1) { - switch (c) { - case 'f': - asl_dump_from_file(optarg); - return (0); - case 'o': + while ((c = getopt(argc, argv, "o:")) != -1) { + if (c == 'o') aml_dumpfile = optarg; - break; - default: + else usage(); - } } + if (aml_dumpfile == NULL) + usage(); + asl_dump_from_devmem(); + return (0); } diff --git a/usr.sbin/acpidump/acpidump.h b/usr.sbin/acpidump/acpidump.h deleted file mode 100644 index 682f20c0a39..00000000000 --- a/usr.sbin/acpidump/acpidump.h +++ /dev/null @@ -1,185 +0,0 @@ -/* $OpenBSD: acpidump.h,v 1.3 2007/10/08 08:20:49 gilles Exp $ */ -/*- - * Copyright (c) 1999 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: acpidump.h,v 1.3 2007/10/08 08:20:49 gilles Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.h,v 1.2 2000/11/08 02:37:00 iwasaki Exp $ - */ - -#ifndef _ACPIDUMP_H_ -#define _ACPIDUMP_H_ -#include - -typedef unsigned long vm_offset_t; - -/* Generic Address structure */ -struct ACPIgas { - u_int8_t address_space_id; -#define ACPI_GAS_MEMORY 0 -#define ACPI_GAS_IO 1 -#define ACPI_GAS_PCI 2 -#define ACPI_GAS_EMBEDDED 3 -#define ACPI_GAS_SMBUS 4 -#define ACPI_GAS_FIXED 0x7f - u_int8_t register_bit_width; - u_int8_t register_bit_offset; - u_int8_t res; - u_int64_t address; -} __packed; - -/* Root System Description Pointer */ -struct ACPIrsdp { - u_char signature[8]; - u_char sum; - u_char oem[6]; - u_char res; - u_int32_t addr; -} __packed; - -/* System Description Table */ -struct ACPIsdt { - u_char signature[4]; - u_int32_t len; - u_char rev; - u_char check; - u_char oemid[6]; - u_char oemtblid[8]; - u_int32_t oemrev; - u_char creator[4]; - u_int32_t crerev; -#define SIZEOF_SDT_HDR 36 /* struct size except body */ - u_int32_t body[1];/* This member should be casted */ -} __packed; - -/* Fixed ACPI Description Table (body) */ -struct FACPbody { - u_int32_t facs_ptr; - u_int32_t dsdt_ptr; - u_int8_t int_model; -#define ACPI_FACP_INTMODEL_PIC 0 /* Standard PC-AT PIC */ -#define ACPI_FACP_INTMODEL_APIC 1 /* Multiple APIC */ - u_char reserved1; - u_int16_t sci_int; - u_int32_t smi_cmd; - u_int8_t acpi_enable; - u_int8_t acpi_disable; - u_int8_t s4biosreq; - u_int8_t reserved2; - u_int32_t pm1a_evt_blk; - u_int32_t pm1b_evt_blk; - u_int32_t pm1a_cnt_blk; - u_int32_t pm1b_cnt_blk; - u_int32_t pm2_cnt_blk; - u_int32_t pm_tmr_blk; - u_int32_t gpe0_blk; - u_int32_t gpe1_blk; - u_int8_t pm1_evt_len; - u_int8_t pm1_cnt_len; - u_int8_t pm2_cnt_len; - u_int8_t pm_tmr_len; - u_int8_t gpe0_len; - u_int8_t gpe1_len; - u_int8_t gpe1_base; - u_int8_t reserved3; - u_int16_t p_lvl2_lat; - u_int16_t p_lvl3_lat; - u_int16_t flush_size; - u_int16_t flush_stride; - u_int8_t duty_off; - u_int8_t duty_width; - u_int8_t day_alrm; - u_int8_t mon_alrm; - u_int8_t century; - u_int16_t iapc_boot_arch; - u_char reserved4[1]; - u_int32_t flags; -#define ACPI_FACP_FLAG_WBINVD 1 /* WBINVD is correctly supported */ -#define ACPI_FACP_FLAG_WBINVD_FLUSH 2 /* WBINVD flushes caches */ -#define ACPI_FACP_FLAG_PROC_C1 4 /* C1 power state supported */ -#define ACPI_FACP_FLAG_P_LVL2_UP 8 /* C2 power state works on SMP */ -#define ACPI_FACP_FLAG_PWR_BUTTON 16 /* Power button uses control method */ -#define ACPI_FACP_FLAG_SLP_BUTTON 32 /* Sleep button uses control method */ -#define ACPI_FACP_FLAG_FIX_RTC 64 /* RTC wakeup not supported */ -#define ACPI_FACP_FLAG_RTC_S4 128 /* RTC can wakeup from S4 state */ -#define ACPI_FACP_FLAG_TMR_VAL_EXT 256 /* TMR_VAL is 32bit */ -#define ACPI_FACP_FLAG_DCK_CAP 512 /* Can support docking */ - struct ACPIgas reset_reg; - u_int8_t reset_value; - u_int8_t reserved5[3]; - u_int64_t x_firmware_ctrl; - u_int64_t x_dsdt; - struct ACPIgas x_pm1a_evt_blk; - struct ACPIgas x_pm1b_evt_blk; - struct ACPIgas x_pm1a_cnt_blk; - struct ACPIgas x_pm1b_cnt_blk; - struct ACPIgas x_pm2_cnt_blk; - struct ACPIgas x_pm_tmr_blk; - struct ACPIgas x_gpe0_blk; - struct ACPIgas x_gpe1_blk; -} __packed; - -/* Firmware ACPI Control Structure */ -struct FACS { - u_char signature[4]; - u_int32_t len; - u_char hard_sig[4]; - /* - * NOTE This should be filled with physical address below 1MB!! - * sigh.... - */ - u_int32_t firm_wake_vec; - u_int32_t g_lock; /* bit field */ - /* 5.2.6.1 Global Lock */ -#define ACPI_GLOBAL_LOCK_PENDING 1 -#define ACPI_GLOBAL_LOCK_OWNED 2 - u_int32_t flags; /* bit field */ -#define ACPI_FACS_FLAG_S4BIOS_F 1 /* Supports S4BIOS_SEQ */ - char reserved[40]; -} __packed; - -void *acpi_map_physical(vm_offset_t, size_t); -struct ACPIrsdp *acpi_find_rsd_ptr(void); -int acpi_checksum(void *, size_t) - __attribute__ ((__bounded__(__buffer__,1,2))); -struct ACPIsdt *acpi_map_sdt(vm_offset_t); -void acpi_print_rsd_ptr(struct ACPIrsdp *); -void acpi_print_sdt(struct ACPIsdt *); -void acpi_print_rsdt(struct ACPIsdt *); -void acpi_print_facp(struct FACPbody *); -void acpi_print_dsdt(struct ACPIsdt *); - -void asl_dump_termobj(u_int8_t **, int); -void asl_dump_objectlist(u_int8_t **, u_int8_t *, int); - -void aml_dump(struct ACPIsdt *); - -void acpi_handle_rsdt(struct ACPIsdt *); -void acpi_load_dsdt(char *, u_int8_t **, u_int8_t **); -void acpi_dump_dsdt(u_int8_t *, u_int8_t *); -extern char *aml_dumpfile; -extern struct ACPIsdt dsdt_header; - -#endif /* !_ACPIDUMP_H_ */ diff --git a/usr.sbin/acpidump/aml_dump.c b/usr.sbin/acpidump/aml_dump.c deleted file mode 100644 index b18e957261d..00000000000 --- a/usr.sbin/acpidump/aml_dump.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $OpenBSD: aml_dump.c,v 1.2 2007/02/22 19:09:26 jordan Exp $ */ -/*- - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: aml_dump.c,v 1.2 2007/02/22 19:09:26 jordan Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/aml_dump.c,v 1.3 2000/11/08 02:37:00 iwasaki Exp $ - */ - -#include -#include - -#include -#include -#include - -#include "acpidump.h" - -char *aml_dumpfile = NULL; - -void -aml_dump(struct ACPIsdt *hdr) -{ - static int hdr_index; - char name[128]; - int fd; - mode_t mode; - - if (aml_dumpfile == NULL) { - return; - } - - snprintf(name, sizeof(name), "%s.%c%c%c%c.%d", - aml_dumpfile, hdr->signature[0], hdr->signature[1], - hdr->signature[2], hdr->signature[3], - hdr_index++); - - mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd == -1) { - return; - } - write(fd, hdr, SIZEOF_SDT_HDR); - write(fd, hdr->body, hdr->len - SIZEOF_SDT_HDR); - close(fd); -} diff --git a/usr.sbin/acpidump/asl_dump.c b/usr.sbin/acpidump/asl_dump.c deleted file mode 100644 index a0faa90eb8d..00000000000 --- a/usr.sbin/acpidump/asl_dump.c +++ /dev/null @@ -1,1191 +0,0 @@ -/* $OpenBSD: asl_dump.c,v 1.8 2008/06/06 10:16:47 marco Exp $ */ -/*- - * Copyright (c) 1999 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: asl_dump.c,v 1.8 2008/06/06 10:16:47 marco Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpidump/asl_dump.c,v 1.5 2001/10/23 14:53:58 takawata Exp $ - */ - -#include - -#include -#include -#include - -#include "acpidump.h" - -#include "aml/aml_env.h" - -struct aml_environ asl_env; - -static u_int32_t -asl_dump_pkglength(u_int8_t **dpp) -{ - u_int8_t *dp; - u_int32_t pkglength; - - dp = *dpp; - pkglength = *dp++; - switch (pkglength >> 6) { - case 0: - break; - case 1: - pkglength = (pkglength & 0xf) + (dp[0] << 4); - dp += 1; - break; - case 2: - pkglength = (pkglength & 0xf) + (dp[0] << 4) + (dp[1] << 12); - dp += 2; - break; - case 3: - pkglength = (pkglength & 0xf) - + (dp[0] << 4) + (dp[1] << 12) + (dp[2] << 20); - dp += 3; - break; - } - - *dpp = dp; - return (pkglength); -} - -static void -print_nameseg(u_int8_t *dp) -{ - - if (dp[3] != '_') - printf("%c%c%c%c", dp[0], dp[1], dp[2], dp[3]); - else if (dp[2] != '_') - printf("%c%c%c_", dp[0], dp[1], dp[2]); - else if (dp[1] != '_') - printf("%c%c__", dp[0], dp[1]); - else if (dp[0] != '_') - printf("%c___", dp[0]); -} - -static u_int8_t -asl_dump_bytedata(u_int8_t **dpp) -{ - u_int8_t *dp; - u_int8_t data; - - dp = *dpp; - data = dp[0]; - *dpp = dp + 1; - return (data); -} - -static u_int16_t -asl_dump_worddata(u_int8_t **dpp) -{ - u_int8_t *dp; - u_int16_t data; - - dp = *dpp; - data = dp[0] + (dp[1] << 8); - *dpp = dp + 2; - return (data); -} - -static u_int32_t -asl_dump_dworddata(u_int8_t **dpp) -{ - u_int8_t *dp; - u_int32_t data; - - dp = *dpp; - data = dp[0] + (dp[1] << 8) + (dp[2] << 16) + (dp[3] << 24); - *dpp = dp + 4; - return (data); -} - -static u_int8_t * -asl_dump_namestring(u_int8_t **dpp) -{ - u_int8_t *dp; - u_int8_t *name; - - dp = *dpp; - name = dp; - if (dp[0] == '\\') - dp++; - else if (dp[0] == '^') - while (dp[0] == '^') - dp++; - if (dp[0] == 0x00) /* NullName */ - dp++; - else if (dp[0] == 0x2e) /* DualNamePrefix */ - dp += 1 + 4 + 4;/* NameSeg, NameSeg */ - else if (dp[0] == 0x2f) { /* MultiNamePrefix */ - int segcount = dp[1]; - dp += 1 + 1 + segcount * 4; /* segcount * NameSeg */ - } else - dp += 4; /* NameSeg */ - - *dpp = dp; - return (name); -} - -static void -print_namestring(u_int8_t *dp) -{ - - if (dp[0] == '\\') { - putchar(dp[0]); - dp++; - } else if (dp[0] == '^') { - while (dp[0] == '^') { - putchar(dp[0]); - dp++; - } - } - if (dp[0] == 0x00) { /* NullName */ - /* printf(""); */ - dp++; - } else if (dp[0] == 0x2e) { /* DualNamePrefix */ - print_nameseg(dp + 1); - putchar('.'); - print_nameseg(dp + 5); - } else if (dp[0] == 0x2f) { /* MultiNamePrefix */ - int segcount = dp[1]; - int i; - for (i = 0, dp += 2; i < segcount; i++, dp += 4) { - if (i > 0) - putchar('.'); - print_nameseg(dp); - } - } else /* NameSeg */ - print_nameseg(dp); -} - -static void -print_indent(int indent) -{ - int i; - - for (i = 0; i < indent; i++) - printf(" "); -} - -#define ASL_ENTER_SCOPE(dp_orig, old_name) do { \ - u_int8_t *dp_copy; \ - u_int8_t *name; \ - old_name = asl_env.curname; \ - dp_copy = dp_orig; \ - name = asl_dump_namestring(&dp_copy); \ - asl_env.curname = aml_search_name(&asl_env, name); \ -} while(0) - -#define ASL_LEAVE_SCOPE(old_name) do { \ - asl_env.curname = old_name; \ -} while(0) - -#define ASL_CREATE_LOCALNAMEOBJ(dp) do { \ - if(scope_within_method){ \ - aml_create_name(&asl_env, dp); \ - } \ -}while(0); - -static void -asl_dump_defscope(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - struct aml_name *oname; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - - printf("Scope("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - printf(") {\n"); - end = start + pkglength; - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - -static void -asl_dump_defbuffer(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - printf("Buffer("); - asl_dump_termobj(&dp, indent); - printf(") {"); - while (dp < end) { - printf("0x%x", *dp++); - if (dp < end) - printf(", "); - } - printf(" }"); - - *dpp = dp; -} - -static void -asl_dump_defpackage(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t numelements; - u_int32_t pkglength; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - numelements = asl_dump_bytedata(&dp); - end = start + pkglength; - printf("Package(0x%x) {\n", numelements); - while (dp < end) { - print_indent(indent + 1); - asl_dump_termobj(&dp, indent + 1); - printf(",\n"); - } - - print_indent(indent); - printf("}"); - - dp = end; - - *dpp = dp; -} - -int scope_within_method = 0; - -static void -asl_dump_defmethod(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t flags; - u_int32_t pkglength; - struct aml_name *oname; - int swi; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - - swi = scope_within_method; - scope_within_method = 0; - - printf("Method("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - flags = *dp++; - if (flags) { - printf(", %d", flags & 7); - if (flags & 8) { - printf(", Serialized"); - } - } - printf(") {\n"); - end = start + pkglength; - scope_within_method = 1; - asl_dump_objectlist(&dp, end, indent + 1); - scope_within_method = swi; - print_indent(indent); - printf("}"); - - assert(dp == end); - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - - -static void -asl_dump_defopregion(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - const char *regions[] = { - "SystemMemory", - "SystemIO", - "PCI_Config", - "EmbeddedControl", - "SMBus", - }; - - dp = *dpp; - printf("OperationRegion("); - ASL_CREATE_LOCALNAMEOBJ(dp); - asl_dump_termobj(&dp, indent); /* Name */ - printf(", %s, ", regions[*dp++]); /* Space */ - asl_dump_termobj(&dp, indent); /* Offset */ - printf(", "); - asl_dump_termobj(&dp, indent); /* Length */ - printf(")"); - - *dpp = dp; -} - -static const char *accessnames[] = { - "AnyAcc", - "ByteAcc", - "WordAcc", - "DWordAcc", - "BlockAcc", - "SMBSendRecvAcc", - "SMBQuickAcc" -}; - -static int -asl_dump_field(u_int8_t **dpp, u_int32_t offset) -{ - u_int8_t *dp; - u_int8_t *name; - u_int8_t access, attribute; - u_int32_t width; - - dp = *dpp; - switch (*dp) { - case '\\': - case '^': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case '.': - case '/': - ASL_CREATE_LOCALNAMEOBJ(dp); - name = asl_dump_namestring(&dp); - width = asl_dump_pkglength(&dp); - offset += width; - print_namestring(name); - printf(",\t%d", width); - break; - case 0x00: - dp++; - width = asl_dump_pkglength(&dp); - offset += width; - if ((offset % 8) == 0) { - printf("Offset(0x%x)", offset / 8); - } else { - printf(",\t%d", width); - } - break; - case 0x01: - access = dp[1]; - attribute = dp[2]; - dp += 3; - printf("AccessAs(%s, %d)", accessnames[access], attribute); - break; - } - - *dpp = dp; - return (offset); -} - -static void -asl_dump_fieldlist(u_int8_t **dpp, u_int8_t *end, int indent) -{ - u_int8_t *dp; - u_int32_t offset; - - dp = *dpp; - offset = 0; - while (dp < end) { - print_indent(indent); - offset = asl_dump_field(&dp, offset); - if (dp < end) - printf(",\n"); - else - printf("\n"); - } - - *dpp = dp; -} - -static void -asl_dump_deffield(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t flags; - u_int32_t pkglength; - static const char *lockrules[] = {"NoLock", "Lock"}; - static const char *updaterules[] = {"Preserve", "WriteAsOnes", - "WriteAsZeros", "*Error*"}; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("Field("); - asl_dump_termobj(&dp, indent); /* Name */ - flags = asl_dump_bytedata(&dp); - printf(", %s, %s, %s) {\n", - accessnames[flags & 0xf], - lockrules[(flags >> 4) & 1], - updaterules[(flags >> 5) & 3]); - asl_dump_fieldlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_defindexfield(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t flags; - u_int32_t pkglength; - static const char *lockrules[] = {"NoLock", "Lock"}; - static const char *updaterules[] = {"Preserve", "WriteAsOnes", - "WriteAsZeros", "*Error*"}; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("IndexField("); - asl_dump_termobj(&dp, indent); /* Name1 */ - printf(", "); - asl_dump_termobj(&dp, indent); /* Name2 */ - flags = asl_dump_bytedata(&dp); - printf(", %s, %s, %s) {\n", - accessnames[flags & 0xf], - lockrules[(flags >> 4) & 1], - updaterules[(flags >> 5) & 3]); - asl_dump_fieldlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_defbankfield(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t flags; - u_int32_t pkglength; - static const char *lockrules[] = {"NoLock", "Lock"}; - static const char *updaterules[] = {"Preserve", "WriteAsOnes", - "WriteAsZeros", "*Error*"}; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - printf("BankField("); - asl_dump_termobj(&dp, indent); /* Name1 */ - printf(", "); - asl_dump_termobj(&dp, indent); /* Name2 */ - printf(", "); - asl_dump_termobj(&dp, indent); /* BankValue */ - flags = asl_dump_bytedata(&dp); - printf(", %s, %s, %s) {\n", - accessnames[flags & 0xf], - lockrules[(flags >> 4) & 1], - updaterules[(flags >> 5) & 3]); - asl_dump_fieldlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_defdevice(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - struct aml_name *oname; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("Device("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - printf(") {\n"); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - -static void -asl_dump_defprocessor(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t procid; - u_int8_t pblklen; - u_int32_t pkglength; - u_int32_t pblkaddr; - struct aml_name *oname; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("Processor("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - procid = asl_dump_bytedata(&dp); - pblkaddr = asl_dump_dworddata(&dp); - pblklen = asl_dump_bytedata(&dp); - printf(", %d, 0x%x, 0x%x) {\n", procid, pblkaddr, pblklen); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - -static void -asl_dump_defpowerres(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int8_t systemlevel; - u_int16_t resourceorder; - u_int32_t pkglength; - struct aml_name *oname; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("PowerResource("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - systemlevel = asl_dump_bytedata(&dp); - resourceorder = asl_dump_worddata(&dp); - printf(", %d, %d) {\n", systemlevel, resourceorder); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - -static void -asl_dump_defthermalzone(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - struct aml_name *oname; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("ThermalZone("); - ASL_ENTER_SCOPE(dp, oname); - asl_dump_termobj(&dp, indent); - printf(") {\n"); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - ASL_LEAVE_SCOPE(oname); - *dpp = dp; -} - -static void -asl_dump_defif(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("If("); - asl_dump_termobj(&dp, indent); - printf(") {\n"); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_defelse(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("Else {\n"); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_defwhile(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *start; - u_int8_t *end; - u_int32_t pkglength; - - dp = *dpp; - start = dp; - pkglength = asl_dump_pkglength(&dp); - end = start + pkglength; - - printf("While("); - asl_dump_termobj(&dp, indent); - printf(") {\n"); - asl_dump_objectlist(&dp, end, indent + 1); - print_indent(indent); - printf("}"); - - assert(dp == end); - - *dpp = dp; -} - -static void -asl_dump_oparg(u_int8_t **dpp, int indent, const char *mnem, - const char *fmt) -{ - int idx; - const char *pfx=""; - - printf("%s(", mnem); - for (idx=0; fmt[idx]; idx++) { - if (fmt[idx] == 'N') { - ASL_CREATE_LOCALNAMEOBJ(*dpp); - } - else if (fmt[idx] == 'o' && **dpp == 0x00) { - /* Optional Argument */ - (*dpp)++; - continue; - } - - printf(pfx); - if (fmt[idx] == 'b') - printf("0x%x", asl_dump_bytedata(dpp)); - else if (fmt[idx] == 'w') - printf("0x%x", asl_dump_worddata(dpp)); - else if (fmt[idx] == 'd') - printf("0x%x", asl_dump_dworddata(dpp)); - else - asl_dump_termobj(dpp, indent); - pfx = ", "; - } - printf(")"); -} -/* - * Public interfaces - */ -void -asl_dump_termobj(u_int8_t **dpp, int indent) -{ - u_int8_t *dp; - u_int8_t *name; - u_int8_t opcode; - struct aml_name *method; - const char *matchstr[] = { - "MTR", "MEQ", "MLE", "MLT", "MGE", "MGT", - }; - -#define OPTARG() do { \ - if (*dp == 0x00) { \ - dp++; \ - } else { \ - printf(", "); \ - asl_dump_termobj(&dp, indent); \ - } \ -} while (0) - - dp = *dpp; - opcode = *dp++; - switch (opcode) { - case '\\': - case '^': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': - case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': - case 'V': case 'W': case 'X': case 'Y': case 'Z': - case '_': - case '.': - case '/': - dp--; - print_namestring((name = asl_dump_namestring(&dp))); - if (scope_within_method == 1) { - method = aml_search_name(&asl_env, name); - if (method != NULL && method->property != NULL && - method->property->type == aml_t_method) { - int i, argnum; - - argnum = method->property->meth.argnum & 7; - printf("("); - for (i = 0; i < argnum; i++) { - asl_dump_termobj(&dp, indent); - if (i < (argnum-1)) { - printf(", "); - } - } - printf(")"); - } - } - break; - case 0x0a: /* BytePrefix */ - printf("0x%x", asl_dump_bytedata(&dp)); - break; - case 0x0b: /* WordPrefix */ - printf("0x%04x", asl_dump_worddata(&dp)); - break; - case 0x0c: /* DWordPrefix */ - printf("0x%08x", asl_dump_dworddata(&dp)); - break; - case 0x0d: /* StringPrefix */ - printf("\"%s\"", (const char *) dp); - while (*dp) - dp++; - dp++; /* NUL terminate */ - break; - case 0x00: /* ZeroOp */ - printf("Zero"); - break; - case 0x01: /* OneOp */ - printf("One"); - break; - case 0xff: /* OnesOp */ - printf("Ones"); - break; - case 0x06: /* AliasOp */ - asl_dump_oparg(&dp, indent, "Alias", "tN"); - break; - case 0x08: /* NameOp */ - asl_dump_oparg(&dp, indent, "Name", "Nt"); - break; - case 0x10: /* ScopeOp */ - asl_dump_defscope(&dp, indent); - break; - case 0x11: /* BufferOp */ - asl_dump_defbuffer(&dp, indent); - break; - case 0x12: /* PackageOp */ - asl_dump_defpackage(&dp, indent); - break; - case 0x14: /* MethodOp */ - asl_dump_defmethod(&dp, indent); - break; - case 0x5b: /* ExtOpPrefix */ - opcode = *dp++; - switch (opcode) { - case 0x01: /* MutexOp */ - printf("Mutex("); - ASL_CREATE_LOCALNAMEOBJ(dp); - asl_dump_termobj(&dp, indent); - printf(", %d)", *dp++); - break; - case 0x02: /* EventOp */ - asl_dump_oparg(&dp, indent, "Event", "t"); - break; - case 0x12: /* CondRefOfOp */ - asl_dump_oparg(&dp, indent, "CondRefOf", "tt"); - break; - case 0x13: /* CreateFieldOp */ - asl_dump_oparg(&dp, indent, "CreateField", "tiiN"); - break; - case 0x1F: /* LoadTableOp */ - asl_dump_oparg(&dp, indent, "LoadTable", "tttttt"); - break; - case 0x20: /* LoadOp */ - asl_dump_oparg(&dp, indent, "Load", "tt"); - break; - case 0x21: /* StallOp */ - asl_dump_oparg(&dp, indent, "Stall", "i"); - break; - case 0x22: /* SleepOp */ - asl_dump_oparg(&dp, indent, "Sleep", "i"); - break; - case 0x23: /* AcquireOp */ - asl_dump_oparg(&dp, indent, "Acquire", "tw"); - break; - case 0x24: /* SignalOp */ - asl_dump_oparg(&dp, indent, "Signal", "t"); - break; - case 0x25: /* WaitOp */ - asl_dump_oparg(&dp, indent, "Wait", "ti"); - break; - case 0x26: /* ResetOp */ - asl_dump_oparg(&dp, indent, "Reset", "t"); - break; - case 0x27: /* ReleaseOp */ - asl_dump_oparg(&dp, indent, "Release", "t"); - break; - case 0x28: /* FromBCDOp */ - asl_dump_oparg(&dp, indent, "FromBCD", "io"); - break; - case 0x29: /* ToBCDOp */ - asl_dump_oparg(&dp, indent, "ToBCD", "io"); - break; - case 0x2a: /* UnloadOp */ - asl_dump_oparg(&dp, indent, "Unload", "t"); - break; - case 0x30: - printf("Revision"); - break; - case 0x31: - printf("Debug"); - break; - case 0x32: /* FatalOp */ - asl_dump_oparg(&dp, indent, "Fatal", "bdi"); - break; - case 0x33: /* TimerOp */ - printf("Timer"); - break; - case 0x80: /* OpRegionOp */ - asl_dump_defopregion(&dp, indent); - break; - case 0x81: /* FieldOp */ - asl_dump_deffield(&dp, indent); - break; - case 0x82: /* DeviceOp */ - asl_dump_defdevice(&dp, indent); - break; - case 0x83: /* ProcessorOp */ - asl_dump_defprocessor(&dp, indent); - break; - case 0x84: /* PowerResOp */ - asl_dump_defpowerres(&dp, indent); - break; - case 0x85: /* ThermalZoneOp */ - asl_dump_defthermalzone(&dp, indent); - break; - case 0x86: /* IndexFieldOp */ - asl_dump_defindexfield(&dp, indent); - break; - case 0x87: /* BankFieldOp */ - asl_dump_defbankfield(&dp, indent); - break; - case 0x88: /* DataRegionOp */ - asl_dump_oparg(&dp, indent, "DataRegion", "Nttt"); - break; - default: - errx(1, "strange opcode 0x5b, 0x%x", opcode); - } - break; - case 0x68: - case 0x69: - case 0x6a: - case 0x6b: - case 0x6c: - case 0x6d: - case 0x6e: /* ArgN */ - printf("Arg%d", opcode - 0x68); - break; - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x66: - case 0x67: - printf("Local%d", opcode - 0x60); - break; - case 0x70: /* StoreOp */ - asl_dump_oparg(&dp, indent, "Store", "tt"); - break; - case 0x71: /* RefOfOp */ - asl_dump_oparg(&dp, indent, "RefOf", "t"); - break; - case 0x72: /* AddOp */ - asl_dump_oparg(&dp, indent, "Add", "iio"); - break; - case 0x73: /* ConcatenateOp */ - asl_dump_oparg(&dp, indent, "Concatenate", "ttt"); - break; - case 0x74: /* SubtractOp */ - asl_dump_oparg(&dp, indent, "Subtract", "iio"); - break; - case 0x75: /* IncrementOp */ - asl_dump_oparg(&dp, indent, "Increment", "t"); - break; - case 0x76: /* DecrementOp */ - asl_dump_oparg(&dp, indent, "Decrement", "t"); - break; - case 0x77: /* MultiplyOp */ - asl_dump_oparg(&dp, indent, "Multiply", "iio"); - break; - case 0x78: /* DivideOp */ - asl_dump_oparg(&dp, indent, "Divide", "iioo"); - break; - case 0x79: /* ShiftLeftOp */ - asl_dump_oparg(&dp, indent, "ShiftLeft", "iio"); - break; - case 0x7a: /* ShiftRightOp */ - asl_dump_oparg(&dp, indent, "ShiftRight", "iio"); - break; - case 0x7b: /* AndOp */ - asl_dump_oparg(&dp, indent, "And", "iio"); - break; - case 0x7c: /* NAndOp */ - asl_dump_oparg(&dp, indent, "NAnd", "iio"); - break; - case 0x7d: /* OrOp */ - asl_dump_oparg(&dp, indent, "Or", "iio"); - break; - case 0x7e: /* NOrOp */ - asl_dump_oparg(&dp, indent, "NOr", "iio"); - break; - case 0x7f: /* XOrOp */ - asl_dump_oparg(&dp, indent, "XOr", "iio"); - break; - case 0x80: /* NotOp */ - asl_dump_oparg(&dp, indent, "Not", "io"); - break; - case 0x81: /* FindSetLeftBitOp */ - asl_dump_oparg(&dp, indent, "FindSetLeftBit", "it"); - break; - case 0x82: /* FindSetRightBitOp */ - asl_dump_oparg(&dp, indent, "FindSetRightBit", "it"); - break; - case 0x83: /* DerefOp */ - asl_dump_oparg(&dp, indent, "DerefOf", "t"); - break; - case 0x84: /* ConcatResTemplateOp */ - asl_dump_oparg(&dp, indent, "ConcatResTemplate", "ttt"); - break; - case 0x85: /* ModOp */ - asl_dump_oparg(&dp, indent, "Mod", "iio"); - break; - case 0x86: /* NotifyOp */ - asl_dump_oparg(&dp, indent, "Notify", "tt"); - break; - case 0x87: /* SizeOfOp */ - asl_dump_oparg(&dp, indent, "SizeOf", "t"); - break; - case 0x88: /* IndexOp */ - asl_dump_oparg(&dp, indent, "Index", "tio"); - break; - case 0x89: /* MatchOp */ - printf("Match("); - asl_dump_termobj(&dp, indent); - printf(", %s, ", matchstr[*dp++]); - asl_dump_termobj(&dp, indent); - printf(", %s, ", matchstr[*dp++]); - asl_dump_termobj(&dp, indent); - printf(", "); - asl_dump_termobj(&dp, indent); - printf(")"); - break; - case 0x8a: /* CreateDWordFieldOp */ - asl_dump_oparg(&dp, indent, "CreateDWordField", "tiN"); - break; - case 0x8b: /* CreateWordFieldOp */ - asl_dump_oparg(&dp, indent, "CreateWordField", "tiN"); - break; - case 0x8c: /* CreateByteFieldOp */ - asl_dump_oparg(&dp, indent, "CreateByteField", "tiN"); - break; - case 0x8d: /* CreateBitFieldOp */ - asl_dump_oparg(&dp, indent, "CreateBitField", "tiN"); - break; - case 0x8e: /* ObjectTypeOp */ - asl_dump_oparg(&dp, indent, "ObjectType", "t"); - break; - case 0x8f: /* CreateQWordFieldOp */ - asl_dump_oparg(&dp, indent, "CreateQWordField", "tiN"); - break; - case 0x90: - asl_dump_oparg(&dp, indent, "LAnd", "ii"); - break; - case 0x91: - asl_dump_oparg(&dp, indent, "LOr", "ii"); - break; - case 0x92: - asl_dump_oparg(&dp, indent, "LNot", "i"); - break; - case 0x93: - asl_dump_oparg(&dp, indent, "LEqual", "tt"); - break; - case 0x94: - asl_dump_oparg(&dp, indent, "LGreater", "tt"); - break; - case 0x95: - asl_dump_oparg(&dp, indent, "LLess", "tt"); - break; - case 0x96: /* ToBufferOp */ - asl_dump_oparg(&dp, indent, "ToBuffer", "to"); - break; - case 0x97: /* ToDecStringOp */ - asl_dump_oparg(&dp, indent, "ToDecString", "to"); - break; - case 0x98: /* ToHexStringOp */ - asl_dump_oparg(&dp, indent, "ToHexString", "to"); - break; - case 0x99: /* ToIntegerOp */ - asl_dump_oparg(&dp, indent, "ToInteger", "to"); - break; - case 0x9c: /* ToStringOp */ - asl_dump_oparg(&dp, indent, "ToString", "tto"); - break; - case 0x9d: /* CopyObjectOp */ - asl_dump_oparg(&dp, indent, "CopyObject", "tt"); - break; - case 0x9e: /* MidOp */ - asl_dump_oparg(&dp, indent, "Mid", "tiio"); - break; - case 0x9f: - printf("Continue"); - break; - case 0xa0: /* IfOp */ - asl_dump_defif(&dp, indent); - break; - case 0xa1: /* ElseOp */ - asl_dump_defelse(&dp, indent); - break; - case 0xa2: /* WhileOp */ - asl_dump_defwhile(&dp, indent); - break; - case 0xa3: /* NoopOp */ - printf("Noop"); - break; - case 0xa5: /* BreakOp */ - printf("Break"); - break; - case 0xa4: /* ReturnOp */ - asl_dump_oparg(&dp, indent, "Return", "t"); - break; - case 0xcc: /* BreakPointOp */ - printf("BreakPoint"); - break; - default: - errx(1, "strange opcode 0x%x", opcode); - } - - *dpp = dp; -} - -void -asl_dump_objectlist(u_int8_t **dpp, u_int8_t *end, int indent) -{ - u_int8_t *dp; - - dp = *dpp; - while (dp < end) { - print_indent(indent); - asl_dump_termobj(&dp, indent); - printf("\n"); - } - - *dpp = dp; -} diff --git a/usr.sbin/acpidump/debug.h b/usr.sbin/acpidump/debug.h deleted file mode 100644 index db645ca1405..00000000000 --- a/usr.sbin/acpidump/debug.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $OpenBSD: debug.h,v 1.1 2005/06/02 20:09:39 tholo Exp $ */ -/*- - * Copyright (c) 1999 Takanori Watanabe - * Copyright (c) 1999, 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: debug.h,v 1.1 2005/06/02 20:09:39 tholo Exp $ - * $FreeBSD: src/usr.sbin/acpi/amldb/debug.h,v 1.1.1.1 2000/08/31 14:45:00 iwasaki Exp $ - */ - -#ifndef _DEBUG_H_ -#define _DEBUG_H_ - -void aml_dbgr(struct aml_environ *, struct aml_environ *); - -#endif /* !_DEBUG_H_ */