1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: dsargs - Support for execution of dynamic arguments for static
5 * objects (regions, fields, buffer fields, etc.)
7 * Copyright (C) 2000 - 2020, Intel Corp.
9 *****************************************************************************/
11 #include <acpi/acpi.h>
18 #define _COMPONENT ACPI_DISPATCHER
19 ACPI_MODULE_NAME("dsargs")
21 /* Local prototypes */
23 acpi_ds_execute_arguments(struct acpi_namespace_node
*node
,
24 struct acpi_namespace_node
*scope_node
,
25 u32 aml_length
, u8
*aml_start
);
27 /*******************************************************************************
29 * FUNCTION: acpi_ds_execute_arguments
31 * PARAMETERS: node - Object NS node
32 * scope_node - Parent NS node
33 * aml_length - Length of executable AML
34 * aml_start - Pointer to the AML
38 * DESCRIPTION: Late (deferred) execution of region or field arguments
40 ******************************************************************************/
43 acpi_ds_execute_arguments(struct acpi_namespace_node
*node
,
44 struct acpi_namespace_node
*scope_node
,
45 u32 aml_length
, u8
*aml_start
)
48 union acpi_parse_object
*op
;
49 struct acpi_walk_state
*walk_state
;
51 ACPI_FUNCTION_TRACE_PTR(ds_execute_arguments
, aml_start
);
53 /* Allocate a new parser op to be the root of the parsed tree */
55 op
= acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP
, aml_start
);
57 return_ACPI_STATUS(AE_NO_MEMORY
);
60 /* Save the Node for use in acpi_ps_parse_aml */
62 op
->common
.node
= scope_node
;
64 /* Create and initialize a new parser state */
66 walk_state
= acpi_ds_create_walk_state(0, NULL
, NULL
, NULL
);
68 status
= AE_NO_MEMORY
;
72 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
, aml_start
,
73 aml_length
, NULL
, ACPI_IMODE_LOAD_PASS1
);
74 if (ACPI_FAILURE(status
)) {
75 acpi_ds_delete_walk_state(walk_state
);
79 /* Mark this parse as a deferred opcode */
81 walk_state
->parse_flags
= ACPI_PARSE_DEFERRED_OP
;
82 walk_state
->deferred_node
= node
;
84 /* Pass1: Parse the entire declaration */
86 status
= acpi_ps_parse_aml(walk_state
);
87 if (ACPI_FAILURE(status
)) {
91 /* Get and init the Op created above */
93 op
->common
.node
= node
;
94 acpi_ps_delete_parse_tree(op
);
96 /* Evaluate the deferred arguments */
98 op
= acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP
, aml_start
);
100 return_ACPI_STATUS(AE_NO_MEMORY
);
103 op
->common
.node
= scope_node
;
105 /* Create and initialize a new parser state */
107 walk_state
= acpi_ds_create_walk_state(0, NULL
, NULL
, NULL
);
109 status
= AE_NO_MEMORY
;
113 /* Execute the opcode and arguments */
115 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
, aml_start
,
116 aml_length
, NULL
, ACPI_IMODE_EXECUTE
);
117 if (ACPI_FAILURE(status
)) {
118 acpi_ds_delete_walk_state(walk_state
);
122 /* Mark this execution as a deferred opcode */
124 walk_state
->deferred_node
= node
;
125 status
= acpi_ps_parse_aml(walk_state
);
128 acpi_ps_delete_parse_tree(op
);
129 return_ACPI_STATUS(status
);
132 /*******************************************************************************
134 * FUNCTION: acpi_ds_get_buffer_field_arguments
136 * PARAMETERS: obj_desc - A valid buffer_field object
140 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
141 * evaluation of these field attributes.
143 ******************************************************************************/
146 acpi_ds_get_buffer_field_arguments(union acpi_operand_object
*obj_desc
)
148 union acpi_operand_object
*extra_desc
;
149 struct acpi_namespace_node
*node
;
152 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments
, obj_desc
);
154 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
155 return_ACPI_STATUS(AE_OK
);
158 /* Get the AML pointer (method object) and buffer_field node */
160 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
161 node
= obj_desc
->buffer_field
.node
;
163 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
164 (ACPI_TYPE_BUFFER_FIELD
, node
, NULL
));
166 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "[%4.4s] BufferField Arg Init\n",
167 acpi_ut_get_node_name(node
)));
169 /* Execute the AML code for the term_arg arguments */
171 status
= acpi_ds_execute_arguments(node
, node
->parent
,
172 extra_desc
->extra
.aml_length
,
173 extra_desc
->extra
.aml_start
);
174 return_ACPI_STATUS(status
);
177 /*******************************************************************************
179 * FUNCTION: acpi_ds_get_bank_field_arguments
181 * PARAMETERS: obj_desc - A valid bank_field object
185 * DESCRIPTION: Get bank_field bank_value. This implements the late
186 * evaluation of these field attributes.
188 ******************************************************************************/
191 acpi_ds_get_bank_field_arguments(union acpi_operand_object
*obj_desc
)
193 union acpi_operand_object
*extra_desc
;
194 struct acpi_namespace_node
*node
;
197 ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments
, obj_desc
);
199 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
200 return_ACPI_STATUS(AE_OK
);
203 /* Get the AML pointer (method object) and bank_field node */
205 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
206 node
= obj_desc
->bank_field
.node
;
208 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
209 (ACPI_TYPE_LOCAL_BANK_FIELD
, node
, NULL
));
211 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "[%4.4s] BankField Arg Init\n",
212 acpi_ut_get_node_name(node
)));
214 /* Execute the AML code for the term_arg arguments */
216 status
= acpi_ds_execute_arguments(node
, node
->parent
,
217 extra_desc
->extra
.aml_length
,
218 extra_desc
->extra
.aml_start
);
219 if (ACPI_FAILURE(status
)) {
220 return_ACPI_STATUS(status
);
223 status
= acpi_ut_add_address_range(obj_desc
->region
.space_id
,
224 obj_desc
->region
.address
,
225 obj_desc
->region
.length
, node
);
226 return_ACPI_STATUS(status
);
229 /*******************************************************************************
231 * FUNCTION: acpi_ds_get_buffer_arguments
233 * PARAMETERS: obj_desc - A valid Buffer object
237 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
238 * the late evaluation of these attributes.
240 ******************************************************************************/
242 acpi_status
acpi_ds_get_buffer_arguments(union acpi_operand_object
*obj_desc
)
244 struct acpi_namespace_node
*node
;
247 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments
, obj_desc
);
249 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
250 return_ACPI_STATUS(AE_OK
);
253 /* Get the Buffer node */
255 node
= obj_desc
->buffer
.node
;
258 "No pointer back to namespace node in buffer object %p",
260 return_ACPI_STATUS(AE_AML_INTERNAL
);
263 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Buffer Arg Init\n"));
265 /* Execute the AML code for the term_arg arguments */
267 status
= acpi_ds_execute_arguments(node
, node
,
268 obj_desc
->buffer
.aml_length
,
269 obj_desc
->buffer
.aml_start
);
270 return_ACPI_STATUS(status
);
273 /*******************************************************************************
275 * FUNCTION: acpi_ds_get_package_arguments
277 * PARAMETERS: obj_desc - A valid Package object
281 * DESCRIPTION: Get Package length and initializer byte list. This implements
282 * the late evaluation of these attributes.
284 ******************************************************************************/
286 acpi_status
acpi_ds_get_package_arguments(union acpi_operand_object
*obj_desc
)
288 struct acpi_namespace_node
*node
;
291 ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments
, obj_desc
);
293 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
294 return_ACPI_STATUS(AE_OK
);
297 /* Get the Package node */
299 node
= obj_desc
->package
.node
;
302 "No pointer back to namespace node in package %p",
304 return_ACPI_STATUS(AE_AML_INTERNAL
);
307 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Package Argument Init, AML Ptr: %p\n",
308 obj_desc
->package
.aml_start
));
310 /* Execute the AML code for the term_arg arguments */
312 status
= acpi_ds_execute_arguments(node
, node
,
313 obj_desc
->package
.aml_length
,
314 obj_desc
->package
.aml_start
);
316 return_ACPI_STATUS(status
);
319 /*******************************************************************************
321 * FUNCTION: acpi_ds_get_region_arguments
323 * PARAMETERS: obj_desc - A valid region object
327 * DESCRIPTION: Get region address and length. This implements the late
328 * evaluation of these region attributes.
330 ******************************************************************************/
332 acpi_status
acpi_ds_get_region_arguments(union acpi_operand_object
*obj_desc
)
334 struct acpi_namespace_node
*node
;
336 union acpi_operand_object
*extra_desc
;
338 ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments
, obj_desc
);
340 if (obj_desc
->region
.flags
& AOPOBJ_DATA_VALID
) {
341 return_ACPI_STATUS(AE_OK
);
344 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
346 return_ACPI_STATUS(AE_NOT_EXIST
);
349 /* Get the Region node */
351 node
= obj_desc
->region
.node
;
353 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
354 (ACPI_TYPE_REGION
, node
, NULL
));
356 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
357 "[%4.4s] OpRegion Arg Init at AML %p\n",
358 acpi_ut_get_node_name(node
),
359 extra_desc
->extra
.aml_start
));
361 /* Execute the argument AML */
363 status
= acpi_ds_execute_arguments(node
, extra_desc
->extra
.scope_node
,
364 extra_desc
->extra
.aml_length
,
365 extra_desc
->extra
.aml_start
);
366 if (ACPI_FAILURE(status
)) {
367 return_ACPI_STATUS(status
);
370 status
= acpi_ut_add_address_range(obj_desc
->region
.space_id
,
371 obj_desc
->region
.address
,
372 obj_desc
->region
.length
, node
);
373 return_ACPI_STATUS(status
);