1 /* $OpenBSD: acpidump.c,v 1.5 2008/09/10 14:59:51 miod Exp $ */ 2 /*- 3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $Id: acpidump.c,v 1.5 2008/09/10 14:59:51 miod Exp $ 28 * $FreeBSD: src/usr.sbin/acpi/acpidump/acpidump.c,v 1.3 2000/11/08 02:37:00 iwasaki Exp $ 29 */ 30 31 #include <sys/types.h> 32 33 #include <assert.h> 34 #include <err.h> 35 #include <stdio.h> 36 #include <string.h> 37 #include <unistd.h> 38 39 #include "acpidump.h" 40 41 static void 42 asl_dump_from_file(char *file) 43 { 44 u_int8_t *dp; 45 u_int8_t *end; 46 47 acpi_load_dsdt(file, &dp, &end); 48 acpi_dump_dsdt(dp, end); 49 } 50 51 static void 52 asl_dump_from_devmem() 53 { 54 struct ACPIrsdp *rp; 55 struct ACPIsdt *rsdp; 56 57 rp = acpi_find_rsd_ptr(); 58 if (!rp) 59 errx(1, "Can't find ACPI information"); 60 61 acpi_print_rsd_ptr(rp); 62 rsdp = (struct ACPIsdt *) acpi_map_sdt(rp->addr); 63 if (memcmp(rsdp->signature, "RSDT", 4) || 64 acpi_checksum(rsdp, rsdp->len)) 65 errx(1, "RSDT is corrupted"); 66 67 acpi_handle_rsdt(rsdp); 68 } 69 70 static void 71 usage(void) 72 { 73 74 printf("usage: acpidump [-o dsdt_file_for_output]\n"); 75 printf(" acpidump [-f dsdt_file_for_input]\n"); 76 exit(1); 77 } 78 79 int 80 main(int argc, char *argv[]) 81 { 82 char c; 83 84 while ((c = getopt(argc, argv, "f:o:")) != -1) { 85 switch (c) { 86 case 'f': 87 asl_dump_from_file(optarg); 88 return (0); 89 case 'o': 90 aml_dumpfile = optarg; 91 break; 92 default: 93 usage(); 94 } 95 } 96 97 asl_dump_from_devmem(); 98 return (0); 99 } 100