2 /******************************************************************************
4 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, 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 #define __EXOPARG6_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acinterp.h>
50 #include <contrib/dev/acpica/include/acparser.h>
51 #include <contrib/dev/acpica/include/amlcode.h>
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exoparg6")
59 * Naming convention for AML interpreter execution routines.
61 * The routines that begin execution of AML opcodes are named with a common
62 * convention based upon the number of arguments, the number of target operands,
63 * and whether or not a value is returned:
65 * AcpiExOpcode_xA_yT_zR
69 * xA - ARGUMENTS: The number of arguments (input operands) that are
70 * required for this opcode type (1 through 6 args).
71 * yT - TARGETS: The number of targets (output operands) that are required
72 * for this opcode type (0, 1, or 2 targets).
73 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
74 * as the function return (0 or 1).
76 * The AcpiExOpcode* functions are called via the Dispatcher component with
77 * fully resolved operands.
80 /* Local prototypes */
85 ACPI_OPERAND_OBJECT *PackageObj,
86 ACPI_OPERAND_OBJECT *MatchObj);
89 /*******************************************************************************
91 * FUNCTION: AcpiExDoMatch
93 * PARAMETERS: MatchOp - The AML match operand
94 * PackageObj - Object from the target package
95 * MatchObj - Object to be matched
97 * RETURN: TRUE if the match is successful, FALSE otherwise
99 * DESCRIPTION: Implements the low-level match for the ASL Match operator.
100 * Package elements will be implicitly converted to the type of
101 * the match object (Integer/Buffer/String).
103 ******************************************************************************/
108 ACPI_OPERAND_OBJECT *PackageObj,
109 ACPI_OPERAND_OBJECT *MatchObj)
111 BOOLEAN LogicalResult = TRUE;
116 * Note: Since the PackageObj/MatchObj ordering is opposite to that of
117 * the standard logical operators, we have to reverse them when we call
118 * DoLogicalOp in order to make the implicit conversion rules work
119 * correctly. However, this means we have to flip the entire equation
120 * also. A bit ugly perhaps, but overall, better than fussing the
121 * parameters around at runtime, over and over again.
123 * Below, P[i] refers to the package element, M refers to the Match object.
136 * True if equal: (P[i] == M)
137 * Change to: (M == P[i])
139 Status = AcpiExDoLogicalOp (AML_LEQUAL_OP, MatchObj, PackageObj,
141 if (ACPI_FAILURE (Status))
150 * True if less than or equal: (P[i] <= M) (P[i] NotGreater than M)
151 * Change to: (M >= P[i]) (M NotLess than P[i])
153 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
155 if (ACPI_FAILURE (Status))
159 LogicalResult = (BOOLEAN) !LogicalResult;
165 * True if less than: (P[i] < M)
166 * Change to: (M > P[i])
168 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
170 if (ACPI_FAILURE (Status))
179 * True if greater than or equal: (P[i] >= M) (P[i] NotLess than M)
180 * Change to: (M <= P[i]) (M NotGreater than P[i])
182 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
184 if (ACPI_FAILURE (Status))
188 LogicalResult = (BOOLEAN)!LogicalResult;
194 * True if greater than: (P[i] > M)
195 * Change to: (M < P[i])
197 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
199 if (ACPI_FAILURE (Status))
212 return LogicalResult;
216 /*******************************************************************************
218 * FUNCTION: AcpiExOpcode_6A_0T_1R
220 * PARAMETERS: WalkState - Current walk state
224 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
226 ******************************************************************************/
229 AcpiExOpcode_6A_0T_1R (
230 ACPI_WALK_STATE *WalkState)
232 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
233 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
234 ACPI_STATUS Status = AE_OK;
236 ACPI_OPERAND_OBJECT *ThisElement;
239 ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R,
240 AcpiPsGetOpcodeName (WalkState->Opcode));
243 switch (WalkState->Opcode)
247 * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2],
248 * MatchOp2[3], MatchObj2[4], StartIndex[5])
251 /* Validate both Match Term Operators (MTR, MEQ, etc.) */
253 if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) ||
254 (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR))
256 ACPI_ERROR ((AE_INFO, "Match operator out of range"));
257 Status = AE_AML_OPERAND_VALUE;
261 /* Get the package StartIndex, validate against the package length */
263 Index = Operand[5]->Integer.Value;
264 if (Index >= Operand[0]->Package.Count)
266 ACPI_ERROR ((AE_INFO,
267 "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
268 ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count));
269 Status = AE_AML_PACKAGE_LIMIT;
273 /* Create an integer for the return value */
274 /* Default return value is ACPI_UINT64_MAX if no match found */
276 ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX);
279 Status = AE_NO_MEMORY;
285 * Examine each element until a match is found. Both match conditions
286 * must be satisfied for a match to occur. Within the loop,
287 * "continue" signifies that the current element does not match
288 * and the next should be examined.
290 * Upon finding a match, the loop will terminate via "break" at
291 * the bottom. If it terminates "normally", MatchValue will be
292 * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
295 for ( ; Index < Operand[0]->Package.Count; Index++)
297 /* Get the current package element */
299 ThisElement = Operand[0]->Package.Elements[Index];
301 /* Treat any uninitialized (NULL) elements as non-matching */
309 * Both match conditions must be satisfied. Execution of a continue
310 * (proceed to next iteration of enclosing for loop) signifies a
313 if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value,
314 ThisElement, Operand[2]))
319 if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value,
320 ThisElement, Operand[4]))
325 /* Match found: Index is the return value */
327 ReturnDesc->Integer.Value = Index;
333 case AML_LOAD_TABLE_OP:
335 Status = AcpiExLoadTableOp (WalkState, &ReturnDesc);
341 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
343 Status = AE_AML_BAD_OPCODE;
350 /* Delete return object on error */
352 if (ACPI_FAILURE (Status))
354 AcpiUtRemoveReference (ReturnDesc);
357 /* Save return object on success */
361 WalkState->ResultObj = ReturnDesc;
364 return_ACPI_STATUS (Status);