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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acinterp.h> |
| 47 | #include <acpi/acparser.h> |
| 48 | #include <acpi/amlcode.h> |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("exoparg6") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /*! |
| 54 | * Naming convention for AML interpreter execution routines. |
| 55 | * |
| 56 | * The routines that begin execution of AML opcodes are named with a common |
| 57 | * convention based upon the number of arguments, the number of target operands, |
| 58 | * and whether or not a value is returned: |
| 59 | * |
| 60 | * AcpiExOpcode_xA_yT_zR |
| 61 | * |
| 62 | * Where: |
| 63 | * |
| 64 | * xA - ARGUMENTS: The number of arguments (input operands) that are |
| 65 | * required for this opcode type (1 through 6 args). |
| 66 | * yT - TARGETS: The number of targets (output operands) that are required |
| 67 | * for this opcode type (0, 1, or 2 targets). |
| 68 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value |
| 69 | * as the function return (0 or 1). |
| 70 | * |
| 71 | * The AcpiExOpcode* functions are called via the Dispatcher component with |
| 72 | * fully resolved operands. |
| 73 | !*/ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 74 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 75 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | acpi_ex_do_match(u32 match_op, |
| 77 | union acpi_operand_object *package_obj, |
| 78 | union acpi_operand_object *match_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /******************************************************************************* |
| 81 | * |
| 82 | * FUNCTION: acpi_ex_do_match |
| 83 | * |
| 84 | * PARAMETERS: match_op - The AML match operand |
| 85 | * package_obj - Object from the target package |
| 86 | * match_obj - Object to be matched |
| 87 | * |
| 88 | * RETURN: TRUE if the match is successful, FALSE otherwise |
| 89 | * |
| 90 | * DESCRIPTION: Implements the low-level match for the ASL Match operator. |
| 91 | * Package elements will be implicitly converted to the type of |
| 92 | * the match object (Integer/Buffer/String). |
| 93 | * |
| 94 | ******************************************************************************/ |
| 95 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 96 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | acpi_ex_do_match(u32 match_op, |
| 98 | union acpi_operand_object *package_obj, |
| 99 | union acpi_operand_object *match_obj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | u8 logical_result = TRUE; |
| 102 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Note: Since the package_obj/match_obj ordering is opposite to that of |
| 106 | * the standard logical operators, we have to reverse them when we call |
| 107 | * do_logical_op in order to make the implicit conversion rules work |
| 108 | * correctly. However, this means we have to flip the entire equation |
| 109 | * also. A bit ugly perhaps, but overall, better than fussing the |
| 110 | * parameters around at runtime, over and over again. |
| 111 | * |
| 112 | * Below, P[i] refers to the package element, M refers to the Match object. |
| 113 | */ |
| 114 | switch (match_op) { |
| 115 | case MATCH_MTR: |
| 116 | |
| 117 | /* Always true */ |
| 118 | |
| 119 | break; |
| 120 | |
| 121 | case MATCH_MEQ: |
| 122 | |
| 123 | /* |
| 124 | * True if equal: (P[i] == M) |
| 125 | * Change to: (M == P[i]) |
| 126 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | status = |
| 128 | acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj, |
| 129 | &logical_result); |
| 130 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | status = |
| 142 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 143 | &logical_result); |
| 144 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return (FALSE); |
| 146 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | break; |
| 149 | |
| 150 | case MATCH_MLT: |
| 151 | |
| 152 | /* |
| 153 | * True if less than: (P[i] < M) |
| 154 | * Change to: (M > P[i]) |
| 155 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | status = |
| 157 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 158 | package_obj, &logical_result); |
| 159 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return (FALSE); |
| 161 | } |
| 162 | break; |
| 163 | |
| 164 | case MATCH_MGE: |
| 165 | |
| 166 | /* |
| 167 | * True if greater than or equal: (P[i] >= M) (P[i] not_less than M) |
| 168 | * Change to: (M <= P[i]) (M not_greater than P[i]) |
| 169 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | status = |
| 171 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 172 | package_obj, &logical_result); |
| 173 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return (FALSE); |
| 175 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | break; |
| 178 | |
| 179 | case MATCH_MGT: |
| 180 | |
| 181 | /* |
| 182 | * True if greater than: (P[i] > M) |
| 183 | * Change to: (M < P[i]) |
| 184 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | status = |
| 186 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 187 | &logical_result); |
| 188 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return (FALSE); |
| 190 | } |
| 191 | break; |
| 192 | |
| 193 | default: |
| 194 | |
| 195 | /* Undefined */ |
| 196 | |
| 197 | return (FALSE); |
| 198 | } |
| 199 | |
| 200 | return logical_result; |
| 201 | } |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /******************************************************************************* |
| 204 | * |
| 205 | * FUNCTION: acpi_ex_opcode_6A_0T_1R |
| 206 | * |
| 207 | * PARAMETERS: walk_state - Current walk state |
| 208 | * |
| 209 | * RETURN: Status |
| 210 | * |
| 211 | * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value |
| 212 | * |
| 213 | ******************************************************************************/ |
| 214 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 218 | union acpi_operand_object *return_desc = NULL; |
| 219 | acpi_status status = AE_OK; |
| 220 | acpi_integer index; |
| 221 | union acpi_operand_object *this_element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | ACPI_FUNCTION_TRACE_STR("ex_opcode_6A_0T_1R", |
| 224 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | (operand[3]->integer.value > MAX_MATCH_OPERATOR)) { |
| 237 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 238 | "Match operator out of range\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | status = AE_AML_OPERAND_VALUE; |
| 240 | goto cleanup; |
| 241 | } |
| 242 | |
| 243 | /* Get the package start_index, validate against the package length */ |
| 244 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 245 | index = operand[5]->integer.value; |
| 246 | if (index >= operand[0]->package.count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 248 | "Index (%X%8.8X) beyond package end (%X)\n", |
| 249 | ACPI_FORMAT_UINT64(index), |
| 250 | operand[0]->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | status = AE_AML_PACKAGE_LIMIT; |
| 252 | goto cleanup; |
| 253 | } |
| 254 | |
| 255 | /* Create an integer for the return value */ |
| 256 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (!return_desc) { |
| 259 | status = AE_NO_MEMORY; |
| 260 | goto cleanup; |
| 261 | |
| 262 | } |
| 263 | |
| 264 | /* Default return value if no match found */ |
| 265 | |
| 266 | return_desc->integer.value = ACPI_INTEGER_MAX; |
| 267 | |
| 268 | /* |
| 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. |
| 273 | * |
| 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 |
| 277 | * match was found. |
| 278 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | for (; index < operand[0]->package.count; index++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* Get the current package element */ |
| 281 | |
| 282 | this_element = operand[0]->package.elements[index]; |
| 283 | |
| 284 | /* Treat any uninitialized (NULL) elements as non-matching */ |
| 285 | |
| 286 | if (!this_element) { |
| 287 | continue; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Both match conditions must be satisfied. Execution of a continue |
| 292 | * (proceed to next iteration of enclosing for loop) signifies a |
| 293 | * non-match. |
| 294 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 295 | if (!acpi_ex_do_match((u32) operand[1]->integer.value, |
| 296 | this_element, operand[2])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | continue; |
| 298 | } |
| 299 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | if (!acpi_ex_do_match((u32) operand[3]->integer.value, |
| 301 | this_element, operand[4])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | continue; |
| 303 | } |
| 304 | |
| 305 | /* Match found: Index is the return value */ |
| 306 | |
| 307 | return_desc->integer.value = index; |
| 308 | break; |
| 309 | } |
| 310 | break; |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | case AML_LOAD_TABLE_OP: |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | status = acpi_ex_load_table_op(walk_state, &return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | break; |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | default: |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | ACPI_REPORT_ERROR(("acpi_ex_opcode_6A_0T_1R: Unknown opcode %X\n", walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | status = AE_AML_BAD_OPCODE; |
| 321 | goto cleanup; |
| 322 | } |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | walk_state->result_obj = return_desc; |
| 325 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | /* Delete return object on error */ |
| 329 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | if (ACPI_FAILURE(status)) { |
| 331 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |