Commit | Line | Data |
---|---|---|
506f57dd LZ |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: apmain - Main module for the acpidump utility | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
82a80941 | 8 | * Copyright (C) 2000 - 2015, Intel Corp. |
506f57dd LZ |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
44 | #define _DECLARE_GLOBALS | |
45 | #include "acpidump.h" | |
46 | #include "acapps.h" | |
47 | ||
48 | /* | |
49 | * acpidump - A portable utility for obtaining system ACPI tables and dumping | |
50 | * them in an ASCII hex format suitable for binary extraction via acpixtract. | |
51 | * | |
52 | * Obtaining the system ACPI tables is an OS-specific operation. | |
53 | * | |
54 | * This utility can be ported to any host operating system by providing a | |
55 | * module containing system-specific versions of these interfaces: | |
56 | * | |
57 | * acpi_os_get_table_by_address | |
58 | * acpi_os_get_table_by_index | |
59 | * acpi_os_get_table_by_name | |
60 | * | |
61 | * See the ACPICA Reference Guide for the exact definitions of these | |
62 | * interfaces. Also, see these ACPICA source code modules for example | |
63 | * implementations: | |
64 | * | |
65 | * source/os_specific/service_layers/oswintbl.c | |
66 | * source/os_specific/service_layers/oslinuxtbl.c | |
67 | */ | |
68 | ||
69 | /* Local prototypes */ | |
70 | ||
71 | static void ap_display_usage(void); | |
72 | ||
73 | static int ap_do_options(int argc, char **argv); | |
74 | ||
135610f7 | 75 | static int ap_insert_action(char *argument, u32 to_be_done); |
506f57dd LZ |
76 | |
77 | /* Table for deferred actions from command line options */ | |
78 | ||
79 | struct ap_dump_action action_table[AP_MAX_ACTIONS]; | |
80 | u32 current_action = 0; | |
81 | ||
82 | #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility" | |
c7932267 | 83 | #define AP_SUPPORTED_OPTIONS "?a:bcf:hn:o:r:svxz" |
506f57dd LZ |
84 | |
85 | /****************************************************************************** | |
86 | * | |
87 | * FUNCTION: ap_display_usage | |
88 | * | |
89 | * DESCRIPTION: Usage message for the acpi_dump utility | |
90 | * | |
91 | ******************************************************************************/ | |
92 | ||
93 | static void ap_display_usage(void) | |
94 | { | |
95 | ||
96 | ACPI_USAGE_HEADER("acpidump [options]"); | |
97 | ||
98 | ACPI_OPTION("-b", "Dump tables to binary files"); | |
99 | ACPI_OPTION("-c", "Dump customized tables"); | |
100 | ACPI_OPTION("-h -?", "This help message"); | |
101 | ACPI_OPTION("-o <File>", "Redirect output to file"); | |
102 | ACPI_OPTION("-r <Address>", "Dump tables from specified RSDP"); | |
103 | ACPI_OPTION("-s", "Print table summaries only"); | |
104 | ACPI_OPTION("-v", "Display version information"); | |
105 | ACPI_OPTION("-z", "Verbose mode"); | |
106 | ||
d9cf147d | 107 | ACPI_USAGE_TEXT("\nTable Options:\n"); |
506f57dd LZ |
108 | |
109 | ACPI_OPTION("-a <Address>", "Get table via a physical address"); | |
110 | ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file"); | |
111 | ACPI_OPTION("-n <Signature>", "Get table via a name/signature"); | |
c7932267 LZ |
112 | ACPI_OPTION("-x", "Do not use but dump XSDT"); |
113 | ACPI_OPTION("-x -x", "Do not use or dump XSDT"); | |
506f57dd | 114 | |
d9cf147d LZ |
115 | ACPI_USAGE_TEXT("\n" |
116 | "Invocation without parameters dumps all available tables\n" | |
117 | "Multiple mixed instances of -a, -f, and -n are supported\n\n"); | |
506f57dd LZ |
118 | } |
119 | ||
120 | /****************************************************************************** | |
121 | * | |
122 | * FUNCTION: ap_insert_action | |
123 | * | |
124 | * PARAMETERS: argument - Pointer to the argument for this action | |
125 | * to_be_done - What to do to process this action | |
126 | * | |
135610f7 | 127 | * RETURN: Status |
506f57dd LZ |
128 | * |
129 | * DESCRIPTION: Add an action item to the action table | |
130 | * | |
131 | ******************************************************************************/ | |
132 | ||
135610f7 | 133 | static int ap_insert_action(char *argument, u32 to_be_done) |
506f57dd LZ |
134 | { |
135 | ||
136 | /* Insert action and check for table overflow */ | |
137 | ||
138 | action_table[current_action].argument = argument; | |
139 | action_table[current_action].to_be_done = to_be_done; | |
140 | ||
141 | current_action++; | |
142 | if (current_action > AP_MAX_ACTIONS) { | |
dcaff16d LZ |
143 | acpi_log_error("Too many table options (max %u)\n", |
144 | AP_MAX_ACTIONS); | |
135610f7 | 145 | return (-1); |
506f57dd | 146 | } |
135610f7 LZ |
147 | |
148 | return (0); | |
506f57dd LZ |
149 | } |
150 | ||
151 | /****************************************************************************** | |
152 | * | |
153 | * FUNCTION: ap_do_options | |
154 | * | |
155 | * PARAMETERS: argc/argv - Standard argc/argv | |
156 | * | |
157 | * RETURN: Status | |
158 | * | |
159 | * DESCRIPTION: Command line option processing. The main actions for getting | |
160 | * and dumping tables are deferred via the action table. | |
161 | * | |
162 | *****************************************************************************/ | |
163 | ||
164 | static int ap_do_options(int argc, char **argv) | |
165 | { | |
166 | int j; | |
167 | acpi_status status; | |
168 | ||
169 | /* Command line options */ | |
170 | ||
a92e9577 LZ |
171 | while ((j = |
172 | acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) | |
506f57dd LZ |
173 | switch (j) { |
174 | /* | |
175 | * Global options | |
176 | */ | |
177 | case 'b': /* Dump all input tables to binary files */ | |
178 | ||
179 | gbl_binary_mode = TRUE; | |
180 | continue; | |
181 | ||
182 | case 'c': /* Dump customized tables */ | |
183 | ||
184 | gbl_dump_customized_tables = TRUE; | |
185 | continue; | |
186 | ||
187 | case 'h': | |
188 | case '?': | |
189 | ||
190 | ap_display_usage(); | |
135610f7 | 191 | return (1); |
506f57dd LZ |
192 | |
193 | case 'o': /* Redirect output to a single file */ | |
194 | ||
195 | if (ap_open_output_file(acpi_gbl_optarg)) { | |
135610f7 | 196 | return (-1); |
506f57dd LZ |
197 | } |
198 | continue; | |
199 | ||
200 | case 'r': /* Dump tables from specified RSDP */ | |
201 | ||
202 | status = | |
203 | acpi_ut_strtoul64(acpi_gbl_optarg, 0, | |
204 | &gbl_rsdp_base); | |
205 | if (ACPI_FAILURE(status)) { | |
dcaff16d LZ |
206 | acpi_log_error |
207 | ("%s: Could not convert to a physical address\n", | |
208 | acpi_gbl_optarg); | |
135610f7 | 209 | return (-1); |
506f57dd LZ |
210 | } |
211 | continue; | |
212 | ||
213 | case 's': /* Print table summaries only */ | |
214 | ||
215 | gbl_summary_mode = TRUE; | |
216 | continue; | |
217 | ||
c7932267 LZ |
218 | case 'x': /* Do not use XSDT */ |
219 | ||
220 | if (!acpi_gbl_do_not_use_xsdt) { | |
221 | acpi_gbl_do_not_use_xsdt = TRUE; | |
222 | } else { | |
223 | gbl_do_not_dump_xsdt = TRUE; | |
224 | } | |
225 | continue; | |
226 | ||
506f57dd LZ |
227 | case 'v': /* Revision/version */ |
228 | ||
dcaff16d | 229 | acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); |
135610f7 | 230 | return (1); |
506f57dd LZ |
231 | |
232 | case 'z': /* Verbose mode */ | |
233 | ||
234 | gbl_verbose_mode = TRUE; | |
dcaff16d | 235 | acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); |
506f57dd LZ |
236 | continue; |
237 | ||
238 | /* | |
239 | * Table options | |
240 | */ | |
241 | case 'a': /* Get table by physical address */ | |
242 | ||
135610f7 LZ |
243 | if (ap_insert_action |
244 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) { | |
245 | return (-1); | |
246 | } | |
506f57dd LZ |
247 | break; |
248 | ||
249 | case 'f': /* Get table from a file */ | |
250 | ||
135610f7 LZ |
251 | if (ap_insert_action |
252 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) { | |
253 | return (-1); | |
254 | } | |
506f57dd LZ |
255 | break; |
256 | ||
257 | case 'n': /* Get table by input name (signature) */ | |
258 | ||
135610f7 LZ |
259 | if (ap_insert_action |
260 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) { | |
261 | return (-1); | |
262 | } | |
506f57dd LZ |
263 | break; |
264 | ||
265 | default: | |
266 | ||
267 | ap_display_usage(); | |
135610f7 | 268 | return (-1); |
506f57dd LZ |
269 | } |
270 | ||
271 | /* If there are no actions, this means "get/dump all tables" */ | |
272 | ||
273 | if (current_action == 0) { | |
135610f7 LZ |
274 | if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) { |
275 | return (-1); | |
276 | } | |
506f57dd LZ |
277 | } |
278 | ||
279 | return (0); | |
280 | } | |
281 | ||
282 | /****************************************************************************** | |
283 | * | |
284 | * FUNCTION: main | |
285 | * | |
286 | * PARAMETERS: argc/argv - Standard argc/argv | |
287 | * | |
288 | * RETURN: Status | |
289 | * | |
290 | * DESCRIPTION: C main function for acpidump utility | |
291 | * | |
292 | ******************************************************************************/ | |
293 | ||
4d2c8223 | 294 | #ifndef _GNU_EFI |
506f57dd | 295 | int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) |
4d2c8223 LZ |
296 | #else |
297 | int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[]) | |
298 | #endif | |
506f57dd LZ |
299 | { |
300 | int status = 0; | |
301 | struct ap_dump_action *action; | |
302 | u32 file_size; | |
303 | u32 i; | |
304 | ||
305 | ACPI_DEBUG_INITIALIZE(); /* For debug version only */ | |
83b80bac | 306 | acpi_os_initialize(); |
846d6ef4 | 307 | gbl_output_file = ACPI_FILE_OUT; |
506f57dd LZ |
308 | |
309 | /* Process command line options */ | |
310 | ||
135610f7 LZ |
311 | status = ap_do_options(argc, argv); |
312 | if (status > 0) { | |
313 | return (0); | |
314 | } | |
315 | if (status < 0) { | |
316 | return (status); | |
506f57dd LZ |
317 | } |
318 | ||
319 | /* Get/dump ACPI table(s) as requested */ | |
320 | ||
321 | for (i = 0; i < current_action; i++) { | |
322 | action = &action_table[i]; | |
323 | switch (action->to_be_done) { | |
324 | case AP_DUMP_ALL_TABLES: | |
325 | ||
326 | status = ap_dump_all_tables(); | |
327 | break; | |
328 | ||
329 | case AP_DUMP_TABLE_BY_ADDRESS: | |
330 | ||
331 | status = ap_dump_table_by_address(action->argument); | |
332 | break; | |
333 | ||
334 | case AP_DUMP_TABLE_BY_NAME: | |
335 | ||
336 | status = ap_dump_table_by_name(action->argument); | |
337 | break; | |
338 | ||
339 | case AP_DUMP_TABLE_BY_FILE: | |
340 | ||
341 | status = ap_dump_table_from_file(action->argument); | |
342 | break; | |
343 | ||
344 | default: | |
345 | ||
dcaff16d LZ |
346 | acpi_log_error("Internal error, invalid action: 0x%X\n", |
347 | action->to_be_done); | |
506f57dd LZ |
348 | return (-1); |
349 | } | |
350 | ||
351 | if (status) { | |
352 | return (status); | |
353 | } | |
354 | } | |
355 | ||
846d6ef4 | 356 | if (gbl_output_filename) { |
506f57dd LZ |
357 | if (gbl_verbose_mode) { |
358 | ||
359 | /* Summary for the output file */ | |
360 | ||
361 | file_size = cm_get_file_size(gbl_output_file); | |
dcaff16d LZ |
362 | acpi_log_error |
363 | ("Output file %s contains 0x%X (%u) bytes\n\n", | |
364 | gbl_output_filename, file_size, file_size); | |
506f57dd LZ |
365 | } |
366 | ||
dcaff16d | 367 | acpi_os_close_file(gbl_output_file); |
506f57dd LZ |
368 | } |
369 | ||
370 | return (status); | |
371 | } |