1 /******************************************************************************
3 * Module Name: dsobject - Dispatcher object management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, Intel Corp.
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>
52 #define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME("dsobject")
55 /* Local prototypes */
57 acpi_ds_build_internal_object(struct acpi_walk_state
*walk_state
,
58 union acpi_parse_object
*op
,
59 union acpi_operand_object
**obj_desc_ptr
);
61 #ifndef ACPI_NO_METHOD_EXECUTION
62 /*******************************************************************************
64 * FUNCTION: acpi_ds_build_internal_object
66 * PARAMETERS: walk_state - Current walk state
67 * Op - Parser object to be translated
68 * obj_desc_ptr - Where the ACPI internal object is returned
72 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
73 * Simple objects are any objects other than a package object!
75 ******************************************************************************/
78 acpi_ds_build_internal_object(struct acpi_walk_state
*walk_state
,
79 union acpi_parse_object
*op
,
80 union acpi_operand_object
**obj_desc_ptr
)
82 union acpi_operand_object
*obj_desc
;
85 ACPI_FUNCTION_TRACE(ds_build_internal_object
);
88 if (op
->common
.aml_opcode
== AML_INT_NAMEPATH_OP
) {
90 * This is a named object reference. If this name was
91 * previously looked up in the namespace, it was stored in this op.
92 * Otherwise, go ahead and look it up now
94 if (!op
->common
.node
) {
95 status
= acpi_ns_lookup(walk_state
->scope_info
,
96 op
->common
.value
.string
,
99 ACPI_NS_SEARCH_PARENT
|
100 ACPI_NS_DONT_OPEN_SCOPE
, NULL
,
101 ACPI_CAST_INDIRECT_PTR(struct
106 if (ACPI_FAILURE(status
)) {
108 /* Check if we are resolving a named reference within a package */
110 if ((status
== AE_NOT_FOUND
)
111 && (acpi_gbl_enable_interpreter_slack
)
113 ((op
->common
.parent
->common
.aml_opcode
==
115 || (op
->common
.parent
->common
.aml_opcode
==
116 AML_VAR_PACKAGE_OP
))) {
118 * We didn't find the target and we are populating elements
119 * of a package - ignore if slack enabled. Some ASL code
120 * contains dangling invalid references in packages and
121 * expects that no exception will be issued. Leave the
122 * element as a null element. It cannot be used, but it
123 * can be overwritten by subsequent ASL code - this is
124 * typically the case.
126 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
127 "Ignoring unresolved reference in package [%4.4s]\n",
132 return_ACPI_STATUS(AE_OK
);
134 ACPI_ERROR_NAMESPACE(op
->common
.value
.
138 return_ACPI_STATUS(status
);
142 /* Special object resolution for elements of a package */
144 if ((op
->common
.parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
145 (op
->common
.parent
->common
.aml_opcode
==
146 AML_VAR_PACKAGE_OP
)) {
148 * Attempt to resolve the node to a value before we insert it into
149 * the package. If this is a reference to a common data type,
150 * resolve it immediately. According to the ACPI spec, package
151 * elements can only be "data objects" or method references.
152 * Attempt to resolve to an Integer, Buffer, String or Package.
153 * If cannot, return the named reference (for things like Devices,
154 * Methods, etc.) Buffer Fields and Fields will resolve to simple
155 * objects (int/buf/str/pkg).
157 * NOTE: References to things like Devices, Methods, Mutexes, etc.
158 * will remain as named references. This behavior is not described
159 * in the ACPI spec, but it appears to be an oversight.
162 ACPI_CAST_PTR(union acpi_operand_object
,
166 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
171 if (ACPI_FAILURE(status
)) {
172 return_ACPI_STATUS(status
);
175 switch (op
->common
.node
->type
) {
177 * For these types, we need the actual node, not the subobject.
178 * However, the subobject did not get an extra reference count above.
180 * TBD: should ex_resolve_node_to_value be changed to fix this?
182 case ACPI_TYPE_DEVICE
:
183 case ACPI_TYPE_THERMAL
:
185 acpi_ut_add_reference(op
->common
.node
->object
);
187 /*lint -fallthrough */
189 * For these types, we need the actual node, not the subobject.
190 * The subobject got an extra reference count in ex_resolve_node_to_value.
192 case ACPI_TYPE_MUTEX
:
193 case ACPI_TYPE_METHOD
:
194 case ACPI_TYPE_POWER
:
195 case ACPI_TYPE_PROCESSOR
:
196 case ACPI_TYPE_EVENT
:
197 case ACPI_TYPE_REGION
:
199 /* We will create a reference object for these types below */
204 * All other types - the node was resolved to an actual
205 * object, we are done.
212 /* Create and init a new internal ACPI object */
214 obj_desc
= acpi_ut_create_internal_object((acpi_ps_get_opcode_info
215 (op
->common
.aml_opcode
))->
218 return_ACPI_STATUS(AE_NO_MEMORY
);
222 acpi_ds_init_object_from_op(walk_state
, op
, op
->common
.aml_opcode
,
224 if (ACPI_FAILURE(status
)) {
225 acpi_ut_remove_reference(obj_desc
);
226 return_ACPI_STATUS(status
);
230 *obj_desc_ptr
= obj_desc
;
231 return_ACPI_STATUS(status
);
234 /*******************************************************************************
236 * FUNCTION: acpi_ds_build_internal_buffer_obj
238 * PARAMETERS: walk_state - Current walk state
239 * Op - Parser object to be translated
240 * buffer_length - Length of the buffer
241 * obj_desc_ptr - Where the ACPI internal object is returned
245 * DESCRIPTION: Translate a parser Op package object to the equivalent
248 ******************************************************************************/
251 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state
*walk_state
,
252 union acpi_parse_object
*op
,
254 union acpi_operand_object
**obj_desc_ptr
)
256 union acpi_parse_object
*arg
;
257 union acpi_operand_object
*obj_desc
;
258 union acpi_parse_object
*byte_list
;
259 u32 byte_list_length
= 0;
261 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj
);
264 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
265 * The buffer object already exists (from the NS node), otherwise it must
268 obj_desc
= *obj_desc_ptr
;
271 /* Create a new buffer object */
273 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_BUFFER
);
274 *obj_desc_ptr
= obj_desc
;
276 return_ACPI_STATUS(AE_NO_MEMORY
);
281 * Second arg is the buffer data (optional) byte_list can be either
282 * individual bytes or a string initializer. In either case, a
283 * byte_list appears in the AML.
285 arg
= op
->common
.value
.arg
; /* skip first arg */
287 byte_list
= arg
->named
.next
;
289 if (byte_list
->common
.aml_opcode
!= AML_INT_BYTELIST_OP
) {
291 "Expecting bytelist, got AML opcode %X in op %p",
292 byte_list
->common
.aml_opcode
, byte_list
));
294 acpi_ut_remove_reference(obj_desc
);
298 byte_list_length
= (u32
) byte_list
->common
.value
.integer
;
302 * The buffer length (number of bytes) will be the larger of:
303 * 1) The specified buffer length and
304 * 2) The length of the initializer byte list
306 obj_desc
->buffer
.length
= buffer_length
;
307 if (byte_list_length
> buffer_length
) {
308 obj_desc
->buffer
.length
= byte_list_length
;
311 /* Allocate the buffer */
313 if (obj_desc
->buffer
.length
== 0) {
314 obj_desc
->buffer
.pointer
= NULL
;
315 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
316 "Buffer defined with zero length in AML, creating\n"));
318 obj_desc
->buffer
.pointer
=
319 ACPI_ALLOCATE_ZEROED(obj_desc
->buffer
.length
);
320 if (!obj_desc
->buffer
.pointer
) {
321 acpi_ut_delete_object_desc(obj_desc
);
322 return_ACPI_STATUS(AE_NO_MEMORY
);
325 /* Initialize buffer from the byte_list (if present) */
328 ACPI_MEMCPY(obj_desc
->buffer
.pointer
,
329 byte_list
->named
.data
, byte_list_length
);
333 obj_desc
->buffer
.flags
|= AOPOBJ_DATA_VALID
;
334 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
335 return_ACPI_STATUS(AE_OK
);
338 /*******************************************************************************
340 * FUNCTION: acpi_ds_build_internal_package_obj
342 * PARAMETERS: walk_state - Current walk state
343 * Op - Parser object to be translated
344 * element_count - Number of elements in the package - this is
345 * the num_elements argument to Package()
346 * obj_desc_ptr - Where the ACPI internal object is returned
350 * DESCRIPTION: Translate a parser Op package object to the equivalent
353 * NOTE: The number of elements in the package will be always be the num_elements
354 * count, regardless of the number of elements in the package list. If
355 * num_elements is smaller, only that many package list elements are used.
356 * if num_elements is larger, the Package object is padded out with
357 * objects of type Uninitialized (as per ACPI spec.)
359 * Even though the ASL compilers do not allow num_elements to be smaller
360 * than the Package list length (for the fixed length package opcode), some
361 * BIOS code modifies the AML on the fly to adjust the num_elements, and
362 * this code compensates for that. This also provides compatibility with
363 * other AML interpreters.
365 ******************************************************************************/
368 acpi_ds_build_internal_package_obj(struct acpi_walk_state
*walk_state
,
369 union acpi_parse_object
*op
,
371 union acpi_operand_object
**obj_desc_ptr
)
373 union acpi_parse_object
*arg
;
374 union acpi_parse_object
*parent
;
375 union acpi_operand_object
*obj_desc
= NULL
;
376 acpi_status status
= AE_OK
;
381 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj
);
383 /* Find the parent of a possibly nested package */
385 parent
= op
->common
.parent
;
386 while ((parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
387 (parent
->common
.aml_opcode
== AML_VAR_PACKAGE_OP
)) {
388 parent
= parent
->common
.parent
;
392 * If we are evaluating a Named package object "Name (xxxx, Package)",
393 * the package object already exists, otherwise it must be created.
395 obj_desc
= *obj_desc_ptr
;
397 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE
);
398 *obj_desc_ptr
= obj_desc
;
400 return_ACPI_STATUS(AE_NO_MEMORY
);
403 obj_desc
->package
.node
= parent
->common
.node
;
407 * Allocate the element array (array of pointers to the individual
408 * objects) based on the num_elements parameter. Add an extra pointer slot
409 * so that the list is always null terminated.
411 obj_desc
->package
.elements
= ACPI_ALLOCATE_ZEROED(((acpi_size
)
413 1) * sizeof(void *));
415 if (!obj_desc
->package
.elements
) {
416 acpi_ut_delete_object_desc(obj_desc
);
417 return_ACPI_STATUS(AE_NO_MEMORY
);
420 obj_desc
->package
.count
= element_count
;
423 * Initialize the elements of the package, up to the num_elements count.
424 * Package is automatically padded with uninitialized (NULL) elements
425 * if num_elements is greater than the package list length. Likewise,
426 * Package is truncated if num_elements is less than the list length.
428 arg
= op
->common
.value
.arg
;
429 arg
= arg
->common
.next
;
430 for (i
= 0; arg
&& (i
< element_count
); i
++) {
431 if (arg
->common
.aml_opcode
== AML_INT_RETURN_VALUE_OP
) {
432 if (arg
->common
.node
->type
== ACPI_TYPE_METHOD
) {
434 * A method reference "looks" to the parser to be a method
435 * invocation, so we special case it here
437 arg
->common
.aml_opcode
= AML_INT_NAMEPATH_OP
;
439 acpi_ds_build_internal_object(walk_state
,
445 /* This package element is already built, just get it */
447 obj_desc
->package
.elements
[i
] =
448 ACPI_CAST_PTR(union acpi_operand_object
,
452 status
= acpi_ds_build_internal_object(walk_state
, arg
,
460 /* Existing package, get existing reference count */
463 (*obj_desc_ptr
)->common
.reference_count
;
464 if (reference_count
> 1) {
466 /* Make new element ref count match original ref count */
468 for (index
= 0; index
< (reference_count
- 1);
470 acpi_ut_add_reference((obj_desc
->
477 arg
= arg
->common
.next
;
480 /* Check for match between num_elements and actual length of package_list */
484 * num_elements was exhausted, but there are remaining elements in the
487 * Note: technically, this is an error, from ACPI spec: "It is an error
488 * for NumElements to be less than the number of elements in the
489 * PackageList". However, for now, we just print an error message and
490 * no exception is returned.
494 /* Find out how many elements there really are */
497 arg
= arg
->common
.next
;
500 ACPI_WARNING((AE_INFO
,
501 "Package List length (%X) larger than NumElements count (%X), truncated\n",
503 } else if (i
< element_count
) {
505 * Arg list (elements) was exhausted, but we did not reach num_elements count.
506 * Note: this is not an error, the package is padded out with NULLs.
508 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
509 "Package List length (%X) smaller than NumElements count (%X), padded with null elements\n",
513 obj_desc
->package
.flags
|= AOPOBJ_DATA_VALID
;
514 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
515 return_ACPI_STATUS(status
);
518 /*******************************************************************************
520 * FUNCTION: acpi_ds_create_node
522 * PARAMETERS: walk_state - Current walk state
523 * Node - NS Node to be initialized
524 * Op - Parser object to be translated
528 * DESCRIPTION: Create the object to be associated with a namespace node
530 ******************************************************************************/
533 acpi_ds_create_node(struct acpi_walk_state
*walk_state
,
534 struct acpi_namespace_node
*node
,
535 union acpi_parse_object
*op
)
538 union acpi_operand_object
*obj_desc
;
540 ACPI_FUNCTION_TRACE_PTR(ds_create_node
, op
);
543 * Because of the execution pass through the non-control-method
544 * parts of the table, we can arrive here twice. Only init
545 * the named object node the first time through
547 if (acpi_ns_get_attached_object(node
)) {
548 return_ACPI_STATUS(AE_OK
);
551 if (!op
->common
.value
.arg
) {
553 /* No arguments, there is nothing to do */
555 return_ACPI_STATUS(AE_OK
);
558 /* Build an internal object for the argument(s) */
560 status
= acpi_ds_build_internal_object(walk_state
, op
->common
.value
.arg
,
562 if (ACPI_FAILURE(status
)) {
563 return_ACPI_STATUS(status
);
566 /* Re-type the object according to its argument */
568 node
->type
= obj_desc
->common
.type
;
570 /* Attach obj to node */
572 status
= acpi_ns_attach_object(node
, obj_desc
, node
->type
);
574 /* Remove local reference to the object */
576 acpi_ut_remove_reference(obj_desc
);
577 return_ACPI_STATUS(status
);
580 #endif /* ACPI_NO_METHOD_EXECUTION */
582 /*******************************************************************************
584 * FUNCTION: acpi_ds_init_object_from_op
586 * PARAMETERS: walk_state - Current walk state
587 * Op - Parser op used to init the internal object
588 * Opcode - AML opcode associated with the object
589 * ret_obj_desc - Namespace object to be initialized
593 * DESCRIPTION: Initialize a namespace object from a parser Op and its
594 * associated arguments. The namespace object is a more compact
595 * representation of the Op and its arguments.
597 ******************************************************************************/
600 acpi_ds_init_object_from_op(struct acpi_walk_state
*walk_state
,
601 union acpi_parse_object
*op
,
603 union acpi_operand_object
**ret_obj_desc
)
605 const struct acpi_opcode_info
*op_info
;
606 union acpi_operand_object
*obj_desc
;
607 acpi_status status
= AE_OK
;
609 ACPI_FUNCTION_TRACE(ds_init_object_from_op
);
611 obj_desc
= *ret_obj_desc
;
612 op_info
= acpi_ps_get_opcode_info(opcode
);
613 if (op_info
->class == AML_CLASS_UNKNOWN
) {
617 return_ACPI_STATUS(AE_TYPE
);
620 /* Perform per-object initialization */
622 switch (obj_desc
->common
.type
) {
623 case ACPI_TYPE_BUFFER
:
626 * Defer evaluation of Buffer term_arg operand
628 obj_desc
->buffer
.node
=
629 ACPI_CAST_PTR(struct acpi_namespace_node
,
630 walk_state
->operands
[0]);
631 obj_desc
->buffer
.aml_start
= op
->named
.data
;
632 obj_desc
->buffer
.aml_length
= op
->named
.length
;
635 case ACPI_TYPE_PACKAGE
:
638 * Defer evaluation of Package term_arg operand
640 obj_desc
->package
.node
=
641 ACPI_CAST_PTR(struct acpi_namespace_node
,
642 walk_state
->operands
[0]);
643 obj_desc
->package
.aml_start
= op
->named
.data
;
644 obj_desc
->package
.aml_length
= op
->named
.length
;
647 case ACPI_TYPE_INTEGER
:
649 switch (op_info
->type
) {
650 case AML_TYPE_CONSTANT
:
652 * Resolve AML Constants here - AND ONLY HERE!
653 * All constants are integers.
654 * We mark the integer with a flag that indicates that it started
655 * life as a constant -- so that stores to constants will perform
656 * as expected (noop). zero_op is used as a placeholder for optional
659 obj_desc
->common
.flags
= AOPOBJ_AML_CONSTANT
;
664 obj_desc
->integer
.value
= 0;
669 obj_desc
->integer
.value
= 1;
674 obj_desc
->integer
.value
= ACPI_INTEGER_MAX
;
676 /* Truncate value if we are executing from a 32-bit ACPI table */
678 #ifndef ACPI_NO_METHOD_EXECUTION
679 acpi_ex_truncate_for32bit_table(obj_desc
);
683 case AML_REVISION_OP
:
685 obj_desc
->integer
.value
= ACPI_CA_VERSION
;
691 "Unknown constant opcode %X",
693 status
= AE_AML_OPERAND_TYPE
;
698 case AML_TYPE_LITERAL
:
700 obj_desc
->integer
.value
= op
->common
.value
.integer
;
701 #ifndef ACPI_NO_METHOD_EXECUTION
702 acpi_ex_truncate_for32bit_table(obj_desc
);
707 ACPI_ERROR((AE_INFO
, "Unknown Integer type %X",
709 status
= AE_AML_OPERAND_TYPE
;
714 case ACPI_TYPE_STRING
:
716 obj_desc
->string
.pointer
= op
->common
.value
.string
;
717 obj_desc
->string
.length
=
718 (u32
) ACPI_STRLEN(op
->common
.value
.string
);
721 * The string is contained in the ACPI table, don't ever try
724 obj_desc
->common
.flags
|= AOPOBJ_STATIC_POINTER
;
727 case ACPI_TYPE_METHOD
:
730 case ACPI_TYPE_LOCAL_REFERENCE
:
732 switch (op_info
->type
) {
733 case AML_TYPE_LOCAL_VARIABLE
:
735 /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
737 obj_desc
->reference
.value
=
738 ((u32
)opcode
) - AML_LOCAL_OP
;
739 obj_desc
->reference
.class = ACPI_REFCLASS_LOCAL
;
741 #ifndef ACPI_NO_METHOD_EXECUTION
743 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL
,
746 ACPI_CAST_INDIRECT_PTR
749 &obj_desc
->reference
.
754 case AML_TYPE_METHOD_ARGUMENT
:
756 /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
758 obj_desc
->reference
.value
= ((u32
)opcode
) - AML_ARG_OP
;
759 obj_desc
->reference
.class = ACPI_REFCLASS_ARG
;
761 #ifndef ACPI_NO_METHOD_EXECUTION
762 status
= acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG
,
766 ACPI_CAST_INDIRECT_PTR
775 default: /* Object name or Debug object */
777 switch (op
->common
.aml_opcode
) {
778 case AML_INT_NAMEPATH_OP
:
780 /* Node was saved in Op */
782 obj_desc
->reference
.node
= op
->common
.node
;
783 obj_desc
->reference
.object
=
784 op
->common
.node
->object
;
785 obj_desc
->reference
.class = ACPI_REFCLASS_NAME
;
790 obj_desc
->reference
.class = ACPI_REFCLASS_DEBUG
;
796 "Unimplemented reference type for AML opcode: %4.4X",
798 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
806 ACPI_ERROR((AE_INFO
, "Unimplemented data type: %X",
807 obj_desc
->common
.type
));
809 status
= AE_AML_OPERAND_TYPE
;
813 return_ACPI_STATUS(status
);