1f8146b88SJung-uk Kim /****************************************************************************** 2f8146b88SJung-uk Kim * 3f8146b88SJung-uk Kim * Module Name: acfileio - Get ACPI tables from file 4f8146b88SJung-uk Kim * 5f8146b88SJung-uk Kim *****************************************************************************/ 6f8146b88SJung-uk Kim 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11*804fe266SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 12f8146b88SJung-uk Kim * All rights reserved. 13f8146b88SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119f8146b88SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120f8146b88SJung-uk Kim * modification, are permitted provided that the following conditions 121f8146b88SJung-uk Kim * are met: 122f8146b88SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123f8146b88SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124f8146b88SJung-uk Kim * without modification. 125f8146b88SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126f8146b88SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127f8146b88SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128f8146b88SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129f8146b88SJung-uk Kim * binary redistribution. 130f8146b88SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131f8146b88SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132f8146b88SJung-uk Kim * from this software without specific prior written permission. 133f8146b88SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147f8146b88SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148f8146b88SJung-uk Kim * Software Foundation. 149f8146b88SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151f8146b88SJung-uk Kim 152f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h> 153f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h> 154f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/actables.h> 155f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acutils.h> 156493deb39SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 157f8146b88SJung-uk Kim 158f8146b88SJung-uk Kim #define _COMPONENT ACPI_UTILITIES 159f8146b88SJung-uk Kim ACPI_MODULE_NAME ("acfileio") 160f8146b88SJung-uk Kim 161f8146b88SJung-uk Kim 162f8146b88SJung-uk Kim /* Local prototypes */ 163f8146b88SJung-uk Kim 164f8146b88SJung-uk Kim static ACPI_STATUS 165f8146b88SJung-uk Kim AcGetOneTableFromFile ( 166f8146b88SJung-uk Kim char *Filename, 167f8146b88SJung-uk Kim FILE *File, 168f8146b88SJung-uk Kim UINT8 GetOnlyAmlTables, 169f8146b88SJung-uk Kim ACPI_TABLE_HEADER **Table); 170f8146b88SJung-uk Kim 171f8146b88SJung-uk Kim static ACPI_STATUS 172f8146b88SJung-uk Kim AcCheckTextModeCorruption ( 173f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table); 174f8146b88SJung-uk Kim 175f8146b88SJung-uk Kim 176f8146b88SJung-uk Kim /******************************************************************************* 177f8146b88SJung-uk Kim * 1785f9b24faSJung-uk Kim * FUNCTION: AcDeleteTableList 1795f9b24faSJung-uk Kim * 1805f9b24faSJung-uk Kim * PARAMETERS: ListHead - List to delete 1815f9b24faSJung-uk Kim * 1825f9b24faSJung-uk Kim * RETURN: Status 1835f9b24faSJung-uk Kim * 1845f9b24faSJung-uk Kim * DESCRIPTION: Delete a list of tables. This is useful for removing memory 1855f9b24faSJung-uk Kim * allocated by AcGetAllTablesFromFile 1865f9b24faSJung-uk Kim * 1875f9b24faSJung-uk Kim ******************************************************************************/ 1885f9b24faSJung-uk Kim 1895f9b24faSJung-uk Kim void 1905f9b24faSJung-uk Kim AcDeleteTableList ( 1915f9b24faSJung-uk Kim ACPI_NEW_TABLE_DESC *ListHead) 1925f9b24faSJung-uk Kim { 1935f9b24faSJung-uk Kim ACPI_NEW_TABLE_DESC *Current = ListHead; 1945f9b24faSJung-uk Kim ACPI_NEW_TABLE_DESC *Previous = Current; 1955f9b24faSJung-uk Kim 1965f9b24faSJung-uk Kim 1975f9b24faSJung-uk Kim while (Current) 1985f9b24faSJung-uk Kim { 1995f9b24faSJung-uk Kim Current = Current->Next; 2005f9b24faSJung-uk Kim AcpiOsFree (Previous); 2015f9b24faSJung-uk Kim Previous = Current; 2025f9b24faSJung-uk Kim } 2035f9b24faSJung-uk Kim } 2045f9b24faSJung-uk Kim 2055f9b24faSJung-uk Kim 2065f9b24faSJung-uk Kim /******************************************************************************* 2075f9b24faSJung-uk Kim * 208f8146b88SJung-uk Kim * FUNCTION: AcGetAllTablesFromFile 209f8146b88SJung-uk Kim * 210f8146b88SJung-uk Kim * PARAMETERS: Filename - Table filename 211f8146b88SJung-uk Kim * GetOnlyAmlTables - TRUE if the tables must be AML tables 212f8146b88SJung-uk Kim * ReturnListHead - Where table list is returned 213f8146b88SJung-uk Kim * 214f8146b88SJung-uk Kim * RETURN: Status 215f8146b88SJung-uk Kim * 216f8146b88SJung-uk Kim * DESCRIPTION: Get all ACPI tables from within a single file. 217f8146b88SJung-uk Kim * 218f8146b88SJung-uk Kim ******************************************************************************/ 219f8146b88SJung-uk Kim 220f8146b88SJung-uk Kim ACPI_STATUS 221f8146b88SJung-uk Kim AcGetAllTablesFromFile ( 222f8146b88SJung-uk Kim char *Filename, 223f8146b88SJung-uk Kim UINT8 GetOnlyAmlTables, 224f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC **ReturnListHead) 225f8146b88SJung-uk Kim { 226f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC *ListHead = NULL; 227f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC *ListTail = NULL; 228f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC *TableDesc; 229f8146b88SJung-uk Kim FILE *File; 230f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table = NULL; 231f8146b88SJung-uk Kim UINT32 FileSize; 232f8146b88SJung-uk Kim ACPI_STATUS Status = AE_OK; 233f8146b88SJung-uk Kim 234f8146b88SJung-uk Kim 235f8146b88SJung-uk Kim File = fopen (Filename, "rb"); 236f8146b88SJung-uk Kim if (!File) 237f8146b88SJung-uk Kim { 238493deb39SJung-uk Kim fprintf (stderr, "Could not open input file: %s\n", Filename); 239f8146b88SJung-uk Kim if (errno == ENOENT) 240f8146b88SJung-uk Kim { 241f8146b88SJung-uk Kim return (AE_NOT_EXIST); 242f8146b88SJung-uk Kim } 243f8146b88SJung-uk Kim 244f8146b88SJung-uk Kim return (AE_ERROR); 245f8146b88SJung-uk Kim } 246f8146b88SJung-uk Kim 247f8146b88SJung-uk Kim /* Get the file size */ 248f8146b88SJung-uk Kim 249f8146b88SJung-uk Kim FileSize = CmGetFileSize (File); 250f8146b88SJung-uk Kim if (FileSize == ACPI_UINT32_MAX) 251f8146b88SJung-uk Kim { 252f8146b88SJung-uk Kim Status = AE_ERROR; 2531cc50d6bSJung-uk Kim goto Exit; 254f8146b88SJung-uk Kim } 255f8146b88SJung-uk Kim 256f8146b88SJung-uk Kim fprintf (stderr, 257f8146b88SJung-uk Kim "Input file %s, Length 0x%X (%u) bytes\n", 258f8146b88SJung-uk Kim Filename, FileSize, FileSize); 259f8146b88SJung-uk Kim 260f8146b88SJung-uk Kim /* We must have at least one ACPI table header */ 261f8146b88SJung-uk Kim 262f8146b88SJung-uk Kim if (FileSize < sizeof (ACPI_TABLE_HEADER)) 263f8146b88SJung-uk Kim { 264f8146b88SJung-uk Kim Status = AE_BAD_HEADER; 2651cc50d6bSJung-uk Kim goto Exit; 266f8146b88SJung-uk Kim } 267f8146b88SJung-uk Kim 268f8146b88SJung-uk Kim /* Check for an non-binary file */ 269f8146b88SJung-uk Kim 270f8146b88SJung-uk Kim if (!AcIsFileBinary (File)) 271f8146b88SJung-uk Kim { 272f8146b88SJung-uk Kim fprintf (stderr, 273f8146b88SJung-uk Kim " %s: File does not appear to contain a valid AML table\n", 274f8146b88SJung-uk Kim Filename); 2751cc50d6bSJung-uk Kim Status = AE_TYPE; 2761cc50d6bSJung-uk Kim goto Exit; 277f8146b88SJung-uk Kim } 278f8146b88SJung-uk Kim 279f8146b88SJung-uk Kim /* Read all tables within the file */ 280f8146b88SJung-uk Kim 281f8146b88SJung-uk Kim while (ACPI_SUCCESS (Status)) 282f8146b88SJung-uk Kim { 283f8146b88SJung-uk Kim /* Get one entire ACPI table */ 284f8146b88SJung-uk Kim 285f8146b88SJung-uk Kim Status = AcGetOneTableFromFile ( 286f8146b88SJung-uk Kim Filename, File, GetOnlyAmlTables, &Table); 287f8146b88SJung-uk Kim 288f8146b88SJung-uk Kim if (Status == AE_CTRL_TERMINATE) 289f8146b88SJung-uk Kim { 290f8146b88SJung-uk Kim Status = AE_OK; 291f8146b88SJung-uk Kim break; 292f8146b88SJung-uk Kim } 293f8146b88SJung-uk Kim else if (Status == AE_TYPE) 294f8146b88SJung-uk Kim { 2951cc50d6bSJung-uk Kim Status = AE_OK; 2961cc50d6bSJung-uk Kim goto Exit; 297f8146b88SJung-uk Kim } 298f8146b88SJung-uk Kim else if (ACPI_FAILURE (Status)) 299f8146b88SJung-uk Kim { 3001cc50d6bSJung-uk Kim goto Exit; 301f8146b88SJung-uk Kim } 302f8146b88SJung-uk Kim 303f8146b88SJung-uk Kim /* Print table header for iASL/disassembler only */ 304f8146b88SJung-uk Kim 305f8146b88SJung-uk Kim #ifdef ACPI_ASL_COMPILER 306f8146b88SJung-uk Kim 307f8146b88SJung-uk Kim AcpiTbPrintTableHeader (0, Table); 308f8146b88SJung-uk Kim #endif 309f8146b88SJung-uk Kim 310f8146b88SJung-uk Kim /* Allocate and link a table descriptor */ 311f8146b88SJung-uk Kim 312f8146b88SJung-uk Kim TableDesc = AcpiOsAllocate (sizeof (ACPI_NEW_TABLE_DESC)); 3131cc50d6bSJung-uk Kim if (!TableDesc) 3141cc50d6bSJung-uk Kim { 3151cc50d6bSJung-uk Kim AcpiOsFree (Table); 3161cc50d6bSJung-uk Kim Status = AE_NO_MEMORY; 3171cc50d6bSJung-uk Kim goto Exit; 3181cc50d6bSJung-uk Kim } 3191cc50d6bSJung-uk Kim 320f8146b88SJung-uk Kim TableDesc->Table = Table; 321f8146b88SJung-uk Kim TableDesc->Next = NULL; 322f8146b88SJung-uk Kim 323f8146b88SJung-uk Kim /* Link at the end of the local table list */ 324f8146b88SJung-uk Kim 325f8146b88SJung-uk Kim if (!ListHead) 326f8146b88SJung-uk Kim { 327f8146b88SJung-uk Kim ListHead = TableDesc; 328f8146b88SJung-uk Kim ListTail = TableDesc; 329f8146b88SJung-uk Kim } 330f8146b88SJung-uk Kim else 331f8146b88SJung-uk Kim { 332f8146b88SJung-uk Kim ListTail->Next = TableDesc; 333f8146b88SJung-uk Kim ListTail = TableDesc; 334f8146b88SJung-uk Kim } 335f8146b88SJung-uk Kim } 336f8146b88SJung-uk Kim 337f8146b88SJung-uk Kim /* Add the local table list to the end of the global list */ 338f8146b88SJung-uk Kim 339f8146b88SJung-uk Kim if (*ReturnListHead) 340f8146b88SJung-uk Kim { 341f8146b88SJung-uk Kim ListTail = *ReturnListHead; 342f8146b88SJung-uk Kim while (ListTail->Next) 343f8146b88SJung-uk Kim { 344f8146b88SJung-uk Kim ListTail = ListTail->Next; 345f8146b88SJung-uk Kim } 346f8146b88SJung-uk Kim 347f8146b88SJung-uk Kim ListTail->Next = ListHead; 348f8146b88SJung-uk Kim } 349f8146b88SJung-uk Kim else 350f8146b88SJung-uk Kim { 351f8146b88SJung-uk Kim *ReturnListHead = ListHead; 352f8146b88SJung-uk Kim } 353f8146b88SJung-uk Kim 3541cc50d6bSJung-uk Kim Exit: 355f8146b88SJung-uk Kim fclose(File); 356f8146b88SJung-uk Kim return (Status); 357f8146b88SJung-uk Kim } 358f8146b88SJung-uk Kim 359f8146b88SJung-uk Kim 360f8146b88SJung-uk Kim /******************************************************************************* 361f8146b88SJung-uk Kim * 362f8146b88SJung-uk Kim * FUNCTION: AcGetOneTableFromFile 363f8146b88SJung-uk Kim * 364f8146b88SJung-uk Kim * PARAMETERS: Filename - File where table is located 365f8146b88SJung-uk Kim * File - Open FILE pointer to Filename 366f8146b88SJung-uk Kim * GetOnlyAmlTables - TRUE if the tables must be AML tables. 367f8146b88SJung-uk Kim * ReturnTable - Where a pointer to the table is returned 368f8146b88SJung-uk Kim * 369f8146b88SJung-uk Kim * RETURN: Status 370f8146b88SJung-uk Kim * 371f8146b88SJung-uk Kim * DESCRIPTION: Read the next ACPI table from a file. Implements support 372f8146b88SJung-uk Kim * for multiple tables within a single file. File must already 373f8146b88SJung-uk Kim * be open. 374f8146b88SJung-uk Kim * 375f8146b88SJung-uk Kim * Note: Loading an RSDP is not supported. 376f8146b88SJung-uk Kim * 377f8146b88SJung-uk Kim ******************************************************************************/ 378f8146b88SJung-uk Kim 379f8146b88SJung-uk Kim static ACPI_STATUS 380f8146b88SJung-uk Kim AcGetOneTableFromFile ( 381f8146b88SJung-uk Kim char *Filename, 382f8146b88SJung-uk Kim FILE *File, 383f8146b88SJung-uk Kim UINT8 GetOnlyAmlTables, 384f8146b88SJung-uk Kim ACPI_TABLE_HEADER **ReturnTable) 385f8146b88SJung-uk Kim { 386f8146b88SJung-uk Kim ACPI_STATUS Status = AE_OK; 387f8146b88SJung-uk Kim ACPI_TABLE_HEADER TableHeader; 388f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table; 389f8146b88SJung-uk Kim INT32 Count; 3909a4bc520SJung-uk Kim UINT32 TableLength; 3919a4bc520SJung-uk Kim UINT32 HeaderLength; 3929a4bc520SJung-uk Kim long TableOffset = 0; 393f8146b88SJung-uk Kim 394f8146b88SJung-uk Kim *ReturnTable = NULL; 395f8146b88SJung-uk Kim 396f8146b88SJung-uk Kim /* Get the table header to examine signature and length */ 3979a4bc520SJung-uk Kim /* 3989a4bc520SJung-uk Kim * Special handling for the CDAT table (both the Length field 3999a4bc520SJung-uk Kim * and the Checksum field are not in the standard positions). 4009a4bc520SJung-uk Kim * (The table header is non-standard). 4019a4bc520SJung-uk Kim */ 4029a4bc520SJung-uk Kim if (AcpiGbl_CDAT) 4039a4bc520SJung-uk Kim { 4049a4bc520SJung-uk Kim HeaderLength = sizeof (ACPI_TABLE_CDAT); 4059a4bc520SJung-uk Kim } 4069a4bc520SJung-uk Kim else 4079a4bc520SJung-uk Kim { 4089a4bc520SJung-uk Kim HeaderLength = sizeof (ACPI_TABLE_HEADER); 4099a4bc520SJung-uk Kim } 4109a4bc520SJung-uk Kim 4119a4bc520SJung-uk Kim Status = AcValidateTableHeader (File, TableOffset); 4129a4bc520SJung-uk Kim if (ACPI_FAILURE (Status)) 4139a4bc520SJung-uk Kim { 4149a4bc520SJung-uk Kim return (Status); 4159a4bc520SJung-uk Kim } 416f8146b88SJung-uk Kim 417f8146b88SJung-uk Kim TableOffset = ftell (File); 4189a4bc520SJung-uk Kim Count = fread (&TableHeader, 1, HeaderLength, File); 4199a4bc520SJung-uk Kim if (Count != (INT32) HeaderLength) 420f8146b88SJung-uk Kim { 421f8146b88SJung-uk Kim return (AE_CTRL_TERMINATE); 422f8146b88SJung-uk Kim } 423f8146b88SJung-uk Kim 4243d90091dSJung-uk Kim if (GetOnlyAmlTables) 4253d90091dSJung-uk Kim { 426f8146b88SJung-uk Kim /* Validate the table signature/header (limited ASCII chars) */ 427f8146b88SJung-uk Kim 428493deb39SJung-uk Kim /* 429493deb39SJung-uk Kim * Table must be an AML table (DSDT/SSDT). 430493deb39SJung-uk Kim * Used for iASL -e option only. 431493deb39SJung-uk Kim */ 432493deb39SJung-uk Kim if (!AcpiUtIsAmlTable (&TableHeader)) 433f8146b88SJung-uk Kim { 434f8146b88SJung-uk Kim fprintf (stderr, 435f8146b88SJung-uk Kim " %s: Table [%4.4s] is not an AML table - ignoring\n", 436f8146b88SJung-uk Kim Filename, TableHeader.Signature); 437f8146b88SJung-uk Kim 438f8146b88SJung-uk Kim return (AE_TYPE); 439f8146b88SJung-uk Kim } 440f8146b88SJung-uk Kim } 441f8146b88SJung-uk Kim 4429a4bc520SJung-uk Kim /* 4439a4bc520SJung-uk Kim * Special handling for the CDAT table (both the Length field 4449a4bc520SJung-uk Kim * and the Checksum field are not in the standard positions). 4459a4bc520SJung-uk Kim */ 4469a4bc520SJung-uk Kim if (AcpiGbl_CDAT) 4479a4bc520SJung-uk Kim { 4489a4bc520SJung-uk Kim TableLength = ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader)->Length; 4499a4bc520SJung-uk Kim } 4509a4bc520SJung-uk Kim else 4519a4bc520SJung-uk Kim { 4529a4bc520SJung-uk Kim TableLength = TableHeader.Length; 4539a4bc520SJung-uk Kim } 4549a4bc520SJung-uk Kim 455f8146b88SJung-uk Kim /* Allocate a buffer for the entire table */ 456f8146b88SJung-uk Kim 4579a4bc520SJung-uk Kim Table = AcpiOsAllocate ((ACPI_SIZE) TableLength); 458f8146b88SJung-uk Kim if (!Table) 459f8146b88SJung-uk Kim { 460f8146b88SJung-uk Kim return (AE_NO_MEMORY); 461f8146b88SJung-uk Kim } 462f8146b88SJung-uk Kim 463f8146b88SJung-uk Kim /* Read the entire ACPI table, including header */ 464f8146b88SJung-uk Kim 465f8146b88SJung-uk Kim fseek (File, TableOffset, SEEK_SET); 4669a4bc520SJung-uk Kim Count = fread (Table, 1, TableLength, File); 4673d90091dSJung-uk Kim 4683d90091dSJung-uk Kim /* 4693d90091dSJung-uk Kim * Checks for data table headers happen later in the execution. Only verify 4703d90091dSJung-uk Kim * for Aml tables at this point in the code. 4713d90091dSJung-uk Kim */ 4729a4bc520SJung-uk Kim if (GetOnlyAmlTables && Count != (INT32) TableLength) 473f8146b88SJung-uk Kim { 474f8146b88SJung-uk Kim Status = AE_ERROR; 475f8146b88SJung-uk Kim goto ErrorExit; 476f8146b88SJung-uk Kim } 477f8146b88SJung-uk Kim 4789a4bc520SJung-uk Kim /* 4799a4bc520SJung-uk Kim * Validate the checksum (just issue a warning if incorrect). 4809a4bc520SJung-uk Kim * Note: CDAT is special cased here because the table does 4819a4bc520SJung-uk Kim * not have the checksum field in the standard position. 4829a4bc520SJung-uk Kim */ 4839a4bc520SJung-uk Kim if (AcpiGbl_CDAT) 4849a4bc520SJung-uk Kim { 4859a4bc520SJung-uk Kim Status = AcpiUtVerifyCdatChecksum ((ACPI_TABLE_CDAT *) Table, TableLength); 4869a4bc520SJung-uk Kim } else 4879a4bc520SJung-uk Kim { 4889a4bc520SJung-uk Kim Status = AcpiUtVerifyChecksum (Table, TableLength); 4899a4bc520SJung-uk Kim } 490f8146b88SJung-uk Kim 491f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 492f8146b88SJung-uk Kim { 493f8146b88SJung-uk Kim Status = AcCheckTextModeCorruption (Table); 494f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 495f8146b88SJung-uk Kim { 496f8146b88SJung-uk Kim goto ErrorExit; 497f8146b88SJung-uk Kim } 498f8146b88SJung-uk Kim } 499f8146b88SJung-uk Kim 500f8146b88SJung-uk Kim *ReturnTable = Table; 501f8146b88SJung-uk Kim return (AE_OK); 502f8146b88SJung-uk Kim 503f8146b88SJung-uk Kim 504f8146b88SJung-uk Kim ErrorExit: 505f8146b88SJung-uk Kim AcpiOsFree (Table); 506f8146b88SJung-uk Kim return (Status); 507f8146b88SJung-uk Kim } 508f8146b88SJung-uk Kim 509f8146b88SJung-uk Kim 510f8146b88SJung-uk Kim /******************************************************************************* 511f8146b88SJung-uk Kim * 512f8146b88SJung-uk Kim * FUNCTION: AcIsFileBinary 513f8146b88SJung-uk Kim * 514f8146b88SJung-uk Kim * PARAMETERS: File - Open input file 515f8146b88SJung-uk Kim * 516f8146b88SJung-uk Kim * RETURN: TRUE if file appears to be binary 517f8146b88SJung-uk Kim * 518f8146b88SJung-uk Kim * DESCRIPTION: Scan a file for any non-ASCII bytes. 519f8146b88SJung-uk Kim * 520f8146b88SJung-uk Kim * Note: Maintains current file position. 521f8146b88SJung-uk Kim * 522f8146b88SJung-uk Kim ******************************************************************************/ 523f8146b88SJung-uk Kim 524f8146b88SJung-uk Kim BOOLEAN 525f8146b88SJung-uk Kim AcIsFileBinary ( 526f8146b88SJung-uk Kim FILE *File) 527f8146b88SJung-uk Kim { 528f8146b88SJung-uk Kim UINT8 Byte; 529f8146b88SJung-uk Kim BOOLEAN IsBinary = FALSE; 530f8146b88SJung-uk Kim long FileOffset; 531f8146b88SJung-uk Kim 532f8146b88SJung-uk Kim 533f8146b88SJung-uk Kim /* Scan entire file for any non-ASCII bytes */ 534f8146b88SJung-uk Kim 535f8146b88SJung-uk Kim FileOffset = ftell (File); 536f8146b88SJung-uk Kim while (fread (&Byte, 1, 1, File) == 1) 537f8146b88SJung-uk Kim { 538f8146b88SJung-uk Kim if (!isprint (Byte) && !isspace (Byte)) 539f8146b88SJung-uk Kim { 540f8146b88SJung-uk Kim IsBinary = TRUE; 541f8146b88SJung-uk Kim goto Exit; 542f8146b88SJung-uk Kim } 543f8146b88SJung-uk Kim } 544f8146b88SJung-uk Kim 545f8146b88SJung-uk Kim Exit: 546f8146b88SJung-uk Kim fseek (File, FileOffset, SEEK_SET); 547f8146b88SJung-uk Kim return (IsBinary); 548f8146b88SJung-uk Kim } 549f8146b88SJung-uk Kim 550f8146b88SJung-uk Kim 551f8146b88SJung-uk Kim /******************************************************************************* 552f8146b88SJung-uk Kim * 553f8146b88SJung-uk Kim * FUNCTION: AcValidateTableHeader 554f8146b88SJung-uk Kim * 555f8146b88SJung-uk Kim * PARAMETERS: File - Open input file 556f8146b88SJung-uk Kim * 557f8146b88SJung-uk Kim * RETURN: Status 558f8146b88SJung-uk Kim * 559f8146b88SJung-uk Kim * DESCRIPTION: Determine if a file seems to contain one or more binary ACPI 560f8146b88SJung-uk Kim * tables, via the 561f8146b88SJung-uk Kim * following checks on what would be the table header: 562f8146b88SJung-uk Kim * 1) File must be at least as long as an ACPI_TABLE_HEADER 563f8146b88SJung-uk Kim * 2) There must be enough room in the file to hold entire table 564f8146b88SJung-uk Kim * 3) Signature, OemId, OemTableId, AslCompilerId must be ASCII 565f8146b88SJung-uk Kim * 566f8146b88SJung-uk Kim * Note: There can be multiple definition blocks per file, so we cannot 567f8146b88SJung-uk Kim * expect/compare the file size to be equal to the table length. 12/2015. 568f8146b88SJung-uk Kim * 569f8146b88SJung-uk Kim * Note: Maintains current file position. 570f8146b88SJung-uk Kim * 571f8146b88SJung-uk Kim ******************************************************************************/ 572f8146b88SJung-uk Kim 573f8146b88SJung-uk Kim ACPI_STATUS 574f8146b88SJung-uk Kim AcValidateTableHeader ( 575f8146b88SJung-uk Kim FILE *File, 576f8146b88SJung-uk Kim long TableOffset) 577f8146b88SJung-uk Kim { 578f8146b88SJung-uk Kim ACPI_TABLE_HEADER TableHeader; 5799a4bc520SJung-uk Kim ACPI_TABLE_CDAT *CdatTableHeader = ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader); 5809a4bc520SJung-uk Kim UINT32 HeaderLength; 581493deb39SJung-uk Kim ACPI_SIZE Actual; 582f8146b88SJung-uk Kim long OriginalOffset; 583f8146b88SJung-uk Kim UINT32 FileSize; 584f8146b88SJung-uk Kim UINT32 i; 585f8146b88SJung-uk Kim 586f8146b88SJung-uk Kim 58728482948SJung-uk Kim ACPI_FUNCTION_TRACE (AcValidateTableHeader); 588f8146b88SJung-uk Kim 5899a4bc520SJung-uk Kim /* Determine the type of table header */ 5909a4bc520SJung-uk Kim 5919a4bc520SJung-uk Kim if (AcpiGbl_CDAT) 5929a4bc520SJung-uk Kim { 5939a4bc520SJung-uk Kim HeaderLength = sizeof (ACPI_TABLE_CDAT); 5949a4bc520SJung-uk Kim } 5959a4bc520SJung-uk Kim else 5969a4bc520SJung-uk Kim { 5979a4bc520SJung-uk Kim HeaderLength = sizeof (ACPI_TABLE_HEADER); 5989a4bc520SJung-uk Kim } 599f8146b88SJung-uk Kim 600f8146b88SJung-uk Kim /* Read a potential table header */ 601f8146b88SJung-uk Kim 602f8146b88SJung-uk Kim OriginalOffset = ftell (File); 603ab71bbb7SJung-uk Kim if (fseek (File, TableOffset, SEEK_SET)) 604ab71bbb7SJung-uk Kim { 605ab71bbb7SJung-uk Kim fprintf (stderr, "SEEK error\n"); 606ab71bbb7SJung-uk Kim } 6079a4bc520SJung-uk Kim Actual = fread (&TableHeader, 1, HeaderLength, File); 608ab71bbb7SJung-uk Kim if (fseek (File, OriginalOffset, SEEK_SET)) 609ab71bbb7SJung-uk Kim { 610ab71bbb7SJung-uk Kim fprintf (stderr, "SEEK error\n"); 611ab71bbb7SJung-uk Kim } 612f8146b88SJung-uk Kim 6139a4bc520SJung-uk Kim if (Actual < HeaderLength) 614f8146b88SJung-uk Kim { 615cfd1ed46SJung-uk Kim fprintf (stderr, 616cfd1ed46SJung-uk Kim "Could not read entire table header: Actual %u, Requested %u\n", 6179a4bc520SJung-uk Kim (UINT32) Actual, HeaderLength); 618f8146b88SJung-uk Kim return (AE_ERROR); 619f8146b88SJung-uk Kim } 620f8146b88SJung-uk Kim 621f8146b88SJung-uk Kim /* Validate the signature (limited ASCII chars) */ 622f8146b88SJung-uk Kim 6239a4bc520SJung-uk Kim if (!AcpiGbl_CDAT && !AcpiUtValidNameseg (TableHeader.Signature)) 624f8146b88SJung-uk Kim { 6259a4bc520SJung-uk Kim /* 6269a4bc520SJung-uk Kim * The "-ds cdat" option was not used, and the signature is not valid. 6279a4bc520SJung-uk Kim * 6289a4bc520SJung-uk Kim * For CDAT we are assuming that there should be at least one non-ASCII 6299a4bc520SJung-uk Kim * byte in the (normally) 4-character Signature field (at least the 6309a4bc520SJung-uk Kim * high-order byte should be zero). Otherwise, this is OK. 6319a4bc520SJung-uk Kim */ 6329a4bc520SJung-uk Kim fprintf (stderr, 6339a4bc520SJung-uk Kim "\nTable appears to be a CDAT table, which has no signature.\n" 6349a4bc520SJung-uk Kim "If this is in fact a CDAT table, use the -ds option on the\n" 6359a4bc520SJung-uk Kim "command line to specify the table type (signature):\n" 6369a4bc520SJung-uk Kim "\"iasl -d -ds CDAT <file>\" or \"iasl -ds CDAT -T CDAT\"\n\n"); 6379a4bc520SJung-uk Kim 638f8146b88SJung-uk Kim return (AE_BAD_SIGNATURE); 639f8146b88SJung-uk Kim } 640f8146b88SJung-uk Kim 641f8146b88SJung-uk Kim /* Validate table length against bytes remaining in the file */ 642f8146b88SJung-uk Kim 643f8146b88SJung-uk Kim FileSize = CmGetFileSize (File); 6449a4bc520SJung-uk Kim if (!AcpiGbl_CDAT) 6459a4bc520SJung-uk Kim { 6469a4bc520SJung-uk Kim /* Standard ACPI table header */ 6479a4bc520SJung-uk Kim 648f8146b88SJung-uk Kim if (TableHeader.Length > (UINT32) (FileSize - TableOffset)) 649f8146b88SJung-uk Kim { 650f8146b88SJung-uk Kim fprintf (stderr, "Table [%4.4s] is too long for file - " 651f8146b88SJung-uk Kim "needs: 0x%.2X, remaining in file: 0x%.2X\n", 652f8146b88SJung-uk Kim TableHeader.Signature, TableHeader.Length, 653f8146b88SJung-uk Kim (UINT32) (FileSize - TableOffset)); 654f8146b88SJung-uk Kim return (AE_BAD_HEADER); 655f8146b88SJung-uk Kim } 6569a4bc520SJung-uk Kim } 6579a4bc520SJung-uk Kim else if (CdatTableHeader->Length > (UINT32) (FileSize - TableOffset)) 6589a4bc520SJung-uk Kim { 6599a4bc520SJung-uk Kim /* Special header for CDAT table */ 6609a4bc520SJung-uk Kim 6619a4bc520SJung-uk Kim fprintf (stderr, "Table [CDAT] is too long for file - " 6629a4bc520SJung-uk Kim "needs: 0x%.2X, remaining in file: 0x%.2X\n", 6639a4bc520SJung-uk Kim CdatTableHeader->Length, 6649a4bc520SJung-uk Kim (UINT32) (FileSize - TableOffset)); 6659a4bc520SJung-uk Kim return (AE_BAD_HEADER); 6669a4bc520SJung-uk Kim } 6679a4bc520SJung-uk Kim 6689a4bc520SJung-uk Kim /* For CDAT table, there are no ASCII fields in the header, we are done */ 6699a4bc520SJung-uk Kim 6709a4bc520SJung-uk Kim if (AcpiGbl_CDAT) 6719a4bc520SJung-uk Kim { 6729a4bc520SJung-uk Kim return (AE_OK); 6739a4bc520SJung-uk Kim } 674f8146b88SJung-uk Kim 675f8146b88SJung-uk Kim /* 6769a4bc520SJung-uk Kim * These standard fields must be ASCII: OemId, OemTableId, AslCompilerId. 677f8146b88SJung-uk Kim * We allow a NULL terminator in OemId and OemTableId. 678f8146b88SJung-uk Kim */ 679278f0de6SJung-uk Kim for (i = 0; i < ACPI_NAMESEG_SIZE; i++) 680f8146b88SJung-uk Kim { 681f8146b88SJung-uk Kim if (!ACPI_IS_ASCII ((UINT8) TableHeader.AslCompilerId[i])) 682f8146b88SJung-uk Kim { 683f8146b88SJung-uk Kim goto BadCharacters; 684f8146b88SJung-uk Kim } 685f8146b88SJung-uk Kim } 686f8146b88SJung-uk Kim 687f8146b88SJung-uk Kim for (i = 0; (i < ACPI_OEM_ID_SIZE) && (TableHeader.OemId[i]); i++) 688f8146b88SJung-uk Kim { 689f8146b88SJung-uk Kim if (!ACPI_IS_ASCII ((UINT8) TableHeader.OemId[i])) 690f8146b88SJung-uk Kim { 691f8146b88SJung-uk Kim goto BadCharacters; 692f8146b88SJung-uk Kim } 693f8146b88SJung-uk Kim } 694f8146b88SJung-uk Kim 695f8146b88SJung-uk Kim for (i = 0; (i < ACPI_OEM_TABLE_ID_SIZE) && (TableHeader.OemTableId[i]); i++) 696f8146b88SJung-uk Kim { 697f8146b88SJung-uk Kim if (!ACPI_IS_ASCII ((UINT8) TableHeader.OemTableId[i])) 698f8146b88SJung-uk Kim { 699f8146b88SJung-uk Kim goto BadCharacters; 700f8146b88SJung-uk Kim } 701f8146b88SJung-uk Kim } 702f8146b88SJung-uk Kim 703f8146b88SJung-uk Kim return (AE_OK); 704f8146b88SJung-uk Kim 705f8146b88SJung-uk Kim 706f8146b88SJung-uk Kim BadCharacters: 707f8146b88SJung-uk Kim 708f8146b88SJung-uk Kim ACPI_WARNING ((AE_INFO, 709f8146b88SJung-uk Kim "Table header for [%4.4s] has invalid ASCII character(s)", 710f8146b88SJung-uk Kim TableHeader.Signature)); 711f8146b88SJung-uk Kim return (AE_OK); 712f8146b88SJung-uk Kim } 713f8146b88SJung-uk Kim 714f8146b88SJung-uk Kim 715f8146b88SJung-uk Kim /******************************************************************************* 716f8146b88SJung-uk Kim * 717f8146b88SJung-uk Kim * FUNCTION: AcCheckTextModeCorruption 718f8146b88SJung-uk Kim * 719f8146b88SJung-uk Kim * PARAMETERS: Table - Table buffer starting with table header 720f8146b88SJung-uk Kim * 721f8146b88SJung-uk Kim * RETURN: Status 722f8146b88SJung-uk Kim * 723f8146b88SJung-uk Kim * DESCRIPTION: Check table for text mode file corruption where all linefeed 724f8146b88SJung-uk Kim * characters (LF) have been replaced by carriage return linefeed 725f8146b88SJung-uk Kim * pairs (CR/LF). 726f8146b88SJung-uk Kim * 727f8146b88SJung-uk Kim ******************************************************************************/ 728f8146b88SJung-uk Kim 729f8146b88SJung-uk Kim static ACPI_STATUS 730f8146b88SJung-uk Kim AcCheckTextModeCorruption ( 731f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table) 732f8146b88SJung-uk Kim { 733f8146b88SJung-uk Kim UINT32 i; 734f8146b88SJung-uk Kim UINT32 Pairs = 0; 735f8146b88SJung-uk Kim UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Table); 736f8146b88SJung-uk Kim 737f8146b88SJung-uk Kim 738f8146b88SJung-uk Kim /* Scan entire table to determine if each LF has been prefixed with a CR */ 739f8146b88SJung-uk Kim 740f8146b88SJung-uk Kim for (i = 1; i < Table->Length; i++) 741f8146b88SJung-uk Kim { 742f8146b88SJung-uk Kim if (Buffer[i] == 0x0A) 743f8146b88SJung-uk Kim { 744f8146b88SJung-uk Kim if (Buffer[i - 1] != 0x0D) 745f8146b88SJung-uk Kim { 746f8146b88SJung-uk Kim /* The LF does not have a preceding CR, table not corrupted */ 747f8146b88SJung-uk Kim 748f8146b88SJung-uk Kim return (AE_OK); 749f8146b88SJung-uk Kim } 750f8146b88SJung-uk Kim else 751f8146b88SJung-uk Kim { 752f8146b88SJung-uk Kim /* Found a CR/LF pair */ 753f8146b88SJung-uk Kim 754f8146b88SJung-uk Kim Pairs++; 755f8146b88SJung-uk Kim } 756f8146b88SJung-uk Kim 757f8146b88SJung-uk Kim i++; 758f8146b88SJung-uk Kim } 759f8146b88SJung-uk Kim } 760f8146b88SJung-uk Kim 761f8146b88SJung-uk Kim if (!Pairs) 762f8146b88SJung-uk Kim { 763f8146b88SJung-uk Kim return (AE_OK); 764f8146b88SJung-uk Kim } 765f8146b88SJung-uk Kim 766f8146b88SJung-uk Kim /* 767f8146b88SJung-uk Kim * Entire table scanned, each CR is part of a CR/LF pair -- 768f8146b88SJung-uk Kim * meaning that the table was treated as a text file somewhere. 769f8146b88SJung-uk Kim * 770f8146b88SJung-uk Kim * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the 771f8146b88SJung-uk Kim * original table are left untouched by the text conversion process -- 772f8146b88SJung-uk Kim * meaning that we cannot simply replace CR/LF pairs with LFs. 773f8146b88SJung-uk Kim */ 774f8146b88SJung-uk Kim AcpiOsPrintf ("Table has been corrupted by text mode conversion\n"); 775f8146b88SJung-uk Kim AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs); 776f8146b88SJung-uk Kim AcpiOsPrintf ("Table cannot be repaired!\n"); 777f8146b88SJung-uk Kim 778f8146b88SJung-uk Kim return (AE_BAD_VALUE); 779f8146b88SJung-uk Kim } 780