Home | History | Annotate | Line # | Download | only in tables
tbdata.c revision 1.1.1.9
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: tbdata - Table manager data structure functions
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8  1.1.1.9  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted provided that the following conditions
     13      1.1  christos  * are met:
     14      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.1  christos  *    without modification.
     17      1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.1  christos  *    binary redistribution.
     22      1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1  christos  * Software Foundation.
     29      1.1  christos  *
     30      1.1  christos  * NO WARRANTY
     31      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1  christos  */
     43      1.1  christos 
     44      1.1  christos #include "acpi.h"
     45      1.1  christos #include "accommon.h"
     46      1.1  christos #include "acnamesp.h"
     47      1.1  christos #include "actables.h"
     48  1.1.1.6  christos #include "acevents.h"
     49      1.1  christos 
     50      1.1  christos #define _COMPONENT          ACPI_TABLES
     51      1.1  christos         ACPI_MODULE_NAME    ("tbdata")
     52      1.1  christos 
     53  1.1.1.8  christos /* Local prototypes */
     54  1.1.1.8  christos 
     55  1.1.1.8  christos static ACPI_STATUS
     56  1.1.1.8  christos AcpiTbCheckDuplication (
     57  1.1.1.8  christos     ACPI_TABLE_DESC         *TableDesc,
     58  1.1.1.8  christos     UINT32                  *TableIndex);
     59  1.1.1.8  christos 
     60  1.1.1.8  christos static BOOLEAN
     61  1.1.1.8  christos AcpiTbCompareTables (
     62  1.1.1.8  christos     ACPI_TABLE_DESC         *TableDesc,
     63  1.1.1.8  christos     UINT32                  TableIndex);
     64  1.1.1.8  christos 
     65  1.1.1.8  christos 
     66  1.1.1.8  christos /*******************************************************************************
     67  1.1.1.8  christos  *
     68  1.1.1.8  christos  * FUNCTION:    AcpiTbCompareTables
     69  1.1.1.8  christos  *
     70  1.1.1.8  christos  * PARAMETERS:  TableDesc           - Table 1 descriptor to be compared
     71  1.1.1.8  christos  *              TableIndex          - Index of table 2 to be compared
     72  1.1.1.8  christos  *
     73  1.1.1.8  christos  * RETURN:      TRUE if both tables are identical.
     74  1.1.1.8  christos  *
     75  1.1.1.8  christos  * DESCRIPTION: This function compares a table with another table that has
     76  1.1.1.8  christos  *              already been installed in the root table list.
     77  1.1.1.8  christos  *
     78  1.1.1.8  christos  ******************************************************************************/
     79  1.1.1.8  christos 
     80  1.1.1.8  christos static BOOLEAN
     81  1.1.1.8  christos AcpiTbCompareTables (
     82  1.1.1.8  christos     ACPI_TABLE_DESC         *TableDesc,
     83  1.1.1.8  christos     UINT32                  TableIndex)
     84  1.1.1.8  christos {
     85  1.1.1.8  christos     ACPI_STATUS             Status = AE_OK;
     86  1.1.1.8  christos     BOOLEAN                 IsIdentical;
     87  1.1.1.8  christos     ACPI_TABLE_HEADER       *Table;
     88  1.1.1.8  christos     UINT32                  TableLength;
     89  1.1.1.8  christos     UINT8                   TableFlags;
     90  1.1.1.8  christos 
     91  1.1.1.8  christos 
     92  1.1.1.8  christos     Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
     93  1.1.1.8  christos         &Table, &TableLength, &TableFlags);
     94  1.1.1.8  christos     if (ACPI_FAILURE (Status))
     95  1.1.1.8  christos     {
     96  1.1.1.8  christos         return (FALSE);
     97  1.1.1.8  christos     }
     98  1.1.1.8  christos 
     99  1.1.1.8  christos     /*
    100  1.1.1.8  christos      * Check for a table match on the entire table length,
    101  1.1.1.8  christos      * not just the header.
    102  1.1.1.8  christos      */
    103  1.1.1.8  christos     IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
    104  1.1.1.8  christos         memcmp (TableDesc->Pointer, Table, TableLength)) ?
    105  1.1.1.8  christos         FALSE : TRUE);
    106  1.1.1.8  christos 
    107  1.1.1.8  christos     /* Release the acquired table */
    108  1.1.1.8  christos 
    109  1.1.1.8  christos     AcpiTbReleaseTable (Table, TableLength, TableFlags);
    110  1.1.1.8  christos     return (IsIdentical);
    111  1.1.1.8  christos }
    112  1.1.1.8  christos 
    113      1.1  christos 
    114      1.1  christos /*******************************************************************************
    115      1.1  christos  *
    116      1.1  christos  * FUNCTION:    AcpiTbInitTableDescriptor
    117      1.1  christos  *
    118      1.1  christos  * PARAMETERS:  TableDesc               - Table descriptor
    119      1.1  christos  *              Address                 - Physical address of the table
    120      1.1  christos  *              Flags                   - Allocation flags of the table
    121      1.1  christos  *              Table                   - Pointer to the table
    122      1.1  christos  *
    123      1.1  christos  * RETURN:      None
    124      1.1  christos  *
    125      1.1  christos  * DESCRIPTION: Initialize a new table descriptor
    126      1.1  christos  *
    127      1.1  christos  ******************************************************************************/
    128      1.1  christos 
    129      1.1  christos void
    130      1.1  christos AcpiTbInitTableDescriptor (
    131      1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    132      1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
    133      1.1  christos     UINT8                   Flags,
    134      1.1  christos     ACPI_TABLE_HEADER       *Table)
    135      1.1  christos {
    136      1.1  christos 
    137      1.1  christos     /*
    138      1.1  christos      * Initialize the table descriptor. Set the pointer to NULL, since the
    139      1.1  christos      * table is not fully mapped at this time.
    140      1.1  christos      */
    141  1.1.1.3  christos     memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
    142      1.1  christos     TableDesc->Address = Address;
    143      1.1  christos     TableDesc->Length = Table->Length;
    144      1.1  christos     TableDesc->Flags = Flags;
    145      1.1  christos     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
    146      1.1  christos }
    147      1.1  christos 
    148      1.1  christos 
    149      1.1  christos /*******************************************************************************
    150      1.1  christos  *
    151      1.1  christos  * FUNCTION:    AcpiTbAcquireTable
    152      1.1  christos  *
    153      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    154      1.1  christos  *              TablePtr            - Where table is returned
    155      1.1  christos  *              TableLength         - Where table length is returned
    156      1.1  christos  *              TableFlags          - Where table allocation flags are returned
    157      1.1  christos  *
    158      1.1  christos  * RETURN:      Status
    159      1.1  christos  *
    160      1.1  christos  * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
    161      1.1  christos  *              maintained in the AcpiGbl_RootTableList.
    162      1.1  christos  *
    163      1.1  christos  ******************************************************************************/
    164      1.1  christos 
    165      1.1  christos ACPI_STATUS
    166      1.1  christos AcpiTbAcquireTable (
    167      1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    168      1.1  christos     ACPI_TABLE_HEADER       **TablePtr,
    169      1.1  christos     UINT32                  *TableLength,
    170      1.1  christos     UINT8                   *TableFlags)
    171      1.1  christos {
    172      1.1  christos     ACPI_TABLE_HEADER       *Table = NULL;
    173      1.1  christos 
    174      1.1  christos 
    175      1.1  christos     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
    176      1.1  christos     {
    177      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    178      1.1  christos 
    179      1.1  christos         Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
    180      1.1  christos         break;
    181      1.1  christos 
    182      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    183      1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    184      1.1  christos 
    185  1.1.1.2  christos         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    186  1.1.1.4  christos             ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
    187      1.1  christos         break;
    188      1.1  christos 
    189      1.1  christos     default:
    190      1.1  christos 
    191      1.1  christos         break;
    192      1.1  christos     }
    193      1.1  christos 
    194      1.1  christos     /* Table is not valid yet */
    195      1.1  christos 
    196      1.1  christos     if (!Table)
    197      1.1  christos     {
    198      1.1  christos         return (AE_NO_MEMORY);
    199      1.1  christos     }
    200      1.1  christos 
    201      1.1  christos     /* Fill the return values */
    202      1.1  christos 
    203      1.1  christos     *TablePtr = Table;
    204      1.1  christos     *TableLength = TableDesc->Length;
    205      1.1  christos     *TableFlags = TableDesc->Flags;
    206      1.1  christos     return (AE_OK);
    207      1.1  christos }
    208      1.1  christos 
    209      1.1  christos 
    210      1.1  christos /*******************************************************************************
    211      1.1  christos  *
    212      1.1  christos  * FUNCTION:    AcpiTbReleaseTable
    213      1.1  christos  *
    214      1.1  christos  * PARAMETERS:  Table               - Pointer for the table
    215      1.1  christos  *              TableLength         - Length for the table
    216      1.1  christos  *              TableFlags          - Allocation flags for the table
    217      1.1  christos  *
    218      1.1  christos  * RETURN:      None
    219      1.1  christos  *
    220      1.1  christos  * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
    221      1.1  christos  *
    222      1.1  christos  ******************************************************************************/
    223      1.1  christos 
    224      1.1  christos void
    225      1.1  christos AcpiTbReleaseTable (
    226      1.1  christos     ACPI_TABLE_HEADER       *Table,
    227      1.1  christos     UINT32                  TableLength,
    228      1.1  christos     UINT8                   TableFlags)
    229      1.1  christos {
    230      1.1  christos 
    231      1.1  christos     switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
    232      1.1  christos     {
    233      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    234      1.1  christos 
    235      1.1  christos         AcpiOsUnmapMemory (Table, TableLength);
    236      1.1  christos         break;
    237      1.1  christos 
    238      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    239      1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    240      1.1  christos     default:
    241      1.1  christos 
    242      1.1  christos         break;
    243      1.1  christos     }
    244      1.1  christos }
    245      1.1  christos 
    246      1.1  christos 
    247      1.1  christos /*******************************************************************************
    248      1.1  christos  *
    249      1.1  christos  * FUNCTION:    AcpiTbAcquireTempTable
    250      1.1  christos  *
    251      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be acquired
    252      1.1  christos  *              Address             - Address of the table
    253      1.1  christos  *              Flags               - Allocation flags of the table
    254      1.1  christos  *
    255      1.1  christos  * RETURN:      Status
    256      1.1  christos  *
    257      1.1  christos  * DESCRIPTION: This function validates the table header to obtain the length
    258      1.1  christos  *              of a table and fills the table descriptor to make its state as
    259      1.1  christos  *              "INSTALLED". Such a table descriptor is only used for verified
    260      1.1  christos  *              installation.
    261      1.1  christos  *
    262      1.1  christos  ******************************************************************************/
    263      1.1  christos 
    264      1.1  christos ACPI_STATUS
    265      1.1  christos AcpiTbAcquireTempTable (
    266      1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    267      1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
    268      1.1  christos     UINT8                   Flags)
    269      1.1  christos {
    270      1.1  christos     ACPI_TABLE_HEADER       *TableHeader;
    271      1.1  christos 
    272      1.1  christos 
    273      1.1  christos     switch (Flags & ACPI_TABLE_ORIGIN_MASK)
    274      1.1  christos     {
    275      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    276      1.1  christos 
    277      1.1  christos         /* Get the length of the full table from the header */
    278      1.1  christos 
    279      1.1  christos         TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
    280      1.1  christos         if (!TableHeader)
    281      1.1  christos         {
    282      1.1  christos             return (AE_NO_MEMORY);
    283      1.1  christos         }
    284      1.1  christos 
    285      1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    286      1.1  christos         AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
    287      1.1  christos         return (AE_OK);
    288      1.1  christos 
    289      1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    290      1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    291      1.1  christos 
    292  1.1.1.2  christos         TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    293  1.1.1.4  christos             ACPI_PHYSADDR_TO_PTR (Address));
    294      1.1  christos         if (!TableHeader)
    295      1.1  christos         {
    296      1.1  christos             return (AE_NO_MEMORY);
    297      1.1  christos         }
    298      1.1  christos 
    299      1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    300      1.1  christos         return (AE_OK);
    301      1.1  christos 
    302      1.1  christos     default:
    303      1.1  christos 
    304      1.1  christos         break;
    305      1.1  christos     }
    306      1.1  christos 
    307      1.1  christos     /* Table is not valid yet */
    308      1.1  christos 
    309      1.1  christos     return (AE_NO_MEMORY);
    310      1.1  christos }
    311      1.1  christos 
    312      1.1  christos 
    313      1.1  christos /*******************************************************************************
    314      1.1  christos  *
    315      1.1  christos  * FUNCTION:    AcpiTbReleaseTempTable
    316      1.1  christos  *
    317      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be released
    318      1.1  christos  *
    319      1.1  christos  * RETURN:      Status
    320      1.1  christos  *
    321      1.1  christos  * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
    322      1.1  christos  *
    323      1.1  christos  *****************************************************************************/
    324      1.1  christos 
    325      1.1  christos void
    326      1.1  christos AcpiTbReleaseTempTable (
    327      1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    328      1.1  christos {
    329      1.1  christos 
    330      1.1  christos     /*
    331      1.1  christos      * Note that the .Address is maintained by the callers of
    332      1.1  christos      * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
    333      1.1  christos      * where .Address will be freed.
    334      1.1  christos      */
    335      1.1  christos     AcpiTbInvalidateTable (TableDesc);
    336      1.1  christos }
    337      1.1  christos 
    338      1.1  christos 
    339      1.1  christos /******************************************************************************
    340      1.1  christos  *
    341      1.1  christos  * FUNCTION:    AcpiTbValidateTable
    342      1.1  christos  *
    343      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    344      1.1  christos  *
    345      1.1  christos  * RETURN:      Status
    346      1.1  christos  *
    347      1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    348      1.1  christos  *              table descriptor is in "VALIDATED" state.
    349      1.1  christos  *
    350      1.1  christos  *****************************************************************************/
    351      1.1  christos 
    352      1.1  christos ACPI_STATUS
    353      1.1  christos AcpiTbValidateTable (
    354      1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    355      1.1  christos {
    356      1.1  christos     ACPI_STATUS             Status = AE_OK;
    357      1.1  christos 
    358      1.1  christos 
    359      1.1  christos     ACPI_FUNCTION_TRACE (TbValidateTable);
    360      1.1  christos 
    361      1.1  christos 
    362      1.1  christos     /* Validate the table if necessary */
    363      1.1  christos 
    364      1.1  christos     if (!TableDesc->Pointer)
    365      1.1  christos     {
    366      1.1  christos         Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
    367  1.1.1.4  christos             &TableDesc->Length, &TableDesc->Flags);
    368      1.1  christos         if (!TableDesc->Pointer)
    369      1.1  christos         {
    370      1.1  christos             Status = AE_NO_MEMORY;
    371      1.1  christos         }
    372      1.1  christos     }
    373      1.1  christos 
    374      1.1  christos     return_ACPI_STATUS (Status);
    375      1.1  christos }
    376      1.1  christos 
    377      1.1  christos 
    378      1.1  christos /*******************************************************************************
    379      1.1  christos  *
    380      1.1  christos  * FUNCTION:    AcpiTbInvalidateTable
    381      1.1  christos  *
    382      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    383      1.1  christos  *
    384      1.1  christos  * RETURN:      None
    385      1.1  christos  *
    386      1.1  christos  * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
    387      1.1  christos  *              AcpiTbValidateTable().
    388      1.1  christos  *
    389      1.1  christos  ******************************************************************************/
    390      1.1  christos 
    391      1.1  christos void
    392      1.1  christos AcpiTbInvalidateTable (
    393      1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    394      1.1  christos {
    395      1.1  christos 
    396      1.1  christos     ACPI_FUNCTION_TRACE (TbInvalidateTable);
    397      1.1  christos 
    398      1.1  christos 
    399      1.1  christos     /* Table must be validated */
    400      1.1  christos 
    401      1.1  christos     if (!TableDesc->Pointer)
    402      1.1  christos     {
    403      1.1  christos         return_VOID;
    404      1.1  christos     }
    405      1.1  christos 
    406      1.1  christos     AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
    407      1.1  christos         TableDesc->Flags);
    408      1.1  christos     TableDesc->Pointer = NULL;
    409      1.1  christos 
    410      1.1  christos     return_VOID;
    411      1.1  christos }
    412      1.1  christos 
    413      1.1  christos 
    414      1.1  christos /******************************************************************************
    415      1.1  christos  *
    416      1.1  christos  * FUNCTION:    AcpiTbValidateTempTable
    417      1.1  christos  *
    418      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    419      1.1  christos  *
    420      1.1  christos  * RETURN:      Status
    421      1.1  christos  *
    422      1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    423      1.1  christos  *              table descriptor is in "VALIDATED" state.
    424      1.1  christos  *
    425      1.1  christos  *****************************************************************************/
    426      1.1  christos 
    427      1.1  christos ACPI_STATUS
    428      1.1  christos AcpiTbValidateTempTable (
    429      1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    430      1.1  christos {
    431      1.1  christos 
    432  1.1.1.8  christos     if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)
    433      1.1  christos     {
    434      1.1  christos         /*
    435      1.1  christos          * Only validates the header of the table.
    436      1.1  christos          * Note that Length contains the size of the mapping after invoking
    437      1.1  christos          * this work around, this value is required by
    438      1.1  christos          * AcpiTbReleaseTempTable().
    439      1.1  christos          * We can do this because in AcpiInitTableDescriptor(), the Length
    440      1.1  christos          * field of the installed descriptor is filled with the actual
    441      1.1  christos          * table length obtaining from the table header.
    442      1.1  christos          */
    443      1.1  christos         TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
    444      1.1  christos     }
    445      1.1  christos 
    446      1.1  christos     return (AcpiTbValidateTable (TableDesc));
    447      1.1  christos }
    448      1.1  christos 
    449      1.1  christos 
    450  1.1.1.8  christos /*******************************************************************************
    451  1.1.1.8  christos  *
    452  1.1.1.8  christos  * FUNCTION:    AcpiTbCheckDuplication
    453  1.1.1.8  christos  *
    454  1.1.1.8  christos  * PARAMETERS:  TableDesc           - Table descriptor
    455  1.1.1.8  christos  *              TableIndex          - Where the table index is returned
    456  1.1.1.8  christos  *
    457  1.1.1.8  christos  * RETURN:      Status
    458  1.1.1.8  christos  *
    459  1.1.1.8  christos  * DESCRIPTION: Avoid installing duplicated tables. However table override and
    460  1.1.1.8  christos  *              user aided dynamic table load is allowed, thus comparing the
    461  1.1.1.8  christos  *              address of the table is not sufficient, and checking the entire
    462  1.1.1.8  christos  *              table content is required.
    463  1.1.1.8  christos  *
    464  1.1.1.8  christos  ******************************************************************************/
    465  1.1.1.8  christos 
    466  1.1.1.8  christos static ACPI_STATUS
    467  1.1.1.8  christos AcpiTbCheckDuplication (
    468  1.1.1.8  christos     ACPI_TABLE_DESC         *TableDesc,
    469  1.1.1.8  christos     UINT32                  *TableIndex)
    470  1.1.1.8  christos {
    471  1.1.1.8  christos     UINT32                  i;
    472  1.1.1.8  christos 
    473  1.1.1.8  christos 
    474  1.1.1.8  christos     ACPI_FUNCTION_TRACE (TbCheckDuplication);
    475  1.1.1.8  christos 
    476  1.1.1.8  christos 
    477  1.1.1.8  christos     /* Check if table is already registered */
    478  1.1.1.8  christos 
    479  1.1.1.8  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
    480  1.1.1.8  christos     {
    481  1.1.1.8  christos         /* Do not compare with unverified tables */
    482  1.1.1.8  christos 
    483  1.1.1.8  christos         if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))
    484  1.1.1.8  christos         {
    485  1.1.1.8  christos             continue;
    486  1.1.1.8  christos         }
    487  1.1.1.8  christos 
    488  1.1.1.8  christos         /*
    489  1.1.1.8  christos          * Check for a table match on the entire table length,
    490  1.1.1.8  christos          * not just the header.
    491  1.1.1.8  christos          */
    492  1.1.1.8  christos         if (!AcpiTbCompareTables (TableDesc, i))
    493  1.1.1.8  christos         {
    494  1.1.1.8  christos             continue;
    495  1.1.1.8  christos         }
    496  1.1.1.8  christos 
    497  1.1.1.8  christos         /*
    498  1.1.1.8  christos          * Note: the current mechanism does not unregister a table if it is
    499  1.1.1.8  christos          * dynamically unloaded. The related namespace entries are deleted,
    500  1.1.1.8  christos          * but the table remains in the root table list.
    501  1.1.1.8  christos          *
    502  1.1.1.8  christos          * The assumption here is that the number of different tables that
    503  1.1.1.8  christos          * will be loaded is actually small, and there is minimal overhead
    504  1.1.1.8  christos          * in just keeping the table in case it is needed again.
    505  1.1.1.8  christos          *
    506  1.1.1.8  christos          * If this assumption changes in the future (perhaps on large
    507  1.1.1.8  christos          * machines with many table load/unload operations), tables will
    508  1.1.1.8  christos          * need to be unregistered when they are unloaded, and slots in the
    509  1.1.1.8  christos          * root table list should be reused when empty.
    510  1.1.1.8  christos          */
    511  1.1.1.8  christos         if (AcpiGbl_RootTableList.Tables[i].Flags &
    512  1.1.1.8  christos             ACPI_TABLE_IS_LOADED)
    513  1.1.1.8  christos         {
    514  1.1.1.8  christos             /* Table is still loaded, this is an error */
    515  1.1.1.8  christos 
    516  1.1.1.8  christos             return_ACPI_STATUS (AE_ALREADY_EXISTS);
    517  1.1.1.8  christos         }
    518  1.1.1.8  christos         else
    519  1.1.1.8  christos         {
    520  1.1.1.8  christos             *TableIndex = i;
    521  1.1.1.8  christos             return_ACPI_STATUS (AE_CTRL_TERMINATE);
    522  1.1.1.8  christos         }
    523  1.1.1.8  christos     }
    524  1.1.1.8  christos 
    525  1.1.1.8  christos     /* Indicate no duplication to the caller */
    526  1.1.1.8  christos 
    527  1.1.1.8  christos     return_ACPI_STATUS (AE_OK);
    528  1.1.1.8  christos }
    529  1.1.1.8  christos 
    530  1.1.1.8  christos 
    531      1.1  christos /******************************************************************************
    532      1.1  christos  *
    533      1.1  christos  * FUNCTION:    AcpiTbVerifyTempTable
    534      1.1  christos  *
    535      1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    536      1.1  christos  *              Signature           - Table signature to verify
    537  1.1.1.8  christos  *              TableIndex          - Where the table index is returned
    538      1.1  christos  *
    539      1.1  christos  * RETURN:      Status
    540      1.1  christos  *
    541      1.1  christos  * DESCRIPTION: This function is called to validate and verify the table, the
    542      1.1  christos  *              returned table descriptor is in "VALIDATED" state.
    543  1.1.1.8  christos  *              Note that 'TableIndex' is required to be set to !NULL to
    544  1.1.1.8  christos  *              enable duplication check.
    545      1.1  christos  *
    546      1.1  christos  *****************************************************************************/
    547      1.1  christos 
    548      1.1  christos ACPI_STATUS
    549      1.1  christos AcpiTbVerifyTempTable (
    550      1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    551  1.1.1.8  christos     char                    *Signature,
    552  1.1.1.8  christos     UINT32                  *TableIndex)
    553      1.1  christos {
    554      1.1  christos     ACPI_STATUS             Status = AE_OK;
    555      1.1  christos 
    556      1.1  christos 
    557      1.1  christos     ACPI_FUNCTION_TRACE (TbVerifyTempTable);
    558      1.1  christos 
    559      1.1  christos 
    560      1.1  christos     /* Validate the table */
    561      1.1  christos 
    562      1.1  christos     Status = AcpiTbValidateTempTable (TableDesc);
    563      1.1  christos     if (ACPI_FAILURE (Status))
    564      1.1  christos     {
    565      1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    566      1.1  christos     }
    567      1.1  christos 
    568      1.1  christos     /* If a particular signature is expected (DSDT/FACS), it must match */
    569      1.1  christos 
    570      1.1  christos     if (Signature &&
    571      1.1  christos         !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
    572      1.1  christos     {
    573      1.1  christos         ACPI_BIOS_ERROR ((AE_INFO,
    574      1.1  christos             "Invalid signature 0x%X for ACPI table, expected [%s]",
    575      1.1  christos             TableDesc->Signature.Integer, Signature));
    576      1.1  christos         Status = AE_BAD_SIGNATURE;
    577      1.1  christos         goto InvalidateAndExit;
    578      1.1  christos     }
    579      1.1  christos 
    580  1.1.1.8  christos     if (AcpiGbl_EnableTableValidation)
    581      1.1  christos     {
    582  1.1.1.8  christos         /* Verify the checksum */
    583  1.1.1.8  christos 
    584      1.1  christos         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
    585      1.1  christos         if (ACPI_FAILURE (Status))
    586      1.1  christos         {
    587      1.1  christos             ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
    588  1.1.1.2  christos                 "%4.4s 0x%8.8X%8.8X"
    589      1.1  christos                 " Attempted table install failed",
    590  1.1.1.5  christos                 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
    591      1.1  christos                     TableDesc->Signature.Ascii : "????",
    592  1.1.1.2  christos                 ACPI_FORMAT_UINT64 (TableDesc->Address)));
    593  1.1.1.4  christos 
    594      1.1  christos             goto InvalidateAndExit;
    595      1.1  christos         }
    596  1.1.1.8  christos 
    597  1.1.1.8  christos         /* Avoid duplications */
    598  1.1.1.8  christos 
    599  1.1.1.8  christos         if (TableIndex)
    600  1.1.1.8  christos         {
    601  1.1.1.8  christos             Status = AcpiTbCheckDuplication (TableDesc, TableIndex);
    602  1.1.1.8  christos             if (ACPI_FAILURE (Status))
    603  1.1.1.8  christos             {
    604  1.1.1.8  christos                 if (Status != AE_CTRL_TERMINATE)
    605  1.1.1.8  christos                 {
    606  1.1.1.8  christos                     ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
    607  1.1.1.8  christos                         "%4.4s 0x%8.8X%8.8X"
    608  1.1.1.8  christos                         " Table is duplicated",
    609  1.1.1.8  christos                         AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
    610  1.1.1.8  christos                             TableDesc->Signature.Ascii : "????",
    611  1.1.1.8  christos                         ACPI_FORMAT_UINT64 (TableDesc->Address)));
    612  1.1.1.8  christos                 }
    613  1.1.1.8  christos 
    614  1.1.1.8  christos                 goto InvalidateAndExit;
    615  1.1.1.8  christos             }
    616  1.1.1.8  christos         }
    617  1.1.1.8  christos 
    618  1.1.1.8  christos         TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;
    619      1.1  christos     }
    620      1.1  christos 
    621  1.1.1.8  christos     return_ACPI_STATUS (Status);
    622      1.1  christos 
    623      1.1  christos InvalidateAndExit:
    624      1.1  christos     AcpiTbInvalidateTable (TableDesc);
    625      1.1  christos     return_ACPI_STATUS (Status);
    626      1.1  christos }
    627      1.1  christos 
    628      1.1  christos 
    629      1.1  christos /*******************************************************************************
    630      1.1  christos  *
    631      1.1  christos  * FUNCTION:    AcpiTbResizeRootTableList
    632      1.1  christos  *
    633      1.1  christos  * PARAMETERS:  None
    634      1.1  christos  *
    635      1.1  christos  * RETURN:      Status
    636      1.1  christos  *
    637      1.1  christos  * DESCRIPTION: Expand the size of global table array
    638      1.1  christos  *
    639      1.1  christos  ******************************************************************************/
    640      1.1  christos 
    641      1.1  christos ACPI_STATUS
    642      1.1  christos AcpiTbResizeRootTableList (
    643      1.1  christos     void)
    644      1.1  christos {
    645      1.1  christos     ACPI_TABLE_DESC         *Tables;
    646      1.1  christos     UINT32                  TableCount;
    647  1.1.1.8  christos     UINT32                  CurrentTableCount, MaxTableCount;
    648  1.1.1.8  christos     UINT32                  i;
    649      1.1  christos 
    650      1.1  christos 
    651      1.1  christos     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
    652      1.1  christos 
    653      1.1  christos 
    654      1.1  christos     /* AllowResize flag is a parameter to AcpiInitializeTables */
    655      1.1  christos 
    656      1.1  christos     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
    657      1.1  christos     {
    658      1.1  christos         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
    659      1.1  christos         return_ACPI_STATUS (AE_SUPPORT);
    660      1.1  christos     }
    661      1.1  christos 
    662      1.1  christos     /* Increase the Table Array size */
    663      1.1  christos 
    664      1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    665      1.1  christos     {
    666      1.1  christos         TableCount = AcpiGbl_RootTableList.MaxTableCount;
    667      1.1  christos     }
    668      1.1  christos     else
    669      1.1  christos     {
    670      1.1  christos         TableCount = AcpiGbl_RootTableList.CurrentTableCount;
    671      1.1  christos     }
    672      1.1  christos 
    673  1.1.1.8  christos     MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
    674      1.1  christos     Tables = ACPI_ALLOCATE_ZEROED (
    675  1.1.1.8  christos         ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));
    676      1.1  christos     if (!Tables)
    677      1.1  christos     {
    678      1.1  christos         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
    679      1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    680      1.1  christos     }
    681      1.1  christos 
    682      1.1  christos     /* Copy and free the previous table array */
    683      1.1  christos 
    684  1.1.1.8  christos     CurrentTableCount = 0;
    685      1.1  christos     if (AcpiGbl_RootTableList.Tables)
    686      1.1  christos     {
    687  1.1.1.8  christos         for (i = 0; i < TableCount; i++)
    688  1.1.1.8  christos         {
    689  1.1.1.8  christos             if (AcpiGbl_RootTableList.Tables[i].Address)
    690  1.1.1.8  christos             {
    691  1.1.1.8  christos                 memcpy (Tables + CurrentTableCount,
    692  1.1.1.8  christos                     AcpiGbl_RootTableList.Tables + i,
    693  1.1.1.8  christos                     sizeof (ACPI_TABLE_DESC));
    694  1.1.1.8  christos                 CurrentTableCount++;
    695  1.1.1.8  christos             }
    696  1.1.1.8  christos         }
    697      1.1  christos 
    698      1.1  christos         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    699      1.1  christos         {
    700      1.1  christos             ACPI_FREE (AcpiGbl_RootTableList.Tables);
    701      1.1  christos         }
    702      1.1  christos     }
    703      1.1  christos 
    704      1.1  christos     AcpiGbl_RootTableList.Tables = Tables;
    705  1.1.1.8  christos     AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;
    706  1.1.1.8  christos     AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;
    707      1.1  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
    708      1.1  christos 
    709      1.1  christos     return_ACPI_STATUS (AE_OK);
    710      1.1  christos }
    711      1.1  christos 
    712      1.1  christos 
    713      1.1  christos /*******************************************************************************
    714      1.1  christos  *
    715  1.1.1.2  christos  * FUNCTION:    AcpiTbGetNextTableDescriptor
    716      1.1  christos  *
    717      1.1  christos  * PARAMETERS:  TableIndex          - Where table index is returned
    718  1.1.1.2  christos  *              TableDesc           - Where table descriptor is returned
    719      1.1  christos  *
    720  1.1.1.2  christos  * RETURN:      Status and table index/descriptor.
    721      1.1  christos  *
    722      1.1  christos  * DESCRIPTION: Allocate a new ACPI table entry to the global table list
    723      1.1  christos  *
    724      1.1  christos  ******************************************************************************/
    725      1.1  christos 
    726      1.1  christos ACPI_STATUS
    727  1.1.1.2  christos AcpiTbGetNextTableDescriptor (
    728  1.1.1.2  christos     UINT32                  *TableIndex,
    729  1.1.1.2  christos     ACPI_TABLE_DESC         **TableDesc)
    730      1.1  christos {
    731      1.1  christos     ACPI_STATUS             Status;
    732  1.1.1.2  christos     UINT32                  i;
    733      1.1  christos 
    734      1.1  christos 
    735      1.1  christos     /* Ensure that there is room for the table in the Root Table List */
    736      1.1  christos 
    737      1.1  christos     if (AcpiGbl_RootTableList.CurrentTableCount >=
    738      1.1  christos         AcpiGbl_RootTableList.MaxTableCount)
    739      1.1  christos     {
    740      1.1  christos         Status = AcpiTbResizeRootTableList();
    741      1.1  christos         if (ACPI_FAILURE (Status))
    742      1.1  christos         {
    743      1.1  christos             return (Status);
    744      1.1  christos         }
    745      1.1  christos     }
    746      1.1  christos 
    747  1.1.1.2  christos     i = AcpiGbl_RootTableList.CurrentTableCount;
    748      1.1  christos     AcpiGbl_RootTableList.CurrentTableCount++;
    749  1.1.1.2  christos 
    750  1.1.1.2  christos     if (TableIndex)
    751  1.1.1.2  christos     {
    752  1.1.1.2  christos         *TableIndex = i;
    753  1.1.1.2  christos     }
    754  1.1.1.2  christos     if (TableDesc)
    755  1.1.1.2  christos     {
    756  1.1.1.2  christos         *TableDesc = &AcpiGbl_RootTableList.Tables[i];
    757  1.1.1.2  christos     }
    758  1.1.1.2  christos 
    759      1.1  christos     return (AE_OK);
    760      1.1  christos }
    761      1.1  christos 
    762      1.1  christos 
    763      1.1  christos /*******************************************************************************
    764      1.1  christos  *
    765      1.1  christos  * FUNCTION:    AcpiTbTerminate
    766      1.1  christos  *
    767      1.1  christos  * PARAMETERS:  None
    768      1.1  christos  *
    769      1.1  christos  * RETURN:      None
    770      1.1  christos  *
    771      1.1  christos  * DESCRIPTION: Delete all internal ACPI tables
    772      1.1  christos  *
    773      1.1  christos  ******************************************************************************/
    774      1.1  christos 
    775      1.1  christos void
    776      1.1  christos AcpiTbTerminate (
    777      1.1  christos     void)
    778      1.1  christos {
    779      1.1  christos     UINT32                  i;
    780      1.1  christos 
    781      1.1  christos 
    782      1.1  christos     ACPI_FUNCTION_TRACE (TbTerminate);
    783      1.1  christos 
    784      1.1  christos 
    785      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    786      1.1  christos 
    787      1.1  christos     /* Delete the individual tables */
    788      1.1  christos 
    789      1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    790      1.1  christos     {
    791      1.1  christos         AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
    792      1.1  christos     }
    793      1.1  christos 
    794      1.1  christos     /*
    795      1.1  christos      * Delete the root table array if allocated locally. Array cannot be
    796      1.1  christos      * mapped, so we don't need to check for that flag.
    797      1.1  christos      */
    798      1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    799      1.1  christos     {
    800      1.1  christos         ACPI_FREE (AcpiGbl_RootTableList.Tables);
    801      1.1  christos     }
    802      1.1  christos 
    803      1.1  christos     AcpiGbl_RootTableList.Tables = NULL;
    804      1.1  christos     AcpiGbl_RootTableList.Flags = 0;
    805      1.1  christos     AcpiGbl_RootTableList.CurrentTableCount = 0;
    806      1.1  christos 
    807      1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
    808      1.1  christos 
    809      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    810      1.1  christos     return_VOID;
    811      1.1  christos }
    812      1.1  christos 
    813      1.1  christos 
    814      1.1  christos /*******************************************************************************
    815      1.1  christos  *
    816      1.1  christos  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
    817      1.1  christos  *
    818      1.1  christos  * PARAMETERS:  TableIndex          - Table index
    819      1.1  christos  *
    820      1.1  christos  * RETURN:      Status
    821      1.1  christos  *
    822      1.1  christos  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
    823      1.1  christos  *
    824      1.1  christos  ******************************************************************************/
    825      1.1  christos 
    826      1.1  christos ACPI_STATUS
    827      1.1  christos AcpiTbDeleteNamespaceByOwner (
    828      1.1  christos     UINT32                  TableIndex)
    829      1.1  christos {
    830      1.1  christos     ACPI_OWNER_ID           OwnerId;
    831      1.1  christos     ACPI_STATUS             Status;
    832      1.1  christos 
    833      1.1  christos 
    834      1.1  christos     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
    835      1.1  christos 
    836      1.1  christos 
    837      1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    838      1.1  christos     if (ACPI_FAILURE (Status))
    839      1.1  christos     {
    840      1.1  christos         return_ACPI_STATUS (Status);
    841      1.1  christos     }
    842      1.1  christos 
    843      1.1  christos     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    844      1.1  christos     {
    845      1.1  christos         /* The table index does not exist */
    846      1.1  christos 
    847      1.1  christos         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    848      1.1  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    849      1.1  christos     }
    850      1.1  christos 
    851      1.1  christos     /* Get the owner ID for this table, used to delete namespace nodes */
    852      1.1  christos 
    853      1.1  christos     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    854      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    855      1.1  christos 
    856      1.1  christos     /*
    857      1.1  christos      * Need to acquire the namespace writer lock to prevent interference
    858      1.1  christos      * with any concurrent namespace walks. The interpreter must be
    859      1.1  christos      * released during the deletion since the acquisition of the deletion
    860      1.1  christos      * lock may block, and also since the execution of a namespace walk
    861      1.1  christos      * must be allowed to use the interpreter.
    862      1.1  christos      */
    863      1.1  christos     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
    864      1.1  christos     if (ACPI_FAILURE (Status))
    865      1.1  christos     {
    866      1.1  christos         return_ACPI_STATUS (Status);
    867      1.1  christos     }
    868  1.1.1.6  christos     AcpiNsDeleteNamespaceByOwner (OwnerId);
    869      1.1  christos     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
    870      1.1  christos     return_ACPI_STATUS (Status);
    871      1.1  christos }
    872      1.1  christos 
    873      1.1  christos 
    874      1.1  christos /*******************************************************************************
    875      1.1  christos  *
    876      1.1  christos  * FUNCTION:    AcpiTbAllocateOwnerId
    877      1.1  christos  *
    878      1.1  christos  * PARAMETERS:  TableIndex          - Table index
    879      1.1  christos  *
    880      1.1  christos  * RETURN:      Status
    881      1.1  christos  *
    882      1.1  christos  * DESCRIPTION: Allocates OwnerId in TableDesc
    883      1.1  christos  *
    884      1.1  christos  ******************************************************************************/
    885      1.1  christos 
    886      1.1  christos ACPI_STATUS
    887      1.1  christos AcpiTbAllocateOwnerId (
    888      1.1  christos     UINT32                  TableIndex)
    889      1.1  christos {
    890      1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    891      1.1  christos 
    892      1.1  christos 
    893      1.1  christos     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
    894      1.1  christos 
    895      1.1  christos 
    896      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    897      1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    898      1.1  christos     {
    899      1.1  christos         Status = AcpiUtAllocateOwnerId (
    900  1.1.1.4  christos             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    901      1.1  christos     }
    902      1.1  christos 
    903      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    904      1.1  christos     return_ACPI_STATUS (Status);
    905      1.1  christos }
    906      1.1  christos 
    907      1.1  christos 
    908      1.1  christos /*******************************************************************************
    909      1.1  christos  *
    910      1.1  christos  * FUNCTION:    AcpiTbReleaseOwnerId
    911      1.1  christos  *
    912      1.1  christos  * PARAMETERS:  TableIndex          - Table index
    913      1.1  christos  *
    914      1.1  christos  * RETURN:      Status
    915      1.1  christos  *
    916      1.1  christos  * DESCRIPTION: Releases OwnerId in TableDesc
    917      1.1  christos  *
    918      1.1  christos  ******************************************************************************/
    919      1.1  christos 
    920      1.1  christos ACPI_STATUS
    921      1.1  christos AcpiTbReleaseOwnerId (
    922      1.1  christos     UINT32                  TableIndex)
    923      1.1  christos {
    924      1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    925      1.1  christos 
    926      1.1  christos 
    927      1.1  christos     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
    928      1.1  christos 
    929      1.1  christos 
    930      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    931      1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    932      1.1  christos     {
    933      1.1  christos         AcpiUtReleaseOwnerId (
    934      1.1  christos             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    935      1.1  christos         Status = AE_OK;
    936      1.1  christos     }
    937      1.1  christos 
    938      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    939      1.1  christos     return_ACPI_STATUS (Status);
    940      1.1  christos }
    941      1.1  christos 
    942      1.1  christos 
    943      1.1  christos /*******************************************************************************
    944      1.1  christos  *
    945      1.1  christos  * FUNCTION:    AcpiTbGetOwnerId
    946      1.1  christos  *
    947      1.1  christos  * PARAMETERS:  TableIndex          - Table index
    948      1.1  christos  *              OwnerId             - Where the table OwnerId is returned
    949      1.1  christos  *
    950      1.1  christos  * RETURN:      Status
    951      1.1  christos  *
    952      1.1  christos  * DESCRIPTION: returns OwnerId for the ACPI table
    953      1.1  christos  *
    954      1.1  christos  ******************************************************************************/
    955      1.1  christos 
    956      1.1  christos ACPI_STATUS
    957      1.1  christos AcpiTbGetOwnerId (
    958      1.1  christos     UINT32                  TableIndex,
    959      1.1  christos     ACPI_OWNER_ID           *OwnerId)
    960      1.1  christos {
    961      1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    962      1.1  christos 
    963      1.1  christos 
    964      1.1  christos     ACPI_FUNCTION_TRACE (TbGetOwnerId);
    965      1.1  christos 
    966      1.1  christos 
    967      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    968      1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    969      1.1  christos     {
    970      1.1  christos         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    971      1.1  christos         Status = AE_OK;
    972      1.1  christos     }
    973      1.1  christos 
    974      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    975      1.1  christos     return_ACPI_STATUS (Status);
    976      1.1  christos }
    977      1.1  christos 
    978      1.1  christos 
    979      1.1  christos /*******************************************************************************
    980      1.1  christos  *
    981      1.1  christos  * FUNCTION:    AcpiTbIsTableLoaded
    982      1.1  christos  *
    983      1.1  christos  * PARAMETERS:  TableIndex          - Index into the root table
    984      1.1  christos  *
    985      1.1  christos  * RETURN:      Table Loaded Flag
    986      1.1  christos  *
    987      1.1  christos  ******************************************************************************/
    988      1.1  christos 
    989      1.1  christos BOOLEAN
    990      1.1  christos AcpiTbIsTableLoaded (
    991      1.1  christos     UINT32                  TableIndex)
    992      1.1  christos {
    993      1.1  christos     BOOLEAN                 IsLoaded = FALSE;
    994      1.1  christos 
    995      1.1  christos 
    996      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    997      1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    998      1.1  christos     {
    999      1.1  christos         IsLoaded = (BOOLEAN)
   1000      1.1  christos             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
   1001      1.1  christos             ACPI_TABLE_IS_LOADED);
   1002      1.1  christos     }
   1003      1.1  christos 
   1004      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
   1005      1.1  christos     return (IsLoaded);
   1006      1.1  christos }
   1007      1.1  christos 
   1008      1.1  christos 
   1009      1.1  christos /*******************************************************************************
   1010      1.1  christos  *
   1011      1.1  christos  * FUNCTION:    AcpiTbSetTableLoadedFlag
   1012      1.1  christos  *
   1013      1.1  christos  * PARAMETERS:  TableIndex          - Table index
   1014      1.1  christos  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
   1015      1.1  christos  *
   1016      1.1  christos  * RETURN:      None
   1017      1.1  christos  *
   1018      1.1  christos  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
   1019      1.1  christos  *
   1020      1.1  christos  ******************************************************************************/
   1021      1.1  christos 
   1022      1.1  christos void
   1023      1.1  christos AcpiTbSetTableLoadedFlag (
   1024      1.1  christos     UINT32                  TableIndex,
   1025      1.1  christos     BOOLEAN                 IsLoaded)
   1026      1.1  christos {
   1027      1.1  christos 
   1028      1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
   1029      1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
   1030      1.1  christos     {
   1031      1.1  christos         if (IsLoaded)
   1032      1.1  christos         {
   1033      1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
   1034      1.1  christos                 ACPI_TABLE_IS_LOADED;
   1035      1.1  christos         }
   1036      1.1  christos         else
   1037      1.1  christos         {
   1038      1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
   1039      1.1  christos                 ~ACPI_TABLE_IS_LOADED;
   1040      1.1  christos         }
   1041      1.1  christos     }
   1042      1.1  christos 
   1043      1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
   1044      1.1  christos }
   1045  1.1.1.6  christos 
   1046  1.1.1.6  christos 
   1047  1.1.1.6  christos /*******************************************************************************
   1048  1.1.1.6  christos  *
   1049  1.1.1.6  christos  * FUNCTION:    AcpiTbLoadTable
   1050  1.1.1.6  christos  *
   1051  1.1.1.6  christos  * PARAMETERS:  TableIndex              - Table index
   1052  1.1.1.6  christos  *              ParentNode              - Where table index is returned
   1053  1.1.1.6  christos  *
   1054  1.1.1.6  christos  * RETURN:      Status
   1055  1.1.1.6  christos  *
   1056  1.1.1.6  christos  * DESCRIPTION: Load an ACPI table
   1057  1.1.1.6  christos  *
   1058  1.1.1.6  christos  ******************************************************************************/
   1059  1.1.1.6  christos 
   1060  1.1.1.6  christos ACPI_STATUS
   1061  1.1.1.6  christos AcpiTbLoadTable (
   1062  1.1.1.6  christos     UINT32                  TableIndex,
   1063  1.1.1.6  christos     ACPI_NAMESPACE_NODE     *ParentNode)
   1064  1.1.1.6  christos {
   1065  1.1.1.6  christos     ACPI_TABLE_HEADER       *Table;
   1066  1.1.1.6  christos     ACPI_STATUS             Status;
   1067  1.1.1.6  christos     ACPI_OWNER_ID           OwnerId;
   1068  1.1.1.6  christos 
   1069  1.1.1.6  christos 
   1070  1.1.1.6  christos     ACPI_FUNCTION_TRACE (TbLoadTable);
   1071  1.1.1.6  christos 
   1072  1.1.1.6  christos 
   1073  1.1.1.6  christos     /*
   1074  1.1.1.6  christos      * Note: Now table is "INSTALLED", it must be validated before
   1075  1.1.1.6  christos      * using.
   1076  1.1.1.6  christos      */
   1077  1.1.1.6  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
   1078  1.1.1.6  christos     if (ACPI_FAILURE (Status))
   1079  1.1.1.6  christos     {
   1080  1.1.1.6  christos         return_ACPI_STATUS (Status);
   1081  1.1.1.6  christos     }
   1082  1.1.1.6  christos 
   1083  1.1.1.6  christos     Status = AcpiNsLoadTable (TableIndex, ParentNode);
   1084  1.1.1.6  christos 
   1085  1.1.1.9  christos     /*
   1086  1.1.1.9  christos      * This case handles the legacy option that groups all module-level
   1087  1.1.1.9  christos      * code blocks together and defers execution until all of the tables
   1088  1.1.1.9  christos      * are loaded. Execute all of these blocks at this time.
   1089  1.1.1.9  christos      * Execute any module-level code that was detected during the table
   1090  1.1.1.9  christos      * load phase.
   1091  1.1.1.9  christos      *
   1092  1.1.1.9  christos      * Note: this option is deprecated and will be eliminated in the
   1093  1.1.1.9  christos      * future. Use of this option can cause problems with AML code that
   1094  1.1.1.9  christos      * depends upon in-order immediate execution of module-level code.
   1095  1.1.1.9  christos      */
   1096  1.1.1.9  christos     AcpiNsExecModuleCodeList ();
   1097  1.1.1.6  christos 
   1098  1.1.1.6  christos     /*
   1099  1.1.1.6  christos      * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
   1100  1.1.1.6  christos      * responsible for discovering any new wake GPEs by running _PRW methods
   1101  1.1.1.6  christos      * that may have been loaded by this table.
   1102  1.1.1.6  christos      */
   1103  1.1.1.6  christos     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
   1104  1.1.1.6  christos     if (ACPI_SUCCESS (Status))
   1105  1.1.1.6  christos     {
   1106  1.1.1.6  christos         AcpiEvUpdateGpes (OwnerId);
   1107  1.1.1.6  christos     }
   1108  1.1.1.6  christos 
   1109  1.1.1.8  christos     /* Invoke table handler */
   1110  1.1.1.6  christos 
   1111  1.1.1.8  christos     AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);
   1112  1.1.1.6  christos     return_ACPI_STATUS (Status);
   1113  1.1.1.6  christos }
   1114  1.1.1.6  christos 
   1115  1.1.1.6  christos 
   1116  1.1.1.6  christos /*******************************************************************************
   1117  1.1.1.6  christos  *
   1118  1.1.1.6  christos  * FUNCTION:    AcpiTbInstallAndLoadTable
   1119  1.1.1.6  christos  *
   1120  1.1.1.7  christos  * PARAMETERS:  Address                 - Physical address of the table
   1121  1.1.1.6  christos  *              Flags                   - Allocation flags of the table
   1122  1.1.1.7  christos  *              Override                - Whether override should be performed
   1123  1.1.1.6  christos  *              TableIndex              - Where table index is returned
   1124  1.1.1.6  christos  *
   1125  1.1.1.6  christos  * RETURN:      Status
   1126  1.1.1.6  christos  *
   1127  1.1.1.6  christos  * DESCRIPTION: Install and load an ACPI table
   1128  1.1.1.6  christos  *
   1129  1.1.1.6  christos  ******************************************************************************/
   1130  1.1.1.6  christos 
   1131  1.1.1.6  christos ACPI_STATUS
   1132  1.1.1.6  christos AcpiTbInstallAndLoadTable (
   1133  1.1.1.6  christos     ACPI_PHYSICAL_ADDRESS   Address,
   1134  1.1.1.6  christos     UINT8                   Flags,
   1135  1.1.1.6  christos     BOOLEAN                 Override,
   1136  1.1.1.6  christos     UINT32                  *TableIndex)
   1137  1.1.1.6  christos {
   1138  1.1.1.6  christos     ACPI_STATUS             Status;
   1139  1.1.1.6  christos     UINT32                  i;
   1140  1.1.1.6  christos 
   1141  1.1.1.6  christos 
   1142  1.1.1.7  christos     ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
   1143  1.1.1.6  christos 
   1144  1.1.1.6  christos 
   1145  1.1.1.6  christos     /* Install the table and load it into the namespace */
   1146  1.1.1.6  christos 
   1147  1.1.1.6  christos     Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
   1148  1.1.1.6  christos         Override, &i);
   1149  1.1.1.6  christos     if (ACPI_FAILURE (Status))
   1150  1.1.1.6  christos     {
   1151  1.1.1.8  christos         goto Exit;
   1152  1.1.1.6  christos     }
   1153  1.1.1.6  christos 
   1154  1.1.1.7  christos     Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
   1155  1.1.1.6  christos 
   1156  1.1.1.8  christos Exit:
   1157  1.1.1.7  christos     *TableIndex = i;
   1158  1.1.1.7  christos     return_ACPI_STATUS (Status);
   1159  1.1.1.7  christos }
   1160  1.1.1.6  christos 
   1161  1.1.1.6  christos 
   1162  1.1.1.7  christos /*******************************************************************************
   1163  1.1.1.7  christos  *
   1164  1.1.1.7  christos  * FUNCTION:    AcpiTbUnloadTable
   1165  1.1.1.7  christos  *
   1166  1.1.1.7  christos  * PARAMETERS:  TableIndex              - Table index
   1167  1.1.1.7  christos  *
   1168  1.1.1.7  christos  * RETURN:      Status
   1169  1.1.1.7  christos  *
   1170  1.1.1.7  christos  * DESCRIPTION: Unload an ACPI table
   1171  1.1.1.7  christos  *
   1172  1.1.1.7  christos  ******************************************************************************/
   1173  1.1.1.6  christos 
   1174  1.1.1.7  christos ACPI_STATUS
   1175  1.1.1.7  christos AcpiTbUnloadTable (
   1176  1.1.1.7  christos     UINT32                  TableIndex)
   1177  1.1.1.7  christos {
   1178  1.1.1.7  christos     ACPI_STATUS             Status = AE_OK;
   1179  1.1.1.7  christos     ACPI_TABLE_HEADER       *Table;
   1180  1.1.1.7  christos 
   1181  1.1.1.7  christos 
   1182  1.1.1.7  christos     ACPI_FUNCTION_TRACE (TbUnloadTable);
   1183  1.1.1.7  christos 
   1184  1.1.1.7  christos 
   1185  1.1.1.7  christos     /* Ensure the table is still loaded */
   1186  1.1.1.7  christos 
   1187  1.1.1.7  christos     if (!AcpiTbIsTableLoaded (TableIndex))
   1188  1.1.1.6  christos     {
   1189  1.1.1.7  christos         return_ACPI_STATUS (AE_NOT_EXIST);
   1190  1.1.1.6  christos     }
   1191  1.1.1.6  christos 
   1192  1.1.1.8  christos     /* Invoke table handler */
   1193  1.1.1.6  christos 
   1194  1.1.1.8  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
   1195  1.1.1.8  christos     if (ACPI_SUCCESS (Status))
   1196  1.1.1.6  christos     {
   1197  1.1.1.8  christos         AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);
   1198  1.1.1.6  christos     }
   1199  1.1.1.6  christos 
   1200  1.1.1.7  christos     /* Delete the portion of the namespace owned by this table */
   1201  1.1.1.7  christos 
   1202  1.1.1.7  christos     Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
   1203  1.1.1.7  christos     if (ACPI_FAILURE (Status))
   1204  1.1.1.7  christos     {
   1205  1.1.1.7  christos         return_ACPI_STATUS (Status);
   1206  1.1.1.7  christos     }
   1207  1.1.1.7  christos 
   1208  1.1.1.7  christos     (void) AcpiTbReleaseOwnerId (TableIndex);
   1209  1.1.1.7  christos     AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
   1210  1.1.1.6  christos     return_ACPI_STATUS (Status);
   1211  1.1.1.6  christos }
   1212  1.1.1.8  christos 
   1213  1.1.1.8  christos 
   1214  1.1.1.8  christos /*******************************************************************************
   1215  1.1.1.8  christos  *
   1216  1.1.1.8  christos  * FUNCTION:    AcpiTbNotifyTable
   1217  1.1.1.8  christos  *
   1218  1.1.1.8  christos  * PARAMETERS:  Event               - Table event
   1219  1.1.1.8  christos  *              Table               - Validated table pointer
   1220  1.1.1.8  christos  *
   1221  1.1.1.8  christos  * RETURN:      None
   1222  1.1.1.8  christos  *
   1223  1.1.1.8  christos  * DESCRIPTION: Notify a table event to the users.
   1224  1.1.1.8  christos  *
   1225  1.1.1.8  christos  ******************************************************************************/
   1226  1.1.1.8  christos 
   1227  1.1.1.8  christos void
   1228  1.1.1.8  christos AcpiTbNotifyTable (
   1229  1.1.1.8  christos     UINT32                          Event,
   1230  1.1.1.8  christos     void                            *Table)
   1231  1.1.1.8  christos {
   1232  1.1.1.8  christos     /* Invoke table handler if present */
   1233  1.1.1.8  christos 
   1234  1.1.1.8  christos     if (AcpiGbl_TableHandler)
   1235  1.1.1.8  christos     {
   1236  1.1.1.8  christos         (void) AcpiGbl_TableHandler (Event, Table,
   1237  1.1.1.8  christos             AcpiGbl_TableHandlerContext);
   1238  1.1.1.8  christos     }
   1239  1.1.1.8  christos }
   1240