1 /*******************************************************************************
3 * Module Name: nsobject - Utilities for objects attached to namespace
7 ******************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_NAMESPACE
31 MODULE_NAME ("nsobject")
34 /*******************************************************************************
36 * FUNCTION: Acpi_ns_attach_object
38 * PARAMETERS: Node - Parent Node
39 * Object - Object to be attached
40 * Type - Type of object, or ACPI_TYPE_ANY if not
43 * DESCRIPTION: Record the given object as the value associated with the
44 * name whose ACPI_HANDLE is passed. If Object is NULL
45 * and Type is ACPI_TYPE_ANY, set the name as having no value.
47 * MUTEX: Assumes namespace is locked
49 ******************************************************************************/
52 acpi_ns_attach_object (
53 ACPI_NAMESPACE_NODE
*node
,
54 ACPI_OPERAND_OBJECT
*object
,
55 OBJECT_TYPE_INTERNAL type
)
57 ACPI_OPERAND_OBJECT
*obj_desc
;
58 ACPI_OPERAND_OBJECT
*previous_obj_desc
;
59 OBJECT_TYPE_INTERNAL obj_type
= ACPI_TYPE_ANY
;
65 * Parameter validation
68 if (!acpi_gbl_root_node
) {
69 /* Name space not initialized */
71 REPORT_ERROR (("Ns_attach_object: Namespace not initialized\n"));
72 return (AE_NO_NAMESPACE
);
78 REPORT_ERROR (("Ns_attach_object: Null Named_obj handle\n"));
79 return (AE_BAD_PARAMETER
);
82 if (!object
&& (ACPI_TYPE_ANY
!= type
)) {
85 REPORT_ERROR (("Ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
86 return (AE_BAD_PARAMETER
);
89 if (!VALID_DESCRIPTOR_TYPE (node
, ACPI_DESC_TYPE_NAMED
)) {
90 /* Not a name handle */
92 REPORT_ERROR (("Ns_attach_object: Invalid handle\n"));
93 return (AE_BAD_PARAMETER
);
96 /* Check if this object is already attached */
98 if (node
->object
== object
) {
103 /* Get the current flags field of the Node */
106 flags
&= ~ANOBJ_AML_ATTACHMENT
;
109 /* If null object, we will just install it */
113 obj_type
= ACPI_TYPE_ANY
;
117 * If the object is an Node with an attached object,
118 * we will use that (attached) object
121 else if (VALID_DESCRIPTOR_TYPE (object
, ACPI_DESC_TYPE_NAMED
) &&
122 ((ACPI_NAMESPACE_NODE
*) object
)->object
) {
124 * Value passed is a name handle and that name has a
125 * non-null value. Use that name's value and type.
128 obj_desc
= ((ACPI_NAMESPACE_NODE
*) object
)->object
;
129 obj_type
= ((ACPI_NAMESPACE_NODE
*) object
)->type
;
132 * Copy appropriate flags
135 if (((ACPI_NAMESPACE_NODE
*) object
)->flags
& ANOBJ_AML_ATTACHMENT
) {
136 flags
|= ANOBJ_AML_ATTACHMENT
;
142 * Otherwise, we will use the parameter object, but we must type
147 obj_desc
= (ACPI_OPERAND_OBJECT
*) object
;
150 /* If a valid type (non-ANY) was given, just use it */
152 if (ACPI_TYPE_ANY
!= type
) {
158 * Type is TYPE_Any, we must try to determinte the
159 * actual type of the object
163 * Check if value points into the AML code
165 else if (acpi_tb_system_table_pointer (object
)) {
167 * Object points into the AML stream.
168 * Set a flag bit in the Node to indicate this
171 flags
|= ANOBJ_AML_ATTACHMENT
;
174 * The next byte (perhaps the next two bytes)
175 * will be the AML opcode
178 MOVE_UNALIGNED16_TO_16 (&opcode
, object
);
180 /* Check for a recognized Opcode */
186 if (opcode
!= AML_REVISION_OP
) {
188 * Op_prefix is unrecognized unless part
195 /* Else fall through to set type as Number */
198 case AML_ZERO_OP
: case AML_ONES_OP
: case AML_ONE_OP
:
199 case AML_BYTE_OP
: case AML_WORD_OP
: case AML_DWORD_OP
:
201 obj_type
= ACPI_TYPE_INTEGER
;
207 obj_type
= ACPI_TYPE_STRING
;
213 obj_type
= ACPI_TYPE_BUFFER
;
219 obj_type
= ACPI_TYPE_MUTEX
;
225 obj_type
= ACPI_TYPE_PACKAGE
;
238 * Cannot figure out the type -- set to Def_any which
239 * will print as an error in the name table dump
243 obj_type
= INTERNAL_TYPE_DEF_ANY
;
249 * Must increment the new value's reference count
250 * (if it is an internal object)
253 acpi_cm_add_reference (obj_desc
);
255 /* Save the existing object (if any) for deletion later */
257 previous_obj_desc
= node
->object
;
259 /* Install the object and set the type, flags */
261 node
->object
= obj_desc
;
262 node
->type
= (u8
) obj_type
;
263 node
->flags
|= flags
;
267 * Delete an existing attached object.
270 if (previous_obj_desc
) {
271 /* One for the attach to the Node */
273 acpi_cm_remove_reference (previous_obj_desc
);
277 acpi_cm_remove_reference (previous_obj_desc
);
284 /*******************************************************************************
286 * FUNCTION: Acpi_ns_detach_object
288 * PARAMETERS: Node - An object whose Value will be deleted
292 * DESCRIPTION: Delete the Value associated with a namespace object. If the
293 * Value is an allocated object, it is freed. Otherwise, the
294 * field is simply cleared.
296 ******************************************************************************/
299 acpi_ns_detach_object (
300 ACPI_NAMESPACE_NODE
*node
)
302 ACPI_OPERAND_OBJECT
*obj_desc
;
305 obj_desc
= node
->object
;
310 /* Clear the entry in all cases */
314 /* Found a valid value */
317 * Not every value is an object allocated via Acpi_cm_callocate,
321 if (!acpi_tb_system_table_pointer (obj_desc
)) {
322 /* Attempt to delete the object (and all subobjects) */
324 acpi_cm_remove_reference (obj_desc
);
331 /*******************************************************************************
333 * FUNCTION: Acpi_ns_get_attached_object
335 * PARAMETERS: Handle - Parent Node to be examined
337 * RETURN: Current value of the object field from the Node whose
340 ******************************************************************************/
343 acpi_ns_get_attached_object (
353 return (((ACPI_NAMESPACE_NODE
*) handle
)->object
);