1e1e9a4bfSMitsuru IWASAKI /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 31de7b4b8SPedro F. Giffuni * 4e1e9a4bfSMitsuru IWASAKI * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 5e1e9a4bfSMitsuru IWASAKI * All rights reserved. 6e1e9a4bfSMitsuru IWASAKI * 7e1e9a4bfSMitsuru IWASAKI * Redistribution and use in source and binary forms, with or without 8e1e9a4bfSMitsuru IWASAKI * modification, are permitted provided that the following conditions 9e1e9a4bfSMitsuru IWASAKI * are met: 10e1e9a4bfSMitsuru IWASAKI * 1. Redistributions of source code must retain the above copyright 11e1e9a4bfSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer. 12e1e9a4bfSMitsuru IWASAKI * 2. Redistributions in binary form must reproduce the above copyright 13e1e9a4bfSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer in the 14e1e9a4bfSMitsuru IWASAKI * documentation and/or other materials provided with the distribution. 15e1e9a4bfSMitsuru IWASAKI * 16e1e9a4bfSMitsuru IWASAKI * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17e1e9a4bfSMitsuru IWASAKI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18e1e9a4bfSMitsuru IWASAKI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19e1e9a4bfSMitsuru IWASAKI * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20e1e9a4bfSMitsuru IWASAKI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21e1e9a4bfSMitsuru IWASAKI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22e1e9a4bfSMitsuru IWASAKI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23e1e9a4bfSMitsuru IWASAKI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24e1e9a4bfSMitsuru IWASAKI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25e1e9a4bfSMitsuru IWASAKI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26e1e9a4bfSMitsuru IWASAKI * SUCH DAMAGE. 27e1e9a4bfSMitsuru IWASAKI */ 28e1e9a4bfSMitsuru IWASAKI 29e1e9a4bfSMitsuru IWASAKI #include <sys/param.h> 30e1e9a4bfSMitsuru IWASAKI #include <assert.h> 31e1e9a4bfSMitsuru IWASAKI #include <err.h> 32e1e9a4bfSMitsuru IWASAKI #include <stdio.h> 33945137d9SNate Lawson #include <stdlib.h> 34945137d9SNate Lawson #include <string.h> 35e1e9a4bfSMitsuru IWASAKI #include <unistd.h> 36e1e9a4bfSMitsuru IWASAKI 37e1e9a4bfSMitsuru IWASAKI #include "acpidump.h" 38e1e9a4bfSMitsuru IWASAKI 39945137d9SNate Lawson int dflag; /* Disassemble AML using iasl(8) */ 40945137d9SNate Lawson int tflag; /* Dump contents of SDT tables */ 41945137d9SNate Lawson int vflag; /* Use verbose messages */ 42e1e9a4bfSMitsuru IWASAKI 43e1e9a4bfSMitsuru IWASAKI static void 44e1e9a4bfSMitsuru IWASAKI usage(const char *progname) 45e1e9a4bfSMitsuru IWASAKI { 46e1e9a4bfSMitsuru IWASAKI 47f7675a56SNate Lawson fprintf(stderr, "usage: %s [-d] [-t] [-h] [-v] [-f dsdt_input] " 48*3ff9ea7dSWarner Losh "[-o dsdt_output] [-T table_name]\n", progname); 49ceb8cd64SNate Lawson fprintf(stderr, "To send ASL:\n\t%s -dt | gzip -c9 > foo.asl.gz\n", 50ceb8cd64SNate Lawson progname); 51e1e9a4bfSMitsuru IWASAKI exit(1); 52e1e9a4bfSMitsuru IWASAKI } 53e1e9a4bfSMitsuru IWASAKI 54e1e9a4bfSMitsuru IWASAKI int 55e1e9a4bfSMitsuru IWASAKI main(int argc, char *argv[]) 56e1e9a4bfSMitsuru IWASAKI { 57986dffafSJohn Baldwin ACPI_TABLE_HEADER *rsdt, *sdt; 585ff4e240SAndrew Turner int c; 595ff4e240SAndrew Turner char *progname; 60945137d9SNate Lawson char *dsdt_input_file, *dsdt_output_file; 61*3ff9ea7dSWarner Losh char *tbl = NULL; 62e1e9a4bfSMitsuru IWASAKI 63945137d9SNate Lawson dsdt_input_file = dsdt_output_file = NULL; 64e1e9a4bfSMitsuru IWASAKI progname = argv[0]; 65945137d9SNate Lawson 66945137d9SNate Lawson if (argc < 2) 67945137d9SNate Lawson usage(progname); 68945137d9SNate Lawson 69*3ff9ea7dSWarner Losh while ((c = getopt(argc, argv, "df:ho:tT:vs")) != -1) { 70e1e9a4bfSMitsuru IWASAKI switch (c) { 71945137d9SNate Lawson case 'd': 72945137d9SNate Lawson dflag = 1; 73945137d9SNate Lawson break; 74*3ff9ea7dSWarner Losh case 'T': 75*3ff9ea7dSWarner Losh tbl = optarg; 76*3ff9ea7dSWarner Losh if (strlen(tbl) != 4) { 77*3ff9ea7dSWarner Losh warnx("Illegal table name %s", tbl); 78*3ff9ea7dSWarner Losh usage(progname); 79*3ff9ea7dSWarner Losh } 80*3ff9ea7dSWarner Losh break; 81945137d9SNate Lawson case 't': 82945137d9SNate Lawson tflag = 1; 83945137d9SNate Lawson break; 84945137d9SNate Lawson case 'v': 85945137d9SNate Lawson vflag = 1; 86945137d9SNate Lawson break; 87e1e9a4bfSMitsuru IWASAKI case 'f': 88945137d9SNate Lawson dsdt_input_file = optarg; 89945137d9SNate Lawson break; 90e1e9a4bfSMitsuru IWASAKI case 'o': 91945137d9SNate Lawson dsdt_output_file = optarg; 92e1e9a4bfSMitsuru IWASAKI break; 93f5a04b16STakanori Watanabe case 's': 94f5a04b16STakanori Watanabe dflag = 2; 95f5a04b16STakanori Watanabe break; 96e1e9a4bfSMitsuru IWASAKI case 'h': 97e1e9a4bfSMitsuru IWASAKI default: 98945137d9SNate Lawson usage(progname); 99945137d9SNate Lawson /* NOTREACHED */ 100945137d9SNate Lawson } 101945137d9SNate Lawson } 102e1e9a4bfSMitsuru IWASAKI argc -= optind; 103e1e9a4bfSMitsuru IWASAKI argv += optind; 104945137d9SNate Lawson 105945137d9SNate Lawson /* Get input either from file or /dev/mem */ 106945137d9SNate Lawson if (dsdt_input_file != NULL) { 107945137d9SNate Lawson if (dflag == 0 && tflag == 0) { 108945137d9SNate Lawson warnx("Need to specify -d or -t with DSDT input file"); 109945137d9SNate Lawson usage(progname); 110945137d9SNate Lawson } else if (tflag != 0) { 111945137d9SNate Lawson warnx("Can't use -t with DSDT input file"); 112945137d9SNate Lawson usage(progname); 113e1e9a4bfSMitsuru IWASAKI } 114945137d9SNate Lawson if (vflag) 115945137d9SNate Lawson warnx("loading DSDT file: %s", dsdt_input_file); 116bfa3f012SMarcel Moolenaar rsdt = dsdt_load_file(dsdt_input_file); 117945137d9SNate Lawson } else { 118945137d9SNate Lawson if (vflag) 119945137d9SNate Lawson warnx("loading RSD PTR from /dev/mem"); 120bfa3f012SMarcel Moolenaar rsdt = sdt_load_devmem(); 121e1e9a4bfSMitsuru IWASAKI } 122e1e9a4bfSMitsuru IWASAKI 123945137d9SNate Lawson /* Display misc. SDT tables (only available when using /dev/mem) */ 124*3ff9ea7dSWarner Losh if (tflag || tbl != NULL) { 125945137d9SNate Lawson if (vflag) 126945137d9SNate Lawson warnx("printing various SDT tables"); 127*3ff9ea7dSWarner Losh sdt_print_all(rsdt, tbl); 128945137d9SNate Lawson } 129945137d9SNate Lawson 130945137d9SNate Lawson /* Translate RSDT to DSDT pointer */ 131945137d9SNate Lawson if (dsdt_input_file == NULL) { 132986dffafSJohn Baldwin sdt = sdt_from_rsdt(rsdt, ACPI_SIG_FADT, NULL); 133986dffafSJohn Baldwin sdt = dsdt_from_fadt((ACPI_TABLE_FADT *)sdt); 134bfa3f012SMarcel Moolenaar } else { 135bfa3f012SMarcel Moolenaar sdt = rsdt; 136bfa3f012SMarcel Moolenaar rsdt = NULL; 137945137d9SNate Lawson } 138945137d9SNate Lawson 13962c7bde1SNate Lawson /* Dump the DSDT and SSDTs to a file */ 140945137d9SNate Lawson if (dsdt_output_file != NULL) { 141945137d9SNate Lawson if (vflag) 142945137d9SNate Lawson warnx("saving DSDT file: %s", dsdt_output_file); 143bfa3f012SMarcel Moolenaar dsdt_save_file(dsdt_output_file, rsdt, sdt); 144945137d9SNate Lawson } 145945137d9SNate Lawson 146945137d9SNate Lawson /* Disassemble the DSDT into ASL */ 147945137d9SNate Lawson if (dflag) { 148945137d9SNate Lawson if (vflag) 149945137d9SNate Lawson warnx("disassembling DSDT, iasl messages follow"); 150f5a04b16STakanori Watanabe if (dflag == 1) { 151bfa3f012SMarcel Moolenaar aml_disassemble(rsdt, sdt); 152f5a04b16STakanori Watanabe } else { 153f5a04b16STakanori Watanabe aml_disassemble_separate(rsdt, sdt); 154f5a04b16STakanori Watanabe } 155945137d9SNate Lawson if (vflag) 156945137d9SNate Lawson warnx("iasl processing complete"); 157945137d9SNate Lawson } 158945137d9SNate Lawson 159945137d9SNate Lawson exit(0); 160e1e9a4bfSMitsuru IWASAKI } 161