Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / namespace / nsobject.c
blobafab694cc6726c23704d7e8f68ad23c3b8598275
1 /*******************************************************************************
3 * Module Name: nsobject - Utilities for objects attached to namespace
4 * table entries
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2013, 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
14 * are met:
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.
31 * NO WARRANTY
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.
46 #define __NSOBJECT_C__
48 #include "acpi.h"
49 #include "accommon.h"
50 #include "acnamesp.h"
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nsobject")
57 /*******************************************************************************
59 * FUNCTION: AcpiNsAttachObject
61 * PARAMETERS: Node - Parent Node
62 * Object - Object to be attached
63 * Type - Type of object, or ACPI_TYPE_ANY if not
64 * known
66 * RETURN: Status
68 * DESCRIPTION: Record the given object as the value associated with the
69 * name whose ACPI_HANDLE is passed. If Object is NULL
70 * and Type is ACPI_TYPE_ANY, set the name as having no value.
71 * Note: Future may require that the Node->Flags field be passed
72 * as a parameter.
74 * MUTEX: Assumes namespace is locked
76 ******************************************************************************/
78 ACPI_STATUS
79 AcpiNsAttachObject (
80 ACPI_NAMESPACE_NODE *Node,
81 ACPI_OPERAND_OBJECT *Object,
82 ACPI_OBJECT_TYPE Type)
84 ACPI_OPERAND_OBJECT *ObjDesc;
85 ACPI_OPERAND_OBJECT *LastObjDesc;
86 ACPI_OBJECT_TYPE ObjectType = ACPI_TYPE_ANY;
89 ACPI_FUNCTION_TRACE (NsAttachObject);
93 * Parameter validation
95 if (!Node)
97 /* Invalid handle */
99 ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));
100 return_ACPI_STATUS (AE_BAD_PARAMETER);
103 if (!Object && (ACPI_TYPE_ANY != Type))
105 /* Null object */
107 ACPI_ERROR ((AE_INFO,
108 "Null object, but type not ACPI_TYPE_ANY"));
109 return_ACPI_STATUS (AE_BAD_PARAMETER);
112 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
114 /* Not a name handle */
116 ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",
117 Node, AcpiUtGetDescriptorName (Node)));
118 return_ACPI_STATUS (AE_BAD_PARAMETER);
121 /* Check if this object is already attached */
123 if (Node->Object == Object)
125 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
126 "Obj %p already installed in NameObj %p\n",
127 Object, Node));
129 return_ACPI_STATUS (AE_OK);
132 /* If null object, we will just install it */
134 if (!Object)
136 ObjDesc = NULL;
137 ObjectType = ACPI_TYPE_ANY;
141 * If the source object is a namespace Node with an attached object,
142 * we will use that (attached) object
144 else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&
145 ((ACPI_NAMESPACE_NODE *) Object)->Object)
148 * Value passed is a name handle and that name has a
149 * non-null value. Use that name's value and type.
151 ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;
152 ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
156 * Otherwise, we will use the parameter object, but we must type
157 * it first
159 else
161 ObjDesc = (ACPI_OPERAND_OBJECT *) Object;
163 /* Use the given type */
165 ObjectType = Type;
168 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
169 ObjDesc, Node, AcpiUtGetNodeName (Node)));
171 /* Detach an existing attached object if present */
173 if (Node->Object)
175 AcpiNsDetachObject (Node);
178 if (ObjDesc)
181 * Must increment the new value's reference count
182 * (if it is an internal object)
184 AcpiUtAddReference (ObjDesc);
187 * Handle objects with multiple descriptors - walk
188 * to the end of the descriptor list
190 LastObjDesc = ObjDesc;
191 while (LastObjDesc->Common.NextObject)
193 LastObjDesc = LastObjDesc->Common.NextObject;
196 /* Install the object at the front of the object list */
198 LastObjDesc->Common.NextObject = Node->Object;
201 Node->Type = (UINT8) ObjectType;
202 Node->Object = ObjDesc;
204 return_ACPI_STATUS (AE_OK);
208 /*******************************************************************************
210 * FUNCTION: AcpiNsDetachObject
212 * PARAMETERS: Node - A Namespace node whose object will be detached
214 * RETURN: None.
216 * DESCRIPTION: Detach/delete an object associated with a namespace node.
217 * if the object is an allocated object, it is freed.
218 * Otherwise, the field is simply cleared.
220 ******************************************************************************/
222 void
223 AcpiNsDetachObject (
224 ACPI_NAMESPACE_NODE *Node)
226 ACPI_OPERAND_OBJECT *ObjDesc;
229 ACPI_FUNCTION_TRACE (NsDetachObject);
232 ObjDesc = Node->Object;
234 if (!ObjDesc ||
235 (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
237 return_VOID;
240 if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)
242 /* Free the dynamic aml buffer */
244 if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)
246 ACPI_FREE (ObjDesc->Method.AmlStart);
250 /* Clear the entry in all cases */
252 Node->Object = NULL;
253 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
255 Node->Object = ObjDesc->Common.NextObject;
256 if (Node->Object &&
257 ((Node->Object)->Common.Type != ACPI_TYPE_LOCAL_DATA))
259 Node->Object = Node->Object->Common.NextObject;
263 /* Reset the node type to untyped */
265 Node->Type = ACPI_TYPE_ANY;
267 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
268 Node, AcpiUtGetNodeName (Node), ObjDesc));
270 /* Remove one reference on the object (and all subobjects) */
272 AcpiUtRemoveReference (ObjDesc);
273 return_VOID;
277 /*******************************************************************************
279 * FUNCTION: AcpiNsGetAttachedObject
281 * PARAMETERS: Node - Namespace node
283 * RETURN: Current value of the object field from the Node whose
284 * handle is passed
286 * DESCRIPTION: Obtain the object attached to a namespace node.
288 ******************************************************************************/
290 ACPI_OPERAND_OBJECT *
291 AcpiNsGetAttachedObject (
292 ACPI_NAMESPACE_NODE *Node)
294 ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);
297 if (!Node)
299 ACPI_WARNING ((AE_INFO, "Null Node ptr"));
300 return_PTR (NULL);
303 if (!Node->Object ||
304 ((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&
305 (ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED)) ||
306 ((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))
308 return_PTR (NULL);
311 return_PTR (Node->Object);
315 /*******************************************************************************
317 * FUNCTION: AcpiNsGetSecondaryObject
319 * PARAMETERS: Node - Namespace node
321 * RETURN: Current value of the object field from the Node whose
322 * handle is passed.
324 * DESCRIPTION: Obtain a secondary object associated with a namespace node.
326 ******************************************************************************/
328 ACPI_OPERAND_OBJECT *
329 AcpiNsGetSecondaryObject (
330 ACPI_OPERAND_OBJECT *ObjDesc)
332 ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);
335 if ((!ObjDesc) ||
336 (ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA) ||
337 (!ObjDesc->Common.NextObject) ||
338 ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
340 return_PTR (NULL);
343 return_PTR (ObjDesc->Common.NextObject);
347 /*******************************************************************************
349 * FUNCTION: AcpiNsAttachData
351 * PARAMETERS: Node - Namespace node
352 * Handler - Handler to be associated with the data
353 * Data - Data to be attached
355 * RETURN: Status
357 * DESCRIPTION: Low-level attach data. Create and attach a Data object.
359 ******************************************************************************/
361 ACPI_STATUS
362 AcpiNsAttachData (
363 ACPI_NAMESPACE_NODE *Node,
364 ACPI_OBJECT_HANDLER Handler,
365 void *Data)
367 ACPI_OPERAND_OBJECT *PrevObjDesc;
368 ACPI_OPERAND_OBJECT *ObjDesc;
369 ACPI_OPERAND_OBJECT *DataDesc;
372 /* We only allow one attachment per handler */
374 PrevObjDesc = NULL;
375 ObjDesc = Node->Object;
376 while (ObjDesc)
378 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
379 (ObjDesc->Data.Handler == Handler))
381 return (AE_ALREADY_EXISTS);
384 PrevObjDesc = ObjDesc;
385 ObjDesc = ObjDesc->Common.NextObject;
388 /* Create an internal object for the data */
390 DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);
391 if (!DataDesc)
393 return (AE_NO_MEMORY);
396 DataDesc->Data.Handler = Handler;
397 DataDesc->Data.Pointer = Data;
399 /* Install the data object */
401 if (PrevObjDesc)
403 PrevObjDesc->Common.NextObject = DataDesc;
405 else
407 Node->Object = DataDesc;
410 return (AE_OK);
414 /*******************************************************************************
416 * FUNCTION: AcpiNsDetachData
418 * PARAMETERS: Node - Namespace node
419 * Handler - Handler associated with the data
421 * RETURN: Status
423 * DESCRIPTION: Low-level detach data. Delete the data node, but the caller
424 * is responsible for the actual data.
426 ******************************************************************************/
428 ACPI_STATUS
429 AcpiNsDetachData (
430 ACPI_NAMESPACE_NODE *Node,
431 ACPI_OBJECT_HANDLER Handler)
433 ACPI_OPERAND_OBJECT *ObjDesc;
434 ACPI_OPERAND_OBJECT *PrevObjDesc;
437 PrevObjDesc = NULL;
438 ObjDesc = Node->Object;
439 while (ObjDesc)
441 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
442 (ObjDesc->Data.Handler == Handler))
444 if (PrevObjDesc)
446 PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;
448 else
450 Node->Object = ObjDesc->Common.NextObject;
453 AcpiUtRemoveReference (ObjDesc);
454 return (AE_OK);
457 PrevObjDesc = ObjDesc;
458 ObjDesc = ObjDesc->Common.NextObject;
461 return (AE_NOT_FOUND);
465 /*******************************************************************************
467 * FUNCTION: AcpiNsGetAttachedData
469 * PARAMETERS: Node - Namespace node
470 * Handler - Handler associated with the data
471 * Data - Where the data is returned
473 * RETURN: Status
475 * DESCRIPTION: Low level interface to obtain data previously associated with
476 * a namespace node.
478 ******************************************************************************/
480 ACPI_STATUS
481 AcpiNsGetAttachedData (
482 ACPI_NAMESPACE_NODE *Node,
483 ACPI_OBJECT_HANDLER Handler,
484 void **Data)
486 ACPI_OPERAND_OBJECT *ObjDesc;
489 ObjDesc = Node->Object;
490 while (ObjDesc)
492 if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
493 (ObjDesc->Data.Handler == Handler))
495 *Data = ObjDesc->Data.Pointer;
496 return (AE_OK);
499 ObjDesc = ObjDesc->Common.NextObject;
502 return (AE_NOT_FOUND);