blob: 7556d919bf8bbf08613c8ff08bfa79fb9fec594e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsobject - Dispatcher object management routines
4 *
5 *****************************************************************************/
6
7/*
Bob Moore6c9deb72007-02-02 19:48:24 +03008 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acparser.h>
46#include <acpi/amlcode.h>
47#include <acpi/acdispat.h>
48#include <acpi/acnamesp.h>
49#include <acpi/acinterp.h>
50
51#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("dsobject")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Bob Mooredefba1d2005-12-16 17:05:00 -050054/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040055static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
57 union acpi_parse_object *op,
58 union acpi_operand_object **obj_desc_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#ifndef ACPI_NO_METHOD_EXECUTION
Robert Moore44f6c012005-04-18 22:49:35 -040061/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 *
63 * FUNCTION: acpi_ds_build_internal_object
64 *
65 * PARAMETERS: walk_state - Current walk state
66 * Op - Parser object to be translated
67 * obj_desc_ptr - Where the ACPI internal object is returned
68 *
69 * RETURN: Status
70 *
71 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
72 * Simple objects are any objects other than a package object!
73 *
Robert Moore44f6c012005-04-18 22:49:35 -040074 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Robert Moore44f6c012005-04-18 22:49:35 -040076static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040077acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
78 union acpi_parse_object *op,
79 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Len Brown4be44fc2005-08-05 00:44:28 -040081 union acpi_operand_object *obj_desc;
82 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Bob Mooreb229cf92006-04-21 17:15:00 -040084 ACPI_FUNCTION_TRACE(ds_build_internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 *obj_desc_ptr = NULL;
87 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
88 /*
Bob Mooredefba1d2005-12-16 17:05:00 -050089 * This is a named object reference. If this name was
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 * previously looked up in the namespace, it was stored in this op.
91 * Otherwise, go ahead and look it up now
92 */
93 if (!op->common.node) {
Len Brown4be44fc2005-08-05 00:44:28 -040094 status = acpi_ns_lookup(walk_state->scope_info,
95 op->common.value.string,
96 ACPI_TYPE_ANY,
97 ACPI_IMODE_EXECUTE,
98 ACPI_NS_SEARCH_PARENT |
99 ACPI_NS_DONT_OPEN_SCOPE, NULL,
Bob Mooredefba1d2005-12-16 17:05:00 -0500100 ACPI_CAST_INDIRECT_PTR(struct
101 acpi_namespace_node,
102 &(op->
103 common.
104 node)));
Len Brown4be44fc2005-08-05 00:44:28 -0400105 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400106
Bob Mooredefba1d2005-12-16 17:05:00 -0500107 /* Check if we are resolving a named reference within a package */
108
109 if ((status == AE_NOT_FOUND)
110 && (acpi_gbl_enable_interpreter_slack)
111 &&
112 ((op->common.parent->common.aml_opcode ==
113 AML_PACKAGE_OP)
114 || (op->common.parent->common.aml_opcode ==
115 AML_VAR_PACKAGE_OP))) {
116 /*
117 * We didn't find the target and we are populating elements
118 * of a package - ignore if slack enabled. Some ASL code
119 * contains dangling invalid references in packages and
120 * expects that no exception will be issued. Leave the
121 * element as a null element. It cannot be used, but it
122 * can be overwritten by subsequent ASL code - this is
123 * typically the case.
124 */
125 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
126 "Ignoring unresolved reference in package [%4.4s]\n",
127 walk_state->
128 scope_info->scope.
129 node->name.ascii));
130
131 return_ACPI_STATUS(AE_OK);
132 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500133 ACPI_ERROR_NAMESPACE(op->common.value.
134 string, status);
Bob Mooredefba1d2005-12-16 17:05:00 -0500135 }
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139 }
Bob Moore152c3002007-10-17 16:10:18 -0400140
141 /* Special object resolution for elements of a package */
142
143 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
144 (op->common.parent->common.aml_opcode ==
145 AML_VAR_PACKAGE_OP)) {
146 /*
147 * Attempt to resolve the node to a value before we insert it into
148 * the package. If this is a reference to a common data type,
149 * resolve it immediately. According to the ACPI spec, package
150 * elements can only be "data objects" or method references.
151 * Attempt to resolve to an Integer, Buffer, String or Package.
152 * If cannot, return the named reference (for things like Devices,
153 * Methods, etc.) Buffer Fields and Fields will resolve to simple
154 * objects (int/buf/str/pkg).
155 *
156 * NOTE: References to things like Devices, Methods, Mutexes, etc.
157 * will remain as named references. This behavior is not described
158 * in the ACPI spec, but it appears to be an oversight.
159 */
160 obj_desc = (union acpi_operand_object *)op->common.node;
161
162 status =
163 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
164 (struct
165 acpi_namespace_node,
166 &obj_desc),
167 walk_state);
168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
170 }
171
172 switch (op->common.node->type) {
173 /*
174 * For these types, we need the actual node, not the subobject.
Bob Moore9e41d932008-04-10 19:06:39 +0400175 * However, the subobject did not get an extra reference count above.
176 *
177 * TBD: should ex_resolve_node_to_value be changed to fix this?
178 */
179 case ACPI_TYPE_DEVICE:
180 case ACPI_TYPE_THERMAL:
181
182 acpi_ut_add_reference(op->common.node->object);
183
184 /*lint -fallthrough */
185 /*
186 * For these types, we need the actual node, not the subobject.
187 * The subobject got an extra reference count in ex_resolve_node_to_value.
Bob Moore152c3002007-10-17 16:10:18 -0400188 */
189 case ACPI_TYPE_MUTEX:
190 case ACPI_TYPE_METHOD:
191 case ACPI_TYPE_POWER:
192 case ACPI_TYPE_PROCESSOR:
193 case ACPI_TYPE_EVENT:
194 case ACPI_TYPE_REGION:
Bob Moore152c3002007-10-17 16:10:18 -0400195
Bob Moore9e41d932008-04-10 19:06:39 +0400196 /* We will create a reference object for these types below */
Bob Moore152c3002007-10-17 16:10:18 -0400197 break;
198
199 default:
Bob Moore9e41d932008-04-10 19:06:39 +0400200 /*
201 * All other types - the node was resolved to an actual
202 * object, we are done.
203 */
Bob Moore152c3002007-10-17 16:10:18 -0400204 goto exit;
205 }
206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208
Bob Mooredefba1d2005-12-16 17:05:00 -0500209 /* Create and init a new internal ACPI object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Len Brown4be44fc2005-08-05 00:44:28 -0400211 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
212 (op->common.aml_opcode))->
213 object_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400215 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 status =
219 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
220 &obj_desc);
221 if (ACPI_FAILURE(status)) {
222 acpi_ut_remove_reference(obj_desc);
223 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
Bob Moore152c3002007-10-17 16:10:18 -0400226 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 *obj_desc_ptr = obj_desc;
Bob Moore9e41d932008-04-10 19:06:39 +0400228 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Robert Moore44f6c012005-04-18 22:49:35 -0400231/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 *
233 * FUNCTION: acpi_ds_build_internal_buffer_obj
234 *
235 * PARAMETERS: walk_state - Current walk state
236 * Op - Parser object to be translated
237 * buffer_length - Length of the buffer
238 * obj_desc_ptr - Where the ACPI internal object is returned
239 *
240 * RETURN: Status
241 *
242 * DESCRIPTION: Translate a parser Op package object to the equivalent
243 * namespace object
244 *
Robert Moore44f6c012005-04-18 22:49:35 -0400245 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400248acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
249 union acpi_parse_object *op,
250 u32 buffer_length,
251 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Len Brown4be44fc2005-08-05 00:44:28 -0400253 union acpi_parse_object *arg;
254 union acpi_operand_object *obj_desc;
255 union acpi_parse_object *byte_list;
256 u32 byte_list_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Bob Mooreb229cf92006-04-21 17:15:00 -0400258 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Bob Mooredefba1d2005-12-16 17:05:00 -0500260 /*
261 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
262 * The buffer object already exists (from the NS node), otherwise it must
263 * be created.
264 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500266 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* Create a new buffer object */
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 *obj_desc_ptr = obj_desc;
272 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400273 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275 }
276
277 /*
278 * Second arg is the buffer data (optional) byte_list can be either
279 * individual bytes or a string initializer. In either case, a
280 * byte_list appears in the AML.
281 */
Len Brown4be44fc2005-08-05 00:44:28 -0400282 arg = op->common.value.arg; /* skip first arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 byte_list = arg->named.next;
285 if (byte_list) {
286 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500287 ACPI_ERROR((AE_INFO,
288 "Expecting bytelist, got AML opcode %X in op %p",
289 byte_list->common.aml_opcode, byte_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return (AE_TYPE);
293 }
294
295 byte_list_length = (u32) byte_list->common.value.integer;
296 }
297
298 /*
299 * The buffer length (number of bytes) will be the larger of:
300 * 1) The specified buffer length and
301 * 2) The length of the initializer byte list
302 */
303 obj_desc->buffer.length = buffer_length;
304 if (byte_list_length > buffer_length) {
305 obj_desc->buffer.length = byte_list_length;
306 }
307
308 /* Allocate the buffer */
309
310 if (obj_desc->buffer.length == 0) {
311 obj_desc->buffer.pointer = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400312 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
313 "Buffer defined with zero length in AML, creating\n"));
314 } else {
315 obj_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400316 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 if (!obj_desc->buffer.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400318 acpi_ut_delete_object_desc(obj_desc);
319 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
322 /* Initialize buffer from the byte_list (if present) */
323
324 if (byte_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400325 ACPI_MEMCPY(obj_desc->buffer.pointer,
326 byte_list->named.data, byte_list_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328 }
329
330 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
Bob Moore8f9337c2007-02-02 19:48:18 +0300331 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400332 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Robert Moore44f6c012005-04-18 22:49:35 -0400335/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *
337 * FUNCTION: acpi_ds_build_internal_package_obj
338 *
339 * PARAMETERS: walk_state - Current walk state
340 * Op - Parser object to be translated
Bob Moore8f9337c2007-02-02 19:48:18 +0300341 * element_count - Number of elements in the package - this is
342 * the num_elements argument to Package()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 * obj_desc_ptr - Where the ACPI internal object is returned
344 *
345 * RETURN: Status
346 *
347 * DESCRIPTION: Translate a parser Op package object to the equivalent
348 * namespace object
349 *
Bob Moore8f9337c2007-02-02 19:48:18 +0300350 * NOTE: The number of elements in the package will be always be the num_elements
351 * count, regardless of the number of elements in the package list. If
352 * num_elements is smaller, only that many package list elements are used.
353 * if num_elements is larger, the Package object is padded out with
354 * objects of type Uninitialized (as per ACPI spec.)
355 *
356 * Even though the ASL compilers do not allow num_elements to be smaller
357 * than the Package list length (for the fixed length package opcode), some
358 * BIOS code modifies the AML on the fly to adjust the num_elements, and
359 * this code compensates for that. This also provides compatibility with
360 * other AML interpreters.
361 *
Robert Moore44f6c012005-04-18 22:49:35 -0400362 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400365acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
366 union acpi_parse_object *op,
Bob Moore8f9337c2007-02-02 19:48:18 +0300367 u32 element_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400368 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Len Brown4be44fc2005-08-05 00:44:28 -0400370 union acpi_parse_object *arg;
371 union acpi_parse_object *parent;
372 union acpi_operand_object *obj_desc = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400373 acpi_status status = AE_OK;
Bob Mooredefba1d2005-12-16 17:05:00 -0500374 acpi_native_uint i;
Bob Moore91d02132008-04-10 19:06:38 +0400375 u16 index;
376 u16 reference_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Bob Mooreb229cf92006-04-21 17:15:00 -0400378 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 /* Find the parent of a possibly nested package */
381
382 parent = op->common.parent;
Len Brown4be44fc2005-08-05 00:44:28 -0400383 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
384 (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 parent = parent->common.parent;
386 }
387
Bob Mooredefba1d2005-12-16 17:05:00 -0500388 /*
389 * If we are evaluating a Named package object "Name (xxxx, Package)",
390 * the package object already exists, otherwise it must be created.
391 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500393 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400394 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 *obj_desc_ptr = obj_desc;
396 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400397 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
399
400 obj_desc->package.node = parent->common.node;
401 }
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 /*
Bob Moore8f9337c2007-02-02 19:48:18 +0300404 * Allocate the element array (array of pointers to the individual
405 * objects) based on the num_elements parameter. Add an extra pointer slot
406 * so that the list is always null terminated.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 */
Bob Moore83135242006-10-03 00:00:00 -0400408 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
Bob Moore8f9337c2007-02-02 19:48:18 +0300409 element_count +
Bob Moore83135242006-10-03 00:00:00 -0400410 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (!obj_desc->package.elements) {
Len Brown4be44fc2005-08-05 00:44:28 -0400413 acpi_ut_delete_object_desc(obj_desc);
414 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
Bob Moore8f9337c2007-02-02 19:48:18 +0300417 obj_desc->package.count = element_count;
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 /*
Bob Moore8f9337c2007-02-02 19:48:18 +0300420 * Initialize the elements of the package, up to the num_elements count.
421 * Package is automatically padded with uninitialized (NULL) elements
422 * if num_elements is greater than the package list length. Likewise,
423 * Package is truncated if num_elements is less than the list length.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 arg = op->common.value.arg;
426 arg = arg->common.next;
Bob Moore8f9337c2007-02-02 19:48:18 +0300427 for (i = 0; arg && (i < element_count); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
Bob Moore152c3002007-10-17 16:10:18 -0400429 if (arg->common.node->type == ACPI_TYPE_METHOD) {
430 /*
431 * A method reference "looks" to the parser to be a method
432 * invocation, so we special case it here
433 */
434 arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
435 status =
436 acpi_ds_build_internal_object(walk_state,
437 arg,
438 &obj_desc->
439 package.
440 elements[i]);
441 } else {
442 /* This package element is already built, just get it */
Bob Moore52fc0b02006-10-02 00:00:00 -0400443
Bob Moore152c3002007-10-17 16:10:18 -0400444 obj_desc->package.elements[i] =
445 ACPI_CAST_PTR(union acpi_operand_object,
446 arg->common.node);
447 }
Len Brown4be44fc2005-08-05 00:44:28 -0400448 } else {
449 status = acpi_ds_build_internal_object(walk_state, arg,
450 &obj_desc->
451 package.
452 elements[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
Bob Moore91d02132008-04-10 19:06:38 +0400454
455 if (*obj_desc_ptr) {
456
457 /* Existing package, get existing reference count */
458
459 reference_count =
460 (*obj_desc_ptr)->common.reference_count;
461 if (reference_count > 1) {
462
463 /* Make new element ref count match original ref count */
464
465 for (index = 0; index < (reference_count - 1);
466 index++) {
467 acpi_ut_add_reference((obj_desc->
468 package.
469 elements[i]));
470 }
471 }
472 }
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 arg = arg->common.next;
475 }
476
Bob Moore8f9337c2007-02-02 19:48:18 +0300477 if (!arg) {
478 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
479 "Package List length larger than NumElements count (%X), truncated\n",
480 element_count));
481 }
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
Bob Moore8f9337c2007-02-02 19:48:18 +0300484 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400485 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
Robert Moore44f6c012005-04-18 22:49:35 -0400488/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 *
490 * FUNCTION: acpi_ds_create_node
491 *
492 * PARAMETERS: walk_state - Current walk state
493 * Node - NS Node to be initialized
494 * Op - Parser object to be translated
495 *
496 * RETURN: Status
497 *
498 * DESCRIPTION: Create the object to be associated with a namespace node
499 *
Robert Moore44f6c012005-04-18 22:49:35 -0400500 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400503acpi_ds_create_node(struct acpi_walk_state *walk_state,
504 struct acpi_namespace_node *node,
505 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Len Brown4be44fc2005-08-05 00:44:28 -0400507 acpi_status status;
508 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Bob Mooreb229cf92006-04-21 17:15:00 -0400510 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /*
513 * Because of the execution pass through the non-control-method
514 * parts of the table, we can arrive here twice. Only init
515 * the named object node the first time through
516 */
Len Brown4be44fc2005-08-05 00:44:28 -0400517 if (acpi_ns_get_attached_object(node)) {
518 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
520
521 if (!op->common.value.arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 /* No arguments, there is nothing to do */
524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
528 /* Build an internal object for the argument(s) */
529
Len Brown4be44fc2005-08-05 00:44:28 -0400530 status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
531 &obj_desc);
532 if (ACPI_FAILURE(status)) {
533 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535
536 /* Re-type the object according to its argument */
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 /* Attach obj to node */
541
Len Brown4be44fc2005-08-05 00:44:28 -0400542 status = acpi_ns_attach_object(node, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Remove local reference to the object */
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 acpi_ut_remove_reference(obj_desc);
547 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Len Brown4be44fc2005-08-05 00:44:28 -0400550#endif /* ACPI_NO_METHOD_EXECUTION */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Robert Moore44f6c012005-04-18 22:49:35 -0400552/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 *
554 * FUNCTION: acpi_ds_init_object_from_op
555 *
556 * PARAMETERS: walk_state - Current walk state
557 * Op - Parser op used to init the internal object
558 * Opcode - AML opcode associated with the object
559 * ret_obj_desc - Namespace object to be initialized
560 *
561 * RETURN: Status
562 *
563 * DESCRIPTION: Initialize a namespace object from a parser Op and its
564 * associated arguments. The namespace object is a more compact
565 * representation of the Op and its arguments.
566 *
Robert Moore44f6c012005-04-18 22:49:35 -0400567 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
571 union acpi_parse_object *op,
572 u16 opcode,
573 union acpi_operand_object **ret_obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Len Brown4be44fc2005-08-05 00:44:28 -0400575 const struct acpi_opcode_info *op_info;
576 union acpi_operand_object *obj_desc;
577 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Bob Mooreb229cf92006-04-21 17:15:00 -0400579 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 obj_desc = *ret_obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400582 op_info = acpi_ps_get_opcode_info(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 if (op_info->class == AML_CLASS_UNKNOWN) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* Unknown opcode */
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
590 /* Perform per-object initialization */
591
Len Brown4be44fc2005-08-05 00:44:28 -0400592 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 case ACPI_TYPE_BUFFER:
594
595 /*
596 * Defer evaluation of Buffer term_arg operand
597 */
Bob Moore8f9337c2007-02-02 19:48:18 +0300598 obj_desc->buffer.node =
599 ACPI_CAST_PTR(struct acpi_namespace_node,
600 walk_state->operands[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 obj_desc->buffer.aml_start = op->named.data;
602 obj_desc->buffer.aml_length = op->named.length;
603 break;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 case ACPI_TYPE_PACKAGE:
606
607 /*
608 * Defer evaluation of Package term_arg operand
609 */
Bob Moore8f9337c2007-02-02 19:48:18 +0300610 obj_desc->package.node =
611 ACPI_CAST_PTR(struct acpi_namespace_node,
612 walk_state->operands[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 obj_desc->package.aml_start = op->named.data;
614 obj_desc->package.aml_length = op->named.length;
615 break;
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 case ACPI_TYPE_INTEGER:
618
619 switch (op_info->type) {
620 case AML_TYPE_CONSTANT:
621 /*
622 * Resolve AML Constants here - AND ONLY HERE!
623 * All constants are integers.
Robert Moore44f6c012005-04-18 22:49:35 -0400624 * We mark the integer with a flag that indicates that it started
625 * life as a constant -- so that stores to constants will perform
626 * as expected (noop). zero_op is used as a placeholder for optional
627 * target operands.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 */
629 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
630
631 switch (opcode) {
632 case AML_ZERO_OP:
633
634 obj_desc->integer.value = 0;
635 break;
636
637 case AML_ONE_OP:
638
639 obj_desc->integer.value = 1;
640 break;
641
642 case AML_ONES_OP:
643
644 obj_desc->integer.value = ACPI_INTEGER_MAX;
645
646 /* Truncate value if we are executing from a 32-bit ACPI table */
647
648#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400649 acpi_ex_truncate_for32bit_table(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#endif
651 break;
652
653 case AML_REVISION_OP:
654
655 obj_desc->integer.value = ACPI_CA_VERSION;
656 break;
657
658 default:
659
Bob Mooreb8e4d892006-01-27 16:43:00 -0500660 ACPI_ERROR((AE_INFO,
661 "Unknown constant opcode %X",
662 opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 status = AE_AML_OPERAND_TYPE;
664 break;
665 }
666 break;
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 case AML_TYPE_LITERAL:
669
670 obj_desc->integer.value = op->common.value.integer;
Robert Moore6f42ccf2005-05-13 00:00:00 -0400671#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400672 acpi_ex_truncate_for32bit_table(obj_desc);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400673#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 break;
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500677 ACPI_ERROR((AE_INFO, "Unknown Integer type %X",
678 op_info->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 status = AE_AML_OPERAND_TYPE;
680 break;
681 }
682 break;
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 case ACPI_TYPE_STRING:
685
686 obj_desc->string.pointer = op->common.value.string;
Len Brown4be44fc2005-08-05 00:44:28 -0400687 obj_desc->string.length =
688 (u32) ACPI_STRLEN(op->common.value.string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 /*
691 * The string is contained in the ACPI table, don't ever try
692 * to delete it
693 */
694 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
695 break;
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 case ACPI_TYPE_METHOD:
698 break;
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 case ACPI_TYPE_LOCAL_REFERENCE:
701
702 switch (op_info->type) {
703 case AML_TYPE_LOCAL_VARIABLE:
704
705 /* Split the opcode into a base opcode + offset */
706
707 obj_desc->reference.opcode = AML_LOCAL_OP;
708 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
709
710#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400711 status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
712 obj_desc->
713 reference.offset,
714 walk_state,
715 (struct
716 acpi_namespace_node
717 **)&obj_desc->
718 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#endif
720 break;
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 case AML_TYPE_METHOD_ARGUMENT:
723
724 /* Split the opcode into a base opcode + offset */
725
726 obj_desc->reference.opcode = AML_ARG_OP;
727 obj_desc->reference.offset = opcode - AML_ARG_OP;
728
729#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400730 status = acpi_ds_method_data_get_node(AML_ARG_OP,
731 obj_desc->
732 reference.offset,
733 walk_state,
734 (struct
735 acpi_namespace_node
736 **)&obj_desc->
737 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#endif
739 break;
740
Len Brown4be44fc2005-08-05 00:44:28 -0400741 default: /* Other literals, etc.. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /* Node was saved in Op */
746
747 obj_desc->reference.node = op->common.node;
Bob Moore9e41d932008-04-10 19:06:39 +0400748 obj_desc->reference.object =
749 op->common.node->object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751
752 obj_desc->reference.opcode = opcode;
753 break;
754 }
755 break;
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 default:
758
Bob Mooreb8e4d892006-01-27 16:43:00 -0500759 ACPI_ERROR((AE_INFO, "Unimplemented data type: %X",
760 ACPI_GET_OBJECT_TYPE(obj_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 status = AE_AML_OPERAND_TYPE;
763 break;
764 }
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}