2 /******************************************************************************
4 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME("exoparg6")
55 * Naming convention for AML interpreter execution routines.
57 * The routines that begin execution of AML opcodes are named with a common
58 * convention based upon the number of arguments, the number of target operands,
59 * and whether or not a value is returned:
61 * AcpiExOpcode_xA_yT_zR
65 * xA - ARGUMENTS: The number of arguments (input operands) that are
66 * required for this opcode type (1 through 6 args).
67 * yT - TARGETS: The number of targets (output operands) that are required
68 * for this opcode type (0, 1, or 2 targets).
69 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
70 * as the function return (0 or 1).
72 * The AcpiExOpcode* functions are called via the Dispatcher component with
73 * fully resolved operands.
75 /* Local prototypes */
77 acpi_ex_do_match(u32 match_op,
78 union acpi_operand_object *package_obj,
79 union acpi_operand_object *match_obj);
81 /*******************************************************************************
83 * FUNCTION: acpi_ex_do_match
85 * PARAMETERS: match_op - The AML match operand
86 * package_obj - Object from the target package
87 * match_obj - Object to be matched
89 * RETURN: TRUE if the match is successful, FALSE otherwise
91 * DESCRIPTION: Implements the low-level match for the ASL Match operator.
92 * Package elements will be implicitly converted to the type of
93 * the match object (Integer/Buffer/String).
95 ******************************************************************************/
98 acpi_ex_do_match(u32 match_op,
99 union acpi_operand_object *package_obj,
100 union acpi_operand_object *match_obj)
102 u8 logical_result = TRUE;
106 * Note: Since the package_obj/match_obj ordering is opposite to that of
107 * the standard logical operators, we have to reverse them when we call
108 * do_logical_op in order to make the implicit conversion rules work
109 * correctly. However, this means we have to flip the entire equation
110 * also. A bit ugly perhaps, but overall, better than fussing the
111 * parameters around at runtime, over and over again.
113 * Below, P[i] refers to the package element, M refers to the Match object.
125 * True if equal: (P[i] == M)
126 * Change to: (M == P[i])
129 acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj,
131 if (ACPI_FAILURE(status)) {
139 * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
140 * Change to: (M >= P[i]) (M not_less than P[i])
143 acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
145 if (ACPI_FAILURE(status)) {
148 logical_result = (u8) ! logical_result;
154 * True if less than: (P[i] < M)
155 * Change to: (M > P[i])
158 acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
159 package_obj, &logical_result);
160 if (ACPI_FAILURE(status)) {
168 * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
169 * Change to: (M <= P[i]) (M not_greater than P[i])
172 acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
173 package_obj, &logical_result);
174 if (ACPI_FAILURE(status)) {
177 logical_result = (u8) ! logical_result;
183 * True if greater than: (P[i] > M)
184 * Change to: (M < P[i])
187 acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
189 if (ACPI_FAILURE(status)) {
201 return logical_result;
204 /*******************************************************************************
206 * FUNCTION: acpi_ex_opcode_6A_0T_1R
208 * PARAMETERS: walk_state - Current walk state
212 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
214 ******************************************************************************/
216 acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
218 union acpi_operand_object **operand = &walk_state->operands[0];
219 union acpi_operand_object *return_desc = NULL;
220 acpi_status status = AE_OK;
222 union acpi_operand_object *this_element;
224 ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R,
225 acpi_ps_get_opcode_name(walk_state->opcode));
227 switch (walk_state->opcode) {
230 * Match (search_pkg[0], match_op1[1], match_obj1[2],
231 * match_op2[3], match_obj2[4], start_index[5])
234 /* Validate both Match Term Operators (MTR, MEQ, etc.) */
236 if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
237 (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
238 ACPI_ERROR((AE_INFO, "Match operator out of range"));
239 status = AE_AML_OPERAND_VALUE;
243 /* Get the package start_index, validate against the package length */
245 index = operand[5]->integer.value;
246 if (index >= operand[0]->package.count) {
248 "Index (%X%8.8X) beyond package end (%X)",
249 ACPI_FORMAT_UINT64(index),
250 operand[0]->package.count));
251 status = AE_AML_PACKAGE_LIMIT;
255 /* Create an integer for the return value */
257 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
259 status = AE_NO_MEMORY;
264 /* Default return value if no match found */
266 return_desc->integer.value = ACPI_INTEGER_MAX;
269 * Examine each element until a match is found. Both match conditions
270 * must be satisfied for a match to occur. Within the loop,
271 * "continue" signifies that the current element does not match
272 * and the next should be examined.
274 * Upon finding a match, the loop will terminate via "break" at
275 * the bottom. If it terminates "normally", match_value will be
276 * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no
279 for (; index < operand[0]->package.count; index++) {
281 /* Get the current package element */
283 this_element = operand[0]->package.elements[index];
285 /* Treat any uninitialized (NULL) elements as non-matching */
292 * Both match conditions must be satisfied. Execution of a continue
293 * (proceed to next iteration of enclosing for loop) signifies a
296 if (!acpi_ex_do_match((u32) operand[1]->integer.value,
297 this_element, operand[2])) {
301 if (!acpi_ex_do_match((u32) operand[3]->integer.value,
302 this_element, operand[4])) {
306 /* Match found: Index is the return value */
308 return_desc->integer.value = index;
313 case AML_LOAD_TABLE_OP:
315 status = acpi_ex_load_table_op(walk_state, &return_desc);
320 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
321 walk_state->opcode));
322 status = AE_AML_BAD_OPCODE;
328 /* Delete return object on error */
330 if (ACPI_FAILURE(status)) {
331 acpi_ut_remove_reference(return_desc);
334 /* Save return object on success */
337 walk_state->result_obj = return_desc;
340 return_ACPI_STATUS(status);