1 /******************************************************************************
3 * Module Name: apdump - Dump routines for ACPI tables (acpidump)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
47 /* Local prototypes */
51 ACPI_TABLE_HEADER *Table,
53 ACPI_PHYSICAL_ADDRESS Address);
56 /******************************************************************************
58 * FUNCTION: ApIsValidHeader
60 * PARAMETERS: Table - Pointer to table to be validated
62 * RETURN: TRUE if the header appears to be valid. FALSE otherwise
64 * DESCRIPTION: Check for a valid ACPI table header
66 ******************************************************************************/
70 ACPI_TABLE_HEADER *Table)
73 if (!ACPI_VALIDATE_RSDP_SIG (Table->Signature))
75 /* Make sure signature is all ASCII and a valid ACPI name */
77 if (!AcpiUtValidAcpiName (Table->Signature))
79 fprintf (stderr, "Table signature (0x%8.8X) is invalid\n",
80 *(UINT32 *) Table->Signature);
84 /* Check for minimum table length */
86 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
88 fprintf (stderr, "Table length (0x%8.8X) is invalid\n",
98 /******************************************************************************
100 * FUNCTION: ApIsValidChecksum
102 * PARAMETERS: Table - Pointer to table to be validated
104 * RETURN: TRUE if the checksum appears to be valid. FALSE otherwise.
106 * DESCRIPTION: Check for a valid ACPI table checksum.
108 ******************************************************************************/
112 ACPI_TABLE_HEADER *Table)
115 ACPI_TABLE_RSDP *Rsdp;
118 if (ACPI_VALIDATE_RSDP_SIG (Table->Signature))
122 * Note: Other checksums are computed during the table dump.
124 Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
125 Status = AcpiTbValidateRsdp (Rsdp);
129 Status = AcpiTbVerifyChecksum (Table, Table->Length);
132 if (ACPI_FAILURE (Status))
134 fprintf (stderr, "%4.4s: Warning: wrong checksum in table\n",
142 /******************************************************************************
144 * FUNCTION: ApGetTableLength
146 * PARAMETERS: Table - Pointer to the table
148 * RETURN: Table length
150 * DESCRIPTION: Obtain table length according to table signature.
152 ******************************************************************************/
156 ACPI_TABLE_HEADER *Table)
158 ACPI_TABLE_RSDP *Rsdp;
161 /* Check if table is valid */
163 if (!ApIsValidHeader (Table))
168 if (ACPI_VALIDATE_RSDP_SIG (Table->Signature))
170 Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
171 return (Rsdp->Length);
174 /* Normal ACPI table */
176 return (Table->Length);
180 /******************************************************************************
182 * FUNCTION: ApDumpTableBuffer
184 * PARAMETERS: Table - ACPI table to be dumped
185 * Instance - ACPI table instance no. to be dumped
186 * Address - Physical address of the table
190 * DESCRIPTION: Dump an ACPI table in standard ASCII hex format, with a
191 * header that is compatible with the AcpiXtract utility.
193 ******************************************************************************/
197 ACPI_TABLE_HEADER *Table,
199 ACPI_PHYSICAL_ADDRESS Address)
204 TableLength = ApGetTableLength (Table);
206 /* Print only the header if requested */
210 AcpiTbPrintTableHeader (Address, Table);
214 /* Dump to binary file if requested */
218 return (ApWriteToBinaryFile (Table, Instance));
222 * Dump the table with header for use with acpixtract utility.
223 * Note: simplest to just always emit a 64-bit address. AcpiXtract
224 * utility can handle this.
226 printf ("%4.4s @ 0x%8.8X%8.8X\n", Table->Signature,
227 ACPI_FORMAT_UINT64 (Address));
229 AcpiUtDumpBuffer (ACPI_CAST_PTR (UINT8, Table), TableLength,
236 /******************************************************************************
238 * FUNCTION: ApDumpAllTables
244 * DESCRIPTION: Get all tables from the RSDT/XSDT (or at least all of the
245 * tables that we can possibly get).
247 ******************************************************************************/
253 ACPI_TABLE_HEADER *Table;
255 ACPI_PHYSICAL_ADDRESS Address;
261 /* Get and dump all available ACPI tables */
263 for (i = 0; i < AP_MAX_ACPI_FILES; i++)
265 Status = AcpiOsGetTableByIndex (i, &Table, &Instance, &Address);
266 if (ACPI_FAILURE (Status))
268 /* AE_LIMIT means that no more tables are available */
270 if (Status == AE_LIMIT)
276 fprintf (stderr, "Could not get ACPI tables, %s\n",
277 AcpiFormatException (Status));
282 fprintf (stderr, "Could not get ACPI table at index %u, %s\n",
283 i, AcpiFormatException (Status));
288 TableStatus = ApDumpTableBuffer (Table, Instance, Address);
297 /* Something seriously bad happened if the loop terminates here */
303 /******************************************************************************
305 * FUNCTION: ApDumpTableByAddress
307 * PARAMETERS: AsciiAddress - Address for requested ACPI table
311 * DESCRIPTION: Get an ACPI table via a physical address and dump it.
313 ******************************************************************************/
316 ApDumpTableByAddress (
319 ACPI_PHYSICAL_ADDRESS Address;
320 ACPI_TABLE_HEADER *Table;
326 /* Convert argument to an integer physical address */
328 Status = AcpiUtStrtoul64 (AsciiAddress, 0, &LongAddress);
329 if (ACPI_FAILURE (Status))
331 fprintf (stderr, "%s: Could not convert to a physical address\n",
336 Address = (ACPI_PHYSICAL_ADDRESS) LongAddress;
337 Status = AcpiOsGetTableByAddress (Address, &Table);
338 if (ACPI_FAILURE (Status))
340 fprintf (stderr, "Could not get table at 0x%8.8X%8.8X, %s\n",
341 ACPI_FORMAT_UINT64 (Address),
342 AcpiFormatException (Status));
346 TableStatus = ApDumpTableBuffer (Table, 0, Address);
348 return (TableStatus);
352 /******************************************************************************
354 * FUNCTION: ApDumpTableByName
356 * PARAMETERS: Signature - Requested ACPI table signature
360 * DESCRIPTION: Get an ACPI table via a signature and dump it. Handles
361 * multiple tables with the same signature (SSDTs).
363 ******************************************************************************/
369 char LocalSignature [ACPI_NAME_SIZE + 1];
371 ACPI_TABLE_HEADER *Table;
372 ACPI_PHYSICAL_ADDRESS Address;
377 if (strlen (Signature) != ACPI_NAME_SIZE)
380 "Invalid table signature [%s]: must be exactly 4 characters\n",
385 /* Table signatures are expected to be uppercase */
387 strcpy (LocalSignature, Signature);
388 AcpiUtStrupr (LocalSignature);
390 /* To be friendly, handle tables whose signatures do not match the name */
392 if (ACPI_COMPARE_NAME (LocalSignature, "FADT"))
394 strcpy (LocalSignature, ACPI_SIG_FADT);
396 else if (ACPI_COMPARE_NAME (LocalSignature, "MADT"))
398 strcpy (LocalSignature, ACPI_SIG_MADT);
401 /* Dump all instances of this signature (to handle multiple SSDTs) */
403 for (Instance = 0; Instance < AP_MAX_ACPI_FILES; Instance++)
405 Status = AcpiOsGetTableByName (LocalSignature, Instance,
407 if (ACPI_FAILURE (Status))
409 /* AE_LIMIT means that no more tables are available */
411 if (Status == AE_LIMIT)
417 "Could not get ACPI table with signature [%s], %s\n",
418 LocalSignature, AcpiFormatException (Status));
422 TableStatus = ApDumpTableBuffer (Table, Instance, Address);
431 /* Something seriously bad happened if the loop terminates here */
437 /******************************************************************************
439 * FUNCTION: ApDumpTableFromFile
441 * PARAMETERS: Pathname - File containing the binary ACPI table
445 * DESCRIPTION: Dump an ACPI table from a binary file
447 ******************************************************************************/
450 ApDumpTableFromFile (
453 ACPI_TABLE_HEADER *Table;
455 int TableStatus = -1;
458 /* Get the entire ACPI table from the file */
460 Table = ApGetTableFromFile (Pathname, &FileSize);
466 /* File must be at least as long as the table length */
468 if (Table->Length > FileSize)
471 "Table length (0x%X) is too large for input file (0x%X) %s\n",
472 Table->Length, FileSize, Pathname);
479 "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
480 Pathname, Table->Signature, FileSize, FileSize);
483 TableStatus = ApDumpTableBuffer (Table, 0, 0);
487 return (TableStatus);
491 /******************************************************************************
493 * FUNCTION: AcpiOs* print functions
495 * DESCRIPTION: Used for linkage with ACPICA modules
497 ******************************************************************************/
499 void ACPI_INTERNAL_VAR_XFACE
506 va_start (Args, Fmt);
507 vfprintf (stdout, Fmt, Args);
516 vfprintf (stdout, Fmt, Args);