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