1 /****************************************************************************** 2 * 3 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 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. 25 * 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. 29 * 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. 42 */ 43 44 #define __EXOPARG6_C__ 45 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> 51 52 53 #define _COMPONENT ACPI_EXECUTER 54 ACPI_MODULE_NAME ("exoparg6") 55 56 57 /*! 58 * Naming convention for AML interpreter execution routines. 59 * 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: 63 * 64 * AcpiExOpcode_xA_yT_zR 65 * 66 * Where: 67 * 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). 74 * 75 * The AcpiExOpcode* functions are called via the Dispatcher component with 76 * fully resolved operands. 77 !*/ 78 79 /* Local prototypes */ 80 81 static BOOLEAN 82 AcpiExDoMatch ( 83 UINT32 MatchOp, 84 ACPI_OPERAND_OBJECT *PackageObj, 85 ACPI_OPERAND_OBJECT *MatchObj); 86 87 88 /******************************************************************************* 89 * 90 * FUNCTION: AcpiExDoMatch 91 * 92 * PARAMETERS: MatchOp - The AML match operand 93 * PackageObj - Object from the target package 94 * MatchObj - Object to be matched 95 * 96 * RETURN: TRUE if the match is successful, FALSE otherwise 97 * 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). 101 * 102 ******************************************************************************/ 103 104 static BOOLEAN 105 AcpiExDoMatch ( 106 UINT32 MatchOp, 107 ACPI_OPERAND_OBJECT *PackageObj, 108 ACPI_OPERAND_OBJECT *MatchObj) 109 { 110 BOOLEAN LogicalResult = TRUE; 111 ACPI_STATUS Status; 112 113 114 /* 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. 121 * 122 * Below, P[i] refers to the package element, M refers to the Match object. 123 */ 124 switch (MatchOp) 125 { 126 case MATCH_MTR: 127 128 /* Always true */ 129 130 break; 131 132 case MATCH_MEQ: 133 134 /* 135 * True if equal: (P[i] == M) 136 * Change to: (M == P[i]) 137 */ 138 Status = AcpiExDoLogicalOp (AML_LEQUAL_OP, MatchObj, PackageObj, 139 &LogicalResult); 140 if (ACPI_FAILURE (Status)) 141 { 142 return (FALSE); 143 } 144 break; 145 146 case MATCH_MLE: 147 148 /* 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]) 151 */ 152 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj, 153 &LogicalResult); 154 if (ACPI_FAILURE (Status)) 155 { 156 return (FALSE); 157 } 158 LogicalResult = (BOOLEAN) !LogicalResult; 159 break; 160 161 case MATCH_MLT: 162 163 /* 164 * True if less than: (P[i] < M) 165 * Change to: (M > P[i]) 166 */ 167 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj, 168 &LogicalResult); 169 if (ACPI_FAILURE (Status)) 170 { 171 return (FALSE); 172 } 173 break; 174 175 case MATCH_MGE: 176 177 /* 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]) 180 */ 181 Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj, 182 &LogicalResult); 183 if (ACPI_FAILURE (Status)) 184 { 185 return (FALSE); 186 } 187 LogicalResult = (BOOLEAN)!LogicalResult; 188 break; 189 190 case MATCH_MGT: 191 192 /* 193 * True if greater than: (P[i] > M) 194 * Change to: (M < P[i]) 195 */ 196 Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj, 197 &LogicalResult); 198 if (ACPI_FAILURE (Status)) 199 { 200 return (FALSE); 201 } 202 break; 203 204 default: 205 206 /* Undefined */ 207 208 return (FALSE); 209 } 210 211 return (LogicalResult); 212 } 213 214 215 /******************************************************************************* 216 * 217 * FUNCTION: AcpiExOpcode_6A_0T_1R 218 * 219 * PARAMETERS: WalkState - Current walk state 220 * 221 * RETURN: Status 222 * 223 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value 224 * 225 ******************************************************************************/ 226 227 ACPI_STATUS 228 AcpiExOpcode_6A_0T_1R ( 229 ACPI_WALK_STATE *WalkState) 230 { 231 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 232 ACPI_OPERAND_OBJECT *ReturnDesc = NULL; 233 ACPI_STATUS Status = AE_OK; 234 UINT64 Index; 235 ACPI_OPERAND_OBJECT *ThisElement; 236 237 238 ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R, 239 AcpiPsGetOpcodeName (WalkState->Opcode)); 240 241 242 switch (WalkState->Opcode) 243 { 244 case AML_MATCH_OP: 245 /* 246 * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2], 247 * MatchOp2[3], MatchObj2[4], StartIndex[5]) 248 */ 249 250 /* Validate both Match Term Operators (MTR, MEQ, etc.) */ 251 252 if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) || 253 (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR)) 254 { 255 ACPI_ERROR ((AE_INFO, "Match operator out of range")); 256 Status = AE_AML_OPERAND_VALUE; 257 goto Cleanup; 258 } 259 260 /* Get the package StartIndex, validate against the package length */ 261 262 Index = Operand[5]->Integer.Value; 263 if (Index >= Operand[0]->Package.Count) 264 { 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; 269 goto Cleanup; 270 } 271 272 /* Create an integer for the return value */ 273 /* Default return value is ACPI_UINT64_MAX if no match found */ 274 275 ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX); 276 if (!ReturnDesc) 277 { 278 Status = AE_NO_MEMORY; 279 goto Cleanup; 280 281 } 282 283 /* 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. 288 * 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 292 * match was found. 293 */ 294 for ( ; Index < Operand[0]->Package.Count; Index++) 295 { 296 /* Get the current package element */ 297 298 ThisElement = Operand[0]->Package.Elements[Index]; 299 300 /* Treat any uninitialized (NULL) elements as non-matching */ 301 302 if (!ThisElement) 303 { 304 continue; 305 } 306 307 /* 308 * Both match conditions must be satisfied. Execution of a continue 309 * (proceed to next iteration of enclosing for loop) signifies a 310 * non-match. 311 */ 312 if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value, 313 ThisElement, Operand[2])) 314 { 315 continue; 316 } 317 318 if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value, 319 ThisElement, Operand[4])) 320 { 321 continue; 322 } 323 324 /* Match found: Index is the return value */ 325 326 ReturnDesc->Integer.Value = Index; 327 break; 328 } 329 break; 330 331 332 case AML_LOAD_TABLE_OP: 333 334 Status = AcpiExLoadTableOp (WalkState, &ReturnDesc); 335 break; 336 337 338 default: 339 340 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", 341 WalkState->Opcode)); 342 Status = AE_AML_BAD_OPCODE; 343 goto Cleanup; 344 } 345 346 347 Cleanup: 348 349 /* Delete return object on error */ 350 351 if (ACPI_FAILURE (Status)) 352 { 353 AcpiUtRemoveReference (ReturnDesc); 354 } 355 356 /* Save return object on success */ 357 358 else 359 { 360 WalkState->ResultObj = ReturnDesc; 361 } 362 363 return_ACPI_STATUS (Status); 364 } 365