Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: exoparg6 - AML execution - opcodes with 6 arguments |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acinterp.h" |
| 47 | #include "acparser.h" |
| 48 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* |
| 123 | * True if equal: (P[i] == M) |
| 124 | * Change to: (M == P[i]) |
| 125 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | status = |
| 127 | acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj, |
| 128 | &logical_result); |
| 129 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return (FALSE); |
| 131 | } |
| 132 | break; |
| 133 | |
| 134 | case MATCH_MLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* |
| 136 | * True if less than or equal: (P[i] <= M) (P[i] not_greater than M) |
| 137 | * Change to: (M >= P[i]) (M not_less than P[i]) |
| 138 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | status = |
| 140 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 141 | &logical_result); |
| 142 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return (FALSE); |
| 144 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | break; |
| 147 | |
| 148 | case MATCH_MLT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* |
| 150 | * True if less than: (P[i] < M) |
| 151 | * Change to: (M > P[i]) |
| 152 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | status = |
| 154 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 155 | package_obj, &logical_result); |
| 156 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return (FALSE); |
| 158 | } |
| 159 | break; |
| 160 | |
| 161 | case MATCH_MGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* |
| 163 | * True if greater than or equal: (P[i] >= M) (P[i] not_less than M) |
| 164 | * Change to: (M <= P[i]) (M not_greater than P[i]) |
| 165 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | status = |
| 167 | acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj, |
| 168 | package_obj, &logical_result); |
| 169 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return (FALSE); |
| 171 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | logical_result = (u8) ! logical_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | break; |
| 174 | |
| 175 | case MATCH_MGT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* |
| 177 | * True if greater than: (P[i] > M) |
| 178 | * Change to: (M < P[i]) |
| 179 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | status = |
| 181 | acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj, |
| 182 | &logical_result); |
| 183 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return (FALSE); |
| 185 | } |
| 186 | break; |
| 187 | |
| 188 | default: |
| 189 | |
| 190 | /* Undefined */ |
| 191 | |
| 192 | return (FALSE); |
| 193 | } |
| 194 | |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 195 | return (logical_result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /******************************************************************************* |
| 199 | * |
| 200 | * FUNCTION: acpi_ex_opcode_6A_0T_1R |
| 201 | * |
| 202 | * PARAMETERS: walk_state - Current walk state |
| 203 | * |
| 204 | * RETURN: Status |
| 205 | * |
| 206 | * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value |
| 207 | * |
| 208 | ******************************************************************************/ |
| 209 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | 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] | 211 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 213 | union acpi_operand_object *return_desc = NULL; |
| 214 | acpi_status status = AE_OK; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 215 | u64 index; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | union acpi_operand_object *this_element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 218 | ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | switch (walk_state->opcode) { |
| 222 | case AML_MATCH_OP: |
| 223 | /* |
| 224 | * Match (search_pkg[0], match_op1[1], match_obj1[2], |
| 225 | * match_op2[3], match_obj2[4], start_index[5]) |
| 226 | */ |
| 227 | |
| 228 | /* Validate both Match Term Operators (MTR, MEQ, etc.) */ |
| 229 | |
| 230 | if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | (operand[3]->integer.value > MAX_MATCH_OPERATOR)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 232 | ACPI_ERROR((AE_INFO, "Match operator out of range")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | status = AE_AML_OPERAND_VALUE; |
| 234 | goto cleanup; |
| 235 | } |
| 236 | |
| 237 | /* Get the package start_index, validate against the package length */ |
| 238 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 239 | index = operand[5]->integer.value; |
| 240 | if (index >= operand[0]->package.count) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 241 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 242 | "Index (0x%8.8X%8.8X) beyond package end (0x%X)", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 243 | ACPI_FORMAT_UINT64(index), |
| 244 | operand[0]->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | status = AE_AML_PACKAGE_LIMIT; |
| 246 | goto cleanup; |
| 247 | } |
| 248 | |
| 249 | /* Create an integer for the return value */ |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 250 | /* Default return value is ACPI_UINT64_MAX if no match found */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 252 | return_desc = acpi_ut_create_integer_object(ACPI_UINT64_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (!return_desc) { |
| 254 | status = AE_NO_MEMORY; |
| 255 | goto cleanup; |
| 256 | |
| 257 | } |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* |
| 260 | * Examine each element until a match is found. Both match conditions |
| 261 | * must be satisfied for a match to occur. Within the loop, |
| 262 | * "continue" signifies that the current element does not match |
| 263 | * and the next should be examined. |
| 264 | * |
| 265 | * Upon finding a match, the loop will terminate via "break" at |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 266 | * the bottom. If it terminates "normally", match_value will be |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 267 | * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | * match was found. |
| 269 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | for (; index < operand[0]->package.count; index++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /* Get the current package element */ |
| 273 | |
| 274 | this_element = operand[0]->package.elements[index]; |
| 275 | |
| 276 | /* Treat any uninitialized (NULL) elements as non-matching */ |
| 277 | |
| 278 | if (!this_element) { |
| 279 | continue; |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Both match conditions must be satisfied. Execution of a continue |
| 284 | * (proceed to next iteration of enclosing for loop) signifies a |
| 285 | * non-match. |
| 286 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | if (!acpi_ex_do_match((u32) operand[1]->integer.value, |
| 288 | this_element, operand[2])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | continue; |
| 290 | } |
| 291 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | if (!acpi_ex_do_match((u32) operand[3]->integer.value, |
| 293 | this_element, operand[4])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | continue; |
| 295 | } |
| 296 | |
| 297 | /* Match found: Index is the return value */ |
| 298 | |
| 299 | return_desc->integer.value = index; |
| 300 | break; |
| 301 | } |
| 302 | break; |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | case AML_LOAD_TABLE_OP: |
| 305 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 306 | status = acpi_ex_load_table_op(walk_state, &return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | default: |
| 310 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 311 | ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 312 | walk_state->opcode)); |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | status = AE_AML_BAD_OPCODE; |
| 315 | goto cleanup; |
| 316 | } |
| 317 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 318 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /* Delete return object on error */ |
| 321 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | if (ACPI_FAILURE(status)) { |
| 323 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Bob Moore | 4b6e16c | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 326 | /* Save return object on success */ |
| 327 | |
| 328 | else { |
| 329 | walk_state->result_obj = return_desc; |
| 330 | } |
| 331 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |