blob: a3f29798d1d141670bed635ba4d9c312fac84d33 [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 Moore6c9deb72007-02-02 19:48:24 +03009 * Copyright (C) 2000 - 2007, 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>
Lin Ming941f48b2008-04-10 19:06:41 +040052#include <acpi/actables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040055ACPI_MODULE_NAME("dsopcode")
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Robert Moore44f6c012005-04-18 22:49:35 -040057/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040058static acpi_status
59acpi_ds_execute_arguments(struct acpi_namespace_node *node,
60 struct acpi_namespace_node *scope_node,
61 u32 aml_length, u8 * aml_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Robert Moore44f6c012005-04-18 22:49:35 -040063static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_ds_init_buffer_field(u16 aml_opcode,
65 union acpi_operand_object *obj_desc,
66 union acpi_operand_object *buffer_desc,
67 union acpi_operand_object *offset_desc,
68 union acpi_operand_object *length_desc,
69 union acpi_operand_object *result_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040070
71/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 *
73 * FUNCTION: acpi_ds_execute_arguments
74 *
Robert Moore44f6c012005-04-18 22:49:35 -040075 * PARAMETERS: Node - Object NS node
76 * scope_node - Parent NS node
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * aml_length - Length of executable AML
78 * aml_start - Pointer to the AML
79 *
80 * RETURN: Status.
81 *
82 * DESCRIPTION: Late (deferred) execution of region or field arguments
83 *
Robert Moore44f6c012005-04-18 22:49:35 -040084 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Robert Moore44f6c012005-04-18 22:49:35 -040086static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040087acpi_ds_execute_arguments(struct acpi_namespace_node *node,
88 struct acpi_namespace_node *scope_node,
89 u32 aml_length, u8 * aml_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Len Brown4be44fc2005-08-05 00:44:28 -040091 acpi_status status;
92 union acpi_parse_object *op;
93 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Bob Mooreb229cf92006-04-21 17:15:00 -040095 ACPI_FUNCTION_TRACE(ds_execute_arguments);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /*
98 * Allocate a new parser op to be the root of the parsed tree
99 */
Len Brown4be44fc2005-08-05 00:44:28 -0400100 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 if (!op) {
Len Brown4be44fc2005-08-05 00:44:28 -0400102 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
105 /* Save the Node for use in acpi_ps_parse_aml */
106
107 op->common.node = scope_node;
108
109 /* Create and initialize a new parser state */
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (!walk_state) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400113 status = AE_NO_MEMORY;
114 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
Len Brown4be44fc2005-08-05 00:44:28 -0400117 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
Bob Mooreec3153f2007-02-02 19:48:21 +0300118 aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
Len Brown4be44fc2005-08-05 00:44:28 -0400119 if (ACPI_FAILURE(status)) {
120 acpi_ds_delete_walk_state(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400121 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 /* Mark this parse as a deferred opcode */
125
126 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
127 walk_state->deferred_node = node;
128
129 /* Pass1: Parse the entire declaration */
130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 status = acpi_ps_parse_aml(walk_state);
132 if (ACPI_FAILURE(status)) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400133 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135
136 /* Get and init the Op created above */
137
138 op->common.node = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 acpi_ps_delete_parse_tree(op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* Evaluate the deferred arguments */
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 if (!op) {
Len Brown4be44fc2005-08-05 00:44:28 -0400145 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
148 op->common.node = scope_node;
149
150 /* Create and initialize a new parser state */
151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 if (!walk_state) {
Robert Moore88ac00f2005-05-26 00:00:00 -0400154 status = AE_NO_MEMORY;
155 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158 /* Execute the opcode and arguments */
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
Bob Mooreec3153f2007-02-02 19:48:21 +0300161 aml_length, NULL, ACPI_IMODE_EXECUTE);
Len Brown4be44fc2005-08-05 00:44:28 -0400162 if (ACPI_FAILURE(status)) {
163 acpi_ds_delete_walk_state(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400164 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
167 /* Mark this execution as a deferred opcode */
168
169 walk_state->deferred_node = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400170 status = acpi_ps_parse_aml(walk_state);
Robert Moore88ac00f2005-05-26 00:00:00 -0400171
Len Brown4be44fc2005-08-05 00:44:28 -0400172 cleanup:
173 acpi_ps_delete_parse_tree(op);
174 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
Robert Moore44f6c012005-04-18 22:49:35 -0400177/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 *
179 * FUNCTION: acpi_ds_get_buffer_field_arguments
180 *
181 * PARAMETERS: obj_desc - A valid buffer_field object
182 *
183 * RETURN: Status.
184 *
185 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
186 * evaluation of these field attributes.
187 *
Robert Moore44f6c012005-04-18 22:49:35 -0400188 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400191acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Len Brown4be44fc2005-08-05 00:44:28 -0400193 union acpi_operand_object *extra_desc;
194 struct acpi_namespace_node *node;
195 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Bob Mooreb229cf92006-04-21 17:15:00 -0400197 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400200 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
203 /* Get the AML pointer (method object) and buffer_field node */
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 extra_desc = acpi_ns_get_secondary_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 node = obj_desc->buffer_field.node;
207
Len Brown4be44fc2005-08-05 00:44:28 -0400208 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
209 (ACPI_TYPE_BUFFER_FIELD, node, NULL));
Bob Mooreb229cf92006-04-21 17:15:00 -0400210 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400211 acpi_ut_get_node_name(node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 /* Execute the AML code for the term_arg arguments */
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
216 extra_desc->extra.aml_length,
217 extra_desc->extra.aml_start);
218 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Robert Moore44f6c012005-04-18 22:49:35 -0400221/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 *
223 * FUNCTION: acpi_ds_get_buffer_arguments
224 *
225 * PARAMETERS: obj_desc - A valid Buffer object
226 *
227 * RETURN: Status.
228 *
229 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
230 * the late evaluation of these attributes.
231 *
Robert Moore44f6c012005-04-18 22:49:35 -0400232 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Len Brown4be44fc2005-08-05 00:44:28 -0400234acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Len Brown4be44fc2005-08-05 00:44:28 -0400236 struct acpi_namespace_node *node;
237 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Bob Mooreb229cf92006-04-21 17:15:00 -0400239 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400242 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244
245 /* Get the Buffer node */
246
247 node = obj_desc->buffer.node;
248 if (!node) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500249 ACPI_ERROR((AE_INFO,
250 "No pointer back to NS node in buffer obj %p",
251 obj_desc));
Len Brown4be44fc2005-08-05 00:44:28 -0400252 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* Execute the AML code for the term_arg arguments */
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 status = acpi_ds_execute_arguments(node, node,
260 obj_desc->buffer.aml_length,
261 obj_desc->buffer.aml_start);
262 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Robert Moore44f6c012005-04-18 22:49:35 -0400265/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 *
267 * FUNCTION: acpi_ds_get_package_arguments
268 *
269 * PARAMETERS: obj_desc - A valid Package object
270 *
271 * RETURN: Status.
272 *
273 * DESCRIPTION: Get Package length and initializer byte list. This implements
274 * the late evaluation of these attributes.
275 *
Robert Moore44f6c012005-04-18 22:49:35 -0400276 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Len Brown4be44fc2005-08-05 00:44:28 -0400278acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Len Brown4be44fc2005-08-05 00:44:28 -0400280 struct acpi_namespace_node *node;
281 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Bob Mooreb229cf92006-04-21 17:15:00 -0400283 ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400286 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
288
289 /* Get the Package node */
290
291 node = obj_desc->package.node;
292 if (!node) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500293 ACPI_ERROR((AE_INFO,
294 "No pointer back to NS node in package %p",
295 obj_desc));
Len Brown4be44fc2005-08-05 00:44:28 -0400296 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298
Len Brown4be44fc2005-08-05 00:44:28 -0400299 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 /* Execute the AML code for the term_arg arguments */
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 status = acpi_ds_execute_arguments(node, node,
304 obj_desc->package.aml_length,
305 obj_desc->package.aml_start);
306 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*****************************************************************************
310 *
311 * FUNCTION: acpi_ds_get_region_arguments
312 *
313 * PARAMETERS: obj_desc - A valid region object
314 *
315 * RETURN: Status.
316 *
317 * DESCRIPTION: Get region address and length. This implements the late
318 * evaluation of these region attributes.
319 *
320 ****************************************************************************/
321
Len Brown4be44fc2005-08-05 00:44:28 -0400322acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Len Brown4be44fc2005-08-05 00:44:28 -0400324 struct acpi_namespace_node *node;
325 acpi_status status;
326 union acpi_operand_object *extra_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Bob Mooreb229cf92006-04-21 17:15:00 -0400328 ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400331 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 extra_desc = acpi_ns_get_secondary_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (!extra_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400336 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 /* Get the Region node */
340
341 node = obj_desc->region.node;
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
344 (ACPI_TYPE_REGION, node, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Bob Mooreb229cf92006-04-21 17:15:00 -0400346 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400347 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);
Bob Mooreb229cf92006-04-21 17:15:00 -0400355 if (ACPI_FAILURE(status)) {
356 return_ACPI_STATUS(status);
357 }
358
359 /* Validate the region address/length via the host OS */
360
361 status = acpi_os_validate_address(obj_desc->region.space_id,
362 obj_desc->region.address,
Thomas Renningerdf92e692008-02-04 23:31:22 -0800363 (acpi_size) obj_desc->region.length,
364 acpi_ut_get_node_name(node));
365
Bob Mooreb229cf92006-04-21 17:15:00 -0400366 if (ACPI_FAILURE(status)) {
367 /*
368 * Invalid address/length. We will emit an error message and mark
369 * the region as invalid, so that it will cause an additional error if
370 * it is ever used. Then return AE_OK.
371 */
372 ACPI_EXCEPTION((AE_INFO, status,
373 "During address validation of OpRegion [%4.4s]",
374 node->name.ascii));
375 obj_desc->common.flags |= AOPOBJ_INVALID;
376 status = AE_OK;
377 }
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
Robert Moore44f6c012005-04-18 22:49:35 -0400382/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
384 * FUNCTION: acpi_ds_initialize_region
385 *
Robert Moore44f6c012005-04-18 22:49:35 -0400386 * PARAMETERS: obj_handle - Region namespace node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 *
388 * RETURN: Status
389 *
390 * DESCRIPTION: Front end to ev_initialize_region
391 *
Robert Moore44f6c012005-04-18 22:49:35 -0400392 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Len Brown4be44fc2005-08-05 00:44:28 -0400394acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 union acpi_operand_object *obj_desc;
397 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Len Brown4be44fc2005-08-05 00:44:28 -0400399 obj_desc = acpi_ns_get_attached_object(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* Namespace is NOT locked */
402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 status = acpi_ev_initialize_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return (status);
405}
406
Robert Moore44f6c012005-04-18 22:49:35 -0400407/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 *
409 * FUNCTION: acpi_ds_init_buffer_field
410 *
411 * PARAMETERS: aml_opcode - create_xxx_field
412 * obj_desc - buffer_field object
413 * buffer_desc - Host Buffer
414 * offset_desc - Offset into buffer
Robert Moore44f6c012005-04-18 22:49:35 -0400415 * length_desc - Length of field (CREATE_FIELD_OP only)
416 * result_desc - Where to store the result
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 *
418 * RETURN: Status
419 *
420 * DESCRIPTION: Perform actual initialization of a buffer field
421 *
Robert Moore44f6c012005-04-18 22:49:35 -0400422 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Robert Moore44f6c012005-04-18 22:49:35 -0400424static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_ds_init_buffer_field(u16 aml_opcode,
426 union acpi_operand_object *obj_desc,
427 union acpi_operand_object *buffer_desc,
428 union acpi_operand_object *offset_desc,
429 union acpi_operand_object *length_desc,
430 union acpi_operand_object *result_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Len Brown4be44fc2005-08-05 00:44:28 -0400432 u32 offset;
433 u32 bit_offset;
434 u32 bit_count;
435 u8 field_flags;
436 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Bob Mooreb229cf92006-04-21 17:15:00 -0400438 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /* Host object must be a Buffer */
441
Len Brown4be44fc2005-08-05 00:44:28 -0400442 if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500443 ACPI_ERROR((AE_INFO,
444 "Target of Create Field is not a Buffer object - %s",
445 acpi_ut_get_object_type_name(buffer_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 status = AE_AML_OPERAND_TYPE;
448 goto cleanup;
449 }
450
451 /*
452 * The last parameter to all of these opcodes (result_desc) started
453 * out as a name_string, and should therefore now be a NS node
454 * after resolution in acpi_ex_resolve_operands().
455 */
Len Brown4be44fc2005-08-05 00:44:28 -0400456 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500457 ACPI_ERROR((AE_INFO,
458 "(%s) destination not a NS Node [%s]",
459 acpi_ps_get_opcode_name(aml_opcode),
460 acpi_ut_get_descriptor_name(result_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 status = AE_AML_OPERAND_TYPE;
463 goto cleanup;
464 }
465
466 offset = (u32) offset_desc->integer.value;
467
468 /*
469 * Setup the Bit offsets and counts, according to the opcode
470 */
471 switch (aml_opcode) {
472 case AML_CREATE_FIELD_OP:
473
474 /* Offset is in bits, count is in bits */
475
Robert Moore44f6c012005-04-18 22:49:35 -0400476 field_flags = AML_FIELD_ACCESS_BYTE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400478 bit_count = (u32) length_desc->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400479
480 /* Must have a valid (>0) bit count */
481
482 if (bit_count == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500483 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400484 "Attempt to CreateField of length zero"));
Robert Moore44f6c012005-04-18 22:49:35 -0400485 status = AE_AML_OPERAND_VALUE;
486 goto cleanup;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 break;
489
490 case AML_CREATE_BIT_FIELD_OP:
491
492 /* Offset is in bits, Field is one bit */
493
494 bit_offset = offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400495 bit_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 field_flags = AML_FIELD_ACCESS_BYTE;
497 break;
498
499 case AML_CREATE_BYTE_FIELD_OP:
500
501 /* Offset is in bytes, field is one byte */
502
503 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400504 bit_count = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 field_flags = AML_FIELD_ACCESS_BYTE;
506 break;
507
508 case AML_CREATE_WORD_FIELD_OP:
509
510 /* Offset is in bytes, field is one word */
511
512 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400513 bit_count = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 field_flags = AML_FIELD_ACCESS_WORD;
515 break;
516
517 case AML_CREATE_DWORD_FIELD_OP:
518
519 /* Offset is in bytes, field is one dword */
520
521 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400522 bit_count = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 field_flags = AML_FIELD_ACCESS_DWORD;
524 break;
525
526 case AML_CREATE_QWORD_FIELD_OP:
527
528 /* Offset is in bytes, field is one qword */
529
530 bit_offset = 8 * offset;
Len Brown4be44fc2005-08-05 00:44:28 -0400531 bit_count = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 field_flags = AML_FIELD_ACCESS_QWORD;
533 break;
534
535 default:
536
Bob Mooreb8e4d892006-01-27 16:43:00 -0500537 ACPI_ERROR((AE_INFO,
538 "Unknown field creation opcode %02x", aml_opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 status = AE_AML_BAD_OPCODE;
540 goto cleanup;
541 }
542
543 /* Entire field must fit within the current length of the buffer */
544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500546 ACPI_ERROR((AE_INFO,
547 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
548 acpi_ut_get_node_name(result_desc),
549 bit_offset + bit_count,
550 acpi_ut_get_node_name(buffer_desc->buffer.node),
551 8 * (u32) buffer_desc->buffer.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 status = AE_AML_BUFFER_LIMIT;
553 goto cleanup;
554 }
555
556 /*
557 * Initialize areas of the field object that are common to all fields
Robert Moore44f6c012005-04-18 22:49:35 -0400558 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
559 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 */
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
562 bit_offset, bit_count);
563 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 goto cleanup;
565 }
566
567 obj_desc->buffer_field.buffer_obj = buffer_desc;
568
569 /* Reference count for buffer_desc inherits obj_desc count */
570
Robert Moore44f6c012005-04-18 22:49:35 -0400571 buffer_desc->common.reference_count = (u16)
Len Brown4be44fc2005-08-05 00:44:28 -0400572 (buffer_desc->common.reference_count +
573 obj_desc->common.reference_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 /* Always delete the operands */
578
Len Brown4be44fc2005-08-05 00:44:28 -0400579 acpi_ut_remove_reference(offset_desc);
580 acpi_ut_remove_reference(buffer_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 if (aml_opcode == AML_CREATE_FIELD_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400583 acpi_ut_remove_reference(length_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
586 /* On failure, delete the result descriptor */
587
Len Brown4be44fc2005-08-05 00:44:28 -0400588 if (ACPI_FAILURE(status)) {
589 acpi_ut_remove_reference(result_desc); /* Result descriptor */
590 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /* Now the address and length are valid for this buffer_field */
592
593 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
594 }
595
Len Brown4be44fc2005-08-05 00:44:28 -0400596 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Robert Moore44f6c012005-04-18 22:49:35 -0400599/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 *
601 * FUNCTION: acpi_ds_eval_buffer_field_operands
602 *
603 * PARAMETERS: walk_state - Current walk
604 * Op - A valid buffer_field Op object
605 *
606 * RETURN: Status
607 *
608 * DESCRIPTION: Get buffer_field Buffer and Index
609 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
610 *
Robert Moore44f6c012005-04-18 22:49:35 -0400611 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400614acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
615 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Len Brown4be44fc2005-08-05 00:44:28 -0400617 acpi_status status;
618 union acpi_operand_object *obj_desc;
619 struct acpi_namespace_node *node;
620 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Bob Mooreb229cf92006-04-21 17:15:00 -0400622 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /*
625 * This is where we evaluate the address and length fields of the
626 * create_xxx_field declaration
627 */
Len Brown4be44fc2005-08-05 00:44:28 -0400628 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 /* next_op points to the op that holds the Buffer */
631
632 next_op = op->common.value.arg;
633
634 /* Evaluate/create the address and length operands */
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 status = acpi_ds_create_operands(walk_state, next_op);
637 if (ACPI_FAILURE(status)) {
638 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
Len Brown4be44fc2005-08-05 00:44:28 -0400641 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400643 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
646 /* Resolve the operands */
647
Len Brown4be44fc2005-08-05 00:44:28 -0400648 status = acpi_ex_resolve_operands(op->common.aml_opcode,
649 ACPI_WALK_OPERANDS, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
652 acpi_ps_get_opcode_name(op->common.aml_opcode),
653 walk_state->num_operands,
Bob Mooreb229cf92006-04-21 17:15:00 -0400654 "after AcpiExResolveOperands");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500657 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
658 acpi_ps_get_opcode_name(op->common.aml_opcode),
659 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Len Brown4be44fc2005-08-05 00:44:28 -0400661 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663
664 /* Initialize the Buffer Field */
665
666 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /* NOTE: Slightly different operands for this opcode */
669
Len Brown4be44fc2005-08-05 00:44:28 -0400670 status =
671 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
672 walk_state->operands[0],
673 walk_state->operands[1],
674 walk_state->operands[2],
675 walk_state->operands[3]);
676 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* All other, create_xxx_field opcodes */
678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 status =
680 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
681 walk_state->operands[0],
682 walk_state->operands[1], NULL,
683 walk_state->operands[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
Len Brown4be44fc2005-08-05 00:44:28 -0400686 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Robert Moore44f6c012005-04-18 22:49:35 -0400689/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 *
691 * FUNCTION: acpi_ds_eval_region_operands
692 *
693 * PARAMETERS: walk_state - Current walk
694 * Op - A valid region Op object
695 *
696 * RETURN: Status
697 *
698 * DESCRIPTION: Get region address and length
699 * Called from acpi_ds_exec_end_op during op_region parse tree walk
700 *
Robert Moore44f6c012005-04-18 22:49:35 -0400701 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400704acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
705 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Len Brown4be44fc2005-08-05 00:44:28 -0400707 acpi_status status;
708 union acpi_operand_object *obj_desc;
709 union acpi_operand_object *operand_desc;
710 struct acpi_namespace_node *node;
711 union acpi_parse_object *next_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Bob Mooreb229cf92006-04-21 17:15:00 -0400713 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400716 * This is where we evaluate the address and length fields of the
717 * op_region declaration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 */
Len Brown4be44fc2005-08-05 00:44:28 -0400719 node = op->common.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 /* next_op points to the op that holds the space_iD */
722
723 next_op = op->common.value.arg;
724
725 /* next_op points to address op */
726
727 next_op = next_op->common.next;
728
729 /* Evaluate/create the address and length operands */
730
Len Brown4be44fc2005-08-05 00:44:28 -0400731 status = acpi_ds_create_operands(walk_state, next_op);
732 if (ACPI_FAILURE(status)) {
733 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735
736 /* Resolve the length and address operands to numbers */
737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 status = acpi_ex_resolve_operands(op->common.aml_opcode,
739 ACPI_WALK_OPERANDS, walk_state);
740 if (ACPI_FAILURE(status)) {
741 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
745 acpi_ps_get_opcode_name(op->common.aml_opcode),
Bob Mooreb229cf92006-04-21 17:15:00 -0400746 1, "after AcpiExResolveOperands");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400750 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752
753 /*
754 * Get the length operand and save it
755 * (at Top of stack)
756 */
757 operand_desc = walk_state->operands[walk_state->num_operands - 1];
758
759 obj_desc->region.length = (u32) operand_desc->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400760 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /*
763 * Get the address and save it
764 * (at top of stack - 1)
765 */
766 operand_desc = walk_state->operands[walk_state->num_operands - 2];
767
Robert Moore44f6c012005-04-18 22:49:35 -0400768 obj_desc->region.address = (acpi_physical_address)
Len Brown4be44fc2005-08-05 00:44:28 -0400769 operand_desc->integer.value;
770 acpi_ut_remove_reference(operand_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Bob Mooreb229cf92006-04-21 17:15:00 -0400772 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400773 obj_desc,
Bob Mooreb7f9f042008-04-10 19:06:40 +0400774 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
Len Brown4be44fc2005-08-05 00:44:28 -0400775 obj_desc->region.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 /* Now the address and length are valid for this opregion */
778
779 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
780
Len Brown4be44fc2005-08-05 00:44:28 -0400781 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
Robert Moore44f6c012005-04-18 22:49:35 -0400784/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 *
Lin Ming941f48b2008-04-10 19:06:41 +0400786 * FUNCTION: acpi_ds_eval_table_region_operands
787 *
788 * PARAMETERS: walk_state - Current walk
789 * Op - A valid region Op object
790 *
791 * RETURN: Status
792 *
793 * DESCRIPTION: Get region address and length
794 * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
795 *
796 ******************************************************************************/
797
798acpi_status
799acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
800 union acpi_parse_object *op)
801{
802 acpi_status status;
803 union acpi_operand_object *obj_desc;
804 union acpi_operand_object **operand;
805 struct acpi_namespace_node *node;
806 union acpi_parse_object *next_op;
807 acpi_native_uint table_index;
808 struct acpi_table_header *table;
809
810 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
811
812 /*
813 * This is where we evaluate the signature_string and oem_iDString
814 * and oem_table_iDString of the data_table_region declaration
815 */
816 node = op->common.node;
817
818 /* next_op points to signature_string op */
819
820 next_op = op->common.value.arg;
821
822 /*
823 * Evaluate/create the signature_string and oem_iDString
824 * and oem_table_iDString operands
825 */
826 status = acpi_ds_create_operands(walk_state, next_op);
827 if (ACPI_FAILURE(status)) {
828 return_ACPI_STATUS(status);
829 }
830
831 /*
832 * Resolve the signature_string and oem_iDString
833 * and oem_table_iDString operands
834 */
835 status = acpi_ex_resolve_operands(op->common.aml_opcode,
836 ACPI_WALK_OPERANDS, walk_state);
837 if (ACPI_FAILURE(status)) {
838 return_ACPI_STATUS(status);
839 }
840
841 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
842 acpi_ps_get_opcode_name(op->common.aml_opcode),
843 1, "after AcpiExResolveOperands");
844
845 operand = &walk_state->operands[0];
846
847 /* Find the ACPI table */
848
849 status = acpi_tb_find_table(operand[0]->string.pointer,
850 operand[1]->string.pointer,
851 operand[2]->string.pointer, &table_index);
852 if (ACPI_FAILURE(status)) {
853 return_ACPI_STATUS(status);
854 }
855
856 acpi_ut_remove_reference(operand[0]);
857 acpi_ut_remove_reference(operand[1]);
858 acpi_ut_remove_reference(operand[2]);
859
860 status = acpi_get_table_by_index(table_index, &table);
861 if (ACPI_FAILURE(status)) {
862 return_ACPI_STATUS(status);
863 }
864
865 obj_desc = acpi_ns_get_attached_object(node);
866 if (!obj_desc) {
867 return_ACPI_STATUS(AE_NOT_EXIST);
868 }
869
870 obj_desc->region.address =
871 (acpi_physical_address) ACPI_TO_INTEGER(table);
872 obj_desc->region.length = table->length;
873
874 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
875 obj_desc,
876 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
877 obj_desc->region.length));
878
879 /* Now the address and length are valid for this opregion */
880
881 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
882
883 return_ACPI_STATUS(status);
884}
885
886/*******************************************************************************
887 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 * FUNCTION: acpi_ds_eval_data_object_operands
889 *
890 * PARAMETERS: walk_state - Current walk
891 * Op - A valid data_object Op object
892 * obj_desc - data_object
893 *
894 * RETURN: Status
895 *
896 * DESCRIPTION: Get the operands and complete the following data object types:
897 * Buffer, Package.
898 *
Robert Moore44f6c012005-04-18 22:49:35 -0400899 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400902acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
903 union acpi_parse_object *op,
904 union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Len Brown4be44fc2005-08-05 00:44:28 -0400906 acpi_status status;
907 union acpi_operand_object *arg_desc;
908 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Bob Mooreb229cf92006-04-21 17:15:00 -0400910 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 /* The first operand (for all of these data objects) is the length */
913
Bob Moore773069d2008-04-10 19:06:36 +0400914 /*
915 * Set proper index into operand stack for acpi_ds_obj_stack_push
916 * invoked inside acpi_ds_create_operand.
917 */
918 walk_state->operand_index = walk_state->num_operands;
919
Len Brown4be44fc2005-08-05 00:44:28 -0400920 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
921 if (ACPI_FAILURE(status)) {
922 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 }
924
Len Brown4be44fc2005-08-05 00:44:28 -0400925 status = acpi_ex_resolve_operands(walk_state->opcode,
926 &(walk_state->
927 operands[walk_state->num_operands -
928 1]), walk_state);
929 if (ACPI_FAILURE(status)) {
930 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932
933 /* Extract length operand */
934
Len Brown4be44fc2005-08-05 00:44:28 -0400935 arg_desc = walk_state->operands[walk_state->num_operands - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 length = (u32) arg_desc->integer.value;
937
938 /* Cleanup for length operand */
939
Len Brown4be44fc2005-08-05 00:44:28 -0400940 status = acpi_ds_obj_stack_pop(1, walk_state);
941 if (ACPI_FAILURE(status)) {
942 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944
Len Brown4be44fc2005-08-05 00:44:28 -0400945 acpi_ut_remove_reference(arg_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /*
948 * Create the actual data object
949 */
950 switch (op->common.aml_opcode) {
951 case AML_BUFFER_OP:
952
Len Brown4be44fc2005-08-05 00:44:28 -0400953 status =
954 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
955 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 break;
957
958 case AML_PACKAGE_OP:
959 case AML_VAR_PACKAGE_OP:
960
Len Brown4be44fc2005-08-05 00:44:28 -0400961 status =
962 acpi_ds_build_internal_package_obj(walk_state, op, length,
963 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 break;
965
966 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400967 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
969
Len Brown4be44fc2005-08-05 00:44:28 -0400970 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400972 * Return the object in the walk_state, unless the parent is a package -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 * in this case, the return object will be stored in the parse tree
974 * for the package.
975 */
976 if ((!op->common.parent) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400977 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
978 (op->common.parent->common.aml_opcode !=
979 AML_VAR_PACKAGE_OP)
Len Brownfd350942007-05-09 23:34:35 -0400980 && (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 walk_state->result_obj = obj_desc;
982 }
983 }
984
Len Brown4be44fc2005-08-05 00:44:28 -0400985 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988/*******************************************************************************
989 *
990 * FUNCTION: acpi_ds_exec_begin_control_op
991 *
992 * PARAMETERS: walk_list - The list that owns the walk stack
993 * Op - The control Op
994 *
995 * RETURN: Status
996 *
997 * DESCRIPTION: Handles all control ops encountered during control method
998 * execution.
999 *
1000 ******************************************************************************/
1001
1002acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001003acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
1004 union acpi_parse_object *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
Len Brown4be44fc2005-08-05 00:44:28 -04001006 acpi_status status = AE_OK;
1007 union acpi_generic_state *control_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Bob Mooreb229cf92006-04-21 17:15:00 -04001009 ACPI_FUNCTION_NAME(ds_exec_begin_control_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Len Brown4be44fc2005-08-05 00:44:28 -04001011 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
1012 op->common.aml_opcode, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 switch (op->common.aml_opcode) {
1015 case AML_IF_OP:
1016 case AML_WHILE_OP:
1017
1018 /*
1019 * IF/WHILE: Create a new control state to manage these
1020 * constructs. We need to manage these as a stack, in order
1021 * to handle nesting.
1022 */
Len Brown4be44fc2005-08-05 00:44:28 -04001023 control_state = acpi_ut_create_control_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (!control_state) {
1025 status = AE_NO_MEMORY;
1026 break;
1027 }
1028 /*
1029 * Save a pointer to the predicate for multiple executions
1030 * of a loop
1031 */
Len Brown4be44fc2005-08-05 00:44:28 -04001032 control_state->control.aml_predicate_start =
1033 walk_state->parser_state.aml - 1;
1034 control_state->control.package_end =
1035 walk_state->parser_state.pkg_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 control_state->control.opcode = op->common.aml_opcode;
1037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 /* Push the control state on this walk's control stack */
1039
Len Brown4be44fc2005-08-05 00:44:28 -04001040 acpi_ut_push_generic_state(&walk_state->control_state,
1041 control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 break;
1043
1044 case AML_ELSE_OP:
1045
1046 /* Predicate is in the state object */
1047 /* If predicate is true, the IF was executed, ignore ELSE part */
1048
1049 if (walk_state->last_predicate) {
1050 status = AE_CTRL_TRUE;
1051 }
1052
1053 break;
1054
1055 case AML_RETURN_OP:
1056
1057 break;
1058
1059 default:
1060 break;
1061 }
1062
1063 return (status);
1064}
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066/*******************************************************************************
1067 *
1068 * FUNCTION: acpi_ds_exec_end_control_op
1069 *
1070 * PARAMETERS: walk_list - The list that owns the walk stack
1071 * Op - The control Op
1072 *
1073 * RETURN: Status
1074 *
1075 * DESCRIPTION: Handles all control ops encountered during control method
1076 * execution.
1077 *
1078 ******************************************************************************/
1079
1080acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001081acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
1082 union acpi_parse_object * op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Len Brown4be44fc2005-08-05 00:44:28 -04001084 acpi_status status = AE_OK;
1085 union acpi_generic_state *control_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Bob Mooreb229cf92006-04-21 17:15:00 -04001087 ACPI_FUNCTION_NAME(ds_exec_end_control_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 switch (op->common.aml_opcode) {
1090 case AML_IF_OP:
1091
Len Brown4be44fc2005-08-05 00:44:28 -04001092 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 /*
1095 * Save the result of the predicate in case there is an
1096 * ELSE to come
1097 */
1098 walk_state->last_predicate =
Len Brown4be44fc2005-08-05 00:44:28 -04001099 (u8) walk_state->control_state->common.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 /*
1102 * Pop the control state that was created at the start
1103 * of the IF and free it
1104 */
Len Brown4be44fc2005-08-05 00:44:28 -04001105 control_state =
1106 acpi_ut_pop_generic_state(&walk_state->control_state);
1107 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 case AML_ELSE_OP:
1111
1112 break;
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 case AML_WHILE_OP:
1115
Len Brown4be44fc2005-08-05 00:44:28 -04001116 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 if (walk_state->control_state->common.value) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /* Predicate was true, go back and evaluate it again! */
1121
1122 status = AE_CTRL_PENDING;
1123 }
1124
Len Brown4be44fc2005-08-05 00:44:28 -04001125 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1126 "[WHILE_OP] termination! Op=%p\n", op));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 /* Pop this control state and free it */
1129
Len Brown4be44fc2005-08-05 00:44:28 -04001130 control_state =
1131 acpi_ut_pop_generic_state(&walk_state->control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Len Brown4be44fc2005-08-05 00:44:28 -04001133 walk_state->aml_last_while =
1134 control_state->control.aml_predicate_start;
1135 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 break;
1137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 case AML_RETURN_OP:
1139
Len Brown4be44fc2005-08-05 00:44:28 -04001140 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1141 "[RETURN_OP] Op=%p Arg=%p\n", op,
1142 op->common.value.arg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 /*
1145 * One optional operand -- the return value
1146 * It can be either an immediate operand or a result that
1147 * has been bubbled up the tree
1148 */
1149 if (op->common.value.arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 /* Since we have a real Return(), delete any implicit return */
1152
Len Brown4be44fc2005-08-05 00:44:28 -04001153 acpi_ds_clear_implicit_return(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 /* Return statement has an immediate operand */
1156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 status =
1158 acpi_ds_create_operands(walk_state,
1159 op->common.value.arg);
1160 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 return (status);
1162 }
1163
1164 /*
1165 * If value being returned is a Reference (such as
1166 * an arg or local), resolve it now because it may
1167 * cease to exist at the end of the method.
1168 */
Len Brown4be44fc2005-08-05 00:44:28 -04001169 status =
1170 acpi_ex_resolve_to_value(&walk_state->operands[0],
1171 walk_state);
1172 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 return (status);
1174 }
1175
1176 /*
1177 * Get the return value and save as the last result
1178 * value. This is the only place where walk_state->return_desc
1179 * is set to anything other than zero!
1180 */
1181 walk_state->return_desc = walk_state->operands[0];
Bob Moore773069d2008-04-10 19:06:36 +04001182 } else if (walk_state->result_count) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 /* Since we have a real Return(), delete any implicit return */
1185
Len Brown4be44fc2005-08-05 00:44:28 -04001186 acpi_ds_clear_implicit_return(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 /*
1189 * The return value has come from a previous calculation.
1190 *
1191 * If value being returned is a Reference (such as
1192 * an arg or local), resolve it now because it may
1193 * cease to exist at the end of the method.
1194 *
1195 * Allow references created by the Index operator to return unchanged.
1196 */
Len Brown4be44fc2005-08-05 00:44:28 -04001197 if ((ACPI_GET_DESCRIPTOR_TYPE
1198 (walk_state->results->results.obj_desc[0]) ==
1199 ACPI_DESC_TYPE_OPERAND)
1200 &&
1201 (ACPI_GET_OBJECT_TYPE
1202 (walk_state->results->results.obj_desc[0]) ==
1203 ACPI_TYPE_LOCAL_REFERENCE)
1204 && ((walk_state->results->results.obj_desc[0])->
1205 reference.opcode != AML_INDEX_OP)) {
1206 status =
1207 acpi_ex_resolve_to_value(&walk_state->
1208 results->results.
1209 obj_desc[0],
1210 walk_state);
1211 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 return (status);
1213 }
1214 }
1215
Len Brown4be44fc2005-08-05 00:44:28 -04001216 walk_state->return_desc =
1217 walk_state->results->results.obj_desc[0];
1218 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 /* No return operand */
1220
1221 if (walk_state->num_operands) {
Len Brown4be44fc2005-08-05 00:44:28 -04001222 acpi_ut_remove_reference(walk_state->
1223 operands[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225
Len Brown4be44fc2005-08-05 00:44:28 -04001226 walk_state->operands[0] = NULL;
1227 walk_state->num_operands = 0;
1228 walk_state->return_desc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230
Len Brown4be44fc2005-08-05 00:44:28 -04001231 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
Bob Mooreb229cf92006-04-21 17:15:00 -04001232 "Completed RETURN_OP State=%p, RetVal=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001233 walk_state, walk_state->return_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 /* End the control method execution right now */
1236
1237 status = AE_CTRL_TERMINATE;
1238 break;
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 case AML_NOOP_OP:
1241
1242 /* Just do nothing! */
1243 break;
1244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 case AML_BREAK_POINT_OP:
1246
1247 /* Call up to the OS service layer to handle this */
1248
Len Brown4be44fc2005-08-05 00:44:28 -04001249 status =
1250 acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
1251 "Executed AML Breakpoint opcode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 /* If and when it returns, all done. */
1254
1255 break;
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 case AML_BREAK_OP:
Len Brown4be44fc2005-08-05 00:44:28 -04001258 case AML_CONTINUE_OP: /* ACPI 2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 /* Pop and delete control states until we find a while */
1261
1262 while (walk_state->control_state &&
Len Brown4be44fc2005-08-05 00:44:28 -04001263 (walk_state->control_state->control.opcode !=
1264 AML_WHILE_OP)) {
1265 control_state =
1266 acpi_ut_pop_generic_state(&walk_state->
1267 control_state);
1268 acpi_ut_delete_generic_state(control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
1270
1271 /* No while found? */
1272
1273 if (!walk_state->control_state) {
1274 return (AE_AML_NO_WHILE);
1275 }
1276
1277 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1278
Len Brown4be44fc2005-08-05 00:44:28 -04001279 walk_state->aml_last_while =
1280 walk_state->control_state->control.package_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 /* Return status depending on opcode */
1283
1284 if (op->common.aml_opcode == AML_BREAK_OP) {
1285 status = AE_CTRL_BREAK;
Len Brown4be44fc2005-08-05 00:44:28 -04001286 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 status = AE_CTRL_CONTINUE;
1288 }
1289 break;
1290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 default:
1292
Bob Mooreb8e4d892006-01-27 16:43:00 -05001293 ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
1294 op->common.aml_opcode, op));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 status = AE_AML_BAD_OPCODE;
1297 break;
1298 }
1299
1300 return (status);
1301}