blob: 905a84e4b1458ac68753055d236f8d9a43462212 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsobject - Dispatcher object management routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * 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
Len Brown4be44fc2005-08-05 00:44:28 -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 Mooredefba1d2005-12-16 17:05:00 -0500106 /* Check if we are resolving a named reference within a package */
107
108 if ((status == AE_NOT_FOUND)
109 && (acpi_gbl_enable_interpreter_slack)
110 &&
111 ((op->common.parent->common.aml_opcode ==
112 AML_PACKAGE_OP)
113 || (op->common.parent->common.aml_opcode ==
114 AML_VAR_PACKAGE_OP))) {
115 /*
116 * We didn't find the target and we are populating elements
117 * of a package - ignore if slack enabled. Some ASL code
118 * contains dangling invalid references in packages and
119 * expects that no exception will be issued. Leave the
120 * element as a null element. It cannot be used, but it
121 * can be overwritten by subsequent ASL code - this is
122 * typically the case.
123 */
124 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
125 "Ignoring unresolved reference in package [%4.4s]\n",
126 walk_state->
127 scope_info->scope.
128 node->name.ascii));
129
130 return_ACPI_STATUS(AE_OK);
131 } else {
132 ACPI_REPORT_NSERROR(op->common.value.
133 string, status);
134 }
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138 }
139 }
140
Bob Mooredefba1d2005-12-16 17:05:00 -0500141 /* Create and init a new internal ACPI object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
144 (op->common.aml_opcode))->
145 object_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150 status =
151 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
152 &obj_desc);
153 if (ACPI_FAILURE(status)) {
154 acpi_ut_remove_reference(obj_desc);
155 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158 *obj_desc_ptr = obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400159 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Robert Moore44f6c012005-04-18 22:49:35 -0400162/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 *
164 * FUNCTION: acpi_ds_build_internal_buffer_obj
165 *
166 * PARAMETERS: walk_state - Current walk state
167 * Op - Parser object to be translated
168 * buffer_length - Length of the buffer
169 * obj_desc_ptr - Where the ACPI internal object is returned
170 *
171 * RETURN: Status
172 *
173 * DESCRIPTION: Translate a parser Op package object to the equivalent
174 * namespace object
175 *
Robert Moore44f6c012005-04-18 22:49:35 -0400176 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400179acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
180 union acpi_parse_object *op,
181 u32 buffer_length,
182 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Len Brown4be44fc2005-08-05 00:44:28 -0400184 union acpi_parse_object *arg;
185 union acpi_operand_object *obj_desc;
186 union acpi_parse_object *byte_list;
187 u32 byte_list_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 ACPI_FUNCTION_TRACE("ds_build_internal_buffer_obj");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Mooredefba1d2005-12-16 17:05:00 -0500191 /*
192 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
193 * The buffer object already exists (from the NS node), otherwise it must
194 * be created.
195 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500197 if (!obj_desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /* Create a new buffer object */
199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 *obj_desc_ptr = obj_desc;
202 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205 }
206
207 /*
208 * Second arg is the buffer data (optional) byte_list can be either
209 * individual bytes or a string initializer. In either case, a
210 * byte_list appears in the AML.
211 */
Len Brown4be44fc2005-08-05 00:44:28 -0400212 arg = op->common.value.arg; /* skip first arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 byte_list = arg->named.next;
215 if (byte_list) {
216 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400217 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
218 "Expecting bytelist, got AML opcode %X in op %p\n",
219 byte_list->common.aml_opcode,
220 byte_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Len Brown4be44fc2005-08-05 00:44:28 -0400222 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return (AE_TYPE);
224 }
225
226 byte_list_length = (u32) byte_list->common.value.integer;
227 }
228
229 /*
230 * The buffer length (number of bytes) will be the larger of:
231 * 1) The specified buffer length and
232 * 2) The length of the initializer byte list
233 */
234 obj_desc->buffer.length = buffer_length;
235 if (byte_list_length > buffer_length) {
236 obj_desc->buffer.length = byte_list_length;
237 }
238
239 /* Allocate the buffer */
240
241 if (obj_desc->buffer.length == 0) {
242 obj_desc->buffer.pointer = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400243 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
244 "Buffer defined with zero length in AML, creating\n"));
245 } else {
246 obj_desc->buffer.pointer =
247 ACPI_MEM_CALLOCATE(obj_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (!obj_desc->buffer.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400249 acpi_ut_delete_object_desc(obj_desc);
250 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252
253 /* Initialize buffer from the byte_list (if present) */
254
255 if (byte_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 ACPI_MEMCPY(obj_desc->buffer.pointer,
257 byte_list->named.data, byte_list_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259 }
260
261 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
Len Brown4be44fc2005-08-05 00:44:28 -0400262 op->common.node = (struct acpi_namespace_node *)obj_desc;
263 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
Robert Moore44f6c012005-04-18 22:49:35 -0400266/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 *
268 * FUNCTION: acpi_ds_build_internal_package_obj
269 *
270 * PARAMETERS: walk_state - Current walk state
271 * Op - Parser object to be translated
272 * package_length - Number of elements in the package
273 * obj_desc_ptr - Where the ACPI internal object is returned
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: Translate a parser Op package object to the equivalent
278 * namespace object
279 *
Robert Moore44f6c012005-04-18 22:49:35 -0400280 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400283acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
284 union acpi_parse_object *op,
285 u32 package_length,
286 union acpi_operand_object **obj_desc_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Len Brown4be44fc2005-08-05 00:44:28 -0400288 union acpi_parse_object *arg;
289 union acpi_parse_object *parent;
290 union acpi_operand_object *obj_desc = NULL;
291 u32 package_list_length;
292 acpi_status status = AE_OK;
Bob Mooredefba1d2005-12-16 17:05:00 -0500293 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Len Brown4be44fc2005-08-05 00:44:28 -0400295 ACPI_FUNCTION_TRACE("ds_build_internal_package_obj");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* Find the parent of a possibly nested package */
298
299 parent = op->common.parent;
Len Brown4be44fc2005-08-05 00:44:28 -0400300 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
301 (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 parent = parent->common.parent;
303 }
304
Bob Mooredefba1d2005-12-16 17:05:00 -0500305 /*
306 * If we are evaluating a Named package object "Name (xxxx, Package)",
307 * the package object already exists, otherwise it must be created.
308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 obj_desc = *obj_desc_ptr;
Bob Mooredefba1d2005-12-16 17:05:00 -0500310 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400311 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 *obj_desc_ptr = obj_desc;
313 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400314 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
317 obj_desc->package.node = parent->common.node;
318 }
319
320 obj_desc->package.count = package_length;
321
322 /* Count the number of items in the package list */
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 arg = op->common.value.arg;
325 arg = arg->common.next;
Bob Mooredefba1d2005-12-16 17:05:00 -0500326 for (package_list_length = 0; arg; package_list_length++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 arg = arg->common.next;
328 }
329
330 /*
331 * The package length (number of elements) will be the greater
332 * of the specified length and the length of the initializer list
333 */
334 if (package_list_length > package_length) {
335 obj_desc->package.count = package_list_length;
336 }
337
338 /*
339 * Allocate the pointer array (array of pointers to the
340 * individual objects). Add an extra pointer slot so
341 * that the list is always null terminated.
342 */
Len Brown4be44fc2005-08-05 00:44:28 -0400343 obj_desc->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) obj_desc->
344 package.count +
345 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (!obj_desc->package.elements) {
Len Brown4be44fc2005-08-05 00:44:28 -0400348 acpi_ut_delete_object_desc(obj_desc);
349 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 /*
Bob Mooredefba1d2005-12-16 17:05:00 -0500353 * Initialize all elements of the package
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 arg = op->common.value.arg;
356 arg = arg->common.next;
Bob Mooredefba1d2005-12-16 17:05:00 -0500357 for (i = 0; arg; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
359 /* Object (package or buffer) is already built */
360
Robert Moore44f6c012005-04-18 22:49:35 -0400361 obj_desc->package.elements[i] =
Len Brown4be44fc2005-08-05 00:44:28 -0400362 ACPI_CAST_PTR(union acpi_operand_object,
363 arg->common.node);
364 } else {
365 status = acpi_ds_build_internal_object(walk_state, arg,
366 &obj_desc->
367 package.
368 elements[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 arg = arg->common.next;
371 }
372
373 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
Len Brown4be44fc2005-08-05 00:44:28 -0400374 op->common.node = (struct acpi_namespace_node *)obj_desc;
375 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Robert Moore44f6c012005-04-18 22:49:35 -0400378/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 *
380 * FUNCTION: acpi_ds_create_node
381 *
382 * PARAMETERS: walk_state - Current walk state
383 * Node - NS Node to be initialized
384 * Op - Parser object to be translated
385 *
386 * RETURN: Status
387 *
388 * DESCRIPTION: Create the object to be associated with a namespace node
389 *
Robert Moore44f6c012005-04-18 22:49:35 -0400390 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400393acpi_ds_create_node(struct acpi_walk_state *walk_state,
394 struct acpi_namespace_node *node,
395 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Len Brown4be44fc2005-08-05 00:44:28 -0400397 acpi_status status;
398 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_FUNCTION_TRACE_PTR("ds_create_node", op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 /*
403 * Because of the execution pass through the non-control-method
404 * parts of the table, we can arrive here twice. Only init
405 * the named object node the first time through
406 */
Len Brown4be44fc2005-08-05 00:44:28 -0400407 if (acpi_ns_get_attached_object(node)) {
408 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410
411 if (!op->common.value.arg) {
412 /* No arguments, there is nothing to do */
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
417 /* Build an internal object for the argument(s) */
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
420 &obj_desc);
421 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
425 /* Re-type the object according to its argument */
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 /* Attach obj to node */
430
Len Brown4be44fc2005-08-05 00:44:28 -0400431 status = acpi_ns_attach_object(node, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* Remove local reference to the object */
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 acpi_ut_remove_reference(obj_desc);
436 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439#endif /* ACPI_NO_METHOD_EXECUTION */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Robert Moore44f6c012005-04-18 22:49:35 -0400441/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 * FUNCTION: acpi_ds_init_object_from_op
444 *
445 * PARAMETERS: walk_state - Current walk state
446 * Op - Parser op used to init the internal object
447 * Opcode - AML opcode associated with the object
448 * ret_obj_desc - Namespace object to be initialized
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Initialize a namespace object from a parser Op and its
453 * associated arguments. The namespace object is a more compact
454 * representation of the Op and its arguments.
455 *
Robert Moore44f6c012005-04-18 22:49:35 -0400456 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400459acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
460 union acpi_parse_object *op,
461 u16 opcode,
462 union acpi_operand_object **ret_obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Len Brown4be44fc2005-08-05 00:44:28 -0400464 const struct acpi_opcode_info *op_info;
465 union acpi_operand_object *obj_desc;
466 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Len Brown4be44fc2005-08-05 00:44:28 -0400468 ACPI_FUNCTION_TRACE("ds_init_object_from_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 obj_desc = *ret_obj_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400471 op_info = acpi_ps_get_opcode_info(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 if (op_info->class == AML_CLASS_UNKNOWN) {
473 /* Unknown opcode */
474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
478 /* Perform per-object initialization */
479
Len Brown4be44fc2005-08-05 00:44:28 -0400480 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 case ACPI_TYPE_BUFFER:
482
483 /*
484 * Defer evaluation of Buffer term_arg operand
485 */
Len Brown4be44fc2005-08-05 00:44:28 -0400486 obj_desc->buffer.node = (struct acpi_namespace_node *)
487 walk_state->operands[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 obj_desc->buffer.aml_start = op->named.data;
489 obj_desc->buffer.aml_length = op->named.length;
490 break;
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 case ACPI_TYPE_PACKAGE:
493
494 /*
495 * Defer evaluation of Package term_arg operand
496 */
Len Brown4be44fc2005-08-05 00:44:28 -0400497 obj_desc->package.node = (struct acpi_namespace_node *)
498 walk_state->operands[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 obj_desc->package.aml_start = op->named.data;
500 obj_desc->package.aml_length = op->named.length;
501 break;
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 case ACPI_TYPE_INTEGER:
504
505 switch (op_info->type) {
506 case AML_TYPE_CONSTANT:
507 /*
508 * Resolve AML Constants here - AND ONLY HERE!
509 * All constants are integers.
Robert Moore44f6c012005-04-18 22:49:35 -0400510 * We mark the integer with a flag that indicates that it started
511 * life as a constant -- so that stores to constants will perform
512 * as expected (noop). zero_op is used as a placeholder for optional
513 * target operands.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 */
515 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
516
517 switch (opcode) {
518 case AML_ZERO_OP:
519
520 obj_desc->integer.value = 0;
521 break;
522
523 case AML_ONE_OP:
524
525 obj_desc->integer.value = 1;
526 break;
527
528 case AML_ONES_OP:
529
530 obj_desc->integer.value = ACPI_INTEGER_MAX;
531
532 /* Truncate value if we are executing from a 32-bit ACPI table */
533
534#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400535 acpi_ex_truncate_for32bit_table(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#endif
537 break;
538
539 case AML_REVISION_OP:
540
541 obj_desc->integer.value = ACPI_CA_VERSION;
542 break;
543
544 default:
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
547 "Unknown constant opcode %X\n",
548 opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 status = AE_AML_OPERAND_TYPE;
550 break;
551 }
552 break;
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 case AML_TYPE_LITERAL:
555
556 obj_desc->integer.value = op->common.value.integer;
Robert Moore6f42ccf2005-05-13 00:00:00 -0400557#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400558 acpi_ex_truncate_for32bit_table(obj_desc);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 break;
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400563 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
564 "Unknown Integer type %X\n",
565 op_info->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 status = AE_AML_OPERAND_TYPE;
567 break;
568 }
569 break;
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 case ACPI_TYPE_STRING:
572
573 obj_desc->string.pointer = op->common.value.string;
Len Brown4be44fc2005-08-05 00:44:28 -0400574 obj_desc->string.length =
575 (u32) ACPI_STRLEN(op->common.value.string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 /*
578 * The string is contained in the ACPI table, don't ever try
579 * to delete it
580 */
581 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
582 break;
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 case ACPI_TYPE_METHOD:
585 break;
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 case ACPI_TYPE_LOCAL_REFERENCE:
588
589 switch (op_info->type) {
590 case AML_TYPE_LOCAL_VARIABLE:
591
592 /* Split the opcode into a base opcode + offset */
593
594 obj_desc->reference.opcode = AML_LOCAL_OP;
595 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
596
597#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400598 status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
599 obj_desc->
600 reference.offset,
601 walk_state,
602 (struct
603 acpi_namespace_node
604 **)&obj_desc->
605 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#endif
607 break;
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 case AML_TYPE_METHOD_ARGUMENT:
610
611 /* Split the opcode into a base opcode + offset */
612
613 obj_desc->reference.opcode = AML_ARG_OP;
614 obj_desc->reference.offset = opcode - AML_ARG_OP;
615
616#ifndef ACPI_NO_METHOD_EXECUTION
Len Brown4be44fc2005-08-05 00:44:28 -0400617 status = acpi_ds_method_data_get_node(AML_ARG_OP,
618 obj_desc->
619 reference.offset,
620 walk_state,
621 (struct
622 acpi_namespace_node
623 **)&obj_desc->
624 reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#endif
626 break;
627
Len Brown4be44fc2005-08-05 00:44:28 -0400628 default: /* Other literals, etc.. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
631 /* Node was saved in Op */
632
633 obj_desc->reference.node = op->common.node;
634 }
635
636 obj_desc->reference.opcode = opcode;
637 break;
638 }
639 break;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 default:
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
644 "Unimplemented data type: %X\n",
645 ACPI_GET_OBJECT_TYPE(obj_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 status = AE_AML_OPERAND_TYPE;
648 break;
649 }
650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}