Home | History | Annotate | Line # | Download | only in debugger
dbfileio.c revision 1.1.1.2.20.1
      1           1.1  jruoho /*******************************************************************************
      2           1.1  jruoho  *
      3           1.1  jruoho  * Module Name: dbfileio - Debugger file I/O commands. These can't usually
      4           1.1  jruoho  *              be used when running the debugger in Ring 0 (Kernel mode)
      5           1.1  jruoho  *
      6           1.1  jruoho  ******************************************************************************/
      7           1.1  jruoho 
      8       1.1.1.2  jruoho /*
      9  1.1.1.2.20.1     tls  * Copyright (C) 2000 - 2013, Intel Corp.
     10           1.1  jruoho  * All rights reserved.
     11           1.1  jruoho  *
     12       1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     13       1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     14       1.1.1.2  jruoho  * are met:
     15       1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     16       1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     17       1.1.1.2  jruoho  *    without modification.
     18       1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19       1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20       1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21       1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     22       1.1.1.2  jruoho  *    binary redistribution.
     23       1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24       1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     25       1.1.1.2  jruoho  *    from this software without specific prior written permission.
     26       1.1.1.2  jruoho  *
     27       1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     28       1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29       1.1.1.2  jruoho  * Software Foundation.
     30       1.1.1.2  jruoho  *
     31       1.1.1.2  jruoho  * NO WARRANTY
     32       1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33       1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34       1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35       1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36       1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37       1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38       1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39       1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40       1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41       1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42       1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43       1.1.1.2  jruoho  */
     44           1.1  jruoho 
     45           1.1  jruoho 
     46           1.1  jruoho #include "acpi.h"
     47           1.1  jruoho #include "accommon.h"
     48           1.1  jruoho #include "acdebug.h"
     49           1.1  jruoho 
     50           1.1  jruoho #ifdef ACPI_APPLICATION
     51           1.1  jruoho #include "actables.h"
     52           1.1  jruoho #endif
     53           1.1  jruoho 
     54  1.1.1.2.20.1     tls #ifdef ACPI_ASL_COMPILER
     55  1.1.1.2.20.1     tls #include "aslcompiler.h"
     56  1.1.1.2.20.1     tls #endif
     57  1.1.1.2.20.1     tls 
     58           1.1  jruoho #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
     59           1.1  jruoho 
     60           1.1  jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
     61           1.1  jruoho         ACPI_MODULE_NAME    ("dbfileio")
     62           1.1  jruoho 
     63           1.1  jruoho #ifdef ACPI_DEBUGGER
     64           1.1  jruoho 
     65           1.1  jruoho /* Local prototypes */
     66           1.1  jruoho 
     67           1.1  jruoho #ifdef ACPI_APPLICATION
     68           1.1  jruoho 
     69           1.1  jruoho static ACPI_STATUS
     70           1.1  jruoho AcpiDbCheckTextModeCorruption (
     71           1.1  jruoho     UINT8                   *Table,
     72           1.1  jruoho     UINT32                  TableLength,
     73           1.1  jruoho     UINT32                  FileLength);
     74           1.1  jruoho 
     75           1.1  jruoho #endif
     76           1.1  jruoho 
     77           1.1  jruoho /*******************************************************************************
     78           1.1  jruoho  *
     79           1.1  jruoho  * FUNCTION:    AcpiDbCloseDebugFile
     80           1.1  jruoho  *
     81           1.1  jruoho  * PARAMETERS:  None
     82           1.1  jruoho  *
     83           1.1  jruoho  * RETURN:      None
     84           1.1  jruoho  *
     85           1.1  jruoho  * DESCRIPTION: If open, close the current debug output file
     86           1.1  jruoho  *
     87           1.1  jruoho  ******************************************************************************/
     88           1.1  jruoho 
     89           1.1  jruoho void
     90           1.1  jruoho AcpiDbCloseDebugFile (
     91           1.1  jruoho     void)
     92           1.1  jruoho {
     93           1.1  jruoho 
     94           1.1  jruoho #ifdef ACPI_APPLICATION
     95           1.1  jruoho 
     96           1.1  jruoho     if (AcpiGbl_DebugFile)
     97           1.1  jruoho     {
     98           1.1  jruoho        fclose (AcpiGbl_DebugFile);
     99           1.1  jruoho        AcpiGbl_DebugFile = NULL;
    100           1.1  jruoho        AcpiGbl_DbOutputToFile = FALSE;
    101           1.1  jruoho        AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
    102           1.1  jruoho     }
    103           1.1  jruoho #endif
    104           1.1  jruoho }
    105           1.1  jruoho 
    106           1.1  jruoho 
    107           1.1  jruoho /*******************************************************************************
    108           1.1  jruoho  *
    109           1.1  jruoho  * FUNCTION:    AcpiDbOpenDebugFile
    110           1.1  jruoho  *
    111           1.1  jruoho  * PARAMETERS:  Name                - Filename to open
    112           1.1  jruoho  *
    113           1.1  jruoho  * RETURN:      None
    114           1.1  jruoho  *
    115           1.1  jruoho  * DESCRIPTION: Open a file where debug output will be directed.
    116           1.1  jruoho  *
    117           1.1  jruoho  ******************************************************************************/
    118           1.1  jruoho 
    119           1.1  jruoho void
    120           1.1  jruoho AcpiDbOpenDebugFile (
    121           1.1  jruoho     char                    *Name)
    122           1.1  jruoho {
    123           1.1  jruoho 
    124           1.1  jruoho #ifdef ACPI_APPLICATION
    125           1.1  jruoho 
    126           1.1  jruoho     AcpiDbCloseDebugFile ();
    127           1.1  jruoho     AcpiGbl_DebugFile = fopen (Name, "w+");
    128  1.1.1.2.20.1     tls     if (!AcpiGbl_DebugFile)
    129           1.1  jruoho     {
    130           1.1  jruoho         AcpiOsPrintf ("Could not open debug file %s\n", Name);
    131  1.1.1.2.20.1     tls         return;
    132           1.1  jruoho     }
    133           1.1  jruoho 
    134  1.1.1.2.20.1     tls     AcpiOsPrintf ("Debug output file %s opened\n", Name);
    135  1.1.1.2.20.1     tls     ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name,
    136  1.1.1.2.20.1     tls         sizeof (AcpiGbl_DbDebugFilename));
    137  1.1.1.2.20.1     tls     AcpiGbl_DbOutputToFile = TRUE;
    138  1.1.1.2.20.1     tls 
    139           1.1  jruoho #endif
    140           1.1  jruoho }
    141           1.1  jruoho #endif
    142           1.1  jruoho 
    143           1.1  jruoho 
    144           1.1  jruoho #ifdef ACPI_APPLICATION
    145           1.1  jruoho /*******************************************************************************
    146           1.1  jruoho  *
    147           1.1  jruoho  * FUNCTION:    AcpiDbCheckTextModeCorruption
    148           1.1  jruoho  *
    149           1.1  jruoho  * PARAMETERS:  Table           - Table buffer
    150           1.1  jruoho  *              TableLength     - Length of table from the table header
    151           1.1  jruoho  *              FileLength      - Length of the file that contains the table
    152           1.1  jruoho  *
    153           1.1  jruoho  * RETURN:      Status
    154           1.1  jruoho  *
    155           1.1  jruoho  * DESCRIPTION: Check table for text mode file corruption where all linefeed
    156           1.1  jruoho  *              characters (LF) have been replaced by carriage return linefeed
    157           1.1  jruoho  *              pairs (CR/LF).
    158           1.1  jruoho  *
    159           1.1  jruoho  ******************************************************************************/
    160           1.1  jruoho 
    161           1.1  jruoho static ACPI_STATUS
    162           1.1  jruoho AcpiDbCheckTextModeCorruption (
    163           1.1  jruoho     UINT8                   *Table,
    164           1.1  jruoho     UINT32                  TableLength,
    165           1.1  jruoho     UINT32                  FileLength)
    166           1.1  jruoho {
    167           1.1  jruoho     UINT32                  i;
    168           1.1  jruoho     UINT32                  Pairs = 0;
    169           1.1  jruoho 
    170           1.1  jruoho 
    171           1.1  jruoho     if (TableLength != FileLength)
    172           1.1  jruoho     {
    173           1.1  jruoho         ACPI_WARNING ((AE_INFO,
    174           1.1  jruoho             "File length (0x%X) is not the same as the table length (0x%X)",
    175           1.1  jruoho             FileLength, TableLength));
    176           1.1  jruoho     }
    177           1.1  jruoho 
    178           1.1  jruoho     /* Scan entire table to determine if each LF has been prefixed with a CR */
    179           1.1  jruoho 
    180           1.1  jruoho     for (i = 1; i < FileLength; i++)
    181           1.1  jruoho     {
    182           1.1  jruoho         if (Table[i] == 0x0A)
    183           1.1  jruoho         {
    184           1.1  jruoho             if (Table[i - 1] != 0x0D)
    185           1.1  jruoho             {
    186           1.1  jruoho                 /* The LF does not have a preceding CR, table not corrupted */
    187           1.1  jruoho 
    188           1.1  jruoho                 return (AE_OK);
    189           1.1  jruoho             }
    190           1.1  jruoho             else
    191           1.1  jruoho             {
    192           1.1  jruoho                 /* Found a CR/LF pair */
    193           1.1  jruoho 
    194           1.1  jruoho                 Pairs++;
    195           1.1  jruoho             }
    196           1.1  jruoho             i++;
    197           1.1  jruoho         }
    198           1.1  jruoho     }
    199           1.1  jruoho 
    200           1.1  jruoho     if (!Pairs)
    201           1.1  jruoho     {
    202           1.1  jruoho         return (AE_OK);
    203           1.1  jruoho     }
    204           1.1  jruoho 
    205           1.1  jruoho     /*
    206           1.1  jruoho      * Entire table scanned, each CR is part of a CR/LF pair --
    207           1.1  jruoho      * meaning that the table was treated as a text file somewhere.
    208           1.1  jruoho      *
    209           1.1  jruoho      * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
    210           1.1  jruoho      * original table are left untouched by the text conversion process --
    211           1.1  jruoho      * meaning that we cannot simply replace CR/LF pairs with LFs.
    212           1.1  jruoho      */
    213           1.1  jruoho     AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
    214           1.1  jruoho     AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
    215           1.1  jruoho     AcpiOsPrintf ("Table cannot be repaired!\n");
    216           1.1  jruoho     return (AE_BAD_VALUE);
    217           1.1  jruoho }
    218           1.1  jruoho 
    219           1.1  jruoho 
    220           1.1  jruoho /*******************************************************************************
    221           1.1  jruoho  *
    222           1.1  jruoho  * FUNCTION:    AcpiDbReadTable
    223           1.1  jruoho  *
    224           1.1  jruoho  * PARAMETERS:  fp              - File that contains table
    225           1.1  jruoho  *              Table           - Return value, buffer with table
    226           1.1  jruoho  *              TableLength     - Return value, length of table
    227           1.1  jruoho  *
    228           1.1  jruoho  * RETURN:      Status
    229           1.1  jruoho  *
    230           1.1  jruoho  * DESCRIPTION: Load the DSDT from the file pointer
    231           1.1  jruoho  *
    232           1.1  jruoho  ******************************************************************************/
    233           1.1  jruoho 
    234           1.1  jruoho static ACPI_STATUS
    235           1.1  jruoho AcpiDbReadTable (
    236           1.1  jruoho     FILE                    *fp,
    237           1.1  jruoho     ACPI_TABLE_HEADER       **Table,
    238           1.1  jruoho     UINT32                  *TableLength)
    239           1.1  jruoho {
    240           1.1  jruoho     ACPI_TABLE_HEADER       TableHeader;
    241           1.1  jruoho     UINT32                  Actual;
    242           1.1  jruoho     ACPI_STATUS             Status;
    243           1.1  jruoho     UINT32                  FileSize;
    244           1.1  jruoho     BOOLEAN                 StandardHeader = TRUE;
    245           1.1  jruoho 
    246           1.1  jruoho 
    247           1.1  jruoho     /* Get the file size */
    248           1.1  jruoho 
    249           1.1  jruoho     fseek (fp, 0, SEEK_END);
    250           1.1  jruoho     FileSize = (UINT32) ftell (fp);
    251           1.1  jruoho     fseek (fp, 0, SEEK_SET);
    252           1.1  jruoho 
    253           1.1  jruoho     if (FileSize < 4)
    254           1.1  jruoho     {
    255           1.1  jruoho         return (AE_BAD_HEADER);
    256           1.1  jruoho     }
    257           1.1  jruoho 
    258           1.1  jruoho     /* Read the signature */
    259           1.1  jruoho 
    260           1.1  jruoho     if (fread (&TableHeader, 1, 4, fp) != 4)
    261           1.1  jruoho     {
    262           1.1  jruoho         AcpiOsPrintf ("Could not read the table signature\n");
    263           1.1  jruoho         return (AE_BAD_HEADER);
    264           1.1  jruoho     }
    265           1.1  jruoho 
    266           1.1  jruoho     fseek (fp, 0, SEEK_SET);
    267           1.1  jruoho 
    268  1.1.1.2.20.1     tls     /* The RSDP table does not have standard ACPI header */
    269           1.1  jruoho 
    270  1.1.1.2.20.1     tls     if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD "))
    271           1.1  jruoho     {
    272           1.1  jruoho         *TableLength = FileSize;
    273           1.1  jruoho         StandardHeader = FALSE;
    274           1.1  jruoho     }
    275           1.1  jruoho     else
    276           1.1  jruoho     {
    277           1.1  jruoho         /* Read the table header */
    278           1.1  jruoho 
    279  1.1.1.2.20.1     tls         if (fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp) !=
    280           1.1  jruoho                 sizeof (ACPI_TABLE_HEADER))
    281           1.1  jruoho         {
    282           1.1  jruoho             AcpiOsPrintf ("Could not read the table header\n");
    283           1.1  jruoho             return (AE_BAD_HEADER);
    284           1.1  jruoho         }
    285           1.1  jruoho 
    286           1.1  jruoho #if 0
    287           1.1  jruoho         /* Validate the table header/length */
    288           1.1  jruoho 
    289           1.1  jruoho         Status = AcpiTbValidateTableHeader (&TableHeader);
    290           1.1  jruoho         if (ACPI_FAILURE (Status))
    291           1.1  jruoho         {
    292           1.1  jruoho             AcpiOsPrintf ("Table header is invalid!\n");
    293           1.1  jruoho             return (Status);
    294           1.1  jruoho         }
    295           1.1  jruoho #endif
    296           1.1  jruoho 
    297           1.1  jruoho         /* File size must be at least as long as the Header-specified length */
    298           1.1  jruoho 
    299           1.1  jruoho         if (TableHeader.Length > FileSize)
    300           1.1  jruoho         {
    301           1.1  jruoho             AcpiOsPrintf (
    302           1.1  jruoho                 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
    303           1.1  jruoho                 TableHeader.Length, FileSize);
    304  1.1.1.2.20.1     tls 
    305  1.1.1.2.20.1     tls #ifdef ACPI_ASL_COMPILER
    306  1.1.1.2.20.1     tls             Status = FlCheckForAscii (fp, NULL, FALSE);
    307  1.1.1.2.20.1     tls             if (ACPI_SUCCESS (Status))
    308  1.1.1.2.20.1     tls             {
    309  1.1.1.2.20.1     tls                 AcpiOsPrintf ("File appears to be ASCII only, must be binary\n",
    310  1.1.1.2.20.1     tls                     TableHeader.Length, FileSize);
    311  1.1.1.2.20.1     tls             }
    312  1.1.1.2.20.1     tls #endif
    313           1.1  jruoho             return (AE_BAD_HEADER);
    314           1.1  jruoho         }
    315           1.1  jruoho 
    316           1.1  jruoho #ifdef ACPI_OBSOLETE_CODE
    317           1.1  jruoho         /* We only support a limited number of table types */
    318           1.1  jruoho 
    319  1.1.1.2.20.1     tls         if (!ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_DSDT) &&
    320  1.1.1.2.20.1     tls             !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_PSDT) &&
    321  1.1.1.2.20.1     tls             !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_SSDT))
    322           1.1  jruoho         {
    323           1.1  jruoho             AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
    324           1.1  jruoho                 (char *) TableHeader.Signature);
    325           1.1  jruoho             ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
    326           1.1  jruoho             return (AE_ERROR);
    327           1.1  jruoho         }
    328           1.1  jruoho #endif
    329           1.1  jruoho 
    330           1.1  jruoho         *TableLength = TableHeader.Length;
    331           1.1  jruoho     }
    332           1.1  jruoho 
    333           1.1  jruoho     /* Allocate a buffer for the table */
    334           1.1  jruoho 
    335           1.1  jruoho     *Table = AcpiOsAllocate ((size_t) FileSize);
    336           1.1  jruoho     if (!*Table)
    337           1.1  jruoho     {
    338           1.1  jruoho         AcpiOsPrintf (
    339           1.1  jruoho             "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
    340           1.1  jruoho             TableHeader.Signature, *TableLength);
    341           1.1  jruoho         return (AE_NO_MEMORY);
    342           1.1  jruoho     }
    343           1.1  jruoho 
    344           1.1  jruoho     /* Get the rest of the table */
    345           1.1  jruoho 
    346           1.1  jruoho     fseek (fp, 0, SEEK_SET);
    347           1.1  jruoho     Actual = fread (*Table, 1, (size_t) FileSize, fp);
    348           1.1  jruoho     if (Actual == FileSize)
    349           1.1  jruoho     {
    350           1.1  jruoho         if (StandardHeader)
    351           1.1  jruoho         {
    352           1.1  jruoho             /* Now validate the checksum */
    353           1.1  jruoho 
    354           1.1  jruoho             Status = AcpiTbVerifyChecksum ((void *) *Table,
    355           1.1  jruoho                         ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
    356           1.1  jruoho 
    357           1.1  jruoho             if (Status == AE_BAD_CHECKSUM)
    358           1.1  jruoho             {
    359           1.1  jruoho                 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
    360           1.1  jruoho                             FileSize, (*Table)->Length);
    361           1.1  jruoho                 return (Status);
    362           1.1  jruoho             }
    363           1.1  jruoho         }
    364           1.1  jruoho         return (AE_OK);
    365           1.1  jruoho     }
    366           1.1  jruoho 
    367           1.1  jruoho     if (Actual > 0)
    368           1.1  jruoho     {
    369           1.1  jruoho         AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
    370           1.1  jruoho             FileSize, Actual);
    371           1.1  jruoho         return (AE_OK);
    372           1.1  jruoho     }
    373           1.1  jruoho 
    374           1.1  jruoho     AcpiOsPrintf ("Error - could not read the table file\n");
    375           1.1  jruoho     AcpiOsFree (*Table);
    376           1.1  jruoho     *Table = NULL;
    377           1.1  jruoho     *TableLength = 0;
    378           1.1  jruoho     return (AE_ERROR);
    379           1.1  jruoho }
    380           1.1  jruoho 
    381           1.1  jruoho 
    382           1.1  jruoho /*******************************************************************************
    383           1.1  jruoho  *
    384           1.1  jruoho  * FUNCTION:    AeLocalLoadTable
    385           1.1  jruoho  *
    386           1.1  jruoho  * PARAMETERS:  Table           - pointer to a buffer containing the entire
    387           1.1  jruoho  *                                table to be loaded
    388           1.1  jruoho  *
    389           1.1  jruoho  * RETURN:      Status
    390           1.1  jruoho  *
    391           1.1  jruoho  * DESCRIPTION: This function is called to load a table from the caller's
    392           1.1  jruoho  *              buffer. The buffer must contain an entire ACPI Table including
    393           1.1  jruoho  *              a valid header. The header fields will be verified, and if it
    394           1.1  jruoho  *              is determined that the table is invalid, the call will fail.
    395           1.1  jruoho  *
    396           1.1  jruoho  ******************************************************************************/
    397           1.1  jruoho 
    398           1.1  jruoho static ACPI_STATUS
    399           1.1  jruoho AeLocalLoadTable (
    400           1.1  jruoho     ACPI_TABLE_HEADER       *Table)
    401           1.1  jruoho {
    402           1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    403           1.1  jruoho /*    ACPI_TABLE_DESC         TableInfo; */
    404           1.1  jruoho 
    405           1.1  jruoho 
    406           1.1  jruoho     ACPI_FUNCTION_TRACE (AeLocalLoadTable);
    407           1.1  jruoho #if 0
    408           1.1  jruoho 
    409           1.1  jruoho 
    410           1.1  jruoho     if (!Table)
    411           1.1  jruoho     {
    412           1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    413           1.1  jruoho     }
    414           1.1  jruoho 
    415           1.1  jruoho     TableInfo.Pointer = Table;
    416           1.1  jruoho     Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
    417           1.1  jruoho     if (ACPI_FAILURE (Status))
    418           1.1  jruoho     {
    419           1.1  jruoho         return_ACPI_STATUS (Status);
    420           1.1  jruoho     }
    421           1.1  jruoho 
    422           1.1  jruoho     /* Install the new table into the local data structures */
    423           1.1  jruoho 
    424           1.1  jruoho     Status = AcpiTbInstallTable (&TableInfo);
    425           1.1  jruoho     if (ACPI_FAILURE (Status))
    426           1.1  jruoho     {
    427           1.1  jruoho         if (Status == AE_ALREADY_EXISTS)
    428           1.1  jruoho         {
    429           1.1  jruoho             /* Table already exists, no error */
    430           1.1  jruoho 
    431           1.1  jruoho             Status = AE_OK;
    432           1.1  jruoho         }
    433           1.1  jruoho 
    434           1.1  jruoho         /* Free table allocated by AcpiTbGetTable */
    435           1.1  jruoho 
    436           1.1  jruoho         AcpiTbDeleteSingleTable (&TableInfo);
    437           1.1  jruoho         return_ACPI_STATUS (Status);
    438           1.1  jruoho     }
    439           1.1  jruoho 
    440           1.1  jruoho #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
    441           1.1  jruoho 
    442           1.1  jruoho     Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
    443           1.1  jruoho     if (ACPI_FAILURE (Status))
    444           1.1  jruoho     {
    445           1.1  jruoho         /* Uninstall table and free the buffer */
    446           1.1  jruoho 
    447           1.1  jruoho         AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
    448           1.1  jruoho         return_ACPI_STATUS (Status);
    449           1.1  jruoho     }
    450           1.1  jruoho #endif
    451           1.1  jruoho #endif
    452           1.1  jruoho 
    453           1.1  jruoho     return_ACPI_STATUS (Status);
    454           1.1  jruoho }
    455           1.1  jruoho 
    456           1.1  jruoho 
    457           1.1  jruoho /*******************************************************************************
    458           1.1  jruoho  *
    459           1.1  jruoho  * FUNCTION:    AcpiDbReadTableFromFile
    460           1.1  jruoho  *
    461           1.1  jruoho  * PARAMETERS:  Filename         - File where table is located
    462           1.1  jruoho  *              Table            - Where a pointer to the table is returned
    463           1.1  jruoho  *
    464           1.1  jruoho  * RETURN:      Status
    465           1.1  jruoho  *
    466           1.1  jruoho  * DESCRIPTION: Get an ACPI table from a file
    467           1.1  jruoho  *
    468           1.1  jruoho  ******************************************************************************/
    469           1.1  jruoho 
    470           1.1  jruoho ACPI_STATUS
    471           1.1  jruoho AcpiDbReadTableFromFile (
    472           1.1  jruoho     char                    *Filename,
    473           1.1  jruoho     ACPI_TABLE_HEADER       **Table)
    474           1.1  jruoho {
    475  1.1.1.2.20.1     tls     FILE                    *File;
    476           1.1  jruoho     UINT32                  TableLength;
    477           1.1  jruoho     ACPI_STATUS             Status;
    478           1.1  jruoho 
    479           1.1  jruoho 
    480           1.1  jruoho     /* Open the file */
    481           1.1  jruoho 
    482  1.1.1.2.20.1     tls     File = fopen (Filename, "rb");
    483  1.1.1.2.20.1     tls     if (!File)
    484           1.1  jruoho     {
    485  1.1.1.2.20.1     tls         perror ("Could not open input file");
    486           1.1  jruoho         return (AE_ERROR);
    487           1.1  jruoho     }
    488           1.1  jruoho 
    489           1.1  jruoho     /* Get the entire file */
    490           1.1  jruoho 
    491           1.1  jruoho     fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
    492  1.1.1.2.20.1     tls     Status = AcpiDbReadTable (File, Table, &TableLength);
    493  1.1.1.2.20.1     tls     fclose(File);
    494           1.1  jruoho 
    495           1.1  jruoho     if (ACPI_FAILURE (Status))
    496           1.1  jruoho     {
    497           1.1  jruoho         AcpiOsPrintf ("Could not get table from the file\n");
    498           1.1  jruoho         return (Status);
    499           1.1  jruoho     }
    500           1.1  jruoho 
    501           1.1  jruoho     return (AE_OK);
    502           1.1  jruoho  }
    503           1.1  jruoho #endif
    504           1.1  jruoho 
    505           1.1  jruoho 
    506           1.1  jruoho /*******************************************************************************
    507           1.1  jruoho  *
    508           1.1  jruoho  * FUNCTION:    AcpiDbGetTableFromFile
    509           1.1  jruoho  *
    510           1.1  jruoho  * PARAMETERS:  Filename        - File where table is located
    511           1.1  jruoho  *              ReturnTable     - Where a pointer to the table is returned
    512           1.1  jruoho  *
    513           1.1  jruoho  * RETURN:      Status
    514           1.1  jruoho  *
    515           1.1  jruoho  * DESCRIPTION: Load an ACPI table from a file
    516           1.1  jruoho  *
    517           1.1  jruoho  ******************************************************************************/
    518           1.1  jruoho 
    519           1.1  jruoho ACPI_STATUS
    520           1.1  jruoho AcpiDbGetTableFromFile (
    521           1.1  jruoho     char                    *Filename,
    522           1.1  jruoho     ACPI_TABLE_HEADER       **ReturnTable)
    523           1.1  jruoho {
    524           1.1  jruoho #ifdef ACPI_APPLICATION
    525           1.1  jruoho     ACPI_STATUS             Status;
    526           1.1  jruoho     ACPI_TABLE_HEADER       *Table;
    527           1.1  jruoho     BOOLEAN                 IsAmlTable = TRUE;
    528           1.1  jruoho 
    529           1.1  jruoho 
    530           1.1  jruoho     Status = AcpiDbReadTableFromFile (Filename, &Table);
    531           1.1  jruoho     if (ACPI_FAILURE (Status))
    532           1.1  jruoho     {
    533           1.1  jruoho         return (Status);
    534           1.1  jruoho     }
    535           1.1  jruoho 
    536           1.1  jruoho #ifdef ACPI_DATA_TABLE_DISASSEMBLY
    537           1.1  jruoho     IsAmlTable = AcpiUtIsAmlTable (Table);
    538           1.1  jruoho #endif
    539           1.1  jruoho 
    540           1.1  jruoho     if (IsAmlTable)
    541           1.1  jruoho     {
    542           1.1  jruoho         /* Attempt to recognize and install the table */
    543           1.1  jruoho 
    544           1.1  jruoho         Status = AeLocalLoadTable (Table);
    545           1.1  jruoho         if (ACPI_FAILURE (Status))
    546           1.1  jruoho         {
    547           1.1  jruoho             if (Status == AE_ALREADY_EXISTS)
    548           1.1  jruoho             {
    549           1.1  jruoho                 AcpiOsPrintf ("Table %4.4s is already installed\n",
    550           1.1  jruoho                     Table->Signature);
    551           1.1  jruoho             }
    552           1.1  jruoho             else
    553           1.1  jruoho             {
    554           1.1  jruoho                 AcpiOsPrintf ("Could not install table, %s\n",
    555           1.1  jruoho                     AcpiFormatException (Status));
    556           1.1  jruoho             }
    557           1.1  jruoho 
    558           1.1  jruoho             return (Status);
    559           1.1  jruoho         }
    560           1.1  jruoho 
    561           1.1  jruoho         fprintf (stderr,
    562           1.1  jruoho             "Acpi table [%4.4s] successfully installed and loaded\n",
    563           1.1  jruoho             Table->Signature);
    564           1.1  jruoho     }
    565           1.1  jruoho 
    566           1.1  jruoho     AcpiGbl_AcpiHardwarePresent = FALSE;
    567           1.1  jruoho     if (ReturnTable)
    568           1.1  jruoho     {
    569           1.1  jruoho         *ReturnTable = Table;
    570           1.1  jruoho     }
    571           1.1  jruoho 
    572           1.1  jruoho 
    573           1.1  jruoho #endif  /* ACPI_APPLICATION */
    574           1.1  jruoho     return (AE_OK);
    575           1.1  jruoho }
    576           1.1  jruoho 
    577           1.1  jruoho #endif  /* ACPI_DEBUGGER */
    578