Home | History | Annotate | Line # | Download | only in tables
tbxfload.c revision 1.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.2       mrg  * 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.3  christos #include "acevents.h"
     51  1.1  christos 
     52  1.1  christos #define _COMPONENT          ACPI_TABLES
     53  1.1  christos         ACPI_MODULE_NAME    ("tbxfload")
     54  1.1  christos 
     55  1.1  christos 
     56  1.1  christos /*******************************************************************************
     57  1.1  christos  *
     58  1.1  christos  * FUNCTION:    AcpiLoadTables
     59  1.1  christos  *
     60  1.1  christos  * PARAMETERS:  None
     61  1.1  christos  *
     62  1.1  christos  * RETURN:      Status
     63  1.1  christos  *
     64  1.1  christos  * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
     65  1.1  christos  *
     66  1.1  christos  ******************************************************************************/
     67  1.1  christos 
     68  1.1  christos ACPI_STATUS
     69  1.1  christos AcpiLoadTables (
     70  1.1  christos     void)
     71  1.1  christos {
     72  1.1  christos     ACPI_STATUS             Status;
     73  1.1  christos 
     74  1.1  christos 
     75  1.1  christos     ACPI_FUNCTION_TRACE (AcpiLoadTables);
     76  1.1  christos 
     77  1.1  christos 
     78  1.3  christos     /*
     79  1.3  christos      * Install the default operation region handlers. These are the
     80  1.3  christos      * handlers that are defined by the ACPI specification to be
     81  1.3  christos      * "always accessible" -- namely, SystemMemory, SystemIO, and
     82  1.3  christos      * PCI_Config. This also means that no _REG methods need to be
     83  1.3  christos      * run for these address spaces. We need to have these handlers
     84  1.3  christos      * installed before any AML code can be executed, especially any
     85  1.3  christos      * module-level code (11/2015).
     86  1.3  christos      * Note that we allow OSPMs to install their own region handlers
     87  1.3  christos      * between AcpiInitializeSubsystem() and AcpiLoadTables() to use
     88  1.3  christos      * their customized default region handlers.
     89  1.3  christos      */
     90  1.3  christos     Status = AcpiEvInstallRegionHandlers ();
     91  1.3  christos     if (ACPI_FAILURE (Status))
     92  1.3  christos     {
     93  1.3  christos         ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));
     94  1.3  christos         return_ACPI_STATUS (Status);
     95  1.3  christos     }
     96  1.3  christos 
     97  1.1  christos     /* Load the namespace from the tables */
     98  1.1  christos 
     99  1.1  christos     Status = AcpiTbLoadNamespace ();
    100  1.2       mrg 
    101  1.2       mrg     /* Don't let single failures abort the load */
    102  1.2       mrg 
    103  1.2       mrg     if (Status == AE_CTRL_TERMINATE)
    104  1.2       mrg     {
    105  1.2       mrg         Status = AE_OK;
    106  1.2       mrg     }
    107  1.2       mrg 
    108  1.1  christos     if (ACPI_FAILURE (Status))
    109  1.1  christos     {
    110  1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    111  1.1  christos             "While loading namespace from ACPI tables"));
    112  1.1  christos     }
    113  1.1  christos 
    114  1.3  christos     if (!AcpiGbl_GroupModuleLevelCode)
    115  1.3  christos     {
    116  1.3  christos         /*
    117  1.3  christos          * Initialize the objects that remain uninitialized. This
    118  1.3  christos          * runs the executable AML that may be part of the
    119  1.3  christos          * declaration of these objects:
    120  1.3  christos          * OperationRegions, BufferFields, Buffers, and Packages.
    121  1.3  christos          */
    122  1.3  christos         Status = AcpiNsInitializeObjects ();
    123  1.3  christos         if (ACPI_FAILURE (Status))
    124  1.3  christos         {
    125  1.3  christos             return_ACPI_STATUS (Status);
    126  1.3  christos         }
    127  1.3  christos     }
    128  1.3  christos 
    129  1.3  christos     AcpiGbl_NamespaceInitialized = TRUE;
    130  1.1  christos     return_ACPI_STATUS (Status);
    131  1.1  christos }
    132  1.1  christos 
    133  1.1  christos ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables)
    134  1.1  christos 
    135  1.1  christos 
    136  1.1  christos /*******************************************************************************
    137  1.1  christos  *
    138  1.1  christos  * FUNCTION:    AcpiTbLoadNamespace
    139  1.1  christos  *
    140  1.1  christos  * PARAMETERS:  None
    141  1.1  christos  *
    142  1.1  christos  * RETURN:      Status
    143  1.1  christos  *
    144  1.1  christos  * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
    145  1.1  christos  *              the RSDT/XSDT.
    146  1.1  christos  *
    147  1.1  christos  ******************************************************************************/
    148  1.1  christos 
    149  1.2       mrg ACPI_STATUS
    150  1.1  christos AcpiTbLoadNamespace (
    151  1.1  christos     void)
    152  1.1  christos {
    153  1.1  christos     ACPI_STATUS             Status;
    154  1.1  christos     UINT32                  i;
    155  1.1  christos     ACPI_TABLE_HEADER       *NewDsdt;
    156  1.2       mrg     ACPI_TABLE_DESC         *Table;
    157  1.2       mrg     UINT32                  TablesLoaded = 0;
    158  1.2       mrg     UINT32                  TablesFailed = 0;
    159  1.1  christos 
    160  1.1  christos 
    161  1.1  christos     ACPI_FUNCTION_TRACE (TbLoadNamespace);
    162  1.1  christos 
    163  1.1  christos 
    164  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    165  1.1  christos 
    166  1.1  christos     /*
    167  1.1  christos      * Load the namespace. The DSDT is required, but any SSDT and
    168  1.1  christos      * PSDT tables are optional. Verify the DSDT.
    169  1.1  christos      */
    170  1.2       mrg     Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];
    171  1.2       mrg 
    172  1.1  christos     if (!AcpiGbl_RootTableList.CurrentTableCount ||
    173  1.2       mrg         !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_DSDT) ||
    174  1.2       mrg          ACPI_FAILURE (AcpiTbValidateTable (Table)))
    175  1.1  christos     {
    176  1.1  christos         Status = AE_NO_ACPI_TABLES;
    177  1.1  christos         goto UnlockAndExit;
    178  1.1  christos     }
    179  1.1  christos 
    180  1.1  christos     /*
    181  1.1  christos      * Save the DSDT pointer for simple access. This is the mapped memory
    182  1.1  christos      * address. We must take care here because the address of the .Tables
    183  1.1  christos      * array can change dynamically as tables are loaded at run-time. Note:
    184  1.2       mrg      * .Pointer field is not validated until after call to AcpiTbValidateTable.
    185  1.1  christos      */
    186  1.2       mrg     AcpiGbl_DSDT = Table->Pointer;
    187  1.1  christos 
    188  1.1  christos     /*
    189  1.1  christos      * Optionally copy the entire DSDT to local memory (instead of simply
    190  1.1  christos      * mapping it.) There are some BIOSs that corrupt or replace the original
    191  1.1  christos      * DSDT, creating the need for this option. Default is FALSE, do not copy
    192  1.1  christos      * the DSDT.
    193  1.1  christos      */
    194  1.1  christos     if (AcpiGbl_CopyDsdtLocally)
    195  1.1  christos     {
    196  1.2       mrg         NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);
    197  1.1  christos         if (NewDsdt)
    198  1.1  christos         {
    199  1.1  christos             AcpiGbl_DSDT = NewDsdt;
    200  1.1  christos         }
    201  1.1  christos     }
    202  1.1  christos 
    203  1.1  christos     /*
    204  1.1  christos      * Save the original DSDT header for detection of table corruption
    205  1.1  christos      * and/or replacement of the DSDT from outside the OS.
    206  1.1  christos      */
    207  1.2       mrg     memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
    208  1.1  christos         sizeof (ACPI_TABLE_HEADER));
    209  1.1  christos 
    210  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    211  1.1  christos 
    212  1.1  christos     /* Load and parse tables */
    213  1.1  christos 
    214  1.2       mrg     Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);
    215  1.1  christos     if (ACPI_FAILURE (Status))
    216  1.1  christos     {
    217  1.2       mrg         ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));
    218  1.2       mrg         TablesFailed++;
    219  1.2       mrg     }
    220  1.2       mrg     else
    221  1.2       mrg     {
    222  1.2       mrg         TablesLoaded++;
    223  1.1  christos     }
    224  1.1  christos 
    225  1.1  christos     /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
    226  1.1  christos 
    227  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    228  1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    229  1.1  christos     {
    230  1.2       mrg         Table = &AcpiGbl_RootTableList.Tables[i];
    231  1.1  christos 
    232  1.2       mrg         if (!AcpiGbl_RootTableList.Tables[i].Address ||
    233  1.2       mrg             (!ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_SSDT) &&
    234  1.2       mrg              !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_PSDT) &&
    235  1.2       mrg              !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||
    236  1.2       mrg              ACPI_FAILURE (AcpiTbValidateTable (Table)))
    237  1.1  christos         {
    238  1.1  christos             continue;
    239  1.1  christos         }
    240  1.1  christos 
    241  1.1  christos         /* Ignore errors while loading tables, get as many as possible */
    242  1.1  christos 
    243  1.1  christos         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    244  1.2       mrg         Status =  AcpiNsLoadTable (i, AcpiGbl_RootNode);
    245  1.2       mrg         if (ACPI_FAILURE (Status))
    246  1.2       mrg         {
    247  1.2       mrg             ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",
    248  1.2       mrg                 Table->Signature.Ascii, Table->Pointer->OemTableId));
    249  1.2       mrg 
    250  1.2       mrg             TablesFailed++;
    251  1.2       mrg 
    252  1.2       mrg             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    253  1.2       mrg                 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
    254  1.2       mrg                 Table->Signature.Ascii, Table->Pointer->OemTableId));
    255  1.2       mrg         }
    256  1.2       mrg         else
    257  1.2       mrg         {
    258  1.2       mrg             TablesLoaded++;
    259  1.2       mrg         }
    260  1.2       mrg 
    261  1.1  christos         (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    262  1.1  christos     }
    263  1.1  christos 
    264  1.2       mrg     if (!TablesFailed)
    265  1.2       mrg     {
    266  1.3  christos         ACPI_INFO ((
    267  1.3  christos             "%u ACPI AML tables successfully acquired and loaded\n",
    268  1.2       mrg             TablesLoaded));
    269  1.2       mrg     }
    270  1.2       mrg     else
    271  1.2       mrg     {
    272  1.2       mrg         ACPI_ERROR ((AE_INFO,
    273  1.2       mrg             "%u table load failures, %u successful",
    274  1.2       mrg             TablesFailed, TablesLoaded));
    275  1.2       mrg 
    276  1.2       mrg         /* Indicate at least one failure */
    277  1.2       mrg 
    278  1.2       mrg         Status = AE_CTRL_TERMINATE;
    279  1.2       mrg     }
    280  1.1  christos 
    281  1.1  christos UnlockAndExit:
    282  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    283  1.1  christos     return_ACPI_STATUS (Status);
    284  1.1  christos }
    285  1.1  christos 
    286  1.1  christos 
    287  1.1  christos /*******************************************************************************
    288  1.1  christos  *
    289  1.2       mrg  * FUNCTION:    AcpiInstallTable
    290  1.2       mrg  *
    291  1.2       mrg  * PARAMETERS:  Address             - Address of the ACPI table to be installed.
    292  1.2       mrg  *              Physical            - Whether the address is a physical table
    293  1.2       mrg  *                                    address or not
    294  1.2       mrg  *
    295  1.2       mrg  * RETURN:      Status
    296  1.2       mrg  *
    297  1.2       mrg  * DESCRIPTION: Dynamically install an ACPI table.
    298  1.2       mrg  *              Note: This function should only be invoked after
    299  1.2       mrg  *                    AcpiInitializeTables() and before AcpiLoadTables().
    300  1.2       mrg  *
    301  1.2       mrg  ******************************************************************************/
    302  1.2       mrg 
    303  1.2       mrg ACPI_STATUS
    304  1.2       mrg AcpiInstallTable (
    305  1.2       mrg     ACPI_PHYSICAL_ADDRESS   Address,
    306  1.2       mrg     BOOLEAN                 Physical)
    307  1.2       mrg {
    308  1.2       mrg     ACPI_STATUS             Status;
    309  1.2       mrg     UINT8                   Flags;
    310  1.2       mrg     UINT32                  TableIndex;
    311  1.2       mrg 
    312  1.2       mrg 
    313  1.2       mrg     ACPI_FUNCTION_TRACE (AcpiInstallTable);
    314  1.2       mrg 
    315  1.2       mrg 
    316  1.2       mrg     if (Physical)
    317  1.2       mrg     {
    318  1.2       mrg         Flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
    319  1.2       mrg     }
    320  1.2       mrg     else
    321  1.2       mrg     {
    322  1.2       mrg         Flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
    323  1.2       mrg     }
    324  1.2       mrg 
    325  1.2       mrg     Status = AcpiTbInstallStandardTable (Address, Flags,
    326  1.2       mrg         FALSE, FALSE, &TableIndex);
    327  1.2       mrg 
    328  1.2       mrg     return_ACPI_STATUS (Status);
    329  1.2       mrg }
    330  1.2       mrg 
    331  1.2       mrg ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable)
    332  1.2       mrg 
    333  1.2       mrg 
    334  1.2       mrg /*******************************************************************************
    335  1.2       mrg  *
    336  1.1  christos  * FUNCTION:    AcpiLoadTable
    337  1.1  christos  *
    338  1.1  christos  * PARAMETERS:  Table               - Pointer to a buffer containing the ACPI
    339  1.1  christos  *                                    table to be loaded.
    340  1.1  christos  *
    341  1.1  christos  * RETURN:      Status
    342  1.1  christos  *
    343  1.1  christos  * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
    344  1.1  christos  *              be a valid ACPI table with a valid ACPI table header.
    345  1.1  christos  *              Note1: Mainly intended to support hotplug addition of SSDTs.
    346  1.1  christos  *              Note2: Does not copy the incoming table. User is responsible
    347  1.1  christos  *              to ensure that the table is not deleted or unmapped.
    348  1.1  christos  *
    349  1.1  christos  ******************************************************************************/
    350  1.1  christos 
    351  1.1  christos ACPI_STATUS
    352  1.1  christos AcpiLoadTable (
    353  1.1  christos     ACPI_TABLE_HEADER       *Table)
    354  1.1  christos {
    355  1.1  christos     ACPI_STATUS             Status;
    356  1.1  christos     UINT32                  TableIndex;
    357  1.1  christos 
    358  1.1  christos 
    359  1.1  christos     ACPI_FUNCTION_TRACE (AcpiLoadTable);
    360  1.1  christos 
    361  1.1  christos 
    362  1.1  christos     /* Parameter validation */
    363  1.1  christos 
    364  1.1  christos     if (!Table)
    365  1.1  christos     {
    366  1.1  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    367  1.1  christos     }
    368  1.1  christos 
    369  1.1  christos     /* Must acquire the interpreter lock during this operation */
    370  1.1  christos 
    371  1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
    372  1.1  christos     if (ACPI_FAILURE (Status))
    373  1.1  christos     {
    374  1.1  christos         return_ACPI_STATUS (Status);
    375  1.1  christos     }
    376  1.1  christos 
    377  1.1  christos     /* Install the table and load it into the namespace */
    378  1.1  christos 
    379  1.3  christos     ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
    380  1.2       mrg     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    381  1.2       mrg 
    382  1.2       mrg     Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
    383  1.2       mrg         ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, TRUE, FALSE,
    384  1.2       mrg         &TableIndex);
    385  1.2       mrg 
    386  1.2       mrg     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    387  1.2       mrg     if (ACPI_FAILURE (Status))
    388  1.2       mrg     {
    389  1.2       mrg         goto UnlockAndExit;
    390  1.2       mrg     }
    391  1.2       mrg 
    392  1.2       mrg     /*
    393  1.2       mrg      * Note: Now table is "INSTALLED", it must be validated before
    394  1.2       mrg      * using.
    395  1.2       mrg      */
    396  1.2       mrg     Status = AcpiTbValidateTable (
    397  1.2       mrg         &AcpiGbl_RootTableList.Tables[TableIndex]);
    398  1.1  christos     if (ACPI_FAILURE (Status))
    399  1.1  christos     {
    400  1.1  christos         goto UnlockAndExit;
    401  1.1  christos     }
    402  1.1  christos 
    403  1.1  christos     Status = AcpiNsLoadTable (TableIndex, AcpiGbl_RootNode);
    404  1.1  christos 
    405  1.1  christos     /* Invoke table handler if present */
    406  1.1  christos 
    407  1.1  christos     if (AcpiGbl_TableHandler)
    408  1.1  christos     {
    409  1.1  christos         (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
    410  1.2       mrg             AcpiGbl_TableHandlerContext);
    411  1.1  christos     }
    412  1.1  christos 
    413  1.1  christos UnlockAndExit:
    414  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
    415  1.1  christos     return_ACPI_STATUS (Status);
    416  1.1  christos }
    417  1.1  christos 
    418  1.1  christos ACPI_EXPORT_SYMBOL (AcpiLoadTable)
    419  1.1  christos 
    420  1.1  christos 
    421  1.1  christos /*******************************************************************************
    422  1.1  christos  *
    423  1.1  christos  * FUNCTION:    AcpiUnloadParentTable
    424  1.1  christos  *
    425  1.1  christos  * PARAMETERS:  Object              - Handle to any namespace object owned by
    426  1.1  christos  *                                    the table to be unloaded
    427  1.1  christos  *
    428  1.1  christos  * RETURN:      Status
    429  1.1  christos  *
    430  1.1  christos  * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
    431  1.1  christos  *              the table and deletes all namespace objects associated with
    432  1.1  christos  *              that table. Unloading of the DSDT is not allowed.
    433  1.1  christos  *              Note: Mainly intended to support hotplug removal of SSDTs.
    434  1.1  christos  *
    435  1.1  christos  ******************************************************************************/
    436  1.1  christos 
    437  1.1  christos ACPI_STATUS
    438  1.1  christos AcpiUnloadParentTable (
    439  1.1  christos     ACPI_HANDLE             Object)
    440  1.1  christos {
    441  1.1  christos     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);
    442  1.1  christos     ACPI_STATUS             Status = AE_NOT_EXIST;
    443  1.1  christos     ACPI_OWNER_ID           OwnerId;
    444  1.1  christos     UINT32                  i;
    445  1.1  christos 
    446  1.1  christos 
    447  1.1  christos     ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);
    448  1.1  christos 
    449  1.1  christos 
    450  1.1  christos     /* Parameter validation */
    451  1.1  christos 
    452  1.1  christos     if (!Object)
    453  1.1  christos     {
    454  1.1  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    455  1.1  christos     }
    456  1.1  christos 
    457  1.1  christos     /*
    458  1.1  christos      * The node OwnerId is currently the same as the parent table ID.
    459  1.1  christos      * However, this could change in the future.
    460  1.1  christos      */
    461  1.1  christos     OwnerId = Node->OwnerId;
    462  1.1  christos     if (!OwnerId)
    463  1.1  christos     {
    464  1.1  christos         /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
    465  1.1  christos 
    466  1.1  christos         return_ACPI_STATUS (AE_TYPE);
    467  1.1  christos     }
    468  1.1  christos 
    469  1.1  christos     /* Must acquire the interpreter lock during this operation */
    470  1.1  christos 
    471  1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
    472  1.1  christos     if (ACPI_FAILURE (Status))
    473  1.1  christos     {
    474  1.1  christos         return_ACPI_STATUS (Status);
    475  1.1  christos     }
    476  1.1  christos 
    477  1.1  christos     /* Find the table in the global table list */
    478  1.1  christos 
    479  1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    480  1.1  christos     {
    481  1.1  christos         if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
    482  1.1  christos         {
    483  1.1  christos             continue;
    484  1.1  christos         }
    485  1.1  christos 
    486  1.1  christos         /*
    487  1.1  christos          * Allow unload of SSDT and OEMx tables only. Do not allow unload
    488  1.1  christos          * of the DSDT. No other types of tables should get here, since
    489  1.1  christos          * only these types can contain AML and thus are the only types
    490  1.1  christos          * that can create namespace objects.
    491  1.1  christos          */
    492  1.1  christos         if (ACPI_COMPARE_NAME (
    493  1.2       mrg                 AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
    494  1.2       mrg                 ACPI_SIG_DSDT))
    495  1.1  christos         {
    496  1.1  christos             Status = AE_TYPE;
    497  1.1  christos             break;
    498  1.1  christos         }
    499  1.1  christos 
    500  1.1  christos         /* Ensure the table is actually loaded */
    501  1.1  christos 
    502  1.1  christos         if (!AcpiTbIsTableLoaded (i))
    503  1.1  christos         {
    504  1.1  christos             Status = AE_NOT_EXIST;
    505  1.1  christos             break;
    506  1.1  christos         }
    507  1.1  christos 
    508  1.1  christos         /* Invoke table handler if present */
    509  1.1  christos 
    510  1.1  christos         if (AcpiGbl_TableHandler)
    511  1.1  christos         {
    512  1.1  christos             (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD,
    513  1.2       mrg                 AcpiGbl_RootTableList.Tables[i].Pointer,
    514  1.2       mrg                 AcpiGbl_TableHandlerContext);
    515  1.1  christos         }
    516  1.1  christos 
    517  1.1  christos         /*
    518  1.1  christos          * Delete all namespace objects owned by this table. Note that
    519  1.1  christos          * these objects can appear anywhere in the namespace by virtue
    520  1.1  christos          * of the AML "Scope" operator. Thus, we need to track ownership
    521  1.1  christos          * by an ID, not simply a position within the hierarchy.
    522  1.1  christos          */
    523  1.1  christos         Status = AcpiTbDeleteNamespaceByOwner (i);
    524  1.1  christos         if (ACPI_FAILURE (Status))
    525  1.1  christos         {
    526  1.1  christos             break;
    527  1.1  christos         }
    528  1.1  christos 
    529  1.1  christos         Status = AcpiTbReleaseOwnerId (i);
    530  1.1  christos         AcpiTbSetTableLoadedFlag (i, FALSE);
    531  1.1  christos         break;
    532  1.1  christos     }
    533  1.1  christos 
    534  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
    535  1.1  christos     return_ACPI_STATUS (Status);
    536  1.1  christos }
    537  1.1  christos 
    538  1.1  christos ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)
    539