Path: blob/main/sys/contrib/dev/acpica/components/tables/tbdata.c
48406 views
/******************************************************************************1*2* Module Name: tbdata - Table manager data structure functions3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acnamesp.h>154#include <contrib/dev/acpica/include/actables.h>155#include <contrib/dev/acpica/include/acevents.h>156157#define _COMPONENT ACPI_TABLES158ACPI_MODULE_NAME ("tbdata")159160/* Local prototypes */161162static ACPI_STATUS163AcpiTbCheckDuplication (164ACPI_TABLE_DESC *TableDesc,165UINT32 *TableIndex);166167static BOOLEAN168AcpiTbCompareTables (169ACPI_TABLE_DESC *TableDesc,170UINT32 TableIndex);171172173/*******************************************************************************174*175* FUNCTION: AcpiTbCompareTables176*177* PARAMETERS: TableDesc - Table 1 descriptor to be compared178* TableIndex - Index of table 2 to be compared179*180* RETURN: TRUE if both tables are identical.181*182* DESCRIPTION: This function compares a table with another table that has183* already been installed in the root table list.184*185******************************************************************************/186187static BOOLEAN188AcpiTbCompareTables (189ACPI_TABLE_DESC *TableDesc,190UINT32 TableIndex)191{192ACPI_STATUS Status = AE_OK;193BOOLEAN IsIdentical;194ACPI_TABLE_HEADER *Table;195UINT32 TableLength;196UINT8 TableFlags;197198199Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],200&Table, &TableLength, &TableFlags);201if (ACPI_FAILURE (Status))202{203return (FALSE);204}205206/*207* Check for a table match on the entire table length,208* not just the header.209*/210IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||211memcmp (TableDesc->Pointer, Table, TableLength)) ?212FALSE : TRUE);213214/* Release the acquired table */215216AcpiTbReleaseTable (Table, TableLength, TableFlags);217return (IsIdentical);218}219220221/*******************************************************************************222*223* FUNCTION: AcpiTbInitTableDescriptor224*225* PARAMETERS: TableDesc - Table descriptor226* Address - Physical address of the table227* Flags - Allocation flags of the table228* Table - Pointer to the table229*230* RETURN: None231*232* DESCRIPTION: Initialize a new table descriptor233*234******************************************************************************/235236void237AcpiTbInitTableDescriptor (238ACPI_TABLE_DESC *TableDesc,239ACPI_PHYSICAL_ADDRESS Address,240UINT8 Flags,241ACPI_TABLE_HEADER *Table)242{243244/*245* Initialize the table descriptor. Set the pointer to NULL for external246* tables, since the table is not fully mapped at this time.247*/248memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));249TableDesc->Address = Address;250TableDesc->Length = Table->Length;251TableDesc->Flags = Flags;252ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);253254switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)255{256case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:257case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:258259TableDesc->Pointer = Table;260break;261262case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:263default:264265break;266}267}268269270/*******************************************************************************271*272* FUNCTION: AcpiTbAcquireTable273*274* PARAMETERS: TableDesc - Table descriptor275* TablePtr - Where table is returned276* TableLength - Where table length is returned277* TableFlags - Where table allocation flags are returned278*279* RETURN: Status280*281* DESCRIPTION: Acquire an ACPI table. It can be used for tables not282* maintained in the AcpiGbl_RootTableList.283*284******************************************************************************/285286ACPI_STATUS287AcpiTbAcquireTable (288ACPI_TABLE_DESC *TableDesc,289ACPI_TABLE_HEADER **TablePtr,290UINT32 *TableLength,291UINT8 *TableFlags)292{293ACPI_TABLE_HEADER *Table = NULL;294295296switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)297{298case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:299300Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);301break;302303case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:304case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:305306Table = TableDesc->Pointer;307break;308309default:310311break;312}313314/* Table is not valid yet */315316if (!Table)317{318return (AE_NO_MEMORY);319}320321/* Fill the return values */322323*TablePtr = Table;324*TableLength = TableDesc->Length;325*TableFlags = TableDesc->Flags;326return (AE_OK);327}328329330/*******************************************************************************331*332* FUNCTION: AcpiTbReleaseTable333*334* PARAMETERS: Table - Pointer for the table335* TableLength - Length for the table336* TableFlags - Allocation flags for the table337*338* RETURN: None339*340* DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().341*342******************************************************************************/343344void345AcpiTbReleaseTable (346ACPI_TABLE_HEADER *Table,347UINT32 TableLength,348UINT8 TableFlags)349{350351switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)352{353case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:354355AcpiOsUnmapMemory (Table, TableLength);356break;357358case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:359case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:360default:361362break;363}364}365366367/*******************************************************************************368*369* FUNCTION: AcpiTbAcquireTempTable370*371* PARAMETERS: TableDesc - Table descriptor to be acquired372* Address - Address of the table373* Flags - Allocation flags of the table374* Table - Pointer to the table (required for virtual375* origins, optional for physical)376*377* RETURN: Status378*379* DESCRIPTION: This function validates the table header to obtain the length380* of a table and fills the table descriptor to make its state as381* "INSTALLED". Such a table descriptor is only used for verified382* installation.383*384******************************************************************************/385386ACPI_STATUS387AcpiTbAcquireTempTable (388ACPI_TABLE_DESC *TableDesc,389ACPI_PHYSICAL_ADDRESS Address,390UINT8 Flags,391ACPI_TABLE_HEADER *Table)392{393BOOLEAN MappedTable = FALSE;394395396switch (Flags & ACPI_TABLE_ORIGIN_MASK)397{398case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:399400/* Get the length of the full table from the header */401402if (!Table)403{404Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));405if (!Table)406{407return (AE_NO_MEMORY);408}409410MappedTable = TRUE;411}412413break;414415case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:416case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:417418if (!Table)419{420return (AE_BAD_PARAMETER);421}422423break;424425default:426427/* Table is not valid yet */428429return (AE_NO_MEMORY);430}431432AcpiTbInitTableDescriptor (TableDesc, Address, Flags, Table);433if (MappedTable)434{435AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));436}437438return (AE_OK);439}440441442/*******************************************************************************443*444* FUNCTION: AcpiTbReleaseTempTable445*446* PARAMETERS: TableDesc - Table descriptor to be released447*448* RETURN: Status449*450* DESCRIPTION: The inverse of AcpiTbAcquireTempTable().451*452*****************************************************************************/453454void455AcpiTbReleaseTempTable (456ACPI_TABLE_DESC *TableDesc)457{458459/*460* Note that the .Address is maintained by the callers of461* AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()462* where .Address will be freed.463*/464AcpiTbInvalidateTable (TableDesc);465}466467468/******************************************************************************469*470* FUNCTION: AcpiTbValidateTable471*472* PARAMETERS: TableDesc - Table descriptor473*474* RETURN: Status475*476* DESCRIPTION: This function is called to validate the table, the returned477* table descriptor is in "VALIDATED" state.478*479*****************************************************************************/480481ACPI_STATUS482AcpiTbValidateTable (483ACPI_TABLE_DESC *TableDesc)484{485ACPI_STATUS Status = AE_OK;486487488ACPI_FUNCTION_TRACE (TbValidateTable);489490491/* Validate the table if necessary */492493if (!TableDesc->Pointer)494{495Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,496&TableDesc->Length, &TableDesc->Flags);497if (!TableDesc->Pointer)498{499Status = AE_NO_MEMORY;500}501}502503return_ACPI_STATUS (Status);504}505506507/*******************************************************************************508*509* FUNCTION: AcpiTbInvalidateTable510*511* PARAMETERS: TableDesc - Table descriptor512*513* RETURN: None514*515* DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of516* AcpiTbValidateTable().517*518******************************************************************************/519520void521AcpiTbInvalidateTable (522ACPI_TABLE_DESC *TableDesc)523{524525ACPI_FUNCTION_TRACE (TbInvalidateTable);526527528/* Table must be validated */529530if (!TableDesc->Pointer)531{532return_VOID;533}534535AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,536TableDesc->Flags);537538switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)539{540case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:541542TableDesc->Pointer = NULL;543break;544545case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:546case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:547default:548549break;550}551552return_VOID;553}554555556/******************************************************************************557*558* FUNCTION: AcpiTbValidateTempTable559*560* PARAMETERS: TableDesc - Table descriptor561*562* RETURN: Status563*564* DESCRIPTION: This function is called to validate the table, the returned565* table descriptor is in "VALIDATED" state.566*567*****************************************************************************/568569ACPI_STATUS570AcpiTbValidateTempTable (571ACPI_TABLE_DESC *TableDesc)572{573574if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)575{576/*577* Only validates the header of the table.578* Note that Length contains the size of the mapping after invoking579* this work around, this value is required by580* AcpiTbReleaseTempTable().581* We can do this because in AcpiInitTableDescriptor(), the Length582* field of the installed descriptor is filled with the actual583* table length obtaining from the table header.584*/585TableDesc->Length = sizeof (ACPI_TABLE_HEADER);586}587588return (AcpiTbValidateTable (TableDesc));589}590591592/*******************************************************************************593*594* FUNCTION: AcpiTbCheckDuplication595*596* PARAMETERS: TableDesc - Table descriptor597* TableIndex - Where the table index is returned598*599* RETURN: Status600*601* DESCRIPTION: Avoid installing duplicated tables. However table override and602* user aided dynamic table load is allowed, thus comparing the603* address of the table is not sufficient, and checking the entire604* table content is required.605*606******************************************************************************/607608static ACPI_STATUS609AcpiTbCheckDuplication (610ACPI_TABLE_DESC *TableDesc,611UINT32 *TableIndex)612{613UINT32 i;614615616ACPI_FUNCTION_TRACE (TbCheckDuplication);617618619/* Check if table is already registered */620621for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)622{623/* Do not compare with unverified tables */624625if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))626{627continue;628}629630/*631* Check for a table match on the entire table length,632* not just the header.633*/634if (!AcpiTbCompareTables (TableDesc, i))635{636continue;637}638639/*640* Note: the current mechanism does not unregister a table if it is641* dynamically unloaded. The related namespace entries are deleted,642* but the table remains in the root table list.643*644* The assumption here is that the number of different tables that645* will be loaded is actually small, and there is minimal overhead646* in just keeping the table in case it is needed again.647*648* If this assumption changes in the future (perhaps on large649* machines with many table load/unload operations), tables will650* need to be unregistered when they are unloaded, and slots in the651* root table list should be reused when empty.652*/653if (AcpiGbl_RootTableList.Tables[i].Flags &654ACPI_TABLE_IS_LOADED)655{656/* Table is still loaded, this is an error */657658return_ACPI_STATUS (AE_ALREADY_EXISTS);659}660else661{662*TableIndex = i;663return_ACPI_STATUS (AE_CTRL_TERMINATE);664}665}666667/* Indicate no duplication to the caller */668669return_ACPI_STATUS (AE_OK);670}671672673/******************************************************************************674*675* FUNCTION: AcpiTbVerifyTempTable676*677* PARAMETERS: TableDesc - Table descriptor678* Signature - Table signature to verify679* TableIndex - Where the table index is returned680*681* RETURN: Status682*683* DESCRIPTION: This function is called to validate and verify the table, the684* returned table descriptor is in "VALIDATED" state.685* Note that 'TableIndex' is required to be set to !NULL to686* enable duplication check.687*688*****************************************************************************/689690ACPI_STATUS691AcpiTbVerifyTempTable (692ACPI_TABLE_DESC *TableDesc,693char *Signature,694UINT32 *TableIndex)695{696ACPI_STATUS Status = AE_OK;697698699ACPI_FUNCTION_TRACE (TbVerifyTempTable);700701702/* Validate the table */703704Status = AcpiTbValidateTempTable (TableDesc);705if (ACPI_FAILURE (Status))706{707return_ACPI_STATUS (AE_NO_MEMORY);708}709710/* If a particular signature is expected (DSDT/FACS), it must match */711712if (Signature &&713!ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))714{715ACPI_BIOS_ERROR ((AE_INFO,716"Invalid signature 0x%X for ACPI table, expected [%s]",717TableDesc->Signature.Integer, Signature));718Status = AE_BAD_SIGNATURE;719goto InvalidateAndExit;720}721722if (AcpiGbl_EnableTableValidation)723{724/* Verify the checksum */725726Status = AcpiUtVerifyChecksum (TableDesc->Pointer, TableDesc->Length);727if (ACPI_FAILURE (Status))728{729ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,730"%4.4s 0x%8.8X%8.8X"731" Attempted table install failed",732AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?733TableDesc->Signature.Ascii : "????",734ACPI_FORMAT_UINT64 (TableDesc->Address)));735736goto InvalidateAndExit;737}738739/* Avoid duplications */740741if (TableIndex)742{743Status = AcpiTbCheckDuplication (TableDesc, TableIndex);744if (ACPI_FAILURE (Status))745{746if (Status != AE_CTRL_TERMINATE)747{748ACPI_EXCEPTION ((AE_INFO, Status,749"%4.4s 0x%8.8X%8.8X"750" Table is already loaded",751AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?752TableDesc->Signature.Ascii : "????",753ACPI_FORMAT_UINT64 (TableDesc->Address)));754}755756goto InvalidateAndExit;757}758}759760TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;761}762763return_ACPI_STATUS (Status);764765InvalidateAndExit:766AcpiTbInvalidateTable (TableDesc);767return_ACPI_STATUS (Status);768}769770771/*******************************************************************************772*773* FUNCTION: AcpiTbResizeRootTableList774*775* PARAMETERS: None776*777* RETURN: Status778*779* DESCRIPTION: Expand the size of global table array780*781******************************************************************************/782783ACPI_STATUS784AcpiTbResizeRootTableList (785void)786{787ACPI_TABLE_DESC *Tables;788UINT32 TableCount;789UINT32 CurrentTableCount, MaxTableCount;790UINT32 i;791792793ACPI_FUNCTION_TRACE (TbResizeRootTableList);794795796/* AllowResize flag is a parameter to AcpiInitializeTables */797798if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))799{800ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));801return_ACPI_STATUS (AE_SUPPORT);802}803804/* Increase the Table Array size */805806if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)807{808TableCount = AcpiGbl_RootTableList.MaxTableCount;809}810else811{812TableCount = AcpiGbl_RootTableList.CurrentTableCount;813}814815MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;816Tables = ACPI_ALLOCATE_ZEROED (817((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));818if (!Tables)819{820ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));821return_ACPI_STATUS (AE_NO_MEMORY);822}823824/* Copy and free the previous table array */825826CurrentTableCount = 0;827if (AcpiGbl_RootTableList.Tables)828{829for (i = 0; i < TableCount; i++)830{831if (AcpiGbl_RootTableList.Tables[i].Address)832{833memcpy (Tables + CurrentTableCount,834AcpiGbl_RootTableList.Tables + i,835sizeof (ACPI_TABLE_DESC));836CurrentTableCount++;837}838}839840if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)841{842ACPI_FREE (AcpiGbl_RootTableList.Tables);843}844}845846AcpiGbl_RootTableList.Tables = Tables;847AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;848AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;849AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;850851return_ACPI_STATUS (AE_OK);852}853854855/*******************************************************************************856*857* FUNCTION: AcpiTbGetNextTableDescriptor858*859* PARAMETERS: TableIndex - Where table index is returned860* TableDesc - Where table descriptor is returned861*862* RETURN: Status and table index/descriptor.863*864* DESCRIPTION: Allocate a new ACPI table entry to the global table list865*866******************************************************************************/867868ACPI_STATUS869AcpiTbGetNextTableDescriptor (870UINT32 *TableIndex,871ACPI_TABLE_DESC **TableDesc)872{873ACPI_STATUS Status;874UINT32 i;875876877/* Ensure that there is room for the table in the Root Table List */878879if (AcpiGbl_RootTableList.CurrentTableCount >=880AcpiGbl_RootTableList.MaxTableCount)881{882Status = AcpiTbResizeRootTableList();883if (ACPI_FAILURE (Status))884{885return (Status);886}887}888889i = AcpiGbl_RootTableList.CurrentTableCount;890AcpiGbl_RootTableList.CurrentTableCount++;891892if (TableIndex)893{894*TableIndex = i;895}896if (TableDesc)897{898*TableDesc = &AcpiGbl_RootTableList.Tables[i];899}900901return (AE_OK);902}903904905/*******************************************************************************906*907* FUNCTION: AcpiTbTerminate908*909* PARAMETERS: None910*911* RETURN: None912*913* DESCRIPTION: Delete all internal ACPI tables914*915******************************************************************************/916917void918AcpiTbTerminate (919void)920{921UINT32 i;922923924ACPI_FUNCTION_TRACE (TbTerminate);925926927(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);928929/* Delete the individual tables */930931for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)932{933AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);934}935936/*937* Delete the root table array if allocated locally. Array cannot be938* mapped, so we don't need to check for that flag.939*/940if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)941{942ACPI_FREE (AcpiGbl_RootTableList.Tables);943}944945AcpiGbl_RootTableList.Tables = NULL;946AcpiGbl_RootTableList.Flags = 0;947AcpiGbl_RootTableList.CurrentTableCount = 0;948949ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));950951(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);952return_VOID;953}954955956/*******************************************************************************957*958* FUNCTION: AcpiTbDeleteNamespaceByOwner959*960* PARAMETERS: TableIndex - Table index961*962* RETURN: Status963*964* DESCRIPTION: Delete all namespace objects created when this table was loaded.965*966******************************************************************************/967968ACPI_STATUS969AcpiTbDeleteNamespaceByOwner (970UINT32 TableIndex)971{972ACPI_OWNER_ID OwnerId;973ACPI_STATUS Status;974975976ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);977978979Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);980if (ACPI_FAILURE (Status))981{982return_ACPI_STATUS (Status);983}984985if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)986{987/* The table index does not exist */988989(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);990return_ACPI_STATUS (AE_NOT_EXIST);991}992993/* Get the owner ID for this table, used to delete namespace nodes */994995OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;996(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);997998/*999* Need to acquire the namespace writer lock to prevent interference1000* with any concurrent namespace walks. The interpreter must be1001* released during the deletion since the acquisition of the deletion1002* lock may block, and also since the execution of a namespace walk1003* must be allowed to use the interpreter.1004*/1005Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);1006if (ACPI_FAILURE (Status))1007{1008return_ACPI_STATUS (Status);1009}10101011AcpiNsDeleteNamespaceByOwner (OwnerId);1012AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);1013return_ACPI_STATUS (Status);1014}101510161017/*******************************************************************************1018*1019* FUNCTION: AcpiTbAllocateOwnerId1020*1021* PARAMETERS: TableIndex - Table index1022*1023* RETURN: Status1024*1025* DESCRIPTION: Allocates OwnerId in TableDesc1026*1027******************************************************************************/10281029ACPI_STATUS1030AcpiTbAllocateOwnerId (1031UINT32 TableIndex)1032{1033ACPI_STATUS Status = AE_BAD_PARAMETER;103410351036ACPI_FUNCTION_TRACE (TbAllocateOwnerId);103710381039(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);1040if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)1041{1042Status = AcpiUtAllocateOwnerId (1043&(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));1044}10451046(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);1047return_ACPI_STATUS (Status);1048}104910501051/*******************************************************************************1052*1053* FUNCTION: AcpiTbReleaseOwnerId1054*1055* PARAMETERS: TableIndex - Table index1056*1057* RETURN: Status1058*1059* DESCRIPTION: Releases OwnerId in TableDesc1060*1061******************************************************************************/10621063ACPI_STATUS1064AcpiTbReleaseOwnerId (1065UINT32 TableIndex)1066{1067ACPI_STATUS Status = AE_BAD_PARAMETER;106810691070ACPI_FUNCTION_TRACE (TbReleaseOwnerId);107110721073(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);1074if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)1075{1076AcpiUtReleaseOwnerId (1077&(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));1078Status = AE_OK;1079}10801081(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);1082return_ACPI_STATUS (Status);1083}108410851086/*******************************************************************************1087*1088* FUNCTION: AcpiTbGetOwnerId1089*1090* PARAMETERS: TableIndex - Table index1091* OwnerId - Where the table OwnerId is returned1092*1093* RETURN: Status1094*1095* DESCRIPTION: returns OwnerId for the ACPI table1096*1097******************************************************************************/10981099ACPI_STATUS1100AcpiTbGetOwnerId (1101UINT32 TableIndex,1102ACPI_OWNER_ID *OwnerId)1103{1104ACPI_STATUS Status = AE_BAD_PARAMETER;110511061107ACPI_FUNCTION_TRACE (TbGetOwnerId);110811091110(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);1111if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)1112{1113*OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;1114Status = AE_OK;1115}11161117(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);1118return_ACPI_STATUS (Status);1119}112011211122/*******************************************************************************1123*1124* FUNCTION: AcpiTbIsTableLoaded1125*1126* PARAMETERS: TableIndex - Index into the root table1127*1128* RETURN: Table Loaded Flag1129*1130******************************************************************************/11311132BOOLEAN1133AcpiTbIsTableLoaded (1134UINT32 TableIndex)1135{1136BOOLEAN IsLoaded = FALSE;113711381139(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);1140if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)1141{1142IsLoaded = (BOOLEAN)1143(AcpiGbl_RootTableList.Tables[TableIndex].Flags &1144ACPI_TABLE_IS_LOADED);1145}11461147(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);1148return (IsLoaded);1149}115011511152/*******************************************************************************1153*1154* FUNCTION: AcpiTbSetTableLoadedFlag1155*1156* PARAMETERS: TableIndex - Table index1157* IsLoaded - TRUE if table is loaded, FALSE otherwise1158*1159* RETURN: None1160*1161* DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.1162*1163******************************************************************************/11641165void1166AcpiTbSetTableLoadedFlag (1167UINT32 TableIndex,1168BOOLEAN IsLoaded)1169{11701171(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);1172if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)1173{1174if (IsLoaded)1175{1176AcpiGbl_RootTableList.Tables[TableIndex].Flags |=1177ACPI_TABLE_IS_LOADED;1178}1179else1180{1181AcpiGbl_RootTableList.Tables[TableIndex].Flags &=1182~ACPI_TABLE_IS_LOADED;1183}1184}11851186(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);1187}118811891190/*******************************************************************************1191*1192* FUNCTION: AcpiTbLoadTable1193*1194* PARAMETERS: TableIndex - Table index1195* ParentNode - Where table index is returned1196*1197* RETURN: Status1198*1199* DESCRIPTION: Load an ACPI table1200*1201******************************************************************************/12021203ACPI_STATUS1204AcpiTbLoadTable (1205UINT32 TableIndex,1206ACPI_NAMESPACE_NODE *ParentNode)1207{1208ACPI_TABLE_HEADER *Table;1209ACPI_STATUS Status;1210ACPI_OWNER_ID OwnerId;121112121213ACPI_FUNCTION_TRACE (TbLoadTable);121412151216/*1217* Note: Now table is "INSTALLED", it must be validated before1218* using.1219*/1220Status = AcpiGetTableByIndex (TableIndex, &Table);1221if (ACPI_FAILURE (Status))1222{1223return_ACPI_STATUS (Status);1224}12251226Status = AcpiNsLoadTable (TableIndex, ParentNode);1227if (ACPI_FAILURE (Status))1228{1229return_ACPI_STATUS (Status);1230}12311232/*1233* Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is1234* responsible for discovering any new wake GPEs by running _PRW methods1235* that may have been loaded by this table.1236*/1237Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);1238if (ACPI_SUCCESS (Status))1239{1240AcpiEvUpdateGpes (OwnerId);1241}12421243/* Invoke table handler */12441245AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);1246return_ACPI_STATUS (Status);1247}124812491250/*******************************************************************************1251*1252* FUNCTION: AcpiTbInstallAndLoadTable1253*1254* PARAMETERS: Address - Physical address of the table1255* Flags - Allocation flags of the table1256* Table - Pointer to the table (required for1257* virtual origins, optional for1258* physical)1259* Override - Whether override should be performed1260* TableIndex - Where table index is returned1261*1262* RETURN: Status1263*1264* DESCRIPTION: Install and load an ACPI table1265*1266******************************************************************************/12671268ACPI_STATUS1269AcpiTbInstallAndLoadTable (1270ACPI_PHYSICAL_ADDRESS Address,1271UINT8 Flags,1272ACPI_TABLE_HEADER *Table,1273BOOLEAN Override,1274UINT32 *TableIndex)1275{1276ACPI_STATUS Status;1277UINT32 i;127812791280ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);128112821283/* Install the table and load it into the namespace */12841285Status = AcpiTbInstallStandardTable (Address, Flags, Table, TRUE,1286Override, &i);1287if (ACPI_FAILURE (Status))1288{1289goto Exit;1290}12911292Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);12931294Exit:1295*TableIndex = i;1296return_ACPI_STATUS (Status);1297}129812991300/*******************************************************************************1301*1302* FUNCTION: AcpiTbUnloadTable1303*1304* PARAMETERS: TableIndex - Table index1305*1306* RETURN: Status1307*1308* DESCRIPTION: Unload an ACPI table1309*1310******************************************************************************/13111312ACPI_STATUS1313AcpiTbUnloadTable (1314UINT32 TableIndex)1315{1316ACPI_STATUS Status = AE_OK;1317ACPI_TABLE_HEADER *Table;131813191320ACPI_FUNCTION_TRACE (TbUnloadTable);132113221323/* Ensure the table is still loaded */13241325if (!AcpiTbIsTableLoaded (TableIndex))1326{1327return_ACPI_STATUS (AE_NOT_EXIST);1328}13291330/* Invoke table handler */13311332Status = AcpiGetTableByIndex (TableIndex, &Table);1333if (ACPI_SUCCESS (Status))1334{1335AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);1336}13371338/* Delete the portion of the namespace owned by this table */13391340Status = AcpiTbDeleteNamespaceByOwner (TableIndex);1341if (ACPI_FAILURE (Status))1342{1343return_ACPI_STATUS (Status);1344}13451346(void) AcpiTbReleaseOwnerId (TableIndex);1347AcpiTbSetTableLoadedFlag (TableIndex, FALSE);1348return_ACPI_STATUS (Status);1349}135013511352/*******************************************************************************1353*1354* FUNCTION: AcpiTbNotifyTable1355*1356* PARAMETERS: Event - Table event1357* Table - Validated table pointer1358*1359* RETURN: None1360*1361* DESCRIPTION: Notify a table event to the users.1362*1363******************************************************************************/13641365void1366AcpiTbNotifyTable (1367UINT32 Event,1368void *Table)1369{1370/* Invoke table handler if present */13711372if (AcpiGbl_TableHandler)1373{1374(void) AcpiGbl_TableHandler (Event, Table,1375AcpiGbl_TableHandlerContext);1376}1377}137813791380