acpidump.c revision 65286
1153317Ssam/*- 2186904Ssam * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 3153317Ssam * All rights reserved. 4153317Ssam * 5153317Ssam * Redistribution and use in source and binary forms, with or without 6153317Ssam * modification, are permitted provided that the following conditions 7153317Ssam * are met: 8153317Ssam * 1. Redistributions of source code must retain the above copyright 9153317Ssam * notice, this list of conditions and the following disclaimer. 10153317Ssam * 2. Redistributions in binary form must reproduce the above copyright 11153317Ssam * notice, this list of conditions and the following disclaimer in the 12153317Ssam * documentation and/or other materials provided with the distribution. 13153317Ssam * 14153317Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15153317Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16153317Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17153317Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18153317Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19153317Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20153317Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21153317Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22153317Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23153317Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24153317Ssam * SUCH DAMAGE. 25153317Ssam * 26153317Ssam * $Id: acpidump.c,v 1.3 2000/08/08 14:12:21 iwasaki Exp $ 27153317Ssam * $FreeBSD: head/usr.sbin/acpi/acpidump/acpidump.c 65286 2000-08-31 14:42:32Z iwasaki $ 28153317Ssam */ 29153317Ssam 30153317Ssam#include <sys/param.h> 31153317Ssam#include <sys/acpi.h> 32153317Ssam 33153317Ssam#include <assert.h> 34153317Ssam#include <err.h> 35153317Ssam#include <stdio.h> 36153317Ssam#include <unistd.h> 37179398Ssam 38153317Ssam#include "acpidump.h" 39153317Ssam 40170534Ssamstatic void 41153317Ssamasl_dump_from_file(char *file) 42153317Ssam{ 43153317Ssam u_int8_t *dp; 44170534Ssam u_int8_t *end; 45153317Ssam 46153317Ssam acpi_load_dsdt(file, &dp, &end); 47153317Ssam asl_dump_objectlist(&dp, end, 0); 48153317Ssam} 49153317Ssam 50170534Ssamstatic void 51153317Ssamasl_dump_from_devmem() 52153317Ssam{ 53153317Ssam struct ACPIrsdp *rp; 54153317Ssam struct ACPIsdt *rsdp; 55153317Ssam 56153317Ssam rp = acpi_find_rsd_ptr(); 57153317Ssam if (!rp) 58153317Ssam errx(1, "Can't find ACPI information\n"); 59153317Ssam 60153317Ssam acpi_print_rsd_ptr(rp); 61153317Ssam rsdp = (struct ACPIsdt *) acpi_map_sdt(rp->addr); 62153317Ssam if (memcmp(rsdp->signature, "RSDT", 4) || 63153317Ssam acpi_checksum(rsdp, rsdp->len)) 64195746Ssam errx(1, "RSDT is corrupted\n"); 65153317Ssam 66153317Ssam acpi_handle_rsdt(rsdp); 67153317Ssam} 68195746Ssam 69153317Ssamstatic void 70153317Ssamusage(const char *progname) 71153317Ssam{ 72153317Ssam 73153317Ssam printf("usage:\t%s [-o dsdt_file_for_output]\n", progname); 74153317Ssam printf("or\t%s [-f dsdt_file_for_input]\n", progname); 75153317Ssam exit(1); 76164635Ssam} 77178359Ssam 78178359Ssamint 79178359Ssammain(int argc, char *argv[]) 80186904Ssam{ 81153317Ssam char c, *progname; 82153317Ssam 83153317Ssam progname = argv[0]; 84153317Ssam while ((c = getopt(argc, argv, "f:o:h")) != -1) { 85153317Ssam switch (c) { 86170534Ssam case 'f': 87153317Ssam asl_dump_from_file(optarg); 88153317Ssam return (0); 89153317Ssam case 'o': 90153317Ssam aml_dumpfile = optarg; 91153317Ssam break; 92153317Ssam case 'h': 93153317Ssam usage(progname); 94153317Ssam break; 95153317Ssam default: 96153317Ssam argc -= optind; 97153317Ssam argv += optind; 98153317Ssam } 99153317Ssam } 100195746Ssam 101153317Ssam asl_dump_from_devmem(); 102153317Ssam return (0); 103153317Ssam} 104195746Ssam