1 /******************************************************************************
3 * Module Name: dsobject - Dispatcher object management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #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>
51 #define _COMPONENT ACPI_DISPATCHER
52 ACPI_MODULE_NAME("dsobject")
54 /* Local prototypes */
56 acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
57 union acpi_parse_object *op,
58 union acpi_operand_object **obj_desc_ptr);
60 #ifndef ACPI_NO_METHOD_EXECUTION
61 /*******************************************************************************
63 * FUNCTION: acpi_ds_build_internal_object
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
71 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
72 * Simple objects are any objects other than a package object!
74 ******************************************************************************/
77 acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
78 union acpi_parse_object *op,
79 union acpi_operand_object **obj_desc_ptr)
81 union acpi_operand_object *obj_desc;
84 ACPI_FUNCTION_TRACE(ds_build_internal_object);
87 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
89 * This is a named object reference. If this name was
90 * previously looked up in the namespace, it was stored in this op.
91 * Otherwise, go ahead and look it up now
93 if (!op->common.node) {
94 status = acpi_ns_lookup(walk_state->scope_info,
95 op->common.value.string,
98 ACPI_NS_SEARCH_PARENT |
99 ACPI_NS_DONT_OPEN_SCOPE, NULL,
100 ACPI_CAST_INDIRECT_PTR(struct
105 if (ACPI_FAILURE(status)) {
107 /* Check if we are resolving a named reference within a package */
109 if ((status == AE_NOT_FOUND)
110 && (acpi_gbl_enable_interpreter_slack)
112 ((op->common.parent->common.aml_opcode ==
114 || (op->common.parent->common.aml_opcode ==
115 AML_VAR_PACKAGE_OP))) {
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.
125 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
126 "Ignoring unresolved reference in package [%4.4s]\n",
131 return_ACPI_STATUS(AE_OK);
133 ACPI_ERROR_NAMESPACE(op->common.value.
137 return_ACPI_STATUS(status);
142 /* Create and init a new internal ACPI object */
144 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
145 (op->common.aml_opcode))->
148 return_ACPI_STATUS(AE_NO_MEMORY);
152 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
154 if (ACPI_FAILURE(status)) {
155 acpi_ut_remove_reference(obj_desc);
156 return_ACPI_STATUS(status);
159 *obj_desc_ptr = obj_desc;
160 return_ACPI_STATUS(AE_OK);
163 /*******************************************************************************
165 * FUNCTION: acpi_ds_build_internal_buffer_obj
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
174 * DESCRIPTION: Translate a parser Op package object to the equivalent
177 ******************************************************************************/
180 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
181 union acpi_parse_object *op,
183 union acpi_operand_object **obj_desc_ptr)
185 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;
190 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
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
197 obj_desc = *obj_desc_ptr;
200 /* Create a new buffer object */
202 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
203 *obj_desc_ptr = obj_desc;
205 return_ACPI_STATUS(AE_NO_MEMORY);
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.
214 arg = op->common.value.arg; /* skip first arg */
216 byte_list = arg->named.next;
218 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
220 "Expecting bytelist, got AML opcode %X in op %p",
221 byte_list->common.aml_opcode, byte_list));
223 acpi_ut_remove_reference(obj_desc);
227 byte_list_length = (u32) byte_list->common.value.integer;
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
235 obj_desc->buffer.length = buffer_length;
236 if (byte_list_length > buffer_length) {
237 obj_desc->buffer.length = byte_list_length;
240 /* Allocate the buffer */
242 if (obj_desc->buffer.length == 0) {
243 obj_desc->buffer.pointer = NULL;
244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
245 "Buffer defined with zero length in AML, creating\n"));
247 obj_desc->buffer.pointer =
248 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
249 if (!obj_desc->buffer.pointer) {
250 acpi_ut_delete_object_desc(obj_desc);
251 return_ACPI_STATUS(AE_NO_MEMORY);
254 /* Initialize buffer from the byte_list (if present) */
257 ACPI_MEMCPY(obj_desc->buffer.pointer,
258 byte_list->named.data, byte_list_length);
262 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
263 op->common.node = (struct acpi_namespace_node *)obj_desc;
264 return_ACPI_STATUS(AE_OK);
267 /*******************************************************************************
269 * FUNCTION: acpi_ds_build_internal_package_obj
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
278 * DESCRIPTION: Translate a parser Op package object to the equivalent
281 ******************************************************************************/
284 acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
285 union acpi_parse_object *op,
287 union acpi_operand_object **obj_desc_ptr)
289 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;
296 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
298 /* Find the parent of a possibly nested package */
300 parent = op->common.parent;
301 while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
302 (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
303 parent = parent->common.parent;
307 * If we are evaluating a Named package object "Name (xxxx, Package)",
308 * the package object already exists, otherwise it must be created.
310 obj_desc = *obj_desc_ptr;
312 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
313 *obj_desc_ptr = obj_desc;
315 return_ACPI_STATUS(AE_NO_MEMORY);
318 obj_desc->package.node = parent->common.node;
321 obj_desc->package.count = package_length;
323 /* Count the number of items in the package list */
325 arg = op->common.value.arg;
326 arg = arg->common.next;
327 for (package_list_length = 0; arg; package_list_length++) {
328 arg = arg->common.next;
332 * The package length (number of elements) will be the greater
333 * of the specified length and the length of the initializer list
335 if (package_list_length > package_length) {
336 obj_desc->package.count = package_list_length;
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.
344 obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
347 1) * sizeof(void *));
349 if (!obj_desc->package.elements) {
350 acpi_ut_delete_object_desc(obj_desc);
351 return_ACPI_STATUS(AE_NO_MEMORY);
355 * Initialize all elements of the package
357 arg = op->common.value.arg;
358 arg = arg->common.next;
359 for (i = 0; arg; i++) {
360 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
362 /* Object (package or buffer) is already built */
364 obj_desc->package.elements[i] =
365 ACPI_CAST_PTR(union acpi_operand_object,
368 status = acpi_ds_build_internal_object(walk_state, arg,
373 arg = arg->common.next;
376 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
377 op->common.node = (struct acpi_namespace_node *)obj_desc;
378 return_ACPI_STATUS(status);
381 /*******************************************************************************
383 * FUNCTION: acpi_ds_create_node
385 * PARAMETERS: walk_state - Current walk state
386 * Node - NS Node to be initialized
387 * Op - Parser object to be translated
391 * DESCRIPTION: Create the object to be associated with a namespace node
393 ******************************************************************************/
396 acpi_ds_create_node(struct acpi_walk_state *walk_state,
397 struct acpi_namespace_node *node,
398 union acpi_parse_object *op)
401 union acpi_operand_object *obj_desc;
403 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
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
410 if (acpi_ns_get_attached_object(node)) {
411 return_ACPI_STATUS(AE_OK);
414 if (!op->common.value.arg) {
416 /* No arguments, there is nothing to do */
418 return_ACPI_STATUS(AE_OK);
421 /* Build an internal object for the argument(s) */
423 status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
425 if (ACPI_FAILURE(status)) {
426 return_ACPI_STATUS(status);
429 /* Re-type the object according to its argument */
431 node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
433 /* Attach obj to node */
435 status = acpi_ns_attach_object(node, obj_desc, node->type);
437 /* Remove local reference to the object */
439 acpi_ut_remove_reference(obj_desc);
440 return_ACPI_STATUS(status);
443 #endif /* ACPI_NO_METHOD_EXECUTION */
445 /*******************************************************************************
447 * FUNCTION: acpi_ds_init_object_from_op
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
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.
460 ******************************************************************************/
463 acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
464 union acpi_parse_object *op,
466 union acpi_operand_object **ret_obj_desc)
468 const struct acpi_opcode_info *op_info;
469 union acpi_operand_object *obj_desc;
470 acpi_status status = AE_OK;
472 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
474 obj_desc = *ret_obj_desc;
475 op_info = acpi_ps_get_opcode_info(opcode);
476 if (op_info->class == AML_CLASS_UNKNOWN) {
480 return_ACPI_STATUS(AE_TYPE);
483 /* Perform per-object initialization */
485 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
486 case ACPI_TYPE_BUFFER:
489 * Defer evaluation of Buffer term_arg operand
491 obj_desc->buffer.node = (struct acpi_namespace_node *)
492 walk_state->operands[0];
493 obj_desc->buffer.aml_start = op->named.data;
494 obj_desc->buffer.aml_length = op->named.length;
497 case ACPI_TYPE_PACKAGE:
500 * Defer evaluation of Package term_arg operand
502 obj_desc->package.node = (struct acpi_namespace_node *)
503 walk_state->operands[0];
504 obj_desc->package.aml_start = op->named.data;
505 obj_desc->package.aml_length = op->named.length;
508 case ACPI_TYPE_INTEGER:
510 switch (op_info->type) {
511 case AML_TYPE_CONSTANT:
513 * Resolve AML Constants here - AND ONLY HERE!
514 * All constants are integers.
515 * 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
520 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
525 obj_desc->integer.value = 0;
530 obj_desc->integer.value = 1;
535 obj_desc->integer.value = ACPI_INTEGER_MAX;
537 /* Truncate value if we are executing from a 32-bit ACPI table */
539 #ifndef ACPI_NO_METHOD_EXECUTION
540 acpi_ex_truncate_for32bit_table(obj_desc);
544 case AML_REVISION_OP:
546 obj_desc->integer.value = ACPI_CA_VERSION;
552 "Unknown constant opcode %X",
554 status = AE_AML_OPERAND_TYPE;
559 case AML_TYPE_LITERAL:
561 obj_desc->integer.value = op->common.value.integer;
562 #ifndef ACPI_NO_METHOD_EXECUTION
563 acpi_ex_truncate_for32bit_table(obj_desc);
568 ACPI_ERROR((AE_INFO, "Unknown Integer type %X",
570 status = AE_AML_OPERAND_TYPE;
575 case ACPI_TYPE_STRING:
577 obj_desc->string.pointer = op->common.value.string;
578 obj_desc->string.length =
579 (u32) ACPI_STRLEN(op->common.value.string);
582 * The string is contained in the ACPI table, don't ever try
585 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
588 case ACPI_TYPE_METHOD:
591 case ACPI_TYPE_LOCAL_REFERENCE:
593 switch (op_info->type) {
594 case AML_TYPE_LOCAL_VARIABLE:
596 /* Split the opcode into a base opcode + offset */
598 obj_desc->reference.opcode = AML_LOCAL_OP;
599 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
601 #ifndef ACPI_NO_METHOD_EXECUTION
602 status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
613 case AML_TYPE_METHOD_ARGUMENT:
615 /* Split the opcode into a base opcode + offset */
617 obj_desc->reference.opcode = AML_ARG_OP;
618 obj_desc->reference.offset = opcode - AML_ARG_OP;
620 #ifndef ACPI_NO_METHOD_EXECUTION
621 status = acpi_ds_method_data_get_node(AML_ARG_OP,
632 default: /* Other literals, etc.. */
634 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
636 /* Node was saved in Op */
638 obj_desc->reference.node = op->common.node;
641 obj_desc->reference.opcode = opcode;
648 ACPI_ERROR((AE_INFO, "Unimplemented data type: %X",
649 ACPI_GET_OBJECT_TYPE(obj_desc)));
651 status = AE_AML_OPERAND_TYPE;
655 return_ACPI_STATUS(status);