Home | History | Annotate | Line # | Download | only in tables
tbdata.c revision 1.4
      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.3  christos  * Copyright (C) 2000 - 2015, 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  christos 
     49  1.1  christos #define _COMPONENT          ACPI_TABLES
     50  1.1  christos         ACPI_MODULE_NAME    ("tbdata")
     51  1.1  christos 
     52  1.1  christos 
     53  1.1  christos /*******************************************************************************
     54  1.1  christos  *
     55  1.1  christos  * FUNCTION:    AcpiTbInitTableDescriptor
     56  1.1  christos  *
     57  1.1  christos  * PARAMETERS:  TableDesc               - Table descriptor
     58  1.1  christos  *              Address                 - Physical address of the table
     59  1.1  christos  *              Flags                   - Allocation flags of the table
     60  1.1  christos  *              Table                   - Pointer to the table
     61  1.1  christos  *
     62  1.1  christos  * RETURN:      None
     63  1.1  christos  *
     64  1.1  christos  * DESCRIPTION: Initialize a new table descriptor
     65  1.1  christos  *
     66  1.1  christos  ******************************************************************************/
     67  1.1  christos 
     68  1.1  christos void
     69  1.1  christos AcpiTbInitTableDescriptor (
     70  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
     71  1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
     72  1.1  christos     UINT8                   Flags,
     73  1.1  christos     ACPI_TABLE_HEADER       *Table)
     74  1.1  christos {
     75  1.1  christos 
     76  1.1  christos     /*
     77  1.1  christos      * Initialize the table descriptor. Set the pointer to NULL, since the
     78  1.1  christos      * table is not fully mapped at this time.
     79  1.1  christos      */
     80  1.4  christos     memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
     81  1.1  christos     TableDesc->Address = Address;
     82  1.1  christos     TableDesc->Length = Table->Length;
     83  1.1  christos     TableDesc->Flags = Flags;
     84  1.1  christos     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
     85  1.1  christos }
     86  1.1  christos 
     87  1.1  christos 
     88  1.1  christos /*******************************************************************************
     89  1.1  christos  *
     90  1.1  christos  * FUNCTION:    AcpiTbAcquireTable
     91  1.1  christos  *
     92  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
     93  1.1  christos  *              TablePtr            - Where table is returned
     94  1.1  christos  *              TableLength         - Where table length is returned
     95  1.1  christos  *              TableFlags          - Where table allocation flags are returned
     96  1.1  christos  *
     97  1.1  christos  * RETURN:      Status
     98  1.1  christos  *
     99  1.1  christos  * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
    100  1.1  christos  *              maintained in the AcpiGbl_RootTableList.
    101  1.1  christos  *
    102  1.1  christos  ******************************************************************************/
    103  1.1  christos 
    104  1.1  christos ACPI_STATUS
    105  1.1  christos AcpiTbAcquireTable (
    106  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    107  1.1  christos     ACPI_TABLE_HEADER       **TablePtr,
    108  1.1  christos     UINT32                  *TableLength,
    109  1.1  christos     UINT8                   *TableFlags)
    110  1.1  christos {
    111  1.1  christos     ACPI_TABLE_HEADER       *Table = NULL;
    112  1.1  christos 
    113  1.1  christos 
    114  1.1  christos     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
    115  1.1  christos     {
    116  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    117  1.1  christos 
    118  1.1  christos         Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
    119  1.1  christos         break;
    120  1.1  christos 
    121  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    122  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    123  1.1  christos 
    124  1.3  christos         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    125  1.3  christos                     ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
    126  1.1  christos         break;
    127  1.1  christos 
    128  1.1  christos     default:
    129  1.1  christos 
    130  1.1  christos         break;
    131  1.1  christos     }
    132  1.1  christos 
    133  1.1  christos     /* Table is not valid yet */
    134  1.1  christos 
    135  1.1  christos     if (!Table)
    136  1.1  christos     {
    137  1.1  christos         return (AE_NO_MEMORY);
    138  1.1  christos     }
    139  1.1  christos 
    140  1.1  christos     /* Fill the return values */
    141  1.1  christos 
    142  1.1  christos     *TablePtr = Table;
    143  1.1  christos     *TableLength = TableDesc->Length;
    144  1.1  christos     *TableFlags = TableDesc->Flags;
    145  1.1  christos     return (AE_OK);
    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:    AcpiTbReleaseTable
    152  1.1  christos  *
    153  1.1  christos  * PARAMETERS:  Table               - Pointer for the table
    154  1.1  christos  *              TableLength         - Length for the table
    155  1.1  christos  *              TableFlags          - Allocation flags for the table
    156  1.1  christos  *
    157  1.1  christos  * RETURN:      None
    158  1.1  christos  *
    159  1.1  christos  * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
    160  1.1  christos  *
    161  1.1  christos  ******************************************************************************/
    162  1.1  christos 
    163  1.1  christos void
    164  1.1  christos AcpiTbReleaseTable (
    165  1.1  christos     ACPI_TABLE_HEADER       *Table,
    166  1.1  christos     UINT32                  TableLength,
    167  1.1  christos     UINT8                   TableFlags)
    168  1.1  christos {
    169  1.1  christos 
    170  1.1  christos     switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
    171  1.1  christos     {
    172  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    173  1.1  christos 
    174  1.1  christos         AcpiOsUnmapMemory (Table, TableLength);
    175  1.1  christos         break;
    176  1.1  christos 
    177  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    178  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    179  1.1  christos     default:
    180  1.1  christos 
    181  1.1  christos         break;
    182  1.1  christos     }
    183  1.1  christos }
    184  1.1  christos 
    185  1.1  christos 
    186  1.1  christos /*******************************************************************************
    187  1.1  christos  *
    188  1.1  christos  * FUNCTION:    AcpiTbAcquireTempTable
    189  1.1  christos  *
    190  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be acquired
    191  1.1  christos  *              Address             - Address of the table
    192  1.1  christos  *              Flags               - Allocation flags of the table
    193  1.1  christos  *
    194  1.1  christos  * RETURN:      Status
    195  1.1  christos  *
    196  1.1  christos  * DESCRIPTION: This function validates the table header to obtain the length
    197  1.1  christos  *              of a table and fills the table descriptor to make its state as
    198  1.1  christos  *              "INSTALLED". Such a table descriptor is only used for verified
    199  1.1  christos  *              installation.
    200  1.1  christos  *
    201  1.1  christos  ******************************************************************************/
    202  1.1  christos 
    203  1.1  christos ACPI_STATUS
    204  1.1  christos AcpiTbAcquireTempTable (
    205  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    206  1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
    207  1.1  christos     UINT8                   Flags)
    208  1.1  christos {
    209  1.1  christos     ACPI_TABLE_HEADER       *TableHeader;
    210  1.1  christos 
    211  1.1  christos 
    212  1.1  christos     switch (Flags & ACPI_TABLE_ORIGIN_MASK)
    213  1.1  christos     {
    214  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
    215  1.1  christos 
    216  1.1  christos         /* Get the length of the full table from the header */
    217  1.1  christos 
    218  1.1  christos         TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
    219  1.1  christos         if (!TableHeader)
    220  1.1  christos         {
    221  1.1  christos             return (AE_NO_MEMORY);
    222  1.1  christos         }
    223  1.1  christos 
    224  1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    225  1.1  christos         AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
    226  1.1  christos         return (AE_OK);
    227  1.1  christos 
    228  1.1  christos     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
    229  1.1  christos     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
    230  1.1  christos 
    231  1.3  christos         TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
    232  1.3  christos                         ACPI_PHYSADDR_TO_PTR (Address));
    233  1.1  christos         if (!TableHeader)
    234  1.1  christos         {
    235  1.1  christos             return (AE_NO_MEMORY);
    236  1.1  christos         }
    237  1.1  christos 
    238  1.1  christos         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
    239  1.1  christos         return (AE_OK);
    240  1.1  christos 
    241  1.1  christos     default:
    242  1.1  christos 
    243  1.1  christos         break;
    244  1.1  christos     }
    245  1.1  christos 
    246  1.1  christos     /* Table is not valid yet */
    247  1.1  christos 
    248  1.1  christos     return (AE_NO_MEMORY);
    249  1.1  christos }
    250  1.1  christos 
    251  1.1  christos 
    252  1.1  christos /*******************************************************************************
    253  1.1  christos  *
    254  1.1  christos  * FUNCTION:    AcpiTbReleaseTempTable
    255  1.1  christos  *
    256  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor to be released
    257  1.1  christos  *
    258  1.1  christos  * RETURN:      Status
    259  1.1  christos  *
    260  1.1  christos  * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
    261  1.1  christos  *
    262  1.1  christos  *****************************************************************************/
    263  1.1  christos 
    264  1.1  christos void
    265  1.1  christos AcpiTbReleaseTempTable (
    266  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    267  1.1  christos {
    268  1.1  christos 
    269  1.1  christos     /*
    270  1.1  christos      * Note that the .Address is maintained by the callers of
    271  1.1  christos      * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
    272  1.1  christos      * where .Address will be freed.
    273  1.1  christos      */
    274  1.1  christos     AcpiTbInvalidateTable (TableDesc);
    275  1.1  christos }
    276  1.1  christos 
    277  1.1  christos 
    278  1.1  christos /******************************************************************************
    279  1.1  christos  *
    280  1.1  christos  * FUNCTION:    AcpiTbValidateTable
    281  1.1  christos  *
    282  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    283  1.1  christos  *
    284  1.1  christos  * RETURN:      Status
    285  1.1  christos  *
    286  1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    287  1.1  christos  *              table descriptor is in "VALIDATED" state.
    288  1.1  christos  *
    289  1.1  christos  *****************************************************************************/
    290  1.1  christos 
    291  1.1  christos ACPI_STATUS
    292  1.1  christos AcpiTbValidateTable (
    293  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    294  1.1  christos {
    295  1.1  christos     ACPI_STATUS             Status = AE_OK;
    296  1.1  christos 
    297  1.1  christos 
    298  1.1  christos     ACPI_FUNCTION_TRACE (TbValidateTable);
    299  1.1  christos 
    300  1.1  christos 
    301  1.1  christos     /* Validate the table if necessary */
    302  1.1  christos 
    303  1.1  christos     if (!TableDesc->Pointer)
    304  1.1  christos     {
    305  1.1  christos         Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
    306  1.1  christos                     &TableDesc->Length, &TableDesc->Flags);
    307  1.1  christos         if (!TableDesc->Pointer)
    308  1.1  christos         {
    309  1.1  christos             Status = AE_NO_MEMORY;
    310  1.1  christos         }
    311  1.1  christos     }
    312  1.1  christos 
    313  1.1  christos     return_ACPI_STATUS (Status);
    314  1.1  christos }
    315  1.1  christos 
    316  1.1  christos 
    317  1.1  christos /*******************************************************************************
    318  1.1  christos  *
    319  1.1  christos  * FUNCTION:    AcpiTbInvalidateTable
    320  1.1  christos  *
    321  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    322  1.1  christos  *
    323  1.1  christos  * RETURN:      None
    324  1.1  christos  *
    325  1.1  christos  * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
    326  1.1  christos  *              AcpiTbValidateTable().
    327  1.1  christos  *
    328  1.1  christos  ******************************************************************************/
    329  1.1  christos 
    330  1.1  christos void
    331  1.1  christos AcpiTbInvalidateTable (
    332  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    333  1.1  christos {
    334  1.1  christos 
    335  1.1  christos     ACPI_FUNCTION_TRACE (TbInvalidateTable);
    336  1.1  christos 
    337  1.1  christos 
    338  1.1  christos     /* Table must be validated */
    339  1.1  christos 
    340  1.1  christos     if (!TableDesc->Pointer)
    341  1.1  christos     {
    342  1.1  christos         return_VOID;
    343  1.1  christos     }
    344  1.1  christos 
    345  1.1  christos     AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
    346  1.1  christos         TableDesc->Flags);
    347  1.1  christos     TableDesc->Pointer = NULL;
    348  1.1  christos 
    349  1.1  christos     return_VOID;
    350  1.1  christos }
    351  1.1  christos 
    352  1.1  christos 
    353  1.1  christos /******************************************************************************
    354  1.1  christos  *
    355  1.1  christos  * FUNCTION:    AcpiTbValidateTempTable
    356  1.1  christos  *
    357  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    358  1.1  christos  *
    359  1.1  christos  * RETURN:      Status
    360  1.1  christos  *
    361  1.1  christos  * DESCRIPTION: This function is called to validate the table, the returned
    362  1.1  christos  *              table descriptor is in "VALIDATED" state.
    363  1.1  christos  *
    364  1.1  christos  *****************************************************************************/
    365  1.1  christos 
    366  1.1  christos ACPI_STATUS
    367  1.1  christos AcpiTbValidateTempTable (
    368  1.1  christos     ACPI_TABLE_DESC         *TableDesc)
    369  1.1  christos {
    370  1.1  christos 
    371  1.1  christos     if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
    372  1.1  christos     {
    373  1.1  christos         /*
    374  1.1  christos          * Only validates the header of the table.
    375  1.1  christos          * Note that Length contains the size of the mapping after invoking
    376  1.1  christos          * this work around, this value is required by
    377  1.1  christos          * AcpiTbReleaseTempTable().
    378  1.1  christos          * We can do this because in AcpiInitTableDescriptor(), the Length
    379  1.1  christos          * field of the installed descriptor is filled with the actual
    380  1.1  christos          * table length obtaining from the table header.
    381  1.1  christos          */
    382  1.1  christos         TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
    383  1.1  christos     }
    384  1.1  christos 
    385  1.1  christos     return (AcpiTbValidateTable (TableDesc));
    386  1.1  christos }
    387  1.1  christos 
    388  1.1  christos 
    389  1.1  christos /******************************************************************************
    390  1.1  christos  *
    391  1.1  christos  * FUNCTION:    AcpiTbVerifyTempTable
    392  1.1  christos  *
    393  1.1  christos  * PARAMETERS:  TableDesc           - Table descriptor
    394  1.1  christos  *              Signature           - Table signature to verify
    395  1.1  christos  *
    396  1.1  christos  * RETURN:      Status
    397  1.1  christos  *
    398  1.1  christos  * DESCRIPTION: This function is called to validate and verify the table, the
    399  1.1  christos  *              returned table descriptor is in "VALIDATED" state.
    400  1.1  christos  *
    401  1.1  christos  *****************************************************************************/
    402  1.1  christos 
    403  1.1  christos ACPI_STATUS
    404  1.1  christos AcpiTbVerifyTempTable (
    405  1.1  christos     ACPI_TABLE_DESC         *TableDesc,
    406  1.2  christos     const char              *Signature)
    407  1.1  christos {
    408  1.1  christos     ACPI_STATUS             Status = AE_OK;
    409  1.1  christos 
    410  1.1  christos 
    411  1.1  christos     ACPI_FUNCTION_TRACE (TbVerifyTempTable);
    412  1.1  christos 
    413  1.1  christos 
    414  1.1  christos     /* Validate the table */
    415  1.1  christos 
    416  1.1  christos     Status = AcpiTbValidateTempTable (TableDesc);
    417  1.1  christos     if (ACPI_FAILURE (Status))
    418  1.1  christos     {
    419  1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    420  1.1  christos     }
    421  1.1  christos 
    422  1.1  christos     /* If a particular signature is expected (DSDT/FACS), it must match */
    423  1.1  christos 
    424  1.1  christos     if (Signature &&
    425  1.1  christos         !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
    426  1.1  christos     {
    427  1.1  christos         ACPI_BIOS_ERROR ((AE_INFO,
    428  1.1  christos             "Invalid signature 0x%X for ACPI table, expected [%s]",
    429  1.1  christos             TableDesc->Signature.Integer, Signature));
    430  1.1  christos         Status = AE_BAD_SIGNATURE;
    431  1.1  christos         goto InvalidateAndExit;
    432  1.1  christos     }
    433  1.1  christos 
    434  1.1  christos     /* Verify the checksum */
    435  1.1  christos 
    436  1.1  christos     if (AcpiGbl_VerifyTableChecksum)
    437  1.1  christos     {
    438  1.1  christos         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
    439  1.1  christos         if (ACPI_FAILURE (Status))
    440  1.1  christos         {
    441  1.1  christos             ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
    442  1.3  christos                 "%4.4s 0x%8.8X%8.8X"
    443  1.1  christos                 " Attempted table install failed",
    444  1.1  christos                 AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ?
    445  1.1  christos                     TableDesc->Signature.Ascii : "????",
    446  1.3  christos                 ACPI_FORMAT_UINT64 (TableDesc->Address)));
    447  1.1  christos             goto InvalidateAndExit;
    448  1.1  christos         }
    449  1.1  christos     }
    450  1.1  christos 
    451  1.1  christos     return_ACPI_STATUS (AE_OK);
    452  1.1  christos 
    453  1.1  christos InvalidateAndExit:
    454  1.1  christos     AcpiTbInvalidateTable (TableDesc);
    455  1.1  christos     return_ACPI_STATUS (Status);
    456  1.1  christos }
    457  1.1  christos 
    458  1.1  christos 
    459  1.1  christos /*******************************************************************************
    460  1.1  christos  *
    461  1.1  christos  * FUNCTION:    AcpiTbResizeRootTableList
    462  1.1  christos  *
    463  1.1  christos  * PARAMETERS:  None
    464  1.1  christos  *
    465  1.1  christos  * RETURN:      Status
    466  1.1  christos  *
    467  1.1  christos  * DESCRIPTION: Expand the size of global table array
    468  1.1  christos  *
    469  1.1  christos  ******************************************************************************/
    470  1.1  christos 
    471  1.1  christos ACPI_STATUS
    472  1.1  christos AcpiTbResizeRootTableList (
    473  1.1  christos     void)
    474  1.1  christos {
    475  1.1  christos     ACPI_TABLE_DESC         *Tables;
    476  1.1  christos     UINT32                  TableCount;
    477  1.1  christos 
    478  1.1  christos 
    479  1.1  christos     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
    480  1.1  christos 
    481  1.1  christos 
    482  1.1  christos     /* AllowResize flag is a parameter to AcpiInitializeTables */
    483  1.1  christos 
    484  1.1  christos     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
    485  1.1  christos     {
    486  1.1  christos         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
    487  1.1  christos         return_ACPI_STATUS (AE_SUPPORT);
    488  1.1  christos     }
    489  1.1  christos 
    490  1.1  christos     /* Increase the Table Array size */
    491  1.1  christos 
    492  1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    493  1.1  christos     {
    494  1.1  christos         TableCount = AcpiGbl_RootTableList.MaxTableCount;
    495  1.1  christos     }
    496  1.1  christos     else
    497  1.1  christos     {
    498  1.1  christos         TableCount = AcpiGbl_RootTableList.CurrentTableCount;
    499  1.1  christos     }
    500  1.1  christos 
    501  1.1  christos     Tables = ACPI_ALLOCATE_ZEROED (
    502  1.1  christos         ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
    503  1.1  christos         sizeof (ACPI_TABLE_DESC));
    504  1.1  christos     if (!Tables)
    505  1.1  christos     {
    506  1.1  christos         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
    507  1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    508  1.1  christos     }
    509  1.1  christos 
    510  1.1  christos     /* Copy and free the previous table array */
    511  1.1  christos 
    512  1.1  christos     if (AcpiGbl_RootTableList.Tables)
    513  1.1  christos     {
    514  1.4  christos         memcpy (Tables, AcpiGbl_RootTableList.Tables,
    515  1.1  christos             (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
    516  1.1  christos 
    517  1.1  christos         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    518  1.1  christos         {
    519  1.1  christos             ACPI_FREE (AcpiGbl_RootTableList.Tables);
    520  1.1  christos         }
    521  1.1  christos     }
    522  1.1  christos 
    523  1.1  christos     AcpiGbl_RootTableList.Tables = Tables;
    524  1.1  christos     AcpiGbl_RootTableList.MaxTableCount =
    525  1.1  christos         TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
    526  1.1  christos     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
    527  1.1  christos 
    528  1.1  christos     return_ACPI_STATUS (AE_OK);
    529  1.1  christos }
    530  1.1  christos 
    531  1.1  christos 
    532  1.1  christos /*******************************************************************************
    533  1.1  christos  *
    534  1.3  christos  * FUNCTION:    AcpiTbGetNextTableDescriptor
    535  1.1  christos  *
    536  1.1  christos  * PARAMETERS:  TableIndex          - Where table index is returned
    537  1.3  christos  *              TableDesc           - Where table descriptor is returned
    538  1.1  christos  *
    539  1.3  christos  * RETURN:      Status and table index/descriptor.
    540  1.1  christos  *
    541  1.1  christos  * DESCRIPTION: Allocate a new ACPI table entry to the global table list
    542  1.1  christos  *
    543  1.1  christos  ******************************************************************************/
    544  1.1  christos 
    545  1.1  christos ACPI_STATUS
    546  1.3  christos AcpiTbGetNextTableDescriptor (
    547  1.3  christos     UINT32                  *TableIndex,
    548  1.3  christos     ACPI_TABLE_DESC         **TableDesc)
    549  1.1  christos {
    550  1.1  christos     ACPI_STATUS             Status;
    551  1.3  christos     UINT32                  i;
    552  1.1  christos 
    553  1.1  christos 
    554  1.1  christos     /* Ensure that there is room for the table in the Root Table List */
    555  1.1  christos 
    556  1.1  christos     if (AcpiGbl_RootTableList.CurrentTableCount >=
    557  1.1  christos         AcpiGbl_RootTableList.MaxTableCount)
    558  1.1  christos     {
    559  1.1  christos         Status = AcpiTbResizeRootTableList();
    560  1.1  christos         if (ACPI_FAILURE (Status))
    561  1.1  christos         {
    562  1.1  christos             return (Status);
    563  1.1  christos         }
    564  1.1  christos     }
    565  1.1  christos 
    566  1.3  christos     i = AcpiGbl_RootTableList.CurrentTableCount;
    567  1.1  christos     AcpiGbl_RootTableList.CurrentTableCount++;
    568  1.3  christos 
    569  1.3  christos     if (TableIndex)
    570  1.3  christos     {
    571  1.3  christos         *TableIndex = i;
    572  1.3  christos     }
    573  1.3  christos     if (TableDesc)
    574  1.3  christos     {
    575  1.3  christos         *TableDesc = &AcpiGbl_RootTableList.Tables[i];
    576  1.3  christos     }
    577  1.3  christos 
    578  1.1  christos     return (AE_OK);
    579  1.1  christos }
    580  1.1  christos 
    581  1.1  christos 
    582  1.1  christos /*******************************************************************************
    583  1.1  christos  *
    584  1.1  christos  * FUNCTION:    AcpiTbTerminate
    585  1.1  christos  *
    586  1.1  christos  * PARAMETERS:  None
    587  1.1  christos  *
    588  1.1  christos  * RETURN:      None
    589  1.1  christos  *
    590  1.1  christos  * DESCRIPTION: Delete all internal ACPI tables
    591  1.1  christos  *
    592  1.1  christos  ******************************************************************************/
    593  1.1  christos 
    594  1.1  christos void
    595  1.1  christos AcpiTbTerminate (
    596  1.1  christos     void)
    597  1.1  christos {
    598  1.1  christos     UINT32                  i;
    599  1.1  christos 
    600  1.1  christos 
    601  1.1  christos     ACPI_FUNCTION_TRACE (TbTerminate);
    602  1.1  christos 
    603  1.1  christos 
    604  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    605  1.1  christos 
    606  1.1  christos     /* Delete the individual tables */
    607  1.1  christos 
    608  1.1  christos     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
    609  1.1  christos     {
    610  1.1  christos         AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
    611  1.1  christos     }
    612  1.1  christos 
    613  1.1  christos     /*
    614  1.1  christos      * Delete the root table array if allocated locally. Array cannot be
    615  1.1  christos      * mapped, so we don't need to check for that flag.
    616  1.1  christos      */
    617  1.1  christos     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
    618  1.1  christos     {
    619  1.1  christos         ACPI_FREE (AcpiGbl_RootTableList.Tables);
    620  1.1  christos     }
    621  1.1  christos 
    622  1.1  christos     AcpiGbl_RootTableList.Tables = NULL;
    623  1.1  christos     AcpiGbl_RootTableList.Flags = 0;
    624  1.1  christos     AcpiGbl_RootTableList.CurrentTableCount = 0;
    625  1.1  christos 
    626  1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
    627  1.1  christos 
    628  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    629  1.1  christos     return_VOID;
    630  1.1  christos }
    631  1.1  christos 
    632  1.1  christos 
    633  1.1  christos /*******************************************************************************
    634  1.1  christos  *
    635  1.1  christos  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
    636  1.1  christos  *
    637  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    638  1.1  christos  *
    639  1.1  christos  * RETURN:      Status
    640  1.1  christos  *
    641  1.1  christos  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
    642  1.1  christos  *
    643  1.1  christos  ******************************************************************************/
    644  1.1  christos 
    645  1.1  christos ACPI_STATUS
    646  1.1  christos AcpiTbDeleteNamespaceByOwner (
    647  1.1  christos     UINT32                  TableIndex)
    648  1.1  christos {
    649  1.1  christos     ACPI_OWNER_ID           OwnerId;
    650  1.1  christos     ACPI_STATUS             Status;
    651  1.1  christos 
    652  1.1  christos 
    653  1.1  christos     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
    654  1.1  christos 
    655  1.1  christos 
    656  1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    657  1.1  christos     if (ACPI_FAILURE (Status))
    658  1.1  christos     {
    659  1.1  christos         return_ACPI_STATUS (Status);
    660  1.1  christos     }
    661  1.1  christos 
    662  1.1  christos     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
    663  1.1  christos     {
    664  1.1  christos         /* The table index does not exist */
    665  1.1  christos 
    666  1.1  christos         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    667  1.1  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    668  1.1  christos     }
    669  1.1  christos 
    670  1.1  christos     /* Get the owner ID for this table, used to delete namespace nodes */
    671  1.1  christos 
    672  1.1  christos     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    673  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    674  1.1  christos 
    675  1.1  christos     /*
    676  1.1  christos      * Need to acquire the namespace writer lock to prevent interference
    677  1.1  christos      * with any concurrent namespace walks. The interpreter must be
    678  1.1  christos      * released during the deletion since the acquisition of the deletion
    679  1.1  christos      * lock may block, and also since the execution of a namespace walk
    680  1.1  christos      * must be allowed to use the interpreter.
    681  1.1  christos      */
    682  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
    683  1.1  christos     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
    684  1.1  christos 
    685  1.1  christos     AcpiNsDeleteNamespaceByOwner (OwnerId);
    686  1.1  christos     if (ACPI_FAILURE (Status))
    687  1.1  christos     {
    688  1.1  christos         return_ACPI_STATUS (Status);
    689  1.1  christos     }
    690  1.1  christos 
    691  1.1  christos     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
    692  1.1  christos 
    693  1.1  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
    694  1.1  christos     return_ACPI_STATUS (Status);
    695  1.1  christos }
    696  1.1  christos 
    697  1.1  christos 
    698  1.1  christos /*******************************************************************************
    699  1.1  christos  *
    700  1.1  christos  * FUNCTION:    AcpiTbAllocateOwnerId
    701  1.1  christos  *
    702  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    703  1.1  christos  *
    704  1.1  christos  * RETURN:      Status
    705  1.1  christos  *
    706  1.1  christos  * DESCRIPTION: Allocates OwnerId in TableDesc
    707  1.1  christos  *
    708  1.1  christos  ******************************************************************************/
    709  1.1  christos 
    710  1.1  christos ACPI_STATUS
    711  1.1  christos AcpiTbAllocateOwnerId (
    712  1.1  christos     UINT32                  TableIndex)
    713  1.1  christos {
    714  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    715  1.1  christos 
    716  1.1  christos 
    717  1.1  christos     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
    718  1.1  christos 
    719  1.1  christos 
    720  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    721  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    722  1.1  christos     {
    723  1.1  christos         Status = AcpiUtAllocateOwnerId (
    724  1.1  christos                     &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    725  1.1  christos     }
    726  1.1  christos 
    727  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    728  1.1  christos     return_ACPI_STATUS (Status);
    729  1.1  christos }
    730  1.1  christos 
    731  1.1  christos 
    732  1.1  christos /*******************************************************************************
    733  1.1  christos  *
    734  1.1  christos  * FUNCTION:    AcpiTbReleaseOwnerId
    735  1.1  christos  *
    736  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    737  1.1  christos  *
    738  1.1  christos  * RETURN:      Status
    739  1.1  christos  *
    740  1.1  christos  * DESCRIPTION: Releases OwnerId in TableDesc
    741  1.1  christos  *
    742  1.1  christos  ******************************************************************************/
    743  1.1  christos 
    744  1.1  christos ACPI_STATUS
    745  1.1  christos AcpiTbReleaseOwnerId (
    746  1.1  christos     UINT32                  TableIndex)
    747  1.1  christos {
    748  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    749  1.1  christos 
    750  1.1  christos 
    751  1.1  christos     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
    752  1.1  christos 
    753  1.1  christos 
    754  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    755  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    756  1.1  christos     {
    757  1.1  christos         AcpiUtReleaseOwnerId (
    758  1.1  christos             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
    759  1.1  christos         Status = AE_OK;
    760  1.1  christos     }
    761  1.1  christos 
    762  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    763  1.1  christos     return_ACPI_STATUS (Status);
    764  1.1  christos }
    765  1.1  christos 
    766  1.1  christos 
    767  1.1  christos /*******************************************************************************
    768  1.1  christos  *
    769  1.1  christos  * FUNCTION:    AcpiTbGetOwnerId
    770  1.1  christos  *
    771  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    772  1.1  christos  *              OwnerId             - Where the table OwnerId is returned
    773  1.1  christos  *
    774  1.1  christos  * RETURN:      Status
    775  1.1  christos  *
    776  1.1  christos  * DESCRIPTION: returns OwnerId for the ACPI table
    777  1.1  christos  *
    778  1.1  christos  ******************************************************************************/
    779  1.1  christos 
    780  1.1  christos ACPI_STATUS
    781  1.1  christos AcpiTbGetOwnerId (
    782  1.1  christos     UINT32                  TableIndex,
    783  1.1  christos     ACPI_OWNER_ID           *OwnerId)
    784  1.1  christos {
    785  1.1  christos     ACPI_STATUS             Status = AE_BAD_PARAMETER;
    786  1.1  christos 
    787  1.1  christos 
    788  1.1  christos     ACPI_FUNCTION_TRACE (TbGetOwnerId);
    789  1.1  christos 
    790  1.1  christos 
    791  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    792  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    793  1.1  christos     {
    794  1.1  christos         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
    795  1.1  christos         Status = AE_OK;
    796  1.1  christos     }
    797  1.1  christos 
    798  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    799  1.1  christos     return_ACPI_STATUS (Status);
    800  1.1  christos }
    801  1.1  christos 
    802  1.1  christos 
    803  1.1  christos /*******************************************************************************
    804  1.1  christos  *
    805  1.1  christos  * FUNCTION:    AcpiTbIsTableLoaded
    806  1.1  christos  *
    807  1.1  christos  * PARAMETERS:  TableIndex          - Index into the root table
    808  1.1  christos  *
    809  1.1  christos  * RETURN:      Table Loaded Flag
    810  1.1  christos  *
    811  1.1  christos  ******************************************************************************/
    812  1.1  christos 
    813  1.1  christos BOOLEAN
    814  1.1  christos AcpiTbIsTableLoaded (
    815  1.1  christos     UINT32                  TableIndex)
    816  1.1  christos {
    817  1.1  christos     BOOLEAN                 IsLoaded = FALSE;
    818  1.1  christos 
    819  1.1  christos 
    820  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    821  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    822  1.1  christos     {
    823  1.1  christos         IsLoaded = (BOOLEAN)
    824  1.1  christos             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
    825  1.1  christos             ACPI_TABLE_IS_LOADED);
    826  1.1  christos     }
    827  1.1  christos 
    828  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    829  1.1  christos     return (IsLoaded);
    830  1.1  christos }
    831  1.1  christos 
    832  1.1  christos 
    833  1.1  christos /*******************************************************************************
    834  1.1  christos  *
    835  1.1  christos  * FUNCTION:    AcpiTbSetTableLoadedFlag
    836  1.1  christos  *
    837  1.1  christos  * PARAMETERS:  TableIndex          - Table index
    838  1.1  christos  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
    839  1.1  christos  *
    840  1.1  christos  * RETURN:      None
    841  1.1  christos  *
    842  1.1  christos  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
    843  1.1  christos  *
    844  1.1  christos  ******************************************************************************/
    845  1.1  christos 
    846  1.1  christos void
    847  1.1  christos AcpiTbSetTableLoadedFlag (
    848  1.1  christos     UINT32                  TableIndex,
    849  1.1  christos     BOOLEAN                 IsLoaded)
    850  1.1  christos {
    851  1.1  christos 
    852  1.1  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
    853  1.1  christos     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
    854  1.1  christos     {
    855  1.1  christos         if (IsLoaded)
    856  1.1  christos         {
    857  1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
    858  1.1  christos                 ACPI_TABLE_IS_LOADED;
    859  1.1  christos         }
    860  1.1  christos         else
    861  1.1  christos         {
    862  1.1  christos             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
    863  1.1  christos                 ~ACPI_TABLE_IS_LOADED;
    864  1.1  christos         }
    865  1.1  christos     }
    866  1.1  christos 
    867  1.1  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
    868  1.1  christos }
    869