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