1 /******************************************************************************
3 * Module Name: dsobject - Dispatcher object management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, 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 #ifndef ACPI_NO_METHOD_EXECUTION
56 /*******************************************************************************
58 * FUNCTION: acpi_ds_build_internal_object
60 * PARAMETERS: walk_state - Current walk state
61 * op - Parser object to be translated
62 * obj_desc_ptr - Where the ACPI internal object is returned
66 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
67 * Simple objects are any objects other than a package object!
69 ******************************************************************************/
71 acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
72 union acpi_parse_object *op,
73 union acpi_operand_object **obj_desc_ptr)
75 union acpi_operand_object *obj_desc;
78 ACPI_FUNCTION_TRACE(ds_build_internal_object);
81 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
83 * This is a named object reference. If this name was
84 * previously looked up in the namespace, it was stored in
85 * this op. Otherwise, go ahead and look it up now
87 if (!op->common.node) {
89 /* Check if we are resolving a named reference within a package */
91 if ((op->common.parent->common.aml_opcode ==
93 || (op->common.parent->common.aml_opcode ==
94 AML_VARIABLE_PACKAGE_OP)) {
96 * We won't resolve package elements here, we will do this
97 * after all ACPI tables are loaded into the namespace. This
98 * behavior supports both forward references to named objects
99 * and external references to objects in other tables.
101 goto create_new_object;
103 status = acpi_ns_lookup(walk_state->scope_info,
104 op->common.value.string,
107 ACPI_NS_SEARCH_PARENT |
108 ACPI_NS_DONT_OPEN_SCOPE,
110 ACPI_CAST_INDIRECT_PTR
113 &(op->common.node)));
114 if (ACPI_FAILURE(status)) {
115 ACPI_ERROR_NAMESPACE(op->common.value.
117 return_ACPI_STATUS(status);
125 /* Create and init a new internal ACPI object */
127 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
128 (op->common.aml_opcode))->
131 return_ACPI_STATUS(AE_NO_MEMORY);
135 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
137 if (ACPI_FAILURE(status)) {
138 acpi_ut_remove_reference(obj_desc);
139 return_ACPI_STATUS(status);
143 * Handling for unresolved package reference elements.
144 * These are elements that are namepaths.
146 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
147 (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
148 obj_desc->reference.resolved = TRUE;
150 if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
151 !obj_desc->reference.node) {
153 * Name was unresolved above.
154 * Get the prefix node for later lookup
156 obj_desc->reference.node =
157 walk_state->scope_info->scope.node;
158 obj_desc->reference.aml = op->common.aml;
159 obj_desc->reference.resolved = FALSE;
163 *obj_desc_ptr = obj_desc;
164 return_ACPI_STATUS(status);
167 /*******************************************************************************
169 * FUNCTION: acpi_ds_build_internal_buffer_obj
171 * PARAMETERS: walk_state - Current walk state
172 * op - Parser object to be translated
173 * buffer_length - Length of the buffer
174 * obj_desc_ptr - Where the ACPI internal object is returned
178 * DESCRIPTION: Translate a parser Op package object to the equivalent
181 ******************************************************************************/
184 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
185 union acpi_parse_object *op,
187 union acpi_operand_object **obj_desc_ptr)
189 union acpi_parse_object *arg;
190 union acpi_operand_object *obj_desc;
191 union acpi_parse_object *byte_list;
192 u32 byte_list_length = 0;
194 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
197 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
198 * The buffer object already exists (from the NS node), otherwise it must
201 obj_desc = *obj_desc_ptr;
204 /* Create a new buffer object */
206 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
207 *obj_desc_ptr = obj_desc;
209 return_ACPI_STATUS(AE_NO_MEMORY);
214 * Second arg is the buffer data (optional) byte_list can be either
215 * individual bytes or a string initializer. In either case, a
216 * byte_list appears in the AML.
218 arg = op->common.value.arg; /* skip first arg */
220 byte_list = arg->named.next;
222 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
224 "Expecting bytelist, found AML opcode 0x%X in op %p",
225 byte_list->common.aml_opcode, byte_list));
227 acpi_ut_remove_reference(obj_desc);
231 byte_list_length = (u32) byte_list->common.value.integer;
235 * The buffer length (number of bytes) will be the larger of:
236 * 1) The specified buffer length and
237 * 2) The length of the initializer byte list
239 obj_desc->buffer.length = buffer_length;
240 if (byte_list_length > buffer_length) {
241 obj_desc->buffer.length = byte_list_length;
244 /* Allocate the buffer */
246 if (obj_desc->buffer.length == 0) {
247 obj_desc->buffer.pointer = NULL;
248 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
249 "Buffer defined with zero length in AML, creating\n"));
251 obj_desc->buffer.pointer =
252 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
253 if (!obj_desc->buffer.pointer) {
254 acpi_ut_delete_object_desc(obj_desc);
255 return_ACPI_STATUS(AE_NO_MEMORY);
258 /* Initialize buffer from the byte_list (if present) */
261 memcpy(obj_desc->buffer.pointer, byte_list->named.data,
266 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
267 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
268 return_ACPI_STATUS(AE_OK);
271 /*******************************************************************************
273 * FUNCTION: acpi_ds_create_node
275 * PARAMETERS: walk_state - Current walk state
276 * node - NS Node to be initialized
277 * op - Parser object to be translated
281 * DESCRIPTION: Create the object to be associated with a namespace node
283 ******************************************************************************/
286 acpi_ds_create_node(struct acpi_walk_state *walk_state,
287 struct acpi_namespace_node *node,
288 union acpi_parse_object *op)
291 union acpi_operand_object *obj_desc;
293 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
296 * Because of the execution pass through the non-control-method
297 * parts of the table, we can arrive here twice. Only init
298 * the named object node the first time through
300 if (acpi_ns_get_attached_object(node)) {
301 return_ACPI_STATUS(AE_OK);
304 if (!op->common.value.arg) {
306 /* No arguments, there is nothing to do */
308 return_ACPI_STATUS(AE_OK);
311 /* Build an internal object for the argument(s) */
314 acpi_ds_build_internal_object(walk_state, op->common.value.arg,
316 if (ACPI_FAILURE(status)) {
317 return_ACPI_STATUS(status);
320 /* Re-type the object according to its argument */
322 node->type = obj_desc->common.type;
324 /* Attach obj to node */
326 status = acpi_ns_attach_object(node, obj_desc, node->type);
328 /* Remove local reference to the object */
330 acpi_ut_remove_reference(obj_desc);
331 return_ACPI_STATUS(status);
334 #endif /* ACPI_NO_METHOD_EXECUTION */
336 /*******************************************************************************
338 * FUNCTION: acpi_ds_init_object_from_op
340 * PARAMETERS: walk_state - Current walk state
341 * op - Parser op used to init the internal object
342 * opcode - AML opcode associated with the object
343 * ret_obj_desc - Namespace object to be initialized
347 * DESCRIPTION: Initialize a namespace object from a parser Op and its
348 * associated arguments. The namespace object is a more compact
349 * representation of the Op and its arguments.
351 ******************************************************************************/
354 acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
355 union acpi_parse_object *op,
357 union acpi_operand_object **ret_obj_desc)
359 const struct acpi_opcode_info *op_info;
360 union acpi_operand_object *obj_desc;
361 acpi_status status = AE_OK;
363 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
365 obj_desc = *ret_obj_desc;
366 op_info = acpi_ps_get_opcode_info(opcode);
367 if (op_info->class == AML_CLASS_UNKNOWN) {
371 return_ACPI_STATUS(AE_TYPE);
374 /* Perform per-object initialization */
376 switch (obj_desc->common.type) {
377 case ACPI_TYPE_BUFFER:
379 * Defer evaluation of Buffer term_arg operand
381 obj_desc->buffer.node =
382 ACPI_CAST_PTR(struct acpi_namespace_node,
383 walk_state->operands[0]);
384 obj_desc->buffer.aml_start = op->named.data;
385 obj_desc->buffer.aml_length = op->named.length;
388 case ACPI_TYPE_PACKAGE:
390 * Defer evaluation of Package term_arg operand and all
391 * package elements. (01/2017): We defer the element
392 * resolution to allow forward references from the package
393 * in order to provide compatibility with other ACPI
396 obj_desc->package.node =
397 ACPI_CAST_PTR(struct acpi_namespace_node,
398 walk_state->operands[0]);
400 if (!op->named.data) {
401 return_ACPI_STATUS(AE_OK);
404 obj_desc->package.aml_start = op->named.data;
405 obj_desc->package.aml_length = op->named.length;
408 case ACPI_TYPE_INTEGER:
410 switch (op_info->type) {
411 case AML_TYPE_CONSTANT:
413 * Resolve AML Constants here - AND ONLY HERE!
414 * All constants are integers.
415 * We mark the integer with a flag that indicates that it started
416 * life as a constant -- so that stores to constants will perform
417 * as expected (noop). zero_op is used as a placeholder for optional
420 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
425 obj_desc->integer.value = 0;
430 obj_desc->integer.value = 1;
435 obj_desc->integer.value = ACPI_UINT64_MAX;
437 /* Truncate value if we are executing from a 32-bit ACPI table */
439 #ifndef ACPI_NO_METHOD_EXECUTION
440 (void)acpi_ex_truncate_for32bit_table(obj_desc);
444 case AML_REVISION_OP:
446 obj_desc->integer.value = ACPI_CA_VERSION;
452 "Unknown constant opcode 0x%X",
454 status = AE_AML_OPERAND_TYPE;
459 case AML_TYPE_LITERAL:
461 obj_desc->integer.value = op->common.value.integer;
463 #ifndef ACPI_NO_METHOD_EXECUTION
464 if (acpi_ex_truncate_for32bit_table(obj_desc)) {
466 /* Warn if we found a 64-bit constant in a 32-bit table */
468 ACPI_WARNING((AE_INFO,
469 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
470 ACPI_FORMAT_UINT64(op->common.
472 (u32)obj_desc->integer.value));
479 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
481 status = AE_AML_OPERAND_TYPE;
486 case ACPI_TYPE_STRING:
488 obj_desc->string.pointer = op->common.value.string;
489 obj_desc->string.length = (u32)strlen(op->common.value.string);
492 * The string is contained in the ACPI table, don't ever try
495 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
498 case ACPI_TYPE_METHOD:
501 case ACPI_TYPE_LOCAL_REFERENCE:
503 switch (op_info->type) {
504 case AML_TYPE_LOCAL_VARIABLE:
506 /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
508 obj_desc->reference.value =
509 ((u32)opcode) - AML_FIRST_LOCAL_OP;
510 obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
512 #ifndef ACPI_NO_METHOD_EXECUTION
514 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
517 ACPI_CAST_INDIRECT_PTR
520 &obj_desc->reference.
525 case AML_TYPE_METHOD_ARGUMENT:
527 /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
529 obj_desc->reference.value =
530 ((u32)opcode) - AML_FIRST_ARG_OP;
531 obj_desc->reference.class = ACPI_REFCLASS_ARG;
533 #ifndef ACPI_NO_METHOD_EXECUTION
534 status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
538 ACPI_CAST_INDIRECT_PTR
547 default: /* Object name or Debug object */
549 switch (op->common.aml_opcode) {
550 case AML_INT_NAMEPATH_OP:
552 /* Node was saved in Op */
554 obj_desc->reference.node = op->common.node;
555 obj_desc->reference.class = ACPI_REFCLASS_NAME;
556 if (op->common.node) {
557 obj_desc->reference.object =
558 op->common.node->object;
564 obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
570 "Unimplemented reference type for AML opcode: 0x%4.4X",
572 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
580 ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
581 obj_desc->common.type));
583 status = AE_AML_OPERAND_TYPE;
587 return_ACPI_STATUS(status);