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
35 #define _COMPONENT ACPI_NAMESPACE
36 MODULE_NAME ("nsobject")
39 /*******************************************************************************
41 * FUNCTION: Acpi_ns_attach_object
43 * PARAMETERS: Node - Parent Node
44 * Object - Object to be attached
45 * Type - Type of object, or ACPI_TYPE_ANY if not
48 * DESCRIPTION: Record the given object as the value associated with the
49 * name whose ACPI_HANDLE is passed. If Object is NULL
50 * and Type is ACPI_TYPE_ANY, set the name as having no value.
52 * MUTEX: Assumes namespace is locked
54 ******************************************************************************/
57 acpi_ns_attach_object (
58 ACPI_NAMESPACE_NODE
*node
,
59 ACPI_OPERAND_OBJECT
*object
,
60 OBJECT_TYPE_INTERNAL type
)
62 ACPI_OPERAND_OBJECT
*obj_desc
;
63 ACPI_OPERAND_OBJECT
*previous_obj_desc
;
64 OBJECT_TYPE_INTERNAL obj_type
= ACPI_TYPE_ANY
;
70 * Parameter validation
73 if (!acpi_gbl_root_node
) {
74 /* Name space not initialized */
76 REPORT_ERROR (("Ns_attach_object: Namespace not initialized\n"));
77 return (AE_NO_NAMESPACE
);
83 REPORT_ERROR (("Ns_attach_object: Null Named_obj handle\n"));
84 return (AE_BAD_PARAMETER
);
87 if (!object
&& (ACPI_TYPE_ANY
!= type
)) {
90 REPORT_ERROR (("Ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
91 return (AE_BAD_PARAMETER
);
94 if (!VALID_DESCRIPTOR_TYPE (node
, ACPI_DESC_TYPE_NAMED
)) {
95 /* Not a name handle */
97 REPORT_ERROR (("Ns_attach_object: Invalid handle\n"));
98 return (AE_BAD_PARAMETER
);
101 /* Check if this object is already attached */
103 if (node
->object
== object
) {
108 /* Get the current flags field of the Node */
111 flags
&= ~ANOBJ_AML_ATTACHMENT
;
114 /* If null object, we will just install it */
118 obj_type
= ACPI_TYPE_ANY
;
122 * If the object is an Node with an attached object,
123 * we will use that (attached) object
126 else if (VALID_DESCRIPTOR_TYPE (object
, ACPI_DESC_TYPE_NAMED
) &&
127 ((ACPI_NAMESPACE_NODE
*) object
)->object
) {
129 * Value passed is a name handle and that name has a
130 * non-null value. Use that name's value and type.
133 obj_desc
= ((ACPI_NAMESPACE_NODE
*) object
)->object
;
134 obj_type
= ((ACPI_NAMESPACE_NODE
*) object
)->type
;
137 * Copy appropriate flags
140 if (((ACPI_NAMESPACE_NODE
*) object
)->flags
& ANOBJ_AML_ATTACHMENT
) {
141 flags
|= ANOBJ_AML_ATTACHMENT
;
147 * Otherwise, we will use the parameter object, but we must type
152 obj_desc
= (ACPI_OPERAND_OBJECT
*) object
;
155 /* If a valid type (non-ANY) was given, just use it */
157 if (ACPI_TYPE_ANY
!= type
) {
163 * Type is TYPE_Any, we must try to determinte the
164 * actual type of the object
168 * Check if value points into the AML code
170 else if (acpi_tb_system_table_pointer (object
)) {
172 * Object points into the AML stream.
173 * Set a flag bit in the Node to indicate this
176 flags
|= ANOBJ_AML_ATTACHMENT
;
179 * The next byte (perhaps the next two bytes)
180 * will be the AML opcode
183 MOVE_UNALIGNED16_TO_16 (&opcode
, object
);
185 /* Check for a recognized Opcode */
187 switch ((u8
) opcode
) {
191 if (opcode
!= AML_REVISION_OP
) {
193 * Op_prefix is unrecognized unless part
200 /* Else fall through to set type as Number */
203 case AML_ZERO_OP
: case AML_ONES_OP
: case AML_ONE_OP
:
204 case AML_BYTE_OP
: case AML_WORD_OP
: case AML_DWORD_OP
:
206 obj_type
= ACPI_TYPE_INTEGER
;
212 obj_type
= ACPI_TYPE_STRING
;
218 obj_type
= ACPI_TYPE_BUFFER
;
224 obj_type
= ACPI_TYPE_MUTEX
;
230 obj_type
= ACPI_TYPE_PACKAGE
;
243 * Cannot figure out the type -- set to Def_any which
244 * will print as an error in the name table dump
248 obj_type
= INTERNAL_TYPE_DEF_ANY
;
254 * Must increment the new value's reference count
255 * (if it is an internal object)
258 acpi_cm_add_reference (obj_desc
);
260 /* Save the existing object (if any) for deletion later */
262 previous_obj_desc
= node
->object
;
264 /* Install the object and set the type, flags */
266 node
->object
= obj_desc
;
267 node
->type
= (u8
) obj_type
;
268 node
->flags
|= flags
;
272 * Delete an existing attached object.
275 if (previous_obj_desc
) {
276 /* One for the attach to the Node */
278 acpi_cm_remove_reference (previous_obj_desc
);
282 acpi_cm_remove_reference (previous_obj_desc
);
289 /*******************************************************************************
291 * FUNCTION: Acpi_ns_detach_object
293 * PARAMETERS: Node - An object whose Value will be deleted
297 * DESCRIPTION: Delete the Value associated with a namespace object. If the
298 * Value is an allocated object, it is freed. Otherwise, the
299 * field is simply cleared.
301 ******************************************************************************/
304 acpi_ns_detach_object (
305 ACPI_NAMESPACE_NODE
*node
)
307 ACPI_OPERAND_OBJECT
*obj_desc
;
310 obj_desc
= node
->object
;
315 /* Clear the entry in all cases */
319 /* Found a valid value */
322 * Not every value is an object allocated via Acpi_cm_callocate,
326 if (!acpi_tb_system_table_pointer (obj_desc
)) {
327 /* Attempt to delete the object (and all subobjects) */
329 acpi_cm_remove_reference (obj_desc
);
336 /*******************************************************************************
338 * FUNCTION: Acpi_ns_get_attached_object
340 * PARAMETERS: Handle - Parent Node to be examined
342 * RETURN: Current value of the object field from the Node whose
345 ******************************************************************************/
348 acpi_ns_get_attached_object (
358 return (((ACPI_NAMESPACE_NODE
*) handle
)->object
);