diff options
Diffstat (limited to 'drivers/acpi/acpica/dsopcode.c')
-rw-r--r-- | drivers/acpi/acpica/dsopcode.c | 725 |
1 files changed, 4 insertions, 721 deletions
diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c index bbecf293aeeb..c627a288e027 100644 --- a/drivers/acpi/acpica/dsopcode.c +++ b/drivers/acpi/acpica/dsopcode.c | |||
@@ -1,7 +1,6 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | * |
3 | * Module Name: dsopcode - Dispatcher Op Region support and handling of | 3 | * Module Name: dsopcode - Dispatcher suport for regions and fields |
4 | * "control" opcodes | ||
5 | * | 4 | * |
6 | *****************************************************************************/ | 5 | *****************************************************************************/ |
7 | 6 | ||
@@ -57,11 +56,6 @@ ACPI_MODULE_NAME("dsopcode") | |||
57 | 56 | ||
58 | /* Local prototypes */ | 57 | /* Local prototypes */ |
59 | static acpi_status | 58 | static acpi_status |
60 | acpi_ds_execute_arguments(struct acpi_namespace_node *node, | ||
61 | struct acpi_namespace_node *scope_node, | ||
62 | u32 aml_length, u8 * aml_start); | ||
63 | |||
64 | static acpi_status | ||
65 | acpi_ds_init_buffer_field(u16 aml_opcode, | 59 | acpi_ds_init_buffer_field(u16 aml_opcode, |
66 | union acpi_operand_object *obj_desc, | 60 | union acpi_operand_object *obj_desc, |
67 | union acpi_operand_object *buffer_desc, | 61 | union acpi_operand_object *buffer_desc, |
@@ -71,361 +65,6 @@ acpi_ds_init_buffer_field(u16 aml_opcode, | |||
71 | 65 | ||
72 | /******************************************************************************* | 66 | /******************************************************************************* |
73 | * | 67 | * |
74 | * FUNCTION: acpi_ds_execute_arguments | ||
75 | * | ||
76 | * PARAMETERS: Node - Object NS node | ||
77 | * scope_node - Parent NS node | ||
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 | * | ||
85 | ******************************************************************************/ | ||
86 | |||
87 | static acpi_status | ||
88 | acpi_ds_execute_arguments(struct acpi_namespace_node *node, | ||
89 | struct acpi_namespace_node *scope_node, | ||
90 | u32 aml_length, u8 * aml_start) | ||
91 | { | ||
92 | acpi_status status; | ||
93 | union acpi_parse_object *op; | ||
94 | struct acpi_walk_state *walk_state; | ||
95 | |||
96 | ACPI_FUNCTION_TRACE(ds_execute_arguments); | ||
97 | |||
98 | /* | ||
99 | * Allocate a new parser op to be the root of the parsed tree | ||
100 | */ | ||
101 | op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); | ||
102 | if (!op) { | ||
103 | return_ACPI_STATUS(AE_NO_MEMORY); | ||
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 | |||
112 | walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); | ||
113 | if (!walk_state) { | ||
114 | status = AE_NO_MEMORY; | ||
115 | goto cleanup; | ||
116 | } | ||
117 | |||
118 | status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, | ||
119 | aml_length, NULL, ACPI_IMODE_LOAD_PASS1); | ||
120 | if (ACPI_FAILURE(status)) { | ||
121 | acpi_ds_delete_walk_state(walk_state); | ||
122 | goto cleanup; | ||
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 | |||
132 | status = acpi_ps_parse_aml(walk_state); | ||
133 | if (ACPI_FAILURE(status)) { | ||
134 | goto cleanup; | ||
135 | } | ||
136 | |||
137 | /* Get and init the Op created above */ | ||
138 | |||
139 | op->common.node = node; | ||
140 | acpi_ps_delete_parse_tree(op); | ||
141 | |||
142 | /* Evaluate the deferred arguments */ | ||
143 | |||
144 | op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP); | ||
145 | if (!op) { | ||
146 | return_ACPI_STATUS(AE_NO_MEMORY); | ||
147 | } | ||
148 | |||
149 | op->common.node = scope_node; | ||
150 | |||
151 | /* Create and initialize a new parser state */ | ||
152 | |||
153 | walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); | ||
154 | if (!walk_state) { | ||
155 | status = AE_NO_MEMORY; | ||
156 | goto cleanup; | ||
157 | } | ||
158 | |||
159 | /* Execute the opcode and arguments */ | ||
160 | |||
161 | status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, | ||
162 | aml_length, NULL, ACPI_IMODE_EXECUTE); | ||
163 | if (ACPI_FAILURE(status)) { | ||
164 | acpi_ds_delete_walk_state(walk_state); | ||
165 | goto cleanup; | ||
166 | } | ||
167 | |||
168 | /* Mark this execution as a deferred opcode */ | ||
169 | |||
170 | walk_state->deferred_node = node; | ||
171 | status = acpi_ps_parse_aml(walk_state); | ||
172 | |||
173 | cleanup: | ||
174 | acpi_ps_delete_parse_tree(op); | ||
175 | return_ACPI_STATUS(status); | ||
176 | } | ||
177 | |||
178 | /******************************************************************************* | ||
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 | * | ||
189 | ******************************************************************************/ | ||
190 | |||
191 | acpi_status | ||
192 | acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc) | ||
193 | { | ||
194 | union acpi_operand_object *extra_desc; | ||
195 | struct acpi_namespace_node *node; | ||
196 | acpi_status status; | ||
197 | |||
198 | ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc); | ||
199 | |||
200 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | ||
201 | return_ACPI_STATUS(AE_OK); | ||
202 | } | ||
203 | |||
204 | /* Get the AML pointer (method object) and buffer_field node */ | ||
205 | |||
206 | extra_desc = acpi_ns_get_secondary_object(obj_desc); | ||
207 | node = obj_desc->buffer_field.node; | ||
208 | |||
209 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname | ||
210 | (ACPI_TYPE_BUFFER_FIELD, node, NULL)); | ||
211 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n", | ||
212 | acpi_ut_get_node_name(node))); | ||
213 | |||
214 | /* Execute the AML code for the term_arg arguments */ | ||
215 | |||
216 | status = acpi_ds_execute_arguments(node, node->parent, | ||
217 | extra_desc->extra.aml_length, | ||
218 | extra_desc->extra.aml_start); | ||
219 | return_ACPI_STATUS(status); | ||
220 | } | ||
221 | |||
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, node->parent, | ||
261 | extra_desc->extra.aml_length, | ||
262 | extra_desc->extra.aml_start); | ||
263 | return_ACPI_STATUS(status); | ||
264 | } | ||
265 | |||
266 | /******************************************************************************* | ||
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 | * | ||
277 | ******************************************************************************/ | ||
278 | |||
279 | acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc) | ||
280 | { | ||
281 | struct acpi_namespace_node *node; | ||
282 | acpi_status status; | ||
283 | |||
284 | ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc); | ||
285 | |||
286 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | ||
287 | return_ACPI_STATUS(AE_OK); | ||
288 | } | ||
289 | |||
290 | /* Get the Buffer node */ | ||
291 | |||
292 | node = obj_desc->buffer.node; | ||
293 | if (!node) { | ||
294 | ACPI_ERROR((AE_INFO, | ||
295 | "No pointer back to namespace node in buffer object %p", | ||
296 | obj_desc)); | ||
297 | return_ACPI_STATUS(AE_AML_INTERNAL); | ||
298 | } | ||
299 | |||
300 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n")); | ||
301 | |||
302 | /* Execute the AML code for the term_arg arguments */ | ||
303 | |||
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); | ||
308 | } | ||
309 | |||
310 | /******************************************************************************* | ||
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 | * | ||
321 | ******************************************************************************/ | ||
322 | |||
323 | acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc) | ||
324 | { | ||
325 | struct acpi_namespace_node *node; | ||
326 | acpi_status status; | ||
327 | |||
328 | ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc); | ||
329 | |||
330 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { | ||
331 | return_ACPI_STATUS(AE_OK); | ||
332 | } | ||
333 | |||
334 | /* Get the Package node */ | ||
335 | |||
336 | node = obj_desc->package.node; | ||
337 | if (!node) { | ||
338 | ACPI_ERROR((AE_INFO, | ||
339 | "No pointer back to namespace node in package %p", | ||
340 | obj_desc)); | ||
341 | return_ACPI_STATUS(AE_AML_INTERNAL); | ||
342 | } | ||
343 | |||
344 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n")); | ||
345 | |||
346 | /* Execute the AML code for the term_arg arguments */ | ||
347 | |||
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); | ||
352 | } | ||
353 | |||
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 | |||
367 | acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc) | ||
368 | { | ||
369 | struct acpi_namespace_node *node; | ||
370 | acpi_status status; | ||
371 | union acpi_operand_object *extra_desc; | ||
372 | |||
373 | ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc); | ||
374 | |||
375 | if (obj_desc->region.flags & AOPOBJ_DATA_VALID) { | ||
376 | return_ACPI_STATUS(AE_OK); | ||
377 | } | ||
378 | |||
379 | extra_desc = acpi_ns_get_secondary_object(obj_desc); | ||
380 | if (!extra_desc) { | ||
381 | return_ACPI_STATUS(AE_NOT_EXIST); | ||
382 | } | ||
383 | |||
384 | /* Get the Region node */ | ||
385 | |||
386 | node = obj_desc->region.node; | ||
387 | |||
388 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname | ||
389 | (ACPI_TYPE_REGION, node, NULL)); | ||
390 | |||
391 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n", | ||
392 | acpi_ut_get_node_name(node), | ||
393 | extra_desc->extra.aml_start)); | ||
394 | |||
395 | /* Execute the argument AML */ | ||
396 | |||
397 | status = acpi_ds_execute_arguments(node, node->parent, | ||
398 | extra_desc->extra.aml_length, | ||
399 | extra_desc->extra.aml_start); | ||
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, | ||
408 | (acpi_size) obj_desc->region.length, | ||
409 | acpi_ut_get_node_name(node)); | ||
410 | |||
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 | |||
424 | return_ACPI_STATUS(status); | ||
425 | } | ||
426 | |||
427 | /******************************************************************************* | ||
428 | * | ||
429 | * FUNCTION: acpi_ds_initialize_region | 68 | * FUNCTION: acpi_ds_initialize_region |
430 | * | 69 | * |
431 | * PARAMETERS: obj_handle - Region namespace node | 70 | * PARAMETERS: obj_handle - Region namespace node |
@@ -826,8 +465,9 @@ acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state, | |||
826 | * | 465 | * |
827 | * RETURN: Status | 466 | * RETURN: Status |
828 | * | 467 | * |
829 | * DESCRIPTION: Get region address and length | 468 | * DESCRIPTION: Get region address and length. |
830 | * Called from acpi_ds_exec_end_op during data_table_region parse tree walk | 469 | * Called from acpi_ds_exec_end_op during data_table_region parse |
470 | * tree walk. | ||
831 | * | 471 | * |
832 | ******************************************************************************/ | 472 | ******************************************************************************/ |
833 | 473 | ||
@@ -1114,360 +754,3 @@ acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state, | |||
1114 | acpi_ut_remove_reference(operand_desc); | 754 | acpi_ut_remove_reference(operand_desc); |
1115 | return_ACPI_STATUS(status); | 755 | return_ACPI_STATUS(status); |
1116 | } | 756 | } |
1117 | |||
1118 | /******************************************************************************* | ||
1119 | * | ||
1120 | * FUNCTION: acpi_ds_exec_begin_control_op | ||
1121 | * | ||
1122 | * PARAMETERS: walk_list - The list that owns the walk stack | ||
1123 | * Op - The control Op | ||
1124 | * | ||
1125 | * RETURN: Status | ||
1126 | * | ||
1127 | * DESCRIPTION: Handles all control ops encountered during control method | ||
1128 | * execution. | ||
1129 | * | ||
1130 | ******************************************************************************/ | ||
1131 | |||
1132 | acpi_status | ||
1133 | acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state, | ||
1134 | union acpi_parse_object *op) | ||
1135 | { | ||
1136 | acpi_status status = AE_OK; | ||
1137 | union acpi_generic_state *control_state; | ||
1138 | |||
1139 | ACPI_FUNCTION_NAME(ds_exec_begin_control_op); | ||
1140 | |||
1141 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op, | ||
1142 | op->common.aml_opcode, walk_state)); | ||
1143 | |||
1144 | switch (op->common.aml_opcode) { | ||
1145 | case AML_WHILE_OP: | ||
1146 | |||
1147 | /* | ||
1148 | * If this is an additional iteration of a while loop, continue. | ||
1149 | * There is no need to allocate a new control state. | ||
1150 | */ | ||
1151 | if (walk_state->control_state) { | ||
1152 | if (walk_state->control_state->control.aml_predicate_start | ||
1153 | == (walk_state->parser_state.aml - 1)) { | ||
1154 | |||
1155 | /* Reset the state to start-of-loop */ | ||
1156 | |||
1157 | walk_state->control_state->common.state = | ||
1158 | ACPI_CONTROL_CONDITIONAL_EXECUTING; | ||
1159 | break; | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 | /*lint -fallthrough */ | ||
1164 | |||
1165 | case AML_IF_OP: | ||
1166 | |||
1167 | /* | ||
1168 | * IF/WHILE: Create a new control state to manage these | ||
1169 | * constructs. We need to manage these as a stack, in order | ||
1170 | * to handle nesting. | ||
1171 | */ | ||
1172 | control_state = acpi_ut_create_control_state(); | ||
1173 | if (!control_state) { | ||
1174 | status = AE_NO_MEMORY; | ||
1175 | break; | ||
1176 | } | ||
1177 | /* | ||
1178 | * Save a pointer to the predicate for multiple executions | ||
1179 | * of a loop | ||
1180 | */ | ||
1181 | control_state->control.aml_predicate_start = | ||
1182 | walk_state->parser_state.aml - 1; | ||
1183 | control_state->control.package_end = | ||
1184 | walk_state->parser_state.pkg_end; | ||
1185 | control_state->control.opcode = op->common.aml_opcode; | ||
1186 | |||
1187 | /* Push the control state on this walk's control stack */ | ||
1188 | |||
1189 | acpi_ut_push_generic_state(&walk_state->control_state, | ||
1190 | control_state); | ||
1191 | break; | ||
1192 | |||
1193 | case AML_ELSE_OP: | ||
1194 | |||
1195 | /* Predicate is in the state object */ | ||
1196 | /* If predicate is true, the IF was executed, ignore ELSE part */ | ||
1197 | |||
1198 | if (walk_state->last_predicate) { | ||
1199 | status = AE_CTRL_TRUE; | ||
1200 | } | ||
1201 | |||
1202 | break; | ||
1203 | |||
1204 | case AML_RETURN_OP: | ||
1205 | |||
1206 | break; | ||
1207 | |||
1208 | default: | ||
1209 | break; | ||
1210 | } | ||
1211 | |||
1212 | return (status); | ||
1213 | } | ||
1214 | |||
1215 | /******************************************************************************* | ||
1216 | * | ||
1217 | * FUNCTION: acpi_ds_exec_end_control_op | ||
1218 | * | ||
1219 | * PARAMETERS: walk_list - The list that owns the walk stack | ||
1220 | * Op - The control Op | ||
1221 | * | ||
1222 | * RETURN: Status | ||
1223 | * | ||
1224 | * DESCRIPTION: Handles all control ops encountered during control method | ||
1225 | * execution. | ||
1226 | * | ||
1227 | ******************************************************************************/ | ||
1228 | |||
1229 | acpi_status | ||
1230 | acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state, | ||
1231 | union acpi_parse_object * op) | ||
1232 | { | ||
1233 | acpi_status status = AE_OK; | ||
1234 | union acpi_generic_state *control_state; | ||
1235 | |||
1236 | ACPI_FUNCTION_NAME(ds_exec_end_control_op); | ||
1237 | |||
1238 | switch (op->common.aml_opcode) { | ||
1239 | case AML_IF_OP: | ||
1240 | |||
1241 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op)); | ||
1242 | |||
1243 | /* | ||
1244 | * Save the result of the predicate in case there is an | ||
1245 | * ELSE to come | ||
1246 | */ | ||
1247 | walk_state->last_predicate = | ||
1248 | (u8) walk_state->control_state->common.value; | ||
1249 | |||
1250 | /* | ||
1251 | * Pop the control state that was created at the start | ||
1252 | * of the IF and free it | ||
1253 | */ | ||
1254 | control_state = | ||
1255 | acpi_ut_pop_generic_state(&walk_state->control_state); | ||
1256 | acpi_ut_delete_generic_state(control_state); | ||
1257 | break; | ||
1258 | |||
1259 | case AML_ELSE_OP: | ||
1260 | |||
1261 | break; | ||
1262 | |||
1263 | case AML_WHILE_OP: | ||
1264 | |||
1265 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op)); | ||
1266 | |||
1267 | control_state = walk_state->control_state; | ||
1268 | if (control_state->common.value) { | ||
1269 | |||
1270 | /* Predicate was true, the body of the loop was just executed */ | ||
1271 | |||
1272 | /* | ||
1273 | * This loop counter mechanism allows the interpreter to escape | ||
1274 | * possibly infinite loops. This can occur in poorly written AML | ||
1275 | * when the hardware does not respond within a while loop and the | ||
1276 | * loop does not implement a timeout. | ||
1277 | */ | ||
1278 | control_state->control.loop_count++; | ||
1279 | if (control_state->control.loop_count > | ||
1280 | ACPI_MAX_LOOP_ITERATIONS) { | ||
1281 | status = AE_AML_INFINITE_LOOP; | ||
1282 | break; | ||
1283 | } | ||
1284 | |||
1285 | /* | ||
1286 | * Go back and evaluate the predicate and maybe execute the loop | ||
1287 | * another time | ||
1288 | */ | ||
1289 | status = AE_CTRL_PENDING; | ||
1290 | walk_state->aml_last_while = | ||
1291 | control_state->control.aml_predicate_start; | ||
1292 | break; | ||
1293 | } | ||
1294 | |||
1295 | /* Predicate was false, terminate this while loop */ | ||
1296 | |||
1297 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, | ||
1298 | "[WHILE_OP] termination! Op=%p\n", op)); | ||
1299 | |||
1300 | /* Pop this control state and free it */ | ||
1301 | |||
1302 | control_state = | ||
1303 | acpi_ut_pop_generic_state(&walk_state->control_state); | ||
1304 | acpi_ut_delete_generic_state(control_state); | ||
1305 | break; | ||
1306 | |||
1307 | case AML_RETURN_OP: | ||
1308 | |||
1309 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, | ||
1310 | "[RETURN_OP] Op=%p Arg=%p\n", op, | ||
1311 | op->common.value.arg)); | ||
1312 | |||
1313 | /* | ||
1314 | * One optional operand -- the return value | ||
1315 | * It can be either an immediate operand or a result that | ||
1316 | * has been bubbled up the tree | ||
1317 | */ | ||
1318 | if (op->common.value.arg) { | ||
1319 | |||
1320 | /* Since we have a real Return(), delete any implicit return */ | ||
1321 | |||
1322 | acpi_ds_clear_implicit_return(walk_state); | ||
1323 | |||
1324 | /* Return statement has an immediate operand */ | ||
1325 | |||
1326 | status = | ||
1327 | acpi_ds_create_operands(walk_state, | ||
1328 | op->common.value.arg); | ||
1329 | if (ACPI_FAILURE(status)) { | ||
1330 | return (status); | ||
1331 | } | ||
1332 | |||
1333 | /* | ||
1334 | * If value being returned is a Reference (such as | ||
1335 | * an arg or local), resolve it now because it may | ||
1336 | * cease to exist at the end of the method. | ||
1337 | */ | ||
1338 | status = | ||
1339 | acpi_ex_resolve_to_value(&walk_state->operands[0], | ||
1340 | walk_state); | ||
1341 | if (ACPI_FAILURE(status)) { | ||
1342 | return (status); | ||
1343 | } | ||
1344 | |||
1345 | /* | ||
1346 | * Get the return value and save as the last result | ||
1347 | * value. This is the only place where walk_state->return_desc | ||
1348 | * is set to anything other than zero! | ||
1349 | */ | ||
1350 | walk_state->return_desc = walk_state->operands[0]; | ||
1351 | } else if (walk_state->result_count) { | ||
1352 | |||
1353 | /* Since we have a real Return(), delete any implicit return */ | ||
1354 | |||
1355 | acpi_ds_clear_implicit_return(walk_state); | ||
1356 | |||
1357 | /* | ||
1358 | * The return value has come from a previous calculation. | ||
1359 | * | ||
1360 | * If value being returned is a Reference (such as | ||
1361 | * an arg or local), resolve it now because it may | ||
1362 | * cease to exist at the end of the method. | ||
1363 | * | ||
1364 | * Allow references created by the Index operator to return unchanged. | ||
1365 | */ | ||
1366 | if ((ACPI_GET_DESCRIPTOR_TYPE | ||
1367 | (walk_state->results->results.obj_desc[0]) == | ||
1368 | ACPI_DESC_TYPE_OPERAND) | ||
1369 | && ((walk_state->results->results.obj_desc[0])-> | ||
1370 | common.type == ACPI_TYPE_LOCAL_REFERENCE) | ||
1371 | && ((walk_state->results->results.obj_desc[0])-> | ||
1372 | reference.class != ACPI_REFCLASS_INDEX)) { | ||
1373 | status = | ||
1374 | acpi_ex_resolve_to_value(&walk_state-> | ||
1375 | results->results. | ||
1376 | obj_desc[0], | ||
1377 | walk_state); | ||
1378 | if (ACPI_FAILURE(status)) { | ||
1379 | return (status); | ||
1380 | } | ||
1381 | } | ||
1382 | |||
1383 | walk_state->return_desc = | ||
1384 | walk_state->results->results.obj_desc[0]; | ||
1385 | } else { | ||
1386 | /* No return operand */ | ||
1387 | |||
1388 | if (walk_state->num_operands) { | ||
1389 | acpi_ut_remove_reference(walk_state-> | ||
1390 | operands[0]); | ||
1391 | } | ||
1392 | |||
1393 | walk_state->operands[0] = NULL; | ||
1394 | walk_state->num_operands = 0; | ||
1395 | walk_state->return_desc = NULL; | ||
1396 | } | ||
1397 | |||
1398 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, | ||
1399 | "Completed RETURN_OP State=%p, RetVal=%p\n", | ||
1400 | walk_state, walk_state->return_desc)); | ||
1401 | |||
1402 | /* End the control method execution right now */ | ||
1403 | |||
1404 | status = AE_CTRL_TERMINATE; | ||
1405 | break; | ||
1406 | |||
1407 | case AML_NOOP_OP: | ||
1408 | |||
1409 | /* Just do nothing! */ | ||
1410 | break; | ||
1411 | |||
1412 | case AML_BREAK_POINT_OP: | ||
1413 | |||
1414 | /* | ||
1415 | * Set the single-step flag. This will cause the debugger (if present) | ||
1416 | * to break to the console within the AML debugger at the start of the | ||
1417 | * next AML instruction. | ||
1418 | */ | ||
1419 | ACPI_DEBUGGER_EXEC(acpi_gbl_cm_single_step = TRUE); | ||
1420 | ACPI_DEBUGGER_EXEC(acpi_os_printf | ||
1421 | ("**break** Executed AML BreakPoint opcode\n")); | ||
1422 | |||
1423 | /* Call to the OSL in case OS wants a piece of the action */ | ||
1424 | |||
1425 | status = acpi_os_signal(ACPI_SIGNAL_BREAKPOINT, | ||
1426 | "Executed AML Breakpoint opcode"); | ||
1427 | break; | ||
1428 | |||
1429 | case AML_BREAK_OP: | ||
1430 | case AML_CONTINUE_OP: /* ACPI 2.0 */ | ||
1431 | |||
1432 | /* Pop and delete control states until we find a while */ | ||
1433 | |||
1434 | while (walk_state->control_state && | ||
1435 | (walk_state->control_state->control.opcode != | ||
1436 | AML_WHILE_OP)) { | ||
1437 | control_state = | ||
1438 | acpi_ut_pop_generic_state(&walk_state-> | ||
1439 | control_state); | ||
1440 | acpi_ut_delete_generic_state(control_state); | ||
1441 | } | ||
1442 | |||
1443 | /* No while found? */ | ||
1444 | |||
1445 | if (!walk_state->control_state) { | ||
1446 | return (AE_AML_NO_WHILE); | ||
1447 | } | ||
1448 | |||
1449 | /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */ | ||
1450 | |||
1451 | walk_state->aml_last_while = | ||
1452 | walk_state->control_state->control.package_end; | ||
1453 | |||
1454 | /* Return status depending on opcode */ | ||
1455 | |||
1456 | if (op->common.aml_opcode == AML_BREAK_OP) { | ||
1457 | status = AE_CTRL_BREAK; | ||
1458 | } else { | ||
1459 | status = AE_CTRL_CONTINUE; | ||
1460 | } | ||
1461 | break; | ||
1462 | |||
1463 | default: | ||
1464 | |||
1465 | ACPI_ERROR((AE_INFO, "Unknown control opcode=0x%X Op=%p", | ||
1466 | op->common.aml_opcode, op)); | ||
1467 | |||
1468 | status = AE_AML_BAD_OPCODE; | ||
1469 | break; | ||
1470 | } | ||
1471 | |||
1472 | return (status); | ||
1473 | } | ||