Home | History | Annotate | Line # | Download | only in tables
tbutils.c revision 1.1.1.3
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3  1.1.1.3  christos  * Module Name: tbutils - ACPI Table utilities
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.3  christos  * Copyright (C) 2000 - 2013, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #define __TBUTILS_C__
     45      1.1    jruoho 
     46      1.1    jruoho #include "acpi.h"
     47      1.1    jruoho #include "accommon.h"
     48      1.1    jruoho #include "actables.h"
     49      1.1    jruoho 
     50      1.1    jruoho #define _COMPONENT          ACPI_TABLES
     51      1.1    jruoho         ACPI_MODULE_NAME    ("tbutils")
     52      1.1    jruoho 
     53  1.1.1.3  christos 
     54      1.1    jruoho /* Local prototypes */
     55      1.1    jruoho 
     56  1.1.1.3  christos static ACPI_STATUS
     57  1.1.1.3  christos AcpiTbValidateXsdt (
     58  1.1.1.3  christos     ACPI_PHYSICAL_ADDRESS   Address);
     59      1.1    jruoho 
     60      1.1    jruoho static ACPI_PHYSICAL_ADDRESS
     61      1.1    jruoho AcpiTbGetRootTableEntry (
     62      1.1    jruoho     UINT8                   *TableEntry,
     63      1.1    jruoho     UINT32                  TableEntrySize);
     64      1.1    jruoho 
     65      1.1    jruoho 
     66  1.1.1.3  christos #if (!ACPI_REDUCED_HARDWARE)
     67      1.1    jruoho /*******************************************************************************
     68      1.1    jruoho  *
     69      1.1    jruoho  * FUNCTION:    AcpiTbInitializeFacs
     70      1.1    jruoho  *
     71      1.1    jruoho  * PARAMETERS:  None
     72      1.1    jruoho  *
     73      1.1    jruoho  * RETURN:      Status
     74      1.1    jruoho  *
     75      1.1    jruoho  * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
     76      1.1    jruoho  *              for accessing the Global Lock and Firmware Waking Vector
     77      1.1    jruoho  *
     78      1.1    jruoho  ******************************************************************************/
     79      1.1    jruoho 
     80      1.1    jruoho ACPI_STATUS
     81      1.1    jruoho AcpiTbInitializeFacs (
     82      1.1    jruoho     void)
     83      1.1    jruoho {
     84      1.1    jruoho     ACPI_STATUS             Status;
     85      1.1    jruoho 
     86      1.1    jruoho 
     87  1.1.1.3  christos     /* If Hardware Reduced flag is set, there is no FACS */
     88  1.1.1.3  christos 
     89  1.1.1.3  christos     if (AcpiGbl_ReducedHardware)
     90  1.1.1.3  christos     {
     91  1.1.1.3  christos         AcpiGbl_FACS = NULL;
     92  1.1.1.3  christos         return (AE_OK);
     93  1.1.1.3  christos     }
     94  1.1.1.3  christos 
     95      1.1    jruoho     Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS,
     96      1.1    jruoho                 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &AcpiGbl_FACS));
     97      1.1    jruoho     return (Status);
     98      1.1    jruoho }
     99  1.1.1.3  christos #endif /* !ACPI_REDUCED_HARDWARE */
    100      1.1    jruoho 
    101      1.1    jruoho 
    102      1.1    jruoho /*******************************************************************************
    103      1.1    jruoho  *
    104      1.1    jruoho  * FUNCTION:    AcpiTbTablesLoaded
    105      1.1    jruoho  *
    106      1.1    jruoho  * PARAMETERS:  None
    107      1.1    jruoho  *
    108      1.1    jruoho  * RETURN:      TRUE if required ACPI tables are loaded
    109      1.1    jruoho  *
    110      1.1    jruoho  * DESCRIPTION: Determine if the minimum required ACPI tables are present
    111      1.1    jruoho  *              (FADT, FACS, DSDT)
    112      1.1    jruoho  *
    113      1.1    jruoho  ******************************************************************************/
    114      1.1    jruoho 
    115      1.1    jruoho BOOLEAN
    116      1.1    jruoho AcpiTbTablesLoaded (
    117      1.1    jruoho     void)
    118      1.1    jruoho {
    119      1.1    jruoho 
    120      1.1    jruoho     if (AcpiGbl_RootTableList.CurrentTableCount >= 3)
    121      1.1    jruoho     {
    122      1.1    jruoho         return (TRUE);
    123      1.1    jruoho     }
    124      1.1    jruoho 
    125      1.1    jruoho     return (FALSE);
    126      1.1    jruoho }
    127      1.1    jruoho 
    128      1.1    jruoho 
    129      1.1    jruoho /*******************************************************************************
    130      1.1    jruoho  *
    131      1.1    jruoho  * FUNCTION:    AcpiTbCheckDsdtHeader
    132      1.1    jruoho  *
    133      1.1    jruoho  * PARAMETERS:  None
    134      1.1    jruoho  *
    135      1.1    jruoho  * RETURN:      None
    136      1.1    jruoho  *
    137      1.1    jruoho  * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
    138      1.1    jruoho  *              if the DSDT has been replaced from outside the OS and/or if
    139      1.1    jruoho  *              the DSDT header has been corrupted.
    140      1.1    jruoho  *
    141      1.1    jruoho  ******************************************************************************/
    142      1.1    jruoho 
    143      1.1    jruoho void
    144      1.1    jruoho AcpiTbCheckDsdtHeader (
    145      1.1    jruoho     void)
    146      1.1    jruoho {
    147      1.1    jruoho 
    148      1.1    jruoho     /* Compare original length and checksum to current values */
    149      1.1    jruoho 
    150      1.1    jruoho     if (AcpiGbl_OriginalDsdtHeader.Length != AcpiGbl_DSDT->Length ||
    151      1.1    jruoho         AcpiGbl_OriginalDsdtHeader.Checksum != AcpiGbl_DSDT->Checksum)
    152      1.1    jruoho     {
    153  1.1.1.3  christos         ACPI_BIOS_ERROR ((AE_INFO,
    154  1.1.1.3  christos             "The DSDT has been corrupted or replaced - "
    155  1.1.1.3  christos             "old, new headers below"));
    156      1.1    jruoho         AcpiTbPrintTableHeader (0, &AcpiGbl_OriginalDsdtHeader);
    157      1.1    jruoho         AcpiTbPrintTableHeader (0, AcpiGbl_DSDT);
    158      1.1    jruoho 
    159      1.1    jruoho         /* Disable further error messages */
    160      1.1    jruoho 
    161      1.1    jruoho         AcpiGbl_OriginalDsdtHeader.Length = AcpiGbl_DSDT->Length;
    162      1.1    jruoho         AcpiGbl_OriginalDsdtHeader.Checksum = AcpiGbl_DSDT->Checksum;
    163      1.1    jruoho     }
    164      1.1    jruoho }
    165      1.1    jruoho 
    166      1.1    jruoho 
    167      1.1    jruoho /*******************************************************************************
    168      1.1    jruoho  *
    169      1.1    jruoho  * FUNCTION:    AcpiTbCopyDsdt
    170      1.1    jruoho  *
    171      1.1    jruoho  * PARAMETERS:  TableDesc           - Installed table to copy
    172      1.1    jruoho  *
    173      1.1    jruoho  * RETURN:      None
    174      1.1    jruoho  *
    175      1.1    jruoho  * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
    176      1.1    jruoho  *              Some very bad BIOSs are known to either corrupt the DSDT or
    177      1.1    jruoho  *              install a new, bad DSDT. This copy works around the problem.
    178      1.1    jruoho  *
    179      1.1    jruoho  ******************************************************************************/
    180      1.1    jruoho 
    181      1.1    jruoho ACPI_TABLE_HEADER *
    182      1.1    jruoho AcpiTbCopyDsdt (
    183      1.1    jruoho     UINT32                  TableIndex)
    184      1.1    jruoho {
    185      1.1    jruoho     ACPI_TABLE_HEADER       *NewTable;
    186      1.1    jruoho     ACPI_TABLE_DESC         *TableDesc;
    187      1.1    jruoho 
    188      1.1    jruoho 
    189      1.1    jruoho     TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex];
    190      1.1    jruoho 
    191      1.1    jruoho     NewTable = ACPI_ALLOCATE (TableDesc->Length);
    192      1.1    jruoho     if (!NewTable)
    193      1.1    jruoho     {
    194      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Could not copy DSDT of length 0x%X",
    195      1.1    jruoho             TableDesc->Length));
    196      1.1    jruoho         return (NULL);
    197      1.1    jruoho     }
    198      1.1    jruoho 
    199      1.1    jruoho     ACPI_MEMCPY (NewTable, TableDesc->Pointer, TableDesc->Length);
    200      1.1    jruoho     AcpiTbDeleteTable (TableDesc);
    201      1.1    jruoho     TableDesc->Pointer = NewTable;
    202      1.1    jruoho     TableDesc->Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
    203      1.1    jruoho 
    204      1.1    jruoho     ACPI_INFO ((AE_INFO,
    205      1.1    jruoho         "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
    206      1.1    jruoho         NewTable->Length));
    207      1.1    jruoho 
    208      1.1    jruoho     return (NewTable);
    209      1.1    jruoho }
    210      1.1    jruoho 
    211      1.1    jruoho 
    212      1.1    jruoho /*******************************************************************************
    213      1.1    jruoho  *
    214      1.1    jruoho  * FUNCTION:    AcpiTbInstallTable
    215      1.1    jruoho  *
    216      1.1    jruoho  * PARAMETERS:  Address                 - Physical address of DSDT or FACS
    217      1.1    jruoho  *              Signature               - Table signature, NULL if no need to
    218      1.1    jruoho  *                                        match
    219      1.1    jruoho  *              TableIndex              - Index into root table array
    220      1.1    jruoho  *
    221      1.1    jruoho  * RETURN:      None
    222      1.1    jruoho  *
    223      1.1    jruoho  * DESCRIPTION: Install an ACPI table into the global data structure. The
    224  1.1.1.3  christos  *              table override mechanism is called to allow the host
    225      1.1    jruoho  *              OS to replace any table before it is installed in the root
    226      1.1    jruoho  *              table array.
    227      1.1    jruoho  *
    228      1.1    jruoho  ******************************************************************************/
    229      1.1    jruoho 
    230      1.1    jruoho void
    231      1.1    jruoho AcpiTbInstallTable (
    232      1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    233      1.1    jruoho     char                    *Signature,
    234      1.1    jruoho     UINT32                  TableIndex)
    235      1.1    jruoho {
    236  1.1.1.3  christos     ACPI_TABLE_HEADER       *Table;
    237  1.1.1.3  christos     ACPI_TABLE_HEADER       *FinalTable;
    238  1.1.1.3  christos     ACPI_TABLE_DESC         *TableDesc;
    239      1.1    jruoho 
    240      1.1    jruoho 
    241      1.1    jruoho     if (!Address)
    242      1.1    jruoho     {
    243      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
    244      1.1    jruoho             Signature));
    245      1.1    jruoho         return;
    246      1.1    jruoho     }
    247      1.1    jruoho 
    248      1.1    jruoho     /* Map just the table header */
    249      1.1    jruoho 
    250  1.1.1.3  christos     Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
    251  1.1.1.3  christos     if (!Table)
    252      1.1    jruoho     {
    253  1.1.1.3  christos         ACPI_ERROR ((AE_INFO, "Could not map memory for table [%s] at %p",
    254  1.1.1.3  christos             Signature, ACPI_CAST_PTR (void, Address)));
    255      1.1    jruoho         return;
    256      1.1    jruoho     }
    257      1.1    jruoho 
    258      1.1    jruoho     /* If a particular signature is expected (DSDT/FACS), it must match */
    259      1.1    jruoho 
    260      1.1    jruoho     if (Signature &&
    261  1.1.1.3  christos         !ACPI_COMPARE_NAME (Table->Signature, Signature))
    262      1.1    jruoho     {
    263  1.1.1.3  christos         ACPI_BIOS_ERROR ((AE_INFO,
    264      1.1    jruoho             "Invalid signature 0x%X for ACPI table, expected [%s]",
    265  1.1.1.3  christos             *ACPI_CAST_PTR (UINT32, Table->Signature), Signature));
    266      1.1    jruoho         goto UnmapAndExit;
    267      1.1    jruoho     }
    268      1.1    jruoho 
    269      1.1    jruoho     /*
    270  1.1.1.3  christos      * Initialize the table entry. Set the pointer to NULL, since the
    271  1.1.1.3  christos      * table is not fully mapped at this time.
    272  1.1.1.3  christos      */
    273  1.1.1.3  christos     TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex];
    274  1.1.1.3  christos 
    275  1.1.1.3  christos     TableDesc->Address = Address;
    276  1.1.1.3  christos     TableDesc->Pointer = NULL;
    277  1.1.1.3  christos     TableDesc->Length = Table->Length;
    278  1.1.1.3  christos     TableDesc->Flags = ACPI_TABLE_ORIGIN_MAPPED;
    279  1.1.1.3  christos     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
    280  1.1.1.3  christos 
    281  1.1.1.3  christos     /*
    282      1.1    jruoho      * ACPI Table Override:
    283      1.1    jruoho      *
    284      1.1    jruoho      * Before we install the table, let the host OS override it with a new
    285      1.1    jruoho      * one if desired. Any table within the RSDT/XSDT can be replaced,
    286      1.1    jruoho      * including the DSDT which is pointed to by the FADT.
    287  1.1.1.3  christos      *
    288  1.1.1.3  christos      * NOTE: If the table is overridden, then FinalTable will contain a
    289  1.1.1.3  christos      * mapped pointer to the full new table. If the table is not overridden,
    290  1.1.1.3  christos      * or if there has been a physical override, then the table will be
    291  1.1.1.3  christos      * fully mapped later (in verify table). In any case, we must
    292  1.1.1.3  christos      * unmap the header that was mapped above.
    293      1.1    jruoho      */
    294  1.1.1.3  christos     FinalTable = AcpiTbTableOverride (Table, TableDesc);
    295  1.1.1.3  christos     if (!FinalTable)
    296      1.1    jruoho     {
    297  1.1.1.3  christos         FinalTable = Table; /* There was no override */
    298      1.1    jruoho     }
    299      1.1    jruoho 
    300  1.1.1.3  christos     AcpiTbPrintTableHeader (TableDesc->Address, FinalTable);
    301      1.1    jruoho 
    302  1.1.1.3  christos     /* Set the global integer width (based upon revision of the DSDT) */
    303      1.1    jruoho 
    304      1.1    jruoho     if (TableIndex == ACPI_TABLE_INDEX_DSDT)
    305      1.1    jruoho     {
    306  1.1.1.3  christos         AcpiUtSetIntegerWidth (FinalTable->Revision);
    307  1.1.1.3  christos     }
    308      1.1    jruoho 
    309  1.1.1.3  christos     /*
    310  1.1.1.3  christos      * If we have a physical override during this early loading of the ACPI
    311  1.1.1.3  christos      * tables, unmap the table for now. It will be mapped again later when
    312  1.1.1.3  christos      * it is actually used. This supports very early loading of ACPI tables,
    313  1.1.1.3  christos      * before virtual memory is fully initialized and running within the
    314  1.1.1.3  christos      * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE
    315  1.1.1.3  christos      * flag set and will not be deleted below.
    316  1.1.1.3  christos      */
    317  1.1.1.3  christos     if (FinalTable != Table)
    318  1.1.1.3  christos     {
    319  1.1.1.3  christos         AcpiTbDeleteTable (TableDesc);
    320      1.1    jruoho     }
    321      1.1    jruoho 
    322  1.1.1.3  christos 
    323      1.1    jruoho UnmapAndExit:
    324  1.1.1.3  christos 
    325  1.1.1.3  christos     /* Always unmap the table header that we mapped above */
    326  1.1.1.3  christos 
    327  1.1.1.3  christos     AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
    328      1.1    jruoho }
    329      1.1    jruoho 
    330      1.1    jruoho 
    331      1.1    jruoho /*******************************************************************************
    332      1.1    jruoho  *
    333      1.1    jruoho  * FUNCTION:    AcpiTbGetRootTableEntry
    334      1.1    jruoho  *
    335      1.1    jruoho  * PARAMETERS:  TableEntry          - Pointer to the RSDT/XSDT table entry
    336      1.1    jruoho  *              TableEntrySize      - sizeof 32 or 64 (RSDT or XSDT)
    337      1.1    jruoho  *
    338      1.1    jruoho  * RETURN:      Physical address extracted from the root table
    339      1.1    jruoho  *
    340      1.1    jruoho  * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
    341      1.1    jruoho  *              both 32-bit and 64-bit platforms
    342      1.1    jruoho  *
    343      1.1    jruoho  * NOTE:        ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
    344      1.1    jruoho  *              64-bit platforms.
    345      1.1    jruoho  *
    346      1.1    jruoho  ******************************************************************************/
    347      1.1    jruoho 
    348      1.1    jruoho static ACPI_PHYSICAL_ADDRESS
    349      1.1    jruoho AcpiTbGetRootTableEntry (
    350      1.1    jruoho     UINT8                   *TableEntry,
    351      1.1    jruoho     UINT32                  TableEntrySize)
    352      1.1    jruoho {
    353      1.1    jruoho     UINT64                  Address64;
    354      1.1    jruoho 
    355      1.1    jruoho 
    356      1.1    jruoho     /*
    357      1.1    jruoho      * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
    358      1.1    jruoho      * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
    359      1.1    jruoho      */
    360  1.1.1.3  christos     if (TableEntrySize == ACPI_RSDT_ENTRY_SIZE)
    361      1.1    jruoho     {
    362      1.1    jruoho         /*
    363      1.1    jruoho          * 32-bit platform, RSDT: Return 32-bit table entry
    364      1.1    jruoho          * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
    365      1.1    jruoho          */
    366      1.1    jruoho         return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry)));
    367      1.1    jruoho     }
    368      1.1    jruoho     else
    369      1.1    jruoho     {
    370      1.1    jruoho         /*
    371      1.1    jruoho          * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
    372      1.1    jruoho          * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
    373      1.1    jruoho          *  return 64-bit
    374      1.1    jruoho          */
    375      1.1    jruoho         ACPI_MOVE_64_TO_64 (&Address64, TableEntry);
    376      1.1    jruoho 
    377      1.1    jruoho #if ACPI_MACHINE_WIDTH == 32
    378      1.1    jruoho         if (Address64 > ACPI_UINT32_MAX)
    379      1.1    jruoho         {
    380      1.1    jruoho             /* Will truncate 64-bit address to 32 bits, issue warning */
    381      1.1    jruoho 
    382  1.1.1.3  christos             ACPI_BIOS_WARNING ((AE_INFO,
    383      1.1    jruoho                 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
    384      1.1    jruoho                 " truncating",
    385      1.1    jruoho                 ACPI_FORMAT_UINT64 (Address64)));
    386      1.1    jruoho         }
    387      1.1    jruoho #endif
    388      1.1    jruoho         return ((ACPI_PHYSICAL_ADDRESS) (Address64));
    389      1.1    jruoho     }
    390      1.1    jruoho }
    391      1.1    jruoho 
    392      1.1    jruoho 
    393      1.1    jruoho /*******************************************************************************
    394      1.1    jruoho  *
    395  1.1.1.3  christos  * FUNCTION:    AcpiTbValidateXsdt
    396  1.1.1.3  christos  *
    397  1.1.1.3  christos  * PARAMETERS:  Address             - Physical address of the XSDT (from RSDP)
    398  1.1.1.3  christos  *
    399  1.1.1.3  christos  * RETURN:      Status. AE_OK if the table appears to be valid.
    400  1.1.1.3  christos  *
    401  1.1.1.3  christos  * DESCRIPTION: Validate an XSDT to ensure that it is of minimum size and does
    402  1.1.1.3  christos  *              not contain any NULL entries. A problem that is seen in the
    403  1.1.1.3  christos  *              field is that the XSDT exists, but is actually useless because
    404  1.1.1.3  christos  *              of one or more (or all) NULL entries.
    405  1.1.1.3  christos  *
    406  1.1.1.3  christos  ******************************************************************************/
    407  1.1.1.3  christos 
    408  1.1.1.3  christos static ACPI_STATUS
    409  1.1.1.3  christos AcpiTbValidateXsdt (
    410  1.1.1.3  christos     ACPI_PHYSICAL_ADDRESS   XsdtAddress)
    411  1.1.1.3  christos {
    412  1.1.1.3  christos     ACPI_TABLE_HEADER       *Table;
    413  1.1.1.3  christos     UINT8                   *NextEntry;
    414  1.1.1.3  christos     ACPI_PHYSICAL_ADDRESS   Address;
    415  1.1.1.3  christos     UINT32                  Length;
    416  1.1.1.3  christos     UINT32                  EntryCount;
    417  1.1.1.3  christos     ACPI_STATUS             Status;
    418  1.1.1.3  christos     UINT32                  i;
    419  1.1.1.3  christos 
    420  1.1.1.3  christos 
    421  1.1.1.3  christos     /* Get the XSDT length */
    422  1.1.1.3  christos 
    423  1.1.1.3  christos     Table = AcpiOsMapMemory (XsdtAddress, sizeof (ACPI_TABLE_HEADER));
    424  1.1.1.3  christos     if (!Table)
    425  1.1.1.3  christos     {
    426  1.1.1.3  christos         return (AE_NO_MEMORY);
    427  1.1.1.3  christos     }
    428  1.1.1.3  christos 
    429  1.1.1.3  christos     Length = Table->Length;
    430  1.1.1.3  christos     AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
    431  1.1.1.3  christos 
    432  1.1.1.3  christos     /*
    433  1.1.1.3  christos      * Minimum XSDT length is the size of the standard ACPI header
    434  1.1.1.3  christos      * plus one physical address entry
    435  1.1.1.3  christos      */
    436  1.1.1.3  christos     if (Length < (sizeof (ACPI_TABLE_HEADER) + ACPI_XSDT_ENTRY_SIZE))
    437  1.1.1.3  christos     {
    438  1.1.1.3  christos         return (AE_INVALID_TABLE_LENGTH);
    439  1.1.1.3  christos     }
    440  1.1.1.3  christos 
    441  1.1.1.3  christos     /* Map the entire XSDT */
    442  1.1.1.3  christos 
    443  1.1.1.3  christos     Table = AcpiOsMapMemory (XsdtAddress, Length);
    444  1.1.1.3  christos     if (!Table)
    445  1.1.1.3  christos     {
    446  1.1.1.3  christos         return (AE_NO_MEMORY);
    447  1.1.1.3  christos     }
    448  1.1.1.3  christos 
    449  1.1.1.3  christos     /* Get the number of entries and pointer to first entry */
    450  1.1.1.3  christos 
    451  1.1.1.3  christos     Status = AE_OK;
    452  1.1.1.3  christos     NextEntry = ACPI_ADD_PTR (UINT8, Table, sizeof (ACPI_TABLE_HEADER));
    453  1.1.1.3  christos     EntryCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) /
    454  1.1.1.3  christos         ACPI_XSDT_ENTRY_SIZE);
    455  1.1.1.3  christos 
    456  1.1.1.3  christos     /* Validate each entry (physical address) within the XSDT */
    457  1.1.1.3  christos 
    458  1.1.1.3  christos     for (i = 0; i < EntryCount; i++)
    459  1.1.1.3  christos     {
    460  1.1.1.3  christos         Address = AcpiTbGetRootTableEntry (NextEntry, ACPI_XSDT_ENTRY_SIZE);
    461  1.1.1.3  christos         if (!Address)
    462  1.1.1.3  christos         {
    463  1.1.1.3  christos             /* Detected a NULL entry, XSDT is invalid */
    464  1.1.1.3  christos 
    465  1.1.1.3  christos             Status = AE_NULL_ENTRY;
    466  1.1.1.3  christos             break;
    467  1.1.1.3  christos         }
    468  1.1.1.3  christos 
    469  1.1.1.3  christos         NextEntry += ACPI_XSDT_ENTRY_SIZE;
    470  1.1.1.3  christos     }
    471  1.1.1.3  christos 
    472  1.1.1.3  christos     /* Unmap table */
    473  1.1.1.3  christos 
    474  1.1.1.3  christos     AcpiOsUnmapMemory (Table, Length);
    475  1.1.1.3  christos     return (Status);
    476  1.1.1.3  christos }
    477  1.1.1.3  christos 
    478  1.1.1.3  christos 
    479  1.1.1.3  christos /*******************************************************************************
    480  1.1.1.3  christos  *
    481      1.1    jruoho  * FUNCTION:    AcpiTbParseRootTable
    482      1.1    jruoho  *
    483      1.1    jruoho  * PARAMETERS:  Rsdp                    - Pointer to the RSDP
    484      1.1    jruoho  *
    485      1.1    jruoho  * RETURN:      Status
    486      1.1    jruoho  *
    487      1.1    jruoho  * DESCRIPTION: This function is called to parse the Root System Description
    488      1.1    jruoho  *              Table (RSDT or XSDT)
    489      1.1    jruoho  *
    490      1.1    jruoho  * NOTE:        Tables are mapped (not copied) for efficiency. The FACS must
    491      1.1    jruoho  *              be mapped and cannot be copied because it contains the actual
    492      1.1    jruoho  *              memory location of the ACPI Global Lock.
    493      1.1    jruoho  *
    494      1.1    jruoho  ******************************************************************************/
    495      1.1    jruoho 
    496      1.1    jruoho ACPI_STATUS
    497      1.1    jruoho AcpiTbParseRootTable (
    498      1.1    jruoho     ACPI_PHYSICAL_ADDRESS   RsdpAddress)
    499      1.1    jruoho {
    500      1.1    jruoho     ACPI_TABLE_RSDP         *Rsdp;
    501      1.1    jruoho     UINT32                  TableEntrySize;
    502      1.1    jruoho     UINT32                  i;
    503      1.1    jruoho     UINT32                  TableCount;
    504      1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    505      1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address;
    506      1.1    jruoho     UINT32                  Length;
    507      1.1    jruoho     UINT8                   *TableEntry;
    508      1.1    jruoho     ACPI_STATUS             Status;
    509      1.1    jruoho 
    510      1.1    jruoho 
    511      1.1    jruoho     ACPI_FUNCTION_TRACE (TbParseRootTable);
    512      1.1    jruoho 
    513      1.1    jruoho 
    514  1.1.1.3  christos     /* Map the entire RSDP and extract the address of the RSDT or XSDT */
    515  1.1.1.3  christos 
    516      1.1    jruoho     Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP));
    517      1.1    jruoho     if (!Rsdp)
    518      1.1    jruoho     {
    519      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    520      1.1    jruoho     }
    521      1.1    jruoho 
    522      1.1    jruoho     AcpiTbPrintTableHeader (RsdpAddress,
    523      1.1    jruoho         ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp));
    524      1.1    jruoho 
    525  1.1.1.3  christos     /* Use XSDT if present and not overridden. Otherwise, use RSDT */
    526      1.1    jruoho 
    527  1.1.1.3  christos     if ((Rsdp->Revision > 1) &&
    528  1.1.1.3  christos         Rsdp->XsdtPhysicalAddress &&
    529  1.1.1.3  christos         !AcpiGbl_DoNotUseXsdt)
    530      1.1    jruoho     {
    531      1.1    jruoho         /*
    532  1.1.1.3  christos          * RSDP contains an XSDT (64-bit physical addresses). We must use
    533  1.1.1.3  christos          * the XSDT if the revision is > 1 and the XSDT pointer is present,
    534  1.1.1.3  christos          * as per the ACPI specification.
    535      1.1    jruoho          */
    536      1.1    jruoho         Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress;
    537  1.1.1.3  christos         TableEntrySize = ACPI_XSDT_ENTRY_SIZE;
    538      1.1    jruoho     }
    539      1.1    jruoho     else
    540      1.1    jruoho     {
    541      1.1    jruoho         /* Root table is an RSDT (32-bit physical addresses) */
    542      1.1    jruoho 
    543      1.1    jruoho         Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
    544  1.1.1.3  christos         TableEntrySize = ACPI_RSDT_ENTRY_SIZE;
    545      1.1    jruoho     }
    546      1.1    jruoho 
    547      1.1    jruoho     /*
    548      1.1    jruoho      * It is not possible to map more than one entry in some environments,
    549      1.1    jruoho      * so unmap the RSDP here before mapping other tables
    550      1.1    jruoho      */
    551      1.1    jruoho     AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP));
    552      1.1    jruoho 
    553  1.1.1.3  christos     /*
    554  1.1.1.3  christos      * If it is present and used, validate the XSDT for access/size
    555  1.1.1.3  christos      * and ensure that all table entries are at least non-NULL
    556  1.1.1.3  christos      */
    557  1.1.1.3  christos     if (TableEntrySize == ACPI_XSDT_ENTRY_SIZE)
    558  1.1.1.3  christos     {
    559  1.1.1.3  christos         Status = AcpiTbValidateXsdt (Address);
    560  1.1.1.3  christos         if (ACPI_FAILURE (Status))
    561  1.1.1.3  christos         {
    562  1.1.1.3  christos             ACPI_BIOS_WARNING ((AE_INFO, "XSDT is invalid (%s), using RSDT",
    563  1.1.1.3  christos                 AcpiFormatException (Status)));
    564  1.1.1.3  christos 
    565  1.1.1.3  christos             /* Fall back to the RSDT */
    566  1.1.1.3  christos 
    567  1.1.1.3  christos             Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
    568  1.1.1.3  christos             TableEntrySize = ACPI_RSDT_ENTRY_SIZE;
    569  1.1.1.3  christos         }
    570  1.1.1.3  christos     }
    571      1.1    jruoho 
    572      1.1    jruoho     /* Map the RSDT/XSDT table header to get the full table length */
    573      1.1    jruoho 
    574      1.1    jruoho     Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
    575      1.1    jruoho     if (!Table)
    576      1.1    jruoho     {
    577      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    578      1.1    jruoho     }
    579      1.1    jruoho 
    580      1.1    jruoho     AcpiTbPrintTableHeader (Address, Table);
    581      1.1    jruoho 
    582  1.1.1.3  christos     /*
    583  1.1.1.3  christos      * Validate length of the table, and map entire table.
    584  1.1.1.3  christos      * Minimum length table must contain at least one entry.
    585  1.1.1.3  christos      */
    586      1.1    jruoho     Length = Table->Length;
    587      1.1    jruoho     AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
    588      1.1    jruoho 
    589  1.1.1.3  christos     if (Length < (sizeof (ACPI_TABLE_HEADER) + TableEntrySize))
    590      1.1    jruoho     {
    591  1.1.1.3  christos         ACPI_BIOS_ERROR ((AE_INFO,
    592  1.1.1.3  christos             "Invalid table length 0x%X in RSDT/XSDT", Length));
    593      1.1    jruoho         return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
    594      1.1    jruoho     }
    595      1.1    jruoho 
    596      1.1    jruoho     Table = AcpiOsMapMemory (Address, Length);
    597      1.1    jruoho     if (!Table)
    598      1.1    jruoho     {
    599      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    600      1.1    jruoho     }
    601      1.1    jruoho 
    602      1.1    jruoho     /* Validate the root table checksum */
    603      1.1    jruoho 
    604      1.1    jruoho     Status = AcpiTbVerifyChecksum (Table, Length);
    605      1.1    jruoho     if (ACPI_FAILURE (Status))
    606      1.1    jruoho     {
    607      1.1    jruoho         AcpiOsUnmapMemory (Table, Length);
    608      1.1    jruoho         return_ACPI_STATUS (Status);
    609      1.1    jruoho     }
    610      1.1    jruoho 
    611  1.1.1.3  christos     /* Get the number of entries and pointer to first entry */
    612      1.1    jruoho 
    613      1.1    jruoho     TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) /
    614      1.1    jruoho         TableEntrySize);
    615  1.1.1.3  christos     TableEntry = ACPI_ADD_PTR (UINT8, Table, sizeof (ACPI_TABLE_HEADER));
    616      1.1    jruoho 
    617      1.1    jruoho     /*
    618      1.1    jruoho      * First two entries in the table array are reserved for the DSDT
    619      1.1    jruoho      * and FACS, which are not actually present in the RSDT/XSDT - they
    620      1.1    jruoho      * come from the FADT
    621      1.1    jruoho      */
    622      1.1    jruoho     AcpiGbl_RootTableList.CurrentTableCount = 2;
    623      1.1    jruoho 
    624  1.1.1.3  christos     /* Initialize the root table array from the RSDT/XSDT */
    625  1.1.1.3  christos 
    626      1.1    jruoho     for (i = 0; i < TableCount; i++)
    627      1.1    jruoho     {
    628      1.1    jruoho         if (AcpiGbl_RootTableList.CurrentTableCount >=
    629      1.1    jruoho             AcpiGbl_RootTableList.MaxTableCount)
    630      1.1    jruoho         {
    631      1.1    jruoho             /* There is no more room in the root table array, attempt resize */
    632      1.1    jruoho 
    633      1.1    jruoho             Status = AcpiTbResizeRootTableList ();
    634      1.1    jruoho             if (ACPI_FAILURE (Status))
    635      1.1    jruoho             {
    636      1.1    jruoho                 ACPI_WARNING ((AE_INFO, "Truncating %u table entries!",
    637      1.1    jruoho                     (unsigned) (TableCount -
    638      1.1    jruoho                     (AcpiGbl_RootTableList.CurrentTableCount - 2))));
    639      1.1    jruoho                 break;
    640      1.1    jruoho             }
    641      1.1    jruoho         }
    642      1.1    jruoho 
    643      1.1    jruoho         /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
    644      1.1    jruoho 
    645      1.1    jruoho         AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.CurrentTableCount].Address =
    646      1.1    jruoho             AcpiTbGetRootTableEntry (TableEntry, TableEntrySize);
    647      1.1    jruoho 
    648      1.1    jruoho         TableEntry += TableEntrySize;
    649      1.1    jruoho         AcpiGbl_RootTableList.CurrentTableCount++;
    650      1.1    jruoho     }
    651      1.1    jruoho 
    652      1.1    jruoho     /*
    653      1.1    jruoho      * It is not possible to map more than one entry in some environments,
    654      1.1    jruoho      * so unmap the root table here before mapping other tables
    655      1.1    jruoho      */
    656      1.1    jruoho     AcpiOsUnmapMemory (Table, Length);
    657      1.1    jruoho 
    658      1.1    jruoho     /*
    659      1.1    jruoho      * Complete the initialization of the root table array by examining
    660      1.1    jruoho      * the header of each table
    661      1.1    jruoho      */
    662      1.1    jruoho     for (i = 2; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    663      1.1    jruoho     {
    664      1.1    jruoho         AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address,
    665      1.1    jruoho             NULL, i);
    666      1.1    jruoho 
    667  1.1.1.3  christos         /* Special case for FADT - validate it then get the DSDT and FACS */
    668      1.1    jruoho 
    669      1.1    jruoho         if (ACPI_COMPARE_NAME (
    670      1.1    jruoho                 &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT))
    671      1.1    jruoho         {
    672      1.1    jruoho             AcpiTbParseFadt (i);
    673      1.1    jruoho         }
    674      1.1    jruoho     }
    675      1.1    jruoho 
    676      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    677      1.1    jruoho }
    678