Import acpidump from FreeBSD per request from jmcneill@
Changes made in the port: - adapt path to iasl from /usr/sbin/iasl to /usr/bin/iasl - fix realpath() usage to accomplish NetBSD's behaviour - use EXIT_FAILURE/EXIT_SUCCESS everywhere - fix crash on corrupt DSDT file and print proper error message - implemented additional ACPI table parsers for BERT, BOOT, CPEP, DBGP, EINJ, ERST, HEST, MSCT, SBST, SLIT, SPCR, TCPA, WAET, WDAT and WDRT
This commit is contained in:
parent
de1cae9a73
commit
3b140d483b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: acpidump.c,v 1.1 2007/01/14 04:36:13 christos Exp $ */
|
||||
/* $NetBSD: acpidump.c,v 1.2 2009/12/22 08:44:03 cegger Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
|
||||
|
@ -25,89 +25,126 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Id: acpidump.c,v 1.3 2000/08/08 14:12:21 iwasaki Exp
|
||||
* $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.c,v 1.5 2002/01/02 07:01:34 msmith Exp $
|
||||
* $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.c,v 1.13 2009/08/25 20:35:57 jhb Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: acpidump.c,v 1.1 2007/01/14 04:36:13 christos Exp $");
|
||||
__RCSID("$NetBSD: acpidump.c,v 1.2 2009/12/22 08:44:03 cegger Exp $");
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <acpi_common.h>
|
||||
#include "acpidump.h"
|
||||
|
||||
static void
|
||||
asl_dump_from_file(char *file)
|
||||
{
|
||||
u_int8_t *dp;
|
||||
u_int8_t *end;
|
||||
|
||||
acpi_load_dsdt(file, &dp, &end);
|
||||
acpi_dump_dsdt(dp, end);
|
||||
}
|
||||
int dflag; /* Disassemble AML using iasl(8) */
|
||||
int tflag; /* Dump contents of SDT tables */
|
||||
int vflag; /* Use verbose messages */
|
||||
|
||||
static void
|
||||
asl_dump_from_devmem(void)
|
||||
usage(void)
|
||||
{
|
||||
struct ACPIrsdp *rp;
|
||||
struct ACPIsdt *rsdp;
|
||||
const char *progname = getprogname();
|
||||
|
||||
rp = acpi_find_rsd_ptr();
|
||||
if (!rp)
|
||||
errx(1, "Can't find ACPI information\n");
|
||||
|
||||
acpi_print_rsd_ptr(rp);
|
||||
rsdp = (struct ACPIsdt *) acpi_map_sdt(rp->addr);
|
||||
if (memcmp(rsdp->signature, "RSDT", 4) ||
|
||||
acpi_checksum(rsdp, rsdp->len))
|
||||
errx(1, "RSDT is corrupted\n");
|
||||
|
||||
acpi_handle_rsdt(rsdp);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(const char *progname)
|
||||
{
|
||||
|
||||
printf("usage:\t%s [-r] [-o dsdt_file_for_output]\n", progname);
|
||||
printf("\t%s [-r] [-f dsdt_file_for_input]\n", progname);
|
||||
printf("\t%s [-h]\n", progname);
|
||||
exit(1);
|
||||
fprintf(stderr, "usage: %s [-d] [-t] [-h] [-v] [-f dsdt_input] "
|
||||
"[-o dsdt_output]\n", progname);
|
||||
fprintf(stderr, "To send ASL:\n\t%s -dt | gzip -c9 > foo.asl.gz\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char c, *progname;
|
||||
ACPI_TABLE_HEADER *rsdt, *sdt;
|
||||
char c;
|
||||
char *dsdt_input_file, *dsdt_output_file;
|
||||
|
||||
progname = argv[0];
|
||||
while ((c = getopt(argc, argv, "f:o:hr")) != -1) {
|
||||
dsdt_input_file = dsdt_output_file = NULL;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
while ((c = getopt(argc, argv, "dhtvf:o:")) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 't':
|
||||
tflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
case 'f':
|
||||
asl_dump_from_file(optarg);
|
||||
return (0);
|
||||
dsdt_input_file = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
aml_dumpfile = optarg;
|
||||
dsdt_output_file = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage(progname);
|
||||
break;
|
||||
case 'r':
|
||||
rflag++;
|
||||
break;
|
||||
default:
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
asl_dump_from_devmem();
|
||||
return (0);
|
||||
/* Get input either from file or /dev/mem */
|
||||
if (dsdt_input_file != NULL) {
|
||||
if (dflag == 0 && tflag == 0) {
|
||||
warnx("Need to specify -d or -t with DSDT input file");
|
||||
usage();
|
||||
} else if (tflag != 0) {
|
||||
warnx("Can't use -t with DSDT input file");
|
||||
usage();
|
||||
}
|
||||
if (vflag)
|
||||
warnx("loading DSDT file: %s", dsdt_input_file);
|
||||
rsdt = dsdt_load_file(dsdt_input_file);
|
||||
} else {
|
||||
if (vflag)
|
||||
warnx("loading RSD PTR from /dev/mem");
|
||||
rsdt = sdt_load_devmem();
|
||||
}
|
||||
|
||||
/* Display misc. SDT tables (only available when using /dev/mem) */
|
||||
if (tflag) {
|
||||
if (vflag)
|
||||
warnx("printing various SDT tables");
|
||||
sdt_print_all(rsdt);
|
||||
}
|
||||
|
||||
/* Translate RSDT to DSDT pointer */
|
||||
if (dsdt_input_file == NULL) {
|
||||
sdt = sdt_from_rsdt(rsdt, ACPI_SIG_FADT, NULL);
|
||||
sdt = dsdt_from_fadt((ACPI_TABLE_FADT *)sdt);
|
||||
} else {
|
||||
sdt = rsdt;
|
||||
rsdt = NULL;
|
||||
}
|
||||
|
||||
/* Dump the DSDT and SSDTs to a file */
|
||||
if (dsdt_output_file != NULL) {
|
||||
if (vflag)
|
||||
warnx("saving DSDT file: %s", dsdt_output_file);
|
||||
dsdt_save_file(dsdt_output_file, rsdt, sdt);
|
||||
}
|
||||
|
||||
/* Disassemble the DSDT into ASL */
|
||||
if (dflag) {
|
||||
if (vflag)
|
||||
warnx("disassembling DSDT, iasl messages follow");
|
||||
aml_disassemble(rsdt, sdt);
|
||||
if (vflag)
|
||||
warnx("iasl processing complete");
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: acpidump.h,v 1.1 2007/01/14 04:36:13 christos Exp $ */
|
||||
/* $NetBSD: acpidump.h,v 1.2 2009/12/22 08:44:03 cegger Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 Doug Rabson
|
||||
|
@ -26,158 +26,63 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Id: acpidump.h,v 1.3 2000/08/09 14:47:52 iwasaki Exp
|
||||
* $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.h,v 1.5 2002/10/09 19:46:09 jhb Exp $
|
||||
* $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.h,v 1.24 2009/08/25 20:35:57 jhb Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ACPIDUMP_H_
|
||||
#define _ACPIDUMP_H_
|
||||
#define _ACPIDUMP_H_
|
||||
|
||||
/* 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;
|
||||
#include <stdlib.h> /* for size_t */
|
||||
#include <acpi_common.h>
|
||||
#include <dev/acpi/acpica.h>
|
||||
|
||||
/* 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;
|
||||
/* GAS address space ID constants. */
|
||||
#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_CMOS 5
|
||||
#define ACPI_GAS_PCIBAR 6
|
||||
#define ACPI_GAS_DATATABLE 7
|
||||
#define ACPI_GAS_FIXED 0x7f
|
||||
|
||||
/* 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;
|
||||
/* Subfields in the HPET Id member. */
|
||||
#define ACPI_HPET_ID_HARDWARE_REV_ID 0x000000ff
|
||||
#define ACPI_HPET_ID_COMPARATORS 0x00001f00
|
||||
#define ACPI_HPET_ID_COUNT_SIZE_CAP 0x00002000
|
||||
#define ACPI_HPET_ID_LEGACY_CAPABLE 0x00008000
|
||||
#define ACPI_HPET_ID_PCI_VENDOR_ID 0xffff0000
|
||||
|
||||
/* 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;
|
||||
/* Find and map the RSD PTR structure and return it for parsing */
|
||||
ACPI_TABLE_HEADER *sdt_load_devmem(void);
|
||||
|
||||
/* 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;
|
||||
/*
|
||||
* Load the DSDT from a previous save file. Note that other tables are
|
||||
* not saved (i.e. FADT)
|
||||
*/
|
||||
ACPI_TABLE_HEADER *dsdt_load_file(char *);
|
||||
|
||||
void *acpi_map_physical(vm_offset_t, size_t);
|
||||
struct ACPIrsdp *acpi_find_rsd_ptr(void);
|
||||
int acpi_checksum(void *, size_t);
|
||||
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 *);
|
||||
/* Save the DSDT to a file */
|
||||
void dsdt_save_file(char *, ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *);
|
||||
|
||||
void asl_dump_termobj(u_int8_t **, int);
|
||||
void asl_dump_objectlist(u_int8_t **, u_int8_t *, int);
|
||||
/* Print out as many fixed tables as possible, given the RSD PTR */
|
||||
void sdt_print_all(ACPI_TABLE_HEADER *);
|
||||
|
||||
void aml_dump(struct ACPIsdt *);
|
||||
/* Disassemble the AML in the DSDT */
|
||||
void aml_disassemble(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *);
|
||||
|
||||
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;
|
||||
extern int rflag;
|
||||
/* Routines for accessing tables in physical memory */
|
||||
ACPI_TABLE_RSDP *acpi_find_rsd_ptr(void);
|
||||
void *acpi_map_physical(vm_offset_t, size_t);
|
||||
ACPI_TABLE_HEADER *sdt_from_rsdt(ACPI_TABLE_HEADER *, const char *,
|
||||
ACPI_TABLE_HEADER *);
|
||||
ACPI_TABLE_HEADER *dsdt_from_fadt(ACPI_TABLE_FADT *);
|
||||
int acpi_checksum(void *, size_t);
|
||||
|
||||
/* Command line flags */
|
||||
extern int dflag;
|
||||
extern int tflag;
|
||||
extern int vflag;
|
||||
|
||||
#endif /* !_ACPIDUMP_H_ */
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/* $NetBSD: aml_dump.c,v 1.1 2007/01/14 04:36:13 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
|
||||
* 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.3 2000/08/08 14:12:21 iwasaki Exp
|
||||
* $FreeBSD: src/usr.sbin/acpi/acpidump/aml_dump.c,v 1.4 2001/10/22 17:25:25 iwasaki Exp $
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: aml_dump.c,v 1.1 2007/01/14 04:36:13 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <acpi_common.h>
|
||||
#include "acpidump.h"
|
||||
|
||||
char *aml_dumpfile = NULL;
|
||||
|
||||
void
|
||||
aml_dump(struct ACPIsdt *dsdp)
|
||||
{
|
||||
int fd;
|
||||
mode_t mode;
|
||||
|
||||
if (aml_dumpfile == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
fd = open(aml_dumpfile, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
if (fd == -1) {
|
||||
return;
|
||||
}
|
||||
write(fd, dsdp, SIZEOF_SDT_HDR);
|
||||
write(fd, dsdp->body, dsdp->len - SIZEOF_SDT_HDR);
|
||||
close(fd);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue