blob: 72190abb1d59cb9036484b9560cee9a6105f30b3 [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 Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, 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 }
140 }
141
Bob Mooredefba1d2005-12-16 17:05:00 -0500142 /* Create and init a new internal ACPI object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
145 (op->common.aml_opcode))->
146 object_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400148 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 status =
152 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
153 &obj_desc);
154 if (ACPI_FAILURE(status)) {
155 acpi_ut_remove_reference(obj_desc);
156 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
159 *obj_desc_ptr = obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400160 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Robert Moore44f6c012005-04-18 22:49:35 -0400163/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 *
165 * FUNCTION: acpi_ds_build_internal_buffer_obj
166 *
167 * PARAMETERS: walk_state - Current walk state
168 * Op - Parser object to be translated
169 * buffer_length - Length of the buffer
170 * obj_desc_ptr - Where the ACPI internal object is returned
171 *
172 * RETURN: Status
173 *
174 * DESCRIPTION: Translate a parser Op package object to the equivalent
175 * namespace object
176 *
Robert Moore44f6c012005-04-18 22:49:35 -0400177 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400180acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
181 union acpi_parse_object *op,
182 u32 buffer_length,
183 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Len Brown4be44fc2005-08-05 00:44:28 -0400185 union acpi_parse_object *arg;
186 union acpi_operand_object *obj_desc;
187 union acpi_parse_object *byte_list;
188 u32 byte_list_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Bob Mooreb229cf92006-04-21 17:15:00 -0400190 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Bob Mooredefba1d2005-12-16 17:05:00 -0500192 /*
193 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
194 * The buffer object already exists (from the NS node), otherwise it must
195 * be created.
196 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500198 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 /* Create a new buffer object */
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 *obj_desc_ptr = obj_desc;
204 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207 }
208
209 /*
210 * Second arg is the buffer data (optional) byte_list can be either
211 * individual bytes or a string initializer. In either case, a
212 * byte_list appears in the AML.
213 */
Len Brown4be44fc2005-08-05 00:44:28 -0400214 arg = op->common.value.arg; /* skip first arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 byte_list = arg->named.next;
217 if (byte_list) {
218 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500219 ACPI_ERROR((AE_INFO,
220 "Expecting bytelist, got AML opcode %X in op %p",
221 byte_list->common.aml_opcode, byte_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return (AE_TYPE);
225 }
226
227 byte_list_length = (u32) byte_list->common.value.integer;
228 }
229
230 /*
231 * The buffer length (number of bytes) will be the larger of:
232 * 1) The specified buffer length and
233 * 2) The length of the initializer byte list
234 */
235 obj_desc->buffer.length = buffer_length;
236 if (byte_list_length > buffer_length) {
237 obj_desc->buffer.length = byte_list_length;
238 }
239
240 /* Allocate the buffer */
241
242 if (obj_desc->buffer.length == 0) {
243 obj_desc->buffer.pointer = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
245 "Buffer defined with zero length in AML, creating\n"));
246 } else {
247 obj_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400248 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!obj_desc->buffer.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400250 acpi_ut_delete_object_desc(obj_desc);
251 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
254 /* Initialize buffer from the byte_list (if present) */
255
256 if (byte_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400257 ACPI_MEMCPY(obj_desc->buffer.pointer,
258 byte_list->named.data, byte_list_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
260 }
261
262 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
Len Brown4be44fc2005-08-05 00:44:28 -0400263 op->common.node = (struct acpi_namespace_node *)obj_desc;
264 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
Robert Moore44f6c012005-04-18 22:49:35 -0400267/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 *
269 * FUNCTION: acpi_ds_build_internal_package_obj
270 *
271 * PARAMETERS: walk_state - Current walk state
272 * Op - Parser object to be translated
273 * package_length - Number of elements in the package
274 * obj_desc_ptr - Where the ACPI internal object is returned
275 *
276 * RETURN: Status
277 *
278 * DESCRIPTION: Translate a parser Op package object to the equivalent
279 * namespace object
280 *
Robert Moore44f6c012005-04-18 22:49:35 -0400281 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400284acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
285 union acpi_parse_object *op,
286 u32 package_length,
287 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Len Brown4be44fc2005-08-05 00:44:28 -0400289 union acpi_parse_object *arg;
290 union acpi_parse_object *parent;
291 union acpi_operand_object *obj_desc = NULL;
292 u32 package_list_length;
293 acpi_status status = AE_OK;
Bob Mooredefba1d2005-12-16 17:05:00 -0500294 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Bob Mooreb229cf92006-04-21 17:15:00 -0400296 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 /* Find the parent of a possibly nested package */
299
300 parent = op->common.parent;
Len Brown4be44fc2005-08-05 00:44:28 -0400301 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
302 (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 parent = parent->common.parent;
304 }
305
Bob Mooredefba1d2005-12-16 17:05:00 -0500306 /*
307 * If we are evaluating a Named package object "Name (xxxx, Package)",
308 * the package object already exists, otherwise it must be created.
309 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500311 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400312 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 *obj_desc_ptr = obj_desc;
314 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400315 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 }
317
318 obj_desc->package.node = parent->common.node;
319 }
320
321 obj_desc->package.count = package_length;
322
323 /* Count the number of items in the package list */
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 arg = op->common.value.arg;
326 arg = arg->common.next;
Bob Mooredefba1d2005-12-16 17:05:00 -0500327 for (package_list_length = 0; arg; package_list_length++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 arg = arg->common.next;
329 }
330
331 /*
332 * The package length (number of elements) will be the greater
333 * of the specified length and the length of the initializer list
334 */
335 if (package_list_length > package_length) {
336 obj_desc->package.count = package_list_length;
337 }
338
339 /*
340 * Allocate the pointer array (array of pointers to the
341 * individual objects). Add an extra pointer slot so
342 * that the list is always null terminated.
343 */
Bob Moore83135242006-10-03 00:00:00 -0400344 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
345 obj_desc->package.
346 count +
347 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 if (!obj_desc->package.elements) {
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_ut_delete_object_desc(obj_desc);
351 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
354 /*
Bob Mooredefba1d2005-12-16 17:05:00 -0500355 * Initialize all elements of the package
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 arg = op->common.value.arg;
358 arg = arg->common.next;
Bob Mooredefba1d2005-12-16 17:05:00 -0500359 for (i = 0; arg; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 /* Object (package or buffer) is already built */
363
Robert Moore44f6c012005-04-18 22:49:35 -0400364 obj_desc->package.elements[i] =
Len Brown4be44fc2005-08-05 00:44:28 -0400365 ACPI_CAST_PTR(union acpi_operand_object,
366 arg->common.node);
367 } else {
368 status = acpi_ds_build_internal_object(walk_state, arg,
369 &obj_desc->
370 package.
371 elements[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 arg = arg->common.next;
374 }
375
376 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
Len Brown4be44fc2005-08-05 00:44:28 -0400377 op->common.node = (struct acpi_namespace_node *)obj_desc;
378 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
Robert Moore44f6c012005-04-18 22:49:35 -0400381/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 *
383 * FUNCTION: acpi_ds_create_node
384 *
385 * PARAMETERS: walk_state - Current walk state
386 * Node - NS Node to be initialized
387 * Op - Parser object to be translated
388 *
389 * RETURN: Status
390 *
391 * DESCRIPTION: Create the object to be associated with a namespace node
392 *
Robert Moore44f6c012005-04-18 22:49:35 -0400393 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400396acpi_ds_create_node(struct acpi_walk_state *walk_state,
397 struct acpi_namespace_node *node,
398 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Len Brown4be44fc2005-08-05 00:44:28 -0400400 acpi_status status;
401 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Bob Mooreb229cf92006-04-21 17:15:00 -0400403 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /*
406 * Because of the execution pass through the non-control-method
407 * parts of the table, we can arrive here twice. Only init
408 * the named object node the first time through
409 */
Len Brown4be44fc2005-08-05 00:44:28 -0400410 if (acpi_ns_get_attached_object(node)) {
411 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
414 if (!op->common.value.arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /* No arguments, there is nothing to do */
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
421 /* Build an internal object for the argument(s) */
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
424 &obj_desc);
425 if (ACPI_FAILURE(status)) {
426 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
429 /* Re-type the object according to its argument */
430
Len Brown4be44fc2005-08-05 00:44:28 -0400431 node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* Attach obj to node */
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 status = acpi_ns_attach_object(node, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /* Remove local reference to the object */
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 acpi_ut_remove_reference(obj_desc);
440 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
Len Brown4be44fc2005-08-05 00:44:28 -0400443#endif /* ACPI_NO_METHOD_EXECUTION */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Robert Moore44f6c012005-04-18 22:49:35 -0400445/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *
447 * FUNCTION: acpi_ds_init_object_from_op
448 *
449 * PARAMETERS: walk_state - Current walk state
450 * Op - Parser op used to init the internal object
451 * Opcode - AML opcode associated with the object
452 * ret_obj_desc - Namespace object to be initialized
453 *
454 * RETURN: Status
455 *
456 * DESCRIPTION: Initialize a namespace object from a parser Op and its
457 * associated arguments. The namespace object is a more compact
458 * representation of the Op and its arguments.
459 *
Robert Moore44f6c012005-04-18 22:49:35 -0400460 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400463acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
464 union acpi_parse_object *op,
465 u16 opcode,
466 union acpi_operand_object **ret_obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Len Brown4be44fc2005-08-05 00:44:28 -0400468 const struct acpi_opcode_info *op_info;
469 union acpi_operand_object *obj_desc;
470 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Bob Mooreb229cf92006-04-21 17:15:00 -0400472 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 obj_desc = *ret_obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400475 op_info = acpi_ps_get_opcode_info(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (op_info->class == AML_CLASS_UNKNOWN) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 /* Unknown opcode */
479
Len Brown4be44fc2005-08-05 00:44:28 -0400480 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482
483 /* Perform per-object initialization */
484
Len Brown4be44fc2005-08-05 00:44:28 -0400485 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 case ACPI_TYPE_BUFFER:
487
488 /*
489 * Defer evaluation of Buffer term_arg operand
490 */
Len Brown4be44fc2005-08-05 00:44:28 -0400491 obj_desc->buffer.node = (struct acpi_namespace_node *)
492 walk_state->operands[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 obj_desc->buffer.aml_start = op->named.data;
494 obj_desc->buffer.aml_length = op->named.length;
495 break;
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 case ACPI_TYPE_PACKAGE:
498
499 /*
500 * Defer evaluation of Package term_arg operand
501 */
Len Brown4be44fc2005-08-05 00:44:28 -0400502 obj_desc->package.node = (struct acpi_namespace_node *)
503 walk_state->operands[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 obj_desc->package.aml_start = op->named.data;
505 obj_desc->package.aml_length = op->named.length;
506 break;
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 case ACPI_TYPE_INTEGER:
509
510 switch (op_info->type) {
511 case AML_TYPE_CONSTANT:
512 /*
513 * Resolve AML Constants here - AND ONLY HERE!
514 * All constants are integers.
Robert Moore44f6c012005-04-18 22:49:35 -0400515 * We mark the integer with a flag that indicates that it started
516 * life as a constant -- so that stores to constants will perform
517 * as expected (noop). zero_op is used as a placeholder for optional
518 * target operands.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 */
520 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
521
522 switch (opcode) {
523 case AML_ZERO_OP:
524
525 obj_desc->integer.value = 0;
526 break;
527
528 case AML_ONE_OP:
529
530 obj_desc->integer.value = 1;
531 break;
532
533 case AML_ONES_OP:
534
535 obj_desc->integer.value = ACPI_INTEGER_MAX;
536
537 /* Truncate value if we are executing from a 32-bit ACPI table */
538
539#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400540 acpi_ex_truncate_for32bit_table(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#endif
542 break;
543
544 case AML_REVISION_OP:
545
546 obj_desc->integer.value = ACPI_CA_VERSION;
547 break;
548
549 default:
550
Bob Mooreb8e4d892006-01-27 16:43:00 -0500551 ACPI_ERROR((AE_INFO,
552 "Unknown constant opcode %X",
553 opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 status = AE_AML_OPERAND_TYPE;
555 break;
556 }
557 break;
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 case AML_TYPE_LITERAL:
560
561 obj_desc->integer.value = op->common.value.integer;
Robert Moore6f42ccf2005-05-13 00:00:00 -0400562#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400563 acpi_ex_truncate_for32bit_table(obj_desc);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400564#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 break;
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500568 ACPI_ERROR((AE_INFO, "Unknown Integer type %X",
569 op_info->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 status = AE_AML_OPERAND_TYPE;
571 break;
572 }
573 break;
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 case ACPI_TYPE_STRING:
576
577 obj_desc->string.pointer = op->common.value.string;
Len Brown4be44fc2005-08-05 00:44:28 -0400578 obj_desc->string.length =
579 (u32) ACPI_STRLEN(op->common.value.string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 /*
582 * The string is contained in the ACPI table, don't ever try
583 * to delete it
584 */
585 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
586 break;
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 case ACPI_TYPE_METHOD:
589 break;
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 case ACPI_TYPE_LOCAL_REFERENCE:
592
593 switch (op_info->type) {
594 case AML_TYPE_LOCAL_VARIABLE:
595
596 /* Split the opcode into a base opcode + offset */
597
598 obj_desc->reference.opcode = AML_LOCAL_OP;
599 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
600
601#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400602 status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
603 obj_desc->
604 reference.offset,
605 walk_state,
606 (struct
607 acpi_namespace_node
608 **)&obj_desc->
609 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#endif
611 break;
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 case AML_TYPE_METHOD_ARGUMENT:
614
615 /* Split the opcode into a base opcode + offset */
616
617 obj_desc->reference.opcode = AML_ARG_OP;
618 obj_desc->reference.offset = opcode - AML_ARG_OP;
619
620#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400621 status = acpi_ds_method_data_get_node(AML_ARG_OP,
622 obj_desc->
623 reference.offset,
624 walk_state,
625 (struct
626 acpi_namespace_node
627 **)&obj_desc->
628 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#endif
630 break;
631
Len Brown4be44fc2005-08-05 00:44:28 -0400632 default: /* Other literals, etc.. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 /* Node was saved in Op */
637
638 obj_desc->reference.node = op->common.node;
639 }
640
641 obj_desc->reference.opcode = opcode;
642 break;
643 }
644 break;
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 default:
647
Bob Mooreb8e4d892006-01-27 16:43:00 -0500648 ACPI_ERROR((AE_INFO, "Unimplemented data type: %X",
649 ACPI_GET_OBJECT_TYPE(obj_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 status = AE_AML_OPERAND_TYPE;
652 break;
653 }
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}