Path: blob/main/sys/contrib/dev/acpica/components/executer/excreate.c
48521 views
/******************************************************************************1*2* Module Name: excreate - Named object creation3*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 ANY8586* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#include <contrib/dev/acpica/include/acpi.h>153#include <contrib/dev/acpica/include/accommon.h>154#include <contrib/dev/acpica/include/acinterp.h>155#include <contrib/dev/acpica/include/amlcode.h>156#include <contrib/dev/acpica/include/acnamesp.h>157158159#define _COMPONENT ACPI_EXECUTER160ACPI_MODULE_NAME ("excreate")161162163/*******************************************************************************164*165* FUNCTION: AcpiExCreateAlias166*167* PARAMETERS: WalkState - Current state, contains operands168*169* RETURN: Status170*171* DESCRIPTION: Create a new named alias172*173******************************************************************************/174175ACPI_STATUS176AcpiExCreateAlias (177ACPI_WALK_STATE *WalkState)178{179ACPI_NAMESPACE_NODE *TargetNode;180ACPI_NAMESPACE_NODE *AliasNode;181ACPI_STATUS Status = AE_OK;182183184ACPI_FUNCTION_TRACE (ExCreateAlias);185186187/* Get the source/alias operands (both namespace nodes) */188189AliasNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];190TargetNode = (ACPI_NAMESPACE_NODE *) WalkState->Operands[1];191192if ((TargetNode->Type == ACPI_TYPE_LOCAL_ALIAS) ||193(TargetNode->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))194{195/*196* Dereference an existing alias so that we don't create a chain197* of aliases. With this code, we guarantee that an alias is198* always exactly one level of indirection away from the199* actual aliased name.200*/201TargetNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, TargetNode->Object);202}203204/* Ensure that the target node is valid */205206if (!TargetNode)207{208return_ACPI_STATUS (AE_NULL_OBJECT);209}210211/* Construct the alias object (a namespace node) */212213switch (TargetNode->Type)214{215case ACPI_TYPE_METHOD:216/*217* Control method aliases need to be differentiated with218* a special type219*/220AliasNode->Type = ACPI_TYPE_LOCAL_METHOD_ALIAS;221break;222223default:224/*225* All other object types.226*227* The new alias has the type ALIAS and points to the original228* NS node, not the object itself.229*/230AliasNode->Type = ACPI_TYPE_LOCAL_ALIAS;231AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);232break;233}234235/* Since both operands are Nodes, we don't need to delete them */236237AliasNode->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);238return_ACPI_STATUS (Status);239}240241242/*******************************************************************************243*244* FUNCTION: AcpiExCreateEvent245*246* PARAMETERS: WalkState - Current state247*248* RETURN: Status249*250* DESCRIPTION: Create a new event object251*252******************************************************************************/253254ACPI_STATUS255AcpiExCreateEvent (256ACPI_WALK_STATE *WalkState)257{258ACPI_STATUS Status;259ACPI_OPERAND_OBJECT *ObjDesc;260261262ACPI_FUNCTION_TRACE (ExCreateEvent);263264265ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_EVENT);266if (!ObjDesc)267{268Status = AE_NO_MEMORY;269goto Cleanup;270}271272/*273* Create the actual OS semaphore, with zero initial units -- meaning274* that the event is created in an unsignalled state275*/276Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,277&ObjDesc->Event.OsSemaphore);278if (ACPI_FAILURE (Status))279{280goto Cleanup;281}282283/* Attach object to the Node */284285Status = AcpiNsAttachObject (286(ACPI_NAMESPACE_NODE *) WalkState->Operands[0],287ObjDesc, ACPI_TYPE_EVENT);288289Cleanup:290/*291* Remove local reference to the object (on error, will cause deletion292* of both object and semaphore if present.)293*/294AcpiUtRemoveReference (ObjDesc);295return_ACPI_STATUS (Status);296}297298299/*******************************************************************************300*301* FUNCTION: AcpiExCreateMutex302*303* PARAMETERS: WalkState - Current state304*305* RETURN: Status306*307* DESCRIPTION: Create a new mutex object308*309* Mutex (Name[0], SyncLevel[1])310*311******************************************************************************/312313ACPI_STATUS314AcpiExCreateMutex (315ACPI_WALK_STATE *WalkState)316{317ACPI_STATUS Status = AE_OK;318ACPI_OPERAND_OBJECT *ObjDesc;319320321ACPI_FUNCTION_TRACE_PTR (ExCreateMutex, ACPI_WALK_OPERANDS);322323324/* Create the new mutex object */325326ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);327if (!ObjDesc)328{329Status = AE_NO_MEMORY;330goto Cleanup;331}332333/* Create the actual OS Mutex */334335Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);336if (ACPI_FAILURE (Status))337{338goto Cleanup;339}340341/* Init object and attach to NS node */342343ObjDesc->Mutex.SyncLevel = (UINT8) WalkState->Operands[1]->Integer.Value;344ObjDesc->Mutex.Node = (ACPI_NAMESPACE_NODE *) WalkState->Operands[0];345346Status = AcpiNsAttachObject (347ObjDesc->Mutex.Node, ObjDesc, ACPI_TYPE_MUTEX);348349350Cleanup:351/*352* Remove local reference to the object (on error, will cause deletion353* of both object and semaphore if present.)354*/355AcpiUtRemoveReference (ObjDesc);356return_ACPI_STATUS (Status);357}358359360/*******************************************************************************361*362* FUNCTION: AcpiExCreateRegion363*364* PARAMETERS: AmlStart - Pointer to the region declaration AML365* AmlLength - Max length of the declaration AML366* SpaceId - Address space ID for the region367* WalkState - Current state368*369* RETURN: Status370*371* DESCRIPTION: Create a new operation region object372*373******************************************************************************/374375ACPI_STATUS376AcpiExCreateRegion (377UINT8 *AmlStart,378UINT32 AmlLength,379UINT8 SpaceId,380ACPI_WALK_STATE *WalkState)381{382ACPI_STATUS Status;383ACPI_OPERAND_OBJECT *ObjDesc;384ACPI_NAMESPACE_NODE *Node;385ACPI_OPERAND_OBJECT *RegionObj2;386387388ACPI_FUNCTION_TRACE (ExCreateRegion);389390391/* Get the Namespace Node */392393Node = WalkState->Op->Common.Node;394395/*396* If the region object is already attached to this node,397* just return398*/399if (AcpiNsGetAttachedObject (Node))400{401return_ACPI_STATUS (AE_OK);402}403404/*405* Space ID must be one of the predefined IDs, or in the user-defined406* range407*/408if (!AcpiIsValidSpaceId (SpaceId))409{410/*411* Print an error message, but continue. We don't want to abort412* a table load for this exception. Instead, if the region is413* actually used at runtime, abort the executing method.414*/415ACPI_ERROR ((AE_INFO,416"Invalid/unknown Address Space ID: 0x%2.2X", SpaceId));417}418419ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",420AcpiUtGetRegionName (SpaceId), SpaceId));421422/* Create the region descriptor */423424ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);425if (!ObjDesc)426{427Status = AE_NO_MEMORY;428goto Cleanup;429}430431/*432* Remember location in AML stream of address & length433* operands since they need to be evaluated at run time.434*/435RegionObj2 = AcpiNsGetSecondaryObject (ObjDesc);436RegionObj2->Extra.AmlStart = AmlStart;437RegionObj2->Extra.AmlLength = AmlLength;438RegionObj2->Extra.Method_REG = NULL;439if (WalkState->ScopeInfo)440{441RegionObj2->Extra.ScopeNode = WalkState->ScopeInfo->Scope.Node;442}443else444{445RegionObj2->Extra.ScopeNode = Node;446}447448/* Init the region from the operands */449450ObjDesc->Region.SpaceId = SpaceId;451ObjDesc->Region.Address = 0;452ObjDesc->Region.Length = 0;453ObjDesc->Region.Pointer = NULL;454ObjDesc->Region.Node = Node;455ObjDesc->Region.Handler = NULL;456ObjDesc->Common.Flags &=457~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED |458AOPOBJ_OBJECT_INITIALIZED);459460/* Install the new region object in the parent Node */461462Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_REGION);463464465Cleanup:466467/* Remove local reference to the object */468469AcpiUtRemoveReference (ObjDesc);470return_ACPI_STATUS (Status);471}472473474/*******************************************************************************475*476* FUNCTION: AcpiExCreateProcessor477*478* PARAMETERS: WalkState - Current state479*480* RETURN: Status481*482* DESCRIPTION: Create a new processor object and populate the fields483*484* Processor (Name[0], CpuID[1], PblockAddr[2], PblockLength[3])485*486******************************************************************************/487488ACPI_STATUS489AcpiExCreateProcessor (490ACPI_WALK_STATE *WalkState)491{492ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];493ACPI_OPERAND_OBJECT *ObjDesc;494ACPI_STATUS Status;495496497ACPI_FUNCTION_TRACE_PTR (ExCreateProcessor, WalkState);498499500/* Create the processor object */501502ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PROCESSOR);503if (!ObjDesc)504{505return_ACPI_STATUS (AE_NO_MEMORY);506}507508/* Initialize the processor object from the operands */509510ObjDesc->Processor.ProcId = (UINT8) Operand[1]->Integer.Value;511ObjDesc->Processor.Length = (UINT8) Operand[3]->Integer.Value;512ObjDesc->Processor.Address = (ACPI_IO_ADDRESS) Operand[2]->Integer.Value;513514/* Install the processor object in the parent Node */515516Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],517ObjDesc, ACPI_TYPE_PROCESSOR);518519/* Remove local reference to the object */520521AcpiUtRemoveReference (ObjDesc);522return_ACPI_STATUS (Status);523}524525526/*******************************************************************************527*528* FUNCTION: AcpiExCreatePowerResource529*530* PARAMETERS: WalkState - Current state531*532* RETURN: Status533*534* DESCRIPTION: Create a new PowerResource object and populate the fields535*536* PowerResource (Name[0], SystemLevel[1], ResourceOrder[2])537*538******************************************************************************/539540ACPI_STATUS541AcpiExCreatePowerResource (542ACPI_WALK_STATE *WalkState)543{544ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];545ACPI_STATUS Status;546ACPI_OPERAND_OBJECT *ObjDesc;547548549ACPI_FUNCTION_TRACE_PTR (ExCreatePowerResource, WalkState);550551552/* Create the power resource object */553554ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_POWER);555if (!ObjDesc)556{557return_ACPI_STATUS (AE_NO_MEMORY);558}559560/* Initialize the power object from the operands */561562ObjDesc->PowerResource.SystemLevel = (UINT8) Operand[1]->Integer.Value;563ObjDesc->PowerResource.ResourceOrder = (UINT16) Operand[2]->Integer.Value;564565/* Install the power resource object in the parent Node */566567Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],568ObjDesc, ACPI_TYPE_POWER);569570/* Remove local reference to the object */571572AcpiUtRemoveReference (ObjDesc);573return_ACPI_STATUS (Status);574}575576577/*******************************************************************************578*579* FUNCTION: AcpiExCreateMethod580*581* PARAMETERS: AmlStart - First byte of the method's AML582* AmlLength - AML byte count for this method583* WalkState - Current state584*585* RETURN: Status586*587* DESCRIPTION: Create a new method object588*589******************************************************************************/590591ACPI_STATUS592AcpiExCreateMethod (593UINT8 *AmlStart,594UINT32 AmlLength,595ACPI_WALK_STATE *WalkState)596{597ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];598ACPI_OPERAND_OBJECT *ObjDesc;599ACPI_STATUS Status;600UINT8 MethodFlags;601602603ACPI_FUNCTION_TRACE_PTR (ExCreateMethod, WalkState);604605606/* Create a new method object */607608ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);609if (!ObjDesc)610{611Status = AE_NO_MEMORY;612goto Exit;613}614615/* Save the method's AML pointer and length */616617ObjDesc->Method.AmlStart = AmlStart;618ObjDesc->Method.AmlLength = AmlLength;619ObjDesc->Method.Node = Operand[0];620621/*622* Disassemble the method flags. Split off the ArgCount, Serialized623* flag, and SyncLevel for efficiency.624*/625MethodFlags = (UINT8) Operand[1]->Integer.Value;626ObjDesc->Method.ParamCount = (UINT8)627(MethodFlags & AML_METHOD_ARG_COUNT);628629/*630* Get the SyncLevel. If method is serialized, a mutex will be631* created for this method when it is parsed.632*/633if (MethodFlags & AML_METHOD_SERIALIZED)634{635ObjDesc->Method.InfoFlags = ACPI_METHOD_SERIALIZED;636637/*638* ACPI 1.0: SyncLevel = 0639* ACPI 2.0: SyncLevel = SyncLevel in method declaration640*/641ObjDesc->Method.SyncLevel = (UINT8)642((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);643}644645/* Attach the new object to the method Node */646647Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) Operand[0],648ObjDesc, ACPI_TYPE_METHOD);649650/* Remove local reference to the object */651652AcpiUtRemoveReference (ObjDesc);653654Exit:655/* Remove a reference to the operand */656657AcpiUtRemoveReference (Operand[1]);658return_ACPI_STATUS (Status);659}660661662