xref: /minix3/minix/drivers/power/acpi/namespace/nsobject.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: nsobject - Utilities for objects attached to namespace
4433d6423SLionel Sambuc  *                         table entries
5433d6423SLionel Sambuc  *
6433d6423SLionel Sambuc  ******************************************************************************/
7433d6423SLionel Sambuc 
8*29492bb7SDavid van Moolenbroek /*
9*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
10433d6423SLionel Sambuc  * All rights reserved.
11433d6423SLionel Sambuc  *
12*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
13*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
14*29492bb7SDavid van Moolenbroek  * are met:
15*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
16*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
17*29492bb7SDavid van Moolenbroek  *    without modification.
18*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
20*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
21*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
22*29492bb7SDavid van Moolenbroek  *    binary redistribution.
23*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
24*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
25*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
26433d6423SLionel Sambuc  *
27*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
28*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
29*29492bb7SDavid van Moolenbroek  * Software Foundation.
30433d6423SLionel Sambuc  *
31*29492bb7SDavid van Moolenbroek  * NO WARRANTY
32*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
43*29492bb7SDavid van Moolenbroek  */
44433d6423SLionel Sambuc 
45433d6423SLionel Sambuc #include "acpi.h"
46433d6423SLionel Sambuc #include "accommon.h"
47433d6423SLionel Sambuc #include "acnamesp.h"
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc 
50433d6423SLionel Sambuc #define _COMPONENT          ACPI_NAMESPACE
51433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("nsobject")
52433d6423SLionel Sambuc 
53433d6423SLionel Sambuc 
54433d6423SLionel Sambuc /*******************************************************************************
55433d6423SLionel Sambuc  *
56433d6423SLionel Sambuc  * FUNCTION:    AcpiNsAttachObject
57433d6423SLionel Sambuc  *
58433d6423SLionel Sambuc  * PARAMETERS:  Node                - Parent Node
59433d6423SLionel Sambuc  *              Object              - Object to be attached
60433d6423SLionel Sambuc  *              Type                - Type of object, or ACPI_TYPE_ANY if not
61433d6423SLionel Sambuc  *                                    known
62433d6423SLionel Sambuc  *
63433d6423SLionel Sambuc  * RETURN:      Status
64433d6423SLionel Sambuc  *
65433d6423SLionel Sambuc  * DESCRIPTION: Record the given object as the value associated with the
66433d6423SLionel Sambuc  *              name whose ACPI_HANDLE is passed. If Object is NULL
67433d6423SLionel Sambuc  *              and Type is ACPI_TYPE_ANY, set the name as having no value.
68433d6423SLionel Sambuc  *              Note: Future may require that the Node->Flags field be passed
69433d6423SLionel Sambuc  *              as a parameter.
70433d6423SLionel Sambuc  *
71433d6423SLionel Sambuc  * MUTEX:       Assumes namespace is locked
72433d6423SLionel Sambuc  *
73433d6423SLionel Sambuc  ******************************************************************************/
74433d6423SLionel Sambuc 
75433d6423SLionel Sambuc ACPI_STATUS
AcpiNsAttachObject(ACPI_NAMESPACE_NODE * Node,ACPI_OPERAND_OBJECT * Object,ACPI_OBJECT_TYPE Type)76433d6423SLionel Sambuc AcpiNsAttachObject (
77433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
78433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Object,
79433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type)
80433d6423SLionel Sambuc {
81433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
82433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *LastObjDesc;
83433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        ObjectType = ACPI_TYPE_ANY;
84433d6423SLionel Sambuc 
85433d6423SLionel Sambuc 
86433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsAttachObject);
87433d6423SLionel Sambuc 
88433d6423SLionel Sambuc 
89433d6423SLionel Sambuc     /*
90433d6423SLionel Sambuc      * Parameter validation
91433d6423SLionel Sambuc      */
92433d6423SLionel Sambuc     if (!Node)
93433d6423SLionel Sambuc     {
94433d6423SLionel Sambuc         /* Invalid handle */
95433d6423SLionel Sambuc 
96433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));
97433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
98433d6423SLionel Sambuc     }
99433d6423SLionel Sambuc 
100433d6423SLionel Sambuc     if (!Object && (ACPI_TYPE_ANY != Type))
101433d6423SLionel Sambuc     {
102433d6423SLionel Sambuc         /* Null object */
103433d6423SLionel Sambuc 
104433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
105433d6423SLionel Sambuc             "Null object, but type not ACPI_TYPE_ANY"));
106433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
107433d6423SLionel Sambuc     }
108433d6423SLionel Sambuc 
109433d6423SLionel Sambuc     if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
110433d6423SLionel Sambuc     {
111433d6423SLionel Sambuc         /* Not a name handle */
112433d6423SLionel Sambuc 
113433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",
114433d6423SLionel Sambuc             Node, AcpiUtGetDescriptorName (Node)));
115433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
116433d6423SLionel Sambuc     }
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc     /* Check if this object is already attached */
119433d6423SLionel Sambuc 
120433d6423SLionel Sambuc     if (Node->Object == Object)
121433d6423SLionel Sambuc     {
122433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
123433d6423SLionel Sambuc             "Obj %p already installed in NameObj %p\n",
124433d6423SLionel Sambuc             Object, Node));
125433d6423SLionel Sambuc 
126433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
127433d6423SLionel Sambuc     }
128433d6423SLionel Sambuc 
129433d6423SLionel Sambuc     /* If null object, we will just install it */
130433d6423SLionel Sambuc 
131433d6423SLionel Sambuc     if (!Object)
132433d6423SLionel Sambuc     {
133433d6423SLionel Sambuc         ObjDesc    = NULL;
134433d6423SLionel Sambuc         ObjectType = ACPI_TYPE_ANY;
135433d6423SLionel Sambuc     }
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc     /*
138433d6423SLionel Sambuc      * If the source object is a namespace Node with an attached object,
139433d6423SLionel Sambuc      * we will use that (attached) object
140433d6423SLionel Sambuc      */
141433d6423SLionel Sambuc     else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&
142433d6423SLionel Sambuc             ((ACPI_NAMESPACE_NODE *) Object)->Object)
143433d6423SLionel Sambuc     {
144433d6423SLionel Sambuc         /*
145433d6423SLionel Sambuc          * Value passed is a name handle and that name has a
146433d6423SLionel Sambuc          * non-null value. Use that name's value and type.
147433d6423SLionel Sambuc          */
148433d6423SLionel Sambuc         ObjDesc    = ((ACPI_NAMESPACE_NODE *) Object)->Object;
149433d6423SLionel Sambuc         ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
150433d6423SLionel Sambuc     }
151433d6423SLionel Sambuc 
152433d6423SLionel Sambuc     /*
153433d6423SLionel Sambuc      * Otherwise, we will use the parameter object, but we must type
154433d6423SLionel Sambuc      * it first
155433d6423SLionel Sambuc      */
156433d6423SLionel Sambuc     else
157433d6423SLionel Sambuc     {
158433d6423SLionel Sambuc         ObjDesc = (ACPI_OPERAND_OBJECT  *) Object;
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc         /* Use the given type */
161433d6423SLionel Sambuc 
162433d6423SLionel Sambuc         ObjectType = Type;
163433d6423SLionel Sambuc     }
164433d6423SLionel Sambuc 
165433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
166433d6423SLionel Sambuc         ObjDesc, Node, AcpiUtGetNodeName (Node)));
167433d6423SLionel Sambuc 
168433d6423SLionel Sambuc     /* Detach an existing attached object if present */
169433d6423SLionel Sambuc 
170433d6423SLionel Sambuc     if (Node->Object)
171433d6423SLionel Sambuc     {
172433d6423SLionel Sambuc         AcpiNsDetachObject (Node);
173433d6423SLionel Sambuc     }
174433d6423SLionel Sambuc 
175433d6423SLionel Sambuc     if (ObjDesc)
176433d6423SLionel Sambuc     {
177433d6423SLionel Sambuc         /*
178433d6423SLionel Sambuc          * Must increment the new value's reference count
179433d6423SLionel Sambuc          * (if it is an internal object)
180433d6423SLionel Sambuc          */
181433d6423SLionel Sambuc         AcpiUtAddReference (ObjDesc);
182433d6423SLionel Sambuc 
183433d6423SLionel Sambuc         /*
184433d6423SLionel Sambuc          * Handle objects with multiple descriptors - walk
185433d6423SLionel Sambuc          * to the end of the descriptor list
186433d6423SLionel Sambuc          */
187433d6423SLionel Sambuc         LastObjDesc = ObjDesc;
188433d6423SLionel Sambuc         while (LastObjDesc->Common.NextObject)
189433d6423SLionel Sambuc         {
190433d6423SLionel Sambuc             LastObjDesc = LastObjDesc->Common.NextObject;
191433d6423SLionel Sambuc         }
192433d6423SLionel Sambuc 
193433d6423SLionel Sambuc         /* Install the object at the front of the object list */
194433d6423SLionel Sambuc 
195433d6423SLionel Sambuc         LastObjDesc->Common.NextObject = Node->Object;
196433d6423SLionel Sambuc     }
197433d6423SLionel Sambuc 
198433d6423SLionel Sambuc     Node->Type     = (UINT8) ObjectType;
199433d6423SLionel Sambuc     Node->Object   = ObjDesc;
200433d6423SLionel Sambuc 
201433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
202433d6423SLionel Sambuc }
203433d6423SLionel Sambuc 
204433d6423SLionel Sambuc 
205433d6423SLionel Sambuc /*******************************************************************************
206433d6423SLionel Sambuc  *
207433d6423SLionel Sambuc  * FUNCTION:    AcpiNsDetachObject
208433d6423SLionel Sambuc  *
209433d6423SLionel Sambuc  * PARAMETERS:  Node           - A Namespace node whose object will be detached
210433d6423SLionel Sambuc  *
211433d6423SLionel Sambuc  * RETURN:      None.
212433d6423SLionel Sambuc  *
213433d6423SLionel Sambuc  * DESCRIPTION: Detach/delete an object associated with a namespace node.
214433d6423SLionel Sambuc  *              if the object is an allocated object, it is freed.
215433d6423SLionel Sambuc  *              Otherwise, the field is simply cleared.
216433d6423SLionel Sambuc  *
217433d6423SLionel Sambuc  ******************************************************************************/
218433d6423SLionel Sambuc 
219433d6423SLionel Sambuc void
AcpiNsDetachObject(ACPI_NAMESPACE_NODE * Node)220433d6423SLionel Sambuc AcpiNsDetachObject (
221433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node)
222433d6423SLionel Sambuc {
223433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
224433d6423SLionel Sambuc 
225433d6423SLionel Sambuc 
226433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsDetachObject);
227433d6423SLionel Sambuc 
228433d6423SLionel Sambuc 
229433d6423SLionel Sambuc     ObjDesc = Node->Object;
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc     if (!ObjDesc ||
232433d6423SLionel Sambuc         (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
233433d6423SLionel Sambuc     {
234433d6423SLionel Sambuc         return_VOID;
235433d6423SLionel Sambuc     }
236433d6423SLionel Sambuc 
237433d6423SLionel Sambuc     if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)
238433d6423SLionel Sambuc     {
239433d6423SLionel Sambuc         /* Free the dynamic aml buffer */
240433d6423SLionel Sambuc 
241433d6423SLionel Sambuc         if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)
242433d6423SLionel Sambuc         {
243433d6423SLionel Sambuc             ACPI_FREE (ObjDesc->Method.AmlStart);
244433d6423SLionel Sambuc         }
245433d6423SLionel Sambuc     }
246433d6423SLionel Sambuc 
247*29492bb7SDavid van Moolenbroek     /* Clear the Node entry in all cases */
248433d6423SLionel Sambuc 
249433d6423SLionel Sambuc     Node->Object = NULL;
250433d6423SLionel Sambuc     if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
251433d6423SLionel Sambuc     {
252*29492bb7SDavid van Moolenbroek         /* Unlink object from front of possible object list */
253*29492bb7SDavid van Moolenbroek 
254433d6423SLionel Sambuc         Node->Object = ObjDesc->Common.NextObject;
255*29492bb7SDavid van Moolenbroek 
256*29492bb7SDavid van Moolenbroek         /* Handle possible 2-descriptor object */
257*29492bb7SDavid van Moolenbroek 
258433d6423SLionel Sambuc         if (Node->Object &&
259*29492bb7SDavid van Moolenbroek            (Node->Object->Common.Type != ACPI_TYPE_LOCAL_DATA))
260433d6423SLionel Sambuc         {
261433d6423SLionel Sambuc             Node->Object = Node->Object->Common.NextObject;
262433d6423SLionel Sambuc         }
263*29492bb7SDavid van Moolenbroek 
264*29492bb7SDavid van Moolenbroek         /*
265*29492bb7SDavid van Moolenbroek          * Detach the object from any data objects (which are still held by
266*29492bb7SDavid van Moolenbroek          * the namespace node)
267*29492bb7SDavid van Moolenbroek          */
268*29492bb7SDavid van Moolenbroek         if (ObjDesc->Common.NextObject &&
269*29492bb7SDavid van Moolenbroek            ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
270*29492bb7SDavid van Moolenbroek         {
271*29492bb7SDavid van Moolenbroek            ObjDesc->Common.NextObject = NULL;
272*29492bb7SDavid van Moolenbroek         }
273433d6423SLionel Sambuc     }
274433d6423SLionel Sambuc 
275433d6423SLionel Sambuc     /* Reset the node type to untyped */
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc     Node->Type = ACPI_TYPE_ANY;
278433d6423SLionel Sambuc 
279433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
280433d6423SLionel Sambuc         Node, AcpiUtGetNodeName (Node), ObjDesc));
281433d6423SLionel Sambuc 
282433d6423SLionel Sambuc     /* Remove one reference on the object (and all subobjects) */
283433d6423SLionel Sambuc 
284433d6423SLionel Sambuc     AcpiUtRemoveReference (ObjDesc);
285433d6423SLionel Sambuc     return_VOID;
286433d6423SLionel Sambuc }
287433d6423SLionel Sambuc 
288433d6423SLionel Sambuc 
289433d6423SLionel Sambuc /*******************************************************************************
290433d6423SLionel Sambuc  *
291433d6423SLionel Sambuc  * FUNCTION:    AcpiNsGetAttachedObject
292433d6423SLionel Sambuc  *
293433d6423SLionel Sambuc  * PARAMETERS:  Node             - Namespace node
294433d6423SLionel Sambuc  *
295433d6423SLionel Sambuc  * RETURN:      Current value of the object field from the Node whose
296433d6423SLionel Sambuc  *              handle is passed
297433d6423SLionel Sambuc  *
298433d6423SLionel Sambuc  * DESCRIPTION: Obtain the object attached to a namespace node.
299433d6423SLionel Sambuc  *
300433d6423SLionel Sambuc  ******************************************************************************/
301433d6423SLionel Sambuc 
302433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiNsGetAttachedObject(ACPI_NAMESPACE_NODE * Node)303433d6423SLionel Sambuc AcpiNsGetAttachedObject (
304433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node)
305433d6423SLionel Sambuc {
306433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);
307433d6423SLionel Sambuc 
308433d6423SLionel Sambuc 
309433d6423SLionel Sambuc     if (!Node)
310433d6423SLionel Sambuc     {
311433d6423SLionel Sambuc         ACPI_WARNING ((AE_INFO, "Null Node ptr"));
312433d6423SLionel Sambuc         return_PTR (NULL);
313433d6423SLionel Sambuc     }
314433d6423SLionel Sambuc 
315433d6423SLionel Sambuc     if (!Node->Object ||
316433d6423SLionel Sambuc             ((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&
317433d6423SLionel Sambuc              (ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED))  ||
318433d6423SLionel Sambuc         ((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))
319433d6423SLionel Sambuc     {
320433d6423SLionel Sambuc         return_PTR (NULL);
321433d6423SLionel Sambuc     }
322433d6423SLionel Sambuc 
323433d6423SLionel Sambuc     return_PTR (Node->Object);
324433d6423SLionel Sambuc }
325433d6423SLionel Sambuc 
326433d6423SLionel Sambuc 
327433d6423SLionel Sambuc /*******************************************************************************
328433d6423SLionel Sambuc  *
329433d6423SLionel Sambuc  * FUNCTION:    AcpiNsGetSecondaryObject
330433d6423SLionel Sambuc  *
331433d6423SLionel Sambuc  * PARAMETERS:  Node             - Namespace node
332433d6423SLionel Sambuc  *
333433d6423SLionel Sambuc  * RETURN:      Current value of the object field from the Node whose
334433d6423SLionel Sambuc  *              handle is passed.
335433d6423SLionel Sambuc  *
336433d6423SLionel Sambuc  * DESCRIPTION: Obtain a secondary object associated with a namespace node.
337433d6423SLionel Sambuc  *
338433d6423SLionel Sambuc  ******************************************************************************/
339433d6423SLionel Sambuc 
340433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiNsGetSecondaryObject(ACPI_OPERAND_OBJECT * ObjDesc)341433d6423SLionel Sambuc AcpiNsGetSecondaryObject (
342433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc)
343433d6423SLionel Sambuc {
344433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);
345433d6423SLionel Sambuc 
346433d6423SLionel Sambuc 
347433d6423SLionel Sambuc     if ((!ObjDesc)                                     ||
348433d6423SLionel Sambuc         (ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA)  ||
349433d6423SLionel Sambuc         (!ObjDesc->Common.NextObject)                  ||
350433d6423SLionel Sambuc         ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
351433d6423SLionel Sambuc     {
352433d6423SLionel Sambuc         return_PTR (NULL);
353433d6423SLionel Sambuc     }
354433d6423SLionel Sambuc 
355433d6423SLionel Sambuc     return_PTR (ObjDesc->Common.NextObject);
356433d6423SLionel Sambuc }
357433d6423SLionel Sambuc 
358433d6423SLionel Sambuc 
359433d6423SLionel Sambuc /*******************************************************************************
360433d6423SLionel Sambuc  *
361433d6423SLionel Sambuc  * FUNCTION:    AcpiNsAttachData
362433d6423SLionel Sambuc  *
363433d6423SLionel Sambuc  * PARAMETERS:  Node            - Namespace node
364433d6423SLionel Sambuc  *              Handler         - Handler to be associated with the data
365433d6423SLionel Sambuc  *              Data            - Data to be attached
366433d6423SLionel Sambuc  *
367433d6423SLionel Sambuc  * RETURN:      Status
368433d6423SLionel Sambuc  *
369433d6423SLionel Sambuc  * DESCRIPTION: Low-level attach data. Create and attach a Data object.
370433d6423SLionel Sambuc  *
371433d6423SLionel Sambuc  ******************************************************************************/
372433d6423SLionel Sambuc 
373433d6423SLionel Sambuc ACPI_STATUS
AcpiNsAttachData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler,void * Data)374433d6423SLionel Sambuc AcpiNsAttachData (
375433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
376433d6423SLionel Sambuc     ACPI_OBJECT_HANDLER     Handler,
377433d6423SLionel Sambuc     void                    *Data)
378433d6423SLionel Sambuc {
379433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *PrevObjDesc;
380433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
381433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *DataDesc;
382433d6423SLionel Sambuc 
383433d6423SLionel Sambuc 
384433d6423SLionel Sambuc     /* We only allow one attachment per handler */
385433d6423SLionel Sambuc 
386433d6423SLionel Sambuc     PrevObjDesc = NULL;
387433d6423SLionel Sambuc     ObjDesc = Node->Object;
388433d6423SLionel Sambuc     while (ObjDesc)
389433d6423SLionel Sambuc     {
390433d6423SLionel Sambuc         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
391433d6423SLionel Sambuc             (ObjDesc->Data.Handler == Handler))
392433d6423SLionel Sambuc         {
393433d6423SLionel Sambuc             return (AE_ALREADY_EXISTS);
394433d6423SLionel Sambuc         }
395433d6423SLionel Sambuc 
396433d6423SLionel Sambuc         PrevObjDesc = ObjDesc;
397433d6423SLionel Sambuc         ObjDesc = ObjDesc->Common.NextObject;
398433d6423SLionel Sambuc     }
399433d6423SLionel Sambuc 
400433d6423SLionel Sambuc     /* Create an internal object for the data */
401433d6423SLionel Sambuc 
402433d6423SLionel Sambuc     DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);
403433d6423SLionel Sambuc     if (!DataDesc)
404433d6423SLionel Sambuc     {
405433d6423SLionel Sambuc         return (AE_NO_MEMORY);
406433d6423SLionel Sambuc     }
407433d6423SLionel Sambuc 
408433d6423SLionel Sambuc     DataDesc->Data.Handler = Handler;
409433d6423SLionel Sambuc     DataDesc->Data.Pointer = Data;
410433d6423SLionel Sambuc 
411433d6423SLionel Sambuc     /* Install the data object */
412433d6423SLionel Sambuc 
413433d6423SLionel Sambuc     if (PrevObjDesc)
414433d6423SLionel Sambuc     {
415433d6423SLionel Sambuc         PrevObjDesc->Common.NextObject = DataDesc;
416433d6423SLionel Sambuc     }
417433d6423SLionel Sambuc     else
418433d6423SLionel Sambuc     {
419433d6423SLionel Sambuc         Node->Object = DataDesc;
420433d6423SLionel Sambuc     }
421433d6423SLionel Sambuc 
422433d6423SLionel Sambuc     return (AE_OK);
423433d6423SLionel Sambuc }
424433d6423SLionel Sambuc 
425433d6423SLionel Sambuc 
426433d6423SLionel Sambuc /*******************************************************************************
427433d6423SLionel Sambuc  *
428433d6423SLionel Sambuc  * FUNCTION:    AcpiNsDetachData
429433d6423SLionel Sambuc  *
430433d6423SLionel Sambuc  * PARAMETERS:  Node            - Namespace node
431433d6423SLionel Sambuc  *              Handler         - Handler associated with the data
432433d6423SLionel Sambuc  *
433433d6423SLionel Sambuc  * RETURN:      Status
434433d6423SLionel Sambuc  *
435433d6423SLionel Sambuc  * DESCRIPTION: Low-level detach data. Delete the data node, but the caller
436433d6423SLionel Sambuc  *              is responsible for the actual data.
437433d6423SLionel Sambuc  *
438433d6423SLionel Sambuc  ******************************************************************************/
439433d6423SLionel Sambuc 
440433d6423SLionel Sambuc ACPI_STATUS
AcpiNsDetachData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler)441433d6423SLionel Sambuc AcpiNsDetachData (
442433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
443433d6423SLionel Sambuc     ACPI_OBJECT_HANDLER     Handler)
444433d6423SLionel Sambuc {
445433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
446433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *PrevObjDesc;
447433d6423SLionel Sambuc 
448433d6423SLionel Sambuc 
449433d6423SLionel Sambuc     PrevObjDesc = NULL;
450433d6423SLionel Sambuc     ObjDesc = Node->Object;
451433d6423SLionel Sambuc     while (ObjDesc)
452433d6423SLionel Sambuc     {
453433d6423SLionel Sambuc         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
454433d6423SLionel Sambuc             (ObjDesc->Data.Handler == Handler))
455433d6423SLionel Sambuc         {
456433d6423SLionel Sambuc             if (PrevObjDesc)
457433d6423SLionel Sambuc             {
458433d6423SLionel Sambuc                 PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;
459433d6423SLionel Sambuc             }
460433d6423SLionel Sambuc             else
461433d6423SLionel Sambuc             {
462433d6423SLionel Sambuc                 Node->Object = ObjDesc->Common.NextObject;
463433d6423SLionel Sambuc             }
464433d6423SLionel Sambuc 
465433d6423SLionel Sambuc             AcpiUtRemoveReference (ObjDesc);
466433d6423SLionel Sambuc             return (AE_OK);
467433d6423SLionel Sambuc         }
468433d6423SLionel Sambuc 
469433d6423SLionel Sambuc         PrevObjDesc = ObjDesc;
470433d6423SLionel Sambuc         ObjDesc = ObjDesc->Common.NextObject;
471433d6423SLionel Sambuc     }
472433d6423SLionel Sambuc 
473433d6423SLionel Sambuc     return (AE_NOT_FOUND);
474433d6423SLionel Sambuc }
475433d6423SLionel Sambuc 
476433d6423SLionel Sambuc 
477433d6423SLionel Sambuc /*******************************************************************************
478433d6423SLionel Sambuc  *
479433d6423SLionel Sambuc  * FUNCTION:    AcpiNsGetAttachedData
480433d6423SLionel Sambuc  *
481433d6423SLionel Sambuc  * PARAMETERS:  Node            - Namespace node
482433d6423SLionel Sambuc  *              Handler         - Handler associated with the data
483433d6423SLionel Sambuc  *              Data            - Where the data is returned
484433d6423SLionel Sambuc  *
485433d6423SLionel Sambuc  * RETURN:      Status
486433d6423SLionel Sambuc  *
487433d6423SLionel Sambuc  * DESCRIPTION: Low level interface to obtain data previously associated with
488433d6423SLionel Sambuc  *              a namespace node.
489433d6423SLionel Sambuc  *
490433d6423SLionel Sambuc  ******************************************************************************/
491433d6423SLionel Sambuc 
492433d6423SLionel Sambuc ACPI_STATUS
AcpiNsGetAttachedData(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_HANDLER Handler,void ** Data)493433d6423SLionel Sambuc AcpiNsGetAttachedData (
494433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
495433d6423SLionel Sambuc     ACPI_OBJECT_HANDLER     Handler,
496433d6423SLionel Sambuc     void                    **Data)
497433d6423SLionel Sambuc {
498433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
499433d6423SLionel Sambuc 
500433d6423SLionel Sambuc 
501433d6423SLionel Sambuc     ObjDesc = Node->Object;
502433d6423SLionel Sambuc     while (ObjDesc)
503433d6423SLionel Sambuc     {
504433d6423SLionel Sambuc         if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
505433d6423SLionel Sambuc             (ObjDesc->Data.Handler == Handler))
506433d6423SLionel Sambuc         {
507433d6423SLionel Sambuc             *Data = ObjDesc->Data.Pointer;
508433d6423SLionel Sambuc             return (AE_OK);
509433d6423SLionel Sambuc         }
510433d6423SLionel Sambuc 
511433d6423SLionel Sambuc         ObjDesc = ObjDesc->Common.NextObject;
512433d6423SLionel Sambuc     }
513433d6423SLionel Sambuc 
514433d6423SLionel Sambuc     return (AE_NOT_FOUND);
515433d6423SLionel Sambuc }
516