Home | History | Annotate | Line # | Download | only in tables
tbdata.c revision 1.8
      1  1.1  christos /******************************************************************************
      2  1.1  christos  *
      3  1.1  christos  * Module Name: tbdata - Table manager data structure functions
      4  1.1  christos  *
      5  1.1  christos  *****************************************************************************/
      6  1.1  christos 
      7  1.1  christos /*
      8  1.8  christos  * Copyright (C) 2000 - 2017, 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 #include "acpi.h"
     45  1.1  christos #include "accommon.h"
     46  1.1  christos #include "acnamesp.h"
     47  1.1  christos #include "actables.h"
     48  1.7  christos #include "acevents.h"
     49  1.1  christos 
     50  1.1  christos #define _COMPONENT          ACPI_TABLES
     51  1.1  christos         ACPI_MODULE_NAME    ("tbdata")
     52  1.1  christos 
     53  1.1  christos 
     54  1.1  christos /*******************************************************************************
     55  1.1  christos  *
     56  1.1  christos  * FUNCTION:    AcpiTbInitTableDescriptor
     57  1.1  christos  *
     58  1.1  christos  * PARAMETERS:  TableDesc               - Table descriptor
     59  1.1  christos  *              Address                 - Physical address of the table
     60  1.1  christos  *              Flags                   - Allocation flags of the table
     61  1.1  christos  *              Table                   - Pointer to the table
     62  1.1  christos  *
     63  1.1  christos  * RETURN:      None
     64  1.1  christos  *
     65  1.1  christos  * DESCRIPTION: Initialize a new table descriptor
     66  1.1  christos  *
     67  1.1  christos  ******************************************************************************/
     68  1.1  christos 
     69  1.1  christos void
     70  1.1  christos AcpiTbInitTableDescriptor (
     71  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
     72  1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
     73  1.1  christos     UINT8                   Flags,
     74  1.1  christos     ACPI_TABLE_HEADER       *Table)
     75  1.1  christos {
     76  1.1  christos 
     77  1.1  christos     /*
     78  1.1  christos      * Initialize the table descriptor. Set the pointer to NULL, since the
     79  1.1  christos      * table is not fully mapped at this time.
     80  1.1  christos      */
     81  1.4  christos     memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
     82  1.1  christos     TableDesc->Address = Address;
     83  1.1  christos     TableDesc->Length = Table->Length;
     84  1.1  christos     TableDesc->Flags = Flags;
     85  1.1  christos     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
     86  1.1  christos }
     87  1.1  christos 
     88  1.1  christos 
     89  1.1  christos /*******************************************************************************
     90  1.1  christos  *
     91  1.1  christos  * FUNCTION:    AcpiTbAcquireTable
     92  1.1  christos  *
     93  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
     94  1.1  christos  *              TablePtr            - Where table is returned
     95  1.1  christos  *              TableLength         - Where table length is returned
     96  1.1  christos  *              TableFlags          - Where table allocation flags are returned
     97  1.1  christos  *
     98  1.1  christos  * RETURN:      Status
     99  1.1  christos  *
    100  1.1  christos  * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
    101  1.1  christos  *              maintained in the AcpiGbl_RootTableList.
    102  1.1  christos  *
    103  1.1  christos  ******************************************************************************/
    104  1.1  christos 
    105  1.1  christos ACPI_STATUS
    106  1.1  christos AcpiTbAcquireTable (
    107  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    108  1.1  christos     ACPI_TABLE_HEADER       **TablePtr,
    109  1.1  christos     UINT32                  *TableLength,
    110  1.1  christos     UINT8                   *TableFlags)
    111  1.1  christos {
    112  1.1  christos     ACPI_TABLE_HEADER       *Table = NULL;
    113  1.1  christos 
    114  1.1  christos 
    115  1.1  christos     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
    116  1.1  christos     {
    117  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    118  1.1  christos 
    119  1.1  christos         Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
    120  1.1  christos         break;
    121  1.1  christos 
    122  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    123  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    124  1.1  christos 
    125  1.3  christos         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    126  1.5  christos             ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
    127  1.1  christos         break;
    128  1.1  christos 
    129  1.1  christos     default:
    130  1.1  christos 
    131  1.1  christos         break;
    132  1.1  christos     }
    133  1.1  christos 
    134  1.1  christos     /* Table is not valid yet */
    135  1.1  christos 
    136  1.1  christos     if (!Table)
    137  1.1  christos     {
    138  1.1  christos         return (AE_NO_MEMORY);
    139  1.1  christos     }
    140  1.1  christos 
    141  1.1  christos     /* Fill the return values */
    142  1.1  christos 
    143  1.1  christos     *TablePtr = Table;
    144  1.1  christos     *TableLength = TableDesc->Length;
    145  1.1  christos     *TableFlags = TableDesc->Flags;
    146  1.1  christos     return (AE_OK);
    147  1.1  christos }
    148  1.1  christos 
    149  1.1  christos 
    150  1.1  christos /*******************************************************************************
    151  1.1  christos  *
    152  1.1  christos  * FUNCTION:    AcpiTbReleaseTable
    153  1.1  christos  *
    154  1.1  christos  * PARAMETERS:  Table               - Pointer for the table
    155  1.1  christos  *              TableLength         - Length for the table
    156  1.1  christos  *              TableFlags          - Allocation flags for the table
    157  1.1  christos  *
    158  1.1  christos  * RETURN:      None
    159  1.1  christos  *
    160  1.1  christos  * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
    161  1.1  christos  *
    162  1.1  christos  ******************************************************************************/
    163  1.1  christos 
    164  1.1  christos void
    165  1.1  christos AcpiTbReleaseTable (
    166  1.1  christos     ACPI_TABLE_HEADER       *Table,
    167  1.1  christos     UINT32                  TableLength,
    168  1.1  christos     UINT8                   TableFlags)
    169  1.1  christos {
    170  1.1  christos 
    171  1.1  christos     switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
    172  1.1  christos     {
    173  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    174  1.1  christos 
    175  1.1  christos         AcpiOsUnmapMemory (Table, TableLength);
    176  1.1  christos         break;
    177  1.1  christos 
    178  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    179  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    180  1.1  christos     default:
    181  1.1  christos 
    182  1.1  christos         break;
    183  1.1  christos     }
    184  1.1  christos }
    185  1.1  christos 
    186  1.1  christos 
    187  1.1  christos /*******************************************************************************
    188  1.1  christos  *
    189  1.1  christos  * FUNCTION:    AcpiTbAcquireTempTable
    190  1.1  christos  *
    191  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be acquired
    192  1.1  christos  *              Address             - Address of the table
    193  1.1  christos  *              Flags               - Allocation flags of the table
    194  1.1  christos  *
    195  1.1  christos  * RETURN:      Status
    196  1.1  christos  *
    197  1.1  christos  * DESCRIPTION: This function validates the table header to obtain the length
    198  1.1  christos  *              of a table and fills the table descriptor to make its state as
    199  1.1  christos  *              "INSTALLED". Such a table descriptor is only used for verified
    200  1.1  christos  *              installation.
    201  1.1  christos  *
    202  1.1  christos  ******************************************************************************/
    203  1.1  christos 
    204  1.1  christos ACPI_STATUS
    205  1.1  christos AcpiTbAcquireTempTable (
    206  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    207  1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
    208  1.1  christos     UINT8                   Flags)
    209  1.1  christos {
    210  1.1  christos     ACPI_TABLE_HEADER       *TableHeader;
    211  1.1  christos 
    212  1.1  christos 
    213  1.1  christos     switch (Flags & ACPI_TABLE_ORIGIN_MASK)
    214  1.1  christos     {
    215  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    216  1.1  christos 
    217  1.1  christos         /* Get the length of the full table from the header */
    218  1.1  christos 
    219  1.1  christos         TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
    220  1.1  christos         if (!TableHeader)
    221  1.1  christos         {
    222  1.1  christos             return (AE_NO_MEMORY);
    223  1.1  christos         }
    224  1.1  christos 
    225  1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    226  1.1  christos         AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
    227  1.1  christos         return (AE_OK);
    228  1.1  christos 
    229  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    230  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    231  1.1  christos 
    232  1.3  christos         TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    233  1.5  christos             ACPI_PHYSADDR_TO_PTR (Address));
    234  1.1  christos         if (!TableHeader)
    235  1.1  christos         {
    236  1.1  christos             return (AE_NO_MEMORY);
    237  1.1  christos         }
    238  1.1  christos 
    239  1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    240  1.1  christos         return (AE_OK);
    241  1.1  christos 
    242  1.1  christos     default:
    243  1.1  christos 
    244  1.1  christos         break;
    245  1.1  christos     }
    246  1.1  christos 
    247  1.1  christos     /* Table is not valid yet */
    248  1.1  christos 
    249  1.1  christos     return (AE_NO_MEMORY);
    250  1.1  christos }
    251  1.1  christos 
    252  1.1  christos 
    253  1.1  christos /*******************************************************************************
    254  1.1  christos  *
    255  1.1  christos  * FUNCTION:    AcpiTbReleaseTempTable
    256  1.1  christos  *
    257  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be released
    258  1.1  christos  *
    259  1.1  christos  * RETURN:      Status
    260  1.1  christos  *
    261  1.1  christos  * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
    262  1.1  christos  *
    263  1.1  christos  *****************************************************************************/
    264  1.1  christos 
    265  1.1  christos void
    266  1.1  christos AcpiTbReleaseTempTable (
    267  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    268  1.1  christos {
    269  1.1  christos 
    270  1.1  christos     /*
    271  1.1  christos      * Note that the .Address is maintained by the callers of
    272  1.1  christos      * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
    273  1.1  christos      * where .Address will be freed.
    274  1.1  christos      */
    275  1.1  christos     AcpiTbInvalidateTable (TableDesc);
    276  1.1  christos }
    277  1.1  christos 
    278  1.1  christos 
    279  1.1  christos /******************************************************************************
    280  1.1  christos  *
    281  1.1  christos  * FUNCTION:    AcpiTbValidateTable
    282  1.1  christos  *
    283  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    284  1.1  christos  *
    285  1.1  christos  * RETURN:      Status
    286  1.1  christos  *
    287  1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    288  1.1  christos  *              table descriptor is in "VALIDATED" state.
    289  1.1  christos  *
    290  1.1  christos  *****************************************************************************/
    291  1.1  christos 
    292  1.1  christos ACPI_STATUS
    293  1.1  christos AcpiTbValidateTable (
    294  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    295  1.1  christos {
    296  1.1  christos     ACPI_STATUS             Status = AE_OK;
    297  1.1  christos 
    298  1.1  christos 
    299  1.1  christos     ACPI_FUNCTION_TRACE (TbValidateTable);
    300  1.1  christos 
    301  1.1  christos 
    302  1.1  christos     /* Validate the table if necessary */
    303  1.1  christos 
    304  1.1  christos     if (!TableDesc->Pointer)
    305  1.1  christos     {
    306  1.1  christos         Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
    307  1.5  christos             &TableDesc->Length, &TableDesc->Flags);
    308  1.1  christos         if (!TableDesc->Pointer)
    309  1.1  christos         {
    310  1.1  christos             Status = AE_NO_MEMORY;
    311  1.1  christos         }
    312  1.1  christos     }
    313  1.1  christos 
    314  1.1  christos     return_ACPI_STATUS (Status);
    315  1.1  christos }
    316  1.1  christos 
    317  1.1  christos 
    318  1.1  christos /*******************************************************************************
    319  1.1  christos  *
    320  1.1  christos  * FUNCTION:    AcpiTbInvalidateTable
    321  1.1  christos  *
    322  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    323  1.1  christos  *
    324  1.1  christos  * RETURN:      None
    325  1.1  christos  *
    326  1.1  christos  * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
    327  1.1  christos  *              AcpiTbValidateTable().
    328  1.1  christos  *
    329  1.1  christos  ******************************************************************************/
    330  1.1  christos 
    331  1.1  christos void
    332  1.1  christos AcpiTbInvalidateTable (
    333  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    334  1.1  christos {
    335  1.1  christos 
    336  1.1  christos     ACPI_FUNCTION_TRACE (TbInvalidateTable);
    337  1.1  christos 
    338  1.1  christos 
    339  1.1  christos     /* Table must be validated */
    340  1.1  christos 
    341  1.1  christos     if (!TableDesc->Pointer)
    342  1.1  christos     {
    343  1.1  christos         return_VOID;
    344  1.1  christos     }
    345  1.1  christos 
    346  1.1  christos     AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
    347  1.1  christos         TableDesc->Flags);
    348  1.1  christos     TableDesc->Pointer = NULL;
    349  1.1  christos 
    350  1.1  christos     return_VOID;
    351  1.1  christos }
    352  1.1  christos 
    353  1.1  christos 
    354  1.1  christos /******************************************************************************
    355  1.1  christos  *
    356  1.1  christos  * FUNCTION:    AcpiTbValidateTempTable
    357  1.1  christos  *
    358  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    359  1.1  christos  *
    360  1.1  christos  * RETURN:      Status
    361  1.1  christos  *
    362  1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    363  1.1  christos  *              table descriptor is in "VALIDATED" state.
    364  1.1  christos  *
    365  1.1  christos  *****************************************************************************/
    366  1.1  christos 
    367  1.1  christos ACPI_STATUS
    368  1.1  christos AcpiTbValidateTempTable (
    369  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    370  1.1  christos {
    371  1.1  christos 
    372  1.1  christos     if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
    373  1.1  christos     {
    374  1.1  christos         /*
    375  1.1  christos          * Only validates the header of the table.
    376  1.1  christos          * Note that Length contains the size of the mapping after invoking
    377  1.1  christos          * this work around, this value is required by
    378  1.1  christos          * AcpiTbReleaseTempTable().
    379  1.1  christos          * We can do this because in AcpiInitTableDescriptor(), the Length
    380  1.1  christos          * field of the installed descriptor is filled with the actual
    381  1.1  christos          * table length obtaining from the table header.
    382  1.1  christos          */
    383  1.1  christos         TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
    384  1.1  christos     }
    385  1.1  christos 
    386  1.1  christos     return (AcpiTbValidateTable (TableDesc));
    387  1.1  christos }
    388  1.1  christos 
    389  1.1  christos 
    390  1.1  christos /******************************************************************************
    391  1.1  christos  *
    392  1.1  christos  * FUNCTION:    AcpiTbVerifyTempTable
    393  1.1  christos  *
    394  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    395  1.1  christos  *              Signature           - Table signature to verify
    396  1.1  christos  *
    397  1.1  christos  * RETURN:      Status
    398  1.1  christos  *
    399  1.1  christos  * DESCRIPTION: This function is called to validate and verify the table, the
    400  1.1  christos  *              returned table descriptor is in "VALIDATED" state.
    401  1.1  christos  *
    402  1.1  christos  *****************************************************************************/
    403  1.1  christos 
    404  1.1  christos ACPI_STATUS
    405  1.1  christos AcpiTbVerifyTempTable (
    406  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    407  1.2  christos     const char              *Signature)
    408  1.1  christos {
    409  1.1  christos     ACPI_STATUS             Status = AE_OK;
    410  1.1  christos 
    411  1.1  christos 
    412  1.1  christos     ACPI_FUNCTION_TRACE (TbVerifyTempTable);
    413  1.1  christos 
    414  1.1  christos 
    415  1.1  christos     /* Validate the table */
    416  1.1  christos 
    417  1.1  christos     Status = AcpiTbValidateTempTable (TableDesc);
    418  1.1  christos     if (ACPI_FAILURE (Status))
    419  1.1  christos     {
    420  1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    421  1.1  christos     }
    422  1.1  christos 
    423  1.1  christos     /* If a particular signature is expected (DSDT/FACS), it must match */
    424  1.1  christos 
    425  1.1  christos     if (Signature &&
    426  1.1  christos         !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
    427  1.1  christos     {
    428  1.1  christos         ACPI_BIOS_ERROR ((AE_INFO,
    429  1.1  christos             "Invalid signature 0x%X for ACPI table, expected [%s]",
    430  1.1  christos             TableDesc->Signature.Integer, Signature));
    431  1.1  christos         Status = AE_BAD_SIGNATURE;
    432  1.1  christos         goto InvalidateAndExit;
    433  1.1  christos     }
    434  1.1  christos 
    435  1.1  christos     /* Verify the checksum */
    436  1.1  christos 
    437  1.1  christos     if (AcpiGbl_VerifyTableChecksum)
    438  1.1  christos     {
    439  1.1  christos         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
    440  1.1  christos         if (ACPI_FAILURE (Status))
    441  1.1  christos         {
    442  1.1  christos             ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
    443  1.3  christos                 "%4.4s 0x%8.8X%8.8X"
    444  1.1  christos                 " Attempted table install failed",
    445  1.6  christos                 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
    446  1.1  christos                     TableDesc->Signature.Ascii : "????",
    447  1.3  christos                 ACPI_FORMAT_UINT64 (TableDesc->Address)));
    448  1.5  christos 
    449  1.1  christos             goto InvalidateAndExit;
    450  1.1  christos         }
    451  1.1  christos     }
    452  1.1  christos 
    453  1.1  christos     return_ACPI_STATUS (AE_OK);
    454  1.1  christos 
    455  1.1  christos InvalidateAndExit:
    456  1.1  christos     AcpiTbInvalidateTable (TableDesc);
    457  1.1  christos     return_ACPI_STATUS (Status);
    458  1.1  christos }
    459  1.1  christos 
    460  1.1  christos 
    461  1.1  christos /*******************************************************************************
    462  1.1  christos  *
    463  1.1  christos  * FUNCTION:    AcpiTbResizeRootTableList
    464  1.1  christos  *
    465  1.1  christos  * PARAMETERS:  None
    466  1.1  christos  *
    467  1.1  christos  * RETURN:      Status
    468  1.1  christos  *
    469  1.1  christos  * DESCRIPTION: Expand the size of global table array
    470  1.1  christos  *
    471  1.1  christos  ******************************************************************************/
    472  1.1  christos 
    473  1.1  christos ACPI_STATUS
    474  1.1  christos AcpiTbResizeRootTableList (
    475  1.1  christos     void)
    476  1.1  christos {
    477  1.1  christos     ACPI_TABLE_DESC         *Tables;
    478  1.1  christos     UINT32                  TableCount;
    479  1.1  christos 
    480  1.1  christos 
    481  1.1  christos     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
    482  1.1  christos 
    483  1.1  christos 
    484  1.1  christos     /* AllowResize flag is a parameter to AcpiInitializeTables */
    485  1.1  christos 
    486  1.1  christos     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
    487  1.1  christos     {
    488  1.1  christos         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
    489  1.1  christos         return_ACPI_STATUS (AE_SUPPORT);
    490  1.1  christos     }
    491  1.1  christos 
    492  1.1  christos     /* Increase the Table Array size */
    493  1.1  christos 
    494  1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    495  1.1  christos     {
    496  1.1  christos         TableCount = AcpiGbl_RootTableList.MaxTableCount;
    497  1.1  christos     }
    498  1.1  christos     else
    499  1.1  christos     {
    500  1.1  christos         TableCount = AcpiGbl_RootTableList.CurrentTableCount;
    501  1.1  christos     }
    502  1.1  christos 
    503  1.1  christos     Tables = ACPI_ALLOCATE_ZEROED (
    504  1.1  christos         ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
    505  1.1  christos         sizeof (ACPI_TABLE_DESC));
    506  1.1  christos     if (!Tables)
    507  1.1  christos     {
    508  1.1  christos         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
    509  1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    510  1.1  christos     }
    511  1.1  christos 
    512  1.1  christos     /* Copy and free the previous table array */
    513  1.1  christos 
    514  1.1  christos     if (AcpiGbl_RootTableList.Tables)
    515  1.1  christos     {
    516  1.4  christos         memcpy (Tables, AcpiGbl_RootTableList.Tables,
    517  1.1  christos             (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
    518  1.1  christos 
    519  1.1  christos         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    520  1.1  christos         {
    521  1.1  christos             ACPI_FREE (AcpiGbl_RootTableList.Tables);
    522  1.1  christos         }
    523  1.1  christos     }
    524  1.1  christos 
    525  1.1  christos     AcpiGbl_RootTableList.Tables = Tables;
    526  1.1  christos     AcpiGbl_RootTableList.MaxTableCount =
    527  1.1  christos         TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
    528  1.1  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
    529  1.1  christos 
    530  1.1  christos     return_ACPI_STATUS (AE_OK);
    531  1.1  christos }
    532  1.1  christos 
    533  1.1  christos 
    534  1.1  christos /*******************************************************************************
    535  1.1  christos  *
    536  1.3  christos  * FUNCTION:    AcpiTbGetNextTableDescriptor
    537  1.1  christos  *
    538  1.1  christos  * PARAMETERS:  TableIndex          - Where table index is returned
    539  1.3  christos  *              TableDesc           - Where table descriptor is returned
    540  1.1  christos  *
    541  1.3  christos  * RETURN:      Status and table index/descriptor.
    542  1.1  christos  *
    543  1.1  christos  * DESCRIPTION: Allocate a new ACPI table entry to the global table list
    544  1.1  christos  *
    545  1.1  christos  ******************************************************************************/
    546  1.1  christos 
    547  1.1  christos ACPI_STATUS
    548  1.3  christos AcpiTbGetNextTableDescriptor (
    549  1.3  christos     UINT32                  *TableIndex,
    550  1.3  christos     ACPI_TABLE_DESC         **TableDesc)
    551  1.1  christos {
    552  1.1  christos     ACPI_STATUS             Status;
    553  1.3  christos     UINT32                  i;
    554  1.1  christos 
    555  1.1  christos 
    556  1.1  christos     /* Ensure that there is room for the table in the Root Table List */
    557  1.1  christos 
    558  1.1  christos     if (AcpiGbl_RootTableList.CurrentTableCount >=
    559  1.1  christos         AcpiGbl_RootTableList.MaxTableCount)
    560  1.1  christos     {
    561  1.1  christos         Status = AcpiTbResizeRootTableList();
    562  1.1  christos         if (ACPI_FAILURE (Status))
    563  1.1  christos         {
    564  1.1  christos             return (Status);
    565  1.1  christos         }
    566  1.1  christos     }
    567  1.1  christos 
    568  1.3  christos     i = AcpiGbl_RootTableList.CurrentTableCount;
    569  1.1  christos     AcpiGbl_RootTableList.CurrentTableCount++;
    570  1.3  christos 
    571  1.3  christos     if (TableIndex)
    572  1.3  christos     {
    573  1.3  christos         *TableIndex = i;
    574  1.3  christos     }
    575  1.3  christos     if (TableDesc)
    576  1.3  christos     {
    577  1.3  christos         *TableDesc = &AcpiGbl_RootTableList.Tables[i];
    578  1.3  christos     }
    579  1.3  christos 
    580  1.1  christos     return (AE_OK);
    581  1.1  christos }
    582  1.1  christos 
    583  1.1  christos 
    584  1.1  christos /*******************************************************************************
    585  1.1  christos  *
    586  1.1  christos  * FUNCTION:    AcpiTbTerminate
    587  1.1  christos  *
    588  1.1  christos  * PARAMETERS:  None
    589  1.1  christos  *
    590  1.1  christos  * RETURN:      None
    591  1.1  christos  *
    592  1.1  christos  * DESCRIPTION: Delete all internal ACPI tables
    593  1.1  christos  *
    594  1.1  christos  ******************************************************************************/
    595  1.1  christos 
    596  1.1  christos void
    597  1.1  christos AcpiTbTerminate (
    598  1.1  christos     void)
    599  1.1  christos {
    600  1.1  christos     UINT32                  i;
    601  1.1  christos 
    602  1.1  christos 
    603  1.1  christos     ACPI_FUNCTION_TRACE (TbTerminate);
    604  1.1  christos 
    605  1.1  christos 
    606  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    607  1.1  christos 
    608  1.1  christos     /* Delete the individual tables */
    609  1.1  christos 
    610  1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    611  1.1  christos     {
    612  1.1  christos         AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
    613  1.1  christos     }
    614  1.1  christos 
    615  1.1  christos     /*
    616  1.1  christos      * Delete the root table array if allocated locally. Array cannot be
    617  1.1  christos      * mapped, so we don't need to check for that flag.
    618  1.1  christos      */
    619  1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    620  1.1  christos     {
    621  1.1  christos         ACPI_FREE (AcpiGbl_RootTableList.Tables);
    622  1.1  christos     }
    623  1.1  christos 
    624  1.1  christos     AcpiGbl_RootTableList.Tables = NULL;
    625  1.1  christos     AcpiGbl_RootTableList.Flags = 0;
    626  1.1  christos     AcpiGbl_RootTableList.CurrentTableCount = 0;
    627  1.1  christos 
    628  1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
    629  1.1  christos 
    630  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    631  1.1  christos     return_VOID;
    632  1.1  christos }
    633  1.1  christos 
    634  1.1  christos 
    635  1.1  christos /*******************************************************************************
    636  1.1  christos  *
    637  1.1  christos  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
    638  1.1  christos  *
    639  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    640  1.1  christos  *
    641  1.1  christos  * RETURN:      Status
    642  1.1  christos  *
    643  1.1  christos  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
    644  1.1  christos  *
    645  1.1  christos  ******************************************************************************/
    646  1.1  christos 
    647  1.1  christos ACPI_STATUS
    648  1.1  christos AcpiTbDeleteNamespaceByOwner (
    649  1.1  christos     UINT32                  TableIndex)
    650  1.1  christos {
    651  1.1  christos     ACPI_OWNER_ID           OwnerId;
    652  1.1  christos     ACPI_STATUS             Status;
    653  1.1  christos 
    654  1.1  christos 
    655  1.1  christos     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
    656  1.1  christos 
    657  1.1  christos 
    658  1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    659  1.1  christos     if (ACPI_FAILURE (Status))
    660  1.1  christos     {
    661  1.1  christos         return_ACPI_STATUS (Status);
    662  1.1  christos     }
    663  1.1  christos 
    664  1.1  christos     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    665  1.1  christos     {
    666  1.1  christos         /* The table index does not exist */
    667  1.1  christos 
    668  1.1  christos         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    669  1.1  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    670  1.1  christos     }
    671  1.1  christos 
    672  1.1  christos     /* Get the owner ID for this table, used to delete namespace nodes */
    673  1.1  christos 
    674  1.1  christos     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    675  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    676  1.1  christos 
    677  1.1  christos     /*
    678  1.1  christos      * Need to acquire the namespace writer lock to prevent interference
    679  1.1  christos      * with any concurrent namespace walks. The interpreter must be
    680  1.1  christos      * released during the deletion since the acquisition of the deletion
    681  1.1  christos      * lock may block, and also since the execution of a namespace walk
    682  1.1  christos      * must be allowed to use the interpreter.
    683  1.1  christos      */
    684  1.1  christos     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
    685  1.1  christos     if (ACPI_FAILURE (Status))
    686  1.1  christos     {
    687  1.1  christos         return_ACPI_STATUS (Status);
    688  1.1  christos     }
    689  1.7  christos     AcpiNsDeleteNamespaceByOwner (OwnerId);
    690  1.1  christos     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
    691  1.1  christos     return_ACPI_STATUS (Status);
    692  1.1  christos }
    693  1.1  christos 
    694  1.1  christos 
    695  1.1  christos /*******************************************************************************
    696  1.1  christos  *
    697  1.1  christos  * FUNCTION:    AcpiTbAllocateOwnerId
    698  1.1  christos  *
    699  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    700  1.1  christos  *
    701  1.1  christos  * RETURN:      Status
    702  1.1  christos  *
    703  1.1  christos  * DESCRIPTION: Allocates OwnerId in TableDesc
    704  1.1  christos  *
    705  1.1  christos  ******************************************************************************/
    706  1.1  christos 
    707  1.1  christos ACPI_STATUS
    708  1.1  christos AcpiTbAllocateOwnerId (
    709  1.1  christos     UINT32                  TableIndex)
    710  1.1  christos {
    711  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    712  1.1  christos 
    713  1.1  christos 
    714  1.1  christos     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
    715  1.1  christos 
    716  1.1  christos 
    717  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    718  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    719  1.1  christos     {
    720  1.1  christos         Status = AcpiUtAllocateOwnerId (
    721  1.5  christos             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    722  1.1  christos     }
    723  1.1  christos 
    724  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    725  1.1  christos     return_ACPI_STATUS (Status);
    726  1.1  christos }
    727  1.1  christos 
    728  1.1  christos 
    729  1.1  christos /*******************************************************************************
    730  1.1  christos  *
    731  1.1  christos  * FUNCTION:    AcpiTbReleaseOwnerId
    732  1.1  christos  *
    733  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    734  1.1  christos  *
    735  1.1  christos  * RETURN:      Status
    736  1.1  christos  *
    737  1.1  christos  * DESCRIPTION: Releases OwnerId in TableDesc
    738  1.1  christos  *
    739  1.1  christos  ******************************************************************************/
    740  1.1  christos 
    741  1.1  christos ACPI_STATUS
    742  1.1  christos AcpiTbReleaseOwnerId (
    743  1.1  christos     UINT32                  TableIndex)
    744  1.1  christos {
    745  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    746  1.1  christos 
    747  1.1  christos 
    748  1.1  christos     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
    749  1.1  christos 
    750  1.1  christos 
    751  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    752  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    753  1.1  christos     {
    754  1.1  christos         AcpiUtReleaseOwnerId (
    755  1.1  christos             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    756  1.1  christos         Status = AE_OK;
    757  1.1  christos     }
    758  1.1  christos 
    759  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    760  1.1  christos     return_ACPI_STATUS (Status);
    761  1.1  christos }
    762  1.1  christos 
    763  1.1  christos 
    764  1.1  christos /*******************************************************************************
    765  1.1  christos  *
    766  1.1  christos  * FUNCTION:    AcpiTbGetOwnerId
    767  1.1  christos  *
    768  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    769  1.1  christos  *              OwnerId             - Where the table OwnerId is returned
    770  1.1  christos  *
    771  1.1  christos  * RETURN:      Status
    772  1.1  christos  *
    773  1.1  christos  * DESCRIPTION: returns OwnerId for the ACPI table
    774  1.1  christos  *
    775  1.1  christos  ******************************************************************************/
    776  1.1  christos 
    777  1.1  christos ACPI_STATUS
    778  1.1  christos AcpiTbGetOwnerId (
    779  1.1  christos     UINT32                  TableIndex,
    780  1.1  christos     ACPI_OWNER_ID           *OwnerId)
    781  1.1  christos {
    782  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    783  1.1  christos 
    784  1.1  christos 
    785  1.1  christos     ACPI_FUNCTION_TRACE (TbGetOwnerId);
    786  1.1  christos 
    787  1.1  christos 
    788  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    789  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    790  1.1  christos     {
    791  1.1  christos         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    792  1.1  christos         Status = AE_OK;
    793  1.1  christos     }
    794  1.1  christos 
    795  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    796  1.1  christos     return_ACPI_STATUS (Status);
    797  1.1  christos }
    798  1.1  christos 
    799  1.1  christos 
    800  1.1  christos /*******************************************************************************
    801  1.1  christos  *
    802  1.1  christos  * FUNCTION:    AcpiTbIsTableLoaded
    803  1.1  christos  *
    804  1.1  christos  * PARAMETERS:  TableIndex          - Index into the root table
    805  1.1  christos  *
    806  1.1  christos  * RETURN:      Table Loaded Flag
    807  1.1  christos  *
    808  1.1  christos  ******************************************************************************/
    809  1.1  christos 
    810  1.1  christos BOOLEAN
    811  1.1  christos AcpiTbIsTableLoaded (
    812  1.1  christos     UINT32                  TableIndex)
    813  1.1  christos {
    814  1.1  christos     BOOLEAN                 IsLoaded = FALSE;
    815  1.1  christos 
    816  1.1  christos 
    817  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    818  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    819  1.1  christos     {
    820  1.1  christos         IsLoaded = (BOOLEAN)
    821  1.1  christos             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
    822  1.1  christos             ACPI_TABLE_IS_LOADED);
    823  1.1  christos     }
    824  1.1  christos 
    825  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    826  1.1  christos     return (IsLoaded);
    827  1.1  christos }
    828  1.1  christos 
    829  1.1  christos 
    830  1.1  christos /*******************************************************************************
    831  1.1  christos  *
    832  1.1  christos  * FUNCTION:    AcpiTbSetTableLoadedFlag
    833  1.1  christos  *
    834  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    835  1.1  christos  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
    836  1.1  christos  *
    837  1.1  christos  * RETURN:      None
    838  1.1  christos  *
    839  1.1  christos  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
    840  1.1  christos  *
    841  1.1  christos  ******************************************************************************/
    842  1.1  christos 
    843  1.1  christos void
    844  1.1  christos AcpiTbSetTableLoadedFlag (
    845  1.1  christos     UINT32                  TableIndex,
    846  1.1  christos     BOOLEAN                 IsLoaded)
    847  1.1  christos {
    848  1.1  christos 
    849  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    850  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    851  1.1  christos     {
    852  1.1  christos         if (IsLoaded)
    853  1.1  christos         {
    854  1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
    855  1.1  christos                 ACPI_TABLE_IS_LOADED;
    856  1.1  christos         }
    857  1.1  christos         else
    858  1.1  christos         {
    859  1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
    860  1.1  christos                 ~ACPI_TABLE_IS_LOADED;
    861  1.1  christos         }
    862  1.1  christos     }
    863  1.1  christos 
    864  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    865  1.1  christos }
    866  1.7  christos 
    867  1.7  christos 
    868  1.7  christos /*******************************************************************************
    869  1.7  christos  *
    870  1.7  christos  * FUNCTION:    AcpiTbLoadTable
    871  1.7  christos  *
    872  1.7  christos  * PARAMETERS:  TableIndex              - Table index
    873  1.7  christos  *              ParentNode              - Where table index is returned
    874  1.7  christos  *
    875  1.7  christos  * RETURN:      Status
    876  1.7  christos  *
    877  1.7  christos  * DESCRIPTION: Load an ACPI table
    878  1.7  christos  *
    879  1.7  christos  ******************************************************************************/
    880  1.7  christos 
    881  1.7  christos ACPI_STATUS
    882  1.7  christos AcpiTbLoadTable (
    883  1.7  christos     UINT32                  TableIndex,
    884  1.7  christos     ACPI_NAMESPACE_NODE     *ParentNode)
    885  1.7  christos {
    886  1.7  christos     ACPI_TABLE_HEADER       *Table;
    887  1.7  christos     ACPI_STATUS             Status;
    888  1.7  christos     ACPI_OWNER_ID           OwnerId;
    889  1.7  christos 
    890  1.7  christos 
    891  1.7  christos     ACPI_FUNCTION_TRACE (TbLoadTable);
    892  1.7  christos 
    893  1.7  christos 
    894  1.7  christos     /*
    895  1.7  christos      * Note: Now table is "INSTALLED", it must be validated before
    896  1.7  christos      * using.
    897  1.7  christos      */
    898  1.7  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
    899  1.7  christos     if (ACPI_FAILURE (Status))
    900  1.7  christos     {
    901  1.7  christos         return_ACPI_STATUS (Status);
    902  1.7  christos     }
    903  1.7  christos 
    904  1.7  christos     Status = AcpiNsLoadTable (TableIndex, ParentNode);
    905  1.7  christos 
    906  1.7  christos     /* Execute any module-level code that was found in the table */
    907  1.7  christos 
    908  1.7  christos     if (!AcpiGbl_ParseTableAsTermList && AcpiGbl_GroupModuleLevelCode)
    909  1.7  christos     {
    910  1.7  christos         AcpiNsExecModuleCodeList ();
    911  1.7  christos     }
    912  1.7  christos 
    913  1.7  christos     /*
    914  1.7  christos      * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
    915  1.7  christos      * responsible for discovering any new wake GPEs by running _PRW methods
    916  1.7  christos      * that may have been loaded by this table.
    917  1.7  christos      */
    918  1.7  christos     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    919  1.7  christos     if (ACPI_SUCCESS (Status))
    920  1.7  christos     {
    921  1.7  christos         AcpiEvUpdateGpes (OwnerId);
    922  1.7  christos     }
    923  1.7  christos 
    924  1.7  christos     /* Invoke table handler if present */
    925  1.7  christos 
    926  1.7  christos     if (AcpiGbl_TableHandler)
    927  1.7  christos     {
    928  1.7  christos         (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
    929  1.7  christos             AcpiGbl_TableHandlerContext);
    930  1.7  christos     }
    931  1.7  christos 
    932  1.7  christos     return_ACPI_STATUS (Status);
    933  1.7  christos }
    934  1.7  christos 
    935  1.7  christos 
    936  1.7  christos /*******************************************************************************
    937  1.7  christos  *
    938  1.7  christos  * FUNCTION:    AcpiTbInstallAndLoadTable
    939  1.7  christos  *
    940  1.8  christos  * PARAMETERS:  Address                 - Physical address of the table
    941  1.7  christos  *              Flags                   - Allocation flags of the table
    942  1.8  christos  *              Override                - Whether override should be performed
    943  1.7  christos  *              TableIndex              - Where table index is returned
    944  1.7  christos  *
    945  1.7  christos  * RETURN:      Status
    946  1.7  christos  *
    947  1.7  christos  * DESCRIPTION: Install and load an ACPI table
    948  1.7  christos  *
    949  1.7  christos  ******************************************************************************/
    950  1.7  christos 
    951  1.7  christos ACPI_STATUS
    952  1.7  christos AcpiTbInstallAndLoadTable (
    953  1.7  christos     ACPI_PHYSICAL_ADDRESS   Address,
    954  1.7  christos     UINT8                   Flags,
    955  1.7  christos     BOOLEAN                 Override,
    956  1.7  christos     UINT32                  *TableIndex)
    957  1.7  christos {
    958  1.7  christos     ACPI_STATUS             Status;
    959  1.7  christos     UINT32                  i;
    960  1.7  christos 
    961  1.7  christos 
    962  1.8  christos     ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
    963  1.7  christos 
    964  1.7  christos 
    965  1.7  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    966  1.7  christos 
    967  1.7  christos     /* Install the table and load it into the namespace */
    968  1.7  christos 
    969  1.7  christos     Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
    970  1.7  christos         Override, &i);
    971  1.7  christos     if (ACPI_FAILURE (Status))
    972  1.7  christos     {
    973  1.7  christos         goto UnlockAndExit;
    974  1.7  christos     }
    975  1.7  christos 
    976  1.8  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    977  1.8  christos     Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
    978  1.8  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    979  1.7  christos 
    980  1.8  christos UnlockAndExit:
    981  1.8  christos     *TableIndex = i;
    982  1.7  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    983  1.8  christos     return_ACPI_STATUS (Status);
    984  1.8  christos }
    985  1.8  christos 
    986  1.8  christos 
    987  1.8  christos /*******************************************************************************
    988  1.8  christos  *
    989  1.8  christos  * FUNCTION:    AcpiTbUnloadTable
    990  1.8  christos  *
    991  1.8  christos  * PARAMETERS:  TableIndex              - Table index
    992  1.8  christos  *
    993  1.8  christos  * RETURN:      Status
    994  1.8  christos  *
    995  1.8  christos  * DESCRIPTION: Unload an ACPI table
    996  1.8  christos  *
    997  1.8  christos  ******************************************************************************/
    998  1.7  christos 
    999  1.8  christos ACPI_STATUS
   1000  1.8  christos AcpiTbUnloadTable (
   1001  1.8  christos     UINT32                  TableIndex)
   1002  1.8  christos {
   1003  1.8  christos     ACPI_STATUS             Status = AE_OK;
   1004  1.8  christos     ACPI_TABLE_HEADER       *Table;
   1005  1.8  christos 
   1006  1.8  christos 
   1007  1.8  christos     ACPI_FUNCTION_TRACE (TbUnloadTable);
   1008  1.8  christos 
   1009  1.8  christos 
   1010  1.8  christos     /* Ensure the table is still loaded */
   1011  1.7  christos 
   1012  1.8  christos     if (!AcpiTbIsTableLoaded (TableIndex))
   1013  1.7  christos     {
   1014  1.8  christos         return_ACPI_STATUS (AE_NOT_EXIST);
   1015  1.7  christos     }
   1016  1.7  christos 
   1017  1.8  christos     /* Invoke table handler if present */
   1018  1.8  christos 
   1019  1.8  christos     if (AcpiGbl_TableHandler)
   1020  1.7  christos     {
   1021  1.8  christos         Status = AcpiGetTableByIndex (TableIndex, &Table);
   1022  1.8  christos         if (ACPI_SUCCESS (Status))
   1023  1.8  christos         {
   1024  1.8  christos             (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
   1025  1.8  christos                 AcpiGbl_TableHandlerContext);
   1026  1.8  christos         }
   1027  1.7  christos     }
   1028  1.7  christos 
   1029  1.8  christos     /* Delete the portion of the namespace owned by this table */
   1030  1.7  christos 
   1031  1.8  christos     Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
   1032  1.8  christos     if (ACPI_FAILURE (Status))
   1033  1.7  christos     {
   1034  1.8  christos         return_ACPI_STATUS (Status);
   1035  1.7  christos     }
   1036  1.7  christos 
   1037  1.8  christos     (void) AcpiTbReleaseOwnerId (TableIndex);
   1038  1.8  christos     AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
   1039  1.7  christos     return_ACPI_STATUS (Status);
   1040  1.7  christos }
   1041