Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dsinit.c
48521 views
/******************************************************************************1*2* Module Name: dsinit - Object initialization namespace walk3*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/acdispat.h>154#include <contrib/dev/acpica/include/acnamesp.h>155#include <contrib/dev/acpica/include/actables.h>156#include <contrib/dev/acpica/include/acinterp.h>157158#define _COMPONENT ACPI_DISPATCHER159ACPI_MODULE_NAME ("dsinit")160161162/* Local prototypes */163164static ACPI_STATUS165AcpiDsInitOneObject (166ACPI_HANDLE ObjHandle,167UINT32 Level,168void *Context,169void **ReturnValue);170171172/*******************************************************************************173*174* FUNCTION: AcpiDsInitOneObject175*176* PARAMETERS: ObjHandle - Node for the object177* Level - Current nesting level178* Context - Points to a init info struct179* ReturnValue - Not used180*181* RETURN: Status182*183* DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object184* within the namespace.185*186* Currently, the only objects that require initialization are:187* 1) Methods188* 2) Operation Regions189*190******************************************************************************/191192static ACPI_STATUS193AcpiDsInitOneObject (194ACPI_HANDLE ObjHandle,195UINT32 Level,196void *Context,197void **ReturnValue)198{199ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;200ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;201ACPI_STATUS Status;202ACPI_OPERAND_OBJECT *ObjDesc;203204205ACPI_FUNCTION_ENTRY ();206207208/*209* We are only interested in NS nodes owned by the table that210* was just loaded211*/212if (Node->OwnerId != Info->OwnerId)213{214return (AE_OK);215}216217Info->ObjectCount++;218219/* And even then, we are only interested in a few object types */220221switch (AcpiNsGetType (ObjHandle))222{223case ACPI_TYPE_REGION:224225Status = AcpiDsInitializeRegion (ObjHandle);226if (ACPI_FAILURE (Status))227{228ACPI_EXCEPTION ((AE_INFO, Status,229"During Region initialization %p [%4.4s]",230ObjHandle, AcpiUtGetNodeName (ObjHandle)));231}232233Info->OpRegionCount++;234break;235236case ACPI_TYPE_METHOD:237/*238* Auto-serialization support. We will examine each method that is239* NotSerialized to determine if it creates any Named objects. If240* it does, it will be marked serialized to prevent problems if241* the method is entered by two or more threads and an attempt is242* made to create the same named object twice -- which results in243* an AE_ALREADY_EXISTS exception and method abort.244*/245Info->MethodCount++;246ObjDesc = AcpiNsGetAttachedObject (Node);247if (!ObjDesc)248{249break;250}251252/* Ignore if already serialized */253254if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)255{256Info->SerialMethodCount++;257break;258}259260if (AcpiGbl_AutoSerializeMethods)261{262/* Parse/scan method and serialize it if necessary */263264AcpiDsAutoSerializeMethod (Node, ObjDesc);265if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)266{267/* Method was just converted to Serialized */268269Info->SerialMethodCount++;270Info->SerializedMethodCount++;271break;272}273}274275Info->NonSerialMethodCount++;276break;277278case ACPI_TYPE_DEVICE:279280Info->DeviceCount++;281break;282283default:284285break;286}287288/*289* We ignore errors from above, and always return OK, since290* we don't want to abort the walk on a single error.291*/292return (AE_OK);293}294295296/*******************************************************************************297*298* FUNCTION: AcpiDsInitializeObjects299*300* PARAMETERS: TableDesc - Descriptor for parent ACPI table301* StartNode - Root of subtree to be initialized.302*303* RETURN: Status304*305* DESCRIPTION: Walk the namespace starting at "StartNode" and perform any306* necessary initialization on the objects found therein307*308******************************************************************************/309310ACPI_STATUS311AcpiDsInitializeObjects (312UINT32 TableIndex,313ACPI_NAMESPACE_NODE *StartNode)314{315ACPI_STATUS Status;316ACPI_INIT_WALK_INFO Info;317ACPI_TABLE_HEADER *Table;318ACPI_OWNER_ID OwnerId;319320321ACPI_FUNCTION_TRACE (DsInitializeObjects);322323324Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);325if (ACPI_FAILURE (Status))326{327return_ACPI_STATUS (Status);328}329330ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,331"**** Starting initialization of namespace objects ****\n"));332333/* Set all init info to zero */334335memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));336337Info.OwnerId = OwnerId;338Info.TableIndex = TableIndex;339340/* Walk entire namespace from the supplied root */341342/*343* We don't use AcpiWalkNamespace since we do not want to acquire344* the namespace reader lock.345*/346Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,347ACPI_NS_WALK_NO_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);348if (ACPI_FAILURE (Status))349{350ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));351}352353Status = AcpiGetTableByIndex (TableIndex, &Table);354if (ACPI_FAILURE (Status))355{356return_ACPI_STATUS (Status);357}358359/* DSDT is always the first AML table */360361if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_DSDT))362{363ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,364"\nACPI table initialization:\n"));365}366367/* Summary of objects initialized */368369ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,370"Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "371"%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",372Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount,373Info.DeviceCount,Info.OpRegionCount, Info.MethodCount,374Info.SerialMethodCount, Info.NonSerialMethodCount,375Info.SerializedMethodCount));376377ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",378Info.MethodCount, Info.OpRegionCount));379380return_ACPI_STATUS (AE_OK);381}382383384