Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: nsobject - Utilities for objects attached to namespace | |
4 | * table entries | |
5 | * | |
6 | ******************************************************************************/ | |
7 | ||
8 | /* | |
25f044e6 | 9 | * Copyright (C) 2000 - 2013, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 45 | #include <acpi/acpi.h> |
e2f7a777 LB |
46 | #include "accommon.h" |
47 | #include "acnamesp.h" | |
1da177e4 | 48 | |
1da177e4 | 49 | #define _COMPONENT ACPI_NAMESPACE |
4be44fcd | 50 | ACPI_MODULE_NAME("nsobject") |
1da177e4 LT |
51 | |
52 | /******************************************************************************* | |
53 | * | |
54 | * FUNCTION: acpi_ns_attach_object | |
55 | * | |
ba494bee BM |
56 | * PARAMETERS: node - Parent Node |
57 | * object - Object to be attached | |
58 | * type - Type of object, or ACPI_TYPE_ANY if not | |
1da177e4 LT |
59 | * known |
60 | * | |
44f6c012 RM |
61 | * RETURN: Status |
62 | * | |
1da177e4 | 63 | * DESCRIPTION: Record the given object as the value associated with the |
73a3090a | 64 | * name whose acpi_handle is passed. If Object is NULL |
1da177e4 LT |
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 | ******************************************************************************/ | |
1da177e4 | 72 | acpi_status |
4be44fcd LB |
73 | acpi_ns_attach_object(struct acpi_namespace_node *node, |
74 | union acpi_operand_object *object, acpi_object_type type) | |
1da177e4 | 75 | { |
4be44fcd LB |
76 | union acpi_operand_object *obj_desc; |
77 | union acpi_operand_object *last_obj_desc; | |
78 | acpi_object_type object_type = ACPI_TYPE_ANY; | |
1da177e4 | 79 | |
b229cf92 | 80 | ACPI_FUNCTION_TRACE(ns_attach_object); |
1da177e4 LT |
81 | |
82 | /* | |
83 | * Parameter validation | |
84 | */ | |
85 | if (!node) { | |
52fc0b02 | 86 | |
1da177e4 LT |
87 | /* Invalid handle */ |
88 | ||
b229cf92 | 89 | ACPI_ERROR((AE_INFO, "Null NamedObj handle")); |
4be44fcd | 90 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
91 | } |
92 | ||
93 | if (!object && (ACPI_TYPE_ANY != type)) { | |
52fc0b02 | 94 | |
1da177e4 LT |
95 | /* Null object */ |
96 | ||
b8e4d893 BM |
97 | ACPI_ERROR((AE_INFO, |
98 | "Null object, but type not ACPI_TYPE_ANY")); | |
4be44fcd | 99 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
100 | } |
101 | ||
4be44fcd | 102 | if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { |
52fc0b02 | 103 | |
1da177e4 LT |
104 | /* Not a name handle */ |
105 | ||
b8e4d893 BM |
106 | ACPI_ERROR((AE_INFO, "Invalid handle %p [%s]", |
107 | node, acpi_ut_get_descriptor_name(node))); | |
4be44fcd | 108 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
109 | } |
110 | ||
111 | /* Check if this object is already attached */ | |
112 | ||
113 | if (node->object == object) { | |
4be44fcd | 114 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
b229cf92 | 115 | "Obj %p already installed in NameObj %p\n", |
4be44fcd | 116 | object, node)); |
1da177e4 | 117 | |
4be44fcd | 118 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
119 | } |
120 | ||
121 | /* If null object, we will just install it */ | |
122 | ||
123 | if (!object) { | |
4be44fcd | 124 | obj_desc = NULL; |
1da177e4 LT |
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 | */ | |
4be44fcd LB |
132 | else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) && |
133 | ((struct acpi_namespace_node *)object)->object) { | |
1da177e4 LT |
134 | /* |
135 | * Value passed is a name handle and that name has a | |
73a3090a | 136 | * non-null value. Use that name's value and type. |
1da177e4 | 137 | */ |
4be44fcd LB |
138 | obj_desc = ((struct acpi_namespace_node *)object)->object; |
139 | object_type = ((struct acpi_namespace_node *)object)->type; | |
1da177e4 LT |
140 | } |
141 | ||
142 | /* | |
143 | * Otherwise, we will use the parameter object, but we must type | |
144 | * it first | |
145 | */ | |
146 | else { | |
4be44fcd | 147 | obj_desc = (union acpi_operand_object *)object; |
1da177e4 LT |
148 | |
149 | /* Use the given type */ | |
150 | ||
151 | object_type = type; | |
152 | } | |
153 | ||
4be44fcd LB |
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))); | |
1da177e4 LT |
156 | |
157 | /* Detach an existing attached object if present */ | |
158 | ||
159 | if (node->object) { | |
4be44fcd | 160 | acpi_ns_detach_object(node); |
1da177e4 LT |
161 | } |
162 | ||
163 | if (obj_desc) { | |
164 | /* | |
165 | * Must increment the new value's reference count | |
166 | * (if it is an internal object) | |
167 | */ | |
4be44fcd | 168 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
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 | ||
4be44fcd LB |
184 | node->type = (u8) object_type; |
185 | node->object = obj_desc; | |
1da177e4 | 186 | |
4be44fcd | 187 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
188 | } |
189 | ||
1da177e4 LT |
190 | /******************************************************************************* |
191 | * | |
192 | * FUNCTION: acpi_ns_detach_object | |
193 | * | |
ba494bee | 194 | * PARAMETERS: node - A Namespace node whose object will be detached |
1da177e4 LT |
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 | ||
4be44fcd | 204 | void acpi_ns_detach_object(struct acpi_namespace_node *node) |
1da177e4 | 205 | { |
4be44fcd | 206 | union acpi_operand_object *obj_desc; |
1da177e4 | 207 | |
b229cf92 | 208 | ACPI_FUNCTION_TRACE(ns_detach_object); |
1da177e4 LT |
209 | |
210 | obj_desc = node->object; | |
211 | ||
3371c19c | 212 | if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) { |
1da177e4 LT |
213 | return_VOID; |
214 | } | |
215 | ||
b2f7ddcf LM |
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 | ||
1da177e4 LT |
225 | /* Clear the entry in all cases */ |
226 | ||
227 | node->object = NULL; | |
4be44fcd | 228 | if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) { |
1da177e4 LT |
229 | node->object = obj_desc->common.next_object; |
230 | if (node->object && | |
3371c19c | 231 | ((node->object)->common.type != ACPI_TYPE_LOCAL_DATA)) { |
1da177e4 LT |
232 | node->object = node->object->common.next_object; |
233 | } | |
234 | } | |
235 | ||
236 | /* Reset the node type to untyped */ | |
237 | ||
238 | node->type = ACPI_TYPE_ANY; | |
239 | ||
4be44fcd LB |
240 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n", |
241 | node, acpi_ut_get_node_name(node), obj_desc)); | |
1da177e4 LT |
242 | |
243 | /* Remove one reference on the object (and all subobjects) */ | |
244 | ||
4be44fcd | 245 | acpi_ut_remove_reference(obj_desc); |
1da177e4 LT |
246 | return_VOID; |
247 | } | |
248 | ||
1da177e4 LT |
249 | /******************************************************************************* |
250 | * | |
251 | * FUNCTION: acpi_ns_get_attached_object | |
252 | * | |
ba494bee | 253 | * PARAMETERS: node - Namespace node |
1da177e4 LT |
254 | * |
255 | * RETURN: Current value of the object field from the Node whose | |
256 | * handle is passed | |
257 | * | |
258 | * DESCRIPTION: Obtain the object attached to a namespace node. | |
259 | * | |
260 | ******************************************************************************/ | |
261 | ||
4be44fcd LB |
262 | union acpi_operand_object *acpi_ns_get_attached_object(struct |
263 | acpi_namespace_node | |
264 | *node) | |
1da177e4 | 265 | { |
b229cf92 | 266 | ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node); |
1da177e4 LT |
267 | |
268 | if (!node) { | |
b8e4d893 | 269 | ACPI_WARNING((AE_INFO, "Null Node ptr")); |
4be44fcd | 270 | return_PTR(NULL); |
1da177e4 LT |
271 | } |
272 | ||
273 | if (!node->object || | |
4be44fcd LB |
274 | ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND) |
275 | && (ACPI_GET_DESCRIPTOR_TYPE(node->object) != | |
276 | ACPI_DESC_TYPE_NAMED)) | |
3371c19c | 277 | || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) { |
4be44fcd | 278 | return_PTR(NULL); |
1da177e4 LT |
279 | } |
280 | ||
4be44fcd | 281 | return_PTR(node->object); |
1da177e4 LT |
282 | } |
283 | ||
1da177e4 LT |
284 | /******************************************************************************* |
285 | * | |
286 | * FUNCTION: acpi_ns_get_secondary_object | |
287 | * | |
ba494bee | 288 | * PARAMETERS: node - Namespace node |
1da177e4 LT |
289 | * |
290 | * RETURN: Current value of the object field from the Node whose | |
291 | * handle is passed. | |
292 | * | |
293 | * DESCRIPTION: Obtain a secondary object associated with a namespace node. | |
294 | * | |
295 | ******************************************************************************/ | |
296 | ||
4be44fcd LB |
297 | union acpi_operand_object *acpi_ns_get_secondary_object(union |
298 | acpi_operand_object | |
299 | *obj_desc) | |
1da177e4 | 300 | { |
b229cf92 | 301 | ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc); |
4be44fcd LB |
302 | |
303 | if ((!obj_desc) || | |
3371c19c | 304 | (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) || |
4be44fcd | 305 | (!obj_desc->common.next_object) || |
3371c19c | 306 | ((obj_desc->common.next_object)->common.type == |
4be44fcd LB |
307 | ACPI_TYPE_LOCAL_DATA)) { |
308 | return_PTR(NULL); | |
1da177e4 LT |
309 | } |
310 | ||
4be44fcd | 311 | return_PTR(obj_desc->common.next_object); |
1da177e4 LT |
312 | } |
313 | ||
1da177e4 LT |
314 | /******************************************************************************* |
315 | * | |
316 | * FUNCTION: acpi_ns_attach_data | |
317 | * | |
ba494bee BM |
318 | * PARAMETERS: node - Namespace node |
319 | * handler - Handler to be associated with the data | |
320 | * data - Data to be attached | |
1da177e4 LT |
321 | * |
322 | * RETURN: Status | |
323 | * | |
73a3090a | 324 | * DESCRIPTION: Low-level attach data. Create and attach a Data object. |
1da177e4 LT |
325 | * |
326 | ******************************************************************************/ | |
327 | ||
328 | acpi_status | |
4be44fcd LB |
329 | acpi_ns_attach_data(struct acpi_namespace_node *node, |
330 | acpi_object_handler handler, void *data) | |
1da177e4 | 331 | { |
4be44fcd LB |
332 | union acpi_operand_object *prev_obj_desc; |
333 | union acpi_operand_object *obj_desc; | |
334 | union acpi_operand_object *data_desc; | |
1da177e4 LT |
335 | |
336 | /* We only allow one attachment per handler */ | |
337 | ||
338 | prev_obj_desc = NULL; | |
339 | obj_desc = node->object; | |
340 | while (obj_desc) { | |
3371c19c | 341 | if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && |
4be44fcd | 342 | (obj_desc->data.handler == handler)) { |
1da177e4 LT |
343 | return (AE_ALREADY_EXISTS); |
344 | } | |
345 | ||
346 | prev_obj_desc = obj_desc; | |
347 | obj_desc = obj_desc->common.next_object; | |
348 | } | |
349 | ||
350 | /* Create an internal object for the data */ | |
351 | ||
4be44fcd | 352 | data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA); |
1da177e4 LT |
353 | if (!data_desc) { |
354 | return (AE_NO_MEMORY); | |
355 | } | |
356 | ||
357 | data_desc->data.handler = handler; | |
358 | data_desc->data.pointer = data; | |
359 | ||
360 | /* Install the data object */ | |
361 | ||
362 | if (prev_obj_desc) { | |
363 | prev_obj_desc->common.next_object = data_desc; | |
4be44fcd | 364 | } else { |
1da177e4 LT |
365 | node->object = data_desc; |
366 | } | |
367 | ||
368 | return (AE_OK); | |
369 | } | |
370 | ||
1da177e4 LT |
371 | /******************************************************************************* |
372 | * | |
373 | * FUNCTION: acpi_ns_detach_data | |
374 | * | |
ba494bee BM |
375 | * PARAMETERS: node - Namespace node |
376 | * handler - Handler associated with the data | |
1da177e4 LT |
377 | * |
378 | * RETURN: Status | |
379 | * | |
73a3090a | 380 | * DESCRIPTION: Low-level detach data. Delete the data node, but the caller |
1da177e4 LT |
381 | * is responsible for the actual data. |
382 | * | |
383 | ******************************************************************************/ | |
384 | ||
385 | acpi_status | |
4be44fcd LB |
386 | acpi_ns_detach_data(struct acpi_namespace_node * node, |
387 | acpi_object_handler handler) | |
1da177e4 | 388 | { |
4be44fcd LB |
389 | union acpi_operand_object *obj_desc; |
390 | union acpi_operand_object *prev_obj_desc; | |
1da177e4 LT |
391 | |
392 | prev_obj_desc = NULL; | |
393 | obj_desc = node->object; | |
394 | while (obj_desc) { | |
3371c19c | 395 | if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && |
4be44fcd | 396 | (obj_desc->data.handler == handler)) { |
1da177e4 | 397 | if (prev_obj_desc) { |
4be44fcd LB |
398 | prev_obj_desc->common.next_object = |
399 | obj_desc->common.next_object; | |
400 | } else { | |
1da177e4 LT |
401 | node->object = obj_desc->common.next_object; |
402 | } | |
403 | ||
4be44fcd | 404 | acpi_ut_remove_reference(obj_desc); |
1da177e4 LT |
405 | return (AE_OK); |
406 | } | |
407 | ||
408 | prev_obj_desc = obj_desc; | |
409 | obj_desc = obj_desc->common.next_object; | |
410 | } | |
411 | ||
412 | return (AE_NOT_FOUND); | |
413 | } | |
414 | ||
1da177e4 LT |
415 | /******************************************************************************* |
416 | * | |
417 | * FUNCTION: acpi_ns_get_attached_data | |
418 | * | |
ba494bee BM |
419 | * PARAMETERS: node - Namespace node |
420 | * handler - Handler associated with the data | |
421 | * data - Where the data is returned | |
1da177e4 LT |
422 | * |
423 | * RETURN: Status | |
424 | * | |
425 | * DESCRIPTION: Low level interface to obtain data previously associated with | |
426 | * a namespace node. | |
427 | * | |
428 | ******************************************************************************/ | |
429 | ||
430 | acpi_status | |
4be44fcd LB |
431 | acpi_ns_get_attached_data(struct acpi_namespace_node * node, |
432 | acpi_object_handler handler, void **data) | |
1da177e4 | 433 | { |
4be44fcd | 434 | union acpi_operand_object *obj_desc; |
1da177e4 LT |
435 | |
436 | obj_desc = node->object; | |
437 | while (obj_desc) { | |
3371c19c | 438 | if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && |
4be44fcd | 439 | (obj_desc->data.handler == handler)) { |
1da177e4 LT |
440 | *data = obj_desc->data.pointer; |
441 | return (AE_OK); | |
442 | } | |
443 | ||
444 | obj_desc = obj_desc->common.next_object; | |
445 | } | |
446 | ||
447 | return (AE_NOT_FOUND); | |
448 | } |