1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: dsobject - Dispatcher object management routines
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
18 #define _COMPONENT ACPI_DISPATCHER
19 ACPI_MODULE_NAME("dsobject")
21 /*******************************************************************************
23 * FUNCTION: acpi_ds_build_internal_object
25 * PARAMETERS: walk_state - Current walk state
26 * op - Parser object to be translated
27 * obj_desc_ptr - Where the ACPI internal object is returned
31 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
32 * Simple objects are any objects other than a package object!
34 ******************************************************************************/
36 acpi_ds_build_internal_object(struct acpi_walk_state
*walk_state
,
37 union acpi_parse_object
*op
,
38 union acpi_operand_object
**obj_desc_ptr
)
40 union acpi_operand_object
*obj_desc
;
43 ACPI_FUNCTION_TRACE(ds_build_internal_object
);
46 if (op
->common
.aml_opcode
== AML_INT_NAMEPATH_OP
) {
48 * This is a named object reference. If this name was
49 * previously looked up in the namespace, it was stored in
50 * this op. Otherwise, go ahead and look it up now
52 if (!op
->common
.node
) {
54 /* Check if we are resolving a named reference within a package */
56 if ((op
->common
.parent
->common
.aml_opcode
==
58 || (op
->common
.parent
->common
.aml_opcode
==
59 AML_VARIABLE_PACKAGE_OP
)) {
61 * We won't resolve package elements here, we will do this
62 * after all ACPI tables are loaded into the namespace. This
63 * behavior supports both forward references to named objects
64 * and external references to objects in other tables.
66 goto create_new_object
;
68 status
= acpi_ns_lookup(walk_state
->scope_info
,
69 op
->common
.value
.string
,
72 ACPI_NS_SEARCH_PARENT
|
73 ACPI_NS_DONT_OPEN_SCOPE
,
75 ACPI_CAST_INDIRECT_PTR
79 if (ACPI_FAILURE(status
)) {
80 ACPI_ERROR_NAMESPACE(walk_state
->
84 return_ACPI_STATUS(status
);
92 /* Create and init a new internal ACPI object */
94 obj_desc
= acpi_ut_create_internal_object((acpi_ps_get_opcode_info
95 (op
->common
.aml_opcode
))->
98 return_ACPI_STATUS(AE_NO_MEMORY
);
102 acpi_ds_init_object_from_op(walk_state
, op
, op
->common
.aml_opcode
,
104 if (ACPI_FAILURE(status
)) {
105 acpi_ut_remove_reference(obj_desc
);
106 return_ACPI_STATUS(status
);
110 * Handling for unresolved package reference elements.
111 * These are elements that are namepaths.
113 if ((op
->common
.parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
114 (op
->common
.parent
->common
.aml_opcode
== AML_VARIABLE_PACKAGE_OP
)) {
115 obj_desc
->reference
.resolved
= TRUE
;
117 if ((op
->common
.aml_opcode
== AML_INT_NAMEPATH_OP
) &&
118 !obj_desc
->reference
.node
) {
120 * Name was unresolved above.
121 * Get the prefix node for later lookup
123 obj_desc
->reference
.node
=
124 walk_state
->scope_info
->scope
.node
;
125 obj_desc
->reference
.aml
= op
->common
.aml
;
126 obj_desc
->reference
.resolved
= FALSE
;
130 *obj_desc_ptr
= obj_desc
;
131 return_ACPI_STATUS(status
);
134 /*******************************************************************************
136 * FUNCTION: acpi_ds_build_internal_buffer_obj
138 * PARAMETERS: walk_state - Current walk state
139 * op - Parser object to be translated
140 * buffer_length - Length of the buffer
141 * obj_desc_ptr - Where the ACPI internal object is returned
145 * DESCRIPTION: Translate a parser Op package object to the equivalent
148 ******************************************************************************/
151 acpi_ds_build_internal_buffer_obj(struct acpi_walk_state
*walk_state
,
152 union acpi_parse_object
*op
,
154 union acpi_operand_object
**obj_desc_ptr
)
156 union acpi_parse_object
*arg
;
157 union acpi_operand_object
*obj_desc
;
158 union acpi_parse_object
*byte_list
;
159 u32 byte_list_length
= 0;
161 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj
);
164 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
165 * The buffer object already exists (from the NS node), otherwise it must
168 obj_desc
= *obj_desc_ptr
;
171 /* Create a new buffer object */
173 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_BUFFER
);
174 *obj_desc_ptr
= obj_desc
;
176 return_ACPI_STATUS(AE_NO_MEMORY
);
181 * Second arg is the buffer data (optional) byte_list can be either
182 * individual bytes or a string initializer. In either case, a
183 * byte_list appears in the AML.
185 arg
= op
->common
.value
.arg
; /* skip first arg */
187 byte_list
= arg
->named
.next
;
189 if (byte_list
->common
.aml_opcode
!= AML_INT_BYTELIST_OP
) {
191 "Expecting bytelist, found AML opcode 0x%X in op %p",
192 byte_list
->common
.aml_opcode
, byte_list
));
194 acpi_ut_remove_reference(obj_desc
);
198 byte_list_length
= (u32
) byte_list
->common
.value
.integer
;
202 * The buffer length (number of bytes) will be the larger of:
203 * 1) The specified buffer length and
204 * 2) The length of the initializer byte list
206 obj_desc
->buffer
.length
= buffer_length
;
207 if (byte_list_length
> buffer_length
) {
208 obj_desc
->buffer
.length
= byte_list_length
;
211 /* Allocate the buffer */
213 if (obj_desc
->buffer
.length
== 0) {
214 obj_desc
->buffer
.pointer
= NULL
;
215 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
216 "Buffer defined with zero length in AML, creating\n"));
218 obj_desc
->buffer
.pointer
=
219 ACPI_ALLOCATE_ZEROED(obj_desc
->buffer
.length
);
220 if (!obj_desc
->buffer
.pointer
) {
221 acpi_ut_delete_object_desc(obj_desc
);
222 return_ACPI_STATUS(AE_NO_MEMORY
);
225 /* Initialize buffer from the byte_list (if present) */
228 memcpy(obj_desc
->buffer
.pointer
, byte_list
->named
.data
,
233 obj_desc
->buffer
.flags
|= AOPOBJ_DATA_VALID
;
234 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
235 return_ACPI_STATUS(AE_OK
);
238 /*******************************************************************************
240 * FUNCTION: acpi_ds_create_node
242 * PARAMETERS: walk_state - Current walk state
243 * node - NS Node to be initialized
244 * op - Parser object to be translated
248 * DESCRIPTION: Create the object to be associated with a namespace node
250 ******************************************************************************/
253 acpi_ds_create_node(struct acpi_walk_state
*walk_state
,
254 struct acpi_namespace_node
*node
,
255 union acpi_parse_object
*op
)
258 union acpi_operand_object
*obj_desc
;
260 ACPI_FUNCTION_TRACE_PTR(ds_create_node
, op
);
263 * Because of the execution pass through the non-control-method
264 * parts of the table, we can arrive here twice. Only init
265 * the named object node the first time through
267 if (acpi_ns_get_attached_object(node
)) {
268 return_ACPI_STATUS(AE_OK
);
271 if (!op
->common
.value
.arg
) {
273 /* No arguments, there is nothing to do */
275 return_ACPI_STATUS(AE_OK
);
278 /* Build an internal object for the argument(s) */
281 acpi_ds_build_internal_object(walk_state
, op
->common
.value
.arg
,
283 if (ACPI_FAILURE(status
)) {
284 return_ACPI_STATUS(status
);
287 /* Re-type the object according to its argument */
289 node
->type
= obj_desc
->common
.type
;
291 /* Attach obj to node */
293 status
= acpi_ns_attach_object(node
, obj_desc
, node
->type
);
295 /* Remove local reference to the object */
297 acpi_ut_remove_reference(obj_desc
);
298 return_ACPI_STATUS(status
);
301 /*******************************************************************************
303 * FUNCTION: acpi_ds_init_object_from_op
305 * PARAMETERS: walk_state - Current walk state
306 * op - Parser op used to init the internal object
307 * opcode - AML opcode associated with the object
308 * ret_obj_desc - Namespace object to be initialized
312 * DESCRIPTION: Initialize a namespace object from a parser Op and its
313 * associated arguments. The namespace object is a more compact
314 * representation of the Op and its arguments.
316 ******************************************************************************/
319 acpi_ds_init_object_from_op(struct acpi_walk_state
*walk_state
,
320 union acpi_parse_object
*op
,
322 union acpi_operand_object
**ret_obj_desc
)
324 const struct acpi_opcode_info
*op_info
;
325 union acpi_operand_object
*obj_desc
;
326 acpi_status status
= AE_OK
;
328 ACPI_FUNCTION_TRACE(ds_init_object_from_op
);
330 obj_desc
= *ret_obj_desc
;
331 op_info
= acpi_ps_get_opcode_info(opcode
);
332 if (op_info
->class == AML_CLASS_UNKNOWN
) {
336 return_ACPI_STATUS(AE_TYPE
);
339 /* Perform per-object initialization */
341 switch (obj_desc
->common
.type
) {
342 case ACPI_TYPE_BUFFER
:
344 * Defer evaluation of Buffer term_arg operand
346 obj_desc
->buffer
.node
=
347 ACPI_CAST_PTR(struct acpi_namespace_node
,
348 walk_state
->operands
[0]);
349 obj_desc
->buffer
.aml_start
= op
->named
.data
;
350 obj_desc
->buffer
.aml_length
= op
->named
.length
;
353 case ACPI_TYPE_PACKAGE
:
355 * Defer evaluation of Package term_arg operand and all
356 * package elements. (01/2017): We defer the element
357 * resolution to allow forward references from the package
358 * in order to provide compatibility with other ACPI
361 obj_desc
->package
.node
=
362 ACPI_CAST_PTR(struct acpi_namespace_node
,
363 walk_state
->operands
[0]);
365 if (!op
->named
.data
) {
366 return_ACPI_STATUS(AE_OK
);
369 obj_desc
->package
.aml_start
= op
->named
.data
;
370 obj_desc
->package
.aml_length
= op
->named
.length
;
373 case ACPI_TYPE_INTEGER
:
375 switch (op_info
->type
) {
376 case AML_TYPE_CONSTANT
:
378 * Resolve AML Constants here - AND ONLY HERE!
379 * All constants are integers.
380 * We mark the integer with a flag that indicates that it started
381 * life as a constant -- so that stores to constants will perform
382 * as expected (noop). zero_op is used as a placeholder for optional
385 obj_desc
->common
.flags
= AOPOBJ_AML_CONSTANT
;
390 obj_desc
->integer
.value
= 0;
395 obj_desc
->integer
.value
= 1;
400 obj_desc
->integer
.value
= ACPI_UINT64_MAX
;
402 /* Truncate value if we are executing from a 32-bit ACPI table */
404 (void)acpi_ex_truncate_for32bit_table(obj_desc
);
407 case AML_REVISION_OP
:
409 obj_desc
->integer
.value
= ACPI_CA_VERSION
;
415 "Unknown constant opcode 0x%X",
417 status
= AE_AML_OPERAND_TYPE
;
422 case AML_TYPE_LITERAL
:
424 obj_desc
->integer
.value
= op
->common
.value
.integer
;
426 if (acpi_ex_truncate_for32bit_table(obj_desc
)) {
428 /* Warn if we found a 64-bit constant in a 32-bit table */
430 ACPI_WARNING((AE_INFO
,
431 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
432 ACPI_FORMAT_UINT64(op
->common
.
434 (u32
)obj_desc
->integer
.value
));
440 ACPI_ERROR((AE_INFO
, "Unknown Integer type 0x%X",
442 status
= AE_AML_OPERAND_TYPE
;
447 case ACPI_TYPE_STRING
:
449 obj_desc
->string
.pointer
= op
->common
.value
.string
;
450 obj_desc
->string
.length
= (u32
)strlen(op
->common
.value
.string
);
453 * The string is contained in the ACPI table, don't ever try
456 obj_desc
->common
.flags
|= AOPOBJ_STATIC_POINTER
;
459 case ACPI_TYPE_METHOD
:
462 case ACPI_TYPE_LOCAL_REFERENCE
:
464 switch (op_info
->type
) {
465 case AML_TYPE_LOCAL_VARIABLE
:
467 /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */
469 obj_desc
->reference
.value
=
470 ((u32
)opcode
) - AML_FIRST_LOCAL_OP
;
471 obj_desc
->reference
.class = ACPI_REFCLASS_LOCAL
;
474 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL
,
477 ACPI_CAST_INDIRECT_PTR
480 &obj_desc
->reference
.
484 case AML_TYPE_METHOD_ARGUMENT
:
486 /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */
488 obj_desc
->reference
.value
=
489 ((u32
)opcode
) - AML_FIRST_ARG_OP
;
490 obj_desc
->reference
.class = ACPI_REFCLASS_ARG
;
492 status
= acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG
,
496 ACPI_CAST_INDIRECT_PTR
504 default: /* Object name or Debug object */
506 switch (op
->common
.aml_opcode
) {
507 case AML_INT_NAMEPATH_OP
:
509 /* Node was saved in Op */
511 obj_desc
->reference
.node
= op
->common
.node
;
512 obj_desc
->reference
.class = ACPI_REFCLASS_NAME
;
513 if (op
->common
.node
) {
514 obj_desc
->reference
.object
=
515 op
->common
.node
->object
;
521 obj_desc
->reference
.class = ACPI_REFCLASS_DEBUG
;
527 "Unimplemented reference type for AML opcode: 0x%4.4X",
529 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
537 ACPI_ERROR((AE_INFO
, "Unimplemented data type: 0x%X",
538 obj_desc
->common
.type
));
540 status
= AE_AML_OPERAND_TYPE
;
544 return_ACPI_STATUS(status
);