inet6: require RTF_ANNOUNCE to proxy NS
[dragonfly.git] / sys / contrib / dev / acpica / source / common / dmtbdump.c
blob86c90d67b683d5df9f097b330c3bce458b4b2c6d
1 /******************************************************************************
3 * Module Name: dmtbdump - Dump ACPI data tables that contain no AML code
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acdisasm.h"
155 #include "actables.h"
157 /* This module used for application-level code only */
159 #define _COMPONENT ACPI_CA_DISASSEMBLER
160 ACPI_MODULE_NAME ("dmtbdump")
163 /* Local prototypes */
165 static void
166 AcpiDmValidateFadtLength (
167 UINT32 Revision,
168 UINT32 Length);
171 /*******************************************************************************
173 * FUNCTION: AcpiDmDumpBuffer
175 * PARAMETERS: Table - ACPI Table or subtable
176 * BufferOffset - Offset of buffer from Table above
177 * Length - Length of the buffer
178 * AbsoluteOffset - Offset of buffer in the main ACPI table
179 * Header - Name of the buffer field (printed on the
180 * first line only.)
182 * RETURN: None
184 * DESCRIPTION: Format the contents of an arbitrary length data buffer (in the
185 * disassembler output format.)
187 ******************************************************************************/
189 void
190 AcpiDmDumpBuffer (
191 void *Table,
192 UINT32 BufferOffset,
193 UINT32 Length,
194 UINT32 AbsoluteOffset,
195 char *Header)
197 UINT8 *Buffer;
198 UINT8 BufChar;
199 UINT32 i;
200 UINT32 j;
203 if (!Length)
205 return;
208 Buffer = ACPI_CAST_PTR (UINT8, Table) + BufferOffset;
209 i = 0;
211 while (i < Length)
213 if ((Length > 16) && (i != 0))
215 if ((Length - i) < 16)
216 AcpiOsPrintf ("\n/* %3.3Xh %4.4u %3u */ ", AbsoluteOffset, AbsoluteOffset, Length - i);
217 else
218 AcpiOsPrintf ("\n/* %3.3Xh %4.4u 16 */ ", AbsoluteOffset, AbsoluteOffset);
220 AbsoluteOffset += 16;
222 /* Emit the raw data bytes*/
224 for (j = 0; j < 16; j++)
226 if (i + j >= Length)
228 /* Dump fill spaces */
230 AcpiOsPrintf ("%*s", (48 - (3 * (Length -i))), " ");
231 break;
233 AcpiOsPrintf ("%.02X ", Buffer[(ACPI_SIZE) i + j]);
236 /* Emit the ASCII equivalent to the raw data bytes */
238 for (j = 0; j < 16; j++)
240 if (i + j >= Length)
242 AcpiOsPrintf (" */\\\n");
243 return;
247 * Add comment characters so rest of line is ignored when
248 * compiled
250 if (j == 0)
252 AcpiOsPrintf ("/* ");
255 BufChar = Buffer[(ACPI_SIZE) i + j];
256 if (isprint (BufChar))
258 AcpiOsPrintf ("%c", BufChar);
260 else
262 AcpiOsPrintf (".");
266 /* Done with that line. */
267 /* Close the comment and insert a backslash - line continuation character */
269 if (Length > 16)
271 AcpiOsPrintf (" */\\");
273 else
275 AcpiOsPrintf (" */\\");
278 i += 16; /* Point to next line */
281 AcpiOsPrintf ("\n");
285 /*******************************************************************************
287 * FUNCTION: AcpiDmDumpUnicode
289 * PARAMETERS: Table - ACPI Table or subtable
290 * BufferOffset - Offset of buffer from Table above
291 * ByteLength - Length of the buffer
293 * RETURN: None
295 * DESCRIPTION: Validate and dump the contents of a buffer that contains
296 * unicode data. The output is a standard ASCII string. If it
297 * appears that the data is not unicode, the buffer is dumped
298 * as hex characters.
300 ******************************************************************************/
302 void
303 AcpiDmDumpUnicode (
304 void *Table,
305 UINT32 BufferOffset,
306 UINT32 ByteLength)
308 UINT8 *Buffer;
309 UINT32 Length;
310 UINT32 i;
313 Buffer = ((UINT8 *) Table) + BufferOffset;
314 Length = ByteLength - 2; /* Last two bytes are the null terminator */
316 /* Ensure all low bytes are entirely printable ASCII */
318 for (i = 0; i < Length; i += 2)
320 if (!isprint (Buffer[i]))
322 goto DumpRawBuffer;
326 /* Ensure all high bytes are zero */
328 for (i = 1; i < Length; i += 2)
330 if (Buffer[i])
332 goto DumpRawBuffer;
336 /* Dump the buffer as a normal string */
338 AcpiOsPrintf ("\"");
339 for (i = 0; i < Length; i += 2)
341 AcpiOsPrintf ("%c", Buffer[i]);
344 AcpiOsPrintf ("\"\n");
345 return;
347 DumpRawBuffer:
348 AcpiDmDumpBuffer (Table, BufferOffset, ByteLength,
349 BufferOffset, NULL);
350 AcpiOsPrintf ("\n");
354 /*******************************************************************************
356 * FUNCTION: AcpiDmDumpRsdp
358 * PARAMETERS: Table - A RSDP
360 * RETURN: Length of the table (there is not always a length field,
361 * use revision or length if available (ACPI 2.0+))
363 * DESCRIPTION: Format the contents of a RSDP
365 ******************************************************************************/
367 UINT32
368 AcpiDmDumpRsdp (
369 ACPI_TABLE_HEADER *Table)
371 ACPI_TABLE_RSDP *Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
372 UINT32 Length = sizeof (ACPI_RSDP_COMMON);
373 UINT8 Checksum;
374 ACPI_STATUS Status;
377 /* Dump the common ACPI 1.0 portion */
379 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp1);
380 if (ACPI_FAILURE (Status))
382 return (Length);
385 /* Validate the first checksum */
387 Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_RSDP_COMMON),
388 Rsdp->Checksum);
389 if (Checksum != Rsdp->Checksum)
391 AcpiOsPrintf ("/* Incorrect Checksum above, should be 0x%2.2X */\n",
392 Checksum);
395 /* The RSDP for ACPI 2.0+ contains more data and has a Length field */
397 if (Rsdp->Revision > 0)
399 Length = Rsdp->Length;
400 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp2);
401 if (ACPI_FAILURE (Status))
403 return (Length);
406 /* Validate the extended checksum over entire RSDP */
408 Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_TABLE_RSDP),
409 Rsdp->ExtendedChecksum);
410 if (Checksum != Rsdp->ExtendedChecksum)
412 AcpiOsPrintf (
413 "/* Incorrect Extended Checksum above, should be 0x%2.2X */\n",
414 Checksum);
418 return (Length);
422 /*******************************************************************************
424 * FUNCTION: AcpiDmDumpRsdt
426 * PARAMETERS: Table - A RSDT
428 * RETURN: None
430 * DESCRIPTION: Format the contents of a RSDT
432 ******************************************************************************/
434 void
435 AcpiDmDumpRsdt (
436 ACPI_TABLE_HEADER *Table)
438 UINT32 *Array;
439 UINT32 Entries;
440 UINT32 Offset;
441 UINT32 i;
444 /* Point to start of table pointer array */
446 Array = ACPI_CAST_PTR (ACPI_TABLE_RSDT, Table)->TableOffsetEntry;
447 Offset = sizeof (ACPI_TABLE_HEADER);
449 /* RSDT uses 32-bit pointers */
451 Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT32);
453 for (i = 0; i < Entries; i++)
455 AcpiDmLineHeader2 (Offset, sizeof (UINT32), "ACPI Table Address", i);
456 AcpiOsPrintf ("%8.8X\n", Array[i]);
457 Offset += sizeof (UINT32);
462 /*******************************************************************************
464 * FUNCTION: AcpiDmDumpXsdt
466 * PARAMETERS: Table - A XSDT
468 * RETURN: None
470 * DESCRIPTION: Format the contents of a XSDT
472 ******************************************************************************/
474 void
475 AcpiDmDumpXsdt (
476 ACPI_TABLE_HEADER *Table)
478 UINT64 *Array;
479 UINT32 Entries;
480 UINT32 Offset;
481 UINT32 i;
484 /* Point to start of table pointer array */
486 Array = ACPI_CAST_PTR (ACPI_TABLE_XSDT, Table)->TableOffsetEntry;
487 Offset = sizeof (ACPI_TABLE_HEADER);
489 /* XSDT uses 64-bit pointers */
491 Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT64);
493 for (i = 0; i < Entries; i++)
495 AcpiDmLineHeader2 (Offset, sizeof (UINT64), "ACPI Table Address", i);
496 AcpiOsPrintf ("%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Array[i]));
497 Offset += sizeof (UINT64);
502 /*******************************************************************************
504 * FUNCTION: AcpiDmDumpFadt
506 * PARAMETERS: Table - A FADT
508 * RETURN: None
510 * DESCRIPTION: Format the contents of a FADT
512 * NOTE: We cannot depend on the FADT version to indicate the actual
513 * contents of the FADT because of BIOS bugs. The table length
514 * is the only reliable indicator.
516 ******************************************************************************/
518 void
519 AcpiDmDumpFadt (
520 ACPI_TABLE_HEADER *Table)
522 ACPI_STATUS Status;
525 /* Always dump the minimum FADT revision 1 fields (ACPI 1.0) */
527 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
528 AcpiDmTableInfoFadt1);
529 if (ACPI_FAILURE (Status))
531 return;
534 /* Check for FADT revision 2 fields (ACPI 1.0B MS extensions) */
536 if ((Table->Length > ACPI_FADT_V1_SIZE) &&
537 (Table->Length <= ACPI_FADT_V2_SIZE))
539 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
540 AcpiDmTableInfoFadt2);
541 if (ACPI_FAILURE (Status))
543 return;
547 /* Check for FADT revision 3/4 fields and up (ACPI 2.0+ extended data) */
549 else if (Table->Length > ACPI_FADT_V2_SIZE)
551 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
552 AcpiDmTableInfoFadt3);
553 if (ACPI_FAILURE (Status))
555 return;
558 /* Check for FADT revision 5 fields and up (ACPI 5.0+) */
560 if (Table->Length > ACPI_FADT_V3_SIZE)
562 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
563 AcpiDmTableInfoFadt5);
564 if (ACPI_FAILURE (Status))
566 return;
570 /* Check for FADT revision 6 fields and up (ACPI 6.0+) */
572 if (Table->Length > ACPI_FADT_V3_SIZE)
574 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
575 AcpiDmTableInfoFadt6);
576 if (ACPI_FAILURE (Status))
578 return;
583 /* Validate various fields in the FADT, including length */
585 AcpiTbCreateLocalFadt (Table, Table->Length);
587 /* Validate FADT length against the revision */
589 AcpiDmValidateFadtLength (Table->Revision, Table->Length);
593 /*******************************************************************************
595 * FUNCTION: AcpiDmValidateFadtLength
597 * PARAMETERS: Revision - FADT revision (Header->Revision)
598 * Length - FADT length (Header->Length
600 * RETURN: None
602 * DESCRIPTION: Check the FADT revision against the expected table length for
603 * that revision. Issue a warning if the length is not what was
604 * expected. This seems to be such a common BIOS bug that the
605 * FADT revision has been rendered virtually meaningless.
607 ******************************************************************************/
609 static void
610 AcpiDmValidateFadtLength (
611 UINT32 Revision,
612 UINT32 Length)
614 UINT32 ExpectedLength;
617 switch (Revision)
619 case 0:
621 AcpiOsPrintf ("// ACPI Warning: Invalid FADT revision: 0\n");
622 return;
624 case 1:
626 ExpectedLength = ACPI_FADT_V1_SIZE;
627 break;
629 case 2:
631 ExpectedLength = ACPI_FADT_V2_SIZE;
632 break;
634 case 3:
635 case 4:
637 ExpectedLength = ACPI_FADT_V3_SIZE;
638 break;
640 case 5:
642 ExpectedLength = ACPI_FADT_V5_SIZE;
643 break;
645 default:
647 return;
650 if (Length == ExpectedLength)
652 return;
655 AcpiOsPrintf (
656 "\n// ACPI Warning: FADT revision %X does not match length: "
657 "found %X expected %X\n",
658 Revision, Length, ExpectedLength);