1 /*******************************************************************************
3 * Module Name: nsobject - Utilities for objects attached to namespace
6 ******************************************************************************/
9 * Copyright (C) 2000 - 2014, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #define __NSOBJECT_C__
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsobject")
56 /*******************************************************************************
58 * FUNCTION: AcpiNsAttachObject
60 * PARAMETERS: Node - Parent Node
61 * Object - Object to be attached
62 * Type - Type of object, or ACPI_TYPE_ANY if not
67 * DESCRIPTION: Record the given object as the value associated with the
68 * name whose ACPI_HANDLE is passed. If Object is NULL
69 * and Type is ACPI_TYPE_ANY, set the name as having no value.
70 * Note: Future may require that the Node->Flags field be passed
73 * MUTEX: Assumes namespace is locked
75 ******************************************************************************/
79 ACPI_NAMESPACE_NODE *Node,
80 ACPI_OPERAND_OBJECT *Object,
81 ACPI_OBJECT_TYPE Type)
83 ACPI_OPERAND_OBJECT *ObjDesc;
84 ACPI_OPERAND_OBJECT *LastObjDesc;
85 ACPI_OBJECT_TYPE ObjectType = ACPI_TYPE_ANY;
88 ACPI_FUNCTION_TRACE (NsAttachObject);
92 * Parameter validation
98 ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));
99 return_ACPI_STATUS (AE_BAD_PARAMETER);
102 if (!Object && (ACPI_TYPE_ANY != Type))
106 ACPI_ERROR ((AE_INFO,
107 "Null object, but type not ACPI_TYPE_ANY"));
108 return_ACPI_STATUS (AE_BAD_PARAMETER);
111 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
113 /* Not a name handle */
115 ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",
116 Node, AcpiUtGetDescriptorName (Node)));
117 return_ACPI_STATUS (AE_BAD_PARAMETER);
120 /* Check if this object is already attached */
122 if (Node->Object == Object)
124 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
125 "Obj %p already installed in NameObj %p\n",
128 return_ACPI_STATUS (AE_OK);
131 /* If null object, we will just install it */
136 ObjectType = ACPI_TYPE_ANY;
140 * If the source object is a namespace Node with an attached object,
141 * we will use that (attached) object
143 else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&
144 ((ACPI_NAMESPACE_NODE *) Object)->Object)
147 * Value passed is a name handle and that name has a
148 * non-null value. Use that name's value and type.
150 ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;
151 ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
155 * Otherwise, we will use the parameter object, but we must type
160 ObjDesc = (ACPI_OPERAND_OBJECT *) Object;
162 /* Use the given type */
167 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
168 ObjDesc, Node, AcpiUtGetNodeName (Node)));
170 /* Detach an existing attached object if present */
174 AcpiNsDetachObject (Node);
180 * Must increment the new value's reference count
181 * (if it is an internal object)
183 AcpiUtAddReference (ObjDesc);
186 * Handle objects with multiple descriptors - walk
187 * to the end of the descriptor list
189 LastObjDesc = ObjDesc;
190 while (LastObjDesc->Common.NextObject)
192 LastObjDesc = LastObjDesc->Common.NextObject;
195 /* Install the object at the front of the object list */
197 LastObjDesc->Common.NextObject = Node->Object;
200 Node->Type = (UINT8) ObjectType;
201 Node->Object = ObjDesc;
203 return_ACPI_STATUS (AE_OK);
207 /*******************************************************************************
209 * FUNCTION: AcpiNsDetachObject
211 * PARAMETERS: Node - A Namespace node whose object will be detached
215 * DESCRIPTION: Detach/delete an object associated with a namespace node.
216 * if the object is an allocated object, it is freed.
217 * Otherwise, the field is simply cleared.
219 ******************************************************************************/
223 ACPI_NAMESPACE_NODE *Node)
225 ACPI_OPERAND_OBJECT *ObjDesc;
228 ACPI_FUNCTION_TRACE (NsDetachObject);
231 ObjDesc = Node->Object;
234 (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
239 if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)
241 /* Free the dynamic aml buffer */
243 if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)
245 ACPI_FREE (ObjDesc->Method.AmlStart);
249 /* Clear the Node entry in all cases */
252 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
254 /* Unlink object from front of possible object list */
256 Node->Object = ObjDesc->Common.NextObject;
258 /* Handle possible 2-descriptor object */
261 (Node->Object->Common.Type != ACPI_TYPE_LOCAL_DATA))
263 Node->Object = Node->Object->Common.NextObject;
267 * Detach the object from any data objects (which are still held by
268 * the namespace node)
270 if (ObjDesc->Common.NextObject &&
271 ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
273 ObjDesc->Common.NextObject = NULL;
277 /* Reset the node type to untyped */
279 Node->Type = ACPI_TYPE_ANY;
281 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
282 Node, AcpiUtGetNodeName (Node), ObjDesc));
284 /* Remove one reference on the object (and all subobjects) */
286 AcpiUtRemoveReference (ObjDesc);
291 /*******************************************************************************
293 * FUNCTION: AcpiNsGetAttachedObject
295 * PARAMETERS: Node - Namespace node
297 * RETURN: Current value of the object field from the Node whose
300 * DESCRIPTION: Obtain the object attached to a namespace node.
302 ******************************************************************************/
304 ACPI_OPERAND_OBJECT *
305 AcpiNsGetAttachedObject (
306 ACPI_NAMESPACE_NODE *Node)
308 ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);
313 ACPI_WARNING ((AE_INFO, "Null Node ptr"));
318 ((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&
319 (ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED)) ||
320 ((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))
325 return_PTR (Node->Object);
329 /*******************************************************************************
331 * FUNCTION: AcpiNsGetSecondaryObject
333 * PARAMETERS: Node - Namespace node
335 * RETURN: Current value of the object field from the Node whose
338 * DESCRIPTION: Obtain a secondary object associated with a namespace node.
340 ******************************************************************************/
342 ACPI_OPERAND_OBJECT *
343 AcpiNsGetSecondaryObject (
344 ACPI_OPERAND_OBJECT *ObjDesc)
346 ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);
350 (ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA) ||
351 (!ObjDesc->Common.NextObject) ||
352 ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
357 return_PTR (ObjDesc->Common.NextObject);
361 /*******************************************************************************
363 * FUNCTION: AcpiNsAttachData
365 * PARAMETERS: Node - Namespace node
366 * Handler - Handler to be associated with the data
367 * Data - Data to be attached
371 * DESCRIPTION: Low-level attach data. Create and attach a Data object.
373 ******************************************************************************/
377 ACPI_NAMESPACE_NODE *Node,
378 ACPI_OBJECT_HANDLER Handler,
381 ACPI_OPERAND_OBJECT *PrevObjDesc;
382 ACPI_OPERAND_OBJECT *ObjDesc;
383 ACPI_OPERAND_OBJECT *DataDesc;
386 /* We only allow one attachment per handler */
389 ObjDesc = Node->Object;
392 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
393 (ObjDesc->Data.Handler == Handler))
395 return (AE_ALREADY_EXISTS);
398 PrevObjDesc = ObjDesc;
399 ObjDesc = ObjDesc->Common.NextObject;
402 /* Create an internal object for the data */
404 DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);
407 return (AE_NO_MEMORY);
410 DataDesc->Data.Handler = Handler;
411 DataDesc->Data.Pointer = Data;
413 /* Install the data object */
417 PrevObjDesc->Common.NextObject = DataDesc;
421 Node->Object = DataDesc;
428 /*******************************************************************************
430 * FUNCTION: AcpiNsDetachData
432 * PARAMETERS: Node - Namespace node
433 * Handler - Handler associated with the data
437 * DESCRIPTION: Low-level detach data. Delete the data node, but the caller
438 * is responsible for the actual data.
440 ******************************************************************************/
444 ACPI_NAMESPACE_NODE *Node,
445 ACPI_OBJECT_HANDLER Handler)
447 ACPI_OPERAND_OBJECT *ObjDesc;
448 ACPI_OPERAND_OBJECT *PrevObjDesc;
452 ObjDesc = Node->Object;
455 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
456 (ObjDesc->Data.Handler == Handler))
460 PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;
464 Node->Object = ObjDesc->Common.NextObject;
467 AcpiUtRemoveReference (ObjDesc);
471 PrevObjDesc = ObjDesc;
472 ObjDesc = ObjDesc->Common.NextObject;
475 return (AE_NOT_FOUND);
479 /*******************************************************************************
481 * FUNCTION: AcpiNsGetAttachedData
483 * PARAMETERS: Node - Namespace node
484 * Handler - Handler associated with the data
485 * Data - Where the data is returned
489 * DESCRIPTION: Low level interface to obtain data previously associated with
492 ******************************************************************************/
495 AcpiNsGetAttachedData (
496 ACPI_NAMESPACE_NODE *Node,
497 ACPI_OBJECT_HANDLER Handler,
500 ACPI_OPERAND_OBJECT *ObjDesc;
503 ObjDesc = Node->Object;
506 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
507 (ObjDesc->Data.Handler == Handler))
509 *Data = ObjDesc->Data.Pointer;
513 ObjDesc = ObjDesc->Common.NextObject;
516 return (AE_NOT_FOUND);