Home | History | Annotate | Line # | Download | only in tables
tbinstal.c revision 1.15.6.1
      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.2  christos /*
      8  1.15.6.1   thorpej  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.2  christos  * Redistribution and use in source and binary forms, with or without
     12       1.2  christos  * modification, are permitted provided that the following conditions
     13       1.2  christos  * are met:
     14       1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15       1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16       1.2  christos  *    without modification.
     17       1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21       1.2  christos  *    binary redistribution.
     22       1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24       1.2  christos  *    from this software without specific prior written permission.
     25       1.2  christos  *
     26       1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27       1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.2  christos  * Software Foundation.
     29       1.2  christos  *
     30       1.2  christos  * NO WARRANTY
     31       1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.15.6.1   thorpej  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42       1.2  christos  */
     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    jruoho 
     52       1.1    jruoho /*******************************************************************************
     53       1.1    jruoho  *
     54       1.3  christos  * FUNCTION:    AcpiTbInstallTableWithOverride
     55       1.1    jruoho  *
     56       1.7  christos  * PARAMETERS:  NewTableDesc            - New table descriptor to install
     57       1.3  christos  *              Override                - Whether override should be performed
     58       1.7  christos  *              TableIndex              - Where the table index is returned
     59       1.1    jruoho  *
     60       1.3  christos  * RETURN:      None
     61       1.1    jruoho  *
     62       1.3  christos  * DESCRIPTION: Install an ACPI table into the global data structure. The
     63       1.3  christos  *              table override mechanism is called to allow the host
     64       1.3  christos  *              OS to replace any table before it is installed in the root
     65       1.3  christos  *              table array.
     66       1.1    jruoho  *
     67       1.1    jruoho  ******************************************************************************/
     68       1.1    jruoho 
     69       1.3  christos void
     70       1.3  christos AcpiTbInstallTableWithOverride (
     71       1.3  christos     ACPI_TABLE_DESC         *NewTableDesc,
     72       1.7  christos     BOOLEAN                 Override,
     73       1.7  christos     UINT32                  *TableIndex)
     74       1.1    jruoho {
     75       1.7  christos     UINT32                  i;
     76       1.7  christos     ACPI_STATUS             Status;
     77       1.7  christos 
     78       1.1    jruoho 
     79       1.7  christos     Status = AcpiTbGetNextTableDescriptor (&i, NULL);
     80       1.7  christos     if (ACPI_FAILURE (Status))
     81       1.1    jruoho     {
     82       1.3  christos         return;
     83       1.1    jruoho     }
     84       1.1    jruoho 
     85       1.1    jruoho     /*
     86       1.3  christos      * ACPI Table Override:
     87       1.2  christos      *
     88       1.3  christos      * Before we install the table, let the host OS override it with a new
     89       1.3  christos      * one if desired. Any table within the RSDT/XSDT can be replaced,
     90       1.3  christos      * including the DSDT which is pointed to by the FADT.
     91       1.1    jruoho      */
     92       1.3  christos     if (Override)
     93       1.2  christos     {
     94       1.3  christos         AcpiTbOverrideTable (NewTableDesc);
     95       1.2  christos     }
     96       1.1    jruoho 
     97       1.7  christos     AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList.Tables[i],
     98       1.3  christos         NewTableDesc->Address, NewTableDesc->Flags, NewTableDesc->Pointer);
     99       1.1    jruoho 
    100       1.3  christos     AcpiTbPrintTableHeader (NewTableDesc->Address, NewTableDesc->Pointer);
    101       1.1    jruoho 
    102       1.7  christos     /* This synchronizes AcpiGbl_DsdtIndex */
    103       1.7  christos 
    104       1.7  christos     *TableIndex = i;
    105       1.7  christos 
    106       1.3  christos     /* Set the global integer width (based upon revision of the DSDT) */
    107       1.1    jruoho 
    108       1.7  christos     if (i == AcpiGbl_DsdtIndex)
    109       1.1    jruoho     {
    110       1.3  christos         AcpiUtSetIntegerWidth (NewTableDesc->Pointer->Revision);
    111       1.1    jruoho     }
    112       1.1    jruoho }
    113       1.1    jruoho 
    114       1.1    jruoho 
    115       1.1    jruoho /*******************************************************************************
    116       1.1    jruoho  *
    117       1.3  christos  * FUNCTION:    AcpiTbInstallStandardTable
    118       1.1    jruoho  *
    119       1.3  christos  * PARAMETERS:  Address             - Address of the table (might be a virtual
    120       1.3  christos  *                                    address depending on the TableFlags)
    121       1.3  christos  *              Flags               - Flags for the table
    122       1.3  christos  *              Reload              - Whether reload should be performed
    123       1.3  christos  *              Override            - Whether override should be performed
    124       1.3  christos  *              TableIndex          - Where the table index is returned
    125       1.1    jruoho  *
    126       1.1    jruoho  * RETURN:      Status
    127       1.1    jruoho  *
    128       1.9  christos  * DESCRIPTION: This function is called to verify and install an ACPI table.
    129       1.3  christos  *              When this function is called by "Load" or "LoadTable" opcodes,
    130       1.3  christos  *              or by AcpiLoadTable() API, the "Reload" parameter is set.
    131      1.13  christos  *              After successfully returning from this function, table is
    132       1.3  christos  *              "INSTALLED" but not "VALIDATED".
    133       1.1    jruoho  *
    134       1.1    jruoho  ******************************************************************************/
    135       1.1    jruoho 
    136       1.1    jruoho ACPI_STATUS
    137       1.3  christos AcpiTbInstallStandardTable (
    138       1.3  christos     ACPI_PHYSICAL_ADDRESS   Address,
    139       1.3  christos     UINT8                   Flags,
    140       1.3  christos     BOOLEAN                 Reload,
    141       1.3  christos     BOOLEAN                 Override,
    142       1.3  christos     UINT32                  *TableIndex)
    143       1.1    jruoho {
    144       1.3  christos     UINT32                  i;
    145       1.3  christos     ACPI_STATUS             Status = AE_OK;
    146       1.3  christos     ACPI_TABLE_DESC         NewTableDesc;
    147       1.1    jruoho 
    148       1.1    jruoho 
    149       1.3  christos     ACPI_FUNCTION_TRACE (TbInstallStandardTable);
    150       1.1    jruoho 
    151       1.1    jruoho 
    152       1.3  christos     /* Acquire a temporary table descriptor for validation */
    153       1.1    jruoho 
    154       1.3  christos     Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags);
    155       1.3  christos     if (ACPI_FAILURE (Status))
    156       1.1    jruoho     {
    157       1.7  christos         ACPI_ERROR ((AE_INFO,
    158       1.7  christos             "Could not acquire table length at %8.8X%8.8X",
    159       1.4  christos             ACPI_FORMAT_UINT64 (Address)));
    160       1.3  christos         return_ACPI_STATUS (Status);
    161       1.1    jruoho     }
    162       1.1    jruoho 
    163       1.3  christos     /*
    164       1.3  christos      * Optionally do not load any SSDTs from the RSDT/XSDT. This can
    165       1.3  christos      * be useful for debugging ACPI problems on some machines.
    166       1.3  christos      */
    167       1.3  christos     if (!Reload &&
    168       1.3  christos         AcpiGbl_DisableSsdtTableInstall &&
    169      1.14  christos         ACPI_COMPARE_NAMESEG (&NewTableDesc.Signature, ACPI_SIG_SSDT))
    170       1.2  christos     {
    171       1.8  christos         ACPI_INFO ((
    172       1.7  christos             "Ignoring installation of %4.4s at %8.8X%8.8X",
    173       1.4  christos             NewTableDesc.Signature.Ascii, ACPI_FORMAT_UINT64 (Address)));
    174       1.3  christos         goto ReleaseAndExit;
    175       1.2  christos     }
    176       1.3  christos 
    177      1.11  christos     /* Acquire the table lock */
    178      1.11  christos 
    179      1.11  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    180      1.11  christos 
    181       1.3  christos     /* Validate and verify a table before installation */
    182       1.3  christos 
    183      1.11  christos     Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL, &i);
    184       1.3  christos     if (ACPI_FAILURE (Status))
    185       1.2  christos     {
    186      1.11  christos         if (Status == AE_CTRL_TERMINATE)
    187       1.3  christos         {
    188       1.3  christos             /*
    189      1.11  christos              * Table was unloaded, allow it to be reloaded.
    190      1.11  christos              * As we are going to return AE_OK to the caller, we should
    191      1.11  christos              * take the responsibility of freeing the input descriptor.
    192      1.11  christos              * Refill the input descriptor to ensure
    193      1.11  christos              * AcpiTbInstallTableWithOverride() can be called again to
    194      1.11  christos              * indicate the re-installation.
    195       1.3  christos              */
    196      1.11  christos             AcpiTbUninstallTable (&NewTableDesc);
    197      1.11  christos             (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    198      1.11  christos             *TableIndex = i;
    199      1.11  christos             return_ACPI_STATUS (AE_OK);
    200       1.1    jruoho         }
    201      1.11  christos         goto UnlockAndExit;
    202       1.1    jruoho     }
    203       1.1    jruoho 
    204       1.3  christos     /* Add the table to the global root table list */
    205       1.1    jruoho 
    206       1.7  christos     AcpiTbInstallTableWithOverride (&NewTableDesc, Override, TableIndex);
    207       1.1    jruoho 
    208      1.11  christos     /* Invoke table handler */
    209      1.11  christos 
    210      1.11  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    211      1.11  christos     AcpiTbNotifyTable (ACPI_TABLE_EVENT_INSTALL, NewTableDesc.Pointer);
    212      1.11  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    213      1.11  christos 
    214      1.11  christos UnlockAndExit:
    215       1.9  christos 
    216      1.11  christos     /* Release the table lock */
    217      1.11  christos 
    218      1.11  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    219       1.9  christos 
    220       1.3  christos ReleaseAndExit:
    221       1.1    jruoho 
    222       1.3  christos     /* Release the temporary table descriptor */
    223       1.1    jruoho 
    224       1.3  christos     AcpiTbReleaseTempTable (&NewTableDesc);
    225       1.3  christos     return_ACPI_STATUS (Status);
    226       1.1    jruoho }
    227       1.1    jruoho 
    228       1.1    jruoho 
    229       1.1    jruoho /*******************************************************************************
    230       1.1    jruoho  *
    231       1.3  christos  * FUNCTION:    AcpiTbOverrideTable
    232       1.1    jruoho  *
    233       1.3  christos  * PARAMETERS:  OldTableDesc        - Validated table descriptor to be
    234       1.3  christos  *                                    overridden
    235       1.1    jruoho  *
    236       1.1    jruoho  * RETURN:      None
    237       1.1    jruoho  *
    238       1.3  christos  * DESCRIPTION: Attempt table override by calling the OSL override functions.
    239       1.3  christos  *              Note: If the table is overridden, then the entire new table
    240       1.3  christos  *              is acquired and returned by this function.
    241       1.3  christos  *              Before/after invocation, the table descriptor is in a state
    242       1.3  christos  *              that is "VALIDATED".
    243       1.1    jruoho  *
    244       1.1    jruoho  ******************************************************************************/
    245       1.1    jruoho 
    246       1.1    jruoho void
    247       1.3  christos AcpiTbOverrideTable (
    248       1.3  christos     ACPI_TABLE_DESC         *OldTableDesc)
    249       1.1    jruoho {
    250       1.3  christos     ACPI_STATUS             Status;
    251       1.3  christos     ACPI_TABLE_DESC         NewTableDesc;
    252       1.3  christos     ACPI_TABLE_HEADER       *Table;
    253       1.3  christos     ACPI_PHYSICAL_ADDRESS   Address;
    254       1.3  christos     UINT32                  Length;
    255      1.12  christos     ACPI_ERROR_ONLY (const char   *OverrideType);
    256       1.1    jruoho 
    257       1.1    jruoho 
    258       1.3  christos     /* (1) Attempt logical override (returns a logical address) */
    259       1.1    jruoho 
    260       1.3  christos     Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table);
    261       1.3  christos     if (ACPI_SUCCESS (Status) && Table)
    262       1.1    jruoho     {
    263       1.3  christos         AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table),
    264       1.3  christos             ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
    265      1.12  christos         ACPI_ERROR_ONLY (OverrideType = "Logical");
    266       1.3  christos         goto FinishOverride;
    267       1.1    jruoho     }
    268       1.1    jruoho 
    269       1.3  christos     /* (2) Attempt physical override (returns a physical address) */
    270       1.1    jruoho 
    271       1.3  christos     Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer,
    272       1.3  christos         &Address, &Length);
    273       1.3  christos     if (ACPI_SUCCESS (Status) && Address && Length)
    274       1.3  christos     {
    275       1.3  christos         AcpiTbAcquireTempTable (&NewTableDesc, Address,
    276       1.3  christos             ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
    277      1.12  christos         ACPI_ERROR_ONLY (OverrideType = "Physical");
    278       1.3  christos         goto FinishOverride;
    279       1.1    jruoho     }
    280       1.1    jruoho 
    281       1.3  christos     return; /* There was no override */
    282       1.1    jruoho 
    283       1.1    jruoho 
    284       1.3  christos FinishOverride:
    285       1.2  christos 
    286      1.11  christos     /*
    287      1.11  christos      * Validate and verify a table before overriding, no nested table
    288      1.11  christos      * duplication check as it's too complicated and unnecessary.
    289      1.11  christos      */
    290      1.11  christos     Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL, NULL);
    291       1.1    jruoho     if (ACPI_FAILURE (Status))
    292       1.1    jruoho     {
    293       1.3  christos         return;
    294       1.1    jruoho     }
    295       1.1    jruoho 
    296       1.8  christos     ACPI_INFO (("%4.4s 0x%8.8X%8.8X"
    297       1.4  christos         " %s table override, new table: 0x%8.8X%8.8X",
    298       1.3  christos         OldTableDesc->Signature.Ascii,
    299       1.4  christos         ACPI_FORMAT_UINT64 (OldTableDesc->Address),
    300       1.4  christos         OverrideType, ACPI_FORMAT_UINT64 (NewTableDesc.Address)));
    301       1.1    jruoho 
    302       1.3  christos     /* We can now uninstall the original table */
    303       1.1    jruoho 
    304       1.3  christos     AcpiTbUninstallTable (OldTableDesc);
    305       1.1    jruoho 
    306       1.1    jruoho     /*
    307       1.3  christos      * Replace the original table descriptor and keep its state as
    308       1.3  christos      * "VALIDATED".
    309       1.1    jruoho      */
    310       1.3  christos     AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address,
    311       1.3  christos         NewTableDesc.Flags, NewTableDesc.Pointer);
    312       1.3  christos     AcpiTbValidateTempTable (OldTableDesc);
    313       1.1    jruoho 
    314       1.3  christos     /* Release the temporary table descriptor */
    315       1.1    jruoho 
    316       1.3  christos     AcpiTbReleaseTempTable (&NewTableDesc);
    317       1.1    jruoho }
    318       1.1    jruoho 
    319       1.1    jruoho 
    320       1.1    jruoho /*******************************************************************************
    321       1.1    jruoho  *
    322       1.3  christos  * FUNCTION:    AcpiTbUninstallTable
    323       1.1    jruoho  *
    324       1.3  christos  * PARAMETERS:  TableDesc           - Table descriptor
    325       1.1    jruoho  *
    326       1.3  christos  * RETURN:      None
    327       1.1    jruoho  *
    328       1.3  christos  * DESCRIPTION: Delete one internal ACPI table
    329       1.1    jruoho  *
    330       1.1    jruoho  ******************************************************************************/
    331       1.1    jruoho 
    332       1.3  christos void
    333       1.3  christos AcpiTbUninstallTable (
    334       1.3  christos     ACPI_TABLE_DESC         *TableDesc)
    335       1.1    jruoho {
    336       1.1    jruoho 
    337       1.3  christos     ACPI_FUNCTION_TRACE (TbUninstallTable);
    338       1.1    jruoho 
    339       1.1    jruoho 
    340       1.3  christos     /* Table must be installed */
    341       1.1    jruoho 
    342       1.3  christos     if (!TableDesc->Address)
    343       1.1    jruoho     {
    344       1.3  christos         return_VOID;
    345       1.1    jruoho     }
    346       1.1    jruoho 
    347       1.3  christos     AcpiTbInvalidateTable (TableDesc);
    348       1.1    jruoho 
    349       1.3  christos     if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
    350       1.3  christos         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL)
    351       1.1    jruoho     {
    352       1.5  christos 	void *ptr = ACPI_PHYSADDR_TO_PTR (TableDesc->Address);
    353       1.5  christos 	if (ptr)
    354       1.5  christos 	{
    355       1.5  christos 		ACPI_FREE (ptr);
    356       1.5  christos 	}
    357       1.1    jruoho     }
    358       1.1    jruoho 
    359       1.3  christos     TableDesc->Address = ACPI_PTR_TO_PHYSADDR (NULL);
    360       1.3  christos     return_VOID;
    361       1.1    jruoho }
    362