Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / tools / acpidump / apdump.c
blobd216cf5e45e5a0babaf5b69c85b66e36d7d37bd8
1 /******************************************************************************
3 * Module Name: apdump - Dump routines for ACPI tables (acpidump)
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "acpidump.h"
47 /* Local prototypes */
49 static int
50 ApDumpTableBuffer (
51 ACPI_TABLE_HEADER *Table,
52 UINT32 Instance,
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 ******************************************************************************/
68 BOOLEAN
69 ApIsValidHeader (
70 ACPI_TABLE_HEADER *Table)
72 if (!ACPI_VALIDATE_RSDP_SIG (Table->Signature))
74 /* Make sure signature is all ASCII and a valid ACPI name */
76 if (!AcpiUtValidAcpiName (Table->Signature))
78 fprintf (stderr, "Table signature (0x%8.8X) is invalid\n",
79 *(UINT32 *) Table->Signature);
80 return (FALSE);
83 /* Check for minimum table length */
85 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
87 fprintf (stderr, "Table length (0x%8.8X) is invalid\n",
88 Table->Length);
89 return (FALSE);
93 return (TRUE);
97 /******************************************************************************
99 * FUNCTION: ApIsValidChecksum
101 * PARAMETERS: Table - Pointer to table to be validated
103 * RETURN: TRUE if the checksum appears to be valid. FALSE otherwise
105 * DESCRIPTION: Check for a valid ACPI table checksum
107 ******************************************************************************/
109 BOOLEAN
110 ApIsValidChecksum (
111 ACPI_TABLE_HEADER *Table)
113 ACPI_STATUS Status;
114 ACPI_TABLE_RSDP *Rsdp;
117 if (ACPI_VALIDATE_RSDP_SIG (Table->Signature))
120 * Checksum for RSDP.
121 * Note: Other checksums are computed during the table dump.
124 Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
125 Status = AcpiTbValidateRsdp (Rsdp);
127 else
129 Status = AcpiTbVerifyChecksum (Table, Table->Length);
132 if (ACPI_FAILURE (Status))
134 fprintf (stderr, "%4.4s: Warning: wrong checksum\n",
135 Table->Signature);
138 return (AE_OK);
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 ******************************************************************************/
154 UINT32
155 ApGetTableLength (
156 ACPI_TABLE_HEADER *Table)
158 ACPI_TABLE_RSDP *Rsdp;
161 /* Check if table is valid */
163 if (!ApIsValidHeader (Table))
165 return (0);
168 if (ACPI_VALIDATE_RSDP_SIG (Table->Signature))
170 Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
171 return (Rsdp->Length);
173 else
175 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
188 * RETURN: None
190 * DESCRIPTION: Dump an ACPI table in standard ASCII hex format, with a
191 * header that is compatible with the AcpiXtract utility.
193 ******************************************************************************/
195 static int
196 ApDumpTableBuffer (
197 ACPI_TABLE_HEADER *Table,
198 UINT32 Instance,
199 ACPI_PHYSICAL_ADDRESS Address)
201 UINT32 TableLength;
204 TableLength = ApGetTableLength (Table);
206 /* Print only the header if requested */
208 if (Gbl_SummaryMode)
210 AcpiTbPrintTableHeader (Address, Table);
211 return (0);
214 /* Dump to binary file if requested */
216 if (Gbl_BinaryMode)
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,
230 DB_BYTE_DISPLAY, 0);
231 printf ("\n");
232 return (0);
236 /******************************************************************************
238 * FUNCTION: ApDumpAllTables
240 * PARAMETERS: None
242 * RETURN: Status
244 * DESCRIPTION: Get all tables from the RSDT/XSDT (or at least all of the
245 * tables that we can possibly get).
247 ******************************************************************************/
250 ApDumpAllTables (
251 void)
253 ACPI_TABLE_HEADER *Table;
254 UINT32 Instance = 0;
255 ACPI_PHYSICAL_ADDRESS Address;
256 ACPI_STATUS Status;
257 UINT32 i;
260 /* Get and dump all available ACPI tables */
262 for (i = 0; i < AP_MAX_ACPI_FILES; i++)
264 Status = AcpiOsGetTableByIndex (i, &Table, &Instance, &Address);
265 if (ACPI_FAILURE (Status))
267 /* AE_LIMIT means that no more tables are available */
269 if (Status == AE_LIMIT)
271 return (0);
273 else if (i == 0)
275 fprintf (stderr, "Could not get ACPI tables, %s\n",
276 AcpiFormatException (Status));
277 return (-1);
279 else
281 fprintf (stderr, "Could not get ACPI table at index %u, %s\n",
282 i, AcpiFormatException (Status));
283 continue;
287 if (ApDumpTableBuffer (Table, Instance, Address))
289 return (-1);
291 free (Table);
294 /* Something seriously bad happened if the loop terminates here */
296 return (-1);
300 /******************************************************************************
302 * FUNCTION: ApDumpTableByAddress
304 * PARAMETERS: AsciiAddress - Address for requested ACPI table
306 * RETURN: Status
308 * DESCRIPTION: Get an ACPI table via a physical address and dump it.
310 ******************************************************************************/
313 ApDumpTableByAddress (
314 char *AsciiAddress)
316 ACPI_PHYSICAL_ADDRESS Address;
317 ACPI_TABLE_HEADER *Table;
318 ACPI_STATUS Status;
319 int TableStatus;
320 UINT64 LongAddress;
323 /* Convert argument to an integer physical address */
325 Status = AcpiUtStrtoul64 (AsciiAddress, 0, &LongAddress);
326 if (ACPI_FAILURE (Status))
328 fprintf (stderr, "%s: Could not convert to a physical address\n",
329 AsciiAddress);
330 return (-1);
333 Address = (ACPI_PHYSICAL_ADDRESS) LongAddress;
334 Status = AcpiOsGetTableByAddress (Address, &Table);
335 if (ACPI_FAILURE (Status))
337 fprintf (stderr, "Could not get table at 0x%8.8X%8.8X, %s\n",
338 ACPI_FORMAT_UINT64 (Address),
339 AcpiFormatException (Status));
340 return (-1);
343 TableStatus = ApDumpTableBuffer (Table, 0, Address);
344 free (Table);
345 return (TableStatus);
349 /******************************************************************************
351 * FUNCTION: ApDumpTableByName
353 * PARAMETERS: Signature - Requested ACPI table signature
355 * RETURN: Status
357 * DESCRIPTION: Get an ACPI table via a signature and dump it. Handles
358 * multiple tables with the same signature (SSDTs).
360 ******************************************************************************/
363 ApDumpTableByName (
364 char *Signature)
366 char LocalSignature [ACPI_NAME_SIZE + 1];
367 UINT32 Instance;
368 ACPI_TABLE_HEADER *Table;
369 ACPI_PHYSICAL_ADDRESS Address;
370 ACPI_STATUS Status;
373 if (strlen (Signature) != ACPI_NAME_SIZE)
375 fprintf (stderr,
376 "Invalid table signature [%s]: must be exactly 4 characters\n",
377 Signature);
378 return (-1);
381 /* Table signatures are expected to be uppercase */
383 strcpy (LocalSignature, Signature);
384 AcpiUtStrupr (LocalSignature);
386 /* To be friendly, handle tables whose signatures do not match the name */
388 if (ACPI_COMPARE_NAME (LocalSignature, AP_DUMP_SIG_RSDP))
390 strcpy (LocalSignature, AP_DUMP_SIG_RSDP);
392 else 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,
406 &Table, &Address);
407 if (ACPI_FAILURE (Status))
409 /* AE_LIMIT means that no more tables are available */
411 if (Status == AE_LIMIT)
413 return (0);
416 fprintf (stderr,
417 "Could not get ACPI table with signature [%s], %s\n",
418 LocalSignature, AcpiFormatException (Status));
419 return (-1);
422 if (ApDumpTableBuffer (Table, Instance, Address))
424 return (-1);
426 free (Table);
429 /* Something seriously bad happened if the loop terminates here */
431 return (-1);
435 /******************************************************************************
437 * FUNCTION: ApDumpTableFromFile
439 * PARAMETERS: Pathname - File containing the binary ACPI table
441 * RETURN: Status
443 * DESCRIPTION: Dump an ACPI table from a binary file
445 ******************************************************************************/
448 ApDumpTableFromFile (
449 char *Pathname)
451 ACPI_TABLE_HEADER *Table;
452 UINT32 FileSize = 0;
453 int TableStatus;
456 /* Get the entire ACPI table from the file */
458 Table = ApGetTableFromFile (Pathname, &FileSize);
459 if (!Table)
461 return (-1);
464 /* File must be at least as long as the table length */
466 if (Table->Length > FileSize)
468 fprintf (stderr,
469 "Table length (0x%X) is too large for input file (0x%X) %s\n",
470 Table->Length, FileSize, Pathname);
471 return (-1);
474 if (Gbl_VerboseMode)
476 fprintf (stderr,
477 "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
478 Pathname, Table->Signature, FileSize, FileSize);
481 TableStatus = ApDumpTableBuffer (Table, 0, 0);
482 free (Table);
483 return (TableStatus);
487 /******************************************************************************
489 * FUNCTION: AcpiOs* print functions
491 * DESCRIPTION: Used for linkage with ACPICA modules
493 ******************************************************************************/
495 void ACPI_INTERNAL_VAR_XFACE
496 AcpiOsPrintf (
497 const char *Fmt,
498 ...)
500 va_list Args;
502 va_start (Args, Fmt);
503 vfprintf (stdout, Fmt, Args);
504 va_end (Args);
507 void
508 AcpiOsVprintf (
509 const char *Fmt,
510 va_list Args)
512 vfprintf (stdout, Fmt, Args);