Home | History | Annotate | Line # | Download | only in tables
tbxface.c revision 1.1.1.9
      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.9  christos  * Copyright (C) 2000 - 2017, 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.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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    jruoho      * in a common, more useable 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.9  christos     UINT32                  i;
    188      1.1    jruoho 
    189      1.1    jruoho 
    190      1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
    191      1.1    jruoho 
    192      1.1    jruoho 
    193      1.1    jruoho     /*
    194      1.1    jruoho      * Only reallocate the root table if the host provided a static buffer
    195      1.1    jruoho      * for the table array in the call to AcpiInitializeTables.
    196      1.1    jruoho      */
    197      1.1    jruoho     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    198      1.1    jruoho     {
    199      1.1    jruoho         return_ACPI_STATUS (AE_SUPPORT);
    200      1.1    jruoho     }
    201      1.1    jruoho 
    202  1.1.1.9  christos     /*
    203  1.1.1.9  christos      * Ensure OS early boot logic, which is required by some hosts. If the
    204  1.1.1.9  christos      * table state is reported to be wrong, developers should fix the
    205  1.1.1.9  christos      * issue by invoking AcpiPutTable() for the reported table during the
    206  1.1.1.9  christos      * early stage.
    207  1.1.1.9  christos      */
    208  1.1.1.9  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    209  1.1.1.9  christos     {
    210  1.1.1.9  christos         if (AcpiGbl_RootTableList.Tables[i].Pointer)
    211  1.1.1.9  christos         {
    212  1.1.1.9  christos             ACPI_ERROR ((AE_INFO,
    213  1.1.1.9  christos                 "Table [%4.4s] is not invalidated during early boot stage",
    214  1.1.1.9  christos                 AcpiGbl_RootTableList.Tables[i].Signature.Ascii));
    215  1.1.1.9  christos         }
    216  1.1.1.9  christos     }
    217  1.1.1.9  christos 
    218  1.1.1.3  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
    219      1.1    jruoho 
    220  1.1.1.3  christos     Status = AcpiTbResizeRootTableList ();
    221  1.1.1.3  christos     return_ACPI_STATUS (Status);
    222      1.1    jruoho }
    223      1.1    jruoho 
    224  1.1.1.3  christos ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
    225      1.1    jruoho 
    226      1.1    jruoho 
    227      1.1    jruoho /*******************************************************************************
    228      1.1    jruoho  *
    229      1.1    jruoho  * FUNCTION:    AcpiGetTableHeader
    230      1.1    jruoho  *
    231      1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature of needed table
    232      1.1    jruoho  *              Instance            - Which instance (for SSDTs)
    233      1.1    jruoho  *              OutTableHeader      - The pointer to the table header to fill
    234      1.1    jruoho  *
    235      1.1    jruoho  * RETURN:      Status and pointer to mapped table header
    236      1.1    jruoho  *
    237      1.1    jruoho  * DESCRIPTION: Finds an ACPI table header.
    238      1.1    jruoho  *
    239      1.1    jruoho  * NOTE:        Caller is responsible in unmapping the header with
    240      1.1    jruoho  *              AcpiOsUnmapMemory
    241      1.1    jruoho  *
    242      1.1    jruoho  ******************************************************************************/
    243      1.1    jruoho 
    244      1.1    jruoho ACPI_STATUS
    245      1.1    jruoho AcpiGetTableHeader (
    246      1.1    jruoho     char                    *Signature,
    247      1.1    jruoho     UINT32                  Instance,
    248      1.1    jruoho     ACPI_TABLE_HEADER       *OutTableHeader)
    249      1.1    jruoho {
    250      1.1    jruoho     UINT32                  i;
    251      1.1    jruoho     UINT32                  j;
    252      1.1    jruoho     ACPI_TABLE_HEADER       *Header;
    253      1.1    jruoho 
    254      1.1    jruoho 
    255      1.1    jruoho     /* Parameter validation */
    256      1.1    jruoho 
    257      1.1    jruoho     if (!Signature || !OutTableHeader)
    258      1.1    jruoho     {
    259      1.1    jruoho         return (AE_BAD_PARAMETER);
    260      1.1    jruoho     }
    261      1.1    jruoho 
    262      1.1    jruoho     /* Walk the root table list */
    263      1.1    jruoho 
    264      1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    265      1.1    jruoho     {
    266  1.1.1.7  christos         if (!ACPI_COMPARE_NAME (
    267  1.1.1.7  christos                 &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
    268      1.1    jruoho         {
    269      1.1    jruoho             continue;
    270      1.1    jruoho         }
    271      1.1    jruoho 
    272      1.1    jruoho         if (++j < Instance)
    273      1.1    jruoho         {
    274      1.1    jruoho             continue;
    275      1.1    jruoho         }
    276      1.1    jruoho 
    277      1.1    jruoho         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
    278      1.1    jruoho         {
    279      1.1    jruoho             if ((AcpiGbl_RootTableList.Tables[i].Flags &
    280      1.1    jruoho                     ACPI_TABLE_ORIGIN_MASK) ==
    281  1.1.1.4  christos                 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
    282      1.1    jruoho             {
    283      1.1    jruoho                 Header = AcpiOsMapMemory (
    284  1.1.1.7  christos                     AcpiGbl_RootTableList.Tables[i].Address,
    285  1.1.1.7  christos                     sizeof (ACPI_TABLE_HEADER));
    286      1.1    jruoho                 if (!Header)
    287      1.1    jruoho                 {
    288  1.1.1.3  christos                     return (AE_NO_MEMORY);
    289      1.1    jruoho                 }
    290      1.1    jruoho 
    291  1.1.1.7  christos                 memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
    292  1.1.1.3  christos                 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
    293      1.1    jruoho             }
    294      1.1    jruoho             else
    295      1.1    jruoho             {
    296  1.1.1.3  christos                 return (AE_NOT_FOUND);
    297      1.1    jruoho             }
    298      1.1    jruoho         }
    299      1.1    jruoho         else
    300      1.1    jruoho         {
    301  1.1.1.6  christos             memcpy (OutTableHeader,
    302      1.1    jruoho                 AcpiGbl_RootTableList.Tables[i].Pointer,
    303  1.1.1.3  christos                 sizeof (ACPI_TABLE_HEADER));
    304      1.1    jruoho         }
    305      1.1    jruoho 
    306      1.1    jruoho         return (AE_OK);
    307      1.1    jruoho     }
    308      1.1    jruoho 
    309      1.1    jruoho     return (AE_NOT_FOUND);
    310      1.1    jruoho }
    311      1.1    jruoho 
    312      1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
    313      1.1    jruoho 
    314      1.1    jruoho 
    315      1.1    jruoho /*******************************************************************************
    316      1.1    jruoho  *
    317      1.1    jruoho  * FUNCTION:    AcpiGetTable
    318      1.1    jruoho  *
    319      1.1    jruoho  * PARAMETERS:  Signature           - ACPI signature of needed table
    320      1.1    jruoho  *              Instance            - Which instance (for SSDTs)
    321      1.1    jruoho  *              OutTable            - Where the pointer to the table is returned
    322      1.1    jruoho  *
    323  1.1.1.3  christos  * RETURN:      Status and pointer to the requested table
    324      1.1    jruoho  *
    325  1.1.1.3  christos  * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
    326  1.1.1.3  christos  *              RSDT/XSDT.
    327  1.1.1.9  christos  *              Note that an early stage AcpiGetTable() call must be paired
    328  1.1.1.9  christos  *              with an early stage AcpiPutTable() call. otherwise the table
    329  1.1.1.9  christos  *              pointer mapped by the early stage mapping implementation may be
    330  1.1.1.9  christos  *              erroneously unmapped by the late stage unmapping implementation
    331  1.1.1.9  christos  *              in an AcpiPutTable() invoked during the late stage.
    332      1.1    jruoho  *
    333      1.1    jruoho  ******************************************************************************/
    334      1.1    jruoho 
    335      1.1    jruoho ACPI_STATUS
    336      1.1    jruoho AcpiGetTable (
    337      1.1    jruoho     char                    *Signature,
    338      1.1    jruoho     UINT32                  Instance,
    339      1.1    jruoho     ACPI_TABLE_HEADER       **OutTable)
    340      1.1    jruoho {
    341      1.1    jruoho     UINT32                  i;
    342      1.1    jruoho     UINT32                  j;
    343  1.1.1.9  christos     ACPI_STATUS             Status = AE_NOT_FOUND;
    344  1.1.1.9  christos     ACPI_TABLE_DESC         *TableDesc;
    345      1.1    jruoho 
    346      1.1    jruoho 
    347      1.1    jruoho     /* Parameter validation */
    348      1.1    jruoho 
    349      1.1    jruoho     if (!Signature || !OutTable)
    350      1.1    jruoho     {
    351      1.1    jruoho         return (AE_BAD_PARAMETER);
    352      1.1    jruoho     }
    353      1.1    jruoho 
    354  1.1.1.9  christos     /*
    355  1.1.1.9  christos      * Note that the following line is required by some OSPMs, they only
    356  1.1.1.9  christos      * check if the returned table is NULL instead of the returned status
    357  1.1.1.9  christos      * to determined if this function is succeeded.
    358  1.1.1.9  christos      */
    359  1.1.1.9  christos     *OutTable = NULL;
    360  1.1.1.9  christos 
    361  1.1.1.9  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    362  1.1.1.9  christos 
    363      1.1    jruoho     /* Walk the root table list */
    364      1.1    jruoho 
    365      1.1    jruoho     for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    366      1.1    jruoho     {
    367  1.1.1.9  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    368  1.1.1.9  christos 
    369  1.1.1.9  christos         if (!ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
    370      1.1    jruoho         {
    371      1.1    jruoho             continue;
    372      1.1    jruoho         }
    373      1.1    jruoho 
    374      1.1    jruoho         if (++j < Instance)
    375      1.1    jruoho         {
    376      1.1    jruoho             continue;
    377      1.1    jruoho         }
    378      1.1    jruoho 
    379  1.1.1.9  christos         Status = AcpiTbGetTable (TableDesc, OutTable);
    380  1.1.1.9  christos         break;
    381  1.1.1.9  christos     }
    382  1.1.1.9  christos 
    383  1.1.1.9  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    384  1.1.1.9  christos     return (Status);
    385  1.1.1.9  christos }
    386  1.1.1.9  christos 
    387  1.1.1.9  christos ACPI_EXPORT_SYMBOL (AcpiGetTable)
    388  1.1.1.9  christos 
    389  1.1.1.9  christos 
    390  1.1.1.9  christos /*******************************************************************************
    391  1.1.1.9  christos  *
    392  1.1.1.9  christos  * FUNCTION:    AcpiPutTable
    393  1.1.1.9  christos  *
    394  1.1.1.9  christos  * PARAMETERS:  Table               - The pointer to the table
    395  1.1.1.9  christos  *
    396  1.1.1.9  christos  * RETURN:      None
    397  1.1.1.9  christos  *
    398  1.1.1.9  christos  * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
    399  1.1.1.9  christos  *              Note that it is not safe if this function was invoked after an
    400  1.1.1.9  christos  *              uninstallation happened to the original table descriptor.
    401  1.1.1.9  christos  *              Currently there is no OSPMs' requirement to handle such
    402  1.1.1.9  christos  *              situations.
    403  1.1.1.9  christos  *
    404  1.1.1.9  christos  ******************************************************************************/
    405  1.1.1.9  christos 
    406  1.1.1.9  christos void
    407  1.1.1.9  christos AcpiPutTable (
    408  1.1.1.9  christos     ACPI_TABLE_HEADER       *Table)
    409  1.1.1.9  christos {
    410  1.1.1.9  christos     UINT32                  i;
    411  1.1.1.9  christos     ACPI_TABLE_DESC         *TableDesc;
    412  1.1.1.9  christos 
    413  1.1.1.9  christos 
    414  1.1.1.9  christos     ACPI_FUNCTION_TRACE (AcpiPutTable);
    415  1.1.1.9  christos 
    416  1.1.1.9  christos 
    417  1.1.1.9  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    418  1.1.1.9  christos 
    419  1.1.1.9  christos     /* Walk the root table list */
    420  1.1.1.9  christos 
    421  1.1.1.9  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    422  1.1.1.9  christos     {
    423  1.1.1.9  christos         TableDesc = &AcpiGbl_RootTableList.Tables[i];
    424  1.1.1.9  christos 
    425  1.1.1.9  christos         if (TableDesc->Pointer != Table)
    426      1.1    jruoho         {
    427  1.1.1.9  christos             continue;
    428      1.1    jruoho         }
    429      1.1    jruoho 
    430  1.1.1.9  christos         AcpiTbPutTable (TableDesc);
    431  1.1.1.9  christos         break;
    432      1.1    jruoho     }
    433      1.1    jruoho 
    434  1.1.1.9  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    435  1.1.1.9  christos     return_VOID;
    436      1.1    jruoho }
    437      1.1    jruoho 
    438  1.1.1.9  christos ACPI_EXPORT_SYMBOL (AcpiPutTable)
    439      1.1    jruoho 
    440      1.1    jruoho 
    441      1.1    jruoho /*******************************************************************************
    442      1.1    jruoho  *
    443      1.1    jruoho  * FUNCTION:    AcpiGetTableByIndex
    444      1.1    jruoho  *
    445      1.1    jruoho  * PARAMETERS:  TableIndex          - Table index
    446  1.1.1.9  christos  *              OutTable            - Where the pointer to the table is returned
    447      1.1    jruoho  *
    448  1.1.1.3  christos  * RETURN:      Status and pointer to the requested table
    449      1.1    jruoho  *
    450  1.1.1.3  christos  * DESCRIPTION: Obtain a table by an index into the global table list. Used
    451  1.1.1.3  christos  *              internally also.
    452      1.1    jruoho  *
    453      1.1    jruoho  ******************************************************************************/
    454      1.1    jruoho 
    455      1.1    jruoho ACPI_STATUS
    456      1.1    jruoho AcpiGetTableByIndex (
    457      1.1    jruoho     UINT32                  TableIndex,
    458  1.1.1.9  christos     ACPI_TABLE_HEADER       **OutTable)
    459      1.1    jruoho {
    460      1.1    jruoho     ACPI_STATUS             Status;
    461      1.1    jruoho 
    462      1.1    jruoho 
    463      1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
    464      1.1    jruoho 
    465      1.1    jruoho 
    466      1.1    jruoho     /* Parameter validation */
    467      1.1    jruoho 
    468  1.1.1.9  christos     if (!OutTable)
    469      1.1    jruoho     {
    470      1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    471      1.1    jruoho     }
    472      1.1    jruoho 
    473  1.1.1.9  christos     /*
    474  1.1.1.9  christos      * Note that the following line is required by some OSPMs, they only
    475  1.1.1.9  christos      * check if the returned table is NULL instead of the returned status
    476  1.1.1.9  christos      * to determined if this function is succeeded.
    477  1.1.1.9  christos      */
    478  1.1.1.9  christos     *OutTable = NULL;
    479  1.1.1.9  christos 
    480      1.1    jruoho     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    481      1.1    jruoho 
    482      1.1    jruoho     /* Validate index */
    483      1.1    jruoho 
    484      1.1    jruoho     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    485      1.1    jruoho     {
    486  1.1.1.9  christos         Status = AE_BAD_PARAMETER;
    487  1.1.1.9  christos         goto UnlockAndExit;
    488      1.1    jruoho     }
    489      1.1    jruoho 
    490  1.1.1.9  christos     Status = AcpiTbGetTable (
    491  1.1.1.9  christos         &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
    492      1.1    jruoho 
    493  1.1.1.9  christos UnlockAndExit:
    494      1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    495  1.1.1.9  christos     return_ACPI_STATUS (Status);
    496      1.1    jruoho }
    497      1.1    jruoho 
    498      1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
    499      1.1    jruoho 
    500      1.1    jruoho 
    501      1.1    jruoho /*******************************************************************************
    502      1.1    jruoho  *
    503      1.1    jruoho  * FUNCTION:    AcpiInstallTableHandler
    504      1.1    jruoho  *
    505      1.1    jruoho  * PARAMETERS:  Handler         - Table event handler
    506      1.1    jruoho  *              Context         - Value passed to the handler on each event
    507      1.1    jruoho  *
    508      1.1    jruoho  * RETURN:      Status
    509      1.1    jruoho  *
    510  1.1.1.3  christos  * DESCRIPTION: Install a global table event handler.
    511      1.1    jruoho  *
    512      1.1    jruoho  ******************************************************************************/
    513      1.1    jruoho 
    514      1.1    jruoho ACPI_STATUS
    515      1.1    jruoho AcpiInstallTableHandler (
    516      1.1    jruoho     ACPI_TABLE_HANDLER      Handler,
    517      1.1    jruoho     void                    *Context)
    518      1.1    jruoho {
    519      1.1    jruoho     ACPI_STATUS             Status;
    520      1.1    jruoho 
    521      1.1    jruoho 
    522      1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
    523      1.1    jruoho 
    524      1.1    jruoho 
    525      1.1    jruoho     if (!Handler)
    526      1.1    jruoho     {
    527      1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    528      1.1    jruoho     }
    529      1.1    jruoho 
    530      1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    531      1.1    jruoho     if (ACPI_FAILURE (Status))
    532      1.1    jruoho     {
    533      1.1    jruoho         return_ACPI_STATUS (Status);
    534      1.1    jruoho     }
    535      1.1    jruoho 
    536      1.1    jruoho     /* Don't allow more than one handler */
    537      1.1    jruoho 
    538      1.1    jruoho     if (AcpiGbl_TableHandler)
    539      1.1    jruoho     {
    540      1.1    jruoho         Status = AE_ALREADY_EXISTS;
    541      1.1    jruoho         goto Cleanup;
    542      1.1    jruoho     }
    543      1.1    jruoho 
    544      1.1    jruoho     /* Install the handler */
    545      1.1    jruoho 
    546      1.1    jruoho     AcpiGbl_TableHandler = Handler;
    547      1.1    jruoho     AcpiGbl_TableHandlerContext = Context;
    548      1.1    jruoho 
    549      1.1    jruoho Cleanup:
    550      1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    551      1.1    jruoho     return_ACPI_STATUS (Status);
    552      1.1    jruoho }
    553      1.1    jruoho 
    554      1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
    555      1.1    jruoho 
    556      1.1    jruoho 
    557      1.1    jruoho /*******************************************************************************
    558      1.1    jruoho  *
    559      1.1    jruoho  * FUNCTION:    AcpiRemoveTableHandler
    560      1.1    jruoho  *
    561      1.1    jruoho  * PARAMETERS:  Handler         - Table event handler that was installed
    562      1.1    jruoho  *                                previously.
    563      1.1    jruoho  *
    564      1.1    jruoho  * RETURN:      Status
    565      1.1    jruoho  *
    566  1.1.1.3  christos  * DESCRIPTION: Remove a table event handler
    567      1.1    jruoho  *
    568      1.1    jruoho  ******************************************************************************/
    569      1.1    jruoho 
    570      1.1    jruoho ACPI_STATUS
    571      1.1    jruoho AcpiRemoveTableHandler (
    572      1.1    jruoho     ACPI_TABLE_HANDLER      Handler)
    573      1.1    jruoho {
    574      1.1    jruoho     ACPI_STATUS             Status;
    575      1.1    jruoho 
    576      1.1    jruoho 
    577      1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
    578      1.1    jruoho 
    579      1.1    jruoho 
    580      1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    581      1.1    jruoho     if (ACPI_FAILURE (Status))
    582      1.1    jruoho     {
    583      1.1    jruoho         return_ACPI_STATUS (Status);
    584      1.1    jruoho     }
    585      1.1    jruoho 
    586      1.1    jruoho     /* Make sure that the installed handler is the same */
    587      1.1    jruoho 
    588      1.1    jruoho     if (!Handler ||
    589      1.1    jruoho         Handler != AcpiGbl_TableHandler)
    590      1.1    jruoho     {
    591      1.1    jruoho         Status = AE_BAD_PARAMETER;
    592      1.1    jruoho         goto Cleanup;
    593      1.1    jruoho     }
    594      1.1    jruoho 
    595      1.1    jruoho     /* Remove the handler */
    596      1.1    jruoho 
    597      1.1    jruoho     AcpiGbl_TableHandler = NULL;
    598      1.1    jruoho 
    599      1.1    jruoho Cleanup:
    600      1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    601      1.1    jruoho     return_ACPI_STATUS (Status);
    602      1.1    jruoho }
    603      1.1    jruoho 
    604      1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
    605