blob: 8a690a9963f2b18599ef9908487e543cbbe0b790 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
5 *
6 *****************************************************************************/
7
8/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
26 *
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.
30 *
31 * NO WARRANTY
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.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acparser.h>
47#include <acpi/amlcode.h>
48#include <acpi/acdispat.h>
49#include <acpi/acinterp.h>
50#include <acpi/acnamesp.h>
51#include <acpi/acevents.h>
52
53#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040054ACPI_MODULE_NAME("dsopcode")
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Robert Moore44f6c012005-04-18 22:49:35 -040056/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040057static acpi_status
58acpi_ds_execute_arguments(struct acpi_namespace_node *node,
59 struct acpi_namespace_node *scope_node,
60 u32 aml_length, u8 * aml_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Robert Moore44f6c012005-04-18 22:49:35 -040062static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040063acpi_ds_init_buffer_field(u16 aml_opcode,
64 union acpi_operand_object *obj_desc,
65 union acpi_operand_object *buffer_desc,
66 union acpi_operand_object *offset_desc,
67 union acpi_operand_object *length_desc,
68 union acpi_operand_object *result_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040069
70/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 *
72 * FUNCTION: acpi_ds_execute_arguments
73 *
Robert Moore44f6c012005-04-18 22:49:35 -040074 * PARAMETERS: Node - Object NS node
75 * scope_node - Parent NS node
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 * aml_length - Length of executable AML
77 * aml_start - Pointer to the AML
78 *
79 * RETURN: Status.
80 *
81 * DESCRIPTION: Late (deferred) execution of region or field arguments
82 *
Robert Moore44f6c012005-04-18 22:49:35 -040083 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Robert Moore44f6c012005-04-18 22:49:35 -040085static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040086acpi_ds_execute_arguments(struct acpi_namespace_node *node,
87 struct acpi_namespace_node *scope_node,
88 u32 aml_length, u8 * aml_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Len Brown4be44fc2005-08-05 00:44:28 -040090 acpi_status status;
91 union acpi_parse_object *op;
92 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Len Brown4be44fc2005-08-05 00:44:28 -040094 ACPI_FUNCTION_TRACE("ds_execute_arguments");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /*
97 * Allocate a new parser op to be the root of the parsed tree
98 */
Len Brown4be44fc2005-08-05 00:44:28 -040099 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (!op) {
Len Brown4be44fc2005-08-05 00:44:28 -0400101 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103
104 /* Save the Node for use in acpi_ps_parse_aml */
105
106 op->common.node = scope_node;
107
108 /* Create and initialize a new parser state */
109
Len Brown4be44fc2005-08-05 00:44:28 -0400110 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (!walk_state) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400112 status = AE_NO_MEMORY;
113 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
Len Brown4be44fc2005-08-05 00:44:28 -0400116 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
117 aml_length, NULL, 1);
118 if (ACPI_FAILURE(status)) {
119 acpi_ds_delete_walk_state(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400120 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
123 /* Mark this parse as a deferred opcode */
124
125 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
126 walk_state->deferred_node = node;
127
128 /* Pass1: Parse the entire declaration */
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 status = acpi_ps_parse_aml(walk_state);
131 if (ACPI_FAILURE(status)) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400132 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
135 /* Get and init the Op created above */
136
137 op->common.node = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 acpi_ps_delete_parse_tree(op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* Evaluate the deferred arguments */
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!op) {
Len Brown4be44fc2005-08-05 00:44:28 -0400144 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146
147 op->common.node = scope_node;
148
149 /* Create and initialize a new parser state */
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (!walk_state) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400153 status = AE_NO_MEMORY;
154 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 }
156
157 /* Execute the opcode and arguments */
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
160 aml_length, NULL, 3);
161 if (ACPI_FAILURE(status)) {
162 acpi_ds_delete_walk_state(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400163 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
166 /* Mark this execution as a deferred opcode */
167
168 walk_state->deferred_node = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400169 status = acpi_ps_parse_aml(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 cleanup:
172 acpi_ps_delete_parse_tree(op);
173 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Robert Moore44f6c012005-04-18 22:49:35 -0400176/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 *
178 * FUNCTION: acpi_ds_get_buffer_field_arguments
179 *
180 * PARAMETERS: obj_desc - A valid buffer_field object
181 *
182 * RETURN: Status.
183 *
184 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
185 * evaluation of these field attributes.
186 *
Robert Moore44f6c012005-04-18 22:49:35 -0400187 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400190acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Len Brown4be44fc2005-08-05 00:44:28 -0400192 union acpi_operand_object *extra_desc;
193 struct acpi_namespace_node *node;
194 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 ACPI_FUNCTION_TRACE_PTR("ds_get_buffer_field_arguments", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 /* Get the AML pointer (method object) and buffer_field node */
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 extra_desc = acpi_ns_get_secondary_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 node = obj_desc->buffer_field.node;
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
208 (ACPI_TYPE_BUFFER_FIELD, node, NULL));
209 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
210 acpi_ut_get_node_name(node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 /* Execute the AML code for the term_arg arguments */
213
Len Brown4be44fc2005-08-05 00:44:28 -0400214 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
215 extra_desc->extra.aml_length,
216 extra_desc->extra.aml_start);
217 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
Robert Moore44f6c012005-04-18 22:49:35 -0400220/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 *
222 * FUNCTION: acpi_ds_get_buffer_arguments
223 *
224 * PARAMETERS: obj_desc - A valid Buffer object
225 *
226 * RETURN: Status.
227 *
228 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
229 * the late evaluation of these attributes.
230 *
Robert Moore44f6c012005-04-18 22:49:35 -0400231 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Len Brown4be44fc2005-08-05 00:44:28 -0400233acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Len Brown4be44fc2005-08-05 00:44:28 -0400235 struct acpi_namespace_node *node;
236 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Len Brown4be44fc2005-08-05 00:44:28 -0400238 ACPI_FUNCTION_TRACE_PTR("ds_get_buffer_arguments", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400241 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243
244 /* Get the Buffer node */
245
246 node = obj_desc->buffer.node;
247 if (!node) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500248 ACPI_ERROR((AE_INFO,
249 "No pointer back to NS node in buffer obj %p",
250 obj_desc));
Len Brown4be44fc2005-08-05 00:44:28 -0400251 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 /* Execute the AML code for the term_arg arguments */
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 status = acpi_ds_execute_arguments(node, node,
259 obj_desc->buffer.aml_length,
260 obj_desc->buffer.aml_start);
261 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Robert Moore44f6c012005-04-18 22:49:35 -0400264/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 *
266 * FUNCTION: acpi_ds_get_package_arguments
267 *
268 * PARAMETERS: obj_desc - A valid Package object
269 *
270 * RETURN: Status.
271 *
272 * DESCRIPTION: Get Package length and initializer byte list. This implements
273 * the late evaluation of these attributes.
274 *
Robert Moore44f6c012005-04-18 22:49:35 -0400275 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Len Brown4be44fc2005-08-05 00:44:28 -0400277acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Len Brown4be44fc2005-08-05 00:44:28 -0400279 struct acpi_namespace_node *node;
280 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 ACPI_FUNCTION_TRACE_PTR("ds_get_package_arguments", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
287
288 /* Get the Package node */
289
290 node = obj_desc->package.node;
291 if (!node) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500292 ACPI_ERROR((AE_INFO,
293 "No pointer back to NS node in package %p",
294 obj_desc));
Len Brown4be44fc2005-08-05 00:44:28 -0400295 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 /* Execute the AML code for the term_arg arguments */
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302 status = acpi_ds_execute_arguments(node, node,
303 obj_desc->package.aml_length,
304 obj_desc->package.aml_start);
305 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308/*****************************************************************************
309 *
310 * FUNCTION: acpi_ds_get_region_arguments
311 *
312 * PARAMETERS: obj_desc - A valid region object
313 *
314 * RETURN: Status.
315 *
316 * DESCRIPTION: Get region address and length. This implements the late
317 * evaluation of these region attributes.
318 *
319 ****************************************************************************/
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Len Brown4be44fc2005-08-05 00:44:28 -0400323 struct acpi_namespace_node *node;
324 acpi_status status;
325 union acpi_operand_object *extra_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 ACPI_FUNCTION_TRACE_PTR("ds_get_region_arguments", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400330 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332
Len Brown4be44fc2005-08-05 00:44:28 -0400333 extra_desc = acpi_ns_get_secondary_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (!extra_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400335 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 }
337
338 /* Get the Region node */
339
340 node = obj_desc->region.node;
341
Len Brown4be44fc2005-08-05 00:44:28 -0400342 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
343 (ACPI_TYPE_REGION, node, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
346 "[%4.4s] op_region Arg Init at AML %p\n",
347 acpi_ut_get_node_name(node),
348 extra_desc->extra.aml_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 /* Execute the argument AML */
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
353 extra_desc->extra.aml_length,
354 extra_desc->extra.aml_start);
355 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
Robert Moore44f6c012005-04-18 22:49:35 -0400358/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 *
360 * FUNCTION: acpi_ds_initialize_region
361 *
Robert Moore44f6c012005-04-18 22:49:35 -0400362 * PARAMETERS: obj_handle - Region namespace node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 *
364 * RETURN: Status
365 *
366 * DESCRIPTION: Front end to ev_initialize_region
367 *
Robert Moore44f6c012005-04-18 22:49:35 -0400368 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Len Brown4be44fc2005-08-05 00:44:28 -0400370acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown4be44fc2005-08-05 00:44:28 -0400372 union acpi_operand_object *obj_desc;
373 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 obj_desc = acpi_ns_get_attached_object(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /* Namespace is NOT locked */
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 status = acpi_ev_initialize_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return (status);
381}
382
Robert Moore44f6c012005-04-18 22:49:35 -0400383/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 *
385 * FUNCTION: acpi_ds_init_buffer_field
386 *
387 * PARAMETERS: aml_opcode - create_xxx_field
388 * obj_desc - buffer_field object
389 * buffer_desc - Host Buffer
390 * offset_desc - Offset into buffer
Robert Moore44f6c012005-04-18 22:49:35 -0400391 * length_desc - Length of field (CREATE_FIELD_OP only)
392 * result_desc - Where to store the result
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Perform actual initialization of a buffer field
397 *
Robert Moore44f6c012005-04-18 22:49:35 -0400398 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Robert Moore44f6c012005-04-18 22:49:35 -0400400static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_ds_init_buffer_field(u16 aml_opcode,
402 union acpi_operand_object *obj_desc,
403 union acpi_operand_object *buffer_desc,
404 union acpi_operand_object *offset_desc,
405 union acpi_operand_object *length_desc,
406 union acpi_operand_object *result_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Len Brown4be44fc2005-08-05 00:44:28 -0400408 u32 offset;
409 u32 bit_offset;
410 u32 bit_count;
411 u8 field_flags;
412 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 ACPI_FUNCTION_TRACE_PTR("ds_init_buffer_field", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 /* Host object must be a Buffer */
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500419 ACPI_ERROR((AE_INFO,
420 "Target of Create Field is not a Buffer object - %s",
421 acpi_ut_get_object_type_name(buffer_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 status = AE_AML_OPERAND_TYPE;
424 goto cleanup;
425 }
426
427 /*
428 * The last parameter to all of these opcodes (result_desc) started
429 * out as a name_string, and should therefore now be a NS node
430 * after resolution in acpi_ex_resolve_operands().
431 */
Len Brown4be44fc2005-08-05 00:44:28 -0400432 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500433 ACPI_ERROR((AE_INFO,
434 "(%s) destination not a NS Node [%s]",
435 acpi_ps_get_opcode_name(aml_opcode),
436 acpi_ut_get_descriptor_name(result_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 status = AE_AML_OPERAND_TYPE;
439 goto cleanup;
440 }
441
442 offset = (u32) offset_desc->integer.value;
443
444 /*
445 * Setup the Bit offsets and counts, according to the opcode
446 */
447 switch (aml_opcode) {
448 case AML_CREATE_FIELD_OP:
449
450 /* Offset is in bits, count is in bits */
451
Robert Moore44f6c012005-04-18 22:49:35 -0400452 field_flags = AML_FIELD_ACCESS_BYTE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 bit_count = (u32) length_desc->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400455
456 /* Must have a valid (>0) bit count */
457
458 if (bit_count == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500459 ACPI_ERROR((AE_INFO,
460 "Attempt to create_field of length zero"));
Robert Moore44f6c012005-04-18 22:49:35 -0400461 status = AE_AML_OPERAND_VALUE;
462 goto cleanup;
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465
466 case AML_CREATE_BIT_FIELD_OP:
467
468 /* Offset is in bits, Field is one bit */
469
470 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400471 bit_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 field_flags = AML_FIELD_ACCESS_BYTE;
473 break;
474
475 case AML_CREATE_BYTE_FIELD_OP:
476
477 /* Offset is in bytes, field is one byte */
478
479 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400480 bit_count = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 field_flags = AML_FIELD_ACCESS_BYTE;
482 break;
483
484 case AML_CREATE_WORD_FIELD_OP:
485
486 /* Offset is in bytes, field is one word */
487
488 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400489 bit_count = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 field_flags = AML_FIELD_ACCESS_WORD;
491 break;
492
493 case AML_CREATE_DWORD_FIELD_OP:
494
495 /* Offset is in bytes, field is one dword */
496
497 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 bit_count = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 field_flags = AML_FIELD_ACCESS_DWORD;
500 break;
501
502 case AML_CREATE_QWORD_FIELD_OP:
503
504 /* Offset is in bytes, field is one qword */
505
506 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400507 bit_count = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 field_flags = AML_FIELD_ACCESS_QWORD;
509 break;
510
511 default:
512
Bob Mooreb8e4d892006-01-27 16:43:00 -0500513 ACPI_ERROR((AE_INFO,
514 "Unknown field creation opcode %02x", aml_opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 status = AE_AML_BAD_OPCODE;
516 goto cleanup;
517 }
518
519 /* Entire field must fit within the current length of the buffer */
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500522 ACPI_ERROR((AE_INFO,
523 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
524 acpi_ut_get_node_name(result_desc),
525 bit_offset + bit_count,
526 acpi_ut_get_node_name(buffer_desc->buffer.node),
527 8 * (u32) buffer_desc->buffer.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 status = AE_AML_BUFFER_LIMIT;
529 goto cleanup;
530 }
531
532 /*
533 * Initialize areas of the field object that are common to all fields
Robert Moore44f6c012005-04-18 22:49:35 -0400534 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
535 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 */
Len Brown4be44fc2005-08-05 00:44:28 -0400537 status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
538 bit_offset, bit_count);
539 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 goto cleanup;
541 }
542
543 obj_desc->buffer_field.buffer_obj = buffer_desc;
544
545 /* Reference count for buffer_desc inherits obj_desc count */
546
Robert Moore44f6c012005-04-18 22:49:35 -0400547 buffer_desc->common.reference_count = (u16)
Len Brown4be44fc2005-08-05 00:44:28 -0400548 (buffer_desc->common.reference_count +
549 obj_desc->common.reference_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 /* Always delete the operands */
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_ut_remove_reference(offset_desc);
556 acpi_ut_remove_reference(buffer_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 if (aml_opcode == AML_CREATE_FIELD_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400559 acpi_ut_remove_reference(length_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
562 /* On failure, delete the result descriptor */
563
Len Brown4be44fc2005-08-05 00:44:28 -0400564 if (ACPI_FAILURE(status)) {
565 acpi_ut_remove_reference(result_desc); /* Result descriptor */
566 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 /* Now the address and length are valid for this buffer_field */
568
569 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
570 }
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Robert Moore44f6c012005-04-18 22:49:35 -0400575/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *
577 * FUNCTION: acpi_ds_eval_buffer_field_operands
578 *
579 * PARAMETERS: walk_state - Current walk
580 * Op - A valid buffer_field Op object
581 *
582 * RETURN: Status
583 *
584 * DESCRIPTION: Get buffer_field Buffer and Index
585 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
586 *
Robert Moore44f6c012005-04-18 22:49:35 -0400587 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400590acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
591 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Len Brown4be44fc2005-08-05 00:44:28 -0400593 acpi_status status;
594 union acpi_operand_object *obj_desc;
595 struct acpi_namespace_node *node;
596 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Len Brown4be44fc2005-08-05 00:44:28 -0400598 ACPI_FUNCTION_TRACE_PTR("ds_eval_buffer_field_operands", op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 /*
601 * This is where we evaluate the address and length fields of the
602 * create_xxx_field declaration
603 */
Len Brown4be44fc2005-08-05 00:44:28 -0400604 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* next_op points to the op that holds the Buffer */
607
608 next_op = op->common.value.arg;
609
610 /* Evaluate/create the address and length operands */
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 status = acpi_ds_create_operands(walk_state, next_op);
613 if (ACPI_FAILURE(status)) {
614 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
622 /* Resolve the operands */
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 status = acpi_ex_resolve_operands(op->common.aml_opcode,
625 ACPI_WALK_OPERANDS, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Len Brown4be44fc2005-08-05 00:44:28 -0400627 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
628 acpi_ps_get_opcode_name(op->common.aml_opcode),
629 walk_state->num_operands,
630 "after acpi_ex_resolve_operands");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Len Brown4be44fc2005-08-05 00:44:28 -0400632 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500633 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
634 acpi_ps_get_opcode_name(op->common.aml_opcode),
635 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639
640 /* Initialize the Buffer Field */
641
642 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 /* NOTE: Slightly different operands for this opcode */
645
Len Brown4be44fc2005-08-05 00:44:28 -0400646 status =
647 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
648 walk_state->operands[0],
649 walk_state->operands[1],
650 walk_state->operands[2],
651 walk_state->operands[3]);
652 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* All other, create_xxx_field opcodes */
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 status =
656 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
657 walk_state->operands[0],
658 walk_state->operands[1], NULL,
659 walk_state->operands[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Robert Moore44f6c012005-04-18 22:49:35 -0400665/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 *
667 * FUNCTION: acpi_ds_eval_region_operands
668 *
669 * PARAMETERS: walk_state - Current walk
670 * Op - A valid region Op object
671 *
672 * RETURN: Status
673 *
674 * DESCRIPTION: Get region address and length
675 * Called from acpi_ds_exec_end_op during op_region parse tree walk
676 *
Robert Moore44f6c012005-04-18 22:49:35 -0400677 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400680acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
681 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Len Brown4be44fc2005-08-05 00:44:28 -0400683 acpi_status status;
684 union acpi_operand_object *obj_desc;
685 union acpi_operand_object *operand_desc;
686 struct acpi_namespace_node *node;
687 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 ACPI_FUNCTION_TRACE_PTR("ds_eval_region_operands", op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400692 * This is where we evaluate the address and length fields of the
693 * op_region declaration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 */
Len Brown4be44fc2005-08-05 00:44:28 -0400695 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697 /* next_op points to the op that holds the space_iD */
698
699 next_op = op->common.value.arg;
700
701 /* next_op points to address op */
702
703 next_op = next_op->common.next;
704
705 /* Evaluate/create the address and length operands */
706
Len Brown4be44fc2005-08-05 00:44:28 -0400707 status = acpi_ds_create_operands(walk_state, next_op);
708 if (ACPI_FAILURE(status)) {
709 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
711
712 /* Resolve the length and address operands to numbers */
713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 status = acpi_ex_resolve_operands(op->common.aml_opcode,
715 ACPI_WALK_OPERANDS, walk_state);
716 if (ACPI_FAILURE(status)) {
717 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719
Len Brown4be44fc2005-08-05 00:44:28 -0400720 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
721 acpi_ps_get_opcode_name(op->common.aml_opcode),
722 1, "after acpi_ex_resolve_operands");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Len Brown4be44fc2005-08-05 00:44:28 -0400724 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400726 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
729 /*
730 * Get the length operand and save it
731 * (at Top of stack)
732 */
733 operand_desc = walk_state->operands[walk_state->num_operands - 1];
734
735 obj_desc->region.length = (u32) operand_desc->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400736 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 /*
739 * Get the address and save it
740 * (at top of stack - 1)
741 */
742 operand_desc = walk_state->operands[walk_state->num_operands - 2];
743
Robert Moore44f6c012005-04-18 22:49:35 -0400744 obj_desc->region.address = (acpi_physical_address)
Len Brown4be44fc2005-08-05 00:44:28 -0400745 operand_desc->integer.value;
746 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
749 obj_desc,
750 ACPI_FORMAT_UINT64(obj_desc->region.address),
751 obj_desc->region.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* Now the address and length are valid for this opregion */
754
755 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
Robert Moore44f6c012005-04-18 22:49:35 -0400760/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 *
762 * FUNCTION: acpi_ds_eval_data_object_operands
763 *
764 * PARAMETERS: walk_state - Current walk
765 * Op - A valid data_object Op object
766 * obj_desc - data_object
767 *
768 * RETURN: Status
769 *
770 * DESCRIPTION: Get the operands and complete the following data object types:
771 * Buffer, Package.
772 *
Robert Moore44f6c012005-04-18 22:49:35 -0400773 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400776acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
777 union acpi_parse_object *op,
778 union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Len Brown4be44fc2005-08-05 00:44:28 -0400780 acpi_status status;
781 union acpi_operand_object *arg_desc;
782 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Len Brown4be44fc2005-08-05 00:44:28 -0400784 ACPI_FUNCTION_TRACE("ds_eval_data_object_operands");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 /* The first operand (for all of these data objects) is the length */
787
Len Brown4be44fc2005-08-05 00:44:28 -0400788 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
789 if (ACPI_FAILURE(status)) {
790 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792
Len Brown4be44fc2005-08-05 00:44:28 -0400793 status = acpi_ex_resolve_operands(walk_state->opcode,
794 &(walk_state->
795 operands[walk_state->num_operands -
796 1]), walk_state);
797 if (ACPI_FAILURE(status)) {
798 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800
801 /* Extract length operand */
802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 arg_desc = walk_state->operands[walk_state->num_operands - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 length = (u32) arg_desc->integer.value;
805
806 /* Cleanup for length operand */
807
Len Brown4be44fc2005-08-05 00:44:28 -0400808 status = acpi_ds_obj_stack_pop(1, walk_state);
809 if (ACPI_FAILURE(status)) {
810 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
812
Len Brown4be44fc2005-08-05 00:44:28 -0400813 acpi_ut_remove_reference(arg_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /*
816 * Create the actual data object
817 */
818 switch (op->common.aml_opcode) {
819 case AML_BUFFER_OP:
820
Len Brown4be44fc2005-08-05 00:44:28 -0400821 status =
822 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
823 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
825
826 case AML_PACKAGE_OP:
827 case AML_VAR_PACKAGE_OP:
828
Len Brown4be44fc2005-08-05 00:44:28 -0400829 status =
830 acpi_ds_build_internal_package_obj(walk_state, op, length,
831 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 break;
833
834 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400835 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
Len Brown4be44fc2005-08-05 00:44:28 -0400838 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400840 * Return the object in the walk_state, unless the parent is a package -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 * in this case, the return object will be stored in the parse tree
842 * for the package.
843 */
844 if ((!op->common.parent) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400845 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
846 (op->common.parent->common.aml_opcode !=
847 AML_VAR_PACKAGE_OP)
848 && (op->common.parent->common.aml_opcode !=
849 AML_NAME_OP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 walk_state->result_obj = obj_desc;
851 }
852 }
853
Len Brown4be44fc2005-08-05 00:44:28 -0400854 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/*******************************************************************************
858 *
859 * FUNCTION: acpi_ds_exec_begin_control_op
860 *
861 * PARAMETERS: walk_list - The list that owns the walk stack
862 * Op - The control Op
863 *
864 * RETURN: Status
865 *
866 * DESCRIPTION: Handles all control ops encountered during control method
867 * execution.
868 *
869 ******************************************************************************/
870
871acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400872acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
873 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Len Brown4be44fc2005-08-05 00:44:28 -0400875 acpi_status status = AE_OK;
876 union acpi_generic_state *control_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Len Brown4be44fc2005-08-05 00:44:28 -0400878 ACPI_FUNCTION_NAME("ds_exec_begin_control_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Len Brown4be44fc2005-08-05 00:44:28 -0400880 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
881 op->common.aml_opcode, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 switch (op->common.aml_opcode) {
884 case AML_IF_OP:
885 case AML_WHILE_OP:
886
887 /*
888 * IF/WHILE: Create a new control state to manage these
889 * constructs. We need to manage these as a stack, in order
890 * to handle nesting.
891 */
Len Brown4be44fc2005-08-05 00:44:28 -0400892 control_state = acpi_ut_create_control_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (!control_state) {
894 status = AE_NO_MEMORY;
895 break;
896 }
897 /*
898 * Save a pointer to the predicate for multiple executions
899 * of a loop
900 */
Len Brown4be44fc2005-08-05 00:44:28 -0400901 control_state->control.aml_predicate_start =
902 walk_state->parser_state.aml - 1;
903 control_state->control.package_end =
904 walk_state->parser_state.pkg_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 control_state->control.opcode = op->common.aml_opcode;
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 /* Push the control state on this walk's control stack */
908
Len Brown4be44fc2005-08-05 00:44:28 -0400909 acpi_ut_push_generic_state(&walk_state->control_state,
910 control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 break;
912
913 case AML_ELSE_OP:
914
915 /* Predicate is in the state object */
916 /* If predicate is true, the IF was executed, ignore ELSE part */
917
918 if (walk_state->last_predicate) {
919 status = AE_CTRL_TRUE;
920 }
921
922 break;
923
924 case AML_RETURN_OP:
925
926 break;
927
928 default:
929 break;
930 }
931
932 return (status);
933}
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935/*******************************************************************************
936 *
937 * FUNCTION: acpi_ds_exec_end_control_op
938 *
939 * PARAMETERS: walk_list - The list that owns the walk stack
940 * Op - The control Op
941 *
942 * RETURN: Status
943 *
944 * DESCRIPTION: Handles all control ops encountered during control method
945 * execution.
946 *
947 ******************************************************************************/
948
949acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400950acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
951 union acpi_parse_object * op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Len Brown4be44fc2005-08-05 00:44:28 -0400953 acpi_status status = AE_OK;
954 union acpi_generic_state *control_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Len Brown4be44fc2005-08-05 00:44:28 -0400956 ACPI_FUNCTION_NAME("ds_exec_end_control_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 switch (op->common.aml_opcode) {
959 case AML_IF_OP:
960
Len Brown4be44fc2005-08-05 00:44:28 -0400961 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 /*
964 * Save the result of the predicate in case there is an
965 * ELSE to come
966 */
967 walk_state->last_predicate =
Len Brown4be44fc2005-08-05 00:44:28 -0400968 (u8) walk_state->control_state->common.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 /*
971 * Pop the control state that was created at the start
972 * of the IF and free it
973 */
Len Brown4be44fc2005-08-05 00:44:28 -0400974 control_state =
975 acpi_ut_pop_generic_state(&walk_state->control_state);
976 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 break;
978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 case AML_ELSE_OP:
980
981 break;
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 case AML_WHILE_OP:
984
Len Brown4be44fc2005-08-05 00:44:28 -0400985 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (walk_state->control_state->common.value) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 /* Predicate was true, go back and evaluate it again! */
990
991 status = AE_CTRL_PENDING;
992 }
993
Len Brown4be44fc2005-08-05 00:44:28 -0400994 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
995 "[WHILE_OP] termination! Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 /* Pop this control state and free it */
998
Len Brown4be44fc2005-08-05 00:44:28 -0400999 control_state =
1000 acpi_ut_pop_generic_state(&walk_state->control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Len Brown4be44fc2005-08-05 00:44:28 -04001002 walk_state->aml_last_while =
1003 control_state->control.aml_predicate_start;
1004 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 break;
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 case AML_RETURN_OP:
1008
Len Brown4be44fc2005-08-05 00:44:28 -04001009 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1010 "[RETURN_OP] Op=%p Arg=%p\n", op,
1011 op->common.value.arg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013 /*
1014 * One optional operand -- the return value
1015 * It can be either an immediate operand or a result that
1016 * has been bubbled up the tree
1017 */
1018 if (op->common.value.arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 /* Since we have a real Return(), delete any implicit return */
1021
Len Brown4be44fc2005-08-05 00:44:28 -04001022 acpi_ds_clear_implicit_return(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 /* Return statement has an immediate operand */
1025
Len Brown4be44fc2005-08-05 00:44:28 -04001026 status =
1027 acpi_ds_create_operands(walk_state,
1028 op->common.value.arg);
1029 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return (status);
1031 }
1032
1033 /*
1034 * If value being returned is a Reference (such as
1035 * an arg or local), resolve it now because it may
1036 * cease to exist at the end of the method.
1037 */
Len Brown4be44fc2005-08-05 00:44:28 -04001038 status =
1039 acpi_ex_resolve_to_value(&walk_state->operands[0],
1040 walk_state);
1041 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return (status);
1043 }
1044
1045 /*
1046 * Get the return value and save as the last result
1047 * value. This is the only place where walk_state->return_desc
1048 * is set to anything other than zero!
1049 */
1050 walk_state->return_desc = walk_state->operands[0];
Len Brown4be44fc2005-08-05 00:44:28 -04001051 } else if ((walk_state->results) &&
1052 (walk_state->results->results.num_results > 0)) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 /* Since we have a real Return(), delete any implicit return */
1055
Len Brown4be44fc2005-08-05 00:44:28 -04001056 acpi_ds_clear_implicit_return(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 /*
1059 * The return value has come from a previous calculation.
1060 *
1061 * If value being returned is a Reference (such as
1062 * an arg or local), resolve it now because it may
1063 * cease to exist at the end of the method.
1064 *
1065 * Allow references created by the Index operator to return unchanged.
1066 */
Len Brown4be44fc2005-08-05 00:44:28 -04001067 if ((ACPI_GET_DESCRIPTOR_TYPE
1068 (walk_state->results->results.obj_desc[0]) ==
1069 ACPI_DESC_TYPE_OPERAND)
1070 &&
1071 (ACPI_GET_OBJECT_TYPE
1072 (walk_state->results->results.obj_desc[0]) ==
1073 ACPI_TYPE_LOCAL_REFERENCE)
1074 && ((walk_state->results->results.obj_desc[0])->
1075 reference.opcode != AML_INDEX_OP)) {
1076 status =
1077 acpi_ex_resolve_to_value(&walk_state->
1078 results->results.
1079 obj_desc[0],
1080 walk_state);
1081 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 return (status);
1083 }
1084 }
1085
Len Brown4be44fc2005-08-05 00:44:28 -04001086 walk_state->return_desc =
1087 walk_state->results->results.obj_desc[0];
1088 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 /* No return operand */
1090
1091 if (walk_state->num_operands) {
Len Brown4be44fc2005-08-05 00:44:28 -04001092 acpi_ut_remove_reference(walk_state->
1093 operands[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095
Len Brown4be44fc2005-08-05 00:44:28 -04001096 walk_state->operands[0] = NULL;
1097 walk_state->num_operands = 0;
1098 walk_state->return_desc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 }
1100
Len Brown4be44fc2005-08-05 00:44:28 -04001101 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1102 "Completed RETURN_OP State=%p, ret_val=%p\n",
1103 walk_state, walk_state->return_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 /* End the control method execution right now */
1106
1107 status = AE_CTRL_TERMINATE;
1108 break;
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 case AML_NOOP_OP:
1111
1112 /* Just do nothing! */
1113 break;
1114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 case AML_BREAK_POINT_OP:
1116
1117 /* Call up to the OS service layer to handle this */
1118
Len Brown4be44fc2005-08-05 00:44:28 -04001119 status =
1120 acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
1121 "Executed AML Breakpoint opcode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 /* If and when it returns, all done. */
1124
1125 break;
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 case AML_BREAK_OP:
Len Brown4be44fc2005-08-05 00:44:28 -04001128 case AML_CONTINUE_OP: /* ACPI 2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 /* Pop and delete control states until we find a while */
1131
1132 while (walk_state->control_state &&
Len Brown4be44fc2005-08-05 00:44:28 -04001133 (walk_state->control_state->control.opcode !=
1134 AML_WHILE_OP)) {
1135 control_state =
1136 acpi_ut_pop_generic_state(&walk_state->
1137 control_state);
1138 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140
1141 /* No while found? */
1142
1143 if (!walk_state->control_state) {
1144 return (AE_AML_NO_WHILE);
1145 }
1146
1147 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1148
Len Brown4be44fc2005-08-05 00:44:28 -04001149 walk_state->aml_last_while =
1150 walk_state->control_state->control.package_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 /* Return status depending on opcode */
1153
1154 if (op->common.aml_opcode == AML_BREAK_OP) {
1155 status = AE_CTRL_BREAK;
Len Brown4be44fc2005-08-05 00:44:28 -04001156 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 status = AE_CTRL_CONTINUE;
1158 }
1159 break;
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 default:
1162
Bob Mooreb8e4d892006-01-27 16:43:00 -05001163 ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
1164 op->common.aml_opcode, op));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 status = AE_AML_BAD_OPCODE;
1167 break;
1168 }
1169
1170 return (status);
1171}