| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 | * | 
|  | 3 | * Module Name: nsobject - Utilities for objects attached to namespace | 
|  | 4 | *                         table entries | 
|  | 5 | * | 
|  | 6 | ******************************************************************************/ | 
|  | 7 |  | 
|  | 8 | /* | 
|  | 9 | * Copyright (C) 2000 - 2005, R. Byron Moore | 
|  | 10 | * All rights reserved. | 
|  | 11 | * | 
|  | 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. | 
|  | 26 | * | 
|  | 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. | 
|  | 30 | * | 
|  | 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. | 
|  | 43 | */ | 
|  | 44 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> | 
|  | 46 | #include <acpi/acnamesp.h> | 
|  | 47 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT          ACPI_NAMESPACE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("nsobject") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
|  | 51 | /******************************************************************************* | 
|  | 52 | * | 
|  | 53 | * FUNCTION:    acpi_ns_attach_object | 
|  | 54 | * | 
|  | 55 | * PARAMETERS:  Node                - Parent Node | 
|  | 56 | *              Object              - Object to be attached | 
|  | 57 | *              Type                - Type of object, or ACPI_TYPE_ANY if not | 
|  | 58 | *                                    known | 
|  | 59 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 60 | * RETURN:      Status | 
|  | 61 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * DESCRIPTION: Record the given object as the value associated with the | 
|  | 63 | *              name whose acpi_handle is passed.  If Object is NULL | 
|  | 64 | *              and Type is ACPI_TYPE_ANY, set the name as having no value. | 
|  | 65 | *              Note: Future may require that the Node->Flags field be passed | 
|  | 66 | *              as a parameter. | 
|  | 67 | * | 
|  | 68 | * MUTEX:       Assumes namespace is locked | 
|  | 69 | * | 
|  | 70 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | acpi_ns_attach_object(struct acpi_namespace_node *node, | 
|  | 73 | union acpi_operand_object *object, acpi_object_type type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | union acpi_operand_object *obj_desc; | 
|  | 76 | union acpi_operand_object *last_obj_desc; | 
|  | 77 | acpi_object_type object_type = ACPI_TYPE_ANY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | ACPI_FUNCTION_TRACE("ns_attach_object"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | /* | 
|  | 82 | * Parameter validation | 
|  | 83 | */ | 
|  | 84 | if (!node) { | 
|  | 85 | /* Invalid handle */ | 
|  | 86 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | ACPI_REPORT_ERROR(("ns_attach_object: Null named_obj handle\n")); | 
|  | 88 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
|  | 91 | if (!object && (ACPI_TYPE_ANY != type)) { | 
|  | 92 | /* Null object */ | 
|  | 93 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | ACPI_REPORT_ERROR(("ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n")); | 
|  | 95 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* Not a name handle */ | 
|  | 100 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | ACPI_REPORT_ERROR(("ns_attach_object: Invalid handle %p [%s]\n", | 
|  | 102 | node, acpi_ut_get_descriptor_name(node))); | 
|  | 103 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
|  | 106 | /* Check if this object is already attached */ | 
|  | 107 |  | 
|  | 108 | if (node->object == object) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
|  | 110 | "Obj %p already installed in name_obj %p\n", | 
|  | 111 | object, node)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
|  | 116 | /* If null object, we will just install it */ | 
|  | 117 |  | 
|  | 118 | if (!object) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | obj_desc = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | object_type = ACPI_TYPE_ANY; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | /* | 
|  | 124 | * If the source object is a namespace Node with an attached object, | 
|  | 125 | * we will use that (attached) object | 
|  | 126 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) && | 
|  | 128 | ((struct acpi_namespace_node *)object)->object) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* | 
|  | 130 | * Value passed is a name handle and that name has a | 
|  | 131 | * non-null value.  Use that name's value and type. | 
|  | 132 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | obj_desc = ((struct acpi_namespace_node *)object)->object; | 
|  | 134 | object_type = ((struct acpi_namespace_node *)object)->type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
|  | 137 | /* | 
|  | 138 | * Otherwise, we will use the parameter object, but we must type | 
|  | 139 | * it first | 
|  | 140 | */ | 
|  | 141 | else { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | obj_desc = (union acpi_operand_object *)object; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  | 
|  | 144 | /* Use the given type */ | 
|  | 145 |  | 
|  | 146 | object_type = type; | 
|  | 147 | } | 
|  | 148 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n", | 
|  | 150 | obj_desc, node, acpi_ut_get_node_name(node))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 |  | 
|  | 152 | /* Detach an existing attached object if present */ | 
|  | 153 |  | 
|  | 154 | if (node->object) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | acpi_ns_detach_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | if (obj_desc) { | 
|  | 159 | /* | 
|  | 160 | * Must increment the new value's reference count | 
|  | 161 | * (if it is an internal object) | 
|  | 162 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | acpi_ut_add_reference(obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
|  | 165 | /* | 
|  | 166 | * Handle objects with multiple descriptors - walk | 
|  | 167 | * to the end of the descriptor list | 
|  | 168 | */ | 
|  | 169 | last_obj_desc = obj_desc; | 
|  | 170 | while (last_obj_desc->common.next_object) { | 
|  | 171 | last_obj_desc = last_obj_desc->common.next_object; | 
|  | 172 | } | 
|  | 173 |  | 
|  | 174 | /* Install the object at the front of the object list */ | 
|  | 175 |  | 
|  | 176 | last_obj_desc->common.next_object = node->object; | 
|  | 177 | } | 
|  | 178 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | node->type = (u8) object_type; | 
|  | 180 | node->object = obj_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } | 
|  | 184 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /******************************************************************************* | 
|  | 186 | * | 
|  | 187 | * FUNCTION:    acpi_ns_detach_object | 
|  | 188 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 189 | * PARAMETERS:  Node           - A Namespace node whose object will be detached | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | * | 
|  | 191 | * RETURN:      None. | 
|  | 192 | * | 
|  | 193 | * DESCRIPTION: Detach/delete an object associated with a namespace node. | 
|  | 194 | *              if the object is an allocated object, it is freed. | 
|  | 195 | *              Otherwise, the field is simply cleared. | 
|  | 196 | * | 
|  | 197 | ******************************************************************************/ | 
|  | 198 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | void acpi_ns_detach_object(struct acpi_namespace_node *node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | union acpi_operand_object *obj_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | ACPI_FUNCTION_TRACE("ns_detach_object"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 |  | 
|  | 205 | obj_desc = node->object; | 
|  | 206 |  | 
|  | 207 | if (!obj_desc || | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | return_VOID; | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | /* Clear the entry in all cases */ | 
|  | 213 |  | 
|  | 214 | node->object = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | node->object = obj_desc->common.next_object; | 
|  | 217 | if (node->object && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | (ACPI_GET_OBJECT_TYPE(node->object) != | 
|  | 219 | ACPI_TYPE_LOCAL_DATA)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | node->object = node->object->common.next_object; | 
|  | 221 | } | 
|  | 222 | } | 
|  | 223 |  | 
|  | 224 | /* Reset the node type to untyped */ | 
|  | 225 |  | 
|  | 226 | node->type = ACPI_TYPE_ANY; | 
|  | 227 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n", | 
|  | 229 | node, acpi_ut_get_node_name(node), obj_desc)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 |  | 
|  | 231 | /* Remove one reference on the object (and all subobjects) */ | 
|  | 232 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | acpi_ut_remove_reference(obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return_VOID; | 
|  | 235 | } | 
|  | 236 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /******************************************************************************* | 
|  | 238 | * | 
|  | 239 | * FUNCTION:    acpi_ns_get_attached_object | 
|  | 240 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 241 | * PARAMETERS:  Node             - Namespace node | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | * | 
|  | 243 | * RETURN:      Current value of the object field from the Node whose | 
|  | 244 | *              handle is passed | 
|  | 245 | * | 
|  | 246 | * DESCRIPTION: Obtain the object attached to a namespace node. | 
|  | 247 | * | 
|  | 248 | ******************************************************************************/ | 
|  | 249 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | union acpi_operand_object *acpi_ns_get_attached_object(struct | 
|  | 251 | acpi_namespace_node | 
|  | 252 | *node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | ACPI_FUNCTION_TRACE_PTR("ns_get_attached_object", node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
|  | 256 | if (!node) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Null Node ptr\n")); | 
|  | 258 | return_PTR(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } | 
|  | 260 |  | 
|  | 261 | if (!node->object || | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND) | 
|  | 263 | && (ACPI_GET_DESCRIPTOR_TYPE(node->object) != | 
|  | 264 | ACPI_DESC_TYPE_NAMED)) | 
|  | 265 | || (ACPI_GET_OBJECT_TYPE(node->object) == ACPI_TYPE_LOCAL_DATA)) { | 
|  | 266 | return_PTR(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } | 
|  | 268 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | return_PTR(node->object); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } | 
|  | 271 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /******************************************************************************* | 
|  | 273 | * | 
|  | 274 | * FUNCTION:    acpi_ns_get_secondary_object | 
|  | 275 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 276 | * PARAMETERS:  Node             - Namespace node | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | * | 
|  | 278 | * RETURN:      Current value of the object field from the Node whose | 
|  | 279 | *              handle is passed. | 
|  | 280 | * | 
|  | 281 | * DESCRIPTION: Obtain a secondary object associated with a namespace node. | 
|  | 282 | * | 
|  | 283 | ******************************************************************************/ | 
|  | 284 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | union acpi_operand_object *acpi_ns_get_secondary_object(union | 
|  | 286 | acpi_operand_object | 
|  | 287 | *obj_desc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | ACPI_FUNCTION_TRACE_PTR("ns_get_secondary_object", obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | if ((!obj_desc) || | 
|  | 292 | (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) || | 
|  | 293 | (!obj_desc->common.next_object) || | 
|  | 294 | (ACPI_GET_OBJECT_TYPE(obj_desc->common.next_object) == | 
|  | 295 | ACPI_TYPE_LOCAL_DATA)) { | 
|  | 296 | return_PTR(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } | 
|  | 298 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | return_PTR(obj_desc->common.next_object); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } | 
|  | 301 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | /******************************************************************************* | 
|  | 303 | * | 
|  | 304 | * FUNCTION:    acpi_ns_attach_data | 
|  | 305 | * | 
|  | 306 | * PARAMETERS:  Node            - Namespace node | 
|  | 307 | *              Handler         - Handler to be associated with the data | 
|  | 308 | *              Data            - Data to be attached | 
|  | 309 | * | 
|  | 310 | * RETURN:      Status | 
|  | 311 | * | 
|  | 312 | * DESCRIPTION: Low-level attach data.  Create and attach a Data object. | 
|  | 313 | * | 
|  | 314 | ******************************************************************************/ | 
|  | 315 |  | 
|  | 316 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | acpi_ns_attach_data(struct acpi_namespace_node *node, | 
|  | 318 | acpi_object_handler handler, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | union acpi_operand_object *prev_obj_desc; | 
|  | 321 | union acpi_operand_object *obj_desc; | 
|  | 322 | union acpi_operand_object *data_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | /* We only allow one attachment per handler */ | 
|  | 325 |  | 
|  | 326 | prev_obj_desc = NULL; | 
|  | 327 | obj_desc = node->object; | 
|  | 328 | while (obj_desc) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && | 
|  | 330 | (obj_desc->data.handler == handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return (AE_ALREADY_EXISTS); | 
|  | 332 | } | 
|  | 333 |  | 
|  | 334 | prev_obj_desc = obj_desc; | 
|  | 335 | obj_desc = obj_desc->common.next_object; | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | /* Create an internal object for the data */ | 
|  | 339 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (!data_desc) { | 
|  | 342 | return (AE_NO_MEMORY); | 
|  | 343 | } | 
|  | 344 |  | 
|  | 345 | data_desc->data.handler = handler; | 
|  | 346 | data_desc->data.pointer = data; | 
|  | 347 |  | 
|  | 348 | /* Install the data object */ | 
|  | 349 |  | 
|  | 350 | if (prev_obj_desc) { | 
|  | 351 | prev_obj_desc->common.next_object = data_desc; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | node->object = data_desc; | 
|  | 354 | } | 
|  | 355 |  | 
|  | 356 | return (AE_OK); | 
|  | 357 | } | 
|  | 358 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /******************************************************************************* | 
|  | 360 | * | 
|  | 361 | * FUNCTION:    acpi_ns_detach_data | 
|  | 362 | * | 
|  | 363 | * PARAMETERS:  Node            - Namespace node | 
|  | 364 | *              Handler         - Handler associated with the data | 
|  | 365 | * | 
|  | 366 | * RETURN:      Status | 
|  | 367 | * | 
|  | 368 | * DESCRIPTION: Low-level detach data.  Delete the data node, but the caller | 
|  | 369 | *              is responsible for the actual data. | 
|  | 370 | * | 
|  | 371 | ******************************************************************************/ | 
|  | 372 |  | 
|  | 373 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | acpi_ns_detach_data(struct acpi_namespace_node * node, | 
|  | 375 | acpi_object_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | union acpi_operand_object *obj_desc; | 
|  | 378 | union acpi_operand_object *prev_obj_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 |  | 
|  | 380 | prev_obj_desc = NULL; | 
|  | 381 | obj_desc = node->object; | 
|  | 382 | while (obj_desc) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && | 
|  | 384 | (obj_desc->data.handler == handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (prev_obj_desc) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | prev_obj_desc->common.next_object = | 
|  | 387 | obj_desc->common.next_object; | 
|  | 388 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | node->object = obj_desc->common.next_object; | 
|  | 390 | } | 
|  | 391 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | acpi_ut_remove_reference(obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return (AE_OK); | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | prev_obj_desc = obj_desc; | 
|  | 397 | obj_desc = obj_desc->common.next_object; | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | return (AE_NOT_FOUND); | 
|  | 401 | } | 
|  | 402 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | /******************************************************************************* | 
|  | 404 | * | 
|  | 405 | * FUNCTION:    acpi_ns_get_attached_data | 
|  | 406 | * | 
|  | 407 | * PARAMETERS:  Node            - Namespace node | 
|  | 408 | *              Handler         - Handler associated with the data | 
|  | 409 | *              Data            - Where the data is returned | 
|  | 410 | * | 
|  | 411 | * RETURN:      Status | 
|  | 412 | * | 
|  | 413 | * DESCRIPTION: Low level interface to obtain data previously associated with | 
|  | 414 | *              a namespace node. | 
|  | 415 | * | 
|  | 416 | ******************************************************************************/ | 
|  | 417 |  | 
|  | 418 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | acpi_ns_get_attached_data(struct acpi_namespace_node * node, | 
|  | 420 | acpi_object_handler handler, void **data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | union acpi_operand_object *obj_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 |  | 
|  | 424 | obj_desc = node->object; | 
|  | 425 | while (obj_desc) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && | 
|  | 427 | (obj_desc->data.handler == handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | *data = obj_desc->data.pointer; | 
|  | 429 | return (AE_OK); | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 | obj_desc = obj_desc->common.next_object; | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | return (AE_NOT_FOUND); | 
|  | 436 | } |