xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/namespace/nsobject.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /*******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: nsobject - Utilities for objects attached to namespace
40174267aSFredrik Holmqvist  *                         table entries
50174267aSFredrik Holmqvist  *
60174267aSFredrik Holmqvist  ******************************************************************************/
70174267aSFredrik Holmqvist 
80174267aSFredrik Holmqvist /******************************************************************************
90174267aSFredrik Holmqvist  *
100174267aSFredrik Holmqvist  * 1. Copyright Notice
110174267aSFredrik Holmqvist  *
12*6dde014fSPulkoMandy  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
130174267aSFredrik Holmqvist  * All rights reserved.
140174267aSFredrik Holmqvist  *
150174267aSFredrik Holmqvist  * 2. License
160174267aSFredrik Holmqvist  *
170174267aSFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
180174267aSFredrik Holmqvist  * rights. You may have additional license terms from the party that provided
190174267aSFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
200174267aSFredrik Holmqvist  * property rights.
210174267aSFredrik Holmqvist  *
220174267aSFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
230174267aSFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
240174267aSFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
250174267aSFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
260174267aSFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
270174267aSFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
280174267aSFredrik Holmqvist  *
290174267aSFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
300174267aSFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
310174267aSFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
320174267aSFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
330174267aSFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
340174267aSFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
350174267aSFredrik Holmqvist  * to or modifications of the Original Intel Code. No other license or right
360174267aSFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
370174267aSFredrik Holmqvist  *
380174267aSFredrik Holmqvist  * The above copyright and patent license is granted only if the following
390174267aSFredrik Holmqvist  * conditions are met:
400174267aSFredrik Holmqvist  *
410174267aSFredrik Holmqvist  * 3. Conditions
420174267aSFredrik Holmqvist  *
430174267aSFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
440174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
450174267aSFredrik Holmqvist  * Code or modification with rights to further distribute source must include
460174267aSFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
470174267aSFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision. In addition,
480174267aSFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
490174267aSFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
500174267aSFredrik Holmqvist  * Code and the date of any change. Licensee must include in that file the
510174267aSFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee. Licensee
520174267aSFredrik Holmqvist  * must include a prominent statement that the modification is derived,
530174267aSFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
540174267aSFredrik Holmqvist  *
550174267aSFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
560174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
570174267aSFredrik Holmqvist  * Code or modification without rights to further distribute source must
580174267aSFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
590174267aSFredrik Holmqvist  * documentation and/or other materials provided with distribution. In
600174267aSFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
610174267aSFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
620174267aSFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
630174267aSFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
640174267aSFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
650174267aSFredrik Holmqvist  * make.
660174267aSFredrik Holmqvist  *
670174267aSFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
680174267aSFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
690174267aSFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
700174267aSFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
710174267aSFredrik Holmqvist  * distribution.
720174267aSFredrik Holmqvist  *
730174267aSFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
740174267aSFredrik Holmqvist  * Intel Code.
750174267aSFredrik Holmqvist  *
760174267aSFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
770174267aSFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
780174267aSFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
790174267aSFredrik Holmqvist  * without prior written authorization from Intel.
800174267aSFredrik Holmqvist  *
810174267aSFredrik Holmqvist  * 4. Disclaimer and Export Compliance
820174267aSFredrik Holmqvist  *
830174267aSFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
840174267aSFredrik Holmqvist  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
850174267aSFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
860174267aSFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
870174267aSFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
880174267aSFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
890174267aSFredrik Holmqvist  * PARTICULAR PURPOSE.
900174267aSFredrik Holmqvist  *
910174267aSFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
920174267aSFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
930174267aSFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
940174267aSFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
950174267aSFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
960174267aSFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
970174267aSFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
980174267aSFredrik Holmqvist  * LIMITED REMEDY.
990174267aSFredrik Holmqvist  *
1000174267aSFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1010174267aSFredrik Holmqvist  * software or system incorporating such software without first obtaining any
1020174267aSFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
1030174267aSFredrik Holmqvist  * any other agency or department of the United States Government. In the
1040174267aSFredrik Holmqvist  * event Licensee exports any such software from the United States or
1050174267aSFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
1060174267aSFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
1070174267aSFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
1080174267aSFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1090174267aSFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
1100174267aSFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
1110174267aSFredrik Holmqvist  * United States government or any agency thereof requires an export license,
1120174267aSFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
1130174267aSFredrik Holmqvist  * such license, approval or letter.
1140174267aSFredrik Holmqvist  *
115ff2e2f81SFredrik Holmqvist  *****************************************************************************
116ff2e2f81SFredrik Holmqvist  *
117ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
118ff2e2f81SFredrik Holmqvist  * following license:
119ff2e2f81SFredrik Holmqvist  *
120ff2e2f81SFredrik Holmqvist  * Redistribution and use in source and binary forms, with or without
121ff2e2f81SFredrik Holmqvist  * modification, are permitted provided that the following conditions
122ff2e2f81SFredrik Holmqvist  * are met:
123ff2e2f81SFredrik Holmqvist  * 1. Redistributions of source code must retain the above copyright
124ff2e2f81SFredrik Holmqvist  *    notice, this list of conditions, and the following disclaimer,
125ff2e2f81SFredrik Holmqvist  *    without modification.
126ff2e2f81SFredrik Holmqvist  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127ff2e2f81SFredrik Holmqvist  *    substantially similar to the "NO WARRANTY" disclaimer below
128ff2e2f81SFredrik Holmqvist  *    ("Disclaimer") and any redistribution must be conditioned upon
129ff2e2f81SFredrik Holmqvist  *    including a substantially similar Disclaimer requirement for further
130ff2e2f81SFredrik Holmqvist  *    binary redistribution.
131ff2e2f81SFredrik Holmqvist  * 3. Neither the names of the above-listed copyright holders nor the names
132ff2e2f81SFredrik Holmqvist  *    of any contributors may be used to endorse or promote products derived
133ff2e2f81SFredrik Holmqvist  *    from this software without specific prior written permission.
134ff2e2f81SFredrik Holmqvist  *
135ff2e2f81SFredrik Holmqvist  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136ff2e2f81SFredrik Holmqvist  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137ff2e2f81SFredrik Holmqvist  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138ff2e2f81SFredrik Holmqvist  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139ff2e2f81SFredrik Holmqvist  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140ff2e2f81SFredrik Holmqvist  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141ff2e2f81SFredrik Holmqvist  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142ff2e2f81SFredrik Holmqvist  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143ff2e2f81SFredrik Holmqvist  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144ff2e2f81SFredrik Holmqvist  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145ff2e2f81SFredrik Holmqvist  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146ff2e2f81SFredrik Holmqvist  *
147ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
148ff2e2f81SFredrik Holmqvist  * GNU General Public License ("GPL") version 2 as published by the Free
149ff2e2f81SFredrik Holmqvist  * Software Foundation.
150ff2e2f81SFredrik Holmqvist  *
1510174267aSFredrik Holmqvist  *****************************************************************************/
1520174267aSFredrik Holmqvist 
1530174267aSFredrik Holmqvist #include "acpi.h"
1540174267aSFredrik Holmqvist #include "accommon.h"
1550174267aSFredrik Holmqvist #include "acnamesp.h"
1560174267aSFredrik Holmqvist 
1570174267aSFredrik Holmqvist 
1580174267aSFredrik Holmqvist #define _COMPONENT          ACPI_NAMESPACE
1590174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("nsobject")
1600174267aSFredrik Holmqvist 
1610174267aSFredrik Holmqvist 
1620174267aSFredrik Holmqvist /*******************************************************************************
1630174267aSFredrik Holmqvist  *
1640174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsAttachObject
1650174267aSFredrik Holmqvist  *
1660174267aSFredrik Holmqvist  * PARAMETERS:  Node                - Parent Node
1670174267aSFredrik Holmqvist  *              Object              - Object to be attached
1680174267aSFredrik Holmqvist  *              Type                - Type of object, or ACPI_TYPE_ANY if not
1690174267aSFredrik Holmqvist  *                                    known
1700174267aSFredrik Holmqvist  *
1710174267aSFredrik Holmqvist  * RETURN:      Status
1720174267aSFredrik Holmqvist  *
1730174267aSFredrik Holmqvist  * DESCRIPTION: Record the given object as the value associated with the
1740174267aSFredrik Holmqvist  *              name whose ACPI_HANDLE is passed. If Object is NULL
1750174267aSFredrik Holmqvist  *              and Type is ACPI_TYPE_ANY, set the name as having no value.
1760174267aSFredrik Holmqvist  *              Note: Future may require that the Node->Flags field be passed
1770174267aSFredrik Holmqvist  *              as a parameter.
1780174267aSFredrik Holmqvist  *
1790174267aSFredrik Holmqvist  * MUTEX:       Assumes namespace is locked
1800174267aSFredrik Holmqvist  *
1810174267aSFredrik Holmqvist  ******************************************************************************/
1820174267aSFredrik Holmqvist 
1830174267aSFredrik Holmqvist ACPI_STATUS
AcpiNsAttachObject(ACPI_NAMESPACE_NODE * Node,ACPI_OPERAND_OBJECT * Object,ACPI_OBJECT_TYPE Type)1840174267aSFredrik Holmqvist AcpiNsAttachObject (
1850174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node,
1860174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *Object,
1870174267aSFredrik Holmqvist     ACPI_OBJECT_TYPE        Type)
1880174267aSFredrik Holmqvist {
1890174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
1900174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *LastObjDesc;
1910174267aSFredrik Holmqvist     ACPI_OBJECT_TYPE        ObjectType = ACPI_TYPE_ANY;
1920174267aSFredrik Holmqvist 
1930174267aSFredrik Holmqvist 
1940174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (NsAttachObject);
1950174267aSFredrik Holmqvist 
1960174267aSFredrik Holmqvist 
1970174267aSFredrik Holmqvist     /*
1980174267aSFredrik Holmqvist      * Parameter validation
1990174267aSFredrik Holmqvist      */
2000174267aSFredrik Holmqvist     if (!Node)
2010174267aSFredrik Holmqvist     {
2020174267aSFredrik Holmqvist         /* Invalid handle */
2030174267aSFredrik Holmqvist 
2040174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));
2050174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_BAD_PARAMETER);
2060174267aSFredrik Holmqvist     }
2070174267aSFredrik Holmqvist 
2080174267aSFredrik Holmqvist     if (!Object && (ACPI_TYPE_ANY != Type))
2090174267aSFredrik Holmqvist     {
2100174267aSFredrik Holmqvist         /* Null object */
2110174267aSFredrik Holmqvist 
2120174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
2130174267aSFredrik Holmqvist             "Null object, but type not ACPI_TYPE_ANY"));
2140174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_BAD_PARAMETER);
2150174267aSFredrik Holmqvist     }
2160174267aSFredrik Holmqvist 
2170174267aSFredrik Holmqvist     if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
2180174267aSFredrik Holmqvist     {
2190174267aSFredrik Holmqvist         /* Not a name handle */
2200174267aSFredrik Holmqvist 
2210174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",
2220174267aSFredrik Holmqvist             Node, AcpiUtGetDescriptorName (Node)));
2230174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_BAD_PARAMETER);
2240174267aSFredrik Holmqvist     }
2250174267aSFredrik Holmqvist 
2260174267aSFredrik Holmqvist     /* Check if this object is already attached */
2270174267aSFredrik Holmqvist 
2280174267aSFredrik Holmqvist     if (Node->Object == Object)
2290174267aSFredrik Holmqvist     {
2300174267aSFredrik Holmqvist         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
2310174267aSFredrik Holmqvist             "Obj %p already installed in NameObj %p\n",
2320174267aSFredrik Holmqvist             Object, Node));
2330174267aSFredrik Holmqvist 
2340174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
2350174267aSFredrik Holmqvist     }
2360174267aSFredrik Holmqvist 
2370174267aSFredrik Holmqvist     /* If null object, we will just install it */
2380174267aSFredrik Holmqvist 
2390174267aSFredrik Holmqvist     if (!Object)
2400174267aSFredrik Holmqvist     {
2410174267aSFredrik Holmqvist         ObjDesc    = NULL;
2420174267aSFredrik Holmqvist         ObjectType = ACPI_TYPE_ANY;
2430174267aSFredrik Holmqvist     }
2440174267aSFredrik Holmqvist 
2450174267aSFredrik Holmqvist     /*
2460174267aSFredrik Holmqvist      * If the source object is a namespace Node with an attached object,
2470174267aSFredrik Holmqvist      * we will use that (attached) object
2480174267aSFredrik Holmqvist      */
2490174267aSFredrik Holmqvist     else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&
2500174267aSFredrik Holmqvist             ((ACPI_NAMESPACE_NODE *) Object)->Object)
2510174267aSFredrik Holmqvist     {
2520174267aSFredrik Holmqvist         /*
2530174267aSFredrik Holmqvist          * Value passed is a name handle and that name has a
2540174267aSFredrik Holmqvist          * non-null value. Use that name's value and type.
2550174267aSFredrik Holmqvist          */
2560174267aSFredrik Holmqvist         ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;
2570174267aSFredrik Holmqvist         ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
2580174267aSFredrik Holmqvist     }
2590174267aSFredrik Holmqvist 
2600174267aSFredrik Holmqvist     /*
2610174267aSFredrik Holmqvist      * Otherwise, we will use the parameter object, but we must type
2620174267aSFredrik Holmqvist      * it first
2630174267aSFredrik Holmqvist      */
2640174267aSFredrik Holmqvist     else
2650174267aSFredrik Holmqvist     {
2660174267aSFredrik Holmqvist         ObjDesc = (ACPI_OPERAND_OBJECT  *) Object;
2670174267aSFredrik Holmqvist 
2680174267aSFredrik Holmqvist         /* Use the given type */
2690174267aSFredrik Holmqvist 
2700174267aSFredrik Holmqvist         ObjectType = Type;
2710174267aSFredrik Holmqvist     }
2720174267aSFredrik Holmqvist 
2730174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
2740174267aSFredrik Holmqvist         ObjDesc, Node, AcpiUtGetNodeName (Node)));
2750174267aSFredrik Holmqvist 
2760174267aSFredrik Holmqvist     /* Detach an existing attached object if present */
2770174267aSFredrik Holmqvist 
2780174267aSFredrik Holmqvist     if (Node->Object)
2790174267aSFredrik Holmqvist     {
2800174267aSFredrik Holmqvist         AcpiNsDetachObject (Node);
2810174267aSFredrik Holmqvist     }
2820174267aSFredrik Holmqvist 
2830174267aSFredrik Holmqvist     if (ObjDesc)
2840174267aSFredrik Holmqvist     {
2850174267aSFredrik Holmqvist         /*
2860174267aSFredrik Holmqvist          * Must increment the new value's reference count
2870174267aSFredrik Holmqvist          * (if it is an internal object)
2880174267aSFredrik Holmqvist          */
2890174267aSFredrik Holmqvist         AcpiUtAddReference (ObjDesc);
2900174267aSFredrik Holmqvist 
2910174267aSFredrik Holmqvist         /*
2920174267aSFredrik Holmqvist          * Handle objects with multiple descriptors - walk
2930174267aSFredrik Holmqvist          * to the end of the descriptor list
2940174267aSFredrik Holmqvist          */
2950174267aSFredrik Holmqvist         LastObjDesc = ObjDesc;
2960174267aSFredrik Holmqvist         while (LastObjDesc->Common.NextObject)
2970174267aSFredrik Holmqvist         {
2980174267aSFredrik Holmqvist             LastObjDesc = LastObjDesc->Common.NextObject;
2990174267aSFredrik Holmqvist         }
3000174267aSFredrik Holmqvist 
3010174267aSFredrik Holmqvist         /* Install the object at the front of the object list */
3020174267aSFredrik Holmqvist 
3030174267aSFredrik Holmqvist         LastObjDesc->Common.NextObject = Node->Object;
3040174267aSFredrik Holmqvist     }
3050174267aSFredrik Holmqvist 
3060174267aSFredrik Holmqvist     Node->Type = (UINT8) ObjectType;
3070174267aSFredrik Holmqvist     Node->Object = ObjDesc;
3080174267aSFredrik Holmqvist 
3090174267aSFredrik Holmqvist     return_ACPI_STATUS (AE_OK);
3100174267aSFredrik Holmqvist }
3110174267aSFredrik Holmqvist 
3120174267aSFredrik Holmqvist 
3130174267aSFredrik Holmqvist /*******************************************************************************
3140174267aSFredrik Holmqvist  *
3150174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsDetachObject
3160174267aSFredrik Holmqvist  *
3170174267aSFredrik Holmqvist  * PARAMETERS:  Node           - A Namespace node whose object will be detached
3180174267aSFredrik Holmqvist  *
3190174267aSFredrik Holmqvist  * RETURN:      None.
3200174267aSFredrik Holmqvist  *
3210174267aSFredrik Holmqvist  * DESCRIPTION: Detach/delete an object associated with a namespace node.
3220174267aSFredrik Holmqvist  *              if the object is an allocated object, it is freed.
3230174267aSFredrik Holmqvist  *              Otherwise, the field is simply cleared.
3240174267aSFredrik Holmqvist  *
3250174267aSFredrik Holmqvist  ******************************************************************************/
3260174267aSFredrik Holmqvist 
3270174267aSFredrik Holmqvist void
AcpiNsDetachObject(ACPI_NAMESPACE_NODE * Node)3280174267aSFredrik Holmqvist AcpiNsDetachObject (
3290174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node)
3300174267aSFredrik Holmqvist {
3310174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
3320174267aSFredrik Holmqvist 
3330174267aSFredrik Holmqvist 
3340174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (NsDetachObject);
3350174267aSFredrik Holmqvist 
3360174267aSFredrik Holmqvist 
3370174267aSFredrik Holmqvist     ObjDesc = Node->Object;
3380174267aSFredrik Holmqvist 
3390174267aSFredrik Holmqvist     if (!ObjDesc ||
3400174267aSFredrik Holmqvist         (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
3410174267aSFredrik Holmqvist     {
3420174267aSFredrik Holmqvist         return_VOID;
3430174267aSFredrik Holmqvist     }
3440174267aSFredrik Holmqvist 
3450174267aSFredrik Holmqvist     if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)
3460174267aSFredrik Holmqvist     {
3470174267aSFredrik Holmqvist         /* Free the dynamic aml buffer */
3480174267aSFredrik Holmqvist 
3490174267aSFredrik Holmqvist         if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)
3500174267aSFredrik Holmqvist         {
3510174267aSFredrik Holmqvist             ACPI_FREE (ObjDesc->Method.AmlStart);
3520174267aSFredrik Holmqvist         }
3530174267aSFredrik Holmqvist     }
3540174267aSFredrik Holmqvist 
3550ffed378SFredrik Holmqvist     if (ObjDesc->Common.Type == ACPI_TYPE_REGION)
3560ffed378SFredrik Holmqvist     {
3570ffed378SFredrik Holmqvist         AcpiUtRemoveAddressRange(ObjDesc->Region.SpaceId, Node);
3580ffed378SFredrik Holmqvist     }
3590ffed378SFredrik Holmqvist 
360ad5bbfb8SFredrik Holmqvist     /* Clear the Node entry in all cases */
3610174267aSFredrik Holmqvist 
3620174267aSFredrik Holmqvist     Node->Object = NULL;
3630174267aSFredrik Holmqvist     if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
3640174267aSFredrik Holmqvist     {
365ad5bbfb8SFredrik Holmqvist         /* Unlink object from front of possible object list */
366ad5bbfb8SFredrik Holmqvist 
3670174267aSFredrik Holmqvist         Node->Object = ObjDesc->Common.NextObject;
368ad5bbfb8SFredrik Holmqvist 
369ad5bbfb8SFredrik Holmqvist         /* Handle possible 2-descriptor object */
370ad5bbfb8SFredrik Holmqvist 
3710174267aSFredrik Holmqvist         if (Node->Object &&
372ad5bbfb8SFredrik Holmqvist            (Node->Object->Common.Type != ACPI_TYPE_LOCAL_DATA))
3730174267aSFredrik Holmqvist         {
3740174267aSFredrik Holmqvist             Node->Object = Node->Object->Common.NextObject;
3750174267aSFredrik Holmqvist         }
376ad5bbfb8SFredrik Holmqvist 
377ad5bbfb8SFredrik Holmqvist         /*
378ad5bbfb8SFredrik Holmqvist          * Detach the object from any data objects (which are still held by
379ad5bbfb8SFredrik Holmqvist          * the namespace node)
380ad5bbfb8SFredrik Holmqvist          */
381ad5bbfb8SFredrik Holmqvist         if (ObjDesc->Common.NextObject &&
382ad5bbfb8SFredrik Holmqvist            ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
383ad5bbfb8SFredrik Holmqvist         {
384ad5bbfb8SFredrik Holmqvist            ObjDesc->Common.NextObject = NULL;
385ad5bbfb8SFredrik Holmqvist         }
3860174267aSFredrik Holmqvist     }
3870174267aSFredrik Holmqvist 
3880174267aSFredrik Holmqvist     /* Reset the node type to untyped */
3890174267aSFredrik Holmqvist 
3900174267aSFredrik Holmqvist     Node->Type = ACPI_TYPE_ANY;
3910174267aSFredrik Holmqvist 
3920174267aSFredrik Holmqvist     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
3930174267aSFredrik Holmqvist         Node, AcpiUtGetNodeName (Node), ObjDesc));
3940174267aSFredrik Holmqvist 
3950174267aSFredrik Holmqvist     /* Remove one reference on the object (and all subobjects) */
3960174267aSFredrik Holmqvist 
3970174267aSFredrik Holmqvist     AcpiUtRemoveReference (ObjDesc);
3980174267aSFredrik Holmqvist     return_VOID;
3990174267aSFredrik Holmqvist }
4000174267aSFredrik Holmqvist 
4010174267aSFredrik Holmqvist 
4020174267aSFredrik Holmqvist /*******************************************************************************
4030174267aSFredrik Holmqvist  *
4040174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsGetAttachedObject
4050174267aSFredrik Holmqvist  *
4060174267aSFredrik Holmqvist  * PARAMETERS:  Node             - Namespace node
4070174267aSFredrik Holmqvist  *
4080174267aSFredrik Holmqvist  * RETURN:      Current value of the object field from the Node whose
4090174267aSFredrik Holmqvist  *              handle is passed
4100174267aSFredrik Holmqvist  *
4110174267aSFredrik Holmqvist  * DESCRIPTION: Obtain the object attached to a namespace node.
4120174267aSFredrik Holmqvist  *
4130174267aSFredrik Holmqvist  ******************************************************************************/
4140174267aSFredrik Holmqvist 
4150174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT *
AcpiNsGetAttachedObject(ACPI_NAMESPACE_NODE * Node)4160174267aSFredrik Holmqvist AcpiNsGetAttachedObject (
4170174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node)
4180174267aSFredrik Holmqvist {
4190174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);
4200174267aSFredrik Holmqvist 
4210174267aSFredrik Holmqvist 
4220174267aSFredrik Holmqvist     if (!Node)
4230174267aSFredrik Holmqvist     {
4240174267aSFredrik Holmqvist         ACPI_WARNING ((AE_INFO, "Null Node ptr"));
4250174267aSFredrik Holmqvist         return_PTR (NULL);
4260174267aSFredrik Holmqvist     }
4270174267aSFredrik Holmqvist 
4280174267aSFredrik Holmqvist     if (!Node->Object ||
4290174267aSFredrik Holmqvist             ((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&
4300174267aSFredrik Holmqvist              (ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED))  ||
4310174267aSFredrik Holmqvist         ((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))
4320174267aSFredrik Holmqvist     {
4330174267aSFredrik Holmqvist         return_PTR (NULL);
4340174267aSFredrik Holmqvist     }
4350174267aSFredrik Holmqvist 
4360174267aSFredrik Holmqvist     return_PTR (Node->Object);
4370174267aSFredrik Holmqvist }
4380174267aSFredrik Holmqvist 
4390174267aSFredrik Holmqvist 
4400174267aSFredrik Holmqvist /*******************************************************************************
4410174267aSFredrik Holmqvist  *
4420174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsGetSecondaryObject
4430174267aSFredrik Holmqvist  *
4440174267aSFredrik Holmqvist  * PARAMETERS:  Node             - Namespace node
4450174267aSFredrik Holmqvist  *
4460174267aSFredrik Holmqvist  * RETURN:      Current value of the object field from the Node whose
4470174267aSFredrik Holmqvist  *              handle is passed.
4480174267aSFredrik Holmqvist  *
4490174267aSFredrik Holmqvist  * DESCRIPTION: Obtain a secondary object associated with a namespace node.
4500174267aSFredrik Holmqvist  *
4510174267aSFredrik Holmqvist  ******************************************************************************/
4520174267aSFredrik Holmqvist 
4530174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT *
AcpiNsGetSecondaryObject(ACPI_OPERAND_OBJECT * ObjDesc)4540174267aSFredrik Holmqvist AcpiNsGetSecondaryObject (
4550174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc)
4560174267aSFredrik Holmqvist {
4570174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);
4580174267aSFredrik Holmqvist 
4590174267aSFredrik Holmqvist 
4600174267aSFredrik Holmqvist     if ((!ObjDesc)                                     ||
4610174267aSFredrik Holmqvist         (ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA)  ||
4620174267aSFredrik Holmqvist         (!ObjDesc->Common.NextObject)                  ||
4630174267aSFredrik Holmqvist         ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
4640174267aSFredrik Holmqvist     {
4650174267aSFredrik Holmqvist         return_PTR (NULL);
4660174267aSFredrik Holmqvist     }
4670174267aSFredrik Holmqvist 
4680174267aSFredrik Holmqvist     return_PTR (ObjDesc->Common.NextObject);
4690174267aSFredrik Holmqvist }
4700174267aSFredrik Holmqvist 
4710174267aSFredrik Holmqvist 
4720174267aSFredrik Holmqvist /*******************************************************************************
4730174267aSFredrik Holmqvist  *
4740174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsAttachData
4750174267aSFredrik Holmqvist  *
4760174267aSFredrik Holmqvist  * PARAMETERS:  Node            - Namespace node
4770174267aSFredrik Holmqvist  *              Handler         - Handler to be associated with the data
4780174267aSFredrik Holmqvist  *              Data            - Data to be attached
4790174267aSFredrik Holmqvist  *
4800174267aSFredrik Holmqvist  * RETURN:      Status
4810174267aSFredrik Holmqvist  *
4820174267aSFredrik Holmqvist  * DESCRIPTION: Low-level attach data. Create and attach a Data object.
4830174267aSFredrik Holmqvist  *
4840174267aSFredrik Holmqvist  ******************************************************************************/
4850174267aSFredrik Holmqvist 
4860174267aSFredrik Holmqvist ACPI_STATUS
AcpiNsAttachData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler,void * Data)4870174267aSFredrik Holmqvist AcpiNsAttachData (
4880174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node,
4890174267aSFredrik Holmqvist     ACPI_OBJECT_HANDLER     Handler,
4900174267aSFredrik Holmqvist     void                    *Data)
4910174267aSFredrik Holmqvist {
4920174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *PrevObjDesc;
4930174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
4940174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *DataDesc;
4950174267aSFredrik Holmqvist 
4960174267aSFredrik Holmqvist 
4970174267aSFredrik Holmqvist     /* We only allow one attachment per handler */
4980174267aSFredrik Holmqvist 
4990174267aSFredrik Holmqvist     PrevObjDesc = NULL;
5000174267aSFredrik Holmqvist     ObjDesc = Node->Object;
5010174267aSFredrik Holmqvist     while (ObjDesc)
5020174267aSFredrik Holmqvist     {
5030174267aSFredrik Holmqvist         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
5040174267aSFredrik Holmqvist             (ObjDesc->Data.Handler == Handler))
5050174267aSFredrik Holmqvist         {
5060174267aSFredrik Holmqvist             return (AE_ALREADY_EXISTS);
5070174267aSFredrik Holmqvist         }
5080174267aSFredrik Holmqvist 
5090174267aSFredrik Holmqvist         PrevObjDesc = ObjDesc;
5100174267aSFredrik Holmqvist         ObjDesc = ObjDesc->Common.NextObject;
5110174267aSFredrik Holmqvist     }
5120174267aSFredrik Holmqvist 
5130174267aSFredrik Holmqvist     /* Create an internal object for the data */
5140174267aSFredrik Holmqvist 
5150174267aSFredrik Holmqvist     DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);
5160174267aSFredrik Holmqvist     if (!DataDesc)
5170174267aSFredrik Holmqvist     {
5180174267aSFredrik Holmqvist         return (AE_NO_MEMORY);
5190174267aSFredrik Holmqvist     }
5200174267aSFredrik Holmqvist 
5210174267aSFredrik Holmqvist     DataDesc->Data.Handler = Handler;
5220174267aSFredrik Holmqvist     DataDesc->Data.Pointer = Data;
5230174267aSFredrik Holmqvist 
5240174267aSFredrik Holmqvist     /* Install the data object */
5250174267aSFredrik Holmqvist 
5260174267aSFredrik Holmqvist     if (PrevObjDesc)
5270174267aSFredrik Holmqvist     {
5280174267aSFredrik Holmqvist         PrevObjDesc->Common.NextObject = DataDesc;
5290174267aSFredrik Holmqvist     }
5300174267aSFredrik Holmqvist     else
5310174267aSFredrik Holmqvist     {
5320174267aSFredrik Holmqvist         Node->Object = DataDesc;
5330174267aSFredrik Holmqvist     }
5340174267aSFredrik Holmqvist 
5350174267aSFredrik Holmqvist     return (AE_OK);
5360174267aSFredrik Holmqvist }
5370174267aSFredrik Holmqvist 
5380174267aSFredrik Holmqvist 
5390174267aSFredrik Holmqvist /*******************************************************************************
5400174267aSFredrik Holmqvist  *
5410174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsDetachData
5420174267aSFredrik Holmqvist  *
5430174267aSFredrik Holmqvist  * PARAMETERS:  Node            - Namespace node
5440174267aSFredrik Holmqvist  *              Handler         - Handler associated with the data
5450174267aSFredrik Holmqvist  *
5460174267aSFredrik Holmqvist  * RETURN:      Status
5470174267aSFredrik Holmqvist  *
5480174267aSFredrik Holmqvist  * DESCRIPTION: Low-level detach data. Delete the data node, but the caller
5490174267aSFredrik Holmqvist  *              is responsible for the actual data.
5500174267aSFredrik Holmqvist  *
5510174267aSFredrik Holmqvist  ******************************************************************************/
5520174267aSFredrik Holmqvist 
5530174267aSFredrik Holmqvist ACPI_STATUS
AcpiNsDetachData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler)5540174267aSFredrik Holmqvist AcpiNsDetachData (
5550174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node,
5560174267aSFredrik Holmqvist     ACPI_OBJECT_HANDLER     Handler)
5570174267aSFredrik Holmqvist {
5580174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
5590174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *PrevObjDesc;
5600174267aSFredrik Holmqvist 
5610174267aSFredrik Holmqvist 
5620174267aSFredrik Holmqvist     PrevObjDesc = NULL;
5630174267aSFredrik Holmqvist     ObjDesc = Node->Object;
5640174267aSFredrik Holmqvist     while (ObjDesc)
5650174267aSFredrik Holmqvist     {
5660174267aSFredrik Holmqvist         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
5670174267aSFredrik Holmqvist             (ObjDesc->Data.Handler == Handler))
5680174267aSFredrik Holmqvist         {
5690174267aSFredrik Holmqvist             if (PrevObjDesc)
5700174267aSFredrik Holmqvist             {
5710174267aSFredrik Holmqvist                 PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;
5720174267aSFredrik Holmqvist             }
5730174267aSFredrik Holmqvist             else
5740174267aSFredrik Holmqvist             {
5750174267aSFredrik Holmqvist                 Node->Object = ObjDesc->Common.NextObject;
5760174267aSFredrik Holmqvist             }
5770174267aSFredrik Holmqvist 
5780174267aSFredrik Holmqvist             AcpiUtRemoveReference (ObjDesc);
5790174267aSFredrik Holmqvist             return (AE_OK);
5800174267aSFredrik Holmqvist         }
5810174267aSFredrik Holmqvist 
5820174267aSFredrik Holmqvist         PrevObjDesc = ObjDesc;
5830174267aSFredrik Holmqvist         ObjDesc = ObjDesc->Common.NextObject;
5840174267aSFredrik Holmqvist     }
5850174267aSFredrik Holmqvist 
5860174267aSFredrik Holmqvist     return (AE_NOT_FOUND);
5870174267aSFredrik Holmqvist }
5880174267aSFredrik Holmqvist 
5890174267aSFredrik Holmqvist 
5900174267aSFredrik Holmqvist /*******************************************************************************
5910174267aSFredrik Holmqvist  *
5920174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsGetAttachedData
5930174267aSFredrik Holmqvist  *
5940174267aSFredrik Holmqvist  * PARAMETERS:  Node            - Namespace node
5950174267aSFredrik Holmqvist  *              Handler         - Handler associated with the data
5960174267aSFredrik Holmqvist  *              Data            - Where the data is returned
5970174267aSFredrik Holmqvist  *
5980174267aSFredrik Holmqvist  * RETURN:      Status
5990174267aSFredrik Holmqvist  *
6000174267aSFredrik Holmqvist  * DESCRIPTION: Low level interface to obtain data previously associated with
6010174267aSFredrik Holmqvist  *              a namespace node.
6020174267aSFredrik Holmqvist  *
6030174267aSFredrik Holmqvist  ******************************************************************************/
6040174267aSFredrik Holmqvist 
6050174267aSFredrik Holmqvist ACPI_STATUS
AcpiNsGetAttachedData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler,void ** Data)6060174267aSFredrik Holmqvist AcpiNsGetAttachedData (
6070174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node,
6080174267aSFredrik Holmqvist     ACPI_OBJECT_HANDLER     Handler,
6090174267aSFredrik Holmqvist     void                    **Data)
6100174267aSFredrik Holmqvist {
6110174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
6120174267aSFredrik Holmqvist 
6130174267aSFredrik Holmqvist 
6140174267aSFredrik Holmqvist     ObjDesc = Node->Object;
6150174267aSFredrik Holmqvist     while (ObjDesc)
6160174267aSFredrik Holmqvist     {
6170174267aSFredrik Holmqvist         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
6180174267aSFredrik Holmqvist             (ObjDesc->Data.Handler == Handler))
6190174267aSFredrik Holmqvist         {
6200174267aSFredrik Holmqvist             *Data = ObjDesc->Data.Pointer;
6210174267aSFredrik Holmqvist             return (AE_OK);
6220174267aSFredrik Holmqvist         }
6230174267aSFredrik Holmqvist 
6240174267aSFredrik Holmqvist         ObjDesc = ObjDesc->Common.NextObject;
6250174267aSFredrik Holmqvist     }
6260174267aSFredrik Holmqvist 
6270174267aSFredrik Holmqvist     return (AE_NOT_FOUND);
6280174267aSFredrik Holmqvist }
629