Home | History | Annotate | Line # | Download | only in tables
tbxfload.c revision 1.1.1.2.2.3
      1          1.1  christos /******************************************************************************
      2          1.1  christos  *
      3          1.1  christos  * Module Name: tbxfload - Table load/unload external interfaces
      4          1.1  christos  *
      5          1.1  christos  *****************************************************************************/
      6          1.1  christos 
      7          1.1  christos /*
      8  1.1.1.2.2.3     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1  christos  * All rights reserved.
     10          1.1  christos  *
     11          1.1  christos  * Redistribution and use in source and binary forms, with or without
     12          1.1  christos  * modification, are permitted provided that the following conditions
     13          1.1  christos  * are met:
     14          1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15          1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16          1.1  christos  *    without modification.
     17          1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18          1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19          1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20          1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21          1.1  christos  *    binary redistribution.
     22          1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23          1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24          1.1  christos  *    from this software without specific prior written permission.
     25          1.1  christos  *
     26          1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27          1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28          1.1  christos  * Software Foundation.
     29          1.1  christos  *
     30          1.1  christos  * NO WARRANTY
     31          1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32          1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33          1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34          1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35          1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36          1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37          1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38          1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39          1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40          1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41          1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42          1.1  christos  */
     43          1.1  christos 
     44          1.1  christos #define EXPORT_ACPI_INTERFACES
     45          1.1  christos 
     46          1.1  christos #include "acpi.h"
     47          1.1  christos #include "accommon.h"
     48          1.1  christos #include "acnamesp.h"
     49          1.1  christos #include "actables.h"
     50          1.1  christos 
     51          1.1  christos #define _COMPONENT          ACPI_TABLES
     52          1.1  christos         ACPI_MODULE_NAME    ("tbxfload")
     53          1.1  christos 
     54          1.1  christos 
     55          1.1  christos /*******************************************************************************
     56          1.1  christos  *
     57          1.1  christos  * FUNCTION:    AcpiLoadTables
     58          1.1  christos  *
     59          1.1  christos  * PARAMETERS:  None
     60          1.1  christos  *
     61          1.1  christos  * RETURN:      Status
     62          1.1  christos  *
     63          1.1  christos  * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
     64          1.1  christos  *
     65          1.1  christos  ******************************************************************************/
     66          1.1  christos 
     67          1.1  christos ACPI_STATUS
     68          1.1  christos AcpiLoadTables (
     69          1.1  christos     void)
     70          1.1  christos {
     71          1.1  christos     ACPI_STATUS             Status;
     72          1.1  christos 
     73          1.1  christos 
     74          1.1  christos     ACPI_FUNCTION_TRACE (AcpiLoadTables);
     75          1.1  christos 
     76          1.1  christos 
     77          1.1  christos     /* Load the namespace from the tables */
     78          1.1  christos 
     79          1.1  christos     Status = AcpiTbLoadNamespace ();
     80  1.1.1.2.2.3     skrll 
     81  1.1.1.2.2.3     skrll     /* Don't let single failures abort the load */
     82  1.1.1.2.2.3     skrll 
     83  1.1.1.2.2.3     skrll     if (Status == AE_CTRL_TERMINATE)
     84  1.1.1.2.2.3     skrll     {
     85  1.1.1.2.2.3     skrll         Status = AE_OK;
     86  1.1.1.2.2.3     skrll     }
     87  1.1.1.2.2.3     skrll 
     88          1.1  christos     if (ACPI_FAILURE (Status))
     89          1.1  christos     {
     90          1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
     91          1.1  christos             "While loading namespace from ACPI tables"));
     92          1.1  christos     }
     93          1.1  christos 
     94          1.1  christos     return_ACPI_STATUS (Status);
     95          1.1  christos }
     96          1.1  christos 
     97          1.1  christos ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables)
     98          1.1  christos 
     99          1.1  christos 
    100          1.1  christos /*******************************************************************************
    101          1.1  christos  *
    102          1.1  christos  * FUNCTION:    AcpiTbLoadNamespace
    103          1.1  christos  *
    104          1.1  christos  * PARAMETERS:  None
    105          1.1  christos  *
    106          1.1  christos  * RETURN:      Status
    107          1.1  christos  *
    108          1.1  christos  * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
    109          1.1  christos  *              the RSDT/XSDT.
    110          1.1  christos  *
    111          1.1  christos  ******************************************************************************/
    112          1.1  christos 
    113  1.1.1.2.2.3     skrll ACPI_STATUS
    114          1.1  christos AcpiTbLoadNamespace (
    115          1.1  christos     void)
    116          1.1  christos {
    117          1.1  christos     ACPI_STATUS             Status;
    118          1.1  christos     UINT32                  i;
    119          1.1  christos     ACPI_TABLE_HEADER       *NewDsdt;
    120  1.1.1.2.2.3     skrll     ACPI_TABLE_DESC         *Table;
    121  1.1.1.2.2.3     skrll     UINT32                  TablesLoaded = 0;
    122  1.1.1.2.2.3     skrll     UINT32                  TablesFailed = 0;
    123          1.1  christos 
    124          1.1  christos 
    125          1.1  christos     ACPI_FUNCTION_TRACE (TbLoadNamespace);
    126          1.1  christos 
    127          1.1  christos 
    128          1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    129          1.1  christos 
    130          1.1  christos     /*
    131          1.1  christos      * Load the namespace. The DSDT is required, but any SSDT and
    132          1.1  christos      * PSDT tables are optional. Verify the DSDT.
    133          1.1  christos      */
    134  1.1.1.2.2.3     skrll     Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];
    135  1.1.1.2.2.3     skrll 
    136          1.1  christos     if (!AcpiGbl_RootTableList.CurrentTableCount ||
    137  1.1.1.2.2.3     skrll         !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_DSDT) ||
    138  1.1.1.2.2.3     skrll          ACPI_FAILURE (AcpiTbValidateTable (Table)))
    139          1.1  christos     {
    140          1.1  christos         Status = AE_NO_ACPI_TABLES;
    141          1.1  christos         goto UnlockAndExit;
    142          1.1  christos     }
    143          1.1  christos 
    144          1.1  christos     /*
    145          1.1  christos      * Save the DSDT pointer for simple access. This is the mapped memory
    146          1.1  christos      * address. We must take care here because the address of the .Tables
    147          1.1  christos      * array can change dynamically as tables are loaded at run-time. Note:
    148      1.1.1.2  christos      * .Pointer field is not validated until after call to AcpiTbValidateTable.
    149          1.1  christos      */
    150  1.1.1.2.2.3     skrll     AcpiGbl_DSDT = Table->Pointer;
    151          1.1  christos 
    152          1.1  christos     /*
    153          1.1  christos      * Optionally copy the entire DSDT to local memory (instead of simply
    154          1.1  christos      * mapping it.) There are some BIOSs that corrupt or replace the original
    155          1.1  christos      * DSDT, creating the need for this option. Default is FALSE, do not copy
    156          1.1  christos      * the DSDT.
    157          1.1  christos      */
    158          1.1  christos     if (AcpiGbl_CopyDsdtLocally)
    159          1.1  christos     {
    160  1.1.1.2.2.3     skrll         NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);
    161          1.1  christos         if (NewDsdt)
    162          1.1  christos         {
    163          1.1  christos             AcpiGbl_DSDT = NewDsdt;
    164          1.1  christos         }
    165          1.1  christos     }
    166          1.1  christos 
    167          1.1  christos     /*
    168          1.1  christos      * Save the original DSDT header for detection of table corruption
    169          1.1  christos      * and/or replacement of the DSDT from outside the OS.
    170          1.1  christos      */
    171  1.1.1.2.2.2     skrll     memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
    172          1.1  christos         sizeof (ACPI_TABLE_HEADER));
    173          1.1  christos 
    174          1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    175          1.1  christos 
    176          1.1  christos     /* Load and parse tables */
    177          1.1  christos 
    178  1.1.1.2.2.3     skrll     Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);
    179          1.1  christos     if (ACPI_FAILURE (Status))
    180          1.1  christos     {
    181  1.1.1.2.2.3     skrll         ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));
    182  1.1.1.2.2.3     skrll         TablesFailed++;
    183  1.1.1.2.2.3     skrll     }
    184  1.1.1.2.2.3     skrll     else
    185  1.1.1.2.2.3     skrll     {
    186  1.1.1.2.2.3     skrll         TablesLoaded++;
    187          1.1  christos     }
    188          1.1  christos 
    189          1.1  christos     /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
    190          1.1  christos 
    191          1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    192          1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    193          1.1  christos     {
    194  1.1.1.2.2.3     skrll         Table = &AcpiGbl_RootTableList.Tables[i];
    195  1.1.1.2.2.3     skrll 
    196  1.1.1.2.2.2     skrll         if (!AcpiGbl_RootTableList.Tables[i].Address ||
    197  1.1.1.2.2.3     skrll             (!ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_SSDT) &&
    198  1.1.1.2.2.3     skrll              !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_PSDT) &&
    199  1.1.1.2.2.3     skrll              !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||
    200  1.1.1.2.2.3     skrll              ACPI_FAILURE (AcpiTbValidateTable (Table)))
    201          1.1  christos         {
    202          1.1  christos             continue;
    203          1.1  christos         }
    204          1.1  christos 
    205          1.1  christos         /* Ignore errors while loading tables, get as many as possible */
    206          1.1  christos 
    207          1.1  christos         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    208  1.1.1.2.2.3     skrll         Status =  AcpiNsLoadTable (i, AcpiGbl_RootNode);
    209  1.1.1.2.2.3     skrll         if (ACPI_FAILURE (Status))
    210  1.1.1.2.2.3     skrll         {
    211  1.1.1.2.2.3     skrll             ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",
    212  1.1.1.2.2.3     skrll                 Table->Signature.Ascii, Table->Pointer->OemTableId));
    213  1.1.1.2.2.3     skrll 
    214  1.1.1.2.2.3     skrll             TablesFailed++;
    215  1.1.1.2.2.3     skrll 
    216  1.1.1.2.2.3     skrll             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    217  1.1.1.2.2.3     skrll                 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
    218  1.1.1.2.2.3     skrll                 Table->Signature.Ascii, Table->Pointer->OemTableId));
    219  1.1.1.2.2.3     skrll         }
    220  1.1.1.2.2.3     skrll         else
    221  1.1.1.2.2.3     skrll         {
    222  1.1.1.2.2.3     skrll             TablesLoaded++;
    223  1.1.1.2.2.3     skrll         }
    224  1.1.1.2.2.3     skrll 
    225          1.1  christos         (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    226          1.1  christos     }
    227          1.1  christos 
    228  1.1.1.2.2.3     skrll     if (!TablesFailed)
    229  1.1.1.2.2.3     skrll     {
    230  1.1.1.2.2.3     skrll         ACPI_INFO ((AE_INFO,
    231  1.1.1.2.2.3     skrll             "%u ACPI AML tables successfully acquired and loaded",
    232  1.1.1.2.2.3     skrll             TablesLoaded));
    233  1.1.1.2.2.3     skrll     }
    234  1.1.1.2.2.3     skrll     else
    235  1.1.1.2.2.3     skrll     {
    236  1.1.1.2.2.3     skrll         ACPI_ERROR ((AE_INFO,
    237  1.1.1.2.2.3     skrll             "%u table load failures, %u successful",
    238  1.1.1.2.2.3     skrll             TablesFailed, TablesLoaded));
    239  1.1.1.2.2.3     skrll 
    240  1.1.1.2.2.3     skrll         /* Indicate at least one failure */
    241  1.1.1.2.2.3     skrll 
    242  1.1.1.2.2.3     skrll         Status = AE_CTRL_TERMINATE;
    243  1.1.1.2.2.3     skrll     }
    244          1.1  christos 
    245          1.1  christos UnlockAndExit:
    246          1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    247          1.1  christos     return_ACPI_STATUS (Status);
    248          1.1  christos }
    249          1.1  christos 
    250          1.1  christos 
    251          1.1  christos /*******************************************************************************
    252          1.1  christos  *
    253      1.1.1.2  christos  * FUNCTION:    AcpiInstallTable
    254      1.1.1.2  christos  *
    255      1.1.1.2  christos  * PARAMETERS:  Address             - Address of the ACPI table to be installed.
    256      1.1.1.2  christos  *              Physical            - Whether the address is a physical table
    257      1.1.1.2  christos  *                                    address or not
    258      1.1.1.2  christos  *
    259      1.1.1.2  christos  * RETURN:      Status
    260      1.1.1.2  christos  *
    261      1.1.1.2  christos  * DESCRIPTION: Dynamically install an ACPI table.
    262      1.1.1.2  christos  *              Note: This function should only be invoked after
    263      1.1.1.2  christos  *                    AcpiInitializeTables() and before AcpiLoadTables().
    264      1.1.1.2  christos  *
    265      1.1.1.2  christos  ******************************************************************************/
    266      1.1.1.2  christos 
    267      1.1.1.2  christos ACPI_STATUS
    268      1.1.1.2  christos AcpiInstallTable (
    269      1.1.1.2  christos     ACPI_PHYSICAL_ADDRESS   Address,
    270      1.1.1.2  christos     BOOLEAN                 Physical)
    271      1.1.1.2  christos {
    272      1.1.1.2  christos     ACPI_STATUS             Status;
    273      1.1.1.2  christos     UINT8                   Flags;
    274      1.1.1.2  christos     UINT32                  TableIndex;
    275      1.1.1.2  christos 
    276      1.1.1.2  christos 
    277      1.1.1.2  christos     ACPI_FUNCTION_TRACE (AcpiInstallTable);
    278      1.1.1.2  christos 
    279      1.1.1.2  christos 
    280      1.1.1.2  christos     if (Physical)
    281      1.1.1.2  christos     {
    282  1.1.1.2.2.2     skrll         Flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
    283      1.1.1.2  christos     }
    284      1.1.1.2  christos     else
    285      1.1.1.2  christos     {
    286  1.1.1.2.2.2     skrll         Flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
    287      1.1.1.2  christos     }
    288      1.1.1.2  christos 
    289      1.1.1.2  christos     Status = AcpiTbInstallStandardTable (Address, Flags,
    290      1.1.1.2  christos         FALSE, FALSE, &TableIndex);
    291      1.1.1.2  christos 
    292      1.1.1.2  christos     return_ACPI_STATUS (Status);
    293      1.1.1.2  christos }
    294      1.1.1.2  christos 
    295      1.1.1.2  christos ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable)
    296      1.1.1.2  christos 
    297      1.1.1.2  christos 
    298      1.1.1.2  christos /*******************************************************************************
    299      1.1.1.2  christos  *
    300          1.1  christos  * FUNCTION:    AcpiLoadTable
    301          1.1  christos  *
    302          1.1  christos  * PARAMETERS:  Table               - Pointer to a buffer containing the ACPI
    303          1.1  christos  *                                    table to be loaded.
    304          1.1  christos  *
    305          1.1  christos  * RETURN:      Status
    306          1.1  christos  *
    307          1.1  christos  * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
    308          1.1  christos  *              be a valid ACPI table with a valid ACPI table header.
    309          1.1  christos  *              Note1: Mainly intended to support hotplug addition of SSDTs.
    310          1.1  christos  *              Note2: Does not copy the incoming table. User is responsible
    311          1.1  christos  *              to ensure that the table is not deleted or unmapped.
    312          1.1  christos  *
    313          1.1  christos  ******************************************************************************/
    314          1.1  christos 
    315          1.1  christos ACPI_STATUS
    316          1.1  christos AcpiLoadTable (
    317          1.1  christos     ACPI_TABLE_HEADER       *Table)
    318          1.1  christos {
    319          1.1  christos     ACPI_STATUS             Status;
    320          1.1  christos     UINT32                  TableIndex;
    321          1.1  christos 
    322          1.1  christos 
    323          1.1  christos     ACPI_FUNCTION_TRACE (AcpiLoadTable);
    324          1.1  christos 
    325          1.1  christos 
    326          1.1  christos     /* Parameter validation */
    327          1.1  christos 
    328          1.1  christos     if (!Table)
    329          1.1  christos     {
    330          1.1  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    331          1.1  christos     }
    332          1.1  christos 
    333          1.1  christos     /* Must acquire the interpreter lock during this operation */
    334          1.1  christos 
    335          1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
    336          1.1  christos     if (ACPI_FAILURE (Status))
    337          1.1  christos     {
    338          1.1  christos         return_ACPI_STATUS (Status);
    339          1.1  christos     }
    340          1.1  christos 
    341          1.1  christos     /* Install the table and load it into the namespace */
    342          1.1  christos 
    343          1.1  christos     ACPI_INFO ((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
    344      1.1.1.2  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    345      1.1.1.2  christos 
    346      1.1.1.2  christos     Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
    347  1.1.1.2.2.3     skrll         ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, TRUE, FALSE,
    348  1.1.1.2.2.3     skrll         &TableIndex);
    349      1.1.1.2  christos 
    350      1.1.1.2  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    351      1.1.1.2  christos     if (ACPI_FAILURE (Status))
    352      1.1.1.2  christos     {
    353      1.1.1.2  christos         goto UnlockAndExit;
    354      1.1.1.2  christos     }
    355      1.1.1.2  christos 
    356      1.1.1.2  christos     /*
    357      1.1.1.2  christos      * Note: Now table is "INSTALLED", it must be validated before
    358      1.1.1.2  christos      * using.
    359      1.1.1.2  christos      */
    360  1.1.1.2.2.3     skrll     Status = AcpiTbValidateTable (
    361  1.1.1.2.2.3     skrll         &AcpiGbl_RootTableList.Tables[TableIndex]);
    362          1.1  christos     if (ACPI_FAILURE (Status))
    363          1.1  christos     {
    364          1.1  christos         goto UnlockAndExit;
    365          1.1  christos     }
    366          1.1  christos 
    367          1.1  christos     Status = AcpiNsLoadTable (TableIndex, AcpiGbl_RootNode);
    368          1.1  christos 
    369          1.1  christos     /* Invoke table handler if present */
    370          1.1  christos 
    371          1.1  christos     if (AcpiGbl_TableHandler)
    372          1.1  christos     {
    373          1.1  christos         (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
    374  1.1.1.2.2.3     skrll             AcpiGbl_TableHandlerContext);
    375          1.1  christos     }
    376          1.1  christos 
    377          1.1  christos UnlockAndExit:
    378          1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
    379          1.1  christos     return_ACPI_STATUS (Status);
    380          1.1  christos }
    381          1.1  christos 
    382          1.1  christos ACPI_EXPORT_SYMBOL (AcpiLoadTable)
    383          1.1  christos 
    384          1.1  christos 
    385          1.1  christos /*******************************************************************************
    386          1.1  christos  *
    387          1.1  christos  * FUNCTION:    AcpiUnloadParentTable
    388          1.1  christos  *
    389          1.1  christos  * PARAMETERS:  Object              - Handle to any namespace object owned by
    390          1.1  christos  *                                    the table to be unloaded
    391          1.1  christos  *
    392          1.1  christos  * RETURN:      Status
    393          1.1  christos  *
    394          1.1  christos  * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
    395          1.1  christos  *              the table and deletes all namespace objects associated with
    396          1.1  christos  *              that table. Unloading of the DSDT is not allowed.
    397          1.1  christos  *              Note: Mainly intended to support hotplug removal of SSDTs.
    398          1.1  christos  *
    399          1.1  christos  ******************************************************************************/
    400          1.1  christos 
    401          1.1  christos ACPI_STATUS
    402          1.1  christos AcpiUnloadParentTable (
    403          1.1  christos     ACPI_HANDLE             Object)
    404          1.1  christos {
    405          1.1  christos     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);
    406          1.1  christos     ACPI_STATUS             Status = AE_NOT_EXIST;
    407          1.1  christos     ACPI_OWNER_ID           OwnerId;
    408          1.1  christos     UINT32                  i;
    409          1.1  christos 
    410          1.1  christos 
    411          1.1  christos     ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);
    412          1.1  christos 
    413          1.1  christos 
    414          1.1  christos     /* Parameter validation */
    415          1.1  christos 
    416          1.1  christos     if (!Object)
    417          1.1  christos     {
    418          1.1  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    419          1.1  christos     }
    420          1.1  christos 
    421          1.1  christos     /*
    422          1.1  christos      * The node OwnerId is currently the same as the parent table ID.
    423          1.1  christos      * However, this could change in the future.
    424          1.1  christos      */
    425          1.1  christos     OwnerId = Node->OwnerId;
    426          1.1  christos     if (!OwnerId)
    427          1.1  christos     {
    428          1.1  christos         /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
    429          1.1  christos 
    430          1.1  christos         return_ACPI_STATUS (AE_TYPE);
    431          1.1  christos     }
    432          1.1  christos 
    433          1.1  christos     /* Must acquire the interpreter lock during this operation */
    434          1.1  christos 
    435          1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
    436          1.1  christos     if (ACPI_FAILURE (Status))
    437          1.1  christos     {
    438          1.1  christos         return_ACPI_STATUS (Status);
    439          1.1  christos     }
    440          1.1  christos 
    441          1.1  christos     /* Find the table in the global table list */
    442          1.1  christos 
    443          1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    444          1.1  christos     {
    445          1.1  christos         if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
    446          1.1  christos         {
    447          1.1  christos             continue;
    448          1.1  christos         }
    449          1.1  christos 
    450          1.1  christos         /*
    451          1.1  christos          * Allow unload of SSDT and OEMx tables only. Do not allow unload
    452          1.1  christos          * of the DSDT. No other types of tables should get here, since
    453          1.1  christos          * only these types can contain AML and thus are the only types
    454          1.1  christos          * that can create namespace objects.
    455          1.1  christos          */
    456          1.1  christos         if (ACPI_COMPARE_NAME (
    457  1.1.1.2.2.3     skrll                 AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
    458  1.1.1.2.2.3     skrll                 ACPI_SIG_DSDT))
    459          1.1  christos         {
    460          1.1  christos             Status = AE_TYPE;
    461          1.1  christos             break;
    462          1.1  christos         }
    463          1.1  christos 
    464          1.1  christos         /* Ensure the table is actually loaded */
    465          1.1  christos 
    466          1.1  christos         if (!AcpiTbIsTableLoaded (i))
    467          1.1  christos         {
    468          1.1  christos             Status = AE_NOT_EXIST;
    469          1.1  christos             break;
    470          1.1  christos         }
    471          1.1  christos 
    472          1.1  christos         /* Invoke table handler if present */
    473          1.1  christos 
    474          1.1  christos         if (AcpiGbl_TableHandler)
    475          1.1  christos         {
    476          1.1  christos             (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD,
    477  1.1.1.2.2.3     skrll                 AcpiGbl_RootTableList.Tables[i].Pointer,
    478  1.1.1.2.2.3     skrll                 AcpiGbl_TableHandlerContext);
    479          1.1  christos         }
    480          1.1  christos 
    481          1.1  christos         /*
    482          1.1  christos          * Delete all namespace objects owned by this table. Note that
    483          1.1  christos          * these objects can appear anywhere in the namespace by virtue
    484          1.1  christos          * of the AML "Scope" operator. Thus, we need to track ownership
    485          1.1  christos          * by an ID, not simply a position within the hierarchy.
    486          1.1  christos          */
    487          1.1  christos         Status = AcpiTbDeleteNamespaceByOwner (i);
    488          1.1  christos         if (ACPI_FAILURE (Status))
    489          1.1  christos         {
    490          1.1  christos             break;
    491          1.1  christos         }
    492          1.1  christos 
    493          1.1  christos         Status = AcpiTbReleaseOwnerId (i);
    494          1.1  christos         AcpiTbSetTableLoadedFlag (i, FALSE);
    495          1.1  christos         break;
    496          1.1  christos     }
    497          1.1  christos 
    498          1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
    499          1.1  christos     return_ACPI_STATUS (Status);
    500          1.1  christos }
    501          1.1  christos 
    502          1.1  christos ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)
    503