1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: apdump - Dump routines for ACPI tables (acpidump)
6 * Copyright (C) 2000 - 2023, Intel Corp.
8 *****************************************************************************/
12 /* Local prototypes */
15 ap_dump_table_buffer(struct acpi_table_header *table,
16 u32 instance, acpi_physical_address address);
18 /******************************************************************************
20 * FUNCTION: ap_is_valid_header
22 * PARAMETERS: table - Pointer to table to be validated
24 * RETURN: TRUE if the header appears to be valid. FALSE otherwise
26 * DESCRIPTION: Check for a valid ACPI table header
28 ******************************************************************************/
30 u8 ap_is_valid_header(struct acpi_table_header *table)
33 if (!ACPI_VALIDATE_RSDP_SIG(table->signature)) {
35 /* Make sure signature is all ASCII and a valid ACPI name */
37 if (!acpi_ut_valid_nameseg(table->signature)) {
39 "Table signature (0x%8.8X) is invalid\n",
40 *(u32 *)table->signature);
44 /* Check for minimum table length */
46 if (table->length < sizeof(struct acpi_table_header)) {
47 fprintf(stderr, "Table length (0x%8.8X) is invalid\n",
56 /******************************************************************************
58 * FUNCTION: ap_is_valid_checksum
60 * PARAMETERS: table - Pointer to table to be validated
62 * RETURN: TRUE if the checksum appears to be valid. FALSE otherwise.
64 * DESCRIPTION: Check for a valid ACPI table checksum.
66 ******************************************************************************/
68 u8 ap_is_valid_checksum(struct acpi_table_header *table)
71 struct acpi_table_rsdp *rsdp;
73 if (ACPI_VALIDATE_RSDP_SIG(table->signature)) {
76 * Note: Other checksums are computed during the table dump.
78 rsdp = ACPI_CAST_PTR(struct acpi_table_rsdp, table);
79 status = acpi_tb_validate_rsdp(rsdp);
81 /* We don't have to check for a CDAT here, since CDAT is not in the RSDT/XSDT */
83 status = acpi_ut_verify_checksum(table, table->length);
86 if (ACPI_FAILURE(status)) {
87 fprintf(stderr, "%4.4s: Warning: wrong checksum in table\n",
94 /******************************************************************************
96 * FUNCTION: ap_get_table_length
98 * PARAMETERS: table - Pointer to the table
100 * RETURN: Table length
102 * DESCRIPTION: Obtain table length according to table signature.
104 ******************************************************************************/
106 u32 ap_get_table_length(struct acpi_table_header *table)
108 struct acpi_table_rsdp *rsdp;
110 /* Check if table is valid */
112 if (!ap_is_valid_header(table)) {
116 if (ACPI_VALIDATE_RSDP_SIG(table->signature)) {
117 rsdp = ACPI_CAST_PTR(struct acpi_table_rsdp, table);
118 return (acpi_tb_get_rsdp_length(rsdp));
121 /* Normal ACPI table */
123 return (table->length);
126 /******************************************************************************
128 * FUNCTION: ap_dump_table_buffer
130 * PARAMETERS: table - ACPI table to be dumped
131 * instance - ACPI table instance no. to be dumped
132 * address - Physical address of the table
136 * DESCRIPTION: Dump an ACPI table in standard ASCII hex format, with a
137 * header that is compatible with the acpi_xtract utility.
139 ******************************************************************************/
142 ap_dump_table_buffer(struct acpi_table_header *table,
143 u32 instance, acpi_physical_address address)
147 table_length = ap_get_table_length(table);
149 /* Print only the header if requested */
151 if (gbl_summary_mode) {
152 acpi_tb_print_table_header(address, table);
156 /* Dump to binary file if requested */
158 if (gbl_binary_mode) {
159 return (ap_write_to_binary_file(table, instance));
163 * Dump the table with header for use with acpixtract utility.
164 * Note: simplest to just always emit a 64-bit address. acpi_xtract
165 * utility can handle this.
167 fprintf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n",
168 table->signature, ACPI_FORMAT_UINT64(address));
170 acpi_ut_dump_buffer_to_file(gbl_output_file,
171 ACPI_CAST_PTR(u8, table), table_length,
173 fprintf(gbl_output_file, "\n");
177 /******************************************************************************
179 * FUNCTION: ap_dump_all_tables
185 * DESCRIPTION: Get all tables from the RSDT/XSDT (or at least all of the
186 * tables that we can possibly get).
188 ******************************************************************************/
190 int ap_dump_all_tables(void)
192 struct acpi_table_header *table;
194 acpi_physical_address address;
199 /* Get and dump all available ACPI tables */
201 for (i = 0; i < AP_MAX_ACPI_FILES; i++) {
203 acpi_os_get_table_by_index(i, &table, &instance, &address);
204 if (ACPI_FAILURE(status)) {
206 /* AE_LIMIT means that no more tables are available */
208 if (status == AE_LIMIT) {
212 "Could not get ACPI tables, %s\n",
213 acpi_format_exception(status));
217 "Could not get ACPI table at index %u, %s\n",
218 i, acpi_format_exception(status));
223 table_status = ap_dump_table_buffer(table, instance, address);
231 /* Something seriously bad happened if the loop terminates here */
236 /******************************************************************************
238 * FUNCTION: ap_dump_table_by_address
240 * PARAMETERS: ascii_address - Address for requested ACPI table
244 * DESCRIPTION: Get an ACPI table via a physical address and dump it.
246 ******************************************************************************/
248 int ap_dump_table_by_address(char *ascii_address)
250 acpi_physical_address address;
251 struct acpi_table_header *table;
256 /* Convert argument to an integer physical address */
258 status = acpi_ut_strtoul64(ascii_address, &long_address);
259 if (ACPI_FAILURE(status)) {
260 fprintf(stderr, "%s: Could not convert to a physical address\n",
265 address = (acpi_physical_address)long_address;
266 status = acpi_os_get_table_by_address(address, &table);
267 if (ACPI_FAILURE(status)) {
268 fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n",
269 ACPI_FORMAT_UINT64(address),
270 acpi_format_exception(status));
274 table_status = ap_dump_table_buffer(table, 0, address);
276 return (table_status);
279 /******************************************************************************
281 * FUNCTION: ap_dump_table_by_name
283 * PARAMETERS: signature - Requested ACPI table signature
287 * DESCRIPTION: Get an ACPI table via a signature and dump it. Handles
288 * multiple tables with the same signature (SSDTs).
290 ******************************************************************************/
292 int ap_dump_table_by_name(char *signature)
294 char local_signature[ACPI_NAMESEG_SIZE + 1];
296 struct acpi_table_header *table;
297 acpi_physical_address address;
301 if (strlen(signature) != ACPI_NAMESEG_SIZE) {
303 "Invalid table signature [%s]: must be exactly 4 characters\n",
308 /* Table signatures are expected to be uppercase */
310 strcpy(local_signature, signature);
311 acpi_ut_strupr(local_signature);
313 /* To be friendly, handle tables whose signatures do not match the name */
315 if (ACPI_COMPARE_NAMESEG(local_signature, "FADT")) {
316 strcpy(local_signature, ACPI_SIG_FADT);
317 } else if (ACPI_COMPARE_NAMESEG(local_signature, "MADT")) {
318 strcpy(local_signature, ACPI_SIG_MADT);
321 /* Dump all instances of this signature (to handle multiple SSDTs) */
323 for (instance = 0; instance < AP_MAX_ACPI_FILES; instance++) {
324 status = acpi_os_get_table_by_name(local_signature, instance,
326 if (ACPI_FAILURE(status)) {
328 /* AE_LIMIT means that no more tables are available */
330 if (status == AE_LIMIT) {
335 "Could not get ACPI table with signature [%s], %s\n",
336 local_signature, acpi_format_exception(status));
340 table_status = ap_dump_table_buffer(table, instance, address);
348 /* Something seriously bad happened if the loop terminates here */
353 /******************************************************************************
355 * FUNCTION: ap_dump_table_from_file
357 * PARAMETERS: pathname - File containing the binary ACPI table
361 * DESCRIPTION: Dump an ACPI table from a binary file
363 ******************************************************************************/
365 int ap_dump_table_from_file(char *pathname)
367 struct acpi_table_header *table;
369 int table_status = -1;
371 /* Get the entire ACPI table from the file */
373 table = ap_get_table_from_file(pathname, &file_size);
378 if (!acpi_ut_valid_nameseg(table->signature)) {
380 "No valid ACPI signature was found in input file %s\n",
384 /* File must be at least as long as the table length */
386 if (table->length > file_size) {
388 "Table length (0x%X) is too large for input file (0x%X) %s\n",
389 table->length, file_size, pathname);
393 if (gbl_verbose_mode) {
395 "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
396 pathname, table->signature, file_size, file_size);
399 table_status = ap_dump_table_buffer(table, 0, 0);
403 return (table_status);