Home | History | Annotate | Line # | Download | only in tables
tbinstal.c revision 1.1.1.6
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: tbinstal - ACPI table installation and removal
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.6  christos  * Copyright (C) 2000 - 2015, 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 #include "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "actables.h"
     47      1.1    jruoho 
     48      1.1    jruoho #define _COMPONENT          ACPI_TABLES
     49      1.1    jruoho         ACPI_MODULE_NAME    ("tbinstal")
     50      1.1    jruoho 
     51  1.1.1.5  christos /* Local prototypes */
     52  1.1.1.5  christos 
     53  1.1.1.5  christos static BOOLEAN
     54  1.1.1.5  christos AcpiTbCompareTables (
     55  1.1.1.5  christos     ACPI_TABLE_DESC         *TableDesc,
     56  1.1.1.5  christos     UINT32                  TableIndex);
     57  1.1.1.5  christos 
     58      1.1    jruoho 
     59  1.1.1.5  christos /*******************************************************************************
     60      1.1    jruoho  *
     61  1.1.1.5  christos  * FUNCTION:    AcpiTbCompareTables
     62      1.1    jruoho  *
     63  1.1.1.5  christos  * PARAMETERS:  TableDesc           - Table 1 descriptor to be compared
     64  1.1.1.5  christos  *              TableIndex          - Index of table 2 to be compared
     65      1.1    jruoho  *
     66  1.1.1.5  christos  * RETURN:      TRUE if both tables are identical.
     67      1.1    jruoho  *
     68  1.1.1.5  christos  * DESCRIPTION: This function compares a table with another table that has
     69  1.1.1.5  christos  *              already been installed in the root table list.
     70      1.1    jruoho  *
     71  1.1.1.5  christos  ******************************************************************************/
     72      1.1    jruoho 
     73  1.1.1.5  christos static BOOLEAN
     74  1.1.1.5  christos AcpiTbCompareTables (
     75  1.1.1.5  christos     ACPI_TABLE_DESC         *TableDesc,
     76  1.1.1.5  christos     UINT32                  TableIndex)
     77      1.1    jruoho {
     78      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
     79  1.1.1.5  christos     BOOLEAN                 IsIdentical;
     80  1.1.1.5  christos     ACPI_TABLE_HEADER       *Table;
     81  1.1.1.5  christos     UINT32                  TableLength;
     82  1.1.1.5  christos     UINT8                   TableFlags;
     83      1.1    jruoho 
     84      1.1    jruoho 
     85  1.1.1.5  christos     Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
     86  1.1.1.5  christos                 &Table, &TableLength, &TableFlags);
     87  1.1.1.5  christos     if (ACPI_FAILURE (Status))
     88      1.1    jruoho     {
     89  1.1.1.5  christos         return (FALSE);
     90      1.1    jruoho     }
     91      1.1    jruoho 
     92  1.1.1.5  christos     /*
     93  1.1.1.5  christos      * Check for a table match on the entire table length,
     94  1.1.1.5  christos      * not just the header.
     95  1.1.1.5  christos      */
     96  1.1.1.5  christos     IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
     97  1.1.1.5  christos         ACPI_MEMCMP (TableDesc->Pointer, Table, TableLength)) ?
     98  1.1.1.5  christos         FALSE : TRUE);
     99      1.1    jruoho 
    100  1.1.1.5  christos     /* Release the acquired table */
    101      1.1    jruoho 
    102  1.1.1.5  christos     AcpiTbReleaseTable (Table, TableLength, TableFlags);
    103  1.1.1.5  christos     return (IsIdentical);
    104      1.1    jruoho }
    105      1.1    jruoho 
    106      1.1    jruoho 
    107      1.1    jruoho /*******************************************************************************
    108      1.1    jruoho  *
    109  1.1.1.5  christos  * FUNCTION:    AcpiTbInstallTableWithOverride
    110      1.1    jruoho  *
    111  1.1.1.5  christos  * PARAMETERS:  TableIndex              - Index into root table array
    112  1.1.1.5  christos  *              NewTableDesc            - New table descriptor to install
    113  1.1.1.5  christos  *              Override                - Whether override should be performed
    114      1.1    jruoho  *
    115  1.1.1.5  christos  * RETURN:      None
    116      1.1    jruoho  *
    117  1.1.1.5  christos  * DESCRIPTION: Install an ACPI table into the global data structure. The
    118  1.1.1.5  christos  *              table override mechanism is called to allow the host
    119  1.1.1.5  christos  *              OS to replace any table before it is installed in the root
    120  1.1.1.5  christos  *              table array.
    121      1.1    jruoho  *
    122      1.1    jruoho  ******************************************************************************/
    123      1.1    jruoho 
    124  1.1.1.5  christos void
    125  1.1.1.5  christos AcpiTbInstallTableWithOverride (
    126  1.1.1.5  christos     UINT32                  TableIndex,
    127  1.1.1.5  christos     ACPI_TABLE_DESC         *NewTableDesc,
    128  1.1.1.5  christos     BOOLEAN                 Override)
    129      1.1    jruoho {
    130      1.1    jruoho 
    131  1.1.1.5  christos     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    132      1.1    jruoho     {
    133  1.1.1.5  christos         return;
    134      1.1    jruoho     }
    135      1.1    jruoho 
    136      1.1    jruoho     /*
    137  1.1.1.5  christos      * ACPI Table Override:
    138  1.1.1.3    jruoho      *
    139  1.1.1.5  christos      * Before we install the table, let the host OS override it with a new
    140  1.1.1.5  christos      * one if desired. Any table within the RSDT/XSDT can be replaced,
    141  1.1.1.5  christos      * including the DSDT which is pointed to by the FADT.
    142      1.1    jruoho      */
    143  1.1.1.5  christos     if (Override)
    144  1.1.1.3    jruoho     {
    145  1.1.1.5  christos         AcpiTbOverrideTable (NewTableDesc);
    146  1.1.1.3    jruoho     }
    147      1.1    jruoho 
    148  1.1.1.5  christos     AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList.Tables[TableIndex],
    149  1.1.1.5  christos         NewTableDesc->Address, NewTableDesc->Flags, NewTableDesc->Pointer);
    150      1.1    jruoho 
    151  1.1.1.5  christos     AcpiTbPrintTableHeader (NewTableDesc->Address, NewTableDesc->Pointer);
    152      1.1    jruoho 
    153  1.1.1.5  christos     /* Set the global integer width (based upon revision of the DSDT) */
    154      1.1    jruoho 
    155  1.1.1.5  christos     if (TableIndex == ACPI_TABLE_INDEX_DSDT)
    156      1.1    jruoho     {
    157  1.1.1.5  christos         AcpiUtSetIntegerWidth (NewTableDesc->Pointer->Revision);
    158      1.1    jruoho     }
    159      1.1    jruoho }
    160      1.1    jruoho 
    161      1.1    jruoho 
    162      1.1    jruoho /*******************************************************************************
    163      1.1    jruoho  *
    164  1.1.1.5  christos  * FUNCTION:    AcpiTbInstallFixedTable
    165  1.1.1.4  christos  *
    166  1.1.1.5  christos  * PARAMETERS:  Address                 - Physical address of DSDT or FACS
    167  1.1.1.5  christos  *              Signature               - Table signature, NULL if no need to
    168  1.1.1.5  christos  *                                        match
    169  1.1.1.5  christos  *              TableIndex              - Index into root table array
    170  1.1.1.4  christos  *
    171  1.1.1.5  christos  * RETURN:      Status
    172  1.1.1.5  christos  *
    173  1.1.1.5  christos  * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
    174  1.1.1.5  christos  *              structure.
    175  1.1.1.4  christos  *
    176  1.1.1.4  christos  ******************************************************************************/
    177  1.1.1.4  christos 
    178  1.1.1.5  christos ACPI_STATUS
    179  1.1.1.5  christos AcpiTbInstallFixedTable (
    180  1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS   Address,
    181  1.1.1.5  christos     char                    *Signature,
    182  1.1.1.5  christos     UINT32                  TableIndex)
    183  1.1.1.4  christos {
    184  1.1.1.5  christos     ACPI_TABLE_DESC         NewTableDesc;
    185  1.1.1.4  christos     ACPI_STATUS             Status;
    186  1.1.1.4  christos 
    187  1.1.1.4  christos 
    188  1.1.1.5  christos     ACPI_FUNCTION_TRACE (TbInstallFixedTable);
    189  1.1.1.5  christos 
    190  1.1.1.4  christos 
    191  1.1.1.5  christos     if (!Address)
    192  1.1.1.4  christos     {
    193  1.1.1.5  christos         ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
    194  1.1.1.5  christos             Signature));
    195  1.1.1.5  christos         return (AE_NO_MEMORY);
    196  1.1.1.4  christos     }
    197  1.1.1.4  christos 
    198  1.1.1.5  christos     /* Fill a table descriptor for validation */
    199  1.1.1.4  christos 
    200  1.1.1.5  christos     Status = AcpiTbAcquireTempTable (&NewTableDesc, Address,
    201  1.1.1.5  christos                 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
    202  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    203  1.1.1.4  christos     {
    204  1.1.1.6  christos         ACPI_ERROR ((AE_INFO, "Could not acquire table length at %8.8X%8.8X",
    205  1.1.1.6  christos             ACPI_FORMAT_UINT64 (Address)));
    206  1.1.1.5  christos         return_ACPI_STATUS (Status);
    207  1.1.1.4  christos     }
    208  1.1.1.4  christos 
    209  1.1.1.5  christos     /* Validate and verify a table before installation */
    210  1.1.1.4  christos 
    211  1.1.1.5  christos     Status = AcpiTbVerifyTempTable (&NewTableDesc, Signature);
    212  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    213  1.1.1.5  christos     {
    214  1.1.1.5  christos         goto ReleaseAndExit;
    215  1.1.1.5  christos     }
    216  1.1.1.4  christos 
    217  1.1.1.5  christos     AcpiTbInstallTableWithOverride (TableIndex, &NewTableDesc, TRUE);
    218  1.1.1.4  christos 
    219  1.1.1.5  christos ReleaseAndExit:
    220  1.1.1.4  christos 
    221  1.1.1.5  christos     /* Release the temporary table descriptor */
    222  1.1.1.4  christos 
    223  1.1.1.5  christos     AcpiTbReleaseTempTable (&NewTableDesc);
    224  1.1.1.5  christos     return_ACPI_STATUS (Status);
    225  1.1.1.4  christos }
    226  1.1.1.4  christos 
    227  1.1.1.4  christos 
    228  1.1.1.4  christos /*******************************************************************************
    229  1.1.1.4  christos  *
    230  1.1.1.5  christos  * FUNCTION:    AcpiTbInstallStandardTable
    231      1.1    jruoho  *
    232  1.1.1.5  christos  * PARAMETERS:  Address             - Address of the table (might be a virtual
    233  1.1.1.5  christos  *                                    address depending on the TableFlags)
    234  1.1.1.5  christos  *              Flags               - Flags for the table
    235  1.1.1.5  christos  *              Reload              - Whether reload should be performed
    236  1.1.1.5  christos  *              Override            - Whether override should be performed
    237  1.1.1.5  christos  *              TableIndex          - Where the table index is returned
    238      1.1    jruoho  *
    239      1.1    jruoho  * RETURN:      Status
    240      1.1    jruoho  *
    241  1.1.1.5  christos  * DESCRIPTION: This function is called to install an ACPI table that is
    242  1.1.1.5  christos  *              neither DSDT nor FACS (a "standard" table.)
    243  1.1.1.5  christos  *              When this function is called by "Load" or "LoadTable" opcodes,
    244  1.1.1.5  christos  *              or by AcpiLoadTable() API, the "Reload" parameter is set.
    245  1.1.1.5  christos  *              After sucessfully returning from this function, table is
    246  1.1.1.5  christos  *              "INSTALLED" but not "VALIDATED".
    247      1.1    jruoho  *
    248      1.1    jruoho  ******************************************************************************/
    249      1.1    jruoho 
    250      1.1    jruoho ACPI_STATUS
    251  1.1.1.5  christos AcpiTbInstallStandardTable (
    252  1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS   Address,
    253  1.1.1.5  christos     UINT8                   Flags,
    254  1.1.1.5  christos     BOOLEAN                 Reload,
    255  1.1.1.5  christos     BOOLEAN                 Override,
    256  1.1.1.5  christos     UINT32                  *TableIndex)
    257      1.1    jruoho {
    258  1.1.1.5  christos     UINT32                  i;
    259  1.1.1.5  christos     ACPI_STATUS             Status = AE_OK;
    260  1.1.1.5  christos     ACPI_TABLE_DESC         NewTableDesc;
    261      1.1    jruoho 
    262      1.1    jruoho 
    263  1.1.1.5  christos     ACPI_FUNCTION_TRACE (TbInstallStandardTable);
    264      1.1    jruoho 
    265      1.1    jruoho 
    266  1.1.1.5  christos     /* Acquire a temporary table descriptor for validation */
    267      1.1    jruoho 
    268  1.1.1.5  christos     Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags);
    269  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    270  1.1.1.4  christos     {
    271  1.1.1.6  christos         ACPI_ERROR ((AE_INFO, "Could not acquire table length at %8.8X%8.8X",
    272  1.1.1.6  christos             ACPI_FORMAT_UINT64 (Address)));
    273  1.1.1.5  christos         return_ACPI_STATUS (Status);
    274  1.1.1.4  christos     }
    275  1.1.1.4  christos 
    276  1.1.1.5  christos     /*
    277  1.1.1.5  christos      * Optionally do not load any SSDTs from the RSDT/XSDT. This can
    278  1.1.1.5  christos      * be useful for debugging ACPI problems on some machines.
    279  1.1.1.5  christos      */
    280  1.1.1.5  christos     if (!Reload &&
    281  1.1.1.5  christos         AcpiGbl_DisableSsdtTableInstall &&
    282  1.1.1.5  christos         ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT))
    283      1.1    jruoho     {
    284  1.1.1.6  christos         ACPI_INFO ((AE_INFO, "Ignoring installation of %4.4s at %8.8X%8.8X",
    285  1.1.1.6  christos             NewTableDesc.Signature.Ascii, ACPI_FORMAT_UINT64 (Address)));
    286  1.1.1.5  christos         goto ReleaseAndExit;
    287      1.1    jruoho     }
    288      1.1    jruoho 
    289  1.1.1.5  christos     /* Validate and verify a table before installation */
    290      1.1    jruoho 
    291  1.1.1.5  christos     Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
    292  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    293      1.1    jruoho     {
    294  1.1.1.5  christos         goto ReleaseAndExit;
    295      1.1    jruoho     }
    296      1.1    jruoho 
    297  1.1.1.5  christos     if (Reload)
    298  1.1.1.5  christos     {
    299  1.1.1.5  christos         /*
    300  1.1.1.5  christos          * Validate the incoming table signature.
    301  1.1.1.5  christos          *
    302  1.1.1.5  christos          * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
    303  1.1.1.5  christos          * 2) We added support for OEMx tables, signature "OEM".
    304  1.1.1.5  christos          * 3) Valid tables were encountered with a null signature, so we just
    305  1.1.1.5  christos          *    gave up on validating the signature, (05/2008).
    306  1.1.1.5  christos          * 4) We encountered non-AML tables such as the MADT, which caused
    307  1.1.1.5  christos          *    interpreter errors and kernel faults. So now, we once again allow
    308  1.1.1.5  christos          *    only "SSDT", "OEMx", and now, also a null signature. (05/2011).
    309  1.1.1.5  christos          */
    310  1.1.1.5  christos         if ((NewTableDesc.Signature.Ascii[0] != 0x00) &&
    311  1.1.1.5  christos            (!ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) &&
    312  1.1.1.5  christos            (ACPI_STRNCMP (NewTableDesc.Signature.Ascii, "OEM", 3)))
    313  1.1.1.5  christos         {
    314  1.1.1.5  christos             ACPI_BIOS_ERROR ((AE_INFO,
    315  1.1.1.5  christos                 "Table has invalid signature [%4.4s] (0x%8.8X), "
    316  1.1.1.5  christos                 "must be SSDT or OEMx",
    317  1.1.1.5  christos                 AcpiUtValidAcpiName (NewTableDesc.Signature.Ascii) ?
    318  1.1.1.5  christos                     NewTableDesc.Signature.Ascii : "????",
    319  1.1.1.5  christos                 NewTableDesc.Signature.Integer));
    320  1.1.1.5  christos 
    321  1.1.1.5  christos             Status = AE_BAD_SIGNATURE;
    322  1.1.1.5  christos             goto ReleaseAndExit;
    323  1.1.1.5  christos         }
    324  1.1.1.5  christos 
    325  1.1.1.5  christos         /* Check if table is already registered */
    326  1.1.1.5  christos 
    327  1.1.1.5  christos         for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    328  1.1.1.5  christos         {
    329  1.1.1.5  christos             /*
    330  1.1.1.5  christos              * Check for a table match on the entire table length,
    331  1.1.1.5  christos              * not just the header.
    332  1.1.1.5  christos              */
    333  1.1.1.5  christos             if (!AcpiTbCompareTables (&NewTableDesc, i))
    334  1.1.1.5  christos             {
    335  1.1.1.5  christos                 continue;
    336  1.1.1.5  christos             }
    337      1.1    jruoho 
    338  1.1.1.5  christos             /*
    339  1.1.1.5  christos              * Note: the current mechanism does not unregister a table if it is
    340  1.1.1.5  christos              * dynamically unloaded. The related namespace entries are deleted,
    341  1.1.1.5  christos              * but the table remains in the root table list.
    342  1.1.1.5  christos              *
    343  1.1.1.5  christos              * The assumption here is that the number of different tables that
    344  1.1.1.5  christos              * will be loaded is actually small, and there is minimal overhead
    345  1.1.1.5  christos              * in just keeping the table in case it is needed again.
    346  1.1.1.5  christos              *
    347  1.1.1.5  christos              * If this assumption changes in the future (perhaps on large
    348  1.1.1.5  christos              * machines with many table load/unload operations), tables will
    349  1.1.1.5  christos              * need to be unregistered when they are unloaded, and slots in the
    350  1.1.1.5  christos              * root table list should be reused when empty.
    351  1.1.1.5  christos              */
    352  1.1.1.5  christos             if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED)
    353  1.1.1.5  christos             {
    354  1.1.1.5  christos                 /* Table is still loaded, this is an error */
    355      1.1    jruoho 
    356  1.1.1.5  christos                 Status = AE_ALREADY_EXISTS;
    357  1.1.1.5  christos                 goto ReleaseAndExit;
    358  1.1.1.5  christos             }
    359  1.1.1.5  christos             else
    360  1.1.1.5  christos             {
    361  1.1.1.5  christos                 /*
    362  1.1.1.5  christos                  * Table was unloaded, allow it to be reloaded.
    363  1.1.1.5  christos                  * As we are going to return AE_OK to the caller, we should
    364  1.1.1.5  christos                  * take the responsibility of freeing the input descriptor.
    365  1.1.1.5  christos                  * Refill the input descriptor to ensure
    366  1.1.1.5  christos                  * AcpiTbInstallTableWithOverride() can be called again to
    367  1.1.1.5  christos                  * indicate the re-installation.
    368  1.1.1.5  christos                  */
    369  1.1.1.5  christos                 AcpiTbUninstallTable (&NewTableDesc);
    370  1.1.1.5  christos                 *TableIndex = i;
    371  1.1.1.5  christos                 return_ACPI_STATUS (AE_OK);
    372  1.1.1.5  christos             }
    373      1.1    jruoho         }
    374      1.1    jruoho     }
    375      1.1    jruoho 
    376  1.1.1.5  christos     /* Add the table to the global root table list */
    377      1.1    jruoho 
    378  1.1.1.6  christos     Status = AcpiTbGetNextTableDescriptor (&i, NULL);
    379  1.1.1.5  christos     if (ACPI_FAILURE (Status))
    380      1.1    jruoho     {
    381  1.1.1.5  christos         goto ReleaseAndExit;
    382      1.1    jruoho     }
    383      1.1    jruoho 
    384  1.1.1.5  christos     *TableIndex = i;
    385  1.1.1.5  christos     AcpiTbInstallTableWithOverride (i, &NewTableDesc, Override);
    386  1.1.1.4  christos 
    387  1.1.1.5  christos ReleaseAndExit:
    388      1.1    jruoho 
    389  1.1.1.5  christos     /* Release the temporary table descriptor */
    390      1.1    jruoho 
    391  1.1.1.5  christos     AcpiTbReleaseTempTable (&NewTableDesc);
    392  1.1.1.5  christos     return_ACPI_STATUS (Status);
    393      1.1    jruoho }
    394      1.1    jruoho 
    395      1.1    jruoho 
    396      1.1    jruoho /*******************************************************************************
    397      1.1    jruoho  *
    398  1.1.1.5  christos  * FUNCTION:    AcpiTbOverrideTable
    399      1.1    jruoho  *
    400  1.1.1.5  christos  * PARAMETERS:  OldTableDesc        - Validated table descriptor to be
    401  1.1.1.5  christos  *                                    overridden
    402      1.1    jruoho  *
    403      1.1    jruoho  * RETURN:      None
    404      1.1    jruoho  *
    405  1.1.1.5  christos  * DESCRIPTION: Attempt table override by calling the OSL override functions.
    406  1.1.1.5  christos  *              Note: If the table is overridden, then the entire new table
    407  1.1.1.5  christos  *              is acquired and returned by this function.
    408  1.1.1.5  christos  *              Before/after invocation, the table descriptor is in a state
    409  1.1.1.5  christos  *              that is "VALIDATED".
    410      1.1    jruoho  *
    411      1.1    jruoho  ******************************************************************************/
    412      1.1    jruoho 
    413      1.1    jruoho void
    414  1.1.1.5  christos AcpiTbOverrideTable (
    415  1.1.1.5  christos     ACPI_TABLE_DESC         *OldTableDesc)
    416      1.1    jruoho {
    417  1.1.1.5  christos     ACPI_STATUS             Status;
    418  1.1.1.5  christos     char                    *OverrideType;
    419  1.1.1.5  christos     ACPI_TABLE_DESC         NewTableDesc;
    420  1.1.1.5  christos     ACPI_TABLE_HEADER       *Table;
    421  1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS   Address;
    422  1.1.1.5  christos     UINT32                  Length;
    423      1.1    jruoho 
    424      1.1    jruoho 
    425  1.1.1.5  christos     /* (1) Attempt logical override (returns a logical address) */
    426      1.1    jruoho 
    427  1.1.1.5  christos     Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table);
    428  1.1.1.5  christos     if (ACPI_SUCCESS (Status) && Table)
    429      1.1    jruoho     {
    430  1.1.1.5  christos         AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table),
    431  1.1.1.5  christos             ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
    432  1.1.1.5  christos         OverrideType = "Logical";
    433  1.1.1.5  christos         goto FinishOverride;
    434      1.1    jruoho     }
    435      1.1    jruoho 
    436  1.1.1.5  christos     /* (2) Attempt physical override (returns a physical address) */
    437  1.1.1.5  christos 
    438  1.1.1.5  christos     Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer,
    439  1.1.1.5  christos         &Address, &Length);
    440  1.1.1.5  christos     if (ACPI_SUCCESS (Status) && Address && Length)
    441      1.1    jruoho     {
    442  1.1.1.5  christos         AcpiTbAcquireTempTable (&NewTableDesc, Address,
    443  1.1.1.5  christos             ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
    444  1.1.1.5  christos         OverrideType = "Physical";
    445  1.1.1.5  christos         goto FinishOverride;
    446      1.1    jruoho     }
    447      1.1    jruoho 
    448  1.1.1.5  christos     return; /* There was no override */
    449      1.1    jruoho 
    450      1.1    jruoho 
    451  1.1.1.5  christos FinishOverride:
    452      1.1    jruoho 
    453  1.1.1.5  christos     /* Validate and verify a table before overriding */
    454      1.1    jruoho 
    455  1.1.1.5  christos     Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
    456      1.1    jruoho     if (ACPI_FAILURE (Status))
    457      1.1    jruoho     {
    458  1.1.1.5  christos         return;
    459      1.1    jruoho     }
    460      1.1    jruoho 
    461  1.1.1.6  christos     ACPI_INFO ((AE_INFO, "%4.4s 0x%8.8X%8.8X"
    462  1.1.1.6  christos         " %s table override, new table: 0x%8.8X%8.8X",
    463  1.1.1.5  christos         OldTableDesc->Signature.Ascii,
    464  1.1.1.6  christos         ACPI_FORMAT_UINT64 (OldTableDesc->Address),
    465  1.1.1.6  christos         OverrideType, ACPI_FORMAT_UINT64 (NewTableDesc.Address)));
    466      1.1    jruoho 
    467  1.1.1.5  christos     /* We can now uninstall the original table */
    468      1.1    jruoho 
    469  1.1.1.5  christos     AcpiTbUninstallTable (OldTableDesc);
    470      1.1    jruoho 
    471      1.1    jruoho     /*
    472  1.1.1.5  christos      * Replace the original table descriptor and keep its state as
    473  1.1.1.5  christos      * "VALIDATED".
    474      1.1    jruoho      */
    475  1.1.1.5  christos     AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address,
    476  1.1.1.5  christos         NewTableDesc.Flags, NewTableDesc.Pointer);
    477  1.1.1.5  christos     AcpiTbValidateTempTable (OldTableDesc);
    478      1.1    jruoho 
    479  1.1.1.5  christos     /* Release the temporary table descriptor */
    480      1.1    jruoho 
    481  1.1.1.5  christos     AcpiTbReleaseTempTable (&NewTableDesc);
    482      1.1    jruoho }
    483      1.1    jruoho 
    484      1.1    jruoho 
    485      1.1    jruoho /*******************************************************************************
    486      1.1    jruoho  *
    487  1.1.1.5  christos  * FUNCTION:    AcpiTbUninstallTable
    488      1.1    jruoho  *
    489  1.1.1.5  christos  * PARAMETERS:  TableDesc           - Table descriptor
    490      1.1    jruoho  *
    491  1.1.1.5  christos  * RETURN:      None
    492      1.1    jruoho  *
    493  1.1.1.5  christos  * DESCRIPTION: Delete one internal ACPI table
    494      1.1    jruoho  *
    495      1.1    jruoho  ******************************************************************************/
    496      1.1    jruoho 
    497  1.1.1.5  christos void
    498  1.1.1.5  christos AcpiTbUninstallTable (
    499  1.1.1.5  christos     ACPI_TABLE_DESC         *TableDesc)
    500      1.1    jruoho {
    501      1.1    jruoho 
    502  1.1.1.5  christos     ACPI_FUNCTION_TRACE (TbUninstallTable);
    503      1.1    jruoho 
    504      1.1    jruoho 
    505  1.1.1.5  christos     /* Table must be installed */
    506      1.1    jruoho 
    507  1.1.1.5  christos     if (!TableDesc->Address)
    508      1.1    jruoho     {
    509  1.1.1.5  christos         return_VOID;
    510      1.1    jruoho     }
    511      1.1    jruoho 
    512  1.1.1.5  christos     AcpiTbInvalidateTable (TableDesc);
    513      1.1    jruoho 
    514  1.1.1.5  christos     if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
    515  1.1.1.5  christos         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL)
    516      1.1    jruoho     {
    517  1.1.1.6  christos         ACPI_FREE (ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
    518      1.1    jruoho     }
    519      1.1    jruoho 
    520  1.1.1.5  christos     TableDesc->Address = ACPI_PTR_TO_PHYSADDR (NULL);
    521  1.1.1.5  christos     return_VOID;
    522      1.1    jruoho }
    523