| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
|  | 2 | /****************************************************************************** | 
|  | 3 | * | 
|  | 4 | * Module Name: exoparg6 - AML execution - opcodes with 6 arguments | 
|  | 5 | * | 
|  | 6 | *****************************************************************************/ | 
|  | 7 |  | 
|  | 8 | /* | 
|  | 9 | * Copyright (C) 2000 - 2005, R. Byron Moore | 
|  | 10 | * All rights reserved. | 
|  | 11 | * | 
|  | 12 | * Redistribution and use in source and binary forms, with or without | 
|  | 13 | * modification, are permitted provided that the following conditions | 
|  | 14 | * are met: | 
|  | 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. | 
|  | 26 | * | 
|  | 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. | 
|  | 30 | * | 
|  | 31 | * NO WARRANTY | 
|  | 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. | 
|  | 43 | */ | 
|  | 44 |  | 
|  | 45 |  | 
|  | 46 | #include <acpi/acpi.h> | 
|  | 47 | #include <acpi/acinterp.h> | 
|  | 48 | #include <acpi/acparser.h> | 
|  | 49 | #include <acpi/amlcode.h> | 
|  | 50 |  | 
|  | 51 |  | 
|  | 52 | #define _COMPONENT          ACPI_EXECUTER | 
|  | 53 | ACPI_MODULE_NAME    ("exoparg6") | 
|  | 54 |  | 
|  | 55 |  | 
|  | 56 | /*! | 
|  | 57 | * Naming convention for AML interpreter execution routines. | 
|  | 58 | * | 
|  | 59 | * The routines that begin execution of AML opcodes are named with a common | 
|  | 60 | * convention based upon the number of arguments, the number of target operands, | 
|  | 61 | * and whether or not a value is returned: | 
|  | 62 | * | 
|  | 63 | *      AcpiExOpcode_xA_yT_zR | 
|  | 64 | * | 
|  | 65 | * Where: | 
|  | 66 | * | 
|  | 67 | * xA - ARGUMENTS:    The number of arguments (input operands) that are | 
|  | 68 | *                    required for this opcode type (1 through 6 args). | 
|  | 69 | * yT - TARGETS:      The number of targets (output operands) that are required | 
|  | 70 | *                    for this opcode type (0, 1, or 2 targets). | 
|  | 71 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value | 
|  | 72 | *                    as the function return (0 or 1). | 
|  | 73 | * | 
|  | 74 | * The AcpiExOpcode* functions are called via the Dispatcher component with | 
|  | 75 | * fully resolved operands. | 
|  | 76 | !*/ | 
|  | 77 |  | 
|  | 78 |  | 
|  | 79 | /******************************************************************************* | 
|  | 80 | * | 
|  | 81 | * FUNCTION:    acpi_ex_do_match | 
|  | 82 | * | 
|  | 83 | * PARAMETERS:  match_op        - The AML match operand | 
|  | 84 | *              package_obj     - Object from the target package | 
|  | 85 | *              match_obj       - Object to be matched | 
|  | 86 | * | 
|  | 87 | * RETURN:      TRUE if the match is successful, FALSE otherwise | 
|  | 88 | * | 
|  | 89 | * DESCRIPTION: Implements the low-level match for the ASL Match operator. | 
|  | 90 | *              Package elements will be implicitly converted to the type of | 
|  | 91 | *              the match object (Integer/Buffer/String). | 
|  | 92 | * | 
|  | 93 | ******************************************************************************/ | 
|  | 94 |  | 
|  | 95 | u8 | 
|  | 96 | acpi_ex_do_match ( | 
|  | 97 | u32                             match_op, | 
|  | 98 | union acpi_operand_object       *package_obj, | 
|  | 99 | union acpi_operand_object       *match_obj) | 
|  | 100 | { | 
|  | 101 | u8                              logical_result = TRUE; | 
|  | 102 | acpi_status                     status; | 
|  | 103 |  | 
|  | 104 |  | 
|  | 105 | /* | 
|  | 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. | 
|  | 112 | * | 
|  | 113 | * Below, P[i] refers to the package element, M refers to the Match object. | 
|  | 114 | */ | 
|  | 115 | switch (match_op) { | 
|  | 116 | case MATCH_MTR: | 
|  | 117 |  | 
|  | 118 | /* Always true */ | 
|  | 119 |  | 
|  | 120 | break; | 
|  | 121 |  | 
|  | 122 | case MATCH_MEQ: | 
|  | 123 |  | 
|  | 124 | /* | 
|  | 125 | * True if equal: (P[i] == M) | 
|  | 126 | * Change to:     (M == P[i]) | 
|  | 127 | */ | 
|  | 128 | status = acpi_ex_do_logical_op (AML_LEQUAL_OP, match_obj, package_obj, | 
|  | 129 | &logical_result); | 
|  | 130 | if (ACPI_FAILURE (status)) { | 
|  | 131 | return (FALSE); | 
|  | 132 | } | 
|  | 133 | break; | 
|  | 134 |  | 
|  | 135 | case MATCH_MLE: | 
|  | 136 |  | 
|  | 137 | /* | 
|  | 138 | * True if less than or equal: (P[i] <= M) (P[i] not_greater than M) | 
|  | 139 | * Change to:                  (M >= P[i]) (M not_less than P[i]) | 
|  | 140 | */ | 
|  | 141 | status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj, | 
|  | 142 | &logical_result); | 
|  | 143 | if (ACPI_FAILURE (status)) { | 
|  | 144 | return (FALSE); | 
|  | 145 | } | 
|  | 146 | logical_result = (u8) !logical_result; | 
|  | 147 | break; | 
|  | 148 |  | 
|  | 149 | case MATCH_MLT: | 
|  | 150 |  | 
|  | 151 | /* | 
|  | 152 | * True if less than: (P[i] < M) | 
|  | 153 | * Change to:         (M > P[i]) | 
|  | 154 | */ | 
|  | 155 | status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj, | 
|  | 156 | &logical_result); | 
|  | 157 | if (ACPI_FAILURE (status)) { | 
|  | 158 | return (FALSE); | 
|  | 159 | } | 
|  | 160 | break; | 
|  | 161 |  | 
|  | 162 | case MATCH_MGE: | 
|  | 163 |  | 
|  | 164 | /* | 
|  | 165 | * True if greater than or equal: (P[i] >= M) (P[i] not_less than M) | 
|  | 166 | * Change to:                     (M <= P[i]) (M not_greater than P[i]) | 
|  | 167 | */ | 
|  | 168 | status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj, | 
|  | 169 | &logical_result); | 
|  | 170 | if (ACPI_FAILURE (status)) { | 
|  | 171 | return (FALSE); | 
|  | 172 | } | 
|  | 173 | logical_result = (u8)!logical_result; | 
|  | 174 | break; | 
|  | 175 |  | 
|  | 176 | case MATCH_MGT: | 
|  | 177 |  | 
|  | 178 | /* | 
|  | 179 | * True if greater than: (P[i] > M) | 
|  | 180 | * Change to:            (M < P[i]) | 
|  | 181 | */ | 
|  | 182 | status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj, | 
|  | 183 | &logical_result); | 
|  | 184 | if (ACPI_FAILURE (status)) { | 
|  | 185 | return (FALSE); | 
|  | 186 | } | 
|  | 187 | break; | 
|  | 188 |  | 
|  | 189 | default: | 
|  | 190 |  | 
|  | 191 | /* Undefined */ | 
|  | 192 |  | 
|  | 193 | return (FALSE); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | return logical_result; | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 |  | 
|  | 200 | /******************************************************************************* | 
|  | 201 | * | 
|  | 202 | * FUNCTION:    acpi_ex_opcode_6A_0T_1R | 
|  | 203 | * | 
|  | 204 | * PARAMETERS:  walk_state          - Current walk state | 
|  | 205 | * | 
|  | 206 | * RETURN:      Status | 
|  | 207 | * | 
|  | 208 | * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value | 
|  | 209 | * | 
|  | 210 | ******************************************************************************/ | 
|  | 211 |  | 
|  | 212 | acpi_status | 
|  | 213 | acpi_ex_opcode_6A_0T_1R ( | 
|  | 214 | struct acpi_walk_state          *walk_state) | 
|  | 215 | { | 
|  | 216 | union acpi_operand_object       **operand = &walk_state->operands[0]; | 
|  | 217 | union acpi_operand_object       *return_desc = NULL; | 
|  | 218 | acpi_status                     status = AE_OK; | 
|  | 219 | u32                             index; | 
|  | 220 | union acpi_operand_object       *this_element; | 
|  | 221 |  | 
|  | 222 |  | 
|  | 223 | ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); | 
|  | 224 |  | 
|  | 225 |  | 
|  | 226 | switch (walk_state->opcode) { | 
|  | 227 | case AML_MATCH_OP: | 
|  | 228 | /* | 
|  | 229 | * Match (search_pkg[0], match_op1[1], match_obj1[2], | 
|  | 230 | *                      match_op2[3], match_obj2[4], start_index[5]) | 
|  | 231 | */ | 
|  | 232 |  | 
|  | 233 | /* Validate both Match Term Operators (MTR, MEQ, etc.) */ | 
|  | 234 |  | 
|  | 235 | if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) || | 
|  | 236 | (operand[3]->integer.value > MAX_MATCH_OPERATOR)) { | 
|  | 237 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Match operator out of range\n")); | 
|  | 238 | status = AE_AML_OPERAND_VALUE; | 
|  | 239 | goto cleanup; | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | /* Get the package start_index, validate against the package length */ | 
|  | 243 |  | 
|  | 244 | index = (u32) operand[5]->integer.value; | 
|  | 245 | if (index >= (u32) operand[0]->package.count) { | 
|  | 246 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index beyond package end\n")); | 
|  | 247 | status = AE_AML_PACKAGE_LIMIT; | 
|  | 248 | goto cleanup; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | /* Create an integer for the return value */ | 
|  | 252 |  | 
|  | 253 | return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); | 
|  | 254 | if (!return_desc) { | 
|  | 255 | status = AE_NO_MEMORY; | 
|  | 256 | goto cleanup; | 
|  | 257 |  | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | /* Default return value if no match found */ | 
|  | 261 |  | 
|  | 262 | return_desc->integer.value = ACPI_INTEGER_MAX; | 
|  | 263 |  | 
|  | 264 | /* | 
|  | 265 | * Examine each element until a match is found. Both match conditions | 
|  | 266 | * must be satisfied for a match to occur. Within the loop, | 
|  | 267 | * "continue" signifies that the current element does not match | 
|  | 268 | * and the next should be examined. | 
|  | 269 | * | 
|  | 270 | * Upon finding a match, the loop will terminate via "break" at | 
|  | 271 | * the bottom.  If it terminates "normally", match_value will be | 
|  | 272 | * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no | 
|  | 273 | * match was found. | 
|  | 274 | */ | 
|  | 275 | for ( ; index < operand[0]->package.count; index++) { | 
|  | 276 | /* Get the current package element */ | 
|  | 277 |  | 
|  | 278 | this_element = operand[0]->package.elements[index]; | 
|  | 279 |  | 
|  | 280 | /* Treat any uninitialized (NULL) elements as non-matching */ | 
|  | 281 |  | 
|  | 282 | if (!this_element) { | 
|  | 283 | continue; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | /* | 
|  | 287 | * Both match conditions must be satisfied. Execution of a continue | 
|  | 288 | * (proceed to next iteration of enclosing for loop) signifies a | 
|  | 289 | * non-match. | 
|  | 290 | */ | 
|  | 291 | if (!acpi_ex_do_match ((u32) operand[1]->integer.value, | 
|  | 292 | this_element, operand[2])) { | 
|  | 293 | continue; | 
|  | 294 | } | 
|  | 295 |  | 
|  | 296 | if (!acpi_ex_do_match ((u32) operand[3]->integer.value, | 
|  | 297 | this_element, operand[4])) { | 
|  | 298 | continue; | 
|  | 299 | } | 
|  | 300 |  | 
|  | 301 | /* Match found: Index is the return value */ | 
|  | 302 |  | 
|  | 303 | return_desc->integer.value = index; | 
|  | 304 | break; | 
|  | 305 | } | 
|  | 306 | break; | 
|  | 307 |  | 
|  | 308 |  | 
|  | 309 | case AML_LOAD_TABLE_OP: | 
|  | 310 |  | 
|  | 311 | status = acpi_ex_load_table_op (walk_state, &return_desc); | 
|  | 312 | break; | 
|  | 313 |  | 
|  | 314 |  | 
|  | 315 | default: | 
|  | 316 |  | 
|  | 317 | ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", | 
|  | 318 | walk_state->opcode)); | 
|  | 319 | status = AE_AML_BAD_OPCODE; | 
|  | 320 | goto cleanup; | 
|  | 321 | } | 
|  | 322 |  | 
|  | 323 |  | 
|  | 324 | walk_state->result_obj = return_desc; | 
|  | 325 |  | 
|  | 326 |  | 
|  | 327 | cleanup: | 
|  | 328 |  | 
|  | 329 | /* Delete return object on error */ | 
|  | 330 |  | 
|  | 331 | if (ACPI_FAILURE (status)) { | 
|  | 332 | acpi_ut_remove_reference (return_desc); | 
|  | 333 | } | 
|  | 334 |  | 
|  | 335 | return_ACPI_STATUS (status); | 
|  | 336 | } |