1 /******************************************************************************
3 * Module Name: dsargs - Support for execution of dynamic arguments for static
4 * objects (regions, fields, buffer fields, etc.)
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2015, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
52 #define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME("dsargs")
55 /* Local prototypes */
57 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
58 struct acpi_namespace_node *scope_node,
59 u32 aml_length, u8 *aml_start);
61 /*******************************************************************************
63 * FUNCTION: acpi_ds_execute_arguments
65 * PARAMETERS: node - Object NS node
66 * scope_node - Parent NS node
67 * aml_length - Length of executable AML
68 * aml_start - Pointer to the AML
72 * DESCRIPTION: Late (deferred) execution of region or field arguments
74 ******************************************************************************/
77 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
78 struct acpi_namespace_node *scope_node,
79 u32 aml_length, u8 *aml_start)
82 union acpi_parse_object *op;
83 struct acpi_walk_state *walk_state;
85 ACPI_FUNCTION_TRACE(ds_execute_arguments);
87 /* Allocate a new parser op to be the root of the parsed tree */
89 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
91 return_ACPI_STATUS(AE_NO_MEMORY);
94 /* Save the Node for use in acpi_ps_parse_aml */
96 op->common.node = scope_node;
98 /* Create and initialize a new parser state */
100 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
102 status = AE_NO_MEMORY;
106 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
107 aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
108 if (ACPI_FAILURE(status)) {
109 acpi_ds_delete_walk_state(walk_state);
113 /* Mark this parse as a deferred opcode */
115 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
116 walk_state->deferred_node = node;
118 /* Pass1: Parse the entire declaration */
120 status = acpi_ps_parse_aml(walk_state);
121 if (ACPI_FAILURE(status)) {
125 /* Get and init the Op created above */
127 op->common.node = node;
128 acpi_ps_delete_parse_tree(op);
130 /* Evaluate the deferred arguments */
132 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
134 return_ACPI_STATUS(AE_NO_MEMORY);
137 op->common.node = scope_node;
139 /* Create and initialize a new parser state */
141 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
143 status = AE_NO_MEMORY;
147 /* Execute the opcode and arguments */
149 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
150 aml_length, NULL, ACPI_IMODE_EXECUTE);
151 if (ACPI_FAILURE(status)) {
152 acpi_ds_delete_walk_state(walk_state);
156 /* Mark this execution as a deferred opcode */
158 walk_state->deferred_node = node;
159 status = acpi_ps_parse_aml(walk_state);
162 acpi_ps_delete_parse_tree(op);
163 return_ACPI_STATUS(status);
166 /*******************************************************************************
168 * FUNCTION: acpi_ds_get_buffer_field_arguments
170 * PARAMETERS: obj_desc - A valid buffer_field object
174 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
175 * evaluation of these field attributes.
177 ******************************************************************************/
180 acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
182 union acpi_operand_object *extra_desc;
183 struct acpi_namespace_node *node;
186 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc);
188 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
189 return_ACPI_STATUS(AE_OK);
192 /* Get the AML pointer (method object) and buffer_field node */
194 extra_desc = acpi_ns_get_secondary_object(obj_desc);
195 node = obj_desc->buffer_field.node;
197 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_BUFFER_FIELD,
200 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
201 acpi_ut_get_node_name(node)));
203 /* Execute the AML code for the term_arg arguments */
205 status = acpi_ds_execute_arguments(node, node->parent,
206 extra_desc->extra.aml_length,
207 extra_desc->extra.aml_start);
208 return_ACPI_STATUS(status);
211 /*******************************************************************************
213 * FUNCTION: acpi_ds_get_bank_field_arguments
215 * PARAMETERS: obj_desc - A valid bank_field object
219 * DESCRIPTION: Get bank_field bank_value. This implements the late
220 * evaluation of these field attributes.
222 ******************************************************************************/
225 acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc)
227 union acpi_operand_object *extra_desc;
228 struct acpi_namespace_node *node;
231 ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc);
233 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
234 return_ACPI_STATUS(AE_OK);
237 /* Get the AML pointer (method object) and bank_field node */
239 extra_desc = acpi_ns_get_secondary_object(obj_desc);
240 node = obj_desc->bank_field.node;
242 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
243 (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL));
245 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
246 acpi_ut_get_node_name(node)));
248 /* Execute the AML code for the term_arg arguments */
250 status = acpi_ds_execute_arguments(node, node->parent,
251 extra_desc->extra.aml_length,
252 extra_desc->extra.aml_start);
253 if (ACPI_FAILURE(status)) {
254 return_ACPI_STATUS(status);
257 status = acpi_ut_add_address_range(obj_desc->region.space_id,
258 obj_desc->region.address,
259 obj_desc->region.length, node);
260 return_ACPI_STATUS(status);
263 /*******************************************************************************
265 * FUNCTION: acpi_ds_get_buffer_arguments
267 * PARAMETERS: obj_desc - A valid Buffer object
271 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
272 * the late evaluation of these attributes.
274 ******************************************************************************/
276 acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
278 struct acpi_namespace_node *node;
281 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
283 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
284 return_ACPI_STATUS(AE_OK);
287 /* Get the Buffer node */
289 node = obj_desc->buffer.node;
292 "No pointer back to namespace node in buffer object %p",
294 return_ACPI_STATUS(AE_AML_INTERNAL);
297 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
299 /* Execute the AML code for the term_arg arguments */
301 status = acpi_ds_execute_arguments(node, node,
302 obj_desc->buffer.aml_length,
303 obj_desc->buffer.aml_start);
304 return_ACPI_STATUS(status);
307 /*******************************************************************************
309 * FUNCTION: acpi_ds_get_package_arguments
311 * PARAMETERS: obj_desc - A valid Package object
315 * DESCRIPTION: Get Package length and initializer byte list. This implements
316 * the late evaluation of these attributes.
318 ******************************************************************************/
320 acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
322 struct acpi_namespace_node *node;
325 ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
327 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
328 return_ACPI_STATUS(AE_OK);
331 /* Get the Package node */
333 node = obj_desc->package.node;
336 "No pointer back to namespace node in package %p",
338 return_ACPI_STATUS(AE_AML_INTERNAL);
341 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
343 /* Execute the AML code for the term_arg arguments */
345 status = acpi_ds_execute_arguments(node, node,
346 obj_desc->package.aml_length,
347 obj_desc->package.aml_start);
348 return_ACPI_STATUS(status);
351 /*******************************************************************************
353 * FUNCTION: acpi_ds_get_region_arguments
355 * PARAMETERS: obj_desc - A valid region object
359 * DESCRIPTION: Get region address and length. This implements the late
360 * evaluation of these region attributes.
362 ******************************************************************************/
364 acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
366 struct acpi_namespace_node *node;
368 union acpi_operand_object *extra_desc;
370 ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc);
372 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
373 return_ACPI_STATUS(AE_OK);
376 extra_desc = acpi_ns_get_secondary_object(obj_desc);
378 return_ACPI_STATUS(AE_NOT_EXIST);
381 /* Get the Region node */
383 node = obj_desc->region.node;
385 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
386 (ACPI_TYPE_REGION, node, NULL));
388 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
389 acpi_ut_get_node_name(node),
390 extra_desc->extra.aml_start));
392 /* Execute the argument AML */
394 status = acpi_ds_execute_arguments(node, extra_desc->extra.scope_node,
395 extra_desc->extra.aml_length,
396 extra_desc->extra.aml_start);
397 if (ACPI_FAILURE(status)) {
398 return_ACPI_STATUS(status);
401 status = acpi_ut_add_address_range(obj_desc->region.space_id,
402 obj_desc->region.address,
403 obj_desc->region.length, node);
404 return_ACPI_STATUS(status);