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