Path: blob/main/sys/contrib/dev/acpica/components/tables/tbxfload.c
48400 views
/******************************************************************************1*2* Module Name: tbxfload - Table load/unload external interfaces3*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#define EXPORT_ACPI_INTERFACES152153#include <contrib/dev/acpica/include/acpi.h>154#include <contrib/dev/acpica/include/accommon.h>155#include <contrib/dev/acpica/include/acnamesp.h>156#include <contrib/dev/acpica/include/actables.h>157#include <contrib/dev/acpica/include/acevents.h>158159#define _COMPONENT ACPI_TABLES160ACPI_MODULE_NAME ("tbxfload")161162163/*******************************************************************************164*165* FUNCTION: AcpiLoadTables166*167* PARAMETERS: None168*169* RETURN: Status170*171* DESCRIPTION: Load the ACPI tables from the RSDT/XSDT172*173******************************************************************************/174175ACPI_STATUS ACPI_INIT_FUNCTION176AcpiLoadTables (177void)178{179ACPI_STATUS Status;180181182ACPI_FUNCTION_TRACE (AcpiLoadTables);183184185/*186* Install the default operation region handlers. These are the187* handlers that are defined by the ACPI specification to be188* "always accessible" -- namely, SystemMemory, SystemIO, and189* PCI_Config. This also means that no _REG methods need to be190* run for these address spaces. We need to have these handlers191* installed before any AML code can be executed, especially any192* module-level code (11/2015).193* Note that we allow OSPMs to install their own region handlers194* between AcpiInitializeSubsystem() and AcpiLoadTables() to use195* their customized default region handlers.196*/197Status = AcpiEvInstallRegionHandlers ();198if (ACPI_FAILURE (Status))199{200ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));201return_ACPI_STATUS (Status);202}203204/* Load the namespace from the tables */205206Status = AcpiTbLoadNamespace ();207208/* Don't let single failures abort the load */209210if (Status == AE_CTRL_TERMINATE)211{212Status = AE_OK;213}214215if (ACPI_FAILURE (Status))216{217ACPI_EXCEPTION ((AE_INFO, Status,218"While loading namespace from ACPI tables"));219}220221/*222* Initialize the objects in the namespace that remain uninitialized.223* This runs the executable AML that may be part of the declaration of224* these name objects:225* OperationRegions, BufferFields, Buffers, and Packages.226*227*/228Status = AcpiNsInitializeObjects ();229if (ACPI_SUCCESS (Status))230{231AcpiGbl_NamespaceInitialized = TRUE;232}233234return_ACPI_STATUS (Status);235}236237ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables)238239240/*******************************************************************************241*242* FUNCTION: AcpiTbLoadNamespace243*244* PARAMETERS: None245*246* RETURN: Status247*248* DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in249* the RSDT/XSDT.250*251******************************************************************************/252253ACPI_STATUS254AcpiTbLoadNamespace (255void)256{257ACPI_STATUS Status;258UINT32 i;259ACPI_TABLE_HEADER *NewDsdt;260ACPI_TABLE_DESC *Table;261UINT32 TablesLoaded = 0;262UINT32 TablesFailed = 0;263264265ACPI_FUNCTION_TRACE (TbLoadNamespace);266267268(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);269270/*271* Load the namespace. The DSDT is required, but any SSDT and272* PSDT tables are optional. Verify the DSDT.273*/274Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];275276if (!AcpiGbl_RootTableList.CurrentTableCount ||277!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_DSDT) ||278ACPI_FAILURE (AcpiTbValidateTable (Table)))279{280Status = AE_NO_ACPI_TABLES;281goto UnlockAndExit;282}283284/*285* Save the DSDT pointer for simple access. This is the mapped memory286* address. We must take care here because the address of the .Tables287* array can change dynamically as tables are loaded at run-time. Note:288* .Pointer field is not validated until after call to AcpiTbValidateTable.289*/290AcpiGbl_DSDT = Table->Pointer;291292/*293* Optionally copy the entire DSDT to local memory (instead of simply294* mapping it.) There are some BIOSs that corrupt or replace the original295* DSDT, creating the need for this option. Default is FALSE, do not copy296* the DSDT.297*/298if (AcpiGbl_CopyDsdtLocally)299{300NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);301if (NewDsdt)302{303AcpiGbl_DSDT = NewDsdt;304}305}306307/*308* Save the original DSDT header for detection of table corruption309* and/or replacement of the DSDT from outside the OS.310*/311memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,312sizeof (ACPI_TABLE_HEADER));313314/* Load and parse tables */315316(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);317Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);318(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);319if (ACPI_FAILURE (Status))320{321ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));322TablesFailed++;323}324else325{326TablesLoaded++;327}328329/* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */330331for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)332{333Table = &AcpiGbl_RootTableList.Tables[i];334335if (!Table->Address ||336(!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_SSDT) &&337!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_PSDT) &&338!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||339ACPI_FAILURE (AcpiTbValidateTable (Table)))340{341continue;342}343344/* Ignore errors while loading tables, get as many as possible */345346(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);347Status = AcpiNsLoadTable (i, AcpiGbl_RootNode);348(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);349if (ACPI_FAILURE (Status))350{351ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",352Table->Signature.Ascii, Table->Pointer->OemTableId));353354TablesFailed++;355356ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,357"Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",358Table->Signature.Ascii, Table->Pointer->OemTableId));359}360else361{362TablesLoaded++;363}364}365366if (!TablesFailed)367{368ACPI_INFO ((369"%u ACPI AML tables successfully acquired and loaded",370TablesLoaded));371}372else373{374ACPI_ERROR ((AE_INFO,375"%u table load failures, %u successful",376TablesFailed, TablesLoaded));377378/* Indicate at least one failure */379380Status = AE_CTRL_TERMINATE;381}382383#ifdef ACPI_APPLICATION384ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "\n"));385#endif386387388UnlockAndExit:389(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);390return_ACPI_STATUS (Status);391}392393394/*******************************************************************************395*396* FUNCTION: AcpiInstallTable397*398* PARAMETERS: Table - Pointer to the ACPI table to be installed.399*400* RETURN: Status401*402* DESCRIPTION: Dynamically install an ACPI table.403* Note: This function should only be invoked after404* AcpiInitializeTables() and before AcpiLoadTables().405*406******************************************************************************/407408ACPI_STATUS ACPI_INIT_FUNCTION409AcpiInstallTable (410ACPI_TABLE_HEADER *Table)411{412ACPI_STATUS Status;413UINT32 TableIndex;414415416ACPI_FUNCTION_TRACE (AcpiInstallTable);417418419Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),420ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, FALSE, &TableIndex);421422return_ACPI_STATUS (Status);423}424425ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable)426427428/*******************************************************************************429*430* FUNCTION: AcpiInstallPhysicalTable431*432* PARAMETERS: Address - Address of the ACPI table to be installed.433*434* RETURN: Status435*436* DESCRIPTION: Dynamically install an ACPI table.437* Note: This function should only be invoked after438* AcpiInitializeTables() and before AcpiLoadTables().439*440******************************************************************************/441442ACPI_STATUS ACPI_INIT_FUNCTION443AcpiInstallPhysicalTable (444ACPI_PHYSICAL_ADDRESS Address)445{446ACPI_STATUS Status;447UINT32 TableIndex;448449450ACPI_FUNCTION_TRACE (AcpiInstallPhysicalTable);451452453Status = AcpiTbInstallStandardTable (Address,454ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, FALSE, &TableIndex);455456return_ACPI_STATUS (Status);457}458459ACPI_EXPORT_SYMBOL_INIT (AcpiInstallPhysicalTable)460461462/*******************************************************************************463*464* FUNCTION: AcpiLoadTable465*466* PARAMETERS: Table - Pointer to a buffer containing the ACPI467* table to be loaded.468* TableIdx - Pointer to a UINT32 for storing the table469* index, might be NULL470*471* RETURN: Status472*473* DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must474* be a valid ACPI table with a valid ACPI table header.475* Note1: Mainly intended to support hotplug addition of SSDTs.476* Note2: Does not copy the incoming table. User is responsible477* to ensure that the table is not deleted or unmapped.478*479******************************************************************************/480481ACPI_STATUS482AcpiLoadTable (483ACPI_TABLE_HEADER *Table,484UINT32 *TableIdx)485{486ACPI_STATUS Status;487UINT32 TableIndex;488489490ACPI_FUNCTION_TRACE (AcpiLoadTable);491492493/* Parameter validation */494495if (!Table)496{497return_ACPI_STATUS (AE_BAD_PARAMETER);498}499500/* Install the table and load it into the namespace */501502ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));503Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),504ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, &TableIndex);505if (TableIdx)506{507*TableIdx = TableIndex;508}509510if (ACPI_SUCCESS (Status))511{512/* Complete the initialization/resolution of new objects */513514AcpiNsInitializeObjects ();515}516517return_ACPI_STATUS (Status);518}519520ACPI_EXPORT_SYMBOL (AcpiLoadTable)521522523/*******************************************************************************524*525* FUNCTION: AcpiUnloadParentTable526*527* PARAMETERS: Object - Handle to any namespace object owned by528* the table to be unloaded529*530* RETURN: Status531*532* DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads533* the table and deletes all namespace objects associated with534* that table. Unloading of the DSDT is not allowed.535* Note: Mainly intended to support hotplug removal of SSDTs.536*537******************************************************************************/538539ACPI_STATUS540AcpiUnloadParentTable (541ACPI_HANDLE Object)542{543ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);544ACPI_STATUS Status = AE_NOT_EXIST;545ACPI_OWNER_ID OwnerId;546UINT32 i;547548549ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);550551552/* Parameter validation */553554if (!Object)555{556return_ACPI_STATUS (AE_BAD_PARAMETER);557}558559/*560* The node OwnerId is currently the same as the parent table ID.561* However, this could change in the future.562*/563OwnerId = Node->OwnerId;564if (!OwnerId)565{566/* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */567568return_ACPI_STATUS (AE_TYPE);569}570571/* Must acquire the table lock during this operation */572573Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);574if (ACPI_FAILURE (Status))575{576return_ACPI_STATUS (Status);577}578579/* Find the table in the global table list */580581for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)582{583if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)584{585continue;586}587588/*589* Allow unload of SSDT and OEMx tables only. Do not allow unload590* of the DSDT. No other types of tables should get here, since591* only these types can contain AML and thus are the only types592* that can create namespace objects.593*/594if (ACPI_COMPARE_NAMESEG (595AcpiGbl_RootTableList.Tables[i].Signature.Ascii,596ACPI_SIG_DSDT))597{598Status = AE_TYPE;599break;600}601602(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);603Status = AcpiTbUnloadTable (i);604(void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);605break;606}607608(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);609return_ACPI_STATUS (Status);610}611612ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)613614615/*******************************************************************************616*617* FUNCTION: AcpiUnloadTable618*619* PARAMETERS: TableIndex - Index as returned by AcpiLoadTable620*621* RETURN: Status622*623* DESCRIPTION: Via the TableIndex representing an SSDT or OEMx table, unloads624* the table and deletes all namespace objects associated with625* that table. Unloading of the DSDT is not allowed.626* Note: Mainly intended to support hotplug removal of SSDTs.627*628******************************************************************************/629630ACPI_STATUS631AcpiUnloadTable (632UINT32 TableIndex)633{634ACPI_STATUS Status;635636637ACPI_FUNCTION_TRACE (AcpiUnloadTable);638639640if (TableIndex == 1)641{642/* TableIndex==1 means DSDT is the owner. DSDT cannot be unloaded */643644return_ACPI_STATUS (AE_TYPE);645}646647Status = AcpiTbUnloadTable (TableIndex);648return_ACPI_STATUS (Status);649}650651ACPI_EXPORT_SYMBOL (AcpiUnloadTable)652653654