sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / acpi / acpica / psloop.c
blob6a9f5059f682cbe0f24f26f875a826cc41e1324b
1 /******************************************************************************
3 * Module Name: psloop - Main AML parse loop
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 * Parse the AML and build an operation tree as most interpreters, (such as
46 * Perl) do. Parsing is done by hand rather than with a YACC generated parser
47 * to tightly constrain stack and dynamic memory usage. Parsing is kept
48 * flexible and the code fairly compact by parsing based on a list of AML
49 * opcode templates in aml_op_info[].
52 #include <acpi/acpi.h>
53 #include "accommon.h"
54 #include "acinterp.h"
55 #include "acparser.h"
56 #include "acdispat.h"
57 #include "amlcode.h"
59 #define _COMPONENT ACPI_PARSER
60 ACPI_MODULE_NAME("psloop")
62 /* Local prototypes */
63 static acpi_status
64 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
65 u8 * aml_op_start, union acpi_parse_object *op);
67 static void
68 acpi_ps_link_module_code(union acpi_parse_object *parent_op,
69 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id);
71 /*******************************************************************************
73 * FUNCTION: acpi_ps_get_arguments
75 * PARAMETERS: walk_state - Current state
76 * aml_op_start - Op start in AML
77 * op - Current Op
79 * RETURN: Status
81 * DESCRIPTION: Get arguments for passed Op.
83 ******************************************************************************/
85 static acpi_status
86 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
87 u8 * aml_op_start, union acpi_parse_object *op)
89 acpi_status status = AE_OK;
90 union acpi_parse_object *arg = NULL;
91 const struct acpi_opcode_info *op_info;
93 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
95 switch (op->common.aml_opcode) {
96 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
97 case AML_WORD_OP: /* AML_WORDDATA_ARG */
98 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
99 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
100 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
102 /* Fill in constant or string argument directly */
104 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
105 GET_CURRENT_ARG_TYPE(walk_state->
106 arg_types),
107 op);
108 break;
110 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
112 status = acpi_ps_get_next_namepath(walk_state,
113 &(walk_state->parser_state),
115 ACPI_POSSIBLE_METHOD_CALL);
116 if (ACPI_FAILURE(status)) {
117 return_ACPI_STATUS(status);
120 walk_state->arg_types = 0;
121 break;
123 default:
125 * Op is not a constant or string, append each argument to the Op
127 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
128 !walk_state->arg_count) {
129 walk_state->aml = walk_state->parser_state.aml;
131 status =
132 acpi_ps_get_next_arg(walk_state,
133 &(walk_state->parser_state),
134 GET_CURRENT_ARG_TYPE
135 (walk_state->arg_types), &arg);
136 if (ACPI_FAILURE(status)) {
137 return_ACPI_STATUS(status);
140 if (arg) {
141 acpi_ps_append_arg(op, arg);
144 INCREMENT_ARG_LIST(walk_state->arg_types);
148 * Handle executable code at "module-level". This refers to
149 * executable opcodes that appear outside of any control method.
151 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) &&
152 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
154 * We want to skip If/Else/While constructs during Pass1 because we
155 * want to actually conditionally execute the code during Pass2.
157 * Except for disassembly, where we always want to walk the
158 * If/Else/While packages
160 switch (op->common.aml_opcode) {
161 case AML_IF_OP:
162 case AML_ELSE_OP:
163 case AML_WHILE_OP:
165 * Currently supported module-level opcodes are:
166 * IF/ELSE/WHILE. These appear to be the most common,
167 * and easiest to support since they open an AML
168 * package.
170 if (walk_state->pass_number ==
171 ACPI_IMODE_LOAD_PASS1) {
172 acpi_ps_link_module_code(op->common.
173 parent,
174 aml_op_start,
175 (u32)
176 (walk_state->
177 parser_state.
178 pkg_end -
179 aml_op_start),
180 walk_state->
181 owner_id);
184 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
185 "Pass1: Skipping an If/Else/While body\n"));
187 /* Skip body of if/else/while in pass 1 */
189 walk_state->parser_state.aml =
190 walk_state->parser_state.pkg_end;
191 walk_state->arg_count = 0;
192 break;
194 default:
196 * Check for an unsupported executable opcode at module
197 * level. We must be in PASS1, the parent must be a SCOPE,
198 * The opcode class must be EXECUTE, and the opcode must
199 * not be an argument to another opcode.
201 if ((walk_state->pass_number ==
202 ACPI_IMODE_LOAD_PASS1)
203 && (op->common.parent->common.aml_opcode ==
204 AML_SCOPE_OP)) {
205 op_info =
206 acpi_ps_get_opcode_info(op->common.
207 aml_opcode);
208 if ((op_info->class ==
209 AML_CLASS_EXECUTE) && (!arg)) {
210 ACPI_WARNING((AE_INFO,
211 "Unsupported module-level executable opcode "
212 "0x%.2X at table offset 0x%.4X",
213 op->common.
214 aml_opcode,
215 (u32)
216 (ACPI_PTR_DIFF
217 (aml_op_start,
218 walk_state->
219 parser_state.
220 aml_start) +
221 sizeof(struct
222 acpi_table_header))));
225 break;
229 /* Special processing for certain opcodes */
231 switch (op->common.aml_opcode) {
232 case AML_METHOD_OP:
234 * Skip parsing of control method because we don't have enough
235 * info in the first pass to parse it correctly.
237 * Save the length and address of the body
239 op->named.data = walk_state->parser_state.aml;
240 op->named.length = (u32)
241 (walk_state->parser_state.pkg_end -
242 walk_state->parser_state.aml);
244 /* Skip body of method */
246 walk_state->parser_state.aml =
247 walk_state->parser_state.pkg_end;
248 walk_state->arg_count = 0;
249 break;
251 case AML_BUFFER_OP:
252 case AML_PACKAGE_OP:
253 case AML_VAR_PACKAGE_OP:
255 if ((op->common.parent) &&
256 (op->common.parent->common.aml_opcode ==
257 AML_NAME_OP)
258 && (walk_state->pass_number <=
259 ACPI_IMODE_LOAD_PASS2)) {
261 * Skip parsing of Buffers and Packages because we don't have
262 * enough info in the first pass to parse them correctly.
264 op->named.data = aml_op_start;
265 op->named.length = (u32)
266 (walk_state->parser_state.pkg_end -
267 aml_op_start);
269 /* Skip body */
271 walk_state->parser_state.aml =
272 walk_state->parser_state.pkg_end;
273 walk_state->arg_count = 0;
275 break;
277 case AML_WHILE_OP:
279 if (walk_state->control_state) {
280 walk_state->control_state->control.package_end =
281 walk_state->parser_state.pkg_end;
283 break;
285 default:
287 /* No action for all other opcodes */
289 break;
292 break;
295 return_ACPI_STATUS(AE_OK);
298 /*******************************************************************************
300 * FUNCTION: acpi_ps_link_module_code
302 * PARAMETERS: parent_op - Parent parser op
303 * aml_start - Pointer to the AML
304 * aml_length - Length of executable AML
305 * owner_id - owner_id of module level code
307 * RETURN: None.
309 * DESCRIPTION: Wrap the module-level code with a method object and link the
310 * object to the global list. Note, the mutex field of the method
311 * object is used to link multiple module-level code objects.
313 ******************************************************************************/
315 static void
316 acpi_ps_link_module_code(union acpi_parse_object *parent_op,
317 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id)
319 union acpi_operand_object *prev;
320 union acpi_operand_object *next;
321 union acpi_operand_object *method_obj;
322 struct acpi_namespace_node *parent_node;
324 ACPI_FUNCTION_TRACE(ps_link_module_code);
326 /* Get the tail of the list */
328 prev = next = acpi_gbl_module_code_list;
329 while (next) {
330 prev = next;
331 next = next->method.mutex;
335 * Insert the module level code into the list. Merge it if it is
336 * adjacent to the previous element.
338 if (!prev ||
339 ((prev->method.aml_start + prev->method.aml_length) != aml_start)) {
341 /* Create, initialize, and link a new temporary method object */
343 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
344 if (!method_obj) {
345 return_VOID;
348 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
349 "Create/Link new code block: %p\n",
350 method_obj));
352 if (parent_op->common.node) {
353 parent_node = parent_op->common.node;
354 } else {
355 parent_node = acpi_gbl_root_node;
358 method_obj->method.aml_start = aml_start;
359 method_obj->method.aml_length = aml_length;
360 method_obj->method.owner_id = owner_id;
361 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
364 * Save the parent node in next_object. This is cheating, but we
365 * don't want to expand the method object.
367 method_obj->method.next_object =
368 ACPI_CAST_PTR(union acpi_operand_object, parent_node);
370 if (!prev) {
371 acpi_gbl_module_code_list = method_obj;
372 } else {
373 prev->method.mutex = method_obj;
375 } else {
376 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
377 "Appending to existing code block: %p\n",
378 prev));
380 prev->method.aml_length += aml_length;
383 return_VOID;
386 /*******************************************************************************
388 * FUNCTION: acpi_ps_parse_loop
390 * PARAMETERS: walk_state - Current state
392 * RETURN: Status
394 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
395 * a tree of ops.
397 ******************************************************************************/
399 acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
401 acpi_status status = AE_OK;
402 union acpi_parse_object *op = NULL; /* current op */
403 struct acpi_parse_state *parser_state;
404 u8 *aml_op_start = NULL;
406 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
408 if (walk_state->descending_callback == NULL) {
409 return_ACPI_STATUS(AE_BAD_PARAMETER);
412 parser_state = &walk_state->parser_state;
413 walk_state->arg_types = 0;
415 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
417 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
419 /* We are restarting a preempted control method */
421 if (acpi_ps_has_completed_scope(parser_state)) {
423 * We must check if a predicate to an IF or WHILE statement
424 * was just completed
426 if ((parser_state->scope->parse_scope.op) &&
427 ((parser_state->scope->parse_scope.op->common.
428 aml_opcode == AML_IF_OP)
429 || (parser_state->scope->parse_scope.op->common.
430 aml_opcode == AML_WHILE_OP))
431 && (walk_state->control_state)
432 && (walk_state->control_state->common.state ==
433 ACPI_CONTROL_PREDICATE_EXECUTING)) {
435 * A predicate was just completed, get the value of the
436 * predicate and branch based on that value
438 walk_state->op = NULL;
439 status =
440 acpi_ds_get_predicate_value(walk_state,
441 ACPI_TO_POINTER
442 (TRUE));
443 if (ACPI_FAILURE(status)
444 && ((status & AE_CODE_MASK) !=
445 AE_CODE_CONTROL)) {
446 if (status == AE_AML_NO_RETURN_VALUE) {
447 ACPI_EXCEPTION((AE_INFO, status,
448 "Invoked method did not return a value"));
451 ACPI_EXCEPTION((AE_INFO, status,
452 "GetPredicate Failed"));
453 return_ACPI_STATUS(status);
456 status =
457 acpi_ps_next_parse_state(walk_state, op,
458 status);
461 acpi_ps_pop_scope(parser_state, &op,
462 &walk_state->arg_types,
463 &walk_state->arg_count);
464 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
465 "Popped scope, Op=%p\n", op));
466 } else if (walk_state->prev_op) {
468 /* We were in the middle of an op */
470 op = walk_state->prev_op;
471 walk_state->arg_types = walk_state->prev_arg_types;
474 #endif
476 /* Iterative parsing loop, while there is more AML to process: */
478 while ((parser_state->aml < parser_state->aml_end) || (op)) {
479 aml_op_start = parser_state->aml;
480 if (!op) {
481 status =
482 acpi_ps_create_op(walk_state, aml_op_start, &op);
483 if (ACPI_FAILURE(status)) {
484 if (status == AE_CTRL_PARSE_CONTINUE) {
485 continue;
488 if (status == AE_CTRL_PARSE_PENDING) {
489 status = AE_OK;
492 if (status == AE_CTRL_TERMINATE) {
493 return_ACPI_STATUS(status);
496 status =
497 acpi_ps_complete_op(walk_state, &op,
498 status);
499 if (ACPI_FAILURE(status)) {
500 return_ACPI_STATUS(status);
503 continue;
506 acpi_ex_start_trace_opcode(op, walk_state);
510 * Start arg_count at zero because we don't know if there are
511 * any args yet
513 walk_state->arg_count = 0;
515 /* Are there any arguments that must be processed? */
517 if (walk_state->arg_types) {
519 /* Get arguments */
521 status =
522 acpi_ps_get_arguments(walk_state, aml_op_start, op);
523 if (ACPI_FAILURE(status)) {
524 status =
525 acpi_ps_complete_op(walk_state, &op,
526 status);
527 if (ACPI_FAILURE(status)) {
528 return_ACPI_STATUS(status);
531 continue;
535 /* Check for arguments that need to be processed */
537 if (walk_state->arg_count) {
539 * There are arguments (complex ones), push Op and
540 * prepare for argument
542 status = acpi_ps_push_scope(parser_state, op,
543 walk_state->arg_types,
544 walk_state->arg_count);
545 if (ACPI_FAILURE(status)) {
546 status =
547 acpi_ps_complete_op(walk_state, &op,
548 status);
549 if (ACPI_FAILURE(status)) {
550 return_ACPI_STATUS(status);
553 continue;
556 op = NULL;
557 continue;
561 * All arguments have been processed -- Op is complete,
562 * prepare for next
564 walk_state->op_info =
565 acpi_ps_get_opcode_info(op->common.aml_opcode);
566 if (walk_state->op_info->flags & AML_NAMED) {
567 if (op->common.aml_opcode == AML_REGION_OP ||
568 op->common.aml_opcode == AML_DATA_REGION_OP) {
570 * Skip parsing of control method or opregion body,
571 * because we don't have enough info in the first pass
572 * to parse them correctly.
574 * Completed parsing an op_region declaration, we now
575 * know the length.
577 op->named.length =
578 (u32) (parser_state->aml - op->named.data);
582 if (walk_state->op_info->flags & AML_CREATE) {
584 * Backup to beginning of create_XXXfield declaration (1 for
585 * Opcode)
587 * body_length is unknown until we parse the body
589 op->named.length =
590 (u32) (parser_state->aml - op->named.data);
593 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
595 * Backup to beginning of bank_field declaration
597 * body_length is unknown until we parse the body
599 op->named.length =
600 (u32) (parser_state->aml - op->named.data);
603 /* This op complete, notify the dispatcher */
605 if (walk_state->ascending_callback != NULL) {
606 walk_state->op = op;
607 walk_state->opcode = op->common.aml_opcode;
609 status = walk_state->ascending_callback(walk_state);
610 status =
611 acpi_ps_next_parse_state(walk_state, op, status);
612 if (status == AE_CTRL_PENDING) {
613 status = AE_OK;
617 status = acpi_ps_complete_op(walk_state, &op, status);
618 if (ACPI_FAILURE(status)) {
619 return_ACPI_STATUS(status);
622 } /* while parser_state->Aml */
624 status = acpi_ps_complete_final_op(walk_state, op, status);
625 return_ACPI_STATUS(status);