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