Home | History | Annotate | Line # | Download | only in tables
tbxface.c revision 1.1.1.14
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.3  christos  * Module Name: tbxface - ACPI table-oriented external interfaces
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.14  christos  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.14  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44   1.1.1.3  christos #define EXPORT_ACPI_INTERFACES
     45       1.1    jruoho 
     46       1.1    jruoho #include "acpi.h"
     47       1.1    jruoho #include "accommon.h"
     48       1.1    jruoho #include "actables.h"
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_TABLES
     51       1.1    jruoho         ACPI_MODULE_NAME    ("tbxface")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54       1.1    jruoho /*******************************************************************************
     55       1.1    jruoho  *
     56       1.1    jruoho  * FUNCTION:    AcpiAllocateRootTable
     57       1.1    jruoho  *
     58       1.1    jruoho  * PARAMETERS:  InitialTableCount   - Size of InitialTableArray, in number of
     59       1.1    jruoho  *                                    ACPI_TABLE_DESC structures
     60       1.1    jruoho  *
     61       1.1    jruoho  * RETURN:      Status
     62       1.1    jruoho  *
     63       1.1    jruoho  * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
     64       1.1    jruoho  *              AcpiInitializeTables.
     65       1.1    jruoho  *
     66       1.1    jruoho  ******************************************************************************/
     67       1.1    jruoho 
     68       1.1    jruoho ACPI_STATUS
     69       1.1    jruoho AcpiAllocateRootTable (
     70       1.1    jruoho     UINT32                  InitialTableCount)
     71       1.1    jruoho {
     72       1.1    jruoho 
     73       1.1    jruoho     AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
     74       1.1    jruoho     AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
     75       1.1    jruoho 
     76       1.1    jruoho     return (AcpiTbResizeRootTableList ());
     77       1.1    jruoho }
     78       1.1    jruoho 
     79       1.1    jruoho 
     80       1.1    jruoho /*******************************************************************************
     81       1.1    jruoho  *
     82       1.1    jruoho  * FUNCTION:    AcpiInitializeTables
     83       1.1    jruoho  *
     84       1.1    jruoho  * PARAMETERS:  InitialTableArray   - Pointer to an array of pre-allocated
     85       1.1    jruoho  *                                    ACPI_TABLE_DESC structures. If NULL, the
     86       1.1    jruoho  *                                    array is dynamically allocated.
     87       1.1    jruoho  *              InitialTableCount   - Size of InitialTableArray, in number of
     88       1.1    jruoho  *                                    ACPI_TABLE_DESC structures
     89   1.1.1.3  christos  *              AllowResize         - Flag to tell Table Manager if resize of
     90       1.1    jruoho  *                                    pre-allocated array is allowed. Ignored
     91       1.1    jruoho  *                                    if InitialTableArray is NULL.
     92       1.1    jruoho  *
     93       1.1    jruoho  * RETURN:      Status
     94       1.1    jruoho  *
     95       1.1    jruoho  * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
     96       1.1    jruoho  *
     97       1.1    jruoho  * NOTE:        Allows static allocation of the initial table array in order
     98       1.1    jruoho  *              to avoid the use of dynamic memory in confined environments
     99       1.1    jruoho  *              such as the kernel boot sequence where it may not be available.
    100       1.1    jruoho  *
    101       1.1    jruoho  *              If the host OS memory managers are initialized, use NULL for
    102       1.1    jruoho  *              InitialTableArray, and the table will be dynamically allocated.
    103       1.1    jruoho  *
    104       1.1    jruoho  ******************************************************************************/
    105       1.1    jruoho 
    106   1.1.1.8  christos ACPI_STATUS ACPI_INIT_FUNCTION
    107       1.1    jruoho AcpiInitializeTables (
    108       1.1    jruoho     ACPI_TABLE_DESC         *InitialTableArray,
    109       1.1    jruoho     UINT32                  InitialTableCount,
    110       1.1    jruoho     BOOLEAN                 AllowResize)
    111       1.1    jruoho {
    112       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   RsdpAddress;
    113       1.1    jruoho     ACPI_STATUS             Status;
    114       1.1    jruoho 
    115       1.1    jruoho 
    116       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInitializeTables);
    117       1.1    jruoho 
    118       1.1    jruoho 
    119       1.1    jruoho     /*
    120   1.1.1.3  christos      * Setup the Root Table Array and allocate the table array
    121   1.1.1.3  christos      * if requested
    122       1.1    jruoho      */
    123       1.1    jruoho     if (!InitialTableArray)
    124       1.1    jruoho     {
    125       1.1    jruoho         Status = AcpiAllocateRootTable (InitialTableCount);
    126       1.1    jruoho         if (ACPI_FAILURE (Status))
    127       1.1    jruoho         {
    128       1.1    jruoho             return_ACPI_STATUS (Status);
    129       1.1    jruoho         }
    130       1.1    jruoho     }
    131       1.1    jruoho     else
    132       1.1    jruoho     {
    133       1.1    jruoho         /* Root Table Array has been statically allocated by the host */
    134       1.1    jruoho 
    135   1.1.1.6  christos         memset (InitialTableArray, 0,
    136       1.1    jruoho             (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
    137       1.1    jruoho 
    138       1.1    jruoho         AcpiGbl_RootTableList.Tables = InitialTableArray;
    139       1.1    jruoho         AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
    140       1.1    jruoho         AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
    141       1.1    jruoho         if (AllowResize)
    142       1.1    jruoho         {
    143       1.1    jruoho             AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
    144       1.1    jruoho         }
    145       1.1    jruoho     }
    146       1.1    jruoho 
    147       1.1    jruoho     /* Get the address of the RSDP */
    148       1.1    jruoho 
    149       1.1    jruoho     RsdpAddress = AcpiOsGetRootPointer ();
    150       1.1    jruoho     if (!RsdpAddress)
    151       1.1    jruoho     {
    152       1.1    jruoho         return_ACPI_STATUS (AE_NOT_FOUND);
    153       1.1    jruoho     }
    154       1.1    jruoho 
    155       1.1    jruoho     /*
    156       1.1    jruoho      * Get the root table (RSDT or XSDT) and extract all entries to the local
    157       1.1    jruoho      * Root Table Array. This array contains the information of the RSDT/XSDT
    158  1.1.1.12  christos      * in a common, more usable format.
    159       1.1    jruoho      */
    160       1.1    jruoho     Status = AcpiTbParseRootTable (RsdpAddress);
    161       1.1    jruoho     return_ACPI_STATUS (Status);
    162       1.1    jruoho }
    163       1.1    jruoho 
    164   1.1.1.3  christos ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables)
    165       1.1    jruoho 
    166       1.1    jruoho 
    167       1.1    jruoho /*******************************************************************************
    168       1.1    jruoho  *
    169       1.1    jruoho  * FUNCTION:    AcpiReallocateRootTable
    170       1.1    jruoho  *
    171       1.1    jruoho  * PARAMETERS:  None
    172       1.1    jruoho  *
    173       1.1    jruoho  * RETURN:      Status
    174       1.1    jruoho  *
    175       1.1    jruoho  * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
    176       1.1    jruoho  *              root list from the previously provided scratch area. Should
    177       1.1    jruoho  *              be called once dynamic memory allocation is available in the
    178   1.1.1.3  christos  *              kernel.
    179       1.1    jruoho  *
    180       1.1    jruoho  ******************************************************************************/
    181       1.1    jruoho 
    182   1.1.1.8  christos ACPI_STATUS ACPI_INIT_FUNCTION
    183       1.1    jruoho AcpiReallocateRootTable (
    184       1.1    jruoho     void)
    185       1.1    jruoho {
    186   1.1.1.3  christos     ACPI_STATUS             Status;
    187  1.1.1.10  christos     ACPI_TABLE_DESC         *TableDesc;
    188  1.1.1.10  christos     UINT32                  i, j;
    189       1.1    jruoho 
    190       1.1    jruoho 
    191       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
    192       1.1    jruoho 
    193       1.1    jruoho 
    194       1.1    jruoho     /*
    195  1.1.1.10  christos      * If there are tables unverified, it is required to reallocate the
    196  1.1.1.10  christos      * root table list to clean up invalid table entries. Otherwise only
    197  1.1.1.10  christos      * reallocate the root table list if the host provided a static buffer
    198  1.1.1.10  christos      * for the table array in the call to AcpiInitializeTables().
    199       1.1    jruoho      */
    200  1.1.1.10  christos     if ((AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
    201  1.1.1.10  christos         AcpiGbl_EnableTableValidation)
    202       1.1    jruoho     {
    203       1.1    jruoho         return_ACPI_STATUS (AE_SUPPORT);
    204       1.1    jruoho     }
    205       1.1    jruoho 
    206  1.1.1.10  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    207  1.1.1.10  christos 
    208   1.1.1.9  christos     /*
    209   1.1.1.9  christos      * Ensure OS early boot logic, which is required by some hosts. If the
    210   1.1.1.9  christos      * table state is reported to be wrong, developers should fix the
    211   1.1.1.9  christos      * issue by invoking AcpiPutTable() for the reported table during the
    212   1.1.1.9  christos      * early stage.
    213   1.1.1.9  christos      */
    214   1.1.1.9  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    215   1.1.1.9  christos     {
    216  1.1.1.10  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    217  1.1.1.10  christos         if (TableDesc->Pointer)
    218   1.1.1.9  christos         {
    219   1.1.1.9  christos             ACPI_ERROR ((AE_INFO,
    220   1.1.1.9  christos                 "Table [%4.4s] is not invalidated during early boot stage",
    221  1.1.1.10  christos                 TableDesc->Signature.Ascii));
    222   1.1.1.9  christos         }
    223   1.1.1.9  christos     }
    224   1.1.1.9  christos 
    225  1.1.1.10  christos     if (!AcpiGbl_EnableTableValidation)
    226  1.1.1.10  christos     {
    227  1.1.1.10  christos         /*
    228  1.1.1.10  christos          * Now it's safe to do full table validation. We can do deferred
    229  1.1.1.12  christos          * table initialization here once the flag is set.
    230  1.1.1.10  christos          */
    231  1.1.1.10  christos         AcpiGbl_EnableTableValidation = TRUE;
    232  1.1.1.10  christos         for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    233  1.1.1.10  christos         {
    234  1.1.1.10  christos             TableDesc = &AcpiGbl_RootTableList.Tables[i];
    235  1.1.1.10  christos             if (!(TableDesc->Flags & ACPI_TABLE_IS_VERIFIED))
    236  1.1.1.10  christos             {
    237  1.1.1.10  christos                 Status = AcpiTbVerifyTempTable (TableDesc, NULL, &j);
    238  1.1.1.10  christos                 if (ACPI_FAILURE (Status))
    239  1.1.1.10  christos                 {
    240  1.1.1.10  christos                     AcpiTbUninstallTable (TableDesc);
    241  1.1.1.10  christos                 }
    242  1.1.1.10  christos             }
    243  1.1.1.10  christos         }
    244  1.1.1.10  christos     }
    245       1.1    jruoho 
    246  1.1.1.10  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
    247   1.1.1.3  christos     Status = AcpiTbResizeRootTableList ();
    248  1.1.1.10  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
    249  1.1.1.10  christos 
    250  1.1.1.10  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    251   1.1.1.3  christos     return_ACPI_STATUS (Status);
    252       1.1    jruoho }
    253       1.1    jruoho 
    254   1.1.1.3  christos ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
    255       1.1    jruoho 
    256       1.1    jruoho 
    257       1.1    jruoho /*******************************************************************************
    258       1.1    jruoho  *
    259       1.1    jruoho  * FUNCTION:    AcpiGetTableHeader
    260       1.1    jruoho  *
    261       1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature of needed table
    262       1.1    jruoho  *              Instance            - Which instance (for SSDTs)
    263  1.1.1.13  christos  *              OutTableHeader      - The pointer to the where the table header
    264  1.1.1.13  christos  *                                    is returned
    265       1.1    jruoho  *
    266  1.1.1.13  christos  * RETURN:      Status and a copy of the table header
    267       1.1    jruoho  *
    268  1.1.1.13  christos  * DESCRIPTION: Finds and returns an ACPI table header. Caller provides the
    269  1.1.1.13  christos  *              memory where a copy of the header is to be returned
    270  1.1.1.13  christos  *              (fixed length).
    271       1.1    jruoho  *
    272       1.1    jruoho  ******************************************************************************/
    273       1.1    jruoho 
    274       1.1    jruoho ACPI_STATUS
    275       1.1    jruoho AcpiGetTableHeader (
    276       1.1    jruoho     char                    *Signature,
    277       1.1    jruoho     UINT32                  Instance,
    278       1.1    jruoho     ACPI_TABLE_HEADER       *OutTableHeader)
    279       1.1    jruoho {
    280       1.1    jruoho     UINT32                  i;
    281       1.1    jruoho     UINT32                  j;
    282       1.1    jruoho     ACPI_TABLE_HEADER       *Header;
    283       1.1    jruoho 
    284       1.1    jruoho 
    285       1.1    jruoho     /* Parameter validation */
    286       1.1    jruoho 
    287       1.1    jruoho     if (!Signature || !OutTableHeader)
    288       1.1    jruoho     {
    289       1.1    jruoho         return (AE_BAD_PARAMETER);
    290       1.1    jruoho     }
    291       1.1    jruoho 
    292       1.1    jruoho     /* Walk the root table list */
    293       1.1    jruoho 
    294       1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    295       1.1    jruoho     {
    296  1.1.1.12  christos         if (!ACPI_COMPARE_NAMESEG (
    297   1.1.1.7  christos                 &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
    298       1.1    jruoho         {
    299       1.1    jruoho             continue;
    300       1.1    jruoho         }
    301       1.1    jruoho 
    302       1.1    jruoho         if (++j < Instance)
    303       1.1    jruoho         {
    304       1.1    jruoho             continue;
    305       1.1    jruoho         }
    306       1.1    jruoho 
    307       1.1    jruoho         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    308       1.1    jruoho         {
    309       1.1    jruoho             if ((AcpiGbl_RootTableList.Tables[i].Flags &
    310       1.1    jruoho                     ACPI_TABLE_ORIGIN_MASK) ==
    311   1.1.1.4  christos                 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
    312       1.1    jruoho             {
    313       1.1    jruoho                 Header = AcpiOsMapMemory (
    314   1.1.1.7  christos                     AcpiGbl_RootTableList.Tables[i].Address,
    315   1.1.1.7  christos                     sizeof (ACPI_TABLE_HEADER));
    316       1.1    jruoho                 if (!Header)
    317       1.1    jruoho                 {
    318   1.1.1.3  christos                     return (AE_NO_MEMORY);
    319       1.1    jruoho                 }
    320       1.1    jruoho 
    321   1.1.1.7  christos                 memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
    322   1.1.1.3  christos                 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
    323       1.1    jruoho             }
    324       1.1    jruoho             else
    325       1.1    jruoho             {
    326   1.1.1.3  christos                 return (AE_NOT_FOUND);
    327       1.1    jruoho             }
    328       1.1    jruoho         }
    329       1.1    jruoho         else
    330       1.1    jruoho         {
    331   1.1.1.6  christos             memcpy (OutTableHeader,
    332       1.1    jruoho                 AcpiGbl_RootTableList.Tables[i].Pointer,
    333   1.1.1.3  christos                 sizeof (ACPI_TABLE_HEADER));
    334       1.1    jruoho         }
    335       1.1    jruoho 
    336       1.1    jruoho         return (AE_OK);
    337       1.1    jruoho     }
    338       1.1    jruoho 
    339       1.1    jruoho     return (AE_NOT_FOUND);
    340       1.1    jruoho }
    341       1.1    jruoho 
    342       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
    343       1.1    jruoho 
    344       1.1    jruoho 
    345       1.1    jruoho /*******************************************************************************
    346       1.1    jruoho  *
    347       1.1    jruoho  * FUNCTION:    AcpiGetTable
    348       1.1    jruoho  *
    349       1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature of needed table
    350       1.1    jruoho  *              Instance            - Which instance (for SSDTs)
    351       1.1    jruoho  *              OutTable            - Where the pointer to the table is returned
    352       1.1    jruoho  *
    353   1.1.1.3  christos  * RETURN:      Status and pointer to the requested table
    354       1.1    jruoho  *
    355   1.1.1.3  christos  * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
    356   1.1.1.3  christos  *              RSDT/XSDT.
    357   1.1.1.9  christos  *              Note that an early stage AcpiGetTable() call must be paired
    358   1.1.1.9  christos  *              with an early stage AcpiPutTable() call. otherwise the table
    359   1.1.1.9  christos  *              pointer mapped by the early stage mapping implementation may be
    360   1.1.1.9  christos  *              erroneously unmapped by the late stage unmapping implementation
    361   1.1.1.9  christos  *              in an AcpiPutTable() invoked during the late stage.
    362       1.1    jruoho  *
    363       1.1    jruoho  ******************************************************************************/
    364       1.1    jruoho 
    365       1.1    jruoho ACPI_STATUS
    366       1.1    jruoho AcpiGetTable (
    367       1.1    jruoho     char                    *Signature,
    368       1.1    jruoho     UINT32                  Instance,
    369       1.1    jruoho     ACPI_TABLE_HEADER       **OutTable)
    370       1.1    jruoho {
    371       1.1    jruoho     UINT32                  i;
    372       1.1    jruoho     UINT32                  j;
    373   1.1.1.9  christos     ACPI_STATUS             Status = AE_NOT_FOUND;
    374   1.1.1.9  christos     ACPI_TABLE_DESC         *TableDesc;
    375       1.1    jruoho 
    376       1.1    jruoho 
    377       1.1    jruoho     /* Parameter validation */
    378       1.1    jruoho 
    379       1.1    jruoho     if (!Signature || !OutTable)
    380       1.1    jruoho     {
    381       1.1    jruoho         return (AE_BAD_PARAMETER);
    382       1.1    jruoho     }
    383       1.1    jruoho 
    384   1.1.1.9  christos     /*
    385   1.1.1.9  christos      * Note that the following line is required by some OSPMs, they only
    386   1.1.1.9  christos      * check if the returned table is NULL instead of the returned status
    387   1.1.1.9  christos      * to determined if this function is succeeded.
    388   1.1.1.9  christos      */
    389   1.1.1.9  christos     *OutTable = NULL;
    390   1.1.1.9  christos 
    391   1.1.1.9  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    392   1.1.1.9  christos 
    393       1.1    jruoho     /* Walk the root table list */
    394       1.1    jruoho 
    395       1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    396       1.1    jruoho     {
    397   1.1.1.9  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    398   1.1.1.9  christos 
    399  1.1.1.12  christos         if (!ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))
    400       1.1    jruoho         {
    401       1.1    jruoho             continue;
    402       1.1    jruoho         }
    403       1.1    jruoho 
    404       1.1    jruoho         if (++j < Instance)
    405       1.1    jruoho         {
    406       1.1    jruoho             continue;
    407       1.1    jruoho         }
    408       1.1    jruoho 
    409   1.1.1.9  christos         Status = AcpiTbGetTable (TableDesc, OutTable);
    410   1.1.1.9  christos         break;
    411   1.1.1.9  christos     }
    412   1.1.1.9  christos 
    413   1.1.1.9  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    414   1.1.1.9  christos     return (Status);
    415   1.1.1.9  christos }
    416   1.1.1.9  christos 
    417   1.1.1.9  christos ACPI_EXPORT_SYMBOL (AcpiGetTable)
    418   1.1.1.9  christos 
    419   1.1.1.9  christos 
    420   1.1.1.9  christos /*******************************************************************************
    421   1.1.1.9  christos  *
    422   1.1.1.9  christos  * FUNCTION:    AcpiPutTable
    423   1.1.1.9  christos  *
    424   1.1.1.9  christos  * PARAMETERS:  Table               - The pointer to the table
    425   1.1.1.9  christos  *
    426   1.1.1.9  christos  * RETURN:      None
    427   1.1.1.9  christos  *
    428   1.1.1.9  christos  * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
    429   1.1.1.9  christos  *              Note that it is not safe if this function was invoked after an
    430   1.1.1.9  christos  *              uninstallation happened to the original table descriptor.
    431   1.1.1.9  christos  *              Currently there is no OSPMs' requirement to handle such
    432   1.1.1.9  christos  *              situations.
    433   1.1.1.9  christos  *
    434   1.1.1.9  christos  ******************************************************************************/
    435   1.1.1.9  christos 
    436   1.1.1.9  christos void
    437   1.1.1.9  christos AcpiPutTable (
    438   1.1.1.9  christos     ACPI_TABLE_HEADER       *Table)
    439   1.1.1.9  christos {
    440   1.1.1.9  christos     UINT32                  i;
    441   1.1.1.9  christos     ACPI_TABLE_DESC         *TableDesc;
    442   1.1.1.9  christos 
    443   1.1.1.9  christos 
    444   1.1.1.9  christos     ACPI_FUNCTION_TRACE (AcpiPutTable);
    445   1.1.1.9  christos 
    446   1.1.1.9  christos 
    447  1.1.1.10  christos     if (!Table)
    448  1.1.1.10  christos     {
    449  1.1.1.10  christos         return_VOID;
    450  1.1.1.10  christos     }
    451  1.1.1.10  christos 
    452   1.1.1.9  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    453   1.1.1.9  christos 
    454   1.1.1.9  christos     /* Walk the root table list */
    455   1.1.1.9  christos 
    456   1.1.1.9  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    457   1.1.1.9  christos     {
    458   1.1.1.9  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    459   1.1.1.9  christos 
    460   1.1.1.9  christos         if (TableDesc->Pointer != Table)
    461       1.1    jruoho         {
    462   1.1.1.9  christos             continue;
    463       1.1    jruoho         }
    464       1.1    jruoho 
    465   1.1.1.9  christos         AcpiTbPutTable (TableDesc);
    466   1.1.1.9  christos         break;
    467       1.1    jruoho     }
    468       1.1    jruoho 
    469   1.1.1.9  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    470   1.1.1.9  christos     return_VOID;
    471       1.1    jruoho }
    472       1.1    jruoho 
    473   1.1.1.9  christos ACPI_EXPORT_SYMBOL (AcpiPutTable)
    474       1.1    jruoho 
    475       1.1    jruoho 
    476       1.1    jruoho /*******************************************************************************
    477       1.1    jruoho  *
    478       1.1    jruoho  * FUNCTION:    AcpiGetTableByIndex
    479       1.1    jruoho  *
    480       1.1    jruoho  * PARAMETERS:  TableIndex          - Table index
    481   1.1.1.9  christos  *              OutTable            - Where the pointer to the table is returned
    482       1.1    jruoho  *
    483   1.1.1.3  christos  * RETURN:      Status and pointer to the requested table
    484       1.1    jruoho  *
    485   1.1.1.3  christos  * DESCRIPTION: Obtain a table by an index into the global table list. Used
    486   1.1.1.3  christos  *              internally also.
    487       1.1    jruoho  *
    488       1.1    jruoho  ******************************************************************************/
    489       1.1    jruoho 
    490       1.1    jruoho ACPI_STATUS
    491       1.1    jruoho AcpiGetTableByIndex (
    492       1.1    jruoho     UINT32                  TableIndex,
    493   1.1.1.9  christos     ACPI_TABLE_HEADER       **OutTable)
    494       1.1    jruoho {
    495       1.1    jruoho     ACPI_STATUS             Status;
    496       1.1    jruoho 
    497       1.1    jruoho 
    498       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
    499       1.1    jruoho 
    500       1.1    jruoho 
    501       1.1    jruoho     /* Parameter validation */
    502       1.1    jruoho 
    503   1.1.1.9  christos     if (!OutTable)
    504       1.1    jruoho     {
    505       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    506       1.1    jruoho     }
    507       1.1    jruoho 
    508   1.1.1.9  christos     /*
    509   1.1.1.9  christos      * Note that the following line is required by some OSPMs, they only
    510   1.1.1.9  christos      * check if the returned table is NULL instead of the returned status
    511   1.1.1.9  christos      * to determined if this function is succeeded.
    512   1.1.1.9  christos      */
    513   1.1.1.9  christos     *OutTable = NULL;
    514   1.1.1.9  christos 
    515       1.1    jruoho     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    516       1.1    jruoho 
    517       1.1    jruoho     /* Validate index */
    518       1.1    jruoho 
    519       1.1    jruoho     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    520       1.1    jruoho     {
    521   1.1.1.9  christos         Status = AE_BAD_PARAMETER;
    522   1.1.1.9  christos         goto UnlockAndExit;
    523       1.1    jruoho     }
    524       1.1    jruoho 
    525   1.1.1.9  christos     Status = AcpiTbGetTable (
    526   1.1.1.9  christos         &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
    527       1.1    jruoho 
    528   1.1.1.9  christos UnlockAndExit:
    529       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    530   1.1.1.9  christos     return_ACPI_STATUS (Status);
    531       1.1    jruoho }
    532       1.1    jruoho 
    533       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
    534       1.1    jruoho 
    535       1.1    jruoho 
    536       1.1    jruoho /*******************************************************************************
    537       1.1    jruoho  *
    538       1.1    jruoho  * FUNCTION:    AcpiInstallTableHandler
    539       1.1    jruoho  *
    540       1.1    jruoho  * PARAMETERS:  Handler         - Table event handler
    541       1.1    jruoho  *              Context         - Value passed to the handler on each event
    542       1.1    jruoho  *
    543       1.1    jruoho  * RETURN:      Status
    544       1.1    jruoho  *
    545   1.1.1.3  christos  * DESCRIPTION: Install a global table event handler.
    546       1.1    jruoho  *
    547       1.1    jruoho  ******************************************************************************/
    548       1.1    jruoho 
    549       1.1    jruoho ACPI_STATUS
    550       1.1    jruoho AcpiInstallTableHandler (
    551       1.1    jruoho     ACPI_TABLE_HANDLER      Handler,
    552       1.1    jruoho     void                    *Context)
    553       1.1    jruoho {
    554       1.1    jruoho     ACPI_STATUS             Status;
    555       1.1    jruoho 
    556       1.1    jruoho 
    557       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
    558       1.1    jruoho 
    559       1.1    jruoho 
    560       1.1    jruoho     if (!Handler)
    561       1.1    jruoho     {
    562       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    563       1.1    jruoho     }
    564       1.1    jruoho 
    565       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    566       1.1    jruoho     if (ACPI_FAILURE (Status))
    567       1.1    jruoho     {
    568       1.1    jruoho         return_ACPI_STATUS (Status);
    569       1.1    jruoho     }
    570       1.1    jruoho 
    571       1.1    jruoho     /* Don't allow more than one handler */
    572       1.1    jruoho 
    573       1.1    jruoho     if (AcpiGbl_TableHandler)
    574       1.1    jruoho     {
    575       1.1    jruoho         Status = AE_ALREADY_EXISTS;
    576       1.1    jruoho         goto Cleanup;
    577       1.1    jruoho     }
    578       1.1    jruoho 
    579       1.1    jruoho     /* Install the handler */
    580       1.1    jruoho 
    581       1.1    jruoho     AcpiGbl_TableHandler = Handler;
    582       1.1    jruoho     AcpiGbl_TableHandlerContext = Context;
    583       1.1    jruoho 
    584       1.1    jruoho Cleanup:
    585       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    586       1.1    jruoho     return_ACPI_STATUS (Status);
    587       1.1    jruoho }
    588       1.1    jruoho 
    589       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
    590       1.1    jruoho 
    591       1.1    jruoho 
    592       1.1    jruoho /*******************************************************************************
    593       1.1    jruoho  *
    594       1.1    jruoho  * FUNCTION:    AcpiRemoveTableHandler
    595       1.1    jruoho  *
    596       1.1    jruoho  * PARAMETERS:  Handler         - Table event handler that was installed
    597       1.1    jruoho  *                                previously.
    598       1.1    jruoho  *
    599       1.1    jruoho  * RETURN:      Status
    600       1.1    jruoho  *
    601   1.1.1.3  christos  * DESCRIPTION: Remove a table event handler
    602       1.1    jruoho  *
    603       1.1    jruoho  ******************************************************************************/
    604       1.1    jruoho 
    605       1.1    jruoho ACPI_STATUS
    606       1.1    jruoho AcpiRemoveTableHandler (
    607       1.1    jruoho     ACPI_TABLE_HANDLER      Handler)
    608       1.1    jruoho {
    609       1.1    jruoho     ACPI_STATUS             Status;
    610       1.1    jruoho 
    611       1.1    jruoho 
    612       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
    613       1.1    jruoho 
    614       1.1    jruoho 
    615       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    616       1.1    jruoho     if (ACPI_FAILURE (Status))
    617       1.1    jruoho     {
    618       1.1    jruoho         return_ACPI_STATUS (Status);
    619       1.1    jruoho     }
    620       1.1    jruoho 
    621       1.1    jruoho     /* Make sure that the installed handler is the same */
    622       1.1    jruoho 
    623       1.1    jruoho     if (!Handler ||
    624       1.1    jruoho         Handler != AcpiGbl_TableHandler)
    625       1.1    jruoho     {
    626       1.1    jruoho         Status = AE_BAD_PARAMETER;
    627       1.1    jruoho         goto Cleanup;
    628       1.1    jruoho     }
    629       1.1    jruoho 
    630       1.1    jruoho     /* Remove the handler */
    631       1.1    jruoho 
    632       1.1    jruoho     AcpiGbl_TableHandler = NULL;
    633       1.1    jruoho 
    634       1.1    jruoho Cleanup:
    635       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    636       1.1    jruoho     return_ACPI_STATUS (Status);
    637       1.1    jruoho }
    638       1.1    jruoho 
    639       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
    640