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(walk_state->
119 return_ACPI_STATUS(status);
127 /* Create and init a new internal ACPI object */
129 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
130 (op->common.aml_opcode))->
133 return_ACPI_STATUS(AE_NO_MEMORY);
137 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
139 if (ACPI_FAILURE(status)) {
140 acpi_ut_remove_reference(obj_desc);
141 return_ACPI_STATUS(status);
145 * Handling for unresolved package reference elements.
146 * These are elements that are namepaths.
148 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
149 (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
150 obj_desc->reference.resolved = TRUE;
152 if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
153 !obj_desc->reference.node) {
155 * Name was unresolved above.
156 * Get the prefix node for later lookup
158 obj_desc->reference.node =
159 walk_state->scope_info->scope.node;
160 obj_desc->reference.aml = op->common.aml;
161 obj_desc->reference.resolved = FALSE;
165 *obj_desc_ptr = obj_desc;
166 return_ACPI_STATUS(status);
169 /*******************************************************************************
171 * FUNCTION: acpi_ds_build_internal_buffer_obj
173 * PARAMETERS: walk_state - Current walk state
174 * op - Parser object to be translated
175 * buffer_length - Length of the buffer
176 * obj_desc_ptr - Where the ACPI internal object is returned
180 * DESCRIPTION: Translate a parser Op package object to the equivalent
183 ******************************************************************************/
186 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
187 union acpi_parse_object *op,
189 union acpi_operand_object **obj_desc_ptr)
191 union acpi_parse_object *arg;
192 union acpi_operand_object *obj_desc;
193 union acpi_parse_object *byte_list;
194 u32 byte_list_length = 0;
196 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
199 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
200 * The buffer object already exists (from the NS node), otherwise it must
203 obj_desc = *obj_desc_ptr;
206 /* Create a new buffer object */
208 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
209 *obj_desc_ptr = obj_desc;
211 return_ACPI_STATUS(AE_NO_MEMORY);
216 * Second arg is the buffer data (optional) byte_list can be either
217 * individual bytes or a string initializer. In either case, a
218 * byte_list appears in the AML.
220 arg = op->common.value.arg; /* skip first arg */
222 byte_list = arg->named.next;
224 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
226 "Expecting bytelist, found AML opcode 0x%X in op %p",
227 byte_list->common.aml_opcode, byte_list));
229 acpi_ut_remove_reference(obj_desc);
233 byte_list_length = (u32) byte_list->common.value.integer;
237 * The buffer length (number of bytes) will be the larger of:
238 * 1) The specified buffer length and
239 * 2) The length of the initializer byte list
241 obj_desc->buffer.length = buffer_length;
242 if (byte_list_length > buffer_length) {
243 obj_desc->buffer.length = byte_list_length;
246 /* Allocate the buffer */
248 if (obj_desc->buffer.length == 0) {
249 obj_desc->buffer.pointer = NULL;
250 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
251 "Buffer defined with zero length in AML, creating\n"));
253 obj_desc->buffer.pointer =
254 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
255 if (!obj_desc->buffer.pointer) {
256 acpi_ut_delete_object_desc(obj_desc);
257 return_ACPI_STATUS(AE_NO_MEMORY);
260 /* Initialize buffer from the byte_list (if present) */
263 memcpy(obj_desc->buffer.pointer, byte_list->named.data,
268 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
269 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
270 return_ACPI_STATUS(AE_OK);
273 /*******************************************************************************
275 * FUNCTION: acpi_ds_create_node
277 * PARAMETERS: walk_state - Current walk state
278 * node - NS Node to be initialized
279 * op - Parser object to be translated
283 * DESCRIPTION: Create the object to be associated with a namespace node
285 ******************************************************************************/
288 acpi_ds_create_node(struct acpi_walk_state *walk_state,
289 struct acpi_namespace_node *node,
290 union acpi_parse_object *op)
293 union acpi_operand_object *obj_desc;
295 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
298 * Because of the execution pass through the non-control-method
299 * parts of the table, we can arrive here twice. Only init
300 * the named object node the first time through
302 if (acpi_ns_get_attached_object(node)) {
303 return_ACPI_STATUS(AE_OK);
306 if (!op->common.value.arg) {
308 /* No arguments, there is nothing to do */
310 return_ACPI_STATUS(AE_OK);
313 /* Build an internal object for the argument(s) */
316 acpi_ds_build_internal_object(walk_state, op->common.value.arg,
318 if (ACPI_FAILURE(status)) {
319 return_ACPI_STATUS(status);
322 /* Re-type the object according to its argument */
324 node->type = obj_desc->common.type;
326 /* Attach obj to node */
328 status = acpi_ns_attach_object(node, obj_desc, node->type);
330 /* Remove local reference to the object */
332 acpi_ut_remove_reference(obj_desc);
333 return_ACPI_STATUS(status);
336 #endif /* ACPI_NO_METHOD_EXECUTION */
338 /*******************************************************************************
340 * FUNCTION: acpi_ds_init_object_from_op
342 * PARAMETERS: walk_state - Current walk state
343 * op - Parser op used to init the internal object
344 * opcode - AML opcode associated with the object
345 * ret_obj_desc - Namespace object to be initialized
349 * DESCRIPTION: Initialize a namespace object from a parser Op and its
350 * associated arguments. The namespace object is a more compact
351 * representation of the Op and its arguments.
353 ******************************************************************************/
356 acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
357 union acpi_parse_object *op,
359 union acpi_operand_object **ret_obj_desc)
361 const struct acpi_opcode_info *op_info;
362 union acpi_operand_object *obj_desc;
363 acpi_status status = AE_OK;
365 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
367 obj_desc = *ret_obj_desc;
368 op_info = acpi_ps_get_opcode_info(opcode);
369 if (op_info->class == AML_CLASS_UNKNOWN) {
373 return_ACPI_STATUS(AE_TYPE);
376 /* Perform per-object initialization */
378 switch (obj_desc->common.type) {
379 case ACPI_TYPE_BUFFER:
381 * Defer evaluation of Buffer term_arg operand
383 obj_desc->buffer.node =
384 ACPI_CAST_PTR(struct acpi_namespace_node,
385 walk_state->operands[0]);
386 obj_desc->buffer.aml_start = op->named.data;
387 obj_desc->buffer.aml_length = op->named.length;
390 case ACPI_TYPE_PACKAGE:
392 * Defer evaluation of Package term_arg operand and all
393 * package elements. (01/2017): We defer the element
394 * resolution to allow forward references from the package
395 * in order to provide compatibility with other ACPI
398 obj_desc->package.node =
399 ACPI_CAST_PTR(struct acpi_namespace_node,
400 walk_state->operands[0]);
402 if (!op->named.data) {
403 return_ACPI_STATUS(AE_OK);
406 obj_desc->package.aml_start = op->named.data;
407 obj_desc->package.aml_length = op->named.length;
410 case ACPI_TYPE_INTEGER:
412 switch (op_info->type) {
413 case AML_TYPE_CONSTANT:
415 * Resolve AML Constants here - AND ONLY HERE!
416 * All constants are integers.
417 * We mark the integer with a flag that indicates that it started
418 * life as a constant -- so that stores to constants will perform
419 * as expected (noop). zero_op is used as a placeholder for optional
422 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
427 obj_desc->integer.value = 0;
432 obj_desc->integer.value = 1;
437 obj_desc->integer.value = ACPI_UINT64_MAX;
439 /* Truncate value if we are executing from a 32-bit ACPI table */
441 #ifndef ACPI_NO_METHOD_EXECUTION
442 (void)acpi_ex_truncate_for32bit_table(obj_desc);
446 case AML_REVISION_OP:
448 obj_desc->integer.value = ACPI_CA_VERSION;
454 "Unknown constant opcode 0x%X",
456 status = AE_AML_OPERAND_TYPE;
461 case AML_TYPE_LITERAL:
463 obj_desc->integer.value = op->common.value.integer;
465 #ifndef ACPI_NO_METHOD_EXECUTION
466 if (acpi_ex_truncate_for32bit_table(obj_desc)) {
468 /* Warn if we found a 64-bit constant in a 32-bit table */
470 ACPI_WARNING((AE_INFO,
471 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
472 ACPI_FORMAT_UINT64(op->common.
474 (u32)obj_desc->integer.value));
481 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
483 status = AE_AML_OPERAND_TYPE;
488 case ACPI_TYPE_STRING:
490 obj_desc->string.pointer = op->common.value.string;
491 obj_desc->string.length = (u32)strlen(op->common.value.string);
494 * The string is contained in the ACPI table, don't ever try
497 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
500 case ACPI_TYPE_METHOD:
503 case ACPI_TYPE_LOCAL_REFERENCE:
505 switch (op_info->type) {
506 case AML_TYPE_LOCAL_VARIABLE:
508 /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
510 obj_desc->reference.value =
511 ((u32)opcode) - AML_FIRST_LOCAL_OP;
512 obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
514 #ifndef ACPI_NO_METHOD_EXECUTION
516 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
519 ACPI_CAST_INDIRECT_PTR
522 &obj_desc->reference.
527 case AML_TYPE_METHOD_ARGUMENT:
529 /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
531 obj_desc->reference.value =
532 ((u32)opcode) - AML_FIRST_ARG_OP;
533 obj_desc->reference.class = ACPI_REFCLASS_ARG;
535 #ifndef ACPI_NO_METHOD_EXECUTION
536 status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
540 ACPI_CAST_INDIRECT_PTR
549 default: /* Object name or Debug object */
551 switch (op->common.aml_opcode) {
552 case AML_INT_NAMEPATH_OP:
554 /* Node was saved in Op */
556 obj_desc->reference.node = op->common.node;
557 obj_desc->reference.class = ACPI_REFCLASS_NAME;
558 if (op->common.node) {
559 obj_desc->reference.object =
560 op->common.node->object;
566 obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
572 "Unimplemented reference type for AML opcode: 0x%4.4X",
574 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
582 ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
583 obj_desc->common.type));
585 status = AE_AML_OPERAND_TYPE;
589 return_ACPI_STATUS(status);