1 /******************************************************************************
3 * Module Name: apdump - Dump routines for ACPI tables (acpidump)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
46 /* Local prototypes */
49 ap_dump_table_buffer(struct acpi_table_header *table,
50 u32 instance, acpi_physical_address address);
52 /******************************************************************************
54 * FUNCTION: ap_is_valid_header
56 * PARAMETERS: table - Pointer to table to be validated
58 * RETURN: TRUE if the header appears to be valid. FALSE otherwise
60 * DESCRIPTION: Check for a valid ACPI table header
62 ******************************************************************************/
64 u8 ap_is_valid_header(struct acpi_table_header *table)
67 if (!ACPI_VALIDATE_RSDP_SIG(table->signature)) {
69 /* Make sure signature is all ASCII and a valid ACPI name */
71 if (!acpi_ut_valid_nameseg(table->signature)) {
72 acpi_log_error("Table signature (0x%8.8X) is invalid\n",
73 *(u32 *)table->signature);
77 /* Check for minimum table length */
79 if (table->length < sizeof(struct acpi_table_header)) {
80 acpi_log_error("Table length (0x%8.8X) is invalid\n",
89 /******************************************************************************
91 * FUNCTION: ap_is_valid_checksum
93 * PARAMETERS: table - Pointer to table to be validated
95 * RETURN: TRUE if the checksum appears to be valid. FALSE otherwise.
97 * DESCRIPTION: Check for a valid ACPI table checksum.
99 ******************************************************************************/
101 u8 ap_is_valid_checksum(struct acpi_table_header *table)
104 struct acpi_table_rsdp *rsdp;
106 if (ACPI_VALIDATE_RSDP_SIG(table->signature)) {
109 * Note: Other checksums are computed during the table dump.
111 rsdp = ACPI_CAST_PTR(struct acpi_table_rsdp, table);
112 status = acpi_tb_validate_rsdp(rsdp);
114 status = acpi_tb_verify_checksum(table, table->length);
117 if (ACPI_FAILURE(status)) {
118 acpi_log_error("%4.4s: Warning: wrong checksum in table\n",
125 /******************************************************************************
127 * FUNCTION: ap_get_table_length
129 * PARAMETERS: table - Pointer to the table
131 * RETURN: Table length
133 * DESCRIPTION: Obtain table length according to table signature.
135 ******************************************************************************/
137 u32 ap_get_table_length(struct acpi_table_header *table)
139 struct acpi_table_rsdp *rsdp;
141 /* Check if table is valid */
143 if (!ap_is_valid_header(table)) {
147 if (ACPI_VALIDATE_RSDP_SIG(table->signature)) {
148 rsdp = ACPI_CAST_PTR(struct acpi_table_rsdp, table);
149 return (acpi_tb_get_rsdp_length(rsdp));
152 /* Normal ACPI table */
154 return (table->length);
157 /******************************************************************************
159 * FUNCTION: ap_dump_table_buffer
161 * PARAMETERS: table - ACPI table to be dumped
162 * instance - ACPI table instance no. to be dumped
163 * address - Physical address of the table
167 * DESCRIPTION: Dump an ACPI table in standard ASCII hex format, with a
168 * header that is compatible with the acpi_xtract utility.
170 ******************************************************************************/
173 ap_dump_table_buffer(struct acpi_table_header *table,
174 u32 instance, acpi_physical_address address)
178 table_length = ap_get_table_length(table);
180 /* Print only the header if requested */
182 if (gbl_summary_mode) {
183 acpi_tb_print_table_header(address, table);
187 /* Dump to binary file if requested */
189 if (gbl_binary_mode) {
190 return (ap_write_to_binary_file(table, instance));
194 * Dump the table with header for use with acpixtract utility.
195 * Note: simplest to just always emit a 64-bit address. acpi_xtract
196 * utility can handle this.
198 acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n",
199 table->signature, ACPI_FORMAT_UINT64(address));
201 acpi_ut_dump_buffer_to_file(gbl_output_file,
202 ACPI_CAST_PTR(u8, table), table_length,
204 acpi_ut_file_printf(gbl_output_file, "\n");
208 /******************************************************************************
210 * FUNCTION: ap_dump_all_tables
216 * DESCRIPTION: Get all tables from the RSDT/XSDT (or at least all of the
217 * tables that we can possibly get).
219 ******************************************************************************/
221 int ap_dump_all_tables(void)
223 struct acpi_table_header *table;
225 acpi_physical_address address;
230 /* Get and dump all available ACPI tables */
232 for (i = 0; i < AP_MAX_ACPI_FILES; i++) {
234 acpi_os_get_table_by_index(i, &table, &instance, &address);
235 if (ACPI_FAILURE(status)) {
237 /* AE_LIMIT means that no more tables are available */
239 if (status == AE_LIMIT) {
243 ("Could not get ACPI tables, %s\n",
244 acpi_format_exception(status));
248 ("Could not get ACPI table at index %u, %s\n",
249 i, acpi_format_exception(status));
254 table_status = ap_dump_table_buffer(table, instance, address);
262 /* Something seriously bad happened if the loop terminates here */
267 /******************************************************************************
269 * FUNCTION: ap_dump_table_by_address
271 * PARAMETERS: ascii_address - Address for requested ACPI table
275 * DESCRIPTION: Get an ACPI table via a physical address and dump it.
277 ******************************************************************************/
279 int ap_dump_table_by_address(char *ascii_address)
281 acpi_physical_address address;
282 struct acpi_table_header *table;
287 /* Convert argument to an integer physical address */
289 status = acpi_ut_strtoul64(ascii_address, ACPI_ANY_BASE,
290 ACPI_MAX64_BYTE_WIDTH, &long_address);
291 if (ACPI_FAILURE(status)) {
292 acpi_log_error("%s: Could not convert to a physical address\n",
297 address = (acpi_physical_address)long_address;
298 status = acpi_os_get_table_by_address(address, &table);
299 if (ACPI_FAILURE(status)) {
300 acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n",
301 ACPI_FORMAT_UINT64(address),
302 acpi_format_exception(status));
306 table_status = ap_dump_table_buffer(table, 0, address);
308 return (table_status);
311 /******************************************************************************
313 * FUNCTION: ap_dump_table_by_name
315 * PARAMETERS: signature - Requested ACPI table signature
319 * DESCRIPTION: Get an ACPI table via a signature and dump it. Handles
320 * multiple tables with the same signature (SSDTs).
322 ******************************************************************************/
324 int ap_dump_table_by_name(char *signature)
326 char local_signature[ACPI_NAME_SIZE + 1];
328 struct acpi_table_header *table;
329 acpi_physical_address address;
333 if (strlen(signature) != ACPI_NAME_SIZE) {
335 ("Invalid table signature [%s]: must be exactly 4 characters\n",
340 /* Table signatures are expected to be uppercase */
342 strcpy(local_signature, signature);
343 acpi_ut_strupr(local_signature);
345 /* To be friendly, handle tables whose signatures do not match the name */
347 if (ACPI_COMPARE_NAME(local_signature, "FADT")) {
348 strcpy(local_signature, ACPI_SIG_FADT);
349 } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) {
350 strcpy(local_signature, ACPI_SIG_MADT);
353 /* Dump all instances of this signature (to handle multiple SSDTs) */
355 for (instance = 0; instance < AP_MAX_ACPI_FILES; instance++) {
356 status = acpi_os_get_table_by_name(local_signature, instance,
358 if (ACPI_FAILURE(status)) {
360 /* AE_LIMIT means that no more tables are available */
362 if (status == AE_LIMIT) {
367 ("Could not get ACPI table with signature [%s], %s\n",
368 local_signature, acpi_format_exception(status));
372 table_status = ap_dump_table_buffer(table, instance, address);
380 /* Something seriously bad happened if the loop terminates here */
385 /******************************************************************************
387 * FUNCTION: ap_dump_table_from_file
389 * PARAMETERS: pathname - File containing the binary ACPI table
393 * DESCRIPTION: Dump an ACPI table from a binary file
395 ******************************************************************************/
397 int ap_dump_table_from_file(char *pathname)
399 struct acpi_table_header *table;
401 int table_status = -1;
403 /* Get the entire ACPI table from the file */
405 table = ap_get_table_from_file(pathname, &file_size);
410 if (!acpi_ut_valid_nameseg(table->signature)) {
412 ("No valid ACPI signature was found in input file %s\n",
416 /* File must be at least as long as the table length */
418 if (table->length > file_size) {
420 ("Table length (0x%X) is too large for input file (0x%X) %s\n",
421 table->length, file_size, pathname);
425 if (gbl_verbose_mode) {
427 ("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
428 pathname, table->signature, file_size, file_size);
431 table_status = ap_dump_table_buffer(table, 0, 0);
435 return (table_status);