Home | History | Annotate | Line # | Download | only in tables
tbxface.c revision 1.13.2.2
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.5  christos  * Module Name: tbxface - ACPI table-oriented external interfaces
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.3    jruoho /*
      8  1.13.2.2    martin  * Copyright (C) 2000 - 2020, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.3    jruoho  * modification, are permitted provided that the following conditions
     13       1.3    jruoho  * are met:
     14       1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.3    jruoho  *    without modification.
     17       1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.3    jruoho  *    binary redistribution.
     22       1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.3    jruoho  *    from this software without specific prior written permission.
     25       1.3    jruoho  *
     26       1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.3    jruoho  * Software Foundation.
     29       1.3    jruoho  *
     30       1.3    jruoho  * NO WARRANTY
     31       1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.3    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.3    jruoho  */
     43       1.1    jruoho 
     44       1.5  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.5  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.10  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.5  christos      * Setup the Root Table Array and allocate the table array
    121       1.5  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.8  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.13.2.1  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.5  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.5  christos  *              kernel.
    179       1.1    jruoho  *
    180       1.1    jruoho  ******************************************************************************/
    181       1.1    jruoho 
    182      1.10  christos ACPI_STATUS ACPI_INIT_FUNCTION
    183       1.1    jruoho AcpiReallocateRootTable (
    184       1.1    jruoho     void)
    185       1.1    jruoho {
    186       1.5  christos     ACPI_STATUS             Status;
    187      1.12  christos     ACPI_TABLE_DESC         *TableDesc;
    188      1.12  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.12  christos      * If there are tables unverified, it is required to reallocate the
    196      1.12  christos      * root table list to clean up invalid table entries. Otherwise only
    197      1.12  christos      * reallocate the root table list if the host provided a static buffer
    198      1.12  christos      * for the table array in the call to AcpiInitializeTables().
    199       1.1    jruoho      */
    200      1.12  christos     if ((AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
    201      1.12  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.12  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    207      1.12  christos 
    208      1.11  christos     /*
    209      1.11  christos      * Ensure OS early boot logic, which is required by some hosts. If the
    210      1.11  christos      * table state is reported to be wrong, developers should fix the
    211      1.11  christos      * issue by invoking AcpiPutTable() for the reported table during the
    212      1.11  christos      * early stage.
    213      1.11  christos      */
    214      1.11  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    215      1.11  christos     {
    216      1.12  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    217      1.12  christos         if (TableDesc->Pointer)
    218      1.11  christos         {
    219      1.11  christos             ACPI_ERROR ((AE_INFO,
    220      1.11  christos                 "Table [%4.4s] is not invalidated during early boot stage",
    221      1.12  christos                 TableDesc->Signature.Ascii));
    222      1.12  christos         }
    223      1.12  christos     }
    224      1.12  christos 
    225      1.12  christos     if (!AcpiGbl_EnableTableValidation)
    226      1.12  christos     {
    227      1.12  christos         /*
    228      1.12  christos          * Now it's safe to do full table validation. We can do deferred
    229  1.13.2.1  christos          * table initialization here once the flag is set.
    230      1.12  christos          */
    231      1.12  christos         AcpiGbl_EnableTableValidation = TRUE;
    232      1.12  christos         for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    233      1.12  christos         {
    234      1.12  christos             TableDesc = &AcpiGbl_RootTableList.Tables[i];
    235      1.12  christos             if (!(TableDesc->Flags & ACPI_TABLE_IS_VERIFIED))
    236      1.12  christos             {
    237      1.12  christos                 Status = AcpiTbVerifyTempTable (TableDesc, NULL, &j);
    238      1.12  christos                 if (ACPI_FAILURE (Status))
    239      1.12  christos                 {
    240      1.12  christos                     AcpiTbUninstallTable (TableDesc);
    241      1.12  christos                 }
    242      1.12  christos             }
    243      1.11  christos         }
    244      1.11  christos     }
    245      1.11  christos 
    246       1.5  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
    247      1.12  christos     Status = AcpiTbResizeRootTableList ();
    248      1.12  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
    249       1.1    jruoho 
    250      1.12  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    251       1.5  christos     return_ACPI_STATUS (Status);
    252       1.1    jruoho }
    253       1.1    jruoho 
    254       1.5  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.13.2.2    martin  *              OutTableHeader      - The pointer to the where the table header
    264  1.13.2.2    martin  *                                    is returned
    265       1.1    jruoho  *
    266  1.13.2.2    martin  * RETURN:      Status and a copy of the table header
    267       1.1    jruoho  *
    268  1.13.2.2    martin  * DESCRIPTION: Finds and returns an ACPI table header. Caller provides the
    269  1.13.2.2    martin  *              memory where a copy of the header is to be returned
    270  1.13.2.2    martin  *              (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.2    jruoho     ACPI_CONST_STRING       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     /* Parameter validation */
    285       1.1    jruoho 
    286       1.1    jruoho     if (!Signature || !OutTableHeader)
    287       1.1    jruoho     {
    288       1.1    jruoho         return (AE_BAD_PARAMETER);
    289       1.1    jruoho     }
    290       1.1    jruoho 
    291       1.1    jruoho     /* Walk the root table list */
    292       1.1    jruoho 
    293       1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    294       1.1    jruoho     {
    295  1.13.2.1  christos         if (!ACPI_COMPARE_NAMESEG (
    296       1.9  christos                 &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
    297       1.1    jruoho         {
    298       1.1    jruoho             continue;
    299       1.1    jruoho         }
    300       1.1    jruoho 
    301       1.1    jruoho         if (++j < Instance)
    302       1.1    jruoho         {
    303       1.1    jruoho             continue;
    304       1.1    jruoho         }
    305       1.1    jruoho 
    306       1.1    jruoho         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    307       1.1    jruoho         {
    308       1.1    jruoho             if ((AcpiGbl_RootTableList.Tables[i].Flags &
    309       1.1    jruoho                     ACPI_TABLE_ORIGIN_MASK) ==
    310       1.6  christos                 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
    311       1.1    jruoho             {
    312       1.1    jruoho                 Header = AcpiOsMapMemory (
    313       1.9  christos                     AcpiGbl_RootTableList.Tables[i].Address,
    314       1.9  christos                     sizeof (ACPI_TABLE_HEADER));
    315       1.1    jruoho                 if (!Header)
    316       1.1    jruoho                 {
    317       1.5  christos                     return (AE_NO_MEMORY);
    318       1.1    jruoho                 }
    319       1.1    jruoho 
    320       1.9  christos                 memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
    321       1.5  christos                 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
    322       1.1    jruoho             }
    323       1.1    jruoho             else
    324       1.1    jruoho             {
    325       1.5  christos                 return (AE_NOT_FOUND);
    326       1.1    jruoho             }
    327       1.1    jruoho         }
    328       1.1    jruoho         else
    329       1.1    jruoho         {
    330       1.8  christos             memcpy (OutTableHeader,
    331       1.1    jruoho                 AcpiGbl_RootTableList.Tables[i].Pointer,
    332       1.5  christos                 sizeof (ACPI_TABLE_HEADER));
    333       1.1    jruoho         }
    334       1.1    jruoho 
    335       1.1    jruoho         return (AE_OK);
    336       1.1    jruoho     }
    337       1.1    jruoho 
    338       1.1    jruoho     return (AE_NOT_FOUND);
    339       1.1    jruoho }
    340       1.1    jruoho 
    341       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
    342       1.1    jruoho 
    343       1.1    jruoho 
    344       1.1    jruoho /*******************************************************************************
    345       1.1    jruoho  *
    346       1.1    jruoho  * FUNCTION:    AcpiGetTable
    347       1.1    jruoho  *
    348       1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature of needed table
    349       1.1    jruoho  *              Instance            - Which instance (for SSDTs)
    350       1.1    jruoho  *              OutTable            - Where the pointer to the table is returned
    351       1.1    jruoho  *
    352       1.5  christos  * RETURN:      Status and pointer to the requested table
    353       1.1    jruoho  *
    354       1.5  christos  * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
    355       1.5  christos  *              RSDT/XSDT.
    356      1.11  christos  *              Note that an early stage AcpiGetTable() call must be paired
    357      1.11  christos  *              with an early stage AcpiPutTable() call. otherwise the table
    358      1.11  christos  *              pointer mapped by the early stage mapping implementation may be
    359      1.11  christos  *              erroneously unmapped by the late stage unmapping implementation
    360      1.11  christos  *              in an AcpiPutTable() invoked during the late stage.
    361       1.1    jruoho  *
    362       1.1    jruoho  ******************************************************************************/
    363       1.1    jruoho 
    364       1.1    jruoho ACPI_STATUS
    365       1.1    jruoho AcpiGetTable (
    366       1.2    jruoho     ACPI_CONST_STRING       Signature,
    367       1.1    jruoho     UINT32                  Instance,
    368       1.1    jruoho     ACPI_TABLE_HEADER       **OutTable)
    369       1.1    jruoho {
    370       1.1    jruoho     UINT32                  i;
    371       1.1    jruoho     UINT32                  j;
    372      1.11  christos     ACPI_STATUS             Status = AE_NOT_FOUND;
    373      1.11  christos     ACPI_TABLE_DESC         *TableDesc;
    374       1.1    jruoho 
    375       1.1    jruoho     /* Parameter validation */
    376       1.1    jruoho 
    377       1.1    jruoho     if (!Signature || !OutTable)
    378       1.1    jruoho     {
    379       1.1    jruoho         return (AE_BAD_PARAMETER);
    380       1.1    jruoho     }
    381       1.1    jruoho 
    382      1.11  christos     /*
    383      1.11  christos      * Note that the following line is required by some OSPMs, they only
    384      1.11  christos      * check if the returned table is NULL instead of the returned status
    385      1.11  christos      * to determined if this function is succeeded.
    386      1.11  christos      */
    387      1.11  christos     *OutTable = NULL;
    388      1.11  christos 
    389      1.11  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    390      1.11  christos 
    391       1.1    jruoho     /* Walk the root table list */
    392       1.1    jruoho 
    393       1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    394       1.1    jruoho     {
    395      1.11  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    396      1.11  christos 
    397  1.13.2.1  christos         if (!ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))
    398       1.1    jruoho         {
    399       1.1    jruoho             continue;
    400       1.1    jruoho         }
    401       1.1    jruoho 
    402       1.1    jruoho         if (++j < Instance)
    403       1.1    jruoho         {
    404       1.1    jruoho             continue;
    405       1.1    jruoho         }
    406       1.1    jruoho 
    407      1.11  christos         Status = AcpiTbGetTable (TableDesc, OutTable);
    408      1.11  christos         break;
    409      1.11  christos     }
    410      1.11  christos 
    411      1.11  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    412      1.11  christos     return (Status);
    413      1.11  christos }
    414      1.11  christos 
    415      1.11  christos ACPI_EXPORT_SYMBOL (AcpiGetTable)
    416      1.11  christos 
    417      1.11  christos 
    418      1.11  christos /*******************************************************************************
    419      1.11  christos  *
    420      1.11  christos  * FUNCTION:    AcpiPutTable
    421      1.11  christos  *
    422      1.11  christos  * PARAMETERS:  Table               - The pointer to the table
    423      1.11  christos  *
    424      1.11  christos  * RETURN:      None
    425      1.11  christos  *
    426      1.11  christos  * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
    427      1.11  christos  *              Note that it is not safe if this function was invoked after an
    428      1.11  christos  *              uninstallation happened to the original table descriptor.
    429      1.11  christos  *              Currently there is no OSPMs' requirement to handle such
    430      1.11  christos  *              situations.
    431      1.11  christos  *
    432      1.11  christos  ******************************************************************************/
    433      1.11  christos 
    434      1.11  christos void
    435      1.11  christos AcpiPutTable (
    436      1.11  christos     ACPI_TABLE_HEADER       *Table)
    437      1.11  christos {
    438      1.11  christos     UINT32                  i;
    439      1.11  christos     ACPI_TABLE_DESC         *TableDesc;
    440      1.11  christos 
    441      1.11  christos 
    442      1.11  christos     ACPI_FUNCTION_TRACE (AcpiPutTable);
    443      1.11  christos 
    444      1.11  christos 
    445      1.12  christos     if (!Table)
    446      1.12  christos     {
    447      1.12  christos         return_VOID;
    448      1.12  christos     }
    449      1.12  christos 
    450      1.11  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    451      1.11  christos 
    452      1.11  christos     /* Walk the root table list */
    453      1.11  christos 
    454      1.11  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    455      1.11  christos     {
    456      1.11  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    457      1.11  christos 
    458      1.11  christos         if (TableDesc->Pointer != Table)
    459       1.1    jruoho         {
    460      1.11  christos             continue;
    461       1.1    jruoho         }
    462       1.1    jruoho 
    463      1.11  christos         AcpiTbPutTable (TableDesc);
    464      1.11  christos         break;
    465       1.1    jruoho     }
    466       1.1    jruoho 
    467      1.11  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    468      1.11  christos     return_VOID;
    469       1.1    jruoho }
    470       1.1    jruoho 
    471      1.11  christos ACPI_EXPORT_SYMBOL (AcpiPutTable)
    472       1.1    jruoho 
    473       1.1    jruoho 
    474       1.1    jruoho /*******************************************************************************
    475       1.1    jruoho  *
    476       1.1    jruoho  * FUNCTION:    AcpiGetTableByIndex
    477       1.1    jruoho  *
    478       1.1    jruoho  * PARAMETERS:  TableIndex          - Table index
    479      1.11  christos  *              OutTable            - Where the pointer to the table is returned
    480       1.1    jruoho  *
    481       1.5  christos  * RETURN:      Status and pointer to the requested table
    482       1.1    jruoho  *
    483       1.5  christos  * DESCRIPTION: Obtain a table by an index into the global table list. Used
    484       1.5  christos  *              internally also.
    485       1.1    jruoho  *
    486       1.1    jruoho  ******************************************************************************/
    487       1.1    jruoho 
    488       1.1    jruoho ACPI_STATUS
    489       1.1    jruoho AcpiGetTableByIndex (
    490       1.1    jruoho     UINT32                  TableIndex,
    491      1.11  christos     ACPI_TABLE_HEADER       **OutTable)
    492       1.1    jruoho {
    493       1.1    jruoho     ACPI_STATUS             Status;
    494       1.1    jruoho 
    495       1.1    jruoho 
    496       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
    497       1.1    jruoho 
    498       1.1    jruoho 
    499       1.1    jruoho     /* Parameter validation */
    500       1.1    jruoho 
    501      1.11  christos     if (!OutTable)
    502       1.1    jruoho     {
    503       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    504       1.1    jruoho     }
    505       1.1    jruoho 
    506      1.11  christos     /*
    507      1.11  christos      * Note that the following line is required by some OSPMs, they only
    508      1.11  christos      * check if the returned table is NULL instead of the returned status
    509      1.11  christos      * to determined if this function is succeeded.
    510      1.11  christos      */
    511      1.11  christos     *OutTable = NULL;
    512      1.11  christos 
    513       1.1    jruoho     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    514       1.1    jruoho 
    515       1.1    jruoho     /* Validate index */
    516       1.1    jruoho 
    517       1.1    jruoho     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    518       1.1    jruoho     {
    519      1.11  christos         Status = AE_BAD_PARAMETER;
    520      1.11  christos         goto UnlockAndExit;
    521       1.1    jruoho     }
    522       1.1    jruoho 
    523      1.11  christos     Status = AcpiTbGetTable (
    524      1.11  christos         &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
    525       1.1    jruoho 
    526      1.11  christos UnlockAndExit:
    527       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    528      1.11  christos     return_ACPI_STATUS (Status);
    529       1.1    jruoho }
    530       1.1    jruoho 
    531       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
    532       1.1    jruoho 
    533       1.1    jruoho 
    534       1.1    jruoho /*******************************************************************************
    535       1.1    jruoho  *
    536       1.1    jruoho  * FUNCTION:    AcpiInstallTableHandler
    537       1.1    jruoho  *
    538       1.1    jruoho  * PARAMETERS:  Handler         - Table event handler
    539       1.1    jruoho  *              Context         - Value passed to the handler on each event
    540       1.1    jruoho  *
    541       1.1    jruoho  * RETURN:      Status
    542       1.1    jruoho  *
    543       1.5  christos  * DESCRIPTION: Install a global table event handler.
    544       1.1    jruoho  *
    545       1.1    jruoho  ******************************************************************************/
    546       1.1    jruoho 
    547       1.1    jruoho ACPI_STATUS
    548       1.1    jruoho AcpiInstallTableHandler (
    549       1.1    jruoho     ACPI_TABLE_HANDLER      Handler,
    550       1.1    jruoho     void                    *Context)
    551       1.1    jruoho {
    552       1.1    jruoho     ACPI_STATUS             Status;
    553       1.1    jruoho 
    554       1.1    jruoho 
    555       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
    556       1.1    jruoho 
    557       1.1    jruoho 
    558       1.1    jruoho     if (!Handler)
    559       1.1    jruoho     {
    560       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    561       1.1    jruoho     }
    562       1.1    jruoho 
    563       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    564       1.1    jruoho     if (ACPI_FAILURE (Status))
    565       1.1    jruoho     {
    566       1.1    jruoho         return_ACPI_STATUS (Status);
    567       1.1    jruoho     }
    568       1.1    jruoho 
    569       1.1    jruoho     /* Don't allow more than one handler */
    570       1.1    jruoho 
    571       1.1    jruoho     if (AcpiGbl_TableHandler)
    572       1.1    jruoho     {
    573       1.1    jruoho         Status = AE_ALREADY_EXISTS;
    574       1.1    jruoho         goto Cleanup;
    575       1.1    jruoho     }
    576       1.1    jruoho 
    577       1.1    jruoho     /* Install the handler */
    578       1.1    jruoho 
    579       1.1    jruoho     AcpiGbl_TableHandler = Handler;
    580       1.1    jruoho     AcpiGbl_TableHandlerContext = Context;
    581       1.1    jruoho 
    582       1.1    jruoho Cleanup:
    583       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    584       1.1    jruoho     return_ACPI_STATUS (Status);
    585       1.1    jruoho }
    586       1.1    jruoho 
    587       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
    588       1.1    jruoho 
    589       1.1    jruoho 
    590       1.1    jruoho /*******************************************************************************
    591       1.1    jruoho  *
    592       1.1    jruoho  * FUNCTION:    AcpiRemoveTableHandler
    593       1.1    jruoho  *
    594       1.1    jruoho  * PARAMETERS:  Handler         - Table event handler that was installed
    595       1.1    jruoho  *                                previously.
    596       1.1    jruoho  *
    597       1.1    jruoho  * RETURN:      Status
    598       1.1    jruoho  *
    599       1.5  christos  * DESCRIPTION: Remove a table event handler
    600       1.1    jruoho  *
    601       1.1    jruoho  ******************************************************************************/
    602       1.1    jruoho 
    603       1.1    jruoho ACPI_STATUS
    604       1.1    jruoho AcpiRemoveTableHandler (
    605       1.1    jruoho     ACPI_TABLE_HANDLER      Handler)
    606       1.1    jruoho {
    607       1.1    jruoho     ACPI_STATUS             Status;
    608       1.1    jruoho 
    609       1.1    jruoho 
    610       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
    611       1.1    jruoho 
    612       1.1    jruoho 
    613       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    614       1.1    jruoho     if (ACPI_FAILURE (Status))
    615       1.1    jruoho     {
    616       1.1    jruoho         return_ACPI_STATUS (Status);
    617       1.1    jruoho     }
    618       1.1    jruoho 
    619       1.1    jruoho     /* Make sure that the installed handler is the same */
    620       1.1    jruoho 
    621       1.1    jruoho     if (!Handler ||
    622       1.1    jruoho         Handler != AcpiGbl_TableHandler)
    623       1.1    jruoho     {
    624       1.1    jruoho         Status = AE_BAD_PARAMETER;
    625       1.1    jruoho         goto Cleanup;
    626       1.1    jruoho     }
    627       1.1    jruoho 
    628       1.1    jruoho     /* Remove the handler */
    629       1.1    jruoho 
    630       1.1    jruoho     AcpiGbl_TableHandler = NULL;
    631       1.1    jruoho 
    632       1.1    jruoho Cleanup:
    633       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    634       1.1    jruoho     return_ACPI_STATUS (Status);
    635       1.1    jruoho }
    636       1.1    jruoho 
    637       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
    638