Path: blob/main/sys/contrib/dev/acpica/common/dmtbdump.c
48375 views
/******************************************************************************1*2* Module Name: dmtbdump - Dump ACPI data tables that contain no AML code3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acdisasm.h>154#include <contrib/dev/acpica/include/actables.h>155156/* This module used for application-level code only */157158#define _COMPONENT ACPI_CA_DISASSEMBLER159ACPI_MODULE_NAME ("dmtbdump")160161162/* Local prototypes */163164static void165AcpiDmValidateFadtLength (166UINT32 Revision,167UINT32 Length);168169170/*******************************************************************************171*172* FUNCTION: AcpiDmDumpBuffer173*174* PARAMETERS: Table - ACPI Table or subtable175* BufferOffset - Offset of buffer from Table above176* Length - Length of the buffer177* AbsoluteOffset - Offset of buffer in the main ACPI table178* Header - Name of the buffer field (printed on the179* first line only.)180*181* RETURN: None182*183* DESCRIPTION: Format the contents of an arbitrary length data buffer (in the184* disassembler output format.)185*186******************************************************************************/187188void189AcpiDmDumpBuffer (190void *Table,191UINT32 BufferOffset,192UINT32 Length,193UINT32 AbsoluteOffset,194char *Header)195{196UINT8 *Buffer;197UINT8 BufChar;198UINT32 i;199UINT32 j;200201202if (!Length)203{204return;205}206207Buffer = ACPI_CAST_PTR (UINT8, Table) + BufferOffset;208i = 0;209210while (i < Length)211{212if ((Length > 16) && (i != 0))213{214if ((Length - i) < 16)215AcpiOsPrintf ("\n/* %3.3Xh %4.4u %3u */ ", AbsoluteOffset, AbsoluteOffset, Length - i);216else217AcpiOsPrintf ("\n/* %3.3Xh %4.4u 16 */ ", AbsoluteOffset, AbsoluteOffset);218}219AbsoluteOffset += 16;220221/* Emit the raw data bytes*/222223for (j = 0; j < 16; j++)224{225if (i + j >= Length)226{227/* Dump fill spaces */228229AcpiOsPrintf ("%*s", (48 - (3 * (Length -i))), " ");230break;231}232AcpiOsPrintf ("%.02X ", Buffer[(ACPI_SIZE) i + j]);233}234235/* Emit the ASCII equivalent to the raw data bytes */236237for (j = 0; j < 16; j++)238{239if (i + j >= Length)240{241AcpiOsPrintf (" */\\\n");242return;243}244245/*246* Add comment characters so rest of line is ignored when247* compiled248*/249if (j == 0)250{251AcpiOsPrintf ("/* ");252}253254BufChar = Buffer[(ACPI_SIZE) i + j];255if (isprint (BufChar))256{257AcpiOsPrintf ("%c", BufChar);258}259else260{261AcpiOsPrintf (".");262}263}264265/* Done with that line. */266/* Close the comment and insert a backslash - line continuation character */267268AcpiOsPrintf (" */\\");269270i += 16; /* Point to next line */271}272273AcpiOsPrintf ("\n");274}275276277/*******************************************************************************278*279* FUNCTION: AcpiDmDumpUnicode280*281* PARAMETERS: Table - ACPI Table or subtable282* BufferOffset - Offset of buffer from Table above283* ByteLength - Length of the buffer284*285* RETURN: None286*287* DESCRIPTION: Validate and dump the contents of a buffer that contains288* unicode data. The output is a standard ASCII string. If it289* appears that the data is not unicode, the buffer is dumped290* as hex characters.291*292******************************************************************************/293294void295AcpiDmDumpUnicode (296void *Table,297UINT32 BufferOffset,298UINT32 ByteLength)299{300UINT8 *Buffer;301UINT32 Length;302UINT32 i;303304305Buffer = ((UINT8 *) Table) + BufferOffset;306Length = ByteLength - 2; /* Last two bytes are the null terminator */307308/* Ensure all low bytes are entirely printable ASCII */309310for (i = 0; i < Length; i += 2)311{312if (!isprint (Buffer[i]))313{314goto DumpRawBuffer;315}316}317318/* Ensure all high bytes are zero */319320for (i = 1; i < Length; i += 2)321{322if (Buffer[i])323{324goto DumpRawBuffer;325}326}327328/* Dump the buffer as a normal string */329330AcpiOsPrintf ("\"");331for (i = 0; i < Length; i += 2)332{333AcpiOsPrintf ("%c", Buffer[i]);334}335336AcpiOsPrintf ("\"\n");337return;338339DumpRawBuffer:340AcpiDmDumpBuffer (Table, BufferOffset, ByteLength,341BufferOffset, NULL);342AcpiOsPrintf ("\n");343}344345346/*******************************************************************************347*348* FUNCTION: AcpiDmDumpRsdp349*350* PARAMETERS: Table - A RSDP351*352* RETURN: Length of the table (there is not always a length field,353* use revision or length if available (ACPI 2.0+))354*355* DESCRIPTION: Format the contents of a RSDP356*357******************************************************************************/358359UINT32360AcpiDmDumpRsdp (361ACPI_TABLE_HEADER *Table)362{363ACPI_TABLE_RSDP *Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);364UINT32 Length = sizeof (ACPI_RSDP_COMMON);365UINT8 Checksum;366ACPI_STATUS Status;367368369/* Dump the common ACPI 1.0 portion */370371Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp1);372if (ACPI_FAILURE (Status))373{374return (Length);375}376377/* Validate the first checksum */378379Checksum = AcpiUtGenerateChecksum (Rsdp, sizeof (ACPI_RSDP_COMMON),380Rsdp->Checksum);381if (Checksum != Rsdp->Checksum)382{383AcpiOsPrintf ("/* Incorrect Checksum above, should be 0x%2.2X */\n",384Checksum);385}386387/* The RSDP for ACPI 2.0+ contains more data and has a Length field */388389if (Rsdp->Revision > 0)390{391Length = Rsdp->Length;392Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp2);393if (ACPI_FAILURE (Status))394{395return (Length);396}397398/* Validate the extended checksum over entire RSDP */399400Checksum = AcpiUtGenerateChecksum (Rsdp, sizeof (ACPI_TABLE_RSDP),401Rsdp->ExtendedChecksum);402if (Checksum != Rsdp->ExtendedChecksum)403{404AcpiOsPrintf (405"/* Incorrect Extended Checksum above, should be 0x%2.2X */\n",406Checksum);407}408}409410return (Length);411}412413414/*******************************************************************************415*416* FUNCTION: AcpiDmDumpRsdt417*418* PARAMETERS: Table - A RSDT419*420* RETURN: None421*422* DESCRIPTION: Format the contents of a RSDT423*424******************************************************************************/425426void427AcpiDmDumpRsdt (428ACPI_TABLE_HEADER *Table)429{430UINT32 *Array;431UINT32 Entries;432UINT32 Offset;433UINT32 i;434435436/* Point to start of table pointer array */437438Array = ACPI_CAST_PTR (ACPI_TABLE_RSDT, Table)->TableOffsetEntry;439Offset = sizeof (ACPI_TABLE_HEADER);440441/* RSDT uses 32-bit pointers */442443Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT32);444445for (i = 0; i < Entries; i++)446{447AcpiDmLineHeader2 (Offset, sizeof (UINT32), "ACPI Table Address", i);448AcpiOsPrintf ("%8.8X\n", Array[i]);449Offset += sizeof (UINT32);450}451}452453454/*******************************************************************************455*456* FUNCTION: AcpiDmDumpXsdt457*458* PARAMETERS: Table - A XSDT459*460* RETURN: None461*462* DESCRIPTION: Format the contents of a XSDT463*464******************************************************************************/465466void467AcpiDmDumpXsdt (468ACPI_TABLE_HEADER *Table)469{470UINT64 *Array;471UINT32 Entries;472UINT32 Offset;473UINT32 i;474475476/* Point to start of table pointer array */477478Array = ACPI_CAST_PTR (ACPI_TABLE_XSDT, Table)->TableOffsetEntry;479Offset = sizeof (ACPI_TABLE_HEADER);480481/* XSDT uses 64-bit pointers */482483Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT64);484485for (i = 0; i < Entries; i++)486{487AcpiDmLineHeader2 (Offset, sizeof (UINT64), "ACPI Table Address", i);488AcpiOsPrintf ("%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Array[i]));489Offset += sizeof (UINT64);490}491}492493494/*******************************************************************************495*496* FUNCTION: AcpiDmDumpFadt497*498* PARAMETERS: Table - A FADT499*500* RETURN: None501*502* DESCRIPTION: Format the contents of a FADT503*504* NOTE: We cannot depend on the FADT version to indicate the actual505* contents of the FADT because of BIOS bugs. The table length506* is the only reliable indicator.507*508******************************************************************************/509510void511AcpiDmDumpFadt (512ACPI_TABLE_HEADER *Table)513{514ACPI_STATUS Status;515516517/* Always dump the minimum FADT revision 1 fields (ACPI 1.0) */518519Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,520AcpiDmTableInfoFadt1);521if (ACPI_FAILURE (Status))522{523return;524}525526/* Check for FADT revision 2 fields (ACPI 1.0B MS extensions) */527528if ((Table->Length > ACPI_FADT_V1_SIZE) &&529(Table->Length <= ACPI_FADT_V2_SIZE))530{531Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,532AcpiDmTableInfoFadt2);533if (ACPI_FAILURE (Status))534{535return;536}537}538539/* Check for FADT revision 3/4 fields and up (ACPI 2.0+ extended data) */540541else if (Table->Length > ACPI_FADT_V2_SIZE)542{543Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,544AcpiDmTableInfoFadt3);545if (ACPI_FAILURE (Status))546{547return;548}549550/* Check for FADT revision 5 fields and up (ACPI 5.0+) */551552if (Table->Length > ACPI_FADT_V3_SIZE)553{554Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,555AcpiDmTableInfoFadt5);556if (ACPI_FAILURE (Status))557{558return;559}560}561562/* Check for FADT revision 6 fields and up (ACPI 6.0+) */563564if (Table->Length > ACPI_FADT_V5_SIZE)565{566Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,567AcpiDmTableInfoFadt6);568if (ACPI_FAILURE (Status))569{570return;571}572}573}574575/* Validate various fields in the FADT, including length */576577AcpiTbCreateLocalFadt (Table, Table->Length);578579/* Validate FADT length against the revision */580581AcpiDmValidateFadtLength (Table->Revision, Table->Length);582}583584585/*******************************************************************************586*587* FUNCTION: AcpiDmValidateFadtLength588*589* PARAMETERS: Revision - FADT revision (Header->Revision)590* Length - FADT length (Header->Length591*592* RETURN: None593*594* DESCRIPTION: Check the FADT revision against the expected table length for595* that revision. Issue a warning if the length is not what was596* expected. This seems to be such a common BIOS bug that the597* FADT revision has been rendered virtually meaningless.598*599******************************************************************************/600601static void602AcpiDmValidateFadtLength (603UINT32 Revision,604UINT32 Length)605{606UINT32 ExpectedLength;607608609switch (Revision)610{611case 0:612613AcpiOsPrintf ("// ACPI Warning: Invalid FADT revision: 0\n");614return;615616case 1:617618ExpectedLength = ACPI_FADT_V1_SIZE;619break;620621case 2:622623ExpectedLength = ACPI_FADT_V2_SIZE;624break;625626case 3:627case 4:628629ExpectedLength = ACPI_FADT_V3_SIZE;630break;631632case 5:633634ExpectedLength = ACPI_FADT_V5_SIZE;635break;636637case 6:638639ExpectedLength = ACPI_FADT_V6_SIZE;640break;641642default:643644return;645}646647if (Length == ExpectedLength)648{649return;650}651652AcpiOsPrintf (653"\n// ACPI Warning: FADT revision %X does not match length: "654"found %X expected %X\n",655Revision, Length, ExpectedLength);656}657658659