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 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame^] | 9 | * Copyright (C) 2000 - 2012, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" |
| 47 | #include "acinterp.h" |
| 48 | #include "acparser.h" |
| 49 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("exoparg6") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /*! |
| 55 | * Naming convention for AML interpreter execution routines. |
| 56 | * |
| 57 | * The routines that begin execution of AML opcodes are named with a common |
| 58 | * convention based upon the number of arguments, the number of target operands, |
| 59 | * and whether or not a value is returned: |
| 60 | * |
| 61 | * AcpiExOpcode_xA_yT_zR |
| 62 | * |
| 63 | * Where: |
| 64 | * |
| 65 | * xA - ARGUMENTS: The number of arguments (input operands) that are |
| 66 | * required for this opcode type (1 through 6 args). |
| 67 | * yT - TARGETS: The number of targets (output operands) that are required |
| 68 | * for this opcode type (0, 1, or 2 targets). |
| 69 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value |
| 70 | * as the function return (0 or 1). |
| 71 | * |
| 72 | * The AcpiExOpcode* functions are called via the Dispatcher component with |
| 73 | * fully resolved operands. |
| 74 | !*/ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 75 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 76 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | acpi_ex_do_match(u32 match_op, |
| 78 | union acpi_operand_object *package_obj, |
| 79 | union acpi_operand_object *match_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /******************************************************************************* |
| 82 | * |
| 83 | * FUNCTION: acpi_ex_do_match |
| 84 | * |
| 85 | * PARAMETERS: match_op - The AML match operand |
| 86 | * package_obj - Object from the target package |
| 87 | * match_obj - Object to be matched |
| 88 | * |
| 89 | * RETURN: TRUE if the match is successful, FALSE otherwise |
| 90 | * |
| 91 | * DESCRIPTION: Implements the low-level match for the ASL Match operator. |
| 92 | * Package elements will be implicitly converted to the type of |
| 93 | * the match object (Integer/Buffer/String). |
| 94 | * |
| 95 | ******************************************************************************/ |
| 96 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 97 | static u8 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | acpi_ex_do_match(u32 match_op, |
| 99 | union acpi_operand_object *package_obj, |
| 100 | union acpi_operand_object *match_obj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | u8 logical_result = TRUE; |
| 103 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | status = |
| 129 | acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj, |
| 130 | &logical_result); |
| 131 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return (FALSE); |
| 133 | } |
| 134 | break; |
| 135 | |
| 136 | case MATCH_MLE: |
| 137 | |
| 138 | /* |
| 139 | * True if less than or equal: (P[i] <= M) (P[i] not_greater than M) |
| 140 | * Change to: (M >= P[i]) (M not_less than P[i]) |
| 141 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | status = |
| 143 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 144 | &logical_result); |
| 145 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | return (FALSE); |
| 147 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | break; |
| 150 | |
| 151 | case MATCH_MLT: |
| 152 | |
| 153 | /* |
| 154 | * True if less than: (P[i] < M) |
| 155 | * Change to: (M > P[i]) |
| 156 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | status = |
| 158 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 159 | package_obj, &logical_result); |
| 160 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return (FALSE); |
| 162 | } |
| 163 | break; |
| 164 | |
| 165 | case MATCH_MGE: |
| 166 | |
| 167 | /* |
| 168 | * True if greater than or equal: (P[i] >= M) (P[i] not_less than M) |
| 169 | * Change to: (M <= P[i]) (M not_greater than P[i]) |
| 170 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | status = |
| 172 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 173 | package_obj, &logical_result); |
| 174 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | return (FALSE); |
| 176 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | |
| 180 | case MATCH_MGT: |
| 181 | |
| 182 | /* |
| 183 | * True if greater than: (P[i] > M) |
| 184 | * Change to: (M < P[i]) |
| 185 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | status = |
| 187 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 188 | &logical_result); |
| 189 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return (FALSE); |
| 191 | } |
| 192 | break; |
| 193 | |
| 194 | default: |
| 195 | |
| 196 | /* Undefined */ |
| 197 | |
| 198 | return (FALSE); |
| 199 | } |
| 200 | |
| 201 | return logical_result; |
| 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /******************************************************************************* |
| 205 | * |
| 206 | * FUNCTION: acpi_ex_opcode_6A_0T_1R |
| 207 | * |
| 208 | * PARAMETERS: walk_state - Current walk state |
| 209 | * |
| 210 | * RETURN: Status |
| 211 | * |
| 212 | * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value |
| 213 | * |
| 214 | ******************************************************************************/ |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | 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] | 217 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 219 | union acpi_operand_object *return_desc = NULL; |
| 220 | acpi_status status = AE_OK; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 221 | u64 index; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | union acpi_operand_object *this_element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 224 | ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | switch (walk_state->opcode) { |
| 228 | case AML_MATCH_OP: |
| 229 | /* |
| 230 | * Match (search_pkg[0], match_op1[1], match_obj1[2], |
| 231 | * match_op2[3], match_obj2[4], start_index[5]) |
| 232 | */ |
| 233 | |
| 234 | /* Validate both Match Term Operators (MTR, MEQ, etc.) */ |
| 235 | |
| 236 | if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | (operand[3]->integer.value > MAX_MATCH_OPERATOR)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 238 | ACPI_ERROR((AE_INFO, "Match operator out of range")); |
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) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 247 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 248 | "Index (0x%8.8X%8.8X) beyond package end (0x%X)", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 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 */ |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 256 | /* Default return value is ACPI_UINT64_MAX if no match found */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 258 | return_desc = acpi_ut_create_integer_object(ACPI_UINT64_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | if (!return_desc) { |
| 260 | status = AE_NO_MEMORY; |
| 261 | goto cleanup; |
| 262 | |
| 263 | } |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /* |
| 266 | * Examine each element until a match is found. Both match conditions |
| 267 | * must be satisfied for a match to occur. Within the loop, |
| 268 | * "continue" signifies that the current element does not match |
| 269 | * and the next should be examined. |
| 270 | * |
| 271 | * Upon finding a match, the loop will terminate via "break" at |
| 272 | * the bottom. If it terminates "normally", match_value will be |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 273 | * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | * match was found. |
| 275 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | for (; index < operand[0]->package.count; index++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* Get the current package element */ |
| 279 | |
| 280 | this_element = operand[0]->package.elements[index]; |
| 281 | |
| 282 | /* Treat any uninitialized (NULL) elements as non-matching */ |
| 283 | |
| 284 | if (!this_element) { |
| 285 | continue; |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Both match conditions must be satisfied. Execution of a continue |
| 290 | * (proceed to next iteration of enclosing for loop) signifies a |
| 291 | * non-match. |
| 292 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | if (!acpi_ex_do_match((u32) operand[1]->integer.value, |
| 294 | this_element, operand[2])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | continue; |
| 296 | } |
| 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | if (!acpi_ex_do_match((u32) operand[3]->integer.value, |
| 299 | this_element, operand[4])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | continue; |
| 301 | } |
| 302 | |
| 303 | /* Match found: Index is the return value */ |
| 304 | |
| 305 | return_desc->integer.value = index; |
| 306 | break; |
| 307 | } |
| 308 | break; |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | case AML_LOAD_TABLE_OP: |
| 311 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | status = acpi_ex_load_table_op(walk_state, &return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | break; |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | default: |
| 316 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 317 | ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 318 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | status = AE_AML_BAD_OPCODE; |
| 320 | goto cleanup; |
| 321 | } |
| 322 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* Delete return object on error */ |
| 326 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | if (ACPI_FAILURE(status)) { |
| 328 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Bob Moore | 4b6e16c | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 331 | /* Save return object on success */ |
| 332 | |
| 333 | else { |
| 334 | walk_state->result_obj = return_desc; |
| 335 | } |
| 336 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |