Home | History | Annotate | Line # | Download | only in debugger
dbfileio.c revision 1.1.1.2
      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  jruoho  * Copyright (C) 2000 - 2011, 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  jruoho #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
     55      1.1  jruoho 
     56      1.1  jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
     57      1.1  jruoho         ACPI_MODULE_NAME    ("dbfileio")
     58      1.1  jruoho 
     59      1.1  jruoho /*
     60      1.1  jruoho  * NOTE: this is here for lack of a better place. It is used in all
     61      1.1  jruoho  * flavors of the debugger, need LCD file
     62      1.1  jruoho  */
     63      1.1  jruoho #ifdef ACPI_APPLICATION
     64      1.1  jruoho #include <stdio.h>
     65      1.1  jruoho FILE                        *AcpiGbl_DebugFile = NULL;
     66      1.1  jruoho #endif
     67      1.1  jruoho 
     68      1.1  jruoho 
     69      1.1  jruoho #ifdef ACPI_DEBUGGER
     70      1.1  jruoho 
     71      1.1  jruoho /* Local prototypes */
     72      1.1  jruoho 
     73      1.1  jruoho #ifdef ACPI_APPLICATION
     74      1.1  jruoho 
     75      1.1  jruoho static ACPI_STATUS
     76      1.1  jruoho AcpiDbCheckTextModeCorruption (
     77      1.1  jruoho     UINT8                   *Table,
     78      1.1  jruoho     UINT32                  TableLength,
     79      1.1  jruoho     UINT32                  FileLength);
     80      1.1  jruoho 
     81      1.1  jruoho #endif
     82      1.1  jruoho 
     83      1.1  jruoho /*******************************************************************************
     84      1.1  jruoho  *
     85      1.1  jruoho  * FUNCTION:    AcpiDbCloseDebugFile
     86      1.1  jruoho  *
     87      1.1  jruoho  * PARAMETERS:  None
     88      1.1  jruoho  *
     89      1.1  jruoho  * RETURN:      None
     90      1.1  jruoho  *
     91      1.1  jruoho  * DESCRIPTION: If open, close the current debug output file
     92      1.1  jruoho  *
     93      1.1  jruoho  ******************************************************************************/
     94      1.1  jruoho 
     95      1.1  jruoho void
     96      1.1  jruoho AcpiDbCloseDebugFile (
     97      1.1  jruoho     void)
     98      1.1  jruoho {
     99      1.1  jruoho 
    100      1.1  jruoho #ifdef ACPI_APPLICATION
    101      1.1  jruoho 
    102      1.1  jruoho     if (AcpiGbl_DebugFile)
    103      1.1  jruoho     {
    104      1.1  jruoho        fclose (AcpiGbl_DebugFile);
    105      1.1  jruoho        AcpiGbl_DebugFile = NULL;
    106      1.1  jruoho        AcpiGbl_DbOutputToFile = FALSE;
    107      1.1  jruoho        AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
    108      1.1  jruoho     }
    109      1.1  jruoho #endif
    110      1.1  jruoho }
    111      1.1  jruoho 
    112      1.1  jruoho 
    113      1.1  jruoho /*******************************************************************************
    114      1.1  jruoho  *
    115      1.1  jruoho  * FUNCTION:    AcpiDbOpenDebugFile
    116      1.1  jruoho  *
    117      1.1  jruoho  * PARAMETERS:  Name                - Filename to open
    118      1.1  jruoho  *
    119      1.1  jruoho  * RETURN:      None
    120      1.1  jruoho  *
    121      1.1  jruoho  * DESCRIPTION: Open a file where debug output will be directed.
    122      1.1  jruoho  *
    123      1.1  jruoho  ******************************************************************************/
    124      1.1  jruoho 
    125      1.1  jruoho void
    126      1.1  jruoho AcpiDbOpenDebugFile (
    127      1.1  jruoho     char                    *Name)
    128      1.1  jruoho {
    129      1.1  jruoho 
    130      1.1  jruoho #ifdef ACPI_APPLICATION
    131      1.1  jruoho 
    132      1.1  jruoho     AcpiDbCloseDebugFile ();
    133      1.1  jruoho     AcpiGbl_DebugFile = fopen (Name, "w+");
    134      1.1  jruoho     if (AcpiGbl_DebugFile)
    135      1.1  jruoho     {
    136      1.1  jruoho         AcpiOsPrintf ("Debug output file %s opened\n", Name);
    137      1.1  jruoho         ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
    138      1.1  jruoho         AcpiGbl_DbOutputToFile = TRUE;
    139      1.1  jruoho     }
    140      1.1  jruoho     else
    141      1.1  jruoho     {
    142      1.1  jruoho         AcpiOsPrintf ("Could not open debug file %s\n", Name);
    143      1.1  jruoho     }
    144      1.1  jruoho 
    145      1.1  jruoho #endif
    146      1.1  jruoho }
    147      1.1  jruoho #endif
    148      1.1  jruoho 
    149      1.1  jruoho 
    150      1.1  jruoho #ifdef ACPI_APPLICATION
    151      1.1  jruoho /*******************************************************************************
    152      1.1  jruoho  *
    153      1.1  jruoho  * FUNCTION:    AcpiDbCheckTextModeCorruption
    154      1.1  jruoho  *
    155      1.1  jruoho  * PARAMETERS:  Table           - Table buffer
    156      1.1  jruoho  *              TableLength     - Length of table from the table header
    157      1.1  jruoho  *              FileLength      - Length of the file that contains the table
    158      1.1  jruoho  *
    159      1.1  jruoho  * RETURN:      Status
    160      1.1  jruoho  *
    161      1.1  jruoho  * DESCRIPTION: Check table for text mode file corruption where all linefeed
    162      1.1  jruoho  *              characters (LF) have been replaced by carriage return linefeed
    163      1.1  jruoho  *              pairs (CR/LF).
    164      1.1  jruoho  *
    165      1.1  jruoho  ******************************************************************************/
    166      1.1  jruoho 
    167      1.1  jruoho static ACPI_STATUS
    168      1.1  jruoho AcpiDbCheckTextModeCorruption (
    169      1.1  jruoho     UINT8                   *Table,
    170      1.1  jruoho     UINT32                  TableLength,
    171      1.1  jruoho     UINT32                  FileLength)
    172      1.1  jruoho {
    173      1.1  jruoho     UINT32                  i;
    174      1.1  jruoho     UINT32                  Pairs = 0;
    175      1.1  jruoho 
    176      1.1  jruoho 
    177      1.1  jruoho     if (TableLength != FileLength)
    178      1.1  jruoho     {
    179      1.1  jruoho         ACPI_WARNING ((AE_INFO,
    180      1.1  jruoho             "File length (0x%X) is not the same as the table length (0x%X)",
    181      1.1  jruoho             FileLength, TableLength));
    182      1.1  jruoho     }
    183      1.1  jruoho 
    184      1.1  jruoho     /* Scan entire table to determine if each LF has been prefixed with a CR */
    185      1.1  jruoho 
    186      1.1  jruoho     for (i = 1; i < FileLength; i++)
    187      1.1  jruoho     {
    188      1.1  jruoho         if (Table[i] == 0x0A)
    189      1.1  jruoho         {
    190      1.1  jruoho             if (Table[i - 1] != 0x0D)
    191      1.1  jruoho             {
    192      1.1  jruoho                 /* The LF does not have a preceding CR, table not corrupted */
    193      1.1  jruoho 
    194      1.1  jruoho                 return (AE_OK);
    195      1.1  jruoho             }
    196      1.1  jruoho             else
    197      1.1  jruoho             {
    198      1.1  jruoho                 /* Found a CR/LF pair */
    199      1.1  jruoho 
    200      1.1  jruoho                 Pairs++;
    201      1.1  jruoho             }
    202      1.1  jruoho             i++;
    203      1.1  jruoho         }
    204      1.1  jruoho     }
    205      1.1  jruoho 
    206      1.1  jruoho     if (!Pairs)
    207      1.1  jruoho     {
    208      1.1  jruoho         return (AE_OK);
    209      1.1  jruoho     }
    210      1.1  jruoho 
    211      1.1  jruoho     /*
    212      1.1  jruoho      * Entire table scanned, each CR is part of a CR/LF pair --
    213      1.1  jruoho      * meaning that the table was treated as a text file somewhere.
    214      1.1  jruoho      *
    215      1.1  jruoho      * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
    216      1.1  jruoho      * original table are left untouched by the text conversion process --
    217      1.1  jruoho      * meaning that we cannot simply replace CR/LF pairs with LFs.
    218      1.1  jruoho      */
    219      1.1  jruoho     AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
    220      1.1  jruoho     AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
    221      1.1  jruoho     AcpiOsPrintf ("Table cannot be repaired!\n");
    222      1.1  jruoho     return (AE_BAD_VALUE);
    223      1.1  jruoho }
    224      1.1  jruoho 
    225      1.1  jruoho 
    226      1.1  jruoho /*******************************************************************************
    227      1.1  jruoho  *
    228      1.1  jruoho  * FUNCTION:    AcpiDbReadTable
    229      1.1  jruoho  *
    230      1.1  jruoho  * PARAMETERS:  fp              - File that contains table
    231      1.1  jruoho  *              Table           - Return value, buffer with table
    232      1.1  jruoho  *              TableLength     - Return value, length of table
    233      1.1  jruoho  *
    234      1.1  jruoho  * RETURN:      Status
    235      1.1  jruoho  *
    236      1.1  jruoho  * DESCRIPTION: Load the DSDT from the file pointer
    237      1.1  jruoho  *
    238      1.1  jruoho  ******************************************************************************/
    239      1.1  jruoho 
    240      1.1  jruoho static ACPI_STATUS
    241      1.1  jruoho AcpiDbReadTable (
    242      1.1  jruoho     FILE                    *fp,
    243      1.1  jruoho     ACPI_TABLE_HEADER       **Table,
    244      1.1  jruoho     UINT32                  *TableLength)
    245      1.1  jruoho {
    246      1.1  jruoho     ACPI_TABLE_HEADER       TableHeader;
    247      1.1  jruoho     UINT32                  Actual;
    248      1.1  jruoho     ACPI_STATUS             Status;
    249      1.1  jruoho     UINT32                  FileSize;
    250      1.1  jruoho     BOOLEAN                 StandardHeader = TRUE;
    251      1.1  jruoho 
    252      1.1  jruoho 
    253      1.1  jruoho     /* Get the file size */
    254      1.1  jruoho 
    255      1.1  jruoho     fseek (fp, 0, SEEK_END);
    256      1.1  jruoho     FileSize = (UINT32) ftell (fp);
    257      1.1  jruoho     fseek (fp, 0, SEEK_SET);
    258      1.1  jruoho 
    259      1.1  jruoho     if (FileSize < 4)
    260      1.1  jruoho     {
    261      1.1  jruoho         return (AE_BAD_HEADER);
    262      1.1  jruoho     }
    263      1.1  jruoho 
    264      1.1  jruoho     /* Read the signature */
    265      1.1  jruoho 
    266      1.1  jruoho     if (fread (&TableHeader, 1, 4, fp) != 4)
    267      1.1  jruoho     {
    268      1.1  jruoho         AcpiOsPrintf ("Could not read the table signature\n");
    269      1.1  jruoho         return (AE_BAD_HEADER);
    270      1.1  jruoho     }
    271      1.1  jruoho 
    272      1.1  jruoho     fseek (fp, 0, SEEK_SET);
    273      1.1  jruoho 
    274      1.1  jruoho     /* The RSDT and FACS tables do not have standard ACPI headers */
    275      1.1  jruoho 
    276      1.1  jruoho     if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
    277      1.1  jruoho         ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
    278      1.1  jruoho     {
    279      1.1  jruoho         *TableLength = FileSize;
    280      1.1  jruoho         StandardHeader = FALSE;
    281      1.1  jruoho     }
    282      1.1  jruoho     else
    283      1.1  jruoho     {
    284      1.1  jruoho         /* Read the table header */
    285      1.1  jruoho 
    286      1.1  jruoho         if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
    287      1.1  jruoho                 sizeof (ACPI_TABLE_HEADER))
    288      1.1  jruoho         {
    289      1.1  jruoho             AcpiOsPrintf ("Could not read the table header\n");
    290      1.1  jruoho             return (AE_BAD_HEADER);
    291      1.1  jruoho         }
    292      1.1  jruoho 
    293      1.1  jruoho #if 0
    294      1.1  jruoho         /* Validate the table header/length */
    295      1.1  jruoho 
    296      1.1  jruoho         Status = AcpiTbValidateTableHeader (&TableHeader);
    297      1.1  jruoho         if (ACPI_FAILURE (Status))
    298      1.1  jruoho         {
    299      1.1  jruoho             AcpiOsPrintf ("Table header is invalid!\n");
    300      1.1  jruoho             return (Status);
    301      1.1  jruoho         }
    302      1.1  jruoho #endif
    303      1.1  jruoho 
    304      1.1  jruoho         /* File size must be at least as long as the Header-specified length */
    305      1.1  jruoho 
    306      1.1  jruoho         if (TableHeader.Length > FileSize)
    307      1.1  jruoho         {
    308      1.1  jruoho             AcpiOsPrintf (
    309      1.1  jruoho                 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
    310      1.1  jruoho                 TableHeader.Length, FileSize);
    311      1.1  jruoho             return (AE_BAD_HEADER);
    312      1.1  jruoho         }
    313      1.1  jruoho 
    314      1.1  jruoho #ifdef ACPI_OBSOLETE_CODE
    315      1.1  jruoho         /* We only support a limited number of table types */
    316      1.1  jruoho 
    317      1.1  jruoho         if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
    318      1.1  jruoho             ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
    319      1.1  jruoho             ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
    320      1.1  jruoho         {
    321      1.1  jruoho             AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
    322      1.1  jruoho                 (char *) TableHeader.Signature);
    323      1.1  jruoho             ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
    324      1.1  jruoho             return (AE_ERROR);
    325      1.1  jruoho         }
    326      1.1  jruoho #endif
    327      1.1  jruoho 
    328      1.1  jruoho         *TableLength = TableHeader.Length;
    329      1.1  jruoho     }
    330      1.1  jruoho 
    331      1.1  jruoho     /* Allocate a buffer for the table */
    332      1.1  jruoho 
    333      1.1  jruoho     *Table = AcpiOsAllocate ((size_t) FileSize);
    334      1.1  jruoho     if (!*Table)
    335      1.1  jruoho     {
    336      1.1  jruoho         AcpiOsPrintf (
    337      1.1  jruoho             "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
    338      1.1  jruoho             TableHeader.Signature, *TableLength);
    339      1.1  jruoho         return (AE_NO_MEMORY);
    340      1.1  jruoho     }
    341      1.1  jruoho 
    342      1.1  jruoho     /* Get the rest of the table */
    343      1.1  jruoho 
    344      1.1  jruoho     fseek (fp, 0, SEEK_SET);
    345      1.1  jruoho     Actual = fread (*Table, 1, (size_t) FileSize, fp);
    346      1.1  jruoho     if (Actual == FileSize)
    347      1.1  jruoho     {
    348      1.1  jruoho         if (StandardHeader)
    349      1.1  jruoho         {
    350      1.1  jruoho             /* Now validate the checksum */
    351      1.1  jruoho 
    352      1.1  jruoho             Status = AcpiTbVerifyChecksum ((void *) *Table,
    353      1.1  jruoho                         ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
    354      1.1  jruoho 
    355      1.1  jruoho             if (Status == AE_BAD_CHECKSUM)
    356      1.1  jruoho             {
    357      1.1  jruoho                 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
    358      1.1  jruoho                             FileSize, (*Table)->Length);
    359      1.1  jruoho                 return (Status);
    360      1.1  jruoho             }
    361      1.1  jruoho         }
    362      1.1  jruoho         return (AE_OK);
    363      1.1  jruoho     }
    364      1.1  jruoho 
    365      1.1  jruoho     if (Actual > 0)
    366      1.1  jruoho     {
    367      1.1  jruoho         AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
    368      1.1  jruoho             FileSize, Actual);
    369      1.1  jruoho         return (AE_OK);
    370      1.1  jruoho     }
    371      1.1  jruoho 
    372      1.1  jruoho     AcpiOsPrintf ("Error - could not read the table file\n");
    373      1.1  jruoho     AcpiOsFree (*Table);
    374      1.1  jruoho     *Table = NULL;
    375      1.1  jruoho     *TableLength = 0;
    376      1.1  jruoho 
    377      1.1  jruoho     return (AE_ERROR);
    378      1.1  jruoho }
    379      1.1  jruoho 
    380      1.1  jruoho 
    381      1.1  jruoho /*******************************************************************************
    382      1.1  jruoho  *
    383      1.1  jruoho  * FUNCTION:    AeLocalLoadTable
    384      1.1  jruoho  *
    385      1.1  jruoho  * PARAMETERS:  Table           - pointer to a buffer containing the entire
    386      1.1  jruoho  *                                table to be loaded
    387      1.1  jruoho  *
    388      1.1  jruoho  * RETURN:      Status
    389      1.1  jruoho  *
    390      1.1  jruoho  * DESCRIPTION: This function is called to load a table from the caller's
    391      1.1  jruoho  *              buffer. The buffer must contain an entire ACPI Table including
    392      1.1  jruoho  *              a valid header. The header fields will be verified, and if it
    393      1.1  jruoho  *              is determined that the table is invalid, the call will fail.
    394      1.1  jruoho  *
    395      1.1  jruoho  ******************************************************************************/
    396      1.1  jruoho 
    397      1.1  jruoho static ACPI_STATUS
    398      1.1  jruoho AeLocalLoadTable (
    399      1.1  jruoho     ACPI_TABLE_HEADER       *Table)
    400      1.1  jruoho {
    401      1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    402      1.1  jruoho /*    ACPI_TABLE_DESC         TableInfo; */
    403      1.1  jruoho 
    404      1.1  jruoho 
    405      1.1  jruoho     ACPI_FUNCTION_TRACE (AeLocalLoadTable);
    406      1.1  jruoho #if 0
    407      1.1  jruoho 
    408      1.1  jruoho 
    409      1.1  jruoho     if (!Table)
    410      1.1  jruoho     {
    411      1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    412      1.1  jruoho     }
    413      1.1  jruoho 
    414      1.1  jruoho     TableInfo.Pointer = Table;
    415      1.1  jruoho     Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
    416      1.1  jruoho     if (ACPI_FAILURE (Status))
    417      1.1  jruoho     {
    418      1.1  jruoho         return_ACPI_STATUS (Status);
    419      1.1  jruoho     }
    420      1.1  jruoho 
    421      1.1  jruoho     /* Install the new table into the local data structures */
    422      1.1  jruoho 
    423      1.1  jruoho     Status = AcpiTbInstallTable (&TableInfo);
    424      1.1  jruoho     if (ACPI_FAILURE (Status))
    425      1.1  jruoho     {
    426      1.1  jruoho         if (Status == AE_ALREADY_EXISTS)
    427      1.1  jruoho         {
    428      1.1  jruoho             /* Table already exists, no error */
    429      1.1  jruoho 
    430      1.1  jruoho             Status = AE_OK;
    431      1.1  jruoho         }
    432      1.1  jruoho 
    433      1.1  jruoho         /* Free table allocated by AcpiTbGetTable */
    434      1.1  jruoho 
    435      1.1  jruoho         AcpiTbDeleteSingleTable (&TableInfo);
    436      1.1  jruoho         return_ACPI_STATUS (Status);
    437      1.1  jruoho     }
    438      1.1  jruoho 
    439      1.1  jruoho #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
    440      1.1  jruoho 
    441      1.1  jruoho     Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
    442      1.1  jruoho     if (ACPI_FAILURE (Status))
    443      1.1  jruoho     {
    444      1.1  jruoho         /* Uninstall table and free the buffer */
    445      1.1  jruoho 
    446      1.1  jruoho         AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
    447      1.1  jruoho         return_ACPI_STATUS (Status);
    448      1.1  jruoho     }
    449      1.1  jruoho #endif
    450      1.1  jruoho #endif
    451      1.1  jruoho 
    452      1.1  jruoho     return_ACPI_STATUS (Status);
    453      1.1  jruoho }
    454      1.1  jruoho 
    455      1.1  jruoho 
    456      1.1  jruoho /*******************************************************************************
    457      1.1  jruoho  *
    458      1.1  jruoho  * FUNCTION:    AcpiDbReadTableFromFile
    459      1.1  jruoho  *
    460      1.1  jruoho  * PARAMETERS:  Filename         - File where table is located
    461      1.1  jruoho  *              Table            - Where a pointer to the table is returned
    462      1.1  jruoho  *
    463      1.1  jruoho  * RETURN:      Status
    464      1.1  jruoho  *
    465      1.1  jruoho  * DESCRIPTION: Get an ACPI table from a file
    466      1.1  jruoho  *
    467      1.1  jruoho  ******************************************************************************/
    468      1.1  jruoho 
    469      1.1  jruoho ACPI_STATUS
    470      1.1  jruoho AcpiDbReadTableFromFile (
    471      1.1  jruoho     char                    *Filename,
    472      1.1  jruoho     ACPI_TABLE_HEADER       **Table)
    473      1.1  jruoho {
    474      1.1  jruoho     FILE                    *fp;
    475      1.1  jruoho     UINT32                  TableLength;
    476      1.1  jruoho     ACPI_STATUS             Status;
    477      1.1  jruoho 
    478      1.1  jruoho 
    479      1.1  jruoho     /* Open the file */
    480      1.1  jruoho 
    481      1.1  jruoho     fp = fopen (Filename, "rb");
    482      1.1  jruoho     if (!fp)
    483      1.1  jruoho     {
    484      1.1  jruoho         AcpiOsPrintf ("Could not open input file %s\n", Filename);
    485      1.1  jruoho         return (AE_ERROR);
    486      1.1  jruoho     }
    487      1.1  jruoho 
    488      1.1  jruoho     /* Get the entire file */
    489      1.1  jruoho 
    490      1.1  jruoho     fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
    491      1.1  jruoho     Status = AcpiDbReadTable (fp, Table, &TableLength);
    492      1.1  jruoho     fclose(fp);
    493      1.1  jruoho 
    494      1.1  jruoho     if (ACPI_FAILURE (Status))
    495      1.1  jruoho     {
    496      1.1  jruoho         AcpiOsPrintf ("Could not get table from the file\n");
    497      1.1  jruoho         return (Status);
    498      1.1  jruoho     }
    499      1.1  jruoho 
    500      1.1  jruoho     return (AE_OK);
    501      1.1  jruoho  }
    502      1.1  jruoho #endif
    503      1.1  jruoho 
    504      1.1  jruoho 
    505      1.1  jruoho /*******************************************************************************
    506      1.1  jruoho  *
    507      1.1  jruoho  * FUNCTION:    AcpiDbGetTableFromFile
    508      1.1  jruoho  *
    509      1.1  jruoho  * PARAMETERS:  Filename        - File where table is located
    510      1.1  jruoho  *              ReturnTable     - Where a pointer to the table is returned
    511      1.1  jruoho  *
    512      1.1  jruoho  * RETURN:      Status
    513      1.1  jruoho  *
    514      1.1  jruoho  * DESCRIPTION: Load an ACPI table from a file
    515      1.1  jruoho  *
    516      1.1  jruoho  ******************************************************************************/
    517      1.1  jruoho 
    518      1.1  jruoho ACPI_STATUS
    519      1.1  jruoho AcpiDbGetTableFromFile (
    520      1.1  jruoho     char                    *Filename,
    521      1.1  jruoho     ACPI_TABLE_HEADER       **ReturnTable)
    522      1.1  jruoho {
    523      1.1  jruoho #ifdef ACPI_APPLICATION
    524      1.1  jruoho     ACPI_STATUS             Status;
    525      1.1  jruoho     ACPI_TABLE_HEADER       *Table;
    526      1.1  jruoho     BOOLEAN                 IsAmlTable = TRUE;
    527      1.1  jruoho 
    528      1.1  jruoho 
    529      1.1  jruoho     Status = AcpiDbReadTableFromFile (Filename, &Table);
    530      1.1  jruoho     if (ACPI_FAILURE (Status))
    531      1.1  jruoho     {
    532      1.1  jruoho         return (Status);
    533      1.1  jruoho     }
    534      1.1  jruoho 
    535      1.1  jruoho #ifdef ACPI_DATA_TABLE_DISASSEMBLY
    536      1.1  jruoho     IsAmlTable = AcpiUtIsAmlTable (Table);
    537      1.1  jruoho #endif
    538      1.1  jruoho 
    539      1.1  jruoho     if (IsAmlTable)
    540      1.1  jruoho     {
    541      1.1  jruoho         /* Attempt to recognize and install the table */
    542      1.1  jruoho 
    543      1.1  jruoho         Status = AeLocalLoadTable (Table);
    544      1.1  jruoho         if (ACPI_FAILURE (Status))
    545      1.1  jruoho         {
    546      1.1  jruoho             if (Status == AE_ALREADY_EXISTS)
    547      1.1  jruoho             {
    548      1.1  jruoho                 AcpiOsPrintf ("Table %4.4s is already installed\n",
    549      1.1  jruoho                     Table->Signature);
    550      1.1  jruoho             }
    551      1.1  jruoho             else
    552      1.1  jruoho             {
    553      1.1  jruoho                 AcpiOsPrintf ("Could not install table, %s\n",
    554      1.1  jruoho                     AcpiFormatException (Status));
    555      1.1  jruoho             }
    556      1.1  jruoho 
    557      1.1  jruoho             return (Status);
    558      1.1  jruoho         }
    559      1.1  jruoho 
    560      1.1  jruoho         fprintf (stderr,
    561      1.1  jruoho             "Acpi table [%4.4s] successfully installed and loaded\n",
    562      1.1  jruoho             Table->Signature);
    563      1.1  jruoho     }
    564      1.1  jruoho 
    565      1.1  jruoho     AcpiGbl_AcpiHardwarePresent = FALSE;
    566      1.1  jruoho     if (ReturnTable)
    567      1.1  jruoho     {
    568      1.1  jruoho         *ReturnTable = Table;
    569      1.1  jruoho     }
    570      1.1  jruoho 
    571      1.1  jruoho 
    572      1.1  jruoho #endif  /* ACPI_APPLICATION */
    573      1.1  jruoho     return (AE_OK);
    574      1.1  jruoho }
    575      1.1  jruoho 
    576      1.1  jruoho #endif  /* ACPI_DEBUGGER */
    577      1.1  jruoho 
    578