Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsobject.c
48524 views
/*******************************************************************************1*2* Module Name: nsobject - Utilities for objects attached to namespace3* table entries4*5******************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* patents that are infringed by the Original Intel Code, to make, use, sell,31* offer to sell, and import the Covered Code and derivative works thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* the above Copyright Notice, the above License, this list of Conditions,46* and the following Disclaimer and Export Compliance provision. In addition,47* Licensee must cause all Covered Code to which Licensee contributes to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* 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/acnamesp.h>155156157#define _COMPONENT ACPI_NAMESPACE158ACPI_MODULE_NAME ("nsobject")159160161/*******************************************************************************162*163* FUNCTION: AcpiNsAttachObject164*165* PARAMETERS: Node - Parent Node166* Object - Object to be attached167* Type - Type of object, or ACPI_TYPE_ANY if not168* known169*170* RETURN: Status171*172* DESCRIPTION: Record the given object as the value associated with the173* name whose ACPI_HANDLE is passed. If Object is NULL174* and Type is ACPI_TYPE_ANY, set the name as having no value.175* Note: Future may require that the Node->Flags field be passed176* as a parameter.177*178* MUTEX: Assumes namespace is locked179*180******************************************************************************/181182ACPI_STATUS183AcpiNsAttachObject (184ACPI_NAMESPACE_NODE *Node,185ACPI_OPERAND_OBJECT *Object,186ACPI_OBJECT_TYPE Type)187{188ACPI_OPERAND_OBJECT *ObjDesc;189ACPI_OPERAND_OBJECT *LastObjDesc;190ACPI_OBJECT_TYPE ObjectType = ACPI_TYPE_ANY;191192193ACPI_FUNCTION_TRACE (NsAttachObject);194195196/*197* Parameter validation198*/199if (!Node)200{201/* Invalid handle */202203ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));204return_ACPI_STATUS (AE_BAD_PARAMETER);205}206207if (!Object && (ACPI_TYPE_ANY != Type))208{209/* Null object */210211ACPI_ERROR ((AE_INFO,212"Null object, but type not ACPI_TYPE_ANY"));213return_ACPI_STATUS (AE_BAD_PARAMETER);214}215216if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)217{218/* Not a name handle */219220ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",221Node, AcpiUtGetDescriptorName (Node)));222return_ACPI_STATUS (AE_BAD_PARAMETER);223}224225/* Check if this object is already attached */226227if (Node->Object == Object)228{229ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,230"Obj %p already installed in NameObj %p\n",231Object, Node));232233return_ACPI_STATUS (AE_OK);234}235236/* If null object, we will just install it */237238if (!Object)239{240ObjDesc = NULL;241ObjectType = ACPI_TYPE_ANY;242}243244/*245* If the source object is a namespace Node with an attached object,246* we will use that (attached) object247*/248else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&249((ACPI_NAMESPACE_NODE *) Object)->Object)250{251/*252* Value passed is a name handle and that name has a253* non-null value. Use that name's value and type.254*/255ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;256ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;257}258259/*260* Otherwise, we will use the parameter object, but we must type261* it first262*/263else264{265ObjDesc = (ACPI_OPERAND_OBJECT *) Object;266267/* Use the given type */268269ObjectType = Type;270}271272ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",273ObjDesc, Node, AcpiUtGetNodeName (Node)));274275/* Detach an existing attached object if present */276277if (Node->Object)278{279AcpiNsDetachObject (Node);280}281282if (ObjDesc)283{284/*285* Must increment the new value's reference count286* (if it is an internal object)287*/288AcpiUtAddReference (ObjDesc);289290/*291* Handle objects with multiple descriptors - walk292* to the end of the descriptor list293*/294LastObjDesc = ObjDesc;295while (LastObjDesc->Common.NextObject)296{297LastObjDesc = LastObjDesc->Common.NextObject;298}299300/* Install the object at the front of the object list */301302LastObjDesc->Common.NextObject = Node->Object;303}304305Node->Type = (UINT8) ObjectType;306Node->Object = ObjDesc;307308return_ACPI_STATUS (AE_OK);309}310311312/*******************************************************************************313*314* FUNCTION: AcpiNsDetachObject315*316* PARAMETERS: Node - A Namespace node whose object will be detached317*318* RETURN: None.319*320* DESCRIPTION: Detach/delete an object associated with a namespace node.321* if the object is an allocated object, it is freed.322* Otherwise, the field is simply cleared.323*324******************************************************************************/325326void327AcpiNsDetachObject (328ACPI_NAMESPACE_NODE *Node)329{330ACPI_OPERAND_OBJECT *ObjDesc;331332333ACPI_FUNCTION_TRACE (NsDetachObject);334335336ObjDesc = Node->Object;337338if (!ObjDesc ||339(ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))340{341return_VOID;342}343344if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)345{346/* Free the dynamic aml buffer */347348if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)349{350ACPI_FREE (ObjDesc->Method.AmlStart);351}352}353354if (ObjDesc->Common.Type == ACPI_TYPE_REGION)355{356AcpiUtRemoveAddressRange(ObjDesc->Region.SpaceId, Node);357}358359/* Clear the Node entry in all cases */360361Node->Object = NULL;362if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)363{364/* Unlink object from front of possible object list */365366Node->Object = ObjDesc->Common.NextObject;367368/* Handle possible 2-descriptor object */369370if (Node->Object &&371(Node->Object->Common.Type != ACPI_TYPE_LOCAL_DATA))372{373Node->Object = Node->Object->Common.NextObject;374}375376/*377* Detach the object from any data objects (which are still held by378* the namespace node)379*/380if (ObjDesc->Common.NextObject &&381((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))382{383ObjDesc->Common.NextObject = NULL;384}385}386387/* Reset the node type to untyped */388389Node->Type = ACPI_TYPE_ANY;390391ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",392Node, AcpiUtGetNodeName (Node), ObjDesc));393394/* Remove one reference on the object (and all subobjects) */395396AcpiUtRemoveReference (ObjDesc);397return_VOID;398}399400401/*******************************************************************************402*403* FUNCTION: AcpiNsGetAttachedObject404*405* PARAMETERS: Node - Namespace node406*407* RETURN: Current value of the object field from the Node whose408* handle is passed409*410* DESCRIPTION: Obtain the object attached to a namespace node.411*412******************************************************************************/413414ACPI_OPERAND_OBJECT *415AcpiNsGetAttachedObject (416ACPI_NAMESPACE_NODE *Node)417{418ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);419420421if (!Node)422{423ACPI_WARNING ((AE_INFO, "Null Node ptr"));424return_PTR (NULL);425}426427if (!Node->Object ||428((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&429(ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED)) ||430((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))431{432return_PTR (NULL);433}434435return_PTR (Node->Object);436}437438439/*******************************************************************************440*441* FUNCTION: AcpiNsGetSecondaryObject442*443* PARAMETERS: Node - Namespace node444*445* RETURN: Current value of the object field from the Node whose446* handle is passed.447*448* DESCRIPTION: Obtain a secondary object associated with a namespace node.449*450******************************************************************************/451452ACPI_OPERAND_OBJECT *453AcpiNsGetSecondaryObject (454ACPI_OPERAND_OBJECT *ObjDesc)455{456ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);457458459if ((!ObjDesc) ||460(ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA) ||461(!ObjDesc->Common.NextObject) ||462((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))463{464return_PTR (NULL);465}466467return_PTR (ObjDesc->Common.NextObject);468}469470471/*******************************************************************************472*473* FUNCTION: AcpiNsAttachData474*475* PARAMETERS: Node - Namespace node476* Handler - Handler to be associated with the data477* Data - Data to be attached478*479* RETURN: Status480*481* DESCRIPTION: Low-level attach data. Create and attach a Data object.482*483******************************************************************************/484485ACPI_STATUS486AcpiNsAttachData (487ACPI_NAMESPACE_NODE *Node,488ACPI_OBJECT_HANDLER Handler,489void *Data)490{491ACPI_OPERAND_OBJECT *PrevObjDesc;492ACPI_OPERAND_OBJECT *ObjDesc;493ACPI_OPERAND_OBJECT *DataDesc;494495496/* We only allow one attachment per handler */497498PrevObjDesc = NULL;499ObjDesc = Node->Object;500while (ObjDesc)501{502if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&503(ObjDesc->Data.Handler == Handler))504{505return (AE_ALREADY_EXISTS);506}507508PrevObjDesc = ObjDesc;509ObjDesc = ObjDesc->Common.NextObject;510}511512/* Create an internal object for the data */513514DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);515if (!DataDesc)516{517return (AE_NO_MEMORY);518}519520DataDesc->Data.Handler = Handler;521DataDesc->Data.Pointer = Data;522523/* Install the data object */524525if (PrevObjDesc)526{527PrevObjDesc->Common.NextObject = DataDesc;528}529else530{531Node->Object = DataDesc;532}533534return (AE_OK);535}536537538/*******************************************************************************539*540* FUNCTION: AcpiNsDetachData541*542* PARAMETERS: Node - Namespace node543* Handler - Handler associated with the data544*545* RETURN: Status546*547* DESCRIPTION: Low-level detach data. Delete the data node, but the caller548* is responsible for the actual data.549*550******************************************************************************/551552ACPI_STATUS553AcpiNsDetachData (554ACPI_NAMESPACE_NODE *Node,555ACPI_OBJECT_HANDLER Handler)556{557ACPI_OPERAND_OBJECT *ObjDesc;558ACPI_OPERAND_OBJECT *PrevObjDesc;559560561PrevObjDesc = NULL;562ObjDesc = Node->Object;563while (ObjDesc)564{565if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&566(ObjDesc->Data.Handler == Handler))567{568if (PrevObjDesc)569{570PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;571}572else573{574Node->Object = ObjDesc->Common.NextObject;575}576577AcpiUtRemoveReference (ObjDesc);578return (AE_OK);579}580581PrevObjDesc = ObjDesc;582ObjDesc = ObjDesc->Common.NextObject;583}584585return (AE_NOT_FOUND);586}587588589/*******************************************************************************590*591* FUNCTION: AcpiNsGetAttachedData592*593* PARAMETERS: Node - Namespace node594* Handler - Handler associated with the data595* Data - Where the data is returned596*597* RETURN: Status598*599* DESCRIPTION: Low level interface to obtain data previously associated with600* a namespace node.601*602******************************************************************************/603604ACPI_STATUS605AcpiNsGetAttachedData (606ACPI_NAMESPACE_NODE *Node,607ACPI_OBJECT_HANDLER Handler,608void **Data)609{610ACPI_OPERAND_OBJECT *ObjDesc;611612613ObjDesc = Node->Object;614while (ObjDesc)615{616if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&617(ObjDesc->Data.Handler == Handler))618{619*Data = ObjDesc->Data.Pointer;620return (AE_OK);621}622623ObjDesc = ObjDesc->Common.NextObject;624}625626return (AE_NOT_FOUND);627}628629630