dbfileio.c revision 151940
167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: dbfileio - Debugger file I/O commands. These can't usually 467754Smsmith * be used when running the debugger in Ring 0 (Kernel mode) 5151937Sjkim * $Revision: 1.84 $ 667754Smsmith * 767754Smsmith ******************************************************************************/ 867754Smsmith 967754Smsmith/****************************************************************************** 1067754Smsmith * 1167754Smsmith * 1. Copyright Notice 1267754Smsmith * 13151937Sjkim * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp. 1470243Smsmith * All rights reserved. 1567754Smsmith * 1667754Smsmith * 2. License 1767754Smsmith * 1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1967754Smsmith * rights. You may have additional license terms from the party that provided 2067754Smsmith * you this software, covering your right to use that party's intellectual 2167754Smsmith * property rights. 2267754Smsmith * 2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2867754Smsmith * Code in any form, with the right to sublicense such rights; and 2967754Smsmith * 3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3167754Smsmith * license (with the right to sublicense), under only those claims of Intel 3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3567754Smsmith * license, and in no event shall the patent license extend to any additions 3667754Smsmith * to or modifications of the Original Intel Code. No other license or right 3767754Smsmith * is granted directly or by implication, estoppel or otherwise; 3867754Smsmith * 3967754Smsmith * The above copyright and patent license is granted only if the following 4067754Smsmith * conditions are met: 4167754Smsmith * 4267754Smsmith * 3. Conditions 4367754Smsmith * 4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4567754Smsmith * Redistribution of source code of any substantial portion of the Covered 4667754Smsmith * Code or modification with rights to further distribute source must include 4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4867754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered 5167754Smsmith * Code and the date of any change. Licensee must include in that file the 5267754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5367754Smsmith * must include a prominent statement that the modification is derived, 5467754Smsmith * directly or indirectly, from Original Intel Code. 5567754Smsmith * 5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5767754Smsmith * Redistribution of source code of any substantial portion of the Covered 5867754Smsmith * Code or modification without rights to further distribute source must 5967754Smsmith * include the following Disclaimer and Export Compliance provision in the 6067754Smsmith * documentation and/or other materials provided with distribution. In 6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6367754Smsmith * license from Licensee to its licensee is limited to the intellectual 6467754Smsmith * property embodied in the software Licensee provides to its licensee, and 6567754Smsmith * not to intellectual property embodied in modifications its licensee may 6667754Smsmith * make. 6767754Smsmith * 6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the 7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 7167754Smsmith * provision in the documentation and/or other materials provided with the 7267754Smsmith * distribution. 7367754Smsmith * 7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7567754Smsmith * Intel Code. 7667754Smsmith * 7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7967754Smsmith * other dealings in products derived from or relating to the Covered Code 8067754Smsmith * without prior written authorization from Intel. 8167754Smsmith * 8267754Smsmith * 4. Disclaimer and Export Compliance 8367754Smsmith * 8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8567754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 9067754Smsmith * PARTICULAR PURPOSE. 9167754Smsmith * 9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9967754Smsmith * LIMITED REMEDY. 10067754Smsmith * 10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10267754Smsmith * software or system incorporating such software without first obtaining any 10367754Smsmith * required license or other approval from the U. S. Department of Commerce or 10467754Smsmith * any other agency or department of the United States Government. In the 10567754Smsmith * event Licensee exports any such software from the United States or 10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10767754Smsmith * ensure that the distribution and export/re-export of the software is in 10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 11167754Smsmith * software, or service, directly or indirectly, to any country for which the 11267754Smsmith * United States government or any agency thereof requires an export license, 11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11467754Smsmith * such license, approval or letter. 11567754Smsmith * 11667754Smsmith *****************************************************************************/ 11767754Smsmith 11867754Smsmith 119151600Sobrien#include <contrib/dev/acpica/acpi.h> 120151600Sobrien#include <contrib/dev/acpica/acdebug.h> 121151600Sobrien#include <contrib/dev/acpica/acnamesp.h> 122151600Sobrien#include <contrib/dev/acpica/actables.h> 12367754Smsmith 124102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) 12567754Smsmith 126102550Siwasaki#define _COMPONENT ACPI_CA_DEBUGGER 12791116Smsmith ACPI_MODULE_NAME ("dbfileio") 12867754Smsmith 12984491Smsmith/* 13084491Smsmith * NOTE: this is here for lack of a better place. It is used in all 13184491Smsmith * flavors of the debugger, need LCD file 13284491Smsmith */ 13367754Smsmith#ifdef ACPI_APPLICATION 13467754Smsmith#include <stdio.h> 13583174SmsmithFILE *AcpiGbl_DebugFile = NULL; 13667754Smsmith#endif 13767754Smsmith 13867754Smsmith 139102550Siwasaki#ifdef ACPI_DEBUGGER 140151937Sjkim 141151937Sjkim/* Local prototypes */ 142151937Sjkim 143151940Sjkim#ifdef ACPI_APPLICATION 144151940Sjkim 145151937Sjkimstatic ACPI_STATUS 146151937SjkimAcpiDbCheckTextModeCorruption ( 147151937Sjkim UINT8 *Table, 148151937Sjkim UINT32 TableLength, 149151937Sjkim UINT32 FileLength); 150151937Sjkim 151151937Sjkimstatic ACPI_STATUS 152151937SjkimAeLocalLoadTable ( 153151937Sjkim ACPI_TABLE_HEADER *TablePtr); 154151937Sjkim 155151940Sjkim#endif 156151937Sjkim 15767754Smsmith/******************************************************************************* 15867754Smsmith * 15967754Smsmith * FUNCTION: AcpiDbCloseDebugFile 16067754Smsmith * 16167754Smsmith * PARAMETERS: None 16267754Smsmith * 163151937Sjkim * RETURN: None 16467754Smsmith * 16567754Smsmith * DESCRIPTION: If open, close the current debug output file 16667754Smsmith * 16767754Smsmith ******************************************************************************/ 16867754Smsmith 16967754Smsmithvoid 17067754SmsmithAcpiDbCloseDebugFile ( 17167754Smsmith void) 17267754Smsmith{ 17367754Smsmith 17467754Smsmith#ifdef ACPI_APPLICATION 17567754Smsmith 17683174Smsmith if (AcpiGbl_DebugFile) 17767754Smsmith { 17883174Smsmith fclose (AcpiGbl_DebugFile); 17983174Smsmith AcpiGbl_DebugFile = NULL; 18083174Smsmith AcpiGbl_DbOutputToFile = FALSE; 18183174Smsmith AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); 18267754Smsmith } 18367754Smsmith#endif 18467754Smsmith} 18567754Smsmith 18667754Smsmith 18767754Smsmith/******************************************************************************* 18867754Smsmith * 18967754Smsmith * FUNCTION: AcpiDbOpenDebugFile 19067754Smsmith * 19167754Smsmith * PARAMETERS: Name - Filename to open 19267754Smsmith * 193151937Sjkim * RETURN: None 19467754Smsmith * 19567754Smsmith * DESCRIPTION: Open a file where debug output will be directed. 19667754Smsmith * 19767754Smsmith ******************************************************************************/ 19867754Smsmith 19967754Smsmithvoid 20067754SmsmithAcpiDbOpenDebugFile ( 201114237Snjl char *Name) 20267754Smsmith{ 20367754Smsmith 20467754Smsmith#ifdef ACPI_APPLICATION 20567754Smsmith 20667754Smsmith AcpiDbCloseDebugFile (); 20783174Smsmith AcpiGbl_DebugFile = fopen (Name, "w+"); 20883174Smsmith if (AcpiGbl_DebugFile) 20967754Smsmith { 21067754Smsmith AcpiOsPrintf ("Debug output file %s opened\n", Name); 21191116Smsmith ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name); 21283174Smsmith AcpiGbl_DbOutputToFile = TRUE; 21367754Smsmith } 21473561Smsmith else 21573561Smsmith { 21673561Smsmith AcpiOsPrintf ("Could not open debug file %s\n", Name); 21773561Smsmith } 21867754Smsmith 21967754Smsmith#endif 22067754Smsmith} 221100966Siwasaki#endif 22267754Smsmith 22367754Smsmith 22467754Smsmith#ifdef ACPI_APPLICATION 22567754Smsmith/******************************************************************************* 22667754Smsmith * 227117521Snjl * FUNCTION: AcpiDbCheckTextModeCorruption 228117521Snjl * 229117521Snjl * PARAMETERS: Table - Table buffer 230117521Snjl * TableLength - Length of table from the table header 231117521Snjl * FileLength - Length of the file that contains the table 232117521Snjl * 233117521Snjl * RETURN: Status 234117521Snjl * 235117521Snjl * DESCRIPTION: Check table for text mode file corruption where all linefeed 236117521Snjl * characters (LF) have been replaced by carriage return linefeed 237117521Snjl * pairs (CR/LF). 238117521Snjl * 239117521Snjl ******************************************************************************/ 240117521Snjl 241117521Snjlstatic ACPI_STATUS 242117521SnjlAcpiDbCheckTextModeCorruption ( 243117521Snjl UINT8 *Table, 244117521Snjl UINT32 TableLength, 245117521Snjl UINT32 FileLength) 246117521Snjl{ 247117521Snjl UINT32 i; 248117521Snjl UINT32 Pairs = 0; 249117521Snjl 250117521Snjl 251117521Snjl if (TableLength != FileLength) 252117521Snjl { 253151937Sjkim ACPI_REPORT_WARNING (( 254151937Sjkim "File length (0x%X) is not the same as the table length (0x%X)\n", 255151937Sjkim FileLength, TableLength)); 256117521Snjl } 257117521Snjl 258117521Snjl /* Scan entire table to determine if each LF has been prefixed with a CR */ 259117521Snjl 260117521Snjl for (i = 1; i < FileLength; i++) 261117521Snjl { 262117521Snjl if (Table[i] == 0x0A) 263117521Snjl { 264117521Snjl if (Table[i - 1] != 0x0D) 265117521Snjl { 266151937Sjkim /* The LF does not have a preceeding CR, table not corrupted */ 267117521Snjl 268117521Snjl return (AE_OK); 269117521Snjl } 270117521Snjl else 271117521Snjl { 272117521Snjl /* Found a CR/LF pair */ 273117521Snjl 274117521Snjl Pairs++; 275117521Snjl } 276117521Snjl i++; 277117521Snjl } 278117521Snjl } 279117521Snjl 280123315Snjl /* 281117521Snjl * Entire table scanned, each CR is part of a CR/LF pair -- 282117521Snjl * meaning that the table was treated as a text file somewhere. 283117521Snjl * 284117521Snjl * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the 285123315Snjl * original table are left untouched by the text conversion process -- 286117521Snjl * meaning that we cannot simply replace CR/LF pairs with LFs. 287117521Snjl */ 288117521Snjl AcpiOsPrintf ("Table has been corrupted by text mode conversion\n"); 289117521Snjl AcpiOsPrintf ("All LFs (%d) were changed to CR/LF pairs\n", Pairs); 290117521Snjl AcpiOsPrintf ("Table cannot be repaired!\n"); 291117521Snjl return (AE_BAD_VALUE); 292117521Snjl} 293117521Snjl 294117521Snjl 295117521Snjl/******************************************************************************* 296117521Snjl * 297114237Snjl * FUNCTION: AcpiDbReadTable 29867754Smsmith * 29967754Smsmith * PARAMETERS: fp - File that contains table 300114237Snjl * Table - Return value, buffer with table 301114237Snjl * TableLength - Return value, length of table 30267754Smsmith * 30367754Smsmith * RETURN: Status 30467754Smsmith * 30567754Smsmith * DESCRIPTION: Load the DSDT from the file pointer 30667754Smsmith * 30767754Smsmith ******************************************************************************/ 30867754Smsmith 30999679Siwasakistatic ACPI_STATUS 310114237SnjlAcpiDbReadTable ( 31167754Smsmith FILE *fp, 312114237Snjl ACPI_TABLE_HEADER **Table, 31367754Smsmith UINT32 *TableLength) 31467754Smsmith{ 31567754Smsmith ACPI_TABLE_HEADER TableHeader; 31667754Smsmith UINT32 Actual; 31769450Smsmith ACPI_STATUS Status; 318117521Snjl UINT32 FileSize; 31967754Smsmith 32067754Smsmith 321117521Snjl fseek (fp, 0, SEEK_END); 322151937Sjkim FileSize = (UINT32) ftell (fp); 323117521Snjl fseek (fp, 0, SEEK_SET); 324117521Snjl 32567754Smsmith /* Read the table header */ 32667754Smsmith 327151937Sjkim if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != 328151937Sjkim sizeof (ACPI_TABLE_HEADER)) 32967754Smsmith { 330151937Sjkim AcpiOsPrintf ("Could not read the table header\n"); 331151937Sjkim return (AE_BAD_HEADER); 33267754Smsmith } 33367754Smsmith 33469450Smsmith /* Validate the table header/length */ 33569450Smsmith 33669450Smsmith Status = AcpiTbValidateTableHeader (&TableHeader); 337151937Sjkim if (ACPI_FAILURE (Status)) 33867754Smsmith { 33969450Smsmith AcpiOsPrintf ("Table header is invalid!\n"); 340151937Sjkim return (Status); 34167754Smsmith } 34267754Smsmith 343151937Sjkim /* File size must be at least as long as the Header-specified length */ 344151937Sjkim 345151937Sjkim if (TableHeader.Length > FileSize) 346151937Sjkim { 347151937Sjkim AcpiOsPrintf ( 348151937Sjkim "TableHeader length [0x%X] greater than the input file size [0x%X]\n", 349151937Sjkim TableHeader.Length, FileSize); 350151937Sjkim return (AE_BAD_HEADER); 351151937Sjkim } 352151937Sjkim 35369450Smsmith /* We only support a limited number of table types */ 35469450Smsmith 35591116Smsmith if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && 35691116Smsmith ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && 35791116Smsmith ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) 35869450Smsmith { 359151937Sjkim AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n", 360151937Sjkim (char *) TableHeader.Signature); 36191116Smsmith ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); 36269450Smsmith return (AE_ERROR); 36369450Smsmith } 36469450Smsmith 36567754Smsmith /* Allocate a buffer for the table */ 36667754Smsmith 36769450Smsmith *TableLength = TableHeader.Length; 368117521Snjl *Table = AcpiOsAllocate ((size_t) (FileSize)); 369114237Snjl if (!*Table) 37067754Smsmith { 371151937Sjkim AcpiOsPrintf ( 372151937Sjkim "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n", 373151937Sjkim TableHeader.Signature, TableHeader.Length); 37467754Smsmith return (AE_NO_MEMORY); 37567754Smsmith } 37667754Smsmith 37767754Smsmith /* Get the rest of the table */ 37867754Smsmith 379117521Snjl fseek (fp, 0, SEEK_SET); 380117521Snjl Actual = fread (*Table, 1, (size_t) FileSize, fp); 381117521Snjl if (Actual == FileSize) 38267754Smsmith { 383107325Siwasaki /* Now validate the checksum */ 384107325Siwasaki 385114237Snjl Status = AcpiTbVerifyTableChecksum (*Table); 386117521Snjl 387117521Snjl if (Status == AE_BAD_CHECKSUM) 388117521Snjl { 389123315Snjl Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table, 390117521Snjl FileSize, (*Table)->Length); 391117521Snjl return (Status); 392117521Snjl } 39367754Smsmith return (AE_OK); 39467754Smsmith } 39567754Smsmith 39667754Smsmith if (Actual > 0) 39767754Smsmith { 398117521Snjl AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", 399117521Snjl FileSize, Actual); 40084491Smsmith return (AE_OK); 40167754Smsmith } 40267754Smsmith 40367754Smsmith AcpiOsPrintf ("Error - could not read the table file\n"); 404114237Snjl AcpiOsFree (*Table); 405114237Snjl *Table = NULL; 40667754Smsmith *TableLength = 0; 40767754Smsmith 40867754Smsmith return (AE_ERROR); 40967754Smsmith} 41067754Smsmith 41167754Smsmith 41267754Smsmith/******************************************************************************* 41367754Smsmith * 41467754Smsmith * FUNCTION: AeLocalLoadTable 41567754Smsmith * 416114237Snjl * PARAMETERS: Table - pointer to a buffer containing the entire 41767754Smsmith * table to be loaded 41867754Smsmith * 41967754Smsmith * RETURN: Status 42067754Smsmith * 42167754Smsmith * DESCRIPTION: This function is called to load a table from the caller's 42267754Smsmith * buffer. The buffer must contain an entire ACPI Table including 42367754Smsmith * a valid header. The header fields will be verified, and if it 42467754Smsmith * is determined that the table is invalid, the call will fail. 42567754Smsmith * 42667754Smsmith ******************************************************************************/ 42767754Smsmith 428151937Sjkimstatic ACPI_STATUS 42967754SmsmithAeLocalLoadTable ( 430114237Snjl ACPI_TABLE_HEADER *Table) 43167754Smsmith{ 43267754Smsmith ACPI_STATUS Status; 43367754Smsmith ACPI_TABLE_DESC TableInfo; 43467754Smsmith 43567754Smsmith 43691116Smsmith ACPI_FUNCTION_TRACE ("AeLocalLoadTable"); 43767754Smsmith 438114237Snjl 439114237Snjl if (!Table) 44067754Smsmith { 44167754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 44267754Smsmith } 44367754Smsmith 444114237Snjl TableInfo.Pointer = Table; 445114237Snjl Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); 446100966Siwasaki if (ACPI_FAILURE (Status)) 447100966Siwasaki { 448100966Siwasaki return_ACPI_STATUS (Status); 449100966Siwasaki } 450100966Siwasaki 45167754Smsmith /* Install the new table into the local data structures */ 45267754Smsmith 45399679Siwasaki Status = AcpiTbInstallTable (&TableInfo); 45467754Smsmith if (ACPI_FAILURE (Status)) 45567754Smsmith { 456151937Sjkim if (Status == AE_ALREADY_EXISTS) 457151937Sjkim { 458151937Sjkim /* Table already exists, no error */ 459151937Sjkim 460151937Sjkim Status = AE_OK; 461151937Sjkim } 462151937Sjkim 46367754Smsmith /* Free table allocated by AcpiTbGetTable */ 46467754Smsmith 46567754Smsmith AcpiTbDeleteSingleTable (&TableInfo); 46667754Smsmith return_ACPI_STATUS (Status); 46767754Smsmith } 46867754Smsmith 469114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 47067754Smsmith 47167754Smsmith Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 47267754Smsmith if (ACPI_FAILURE (Status)) 47367754Smsmith { 47467754Smsmith /* Uninstall table and free the buffer */ 47567754Smsmith 476117521Snjl AcpiTbDeleteTablesByType (ACPI_TABLE_DSDT); 47767754Smsmith return_ACPI_STATUS (Status); 47867754Smsmith } 47967754Smsmith#endif 48067754Smsmith 48167754Smsmith return_ACPI_STATUS (Status); 48267754Smsmith} 48367754Smsmith 48467754Smsmith 485107325Siwasaki/******************************************************************************* 486107325Siwasaki * 487114237Snjl * FUNCTION: AcpiDbReadTableFromFile 488107325Siwasaki * 489114237Snjl * PARAMETERS: Filename - File where table is located 490114237Snjl * Table - Where a pointer to the table is returned 491107325Siwasaki * 492107325Siwasaki * RETURN: Status 493107325Siwasaki * 494107325Siwasaki * DESCRIPTION: Get an ACPI table from a file 495107325Siwasaki * 496107325Siwasaki ******************************************************************************/ 497107325Siwasaki 49867754SmsmithACPI_STATUS 499114237SnjlAcpiDbReadTableFromFile ( 500114237Snjl char *Filename, 501114237Snjl ACPI_TABLE_HEADER **Table) 50267754Smsmith{ 50367754Smsmith FILE *fp; 50499146Siwasaki UINT32 TableLength; 50567754Smsmith ACPI_STATUS Status; 50667754Smsmith 507107325Siwasaki 50867754Smsmith /* Open the file */ 50967754Smsmith 51067754Smsmith fp = fopen (Filename, "rb"); 51167754Smsmith if (!fp) 51267754Smsmith { 513114237Snjl AcpiOsPrintf ("Could not open input file %s\n", Filename); 51467754Smsmith return (AE_ERROR); 51567754Smsmith } 51667754Smsmith 51767754Smsmith /* Get the entire file */ 51867754Smsmith 519100966Siwasaki fprintf (stderr, "Loading Acpi table from file %s\n", Filename); 520114237Snjl Status = AcpiDbReadTable (fp, Table, &TableLength); 52167754Smsmith fclose(fp); 52267754Smsmith 52367754Smsmith if (ACPI_FAILURE (Status)) 52467754Smsmith { 525151937Sjkim AcpiOsPrintf ("Could not get table from the file\n"); 52667754Smsmith return (Status); 52767754Smsmith } 52867754Smsmith 52999146Siwasaki return (AE_OK); 53099146Siwasaki } 53199146Siwasaki#endif 53267754Smsmith 533107325Siwasaki 53499146Siwasaki/******************************************************************************* 53599146Siwasaki * 536114237Snjl * FUNCTION: AcpiDbGetTableFromFile 53799146Siwasaki * 538151937Sjkim * PARAMETERS: Filename - File where table is located 539151937Sjkim * ReturnTable - Where a pointer to the table is returned 54099146Siwasaki * 54199146Siwasaki * RETURN: Status 54299146Siwasaki * 54399146Siwasaki * DESCRIPTION: Load an ACPI table from a file 54499146Siwasaki * 54599146Siwasaki ******************************************************************************/ 54699146Siwasaki 54799146SiwasakiACPI_STATUS 548114237SnjlAcpiDbGetTableFromFile ( 549114237Snjl char *Filename, 550114237Snjl ACPI_TABLE_HEADER **ReturnTable) 55199146Siwasaki{ 55299146Siwasaki#ifdef ACPI_APPLICATION 55399146Siwasaki ACPI_STATUS Status; 554114237Snjl ACPI_TABLE_HEADER *Table; 55599146Siwasaki 55699146Siwasaki 557114237Snjl Status = AcpiDbReadTableFromFile (Filename, &Table); 55899146Siwasaki if (ACPI_FAILURE (Status)) 55999146Siwasaki { 56099146Siwasaki return (Status); 56199146Siwasaki } 56299146Siwasaki 56399146Siwasaki /* Attempt to recognize and install the table */ 56499146Siwasaki 565114237Snjl Status = AeLocalLoadTable (Table); 56667754Smsmith if (ACPI_FAILURE (Status)) 56767754Smsmith { 56887031Smsmith if (Status == AE_ALREADY_EXISTS) 56967754Smsmith { 57067754Smsmith AcpiOsPrintf ("Table %4.4s is already installed\n", 571114237Snjl Table->Signature); 57267754Smsmith } 57367754Smsmith else 57467754Smsmith { 57567754Smsmith AcpiOsPrintf ("Could not install table, %s\n", 57680062Smsmith AcpiFormatException (Status)); 57767754Smsmith } 57880062Smsmith 57967754Smsmith return (Status); 58067754Smsmith } 58167754Smsmith 582100966Siwasaki fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n", 583114237Snjl Table->Signature); 58467754Smsmith 58567754Smsmith AcpiGbl_AcpiHardwarePresent = FALSE; 586114237Snjl if (ReturnTable) 587114237Snjl { 588114237Snjl *ReturnTable = Table; 589114237Snjl } 59067754Smsmith 591114237Snjl 59267754Smsmith#endif /* ACPI_APPLICATION */ 59367754Smsmith return (AE_OK); 59467754Smsmith} 59567754Smsmith 596102550Siwasaki#endif /* ACPI_DEBUGGER */ 59767754Smsmith 598