Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: dsopcode - Dispatcher Op Region support and handling of | |
4 | * "control" opcodes | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
75a44ce0 | 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
10 | * 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 | ||
1da177e4 | 45 | #include <acpi/acpi.h> |
e2f7a777 LB |
46 | #include "accommon.h" |
47 | #include "acparser.h" | |
48 | #include "amlcode.h" | |
49 | #include "acdispat.h" | |
50 | #include "acinterp.h" | |
51 | #include "acnamesp.h" | |
52 | #include "acevents.h" | |
53 | #include "actables.h" | |
1da177e4 LT |
54 | |
55 | #define _COMPONENT ACPI_DISPATCHER | |
4be44fcd | 56 | ACPI_MODULE_NAME("dsopcode") |
1da177e4 | 57 | |
44f6c012 | 58 | /* Local prototypes */ |
44f6c012 | 59 | static acpi_status |
4be44fcd LB |
60 | acpi_ds_execute_arguments(struct acpi_namespace_node *node, |
61 | struct acpi_namespace_node *scope_node, | |
62 | u32 aml_length, u8 * aml_start); | |
44f6c012 RM |
63 | |
64 | static acpi_status | |
4be44fcd LB |
65 | acpi_ds_init_buffer_field(u16 aml_opcode, |
66 | union acpi_operand_object *obj_desc, | |
67 | union acpi_operand_object *buffer_desc, | |
68 | union acpi_operand_object *offset_desc, | |
69 | union acpi_operand_object *length_desc, | |
70 | union acpi_operand_object *result_desc); | |
44f6c012 RM |
71 | |
72 | /******************************************************************************* | |
1da177e4 LT |
73 | * |
74 | * FUNCTION: acpi_ds_execute_arguments | |
75 | * | |
44f6c012 RM |
76 | * PARAMETERS: Node - Object NS node |
77 | * scope_node - Parent NS node | |
1da177e4 LT |
78 | * aml_length - Length of executable AML |
79 | * aml_start - Pointer to the AML | |
80 | * | |
81 | * RETURN: Status. | |
82 | * | |
83 | * DESCRIPTION: Late (deferred) execution of region or field arguments | |
84 | * | |
44f6c012 | 85 | ******************************************************************************/ |
1da177e4 | 86 | |
44f6c012 | 87 | static acpi_status |
4be44fcd LB |
88 | acpi_ds_execute_arguments(struct acpi_namespace_node *node, |
89 | struct acpi_namespace_node *scope_node, | |
90 | u32 aml_length, u8 * aml_start) | |
1da177e4 | 91 | { |
4be44fcd LB |
92 | acpi_status status; |
93 | union acpi_parse_object *op; | |
94 | struct acpi_walk_state *walk_state; | |
1da177e4 | 95 | |
b229cf92 | 96 | ACPI_FUNCTION_TRACE(ds_execute_arguments); |
1da177e4 LT |
97 | |
98 | /* | |
99 | * Allocate a new parser op to be the root of the parsed tree | |
100 | */ | |
4be44fcd | 101 | op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); |
1da177e4 | 102 | if (!op) { |
4be44fcd | 103 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
104 | } |
105 | ||
106 | /* Save the Node for use in acpi_ps_parse_aml */ | |
107 | ||
108 | op->common.node = scope_node; | |
109 | ||
110 | /* Create and initialize a new parser state */ | |
111 | ||
4be44fcd | 112 | walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); |
1da177e4 | 113 | if (!walk_state) { |
88ac00f5 RM |
114 | status = AE_NO_MEMORY; |
115 | goto cleanup; | |
1da177e4 LT |
116 | } |
117 | ||
4be44fcd | 118 | status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, |
ec3153fb | 119 | aml_length, NULL, ACPI_IMODE_LOAD_PASS1); |
4be44fcd LB |
120 | if (ACPI_FAILURE(status)) { |
121 | acpi_ds_delete_walk_state(walk_state); | |
88ac00f5 | 122 | goto cleanup; |
1da177e4 LT |
123 | } |
124 | ||
125 | /* Mark this parse as a deferred opcode */ | |
126 | ||
127 | walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP; | |
128 | walk_state->deferred_node = node; | |
129 | ||
130 | /* Pass1: Parse the entire declaration */ | |
131 | ||
4be44fcd LB |
132 | status = acpi_ps_parse_aml(walk_state); |
133 | if (ACPI_FAILURE(status)) { | |
88ac00f5 | 134 | goto cleanup; |
1da177e4 LT |
135 | } |
136 | ||
137 | /* Get and init the Op created above */ | |
138 | ||
139 | op->common.node = node; | |
4be44fcd | 140 | acpi_ps_delete_parse_tree(op); |
1da177e4 LT |
141 | |
142 | /* Evaluate the deferred arguments */ | |
143 | ||
4be44fcd | 144 | op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); |
1da177e4 | 145 | if (!op) { |
4be44fcd | 146 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
147 | } |
148 | ||
149 | op->common.node = scope_node; | |
150 | ||
151 | /* Create and initialize a new parser state */ | |
152 | ||
4be44fcd | 153 | walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); |
1da177e4 | 154 | if (!walk_state) { |
88ac00f5 RM |
155 | status = AE_NO_MEMORY; |
156 | goto cleanup; | |
1da177e4 LT |
157 | } |
158 | ||
159 | /* Execute the opcode and arguments */ | |
160 | ||
4be44fcd | 161 | status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, |
ec3153fb | 162 | aml_length, NULL, ACPI_IMODE_EXECUTE); |
4be44fcd LB |
163 | if (ACPI_FAILURE(status)) { |
164 | acpi_ds_delete_walk_state(walk_state); | |
88ac00f5 | 165 | goto cleanup; |
1da177e4 LT |
166 | } |
167 | ||
168 | /* Mark this execution as a deferred opcode */ | |
169 | ||
170 | walk_state->deferred_node = node; | |
4be44fcd | 171 | status = acpi_ps_parse_aml(walk_state); |
88ac00f5 | 172 | |
4be44fcd LB |
173 | cleanup: |
174 | acpi_ps_delete_parse_tree(op); | |
175 | return_ACPI_STATUS(status); | |
1da177e4 LT |
176 | } |
177 | ||
44f6c012 | 178 | /******************************************************************************* |
1da177e4 LT |
179 | * |
180 | * FUNCTION: acpi_ds_get_buffer_field_arguments | |
181 | * | |
182 | * PARAMETERS: obj_desc - A valid buffer_field object | |
183 | * | |
184 | * RETURN: Status. | |
185 | * | |
186 | * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late | |
187 | * evaluation of these field attributes. | |
188 | * | |
44f6c012 | 189 | ******************************************************************************/ |
1da177e4 LT |
190 | |
191 | acpi_status | |
4be44fcd | 192 | acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc) |
1da177e4 | 193 | { |
4be44fcd LB |
194 | union acpi_operand_object *extra_desc; |
195 | struct acpi_namespace_node *node; | |
196 | acpi_status status; | |
1da177e4 | 197 | |
b229cf92 | 198 | ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc); |
1da177e4 LT |
199 | |
200 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | |
4be44fcd | 201 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
202 | } |
203 | ||
204 | /* Get the AML pointer (method object) and buffer_field node */ | |
205 | ||
4be44fcd | 206 | extra_desc = acpi_ns_get_secondary_object(obj_desc); |
1da177e4 LT |
207 | node = obj_desc->buffer_field.node; |
208 | ||
4be44fcd LB |
209 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
210 | (ACPI_TYPE_BUFFER_FIELD, node, NULL)); | |
b229cf92 | 211 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n", |
4be44fcd | 212 | acpi_ut_get_node_name(node))); |
1da177e4 LT |
213 | |
214 | /* Execute the AML code for the term_arg arguments */ | |
215 | ||
4be44fcd LB |
216 | status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node), |
217 | extra_desc->extra.aml_length, | |
218 | extra_desc->extra.aml_start); | |
219 | return_ACPI_STATUS(status); | |
1da177e4 LT |
220 | } |
221 | ||
ef805d95 LM |
222 | /******************************************************************************* |
223 | * | |
224 | * FUNCTION: acpi_ds_get_bank_field_arguments | |
225 | * | |
226 | * PARAMETERS: obj_desc - A valid bank_field object | |
227 | * | |
228 | * RETURN: Status. | |
229 | * | |
230 | * DESCRIPTION: Get bank_field bank_value. This implements the late | |
231 | * evaluation of these field attributes. | |
232 | * | |
233 | ******************************************************************************/ | |
234 | ||
235 | acpi_status | |
236 | acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc) | |
237 | { | |
238 | union acpi_operand_object *extra_desc; | |
239 | struct acpi_namespace_node *node; | |
240 | acpi_status status; | |
241 | ||
242 | ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc); | |
243 | ||
244 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | |
245 | return_ACPI_STATUS(AE_OK); | |
246 | } | |
247 | ||
248 | /* Get the AML pointer (method object) and bank_field node */ | |
249 | ||
250 | extra_desc = acpi_ns_get_secondary_object(obj_desc); | |
251 | node = obj_desc->bank_field.node; | |
252 | ||
253 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname | |
254 | (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL)); | |
255 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n", | |
256 | acpi_ut_get_node_name(node))); | |
257 | ||
258 | /* Execute the AML code for the term_arg arguments */ | |
259 | ||
260 | status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node), | |
261 | extra_desc->extra.aml_length, | |
262 | extra_desc->extra.aml_start); | |
263 | return_ACPI_STATUS(status); | |
264 | } | |
265 | ||
44f6c012 | 266 | /******************************************************************************* |
1da177e4 LT |
267 | * |
268 | * FUNCTION: acpi_ds_get_buffer_arguments | |
269 | * | |
270 | * PARAMETERS: obj_desc - A valid Buffer object | |
271 | * | |
272 | * RETURN: Status. | |
273 | * | |
274 | * DESCRIPTION: Get Buffer length and initializer byte list. This implements | |
275 | * the late evaluation of these attributes. | |
276 | * | |
44f6c012 | 277 | ******************************************************************************/ |
1da177e4 | 278 | |
4be44fcd | 279 | acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc) |
1da177e4 | 280 | { |
4be44fcd LB |
281 | struct acpi_namespace_node *node; |
282 | acpi_status status; | |
1da177e4 | 283 | |
b229cf92 | 284 | ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc); |
1da177e4 LT |
285 | |
286 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | |
4be44fcd | 287 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
288 | } |
289 | ||
290 | /* Get the Buffer node */ | |
291 | ||
292 | node = obj_desc->buffer.node; | |
293 | if (!node) { | |
b8e4d893 BM |
294 | ACPI_ERROR((AE_INFO, |
295 | "No pointer back to NS node in buffer obj %p", | |
296 | obj_desc)); | |
4be44fcd | 297 | return_ACPI_STATUS(AE_AML_INTERNAL); |
1da177e4 LT |
298 | } |
299 | ||
4be44fcd | 300 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n")); |
1da177e4 LT |
301 | |
302 | /* Execute the AML code for the term_arg arguments */ | |
303 | ||
4be44fcd LB |
304 | status = acpi_ds_execute_arguments(node, node, |
305 | obj_desc->buffer.aml_length, | |
306 | obj_desc->buffer.aml_start); | |
307 | return_ACPI_STATUS(status); | |
1da177e4 LT |
308 | } |
309 | ||
44f6c012 | 310 | /******************************************************************************* |
1da177e4 LT |
311 | * |
312 | * FUNCTION: acpi_ds_get_package_arguments | |
313 | * | |
314 | * PARAMETERS: obj_desc - A valid Package object | |
315 | * | |
316 | * RETURN: Status. | |
317 | * | |
318 | * DESCRIPTION: Get Package length and initializer byte list. This implements | |
319 | * the late evaluation of these attributes. | |
320 | * | |
44f6c012 | 321 | ******************************************************************************/ |
1da177e4 | 322 | |
4be44fcd | 323 | acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc) |
1da177e4 | 324 | { |
4be44fcd LB |
325 | struct acpi_namespace_node *node; |
326 | acpi_status status; | |
1da177e4 | 327 | |
b229cf92 | 328 | ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc); |
1da177e4 LT |
329 | |
330 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | |
4be44fcd | 331 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
332 | } |
333 | ||
334 | /* Get the Package node */ | |
335 | ||
336 | node = obj_desc->package.node; | |
337 | if (!node) { | |
b8e4d893 BM |
338 | ACPI_ERROR((AE_INFO, |
339 | "No pointer back to NS node in package %p", | |
340 | obj_desc)); | |
4be44fcd | 341 | return_ACPI_STATUS(AE_AML_INTERNAL); |
1da177e4 LT |
342 | } |
343 | ||
4be44fcd | 344 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n")); |
1da177e4 LT |
345 | |
346 | /* Execute the AML code for the term_arg arguments */ | |
347 | ||
4be44fcd LB |
348 | status = acpi_ds_execute_arguments(node, node, |
349 | obj_desc->package.aml_length, | |
350 | obj_desc->package.aml_start); | |
351 | return_ACPI_STATUS(status); | |
1da177e4 LT |
352 | } |
353 | ||
1da177e4 LT |
354 | /***************************************************************************** |
355 | * | |
356 | * FUNCTION: acpi_ds_get_region_arguments | |
357 | * | |
358 | * PARAMETERS: obj_desc - A valid region object | |
359 | * | |
360 | * RETURN: Status. | |
361 | * | |
362 | * DESCRIPTION: Get region address and length. This implements the late | |
363 | * evaluation of these region attributes. | |
364 | * | |
365 | ****************************************************************************/ | |
366 | ||
4be44fcd | 367 | acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc) |
1da177e4 | 368 | { |
4be44fcd LB |
369 | struct acpi_namespace_node *node; |
370 | acpi_status status; | |
371 | union acpi_operand_object *extra_desc; | |
1da177e4 | 372 | |
b229cf92 | 373 | ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc); |
1da177e4 LT |
374 | |
375 | if (obj_desc->region.flags & AOPOBJ_DATA_VALID) { | |
4be44fcd | 376 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
377 | } |
378 | ||
4be44fcd | 379 | extra_desc = acpi_ns_get_secondary_object(obj_desc); |
1da177e4 | 380 | if (!extra_desc) { |
4be44fcd | 381 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
382 | } |
383 | ||
384 | /* Get the Region node */ | |
385 | ||
386 | node = obj_desc->region.node; | |
387 | ||
4be44fcd LB |
388 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
389 | (ACPI_TYPE_REGION, node, NULL)); | |
1da177e4 | 390 | |
b229cf92 | 391 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n", |
4be44fcd LB |
392 | acpi_ut_get_node_name(node), |
393 | extra_desc->extra.aml_start)); | |
1da177e4 LT |
394 | |
395 | /* Execute the argument AML */ | |
396 | ||
4be44fcd LB |
397 | status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node), |
398 | extra_desc->extra.aml_length, | |
399 | extra_desc->extra.aml_start); | |
b229cf92 BM |
400 | if (ACPI_FAILURE(status)) { |
401 | return_ACPI_STATUS(status); | |
402 | } | |
403 | ||
404 | /* Validate the region address/length via the host OS */ | |
405 | ||
406 | status = acpi_os_validate_address(obj_desc->region.space_id, | |
407 | obj_desc->region.address, | |
df92e695 TR |
408 | (acpi_size) obj_desc->region.length, |
409 | acpi_ut_get_node_name(node)); | |
410 | ||
b229cf92 BM |
411 | if (ACPI_FAILURE(status)) { |
412 | /* | |
413 | * Invalid address/length. We will emit an error message and mark | |
414 | * the region as invalid, so that it will cause an additional error if | |
415 | * it is ever used. Then return AE_OK. | |
416 | */ | |
417 | ACPI_EXCEPTION((AE_INFO, status, | |
418 | "During address validation of OpRegion [%4.4s]", | |
419 | node->name.ascii)); | |
420 | obj_desc->common.flags |= AOPOBJ_INVALID; | |
421 | status = AE_OK; | |
422 | } | |
423 | ||
4be44fcd | 424 | return_ACPI_STATUS(status); |
1da177e4 LT |
425 | } |
426 | ||
44f6c012 | 427 | /******************************************************************************* |
1da177e4 LT |
428 | * |
429 | * FUNCTION: acpi_ds_initialize_region | |
430 | * | |
44f6c012 | 431 | * PARAMETERS: obj_handle - Region namespace node |
1da177e4 LT |
432 | * |
433 | * RETURN: Status | |
434 | * | |
435 | * DESCRIPTION: Front end to ev_initialize_region | |
436 | * | |
44f6c012 | 437 | ******************************************************************************/ |
1da177e4 | 438 | |
4be44fcd | 439 | acpi_status acpi_ds_initialize_region(acpi_handle obj_handle) |
1da177e4 | 440 | { |
4be44fcd LB |
441 | union acpi_operand_object *obj_desc; |
442 | acpi_status status; | |
1da177e4 | 443 | |
4be44fcd | 444 | obj_desc = acpi_ns_get_attached_object(obj_handle); |
1da177e4 LT |
445 | |
446 | /* Namespace is NOT locked */ | |
447 | ||
4be44fcd | 448 | status = acpi_ev_initialize_region(obj_desc, FALSE); |
1da177e4 LT |
449 | return (status); |
450 | } | |
451 | ||
44f6c012 | 452 | /******************************************************************************* |
1da177e4 LT |
453 | * |
454 | * FUNCTION: acpi_ds_init_buffer_field | |
455 | * | |
456 | * PARAMETERS: aml_opcode - create_xxx_field | |
457 | * obj_desc - buffer_field object | |
458 | * buffer_desc - Host Buffer | |
459 | * offset_desc - Offset into buffer | |
44f6c012 RM |
460 | * length_desc - Length of field (CREATE_FIELD_OP only) |
461 | * result_desc - Where to store the result | |
1da177e4 LT |
462 | * |
463 | * RETURN: Status | |
464 | * | |
465 | * DESCRIPTION: Perform actual initialization of a buffer field | |
466 | * | |
44f6c012 | 467 | ******************************************************************************/ |
1da177e4 | 468 | |
44f6c012 | 469 | static acpi_status |
4be44fcd LB |
470 | acpi_ds_init_buffer_field(u16 aml_opcode, |
471 | union acpi_operand_object *obj_desc, | |
472 | union acpi_operand_object *buffer_desc, | |
473 | union acpi_operand_object *offset_desc, | |
474 | union acpi_operand_object *length_desc, | |
475 | union acpi_operand_object *result_desc) | |
1da177e4 | 476 | { |
4be44fcd LB |
477 | u32 offset; |
478 | u32 bit_offset; | |
479 | u32 bit_count; | |
480 | u8 field_flags; | |
481 | acpi_status status; | |
1da177e4 | 482 | |
b229cf92 | 483 | ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc); |
1da177e4 LT |
484 | |
485 | /* Host object must be a Buffer */ | |
486 | ||
4be44fcd | 487 | if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) { |
b8e4d893 BM |
488 | ACPI_ERROR((AE_INFO, |
489 | "Target of Create Field is not a Buffer object - %s", | |
490 | acpi_ut_get_object_type_name(buffer_desc))); | |
1da177e4 LT |
491 | |
492 | status = AE_AML_OPERAND_TYPE; | |
493 | goto cleanup; | |
494 | } | |
495 | ||
496 | /* | |
497 | * The last parameter to all of these opcodes (result_desc) started | |
498 | * out as a name_string, and should therefore now be a NS node | |
499 | * after resolution in acpi_ex_resolve_operands(). | |
500 | */ | |
4be44fcd | 501 | if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) { |
b8e4d893 BM |
502 | ACPI_ERROR((AE_INFO, |
503 | "(%s) destination not a NS Node [%s]", | |
504 | acpi_ps_get_opcode_name(aml_opcode), | |
505 | acpi_ut_get_descriptor_name(result_desc))); | |
1da177e4 LT |
506 | |
507 | status = AE_AML_OPERAND_TYPE; | |
508 | goto cleanup; | |
509 | } | |
510 | ||
511 | offset = (u32) offset_desc->integer.value; | |
512 | ||
513 | /* | |
514 | * Setup the Bit offsets and counts, according to the opcode | |
515 | */ | |
516 | switch (aml_opcode) { | |
517 | case AML_CREATE_FIELD_OP: | |
518 | ||
519 | /* Offset is in bits, count is in bits */ | |
520 | ||
44f6c012 | 521 | field_flags = AML_FIELD_ACCESS_BYTE; |
1da177e4 | 522 | bit_offset = offset; |
4be44fcd | 523 | bit_count = (u32) length_desc->integer.value; |
44f6c012 RM |
524 | |
525 | /* Must have a valid (>0) bit count */ | |
526 | ||
527 | if (bit_count == 0) { | |
b8e4d893 | 528 | ACPI_ERROR((AE_INFO, |
b229cf92 | 529 | "Attempt to CreateField of length zero")); |
44f6c012 RM |
530 | status = AE_AML_OPERAND_VALUE; |
531 | goto cleanup; | |
532 | } | |
1da177e4 LT |
533 | break; |
534 | ||
535 | case AML_CREATE_BIT_FIELD_OP: | |
536 | ||
537 | /* Offset is in bits, Field is one bit */ | |
538 | ||
539 | bit_offset = offset; | |
4be44fcd | 540 | bit_count = 1; |
1da177e4 LT |
541 | field_flags = AML_FIELD_ACCESS_BYTE; |
542 | break; | |
543 | ||
544 | case AML_CREATE_BYTE_FIELD_OP: | |
545 | ||
546 | /* Offset is in bytes, field is one byte */ | |
547 | ||
548 | bit_offset = 8 * offset; | |
4be44fcd | 549 | bit_count = 8; |
1da177e4 LT |
550 | field_flags = AML_FIELD_ACCESS_BYTE; |
551 | break; | |
552 | ||
553 | case AML_CREATE_WORD_FIELD_OP: | |
554 | ||
555 | /* Offset is in bytes, field is one word */ | |
556 | ||
557 | bit_offset = 8 * offset; | |
4be44fcd | 558 | bit_count = 16; |
1da177e4 LT |
559 | field_flags = AML_FIELD_ACCESS_WORD; |
560 | break; | |
561 | ||
562 | case AML_CREATE_DWORD_FIELD_OP: | |
563 | ||
564 | /* Offset is in bytes, field is one dword */ | |
565 | ||
566 | bit_offset = 8 * offset; | |
4be44fcd | 567 | bit_count = 32; |
1da177e4 LT |
568 | field_flags = AML_FIELD_ACCESS_DWORD; |
569 | break; | |
570 | ||
571 | case AML_CREATE_QWORD_FIELD_OP: | |
572 | ||
573 | /* Offset is in bytes, field is one qword */ | |
574 | ||
575 | bit_offset = 8 * offset; | |
4be44fcd | 576 | bit_count = 64; |
1da177e4 LT |
577 | field_flags = AML_FIELD_ACCESS_QWORD; |
578 | break; | |
579 | ||
580 | default: | |
581 | ||
b8e4d893 BM |
582 | ACPI_ERROR((AE_INFO, |
583 | "Unknown field creation opcode %02x", aml_opcode)); | |
1da177e4 LT |
584 | status = AE_AML_BAD_OPCODE; |
585 | goto cleanup; | |
586 | } | |
587 | ||
588 | /* Entire field must fit within the current length of the buffer */ | |
589 | ||
4be44fcd | 590 | if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) { |
b8e4d893 BM |
591 | ACPI_ERROR((AE_INFO, |
592 | "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)", | |
593 | acpi_ut_get_node_name(result_desc), | |
594 | bit_offset + bit_count, | |
595 | acpi_ut_get_node_name(buffer_desc->buffer.node), | |
596 | 8 * (u32) buffer_desc->buffer.length)); | |
1da177e4 LT |
597 | status = AE_AML_BUFFER_LIMIT; |
598 | goto cleanup; | |
599 | } | |
600 | ||
601 | /* | |
602 | * Initialize areas of the field object that are common to all fields | |
44f6c012 RM |
603 | * For field_flags, use LOCK_RULE = 0 (NO_LOCK), |
604 | * UPDATE_RULE = 0 (UPDATE_PRESERVE) | |
1da177e4 | 605 | */ |
4be44fcd LB |
606 | status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0, |
607 | bit_offset, bit_count); | |
608 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
609 | goto cleanup; |
610 | } | |
611 | ||
612 | obj_desc->buffer_field.buffer_obj = buffer_desc; | |
613 | ||
614 | /* Reference count for buffer_desc inherits obj_desc count */ | |
615 | ||
44f6c012 | 616 | buffer_desc->common.reference_count = (u16) |
4be44fcd LB |
617 | (buffer_desc->common.reference_count + |
618 | obj_desc->common.reference_count); | |
1da177e4 | 619 | |
4be44fcd | 620 | cleanup: |
1da177e4 LT |
621 | |
622 | /* Always delete the operands */ | |
623 | ||
4be44fcd LB |
624 | acpi_ut_remove_reference(offset_desc); |
625 | acpi_ut_remove_reference(buffer_desc); | |
1da177e4 LT |
626 | |
627 | if (aml_opcode == AML_CREATE_FIELD_OP) { | |
4be44fcd | 628 | acpi_ut_remove_reference(length_desc); |
1da177e4 LT |
629 | } |
630 | ||
631 | /* On failure, delete the result descriptor */ | |
632 | ||
4be44fcd LB |
633 | if (ACPI_FAILURE(status)) { |
634 | acpi_ut_remove_reference(result_desc); /* Result descriptor */ | |
635 | } else { | |
1da177e4 LT |
636 | /* Now the address and length are valid for this buffer_field */ |
637 | ||
638 | obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID; | |
639 | } | |
640 | ||
4be44fcd | 641 | return_ACPI_STATUS(status); |
1da177e4 LT |
642 | } |
643 | ||
44f6c012 | 644 | /******************************************************************************* |
1da177e4 LT |
645 | * |
646 | * FUNCTION: acpi_ds_eval_buffer_field_operands | |
647 | * | |
648 | * PARAMETERS: walk_state - Current walk | |
649 | * Op - A valid buffer_field Op object | |
650 | * | |
651 | * RETURN: Status | |
652 | * | |
653 | * DESCRIPTION: Get buffer_field Buffer and Index | |
654 | * Called from acpi_ds_exec_end_op during buffer_field parse tree walk | |
655 | * | |
44f6c012 | 656 | ******************************************************************************/ |
1da177e4 LT |
657 | |
658 | acpi_status | |
4be44fcd LB |
659 | acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state, |
660 | union acpi_parse_object *op) | |
1da177e4 | 661 | { |
4be44fcd LB |
662 | acpi_status status; |
663 | union acpi_operand_object *obj_desc; | |
664 | struct acpi_namespace_node *node; | |
665 | union acpi_parse_object *next_op; | |
1da177e4 | 666 | |
b229cf92 | 667 | ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op); |
1da177e4 LT |
668 | |
669 | /* | |
670 | * This is where we evaluate the address and length fields of the | |
671 | * create_xxx_field declaration | |
672 | */ | |
4be44fcd | 673 | node = op->common.node; |
1da177e4 LT |
674 | |
675 | /* next_op points to the op that holds the Buffer */ | |
676 | ||
677 | next_op = op->common.value.arg; | |
678 | ||
679 | /* Evaluate/create the address and length operands */ | |
680 | ||
4be44fcd LB |
681 | status = acpi_ds_create_operands(walk_state, next_op); |
682 | if (ACPI_FAILURE(status)) { | |
683 | return_ACPI_STATUS(status); | |
1da177e4 LT |
684 | } |
685 | ||
4be44fcd | 686 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 687 | if (!obj_desc) { |
4be44fcd | 688 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
689 | } |
690 | ||
691 | /* Resolve the operands */ | |
692 | ||
4be44fcd LB |
693 | status = acpi_ex_resolve_operands(op->common.aml_opcode, |
694 | ACPI_WALK_OPERANDS, walk_state); | |
4be44fcd | 695 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
696 | ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)", |
697 | acpi_ps_get_opcode_name(op->common.aml_opcode), | |
698 | status)); | |
1da177e4 | 699 | |
4be44fcd | 700 | return_ACPI_STATUS(status); |
1da177e4 LT |
701 | } |
702 | ||
703 | /* Initialize the Buffer Field */ | |
704 | ||
705 | if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { | |
52fc0b02 | 706 | |
1da177e4 LT |
707 | /* NOTE: Slightly different operands for this opcode */ |
708 | ||
4be44fcd LB |
709 | status = |
710 | acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc, | |
711 | walk_state->operands[0], | |
712 | walk_state->operands[1], | |
713 | walk_state->operands[2], | |
714 | walk_state->operands[3]); | |
715 | } else { | |
1da177e4 LT |
716 | /* All other, create_xxx_field opcodes */ |
717 | ||
4be44fcd LB |
718 | status = |
719 | acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc, | |
720 | walk_state->operands[0], | |
721 | walk_state->operands[1], NULL, | |
722 | walk_state->operands[2]); | |
1da177e4 LT |
723 | } |
724 | ||
4be44fcd | 725 | return_ACPI_STATUS(status); |
1da177e4 LT |
726 | } |
727 | ||
44f6c012 | 728 | /******************************************************************************* |
1da177e4 LT |
729 | * |
730 | * FUNCTION: acpi_ds_eval_region_operands | |
731 | * | |
732 | * PARAMETERS: walk_state - Current walk | |
733 | * Op - A valid region Op object | |
734 | * | |
735 | * RETURN: Status | |
736 | * | |
737 | * DESCRIPTION: Get region address and length | |
738 | * Called from acpi_ds_exec_end_op during op_region parse tree walk | |
739 | * | |
44f6c012 | 740 | ******************************************************************************/ |
1da177e4 LT |
741 | |
742 | acpi_status | |
4be44fcd LB |
743 | acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state, |
744 | union acpi_parse_object *op) | |
1da177e4 | 745 | { |
4be44fcd LB |
746 | acpi_status status; |
747 | union acpi_operand_object *obj_desc; | |
748 | union acpi_operand_object *operand_desc; | |
749 | struct acpi_namespace_node *node; | |
750 | union acpi_parse_object *next_op; | |
1da177e4 | 751 | |
b229cf92 | 752 | ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op); |
1da177e4 LT |
753 | |
754 | /* | |
44f6c012 RM |
755 | * This is where we evaluate the address and length fields of the |
756 | * op_region declaration | |
1da177e4 | 757 | */ |
4be44fcd | 758 | node = op->common.node; |
1da177e4 LT |
759 | |
760 | /* next_op points to the op that holds the space_iD */ | |
761 | ||
762 | next_op = op->common.value.arg; | |
763 | ||
764 | /* next_op points to address op */ | |
765 | ||
766 | next_op = next_op->common.next; | |
767 | ||
768 | /* Evaluate/create the address and length operands */ | |
769 | ||
4be44fcd LB |
770 | status = acpi_ds_create_operands(walk_state, next_op); |
771 | if (ACPI_FAILURE(status)) { | |
772 | return_ACPI_STATUS(status); | |
1da177e4 LT |
773 | } |
774 | ||
775 | /* Resolve the length and address operands to numbers */ | |
776 | ||
4be44fcd LB |
777 | status = acpi_ex_resolve_operands(op->common.aml_opcode, |
778 | ACPI_WALK_OPERANDS, walk_state); | |
779 | if (ACPI_FAILURE(status)) { | |
780 | return_ACPI_STATUS(status); | |
1da177e4 LT |
781 | } |
782 | ||
4be44fcd | 783 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 784 | if (!obj_desc) { |
4be44fcd | 785 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
786 | } |
787 | ||
788 | /* | |
789 | * Get the length operand and save it | |
790 | * (at Top of stack) | |
791 | */ | |
792 | operand_desc = walk_state->operands[walk_state->num_operands - 1]; | |
793 | ||
794 | obj_desc->region.length = (u32) operand_desc->integer.value; | |
4be44fcd | 795 | acpi_ut_remove_reference(operand_desc); |
1da177e4 LT |
796 | |
797 | /* | |
798 | * Get the address and save it | |
799 | * (at top of stack - 1) | |
800 | */ | |
801 | operand_desc = walk_state->operands[walk_state->num_operands - 2]; | |
802 | ||
44f6c012 | 803 | obj_desc->region.address = (acpi_physical_address) |
4be44fcd LB |
804 | operand_desc->integer.value; |
805 | acpi_ut_remove_reference(operand_desc); | |
1da177e4 | 806 | |
b229cf92 | 807 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n", |
4be44fcd | 808 | obj_desc, |
b7f9f042 | 809 | ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address), |
4be44fcd | 810 | obj_desc->region.length)); |
1da177e4 LT |
811 | |
812 | /* Now the address and length are valid for this opregion */ | |
813 | ||
814 | obj_desc->region.flags |= AOPOBJ_DATA_VALID; | |
815 | ||
4be44fcd | 816 | return_ACPI_STATUS(status); |
1da177e4 LT |
817 | } |
818 | ||
941f48bb LM |
819 | /******************************************************************************* |
820 | * | |
821 | * FUNCTION: acpi_ds_eval_table_region_operands | |
822 | * | |
823 | * PARAMETERS: walk_state - Current walk | |
824 | * Op - A valid region Op object | |
825 | * | |
826 | * RETURN: Status | |
827 | * | |
828 | * DESCRIPTION: Get region address and length | |
829 | * Called from acpi_ds_exec_end_op during data_table_region parse tree walk | |
830 | * | |
831 | ******************************************************************************/ | |
832 | ||
833 | acpi_status | |
834 | acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state, | |
835 | union acpi_parse_object *op) | |
836 | { | |
837 | acpi_status status; | |
838 | union acpi_operand_object *obj_desc; | |
839 | union acpi_operand_object **operand; | |
840 | struct acpi_namespace_node *node; | |
841 | union acpi_parse_object *next_op; | |
67a119f9 | 842 | u32 table_index; |
941f48bb LM |
843 | struct acpi_table_header *table; |
844 | ||
845 | ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op); | |
846 | ||
847 | /* | |
848 | * This is where we evaluate the signature_string and oem_iDString | |
849 | * and oem_table_iDString of the data_table_region declaration | |
850 | */ | |
851 | node = op->common.node; | |
852 | ||
853 | /* next_op points to signature_string op */ | |
854 | ||
855 | next_op = op->common.value.arg; | |
856 | ||
857 | /* | |
858 | * Evaluate/create the signature_string and oem_iDString | |
859 | * and oem_table_iDString operands | |
860 | */ | |
861 | status = acpi_ds_create_operands(walk_state, next_op); | |
862 | if (ACPI_FAILURE(status)) { | |
863 | return_ACPI_STATUS(status); | |
864 | } | |
865 | ||
866 | /* | |
867 | * Resolve the signature_string and oem_iDString | |
868 | * and oem_table_iDString operands | |
869 | */ | |
870 | status = acpi_ex_resolve_operands(op->common.aml_opcode, | |
871 | ACPI_WALK_OPERANDS, walk_state); | |
872 | if (ACPI_FAILURE(status)) { | |
873 | return_ACPI_STATUS(status); | |
874 | } | |
875 | ||
941f48bb LM |
876 | operand = &walk_state->operands[0]; |
877 | ||
878 | /* Find the ACPI table */ | |
879 | ||
880 | status = acpi_tb_find_table(operand[0]->string.pointer, | |
881 | operand[1]->string.pointer, | |
882 | operand[2]->string.pointer, &table_index); | |
883 | if (ACPI_FAILURE(status)) { | |
884 | return_ACPI_STATUS(status); | |
885 | } | |
886 | ||
887 | acpi_ut_remove_reference(operand[0]); | |
888 | acpi_ut_remove_reference(operand[1]); | |
889 | acpi_ut_remove_reference(operand[2]); | |
890 | ||
891 | status = acpi_get_table_by_index(table_index, &table); | |
892 | if (ACPI_FAILURE(status)) { | |
893 | return_ACPI_STATUS(status); | |
894 | } | |
895 | ||
896 | obj_desc = acpi_ns_get_attached_object(node); | |
897 | if (!obj_desc) { | |
898 | return_ACPI_STATUS(AE_NOT_EXIST); | |
899 | } | |
900 | ||
901 | obj_desc->region.address = | |
902 | (acpi_physical_address) ACPI_TO_INTEGER(table); | |
903 | obj_desc->region.length = table->length; | |
904 | ||
905 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n", | |
906 | obj_desc, | |
907 | ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address), | |
908 | obj_desc->region.length)); | |
909 | ||
910 | /* Now the address and length are valid for this opregion */ | |
911 | ||
912 | obj_desc->region.flags |= AOPOBJ_DATA_VALID; | |
913 | ||
914 | return_ACPI_STATUS(status); | |
915 | } | |
916 | ||
44f6c012 | 917 | /******************************************************************************* |
1da177e4 LT |
918 | * |
919 | * FUNCTION: acpi_ds_eval_data_object_operands | |
920 | * | |
921 | * PARAMETERS: walk_state - Current walk | |
922 | * Op - A valid data_object Op object | |
923 | * obj_desc - data_object | |
924 | * | |
925 | * RETURN: Status | |
926 | * | |
927 | * DESCRIPTION: Get the operands and complete the following data object types: | |
928 | * Buffer, Package. | |
929 | * | |
44f6c012 | 930 | ******************************************************************************/ |
1da177e4 LT |
931 | |
932 | acpi_status | |
4be44fcd LB |
933 | acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state, |
934 | union acpi_parse_object *op, | |
935 | union acpi_operand_object *obj_desc) | |
1da177e4 | 936 | { |
4be44fcd LB |
937 | acpi_status status; |
938 | union acpi_operand_object *arg_desc; | |
939 | u32 length; | |
1da177e4 | 940 | |
b229cf92 | 941 | ACPI_FUNCTION_TRACE(ds_eval_data_object_operands); |
1da177e4 LT |
942 | |
943 | /* The first operand (for all of these data objects) is the length */ | |
944 | ||
773069d4 BM |
945 | /* |
946 | * Set proper index into operand stack for acpi_ds_obj_stack_push | |
947 | * invoked inside acpi_ds_create_operand. | |
948 | */ | |
949 | walk_state->operand_index = walk_state->num_operands; | |
950 | ||
4be44fcd LB |
951 | status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1); |
952 | if (ACPI_FAILURE(status)) { | |
953 | return_ACPI_STATUS(status); | |
1da177e4 LT |
954 | } |
955 | ||
4be44fcd LB |
956 | status = acpi_ex_resolve_operands(walk_state->opcode, |
957 | &(walk_state-> | |
958 | operands[walk_state->num_operands - | |
959 | 1]), walk_state); | |
960 | if (ACPI_FAILURE(status)) { | |
961 | return_ACPI_STATUS(status); | |
1da177e4 LT |
962 | } |
963 | ||
964 | /* Extract length operand */ | |
965 | ||
4be44fcd | 966 | arg_desc = walk_state->operands[walk_state->num_operands - 1]; |
1da177e4 LT |
967 | length = (u32) arg_desc->integer.value; |
968 | ||
969 | /* Cleanup for length operand */ | |
970 | ||
4be44fcd LB |
971 | status = acpi_ds_obj_stack_pop(1, walk_state); |
972 | if (ACPI_FAILURE(status)) { | |
973 | return_ACPI_STATUS(status); | |
1da177e4 LT |
974 | } |
975 | ||
4be44fcd | 976 | acpi_ut_remove_reference(arg_desc); |
1da177e4 LT |
977 | |
978 | /* | |
979 | * Create the actual data object | |
980 | */ | |
981 | switch (op->common.aml_opcode) { | |
982 | case AML_BUFFER_OP: | |
983 | ||
4be44fcd LB |
984 | status = |
985 | acpi_ds_build_internal_buffer_obj(walk_state, op, length, | |
986 | &obj_desc); | |
1da177e4 LT |
987 | break; |
988 | ||
989 | case AML_PACKAGE_OP: | |
990 | case AML_VAR_PACKAGE_OP: | |
991 | ||
4be44fcd LB |
992 | status = |
993 | acpi_ds_build_internal_package_obj(walk_state, op, length, | |
994 | &obj_desc); | |
1da177e4 LT |
995 | break; |
996 | ||
997 | default: | |
4be44fcd | 998 | return_ACPI_STATUS(AE_AML_BAD_OPCODE); |
1da177e4 LT |
999 | } |
1000 | ||
4be44fcd | 1001 | if (ACPI_SUCCESS(status)) { |
1da177e4 | 1002 | /* |
44f6c012 | 1003 | * Return the object in the walk_state, unless the parent is a package - |
1da177e4 LT |
1004 | * in this case, the return object will be stored in the parse tree |
1005 | * for the package. | |
1006 | */ | |
1007 | if ((!op->common.parent) || | |
4be44fcd LB |
1008 | ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) && |
1009 | (op->common.parent->common.aml_opcode != | |
1010 | AML_VAR_PACKAGE_OP) | |
fd350943 | 1011 | && (op->common.parent->common.aml_opcode != AML_NAME_OP))) { |
1da177e4 LT |
1012 | walk_state->result_obj = obj_desc; |
1013 | } | |
1014 | } | |
1015 | ||
4be44fcd | 1016 | return_ACPI_STATUS(status); |
1da177e4 LT |
1017 | } |
1018 | ||
ef805d95 LM |
1019 | /******************************************************************************* |
1020 | * | |
1021 | * FUNCTION: acpi_ds_eval_bank_field_operands | |
1022 | * | |
1023 | * PARAMETERS: walk_state - Current walk | |
1024 | * Op - A valid bank_field Op object | |
1025 | * | |
1026 | * RETURN: Status | |
1027 | * | |
1028 | * DESCRIPTION: Get bank_field bank_value | |
1029 | * Called from acpi_ds_exec_end_op during bank_field parse tree walk | |
1030 | * | |
1031 | ******************************************************************************/ | |
1032 | ||
1033 | acpi_status | |
1034 | acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state, | |
1035 | union acpi_parse_object *op) | |
1036 | { | |
1037 | acpi_status status; | |
1038 | union acpi_operand_object *obj_desc; | |
1039 | union acpi_operand_object *operand_desc; | |
1040 | struct acpi_namespace_node *node; | |
1041 | union acpi_parse_object *next_op; | |
1042 | union acpi_parse_object *arg; | |
1043 | ||
1044 | ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op); | |
1045 | ||
1046 | /* | |
1047 | * This is where we evaluate the bank_value field of the | |
1048 | * bank_field declaration | |
1049 | */ | |
1050 | ||
1051 | /* next_op points to the op that holds the Region */ | |
1052 | ||
1053 | next_op = op->common.value.arg; | |
1054 | ||
1055 | /* next_op points to the op that holds the Bank Register */ | |
1056 | ||
1057 | next_op = next_op->common.next; | |
1058 | ||
1059 | /* next_op points to the op that holds the Bank Value */ | |
1060 | ||
1061 | next_op = next_op->common.next; | |
1062 | ||
1063 | /* | |
1064 | * Set proper index into operand stack for acpi_ds_obj_stack_push | |
1065 | * invoked inside acpi_ds_create_operand. | |
1066 | * | |
1067 | * We use walk_state->Operands[0] to store the evaluated bank_value | |
1068 | */ | |
1069 | walk_state->operand_index = 0; | |
1070 | ||
1071 | status = acpi_ds_create_operand(walk_state, next_op, 0); | |
1072 | if (ACPI_FAILURE(status)) { | |
1073 | return_ACPI_STATUS(status); | |
1074 | } | |
1075 | ||
1076 | status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state); | |
1077 | if (ACPI_FAILURE(status)) { | |
1078 | return_ACPI_STATUS(status); | |
1079 | } | |
1080 | ||
71d993e1 BM |
1081 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, |
1082 | acpi_ps_get_opcode_name(op->common.aml_opcode), 1); | |
ef805d95 LM |
1083 | /* |
1084 | * Get the bank_value operand and save it | |
1085 | * (at Top of stack) | |
1086 | */ | |
1087 | operand_desc = walk_state->operands[0]; | |
1088 | ||
1089 | /* Arg points to the start Bank Field */ | |
1090 | ||
1091 | arg = acpi_ps_get_arg(op, 4); | |
1092 | while (arg) { | |
1093 | ||
1094 | /* Ignore OFFSET and ACCESSAS terms here */ | |
1095 | ||
1096 | if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) { | |
1097 | node = arg->common.node; | |
1098 | ||
1099 | obj_desc = acpi_ns_get_attached_object(node); | |
1100 | if (!obj_desc) { | |
1101 | return_ACPI_STATUS(AE_NOT_EXIST); | |
1102 | } | |
1103 | ||
1104 | obj_desc->bank_field.value = | |
1105 | (u32) operand_desc->integer.value; | |
1106 | } | |
1107 | ||
1108 | /* Move to next field in the list */ | |
1109 | ||
1110 | arg = arg->common.next; | |
1111 | } | |
1112 | ||
1113 | acpi_ut_remove_reference(operand_desc); | |
1114 | return_ACPI_STATUS(status); | |
1115 | } | |
1116 | ||
1da177e4 LT |
1117 | /******************************************************************************* |
1118 | * | |
1119 | * FUNCTION: acpi_ds_exec_begin_control_op | |
1120 | * | |
1121 | * PARAMETERS: walk_list - The list that owns the walk stack | |
1122 | * Op - The control Op | |
1123 | * | |
1124 | * RETURN: Status | |
1125 | * | |
1126 | * DESCRIPTION: Handles all control ops encountered during control method | |
1127 | * execution. | |
1128 | * | |
1129 | ******************************************************************************/ | |
1130 | ||
1131 | acpi_status | |
4be44fcd LB |
1132 | acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state, |
1133 | union acpi_parse_object *op) | |
1da177e4 | 1134 | { |
4be44fcd LB |
1135 | acpi_status status = AE_OK; |
1136 | union acpi_generic_state *control_state; | |
1da177e4 | 1137 | |
b229cf92 | 1138 | ACPI_FUNCTION_NAME(ds_exec_begin_control_op); |
1da177e4 | 1139 | |
4be44fcd LB |
1140 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op, |
1141 | op->common.aml_opcode, walk_state)); | |
1da177e4 LT |
1142 | |
1143 | switch (op->common.aml_opcode) { | |
1da177e4 LT |
1144 | case AML_WHILE_OP: |
1145 | ||
96411a63 BM |
1146 | /* |
1147 | * If this is an additional iteration of a while loop, continue. | |
1148 | * There is no need to allocate a new control state. | |
1149 | */ | |
1150 | if (walk_state->control_state) { | |
1151 | if (walk_state->control_state->control.aml_predicate_start | |
1152 | == (walk_state->parser_state.aml - 1)) { | |
1153 | ||
1154 | /* Reset the state to start-of-loop */ | |
1155 | ||
1156 | walk_state->control_state->common.state = | |
1157 | ACPI_CONTROL_CONDITIONAL_EXECUTING; | |
1158 | break; | |
1159 | } | |
1160 | } | |
1161 | ||
1162 | /*lint -fallthrough */ | |
1163 | ||
1164 | case AML_IF_OP: | |
1165 | ||
1da177e4 LT |
1166 | /* |
1167 | * IF/WHILE: Create a new control state to manage these | |
1168 | * constructs. We need to manage these as a stack, in order | |
1169 | * to handle nesting. | |
1170 | */ | |
4be44fcd | 1171 | control_state = acpi_ut_create_control_state(); |
1da177e4 LT |
1172 | if (!control_state) { |
1173 | status = AE_NO_MEMORY; | |
1174 | break; | |
1175 | } | |
1176 | /* | |
1177 | * Save a pointer to the predicate for multiple executions | |
1178 | * of a loop | |
1179 | */ | |
4be44fcd LB |
1180 | control_state->control.aml_predicate_start = |
1181 | walk_state->parser_state.aml - 1; | |
1182 | control_state->control.package_end = | |
1183 | walk_state->parser_state.pkg_end; | |
1da177e4 LT |
1184 | control_state->control.opcode = op->common.aml_opcode; |
1185 | ||
1da177e4 LT |
1186 | /* Push the control state on this walk's control stack */ |
1187 | ||
4be44fcd LB |
1188 | acpi_ut_push_generic_state(&walk_state->control_state, |
1189 | control_state); | |
1da177e4 LT |
1190 | break; |
1191 | ||
1192 | case AML_ELSE_OP: | |
1193 | ||
1194 | /* Predicate is in the state object */ | |
1195 | /* If predicate is true, the IF was executed, ignore ELSE part */ | |
1196 | ||
1197 | if (walk_state->last_predicate) { | |
1198 | status = AE_CTRL_TRUE; | |
1199 | } | |
1200 | ||
1201 | break; | |
1202 | ||
1203 | case AML_RETURN_OP: | |
1204 | ||
1205 | break; | |
1206 | ||
1207 | default: | |
1208 | break; | |
1209 | } | |
1210 | ||
1211 | return (status); | |
1212 | } | |
1213 | ||
1da177e4 LT |
1214 | /******************************************************************************* |
1215 | * | |
1216 | * FUNCTION: acpi_ds_exec_end_control_op | |
1217 | * | |
1218 | * PARAMETERS: walk_list - The list that owns the walk stack | |
1219 | * Op - The control Op | |
1220 | * | |
1221 | * RETURN: Status | |
1222 | * | |
1223 | * DESCRIPTION: Handles all control ops encountered during control method | |
1224 | * execution. | |
1225 | * | |
1226 | ******************************************************************************/ | |
1227 | ||
1228 | acpi_status | |
4be44fcd LB |
1229 | acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state, |
1230 | union acpi_parse_object * op) | |
1da177e4 | 1231 | { |
4be44fcd LB |
1232 | acpi_status status = AE_OK; |
1233 | union acpi_generic_state *control_state; | |
1da177e4 | 1234 | |
b229cf92 | 1235 | ACPI_FUNCTION_NAME(ds_exec_end_control_op); |
1da177e4 LT |
1236 | |
1237 | switch (op->common.aml_opcode) { | |
1238 | case AML_IF_OP: | |
1239 | ||
4be44fcd | 1240 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op)); |
1da177e4 LT |
1241 | |
1242 | /* | |
1243 | * Save the result of the predicate in case there is an | |
1244 | * ELSE to come | |
1245 | */ | |
1246 | walk_state->last_predicate = | |
4be44fcd | 1247 | (u8) walk_state->control_state->common.value; |
1da177e4 LT |
1248 | |
1249 | /* | |
1250 | * Pop the control state that was created at the start | |
1251 | * of the IF and free it | |
1252 | */ | |
4be44fcd LB |
1253 | control_state = |
1254 | acpi_ut_pop_generic_state(&walk_state->control_state); | |
1255 | acpi_ut_delete_generic_state(control_state); | |
1da177e4 LT |
1256 | break; |
1257 | ||
1da177e4 LT |
1258 | case AML_ELSE_OP: |
1259 | ||
1260 | break; | |
1261 | ||
1da177e4 LT |
1262 | case AML_WHILE_OP: |
1263 | ||
4be44fcd | 1264 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op)); |
1da177e4 | 1265 | |
fc374457 BM |
1266 | control_state = walk_state->control_state; |
1267 | if (control_state->common.value) { | |
1268 | ||
1269 | /* Predicate was true, the body of the loop was just executed */ | |
1270 | ||
1271 | /* | |
1272 | * This loop counter mechanism allows the interpreter to escape | |
1273 | * possibly infinite loops. This can occur in poorly written AML | |
1274 | * when the hardware does not respond within a while loop and the | |
1275 | * loop does not implement a timeout. | |
1276 | */ | |
1277 | control_state->control.loop_count++; | |
1278 | if (control_state->control.loop_count > | |
1279 | ACPI_MAX_LOOP_ITERATIONS) { | |
1280 | status = AE_AML_INFINITE_LOOP; | |
1281 | break; | |
1282 | } | |
1da177e4 | 1283 | |
fc374457 BM |
1284 | /* |
1285 | * Go back and evaluate the predicate and maybe execute the loop | |
1286 | * another time | |
1287 | */ | |
1da177e4 | 1288 | status = AE_CTRL_PENDING; |
96411a63 | 1289 | walk_state->aml_last_while = |
fc374457 | 1290 | control_state->control.aml_predicate_start; |
96411a63 | 1291 | break; |
1da177e4 LT |
1292 | } |
1293 | ||
96411a63 BM |
1294 | /* Predicate was false, terminate this while loop */ |
1295 | ||
4be44fcd LB |
1296 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
1297 | "[WHILE_OP] termination! Op=%p\n", op)); | |
1da177e4 LT |
1298 | |
1299 | /* Pop this control state and free it */ | |
1300 | ||
4be44fcd LB |
1301 | control_state = |
1302 | acpi_ut_pop_generic_state(&walk_state->control_state); | |
4be44fcd | 1303 | acpi_ut_delete_generic_state(control_state); |
1da177e4 LT |
1304 | break; |
1305 | ||
1da177e4 LT |
1306 | case AML_RETURN_OP: |
1307 | ||
4be44fcd LB |
1308 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
1309 | "[RETURN_OP] Op=%p Arg=%p\n", op, | |
1310 | op->common.value.arg)); | |
1da177e4 LT |
1311 | |
1312 | /* | |
1313 | * One optional operand -- the return value | |
1314 | * It can be either an immediate operand or a result that | |
1315 | * has been bubbled up the tree | |
1316 | */ | |
1317 | if (op->common.value.arg) { | |
52fc0b02 | 1318 | |
1da177e4 LT |
1319 | /* Since we have a real Return(), delete any implicit return */ |
1320 | ||
4be44fcd | 1321 | acpi_ds_clear_implicit_return(walk_state); |
1da177e4 LT |
1322 | |
1323 | /* Return statement has an immediate operand */ | |
1324 | ||
4be44fcd LB |
1325 | status = |
1326 | acpi_ds_create_operands(walk_state, | |
1327 | op->common.value.arg); | |
1328 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
1329 | return (status); |
1330 | } | |
1331 | ||
1332 | /* | |
1333 | * If value being returned is a Reference (such as | |
1334 | * an arg or local), resolve it now because it may | |
1335 | * cease to exist at the end of the method. | |
1336 | */ | |
4be44fcd LB |
1337 | status = |
1338 | acpi_ex_resolve_to_value(&walk_state->operands[0], | |
1339 | walk_state); | |
1340 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
1341 | return (status); |
1342 | } | |
1343 | ||
1344 | /* | |
1345 | * Get the return value and save as the last result | |
1346 | * value. This is the only place where walk_state->return_desc | |
1347 | * is set to anything other than zero! | |
1348 | */ | |
1349 | walk_state->return_desc = walk_state->operands[0]; | |
773069d4 | 1350 | } else if (walk_state->result_count) { |
52fc0b02 | 1351 | |
1da177e4 LT |
1352 | /* Since we have a real Return(), delete any implicit return */ |
1353 | ||
4be44fcd | 1354 | acpi_ds_clear_implicit_return(walk_state); |
1da177e4 LT |
1355 | |
1356 | /* | |
1357 | * The return value has come from a previous calculation. | |
1358 | * | |
1359 | * If value being returned is a Reference (such as | |
1360 | * an arg or local), resolve it now because it may | |
1361 | * cease to exist at the end of the method. | |
1362 | * | |
1363 | * Allow references created by the Index operator to return unchanged. | |
1364 | */ | |
4be44fcd LB |
1365 | if ((ACPI_GET_DESCRIPTOR_TYPE |
1366 | (walk_state->results->results.obj_desc[0]) == | |
1367 | ACPI_DESC_TYPE_OPERAND) | |
1368 | && | |
1369 | (ACPI_GET_OBJECT_TYPE | |
1370 | (walk_state->results->results.obj_desc[0]) == | |
1371 | ACPI_TYPE_LOCAL_REFERENCE) | |
1372 | && ((walk_state->results->results.obj_desc[0])-> | |
1044f1f6 | 1373 | reference.class != ACPI_REFCLASS_INDEX)) { |
4be44fcd LB |
1374 | status = |
1375 | acpi_ex_resolve_to_value(&walk_state-> | |
1376 | results->results. | |
1377 | obj_desc[0], | |
1378 | walk_state); | |
1379 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
1380 | return (status); |
1381 | } | |
1382 | } | |
1383 | ||
4be44fcd LB |
1384 | walk_state->return_desc = |
1385 | walk_state->results->results.obj_desc[0]; | |
1386 | } else { | |
1da177e4 LT |
1387 | /* No return operand */ |
1388 | ||
1389 | if (walk_state->num_operands) { | |
4be44fcd LB |
1390 | acpi_ut_remove_reference(walk_state-> |
1391 | operands[0]); | |
1da177e4 LT |
1392 | } |
1393 | ||
4be44fcd LB |
1394 | walk_state->operands[0] = NULL; |
1395 | walk_state->num_operands = 0; | |
1396 | walk_state->return_desc = NULL; | |
1da177e4 LT |
1397 | } |
1398 | ||
4be44fcd | 1399 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
b229cf92 | 1400 | "Completed RETURN_OP State=%p, RetVal=%p\n", |
4be44fcd | 1401 | walk_state, walk_state->return_desc)); |
1da177e4 LT |
1402 | |
1403 | /* End the control method execution right now */ | |
1404 | ||
1405 | status = AE_CTRL_TERMINATE; | |
1406 | break; | |
1407 | ||
1da177e4 LT |
1408 | case AML_NOOP_OP: |
1409 | ||
1410 | /* Just do nothing! */ | |
1411 | break; | |
1412 | ||
1da177e4 LT |
1413 | case AML_BREAK_POINT_OP: |
1414 | ||
1415 | /* Call up to the OS service layer to handle this */ | |
1416 | ||
4be44fcd LB |
1417 | status = |
1418 | acpi_os_signal(ACPI_SIGNAL_BREAKPOINT, | |
1419 | "Executed AML Breakpoint opcode"); | |
1da177e4 LT |
1420 | |
1421 | /* If and when it returns, all done. */ | |
1422 | ||
1423 | break; | |
1424 | ||
1da177e4 | 1425 | case AML_BREAK_OP: |
4be44fcd | 1426 | case AML_CONTINUE_OP: /* ACPI 2.0 */ |
1da177e4 LT |
1427 | |
1428 | /* Pop and delete control states until we find a while */ | |
1429 | ||
1430 | while (walk_state->control_state && | |
4be44fcd LB |
1431 | (walk_state->control_state->control.opcode != |
1432 | AML_WHILE_OP)) { | |
1433 | control_state = | |
1434 | acpi_ut_pop_generic_state(&walk_state-> | |
1435 | control_state); | |
1436 | acpi_ut_delete_generic_state(control_state); | |
1da177e4 LT |
1437 | } |
1438 | ||
1439 | /* No while found? */ | |
1440 | ||
1441 | if (!walk_state->control_state) { | |
1442 | return (AE_AML_NO_WHILE); | |
1443 | } | |
1444 | ||
1445 | /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */ | |
1446 | ||
4be44fcd LB |
1447 | walk_state->aml_last_while = |
1448 | walk_state->control_state->control.package_end; | |
1da177e4 LT |
1449 | |
1450 | /* Return status depending on opcode */ | |
1451 | ||
1452 | if (op->common.aml_opcode == AML_BREAK_OP) { | |
1453 | status = AE_CTRL_BREAK; | |
4be44fcd | 1454 | } else { |
1da177e4 LT |
1455 | status = AE_CTRL_CONTINUE; |
1456 | } | |
1457 | break; | |
1458 | ||
1da177e4 LT |
1459 | default: |
1460 | ||
b8e4d893 BM |
1461 | ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p", |
1462 | op->common.aml_opcode, op)); | |
1da177e4 LT |
1463 | |
1464 | status = AE_AML_BAD_OPCODE; | |
1465 | break; | |
1466 | } | |
1467 | ||
1468 | return (status); | |
1469 | } |