1 /******************************************************************************
3 * Module Name: dsobject - Dispatcher object management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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
;
84 acpi_object_type type
;
86 ACPI_FUNCTION_TRACE(ds_build_internal_object
);
89 if (op
->common
.aml_opcode
== AML_INT_NAMEPATH_OP
) {
91 * This is a named object reference. If this name was
92 * previously looked up in the namespace, it was stored in this op.
93 * Otherwise, go ahead and look it up now
95 if (!op
->common
.node
) {
96 status
= acpi_ns_lookup(walk_state
->scope_info
,
97 op
->common
.value
.string
,
100 ACPI_NS_SEARCH_PARENT
|
101 ACPI_NS_DONT_OPEN_SCOPE
, NULL
,
102 ACPI_CAST_INDIRECT_PTR(struct
107 if (ACPI_FAILURE(status
)) {
109 /* Check if we are resolving a named reference within a package */
111 if ((status
== AE_NOT_FOUND
)
112 && (acpi_gbl_enable_interpreter_slack
)
114 ((op
->common
.parent
->common
.aml_opcode
==
116 || (op
->common
.parent
->common
.aml_opcode
==
117 AML_VAR_PACKAGE_OP
))) {
119 * We didn't find the target and we are populating elements
120 * of a package - ignore if slack enabled. Some ASL code
121 * contains dangling invalid references in packages and
122 * expects that no exception will be issued. Leave the
123 * element as a null element. It cannot be used, but it
124 * can be overwritten by subsequent ASL code - this is
125 * typically the case.
127 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
128 "Ignoring unresolved reference in package [%4.4s]\n",
133 return_ACPI_STATUS(AE_OK
);
135 ACPI_ERROR_NAMESPACE(op
->common
.value
.
139 return_ACPI_STATUS(status
);
143 /* Special object resolution for elements of a package */
145 if ((op
->common
.parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
146 (op
->common
.parent
->common
.aml_opcode
==
147 AML_VAR_PACKAGE_OP
)) {
149 * Attempt to resolve the node to a value before we insert it into
150 * the package. If this is a reference to a common data type,
151 * resolve it immediately. According to the ACPI spec, package
152 * elements can only be "data objects" or method references.
153 * Attempt to resolve to an Integer, Buffer, String or Package.
154 * If cannot, return the named reference (for things like Devices,
155 * Methods, etc.) Buffer Fields and Fields will resolve to simple
156 * objects (int/buf/str/pkg).
158 * NOTE: References to things like Devices, Methods, Mutexes, etc.
159 * will remain as named references. This behavior is not described
160 * in the ACPI spec, but it appears to be an oversight.
163 ACPI_CAST_PTR(union acpi_operand_object
,
167 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
172 if (ACPI_FAILURE(status
)) {
173 return_ACPI_STATUS(status
);
177 * Special handling for Alias objects. We need to setup the type
178 * and the Op->Common.Node to point to the Alias target. Note,
179 * Alias has at most one level of indirection internally.
181 type
= op
->common
.node
->type
;
182 if (type
== ACPI_TYPE_LOCAL_ALIAS
) {
183 type
= obj_desc
->common
.type
;
185 ACPI_CAST_PTR(struct acpi_namespace_node
,
186 op
->common
.node
->object
);
191 * For these types, we need the actual node, not the subobject.
192 * However, the subobject did not get an extra reference count above.
194 * TBD: should ex_resolve_node_to_value be changed to fix this?
196 case ACPI_TYPE_DEVICE
:
197 case ACPI_TYPE_THERMAL
:
199 acpi_ut_add_reference(op
->common
.node
->object
);
201 /*lint -fallthrough */
203 * For these types, we need the actual node, not the subobject.
204 * The subobject got an extra reference count in ex_resolve_node_to_value.
206 case ACPI_TYPE_MUTEX
:
207 case ACPI_TYPE_METHOD
:
208 case ACPI_TYPE_POWER
:
209 case ACPI_TYPE_PROCESSOR
:
210 case ACPI_TYPE_EVENT
:
211 case ACPI_TYPE_REGION
:
213 /* We will create a reference object for these types below */
218 * All other types - the node was resolved to an actual
219 * object, we are done.
226 /* Create and init a new internal ACPI object */
228 obj_desc
= acpi_ut_create_internal_object((acpi_ps_get_opcode_info
229 (op
->common
.aml_opcode
))->
232 return_ACPI_STATUS(AE_NO_MEMORY
);
236 acpi_ds_init_object_from_op(walk_state
, op
, op
->common
.aml_opcode
,
238 if (ACPI_FAILURE(status
)) {
239 acpi_ut_remove_reference(obj_desc
);
240 return_ACPI_STATUS(status
);
244 *obj_desc_ptr
= obj_desc
;
245 return_ACPI_STATUS(status
);
248 /*******************************************************************************
250 * FUNCTION: acpi_ds_build_internal_buffer_obj
252 * PARAMETERS: walk_state - Current walk state
253 * Op - Parser object to be translated
254 * buffer_length - Length of the buffer
255 * obj_desc_ptr - Where the ACPI internal object is returned
259 * DESCRIPTION: Translate a parser Op package object to the equivalent
262 ******************************************************************************/
265 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state
*walk_state
,
266 union acpi_parse_object
*op
,
268 union acpi_operand_object
**obj_desc_ptr
)
270 union acpi_parse_object
*arg
;
271 union acpi_operand_object
*obj_desc
;
272 union acpi_parse_object
*byte_list
;
273 u32 byte_list_length
= 0;
275 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj
);
277 obj_desc
= *obj_desc_ptr
;
280 /* Create a new buffer object */
282 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_BUFFER
);
283 *obj_desc_ptr
= obj_desc
;
285 return_ACPI_STATUS(AE_NO_MEMORY
);
290 * Second arg is the buffer data (optional) byte_list can be either
291 * individual bytes or a string initializer. In either case, a
292 * byte_list appears in the AML.
294 arg
= op
->common
.value
.arg
; /* skip first arg */
296 byte_list
= arg
->named
.next
;
298 if (byte_list
->common
.aml_opcode
!= AML_INT_BYTELIST_OP
) {
300 "Expecting bytelist, found AML opcode 0x%X in op %p",
301 byte_list
->common
.aml_opcode
, byte_list
));
303 acpi_ut_remove_reference(obj_desc
);
307 byte_list_length
= (u32
) byte_list
->common
.value
.integer
;
311 * The buffer length (number of bytes) will be the larger of:
312 * 1) The specified buffer length and
313 * 2) The length of the initializer byte list
315 obj_desc
->buffer
.length
= buffer_length
;
316 if (byte_list_length
> buffer_length
) {
317 obj_desc
->buffer
.length
= byte_list_length
;
320 /* Allocate the buffer */
322 if (obj_desc
->buffer
.length
== 0) {
323 obj_desc
->buffer
.pointer
= NULL
;
324 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
325 "Buffer defined with zero length in AML, creating\n"));
327 obj_desc
->buffer
.pointer
=
328 ACPI_ALLOCATE_ZEROED(obj_desc
->buffer
.length
);
329 if (!obj_desc
->buffer
.pointer
) {
330 acpi_ut_delete_object_desc(obj_desc
);
331 return_ACPI_STATUS(AE_NO_MEMORY
);
334 /* Initialize buffer from the byte_list (if present) */
337 ACPI_MEMCPY(obj_desc
->buffer
.pointer
,
338 byte_list
->named
.data
, byte_list_length
);
342 obj_desc
->buffer
.flags
|= AOPOBJ_DATA_VALID
;
343 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
344 return_ACPI_STATUS(AE_OK
);
347 /*******************************************************************************
349 * FUNCTION: acpi_ds_build_internal_package_obj
351 * PARAMETERS: walk_state - Current walk state
352 * Op - Parser object to be translated
353 * element_count - Number of elements in the package - this is
354 * the num_elements argument to Package()
355 * obj_desc_ptr - Where the ACPI internal object is returned
359 * DESCRIPTION: Translate a parser Op package object to the equivalent
362 * NOTE: The number of elements in the package will be always be the num_elements
363 * count, regardless of the number of elements in the package list. If
364 * num_elements is smaller, only that many package list elements are used.
365 * if num_elements is larger, the Package object is padded out with
366 * objects of type Uninitialized (as per ACPI spec.)
368 * Even though the ASL compilers do not allow num_elements to be smaller
369 * than the Package list length (for the fixed length package opcode), some
370 * BIOS code modifies the AML on the fly to adjust the num_elements, and
371 * this code compensates for that. This also provides compatibility with
372 * other AML interpreters.
374 ******************************************************************************/
377 acpi_ds_build_internal_package_obj(struct acpi_walk_state
*walk_state
,
378 union acpi_parse_object
*op
,
380 union acpi_operand_object
**obj_desc_ptr
)
382 union acpi_parse_object
*arg
;
383 union acpi_parse_object
*parent
;
384 union acpi_operand_object
*obj_desc
= NULL
;
385 acpi_status status
= AE_OK
;
390 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj
);
392 /* Find the parent of a possibly nested package */
394 parent
= op
->common
.parent
;
395 while ((parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
396 (parent
->common
.aml_opcode
== AML_VAR_PACKAGE_OP
)) {
397 parent
= parent
->common
.parent
;
400 obj_desc
= *obj_desc_ptr
;
402 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE
);
403 *obj_desc_ptr
= obj_desc
;
405 return_ACPI_STATUS(AE_NO_MEMORY
);
408 obj_desc
->package
.node
= parent
->common
.node
;
412 * Allocate the element array (array of pointers to the individual
413 * objects) based on the num_elements parameter. Add an extra pointer slot
414 * so that the list is always null terminated.
416 obj_desc
->package
.elements
= ACPI_ALLOCATE_ZEROED(((acpi_size
)
418 1) * sizeof(void *));
420 if (!obj_desc
->package
.elements
) {
421 acpi_ut_delete_object_desc(obj_desc
);
422 return_ACPI_STATUS(AE_NO_MEMORY
);
425 obj_desc
->package
.count
= element_count
;
428 * Initialize the elements of the package, up to the num_elements count.
429 * Package is automatically padded with uninitialized (NULL) elements
430 * if num_elements is greater than the package list length. Likewise,
431 * Package is truncated if num_elements is less than the list length.
433 arg
= op
->common
.value
.arg
;
434 arg
= arg
->common
.next
;
435 for (i
= 0; arg
&& (i
< element_count
); i
++) {
436 if (arg
->common
.aml_opcode
== AML_INT_RETURN_VALUE_OP
) {
437 if (arg
->common
.node
->type
== ACPI_TYPE_METHOD
) {
439 * A method reference "looks" to the parser to be a method
440 * invocation, so we special case it here
442 arg
->common
.aml_opcode
= AML_INT_NAMEPATH_OP
;
444 acpi_ds_build_internal_object(walk_state
,
450 /* This package element is already built, just get it */
452 obj_desc
->package
.elements
[i
] =
453 ACPI_CAST_PTR(union acpi_operand_object
,
457 status
= acpi_ds_build_internal_object(walk_state
, arg
,
465 /* Existing package, get existing reference count */
468 (*obj_desc_ptr
)->common
.reference_count
;
469 if (reference_count
> 1) {
471 /* Make new element ref count match original ref count */
473 for (index
= 0; index
< (reference_count
- 1);
475 acpi_ut_add_reference((obj_desc
->
482 arg
= arg
->common
.next
;
485 /* Check for match between num_elements and actual length of package_list */
489 * num_elements was exhausted, but there are remaining elements in the
490 * package_list. Truncate the package to num_elements.
492 * Note: technically, this is an error, from ACPI spec: "It is an error
493 * for NumElements to be less than the number of elements in the
494 * PackageList". However, we just print a message and
495 * no exception is returned. This provides Windows compatibility. Some
496 * BIOSs will alter the num_elements on the fly, creating this type
497 * of ill-formed package object.
501 * We must delete any package elements that were created earlier
502 * and are not going to be used because of the package truncation.
504 if (arg
->common
.node
) {
505 acpi_ut_remove_reference(ACPI_CAST_PTR
509 arg
->common
.node
= NULL
;
512 /* Find out how many elements there really are */
515 arg
= arg
->common
.next
;
519 "Actual Package length (%u) is larger than NumElements field (%u), truncated\n",
521 } else if (i
< element_count
) {
523 * Arg list (elements) was exhausted, but we did not reach num_elements count.
524 * Note: this is not an error, the package is padded out with NULLs.
526 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
527 "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
531 obj_desc
->package
.flags
|= AOPOBJ_DATA_VALID
;
532 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
533 return_ACPI_STATUS(status
);
536 /*******************************************************************************
538 * FUNCTION: acpi_ds_create_node
540 * PARAMETERS: walk_state - Current walk state
541 * Node - NS Node to be initialized
542 * Op - Parser object to be translated
546 * DESCRIPTION: Create the object to be associated with a namespace node
548 ******************************************************************************/
551 acpi_ds_create_node(struct acpi_walk_state
*walk_state
,
552 struct acpi_namespace_node
*node
,
553 union acpi_parse_object
*op
)
556 union acpi_operand_object
*obj_desc
;
558 ACPI_FUNCTION_TRACE_PTR(ds_create_node
, op
);
561 * Because of the execution pass through the non-control-method
562 * parts of the table, we can arrive here twice. Only init
563 * the named object node the first time through
565 if (acpi_ns_get_attached_object(node
)) {
566 return_ACPI_STATUS(AE_OK
);
569 if (!op
->common
.value
.arg
) {
571 /* No arguments, there is nothing to do */
573 return_ACPI_STATUS(AE_OK
);
576 /* Build an internal object for the argument(s) */
578 status
= acpi_ds_build_internal_object(walk_state
, op
->common
.value
.arg
,
580 if (ACPI_FAILURE(status
)) {
581 return_ACPI_STATUS(status
);
584 /* Re-type the object according to its argument */
586 node
->type
= obj_desc
->common
.type
;
588 /* Attach obj to node */
590 status
= acpi_ns_attach_object(node
, obj_desc
, node
->type
);
592 /* Remove local reference to the object */
594 acpi_ut_remove_reference(obj_desc
);
595 return_ACPI_STATUS(status
);
598 #endif /* ACPI_NO_METHOD_EXECUTION */
600 /*******************************************************************************
602 * FUNCTION: acpi_ds_init_object_from_op
604 * PARAMETERS: walk_state - Current walk state
605 * Op - Parser op used to init the internal object
606 * Opcode - AML opcode associated with the object
607 * ret_obj_desc - Namespace object to be initialized
611 * DESCRIPTION: Initialize a namespace object from a parser Op and its
612 * associated arguments. The namespace object is a more compact
613 * representation of the Op and its arguments.
615 ******************************************************************************/
618 acpi_ds_init_object_from_op(struct acpi_walk_state
*walk_state
,
619 union acpi_parse_object
*op
,
621 union acpi_operand_object
**ret_obj_desc
)
623 const struct acpi_opcode_info
*op_info
;
624 union acpi_operand_object
*obj_desc
;
625 acpi_status status
= AE_OK
;
627 ACPI_FUNCTION_TRACE(ds_init_object_from_op
);
629 obj_desc
= *ret_obj_desc
;
630 op_info
= acpi_ps_get_opcode_info(opcode
);
631 if (op_info
->class == AML_CLASS_UNKNOWN
) {
635 return_ACPI_STATUS(AE_TYPE
);
638 /* Perform per-object initialization */
640 switch (obj_desc
->common
.type
) {
641 case ACPI_TYPE_BUFFER
:
644 * Defer evaluation of Buffer term_arg operand
646 obj_desc
->buffer
.node
=
647 ACPI_CAST_PTR(struct acpi_namespace_node
,
648 walk_state
->operands
[0]);
649 obj_desc
->buffer
.aml_start
= op
->named
.data
;
650 obj_desc
->buffer
.aml_length
= op
->named
.length
;
653 case ACPI_TYPE_PACKAGE
:
656 * Defer evaluation of Package term_arg operand
658 obj_desc
->package
.node
=
659 ACPI_CAST_PTR(struct acpi_namespace_node
,
660 walk_state
->operands
[0]);
661 obj_desc
->package
.aml_start
= op
->named
.data
;
662 obj_desc
->package
.aml_length
= op
->named
.length
;
665 case ACPI_TYPE_INTEGER
:
667 switch (op_info
->type
) {
668 case AML_TYPE_CONSTANT
:
670 * Resolve AML Constants here - AND ONLY HERE!
671 * All constants are integers.
672 * We mark the integer with a flag that indicates that it started
673 * life as a constant -- so that stores to constants will perform
674 * as expected (noop). zero_op is used as a placeholder for optional
677 obj_desc
->common
.flags
= AOPOBJ_AML_CONSTANT
;
682 obj_desc
->integer
.value
= 0;
687 obj_desc
->integer
.value
= 1;
692 obj_desc
->integer
.value
= ACPI_UINT64_MAX
;
694 /* Truncate value if we are executing from a 32-bit ACPI table */
696 #ifndef ACPI_NO_METHOD_EXECUTION
697 acpi_ex_truncate_for32bit_table(obj_desc
);
701 case AML_REVISION_OP
:
703 obj_desc
->integer
.value
= ACPI_CA_VERSION
;
709 "Unknown constant opcode 0x%X",
711 status
= AE_AML_OPERAND_TYPE
;
716 case AML_TYPE_LITERAL
:
718 obj_desc
->integer
.value
= op
->common
.value
.integer
;
719 #ifndef ACPI_NO_METHOD_EXECUTION
720 acpi_ex_truncate_for32bit_table(obj_desc
);
725 ACPI_ERROR((AE_INFO
, "Unknown Integer type 0x%X",
727 status
= AE_AML_OPERAND_TYPE
;
732 case ACPI_TYPE_STRING
:
734 obj_desc
->string
.pointer
= op
->common
.value
.string
;
735 obj_desc
->string
.length
=
736 (u32
) ACPI_STRLEN(op
->common
.value
.string
);
739 * The string is contained in the ACPI table, don't ever try
742 obj_desc
->common
.flags
|= AOPOBJ_STATIC_POINTER
;
745 case ACPI_TYPE_METHOD
:
748 case ACPI_TYPE_LOCAL_REFERENCE
:
750 switch (op_info
->type
) {
751 case AML_TYPE_LOCAL_VARIABLE
:
753 /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
755 obj_desc
->reference
.value
=
756 ((u32
)opcode
) - AML_LOCAL_OP
;
757 obj_desc
->reference
.class = ACPI_REFCLASS_LOCAL
;
759 #ifndef ACPI_NO_METHOD_EXECUTION
761 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL
,
764 ACPI_CAST_INDIRECT_PTR
767 &obj_desc
->reference
.
772 case AML_TYPE_METHOD_ARGUMENT
:
774 /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
776 obj_desc
->reference
.value
= ((u32
)opcode
) - AML_ARG_OP
;
777 obj_desc
->reference
.class = ACPI_REFCLASS_ARG
;
779 #ifndef ACPI_NO_METHOD_EXECUTION
780 status
= acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG
,
784 ACPI_CAST_INDIRECT_PTR
793 default: /* Object name or Debug object */
795 switch (op
->common
.aml_opcode
) {
796 case AML_INT_NAMEPATH_OP
:
798 /* Node was saved in Op */
800 obj_desc
->reference
.node
= op
->common
.node
;
801 obj_desc
->reference
.object
=
802 op
->common
.node
->object
;
803 obj_desc
->reference
.class = ACPI_REFCLASS_NAME
;
808 obj_desc
->reference
.class = ACPI_REFCLASS_DEBUG
;
814 "Unimplemented reference type for AML opcode: 0x%4.4X",
816 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
824 ACPI_ERROR((AE_INFO
, "Unimplemented data type: 0x%X",
825 obj_desc
->common
.type
));
827 status
= AE_AML_OPERAND_TYPE
;
831 return_ACPI_STATUS(status
);