1 /******************************************************************************
3 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #define __EXOPARG6_C__
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acinterp.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/amlcode.h>
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exoparg6")
58 * Naming convention for AML interpreter execution routines.
60 * The routines that begin execution of AML opcodes are named with a common
61 * convention based upon the number of arguments, the number of target operands,
62 * and whether or not a value is returned:
64 * AcpiExOpcode_xA_yT_zR
68 * xA - ARGUMENTS: The number of arguments (input operands) that are
69 * required for this opcode type (1 through 6 args).
70 * yT - TARGETS: The number of targets (output operands) that are required
71 * for this opcode type (0, 1, or 2 targets).
72 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
73 * as the function return (0 or 1).
75 * The AcpiExOpcode* functions are called via the Dispatcher component with
76 * fully resolved operands.
79 /* Local prototypes */
84 ACPI_OPERAND_OBJECT *PackageObj,
85 ACPI_OPERAND_OBJECT *MatchObj);
88 /*******************************************************************************
90 * FUNCTION: AcpiExDoMatch
92 * PARAMETERS: MatchOp - The AML match operand
93 * PackageObj - Object from the target package
94 * MatchObj - Object to be matched
96 * RETURN: TRUE if the match is successful, FALSE otherwise
98 * DESCRIPTION: Implements the low-level match for the ASL Match operator.
99 * Package elements will be implicitly converted to the type of
100 * the match object (Integer/Buffer/String).
102 ******************************************************************************/
107 ACPI_OPERAND_OBJECT *PackageObj,
108 ACPI_OPERAND_OBJECT *MatchObj)
110 BOOLEAN LogicalResult = TRUE;
115 * Note: Since the PackageObj/MatchObj ordering is opposite to that of
116 * the standard logical operators, we have to reverse them when we call
117 * DoLogicalOp in order to make the implicit conversion rules work
118 * correctly. However, this means we have to flip the entire equation
119 * also. A bit ugly perhaps, but overall, better than fussing the
120 * parameters around at runtime, over and over again.
122 * Below, P[i] refers to the package element, M refers to the Match object.
135 * True if equal: (P[i] == M)
136 * Change to: (M == P[i])
138 Status = AcpiExDoLogicalOp (AML_LEQUAL_OP, MatchObj, PackageObj,
140 if (ACPI_FAILURE (Status))
149 * True if less than or equal: (P[i] <= M) (P[i] NotGreater than M)
150 * Change to: (M >= P[i]) (M NotLess than P[i])
152 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
154 if (ACPI_FAILURE (Status))
158 LogicalResult = (BOOLEAN) !LogicalResult;
164 * True if less than: (P[i] < M)
165 * Change to: (M > P[i])
167 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
169 if (ACPI_FAILURE (Status))
178 * True if greater than or equal: (P[i] >= M) (P[i] NotLess than M)
179 * Change to: (M <= P[i]) (M NotGreater than P[i])
181 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
183 if (ACPI_FAILURE (Status))
187 LogicalResult = (BOOLEAN)!LogicalResult;
193 * True if greater than: (P[i] > M)
194 * Change to: (M < P[i])
196 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
198 if (ACPI_FAILURE (Status))
211 return (LogicalResult);
215 /*******************************************************************************
217 * FUNCTION: AcpiExOpcode_6A_0T_1R
219 * PARAMETERS: WalkState - Current walk state
223 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
225 ******************************************************************************/
228 AcpiExOpcode_6A_0T_1R (
229 ACPI_WALK_STATE *WalkState)
231 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
232 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
233 ACPI_STATUS Status = AE_OK;
235 ACPI_OPERAND_OBJECT *ThisElement;
238 ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R,
239 AcpiPsGetOpcodeName (WalkState->Opcode));
242 switch (WalkState->Opcode)
246 * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2],
247 * MatchOp2[3], MatchObj2[4], StartIndex[5])
250 /* Validate both Match Term Operators (MTR, MEQ, etc.) */
252 if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) ||
253 (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR))
255 ACPI_ERROR ((AE_INFO, "Match operator out of range"));
256 Status = AE_AML_OPERAND_VALUE;
260 /* Get the package StartIndex, validate against the package length */
262 Index = Operand[5]->Integer.Value;
263 if (Index >= Operand[0]->Package.Count)
265 ACPI_ERROR ((AE_INFO,
266 "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
267 ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count));
268 Status = AE_AML_PACKAGE_LIMIT;
272 /* Create an integer for the return value */
273 /* Default return value is ACPI_UINT64_MAX if no match found */
275 ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX);
278 Status = AE_NO_MEMORY;
284 * Examine each element until a match is found. Both match conditions
285 * must be satisfied for a match to occur. Within the loop,
286 * "continue" signifies that the current element does not match
287 * and the next should be examined.
289 * Upon finding a match, the loop will terminate via "break" at
290 * the bottom. If it terminates "normally", MatchValue will be
291 * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
294 for ( ; Index < Operand[0]->Package.Count; Index++)
296 /* Get the current package element */
298 ThisElement = Operand[0]->Package.Elements[Index];
300 /* Treat any uninitialized (NULL) elements as non-matching */
308 * Both match conditions must be satisfied. Execution of a continue
309 * (proceed to next iteration of enclosing for loop) signifies a
312 if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value,
313 ThisElement, Operand[2]))
318 if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value,
319 ThisElement, Operand[4]))
324 /* Match found: Index is the return value */
326 ReturnDesc->Integer.Value = Index;
332 case AML_LOAD_TABLE_OP:
334 Status = AcpiExLoadTableOp (WalkState, &ReturnDesc);
340 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
342 Status = AE_AML_BAD_OPCODE;
349 /* Delete return object on error */
351 if (ACPI_FAILURE (Status))
353 AcpiUtRemoveReference (ReturnDesc);
356 /* Save return object on success */
360 WalkState->ResultObj = ReturnDesc;
363 return_ACPI_STATUS (Status);