Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes |
| 5 | * |
Bob Moore | 4441e55 | 2021-01-15 10:48:25 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2021, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acinterp.h" |
| 13 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 16 | ACPI_MODULE_NAME("exmisc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /******************************************************************************* |
| 19 | * |
| 20 | * FUNCTION: acpi_ex_get_object_reference |
| 21 | * |
| 22 | * PARAMETERS: obj_desc - Create a reference to this object |
| 23 | * return_desc - Where to store the reference |
| 24 | * walk_state - Current state |
| 25 | * |
| 26 | * RETURN: Status |
| 27 | * |
| 28 | * DESCRIPTION: Obtain and return a "reference" to the target object |
| 29 | * Common code for the ref_of_op and the cond_ref_of_op. |
| 30 | * |
| 31 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 33 | acpi_ex_get_object_reference(union acpi_operand_object *obj_desc, |
| 34 | union acpi_operand_object **return_desc, |
| 35 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 37 | union acpi_operand_object *reference_obj; |
| 38 | union acpi_operand_object *referenced_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 40 | ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | *return_desc = NULL; |
| 43 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 44 | switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | case ACPI_DESC_TYPE_OPERAND: |
| 46 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 47 | if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* |
| 52 | * Must be a reference to a Local or Arg |
| 53 | */ |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 54 | switch (obj_desc->reference.class) { |
| 55 | case ACPI_REFCLASS_LOCAL: |
| 56 | case ACPI_REFCLASS_ARG: |
| 57 | case ACPI_REFCLASS_DEBUG: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* The referenced object is the pseudo-node for the local/arg */ |
| 60 | |
| 61 | referenced_obj = obj_desc->reference.object; |
| 62 | break; |
| 63 | |
| 64 | default: |
| 65 | |
Bob Moore | 395ec73 | 2015-12-29 13:55:05 +0800 | [diff] [blame] | 66 | ACPI_ERROR((AE_INFO, "Invalid Reference Class 0x%2.2X", |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 67 | obj_desc->reference.class)); |
Bob Moore | 395ec73 | 2015-12-29 13:55:05 +0800 | [diff] [blame] | 68 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | break; |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | case ACPI_DESC_TYPE_NAMED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* |
| 74 | * A named reference that has already been resolved to a Node |
| 75 | */ |
| 76 | referenced_obj = obj_desc; |
| 77 | break; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | default: |
| 80 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 81 | ACPI_ERROR((AE_INFO, "Invalid descriptor type 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 82 | ACPI_GET_DESCRIPTOR_TYPE(obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* Create a new reference object */ |
| 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | reference_obj = |
| 89 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if (!reference_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 94 | reference_obj->reference.class = ACPI_REFCLASS_REFOF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | reference_obj->reference.object = referenced_obj; |
| 96 | *return_desc = reference_obj; |
| 97 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 99 | "Object %p Type [%s], returning Reference %p\n", |
| 100 | obj_desc, acpi_ut_get_object_type_name(obj_desc), |
| 101 | *return_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /******************************************************************************* |
| 107 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * FUNCTION: acpi_ex_do_math_op |
| 109 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 110 | * PARAMETERS: opcode - AML opcode |
| 111 | * integer0 - Integer operand #0 |
| 112 | * integer1 - Integer operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * |
| 114 | * RETURN: Integer result of the operation |
| 115 | * |
| 116 | * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the |
| 117 | * math functions here is to prevent a lot of pointer dereferencing |
| 118 | * to obtain the operands. |
| 119 | * |
| 120 | ******************************************************************************/ |
| 121 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 122 | u64 acpi_ex_do_math_op(u16 opcode, u64 integer0, u64 integer1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | switch (opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | return (integer0 + integer1); |
| 131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | return (integer0 & integer1); |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | return (~(integer0 & integer1)); |
| 139 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | return (integer0 | integer1); |
| 143 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | return (~(integer0 | integer1)); |
| 147 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | return (integer0 ^ integer1); |
| 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | return (integer0 * integer1); |
| 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 158 | /* |
| 159 | * We need to check if the shiftcount is larger than the integer bit |
| 160 | * width since the behavior of this is not well-defined in the C language. |
| 161 | */ |
| 162 | if (integer1 >= acpi_gbl_integer_bit_width) { |
| 163 | return (0); |
| 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | return (integer0 << integer1); |
| 166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 169 | /* |
| 170 | * We need to check if the shiftcount is larger than the integer bit |
| 171 | * width since the behavior of this is not well-defined in the C language. |
| 172 | */ |
| 173 | if (integer1 >= acpi_gbl_integer_bit_width) { |
| 174 | return (0); |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return (integer0 >> integer1); |
| 177 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | return (integer0 - integer1); |
| 181 | |
| 182 | default: |
| 183 | |
| 184 | return (0); |
| 185 | } |
| 186 | } |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /******************************************************************************* |
| 189 | * |
| 190 | * FUNCTION: acpi_ex_do_logical_numeric_op |
| 191 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 192 | * PARAMETERS: opcode - AML opcode |
| 193 | * integer0 - Integer operand #0 |
| 194 | * integer1 - Integer operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * logical_result - TRUE/FALSE result of the operation |
| 196 | * |
| 197 | * RETURN: Status |
| 198 | * |
| 199 | * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric |
| 200 | * operators (LAnd and LOr), both operands must be integers. |
| 201 | * |
| 202 | * Note: cleanest machine code seems to be produced by the code |
| 203 | * below, rather than using statements of the form: |
| 204 | * Result = (Integer0 && Integer1); |
| 205 | * |
| 206 | ******************************************************************************/ |
| 207 | |
| 208 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | acpi_ex_do_logical_numeric_op(u16 opcode, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 210 | u64 integer0, u64 integer1, u8 *logical_result) |
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 | acpi_status status = AE_OK; |
| 213 | u8 local_result = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 215 | ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | switch (opcode) { |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 218 | case AML_LOGICAL_AND_OP: /* LAnd (Integer0, Integer1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | if (integer0 && integer1) { |
| 221 | local_result = TRUE; |
| 222 | } |
| 223 | break; |
| 224 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 225 | case AML_LOGICAL_OR_OP: /* LOr (Integer0, Integer1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | if (integer0 || integer1) { |
| 228 | local_result = TRUE; |
| 229 | } |
| 230 | break; |
| 231 | |
| 232 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 233 | |
Bob Moore | 376a588 | 2017-08-03 14:27:28 +0800 | [diff] [blame] | 234 | ACPI_ERROR((AE_INFO, |
| 235 | "Invalid numeric logical opcode: %X", opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | status = AE_AML_INTERNAL; |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | /* Return the logical result and status */ |
| 241 | |
| 242 | *logical_result = local_result; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /******************************************************************************* |
| 247 | * |
| 248 | * FUNCTION: acpi_ex_do_logical_op |
| 249 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 250 | * PARAMETERS: opcode - AML opcode |
| 251 | * operand0 - operand #0 |
| 252 | * operand1 - operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | * logical_result - TRUE/FALSE result of the operation |
| 254 | * |
| 255 | * RETURN: Status |
| 256 | * |
| 257 | * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the |
| 258 | * functions here is to prevent a lot of pointer dereferencing |
| 259 | * to obtain the operands and to simplify the generation of the |
| 260 | * logical value. For the Numeric operators (LAnd and LOr), both |
| 261 | * operands must be integers. For the other logical operators, |
| 262 | * operands can be any combination of Integer/String/Buffer. The |
| 263 | * first operand determines the type to which the second operand |
| 264 | * will be converted. |
| 265 | * |
| 266 | * Note: cleanest machine code seems to be produced by the code |
| 267 | * below, rather than using statements of the form: |
| 268 | * Result = (Operand0 == Operand1); |
| 269 | * |
| 270 | ******************************************************************************/ |
| 271 | |
| 272 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | acpi_ex_do_logical_op(u16 opcode, |
| 274 | union acpi_operand_object *operand0, |
| 275 | union acpi_operand_object *operand1, u8 * logical_result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 277 | union acpi_operand_object *local_operand1 = operand1; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 278 | u64 integer0; |
| 279 | u64 integer1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | u32 length0; |
| 281 | u32 length1; |
| 282 | acpi_status status = AE_OK; |
| 283 | u8 local_result = FALSE; |
| 284 | int compare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 286 | ACPI_FUNCTION_TRACE(ex_do_logical_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 289 | * Convert the second operand if necessary. The first operand |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | * determines the type of the second operand, (See the Data Types |
| 291 | * section of the ACPI 3.0+ specification.) Both object types are |
| 292 | * guaranteed to be either Integer/String/Buffer by the operand |
| 293 | * resolution mechanism. |
| 294 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 295 | switch (operand0->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | case ACPI_TYPE_INTEGER: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 297 | |
Bob Moore | 5ebd2ea | 2016-09-07 14:14:30 +0800 | [diff] [blame] | 298 | status = acpi_ex_convert_to_integer(operand1, &local_operand1, |
Bob Moore | fe97d28 | 2017-09-20 10:00:36 +0800 | [diff] [blame] | 299 | ACPI_IMPLICIT_CONVERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | break; |
| 301 | |
| 302 | case ACPI_TYPE_STRING: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 303 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 304 | status = |
| 305 | acpi_ex_convert_to_string(operand1, &local_operand1, |
| 306 | ACPI_IMPLICIT_CONVERT_HEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | |
| 309 | case ACPI_TYPE_BUFFER: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | status = acpi_ex_convert_to_buffer(operand1, &local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | break; |
| 313 | |
| 314 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 315 | |
Bob Moore | 376a588 | 2017-08-03 14:27:28 +0800 | [diff] [blame] | 316 | ACPI_ERROR((AE_INFO, |
| 317 | "Invalid object type for logical operator: %X", |
| 318 | operand0->common.type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | status = AE_AML_INTERNAL; |
| 320 | break; |
| 321 | } |
| 322 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | goto cleanup; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * Two cases: 1) Both Integers, 2) Both Strings or Buffers |
| 329 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 330 | if (operand0->common.type == ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* |
| 332 | * 1) Both operands are of type integer |
| 333 | * Note: local_operand1 may have changed above |
| 334 | */ |
| 335 | integer0 = operand0->integer.value; |
| 336 | integer1 = local_operand1->integer.value; |
| 337 | |
| 338 | switch (opcode) { |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 339 | case AML_LOGICAL_EQUAL_OP: /* LEqual (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | if (integer0 == integer1) { |
| 342 | local_result = TRUE; |
| 343 | } |
| 344 | break; |
| 345 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 346 | case AML_LOGICAL_GREATER_OP: /* LGreater (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | if (integer0 > integer1) { |
| 349 | local_result = TRUE; |
| 350 | } |
| 351 | break; |
| 352 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 353 | case AML_LOGICAL_LESS_OP: /* LLess (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | if (integer0 < integer1) { |
| 356 | local_result = TRUE; |
| 357 | } |
| 358 | break; |
| 359 | |
| 360 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 361 | |
Bob Moore | 376a588 | 2017-08-03 14:27:28 +0800 | [diff] [blame] | 362 | ACPI_ERROR((AE_INFO, |
| 363 | "Invalid comparison opcode: %X", opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | status = AE_AML_INTERNAL; |
| 365 | break; |
| 366 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* |
| 369 | * 2) Both operands are Strings or both are Buffers |
| 370 | * Note: Code below takes advantage of common Buffer/String |
| 371 | * object fields. local_operand1 may have changed above. Use |
| 372 | * memcmp to handle nulls in buffers. |
| 373 | */ |
| 374 | length0 = operand0->buffer.length; |
| 375 | length1 = local_operand1->buffer.length; |
| 376 | |
| 377 | /* Lexicographic compare: compare the data bytes */ |
| 378 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 379 | compare = memcmp(operand0->buffer.pointer, |
| 380 | local_operand1->buffer.pointer, |
| 381 | (length0 > length1) ? length1 : length0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | switch (opcode) { |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 384 | case AML_LOGICAL_EQUAL_OP: /* LEqual (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* Length and all bytes must be equal */ |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | if ((length0 == length1) && (compare == 0)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | /* Length and all bytes match ==> TRUE */ |
| 391 | |
| 392 | local_result = TRUE; |
| 393 | } |
| 394 | break; |
| 395 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 396 | case AML_LOGICAL_GREATER_OP: /* LGreater (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | if (compare > 0) { |
| 399 | local_result = TRUE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | goto cleanup; /* TRUE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | if (compare < 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | goto cleanup; /* FALSE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* Bytes match (to shortest length), compare lengths */ |
| 407 | |
| 408 | if (length0 > length1) { |
| 409 | local_result = TRUE; |
| 410 | } |
| 411 | break; |
| 412 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 413 | case AML_LOGICAL_LESS_OP: /* LLess (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | if (compare > 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | goto cleanup; /* FALSE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | if (compare < 0) { |
| 419 | local_result = TRUE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | goto cleanup; /* TRUE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* Bytes match (to shortest length), compare lengths */ |
| 424 | |
| 425 | if (length0 < length1) { |
| 426 | local_result = TRUE; |
| 427 | } |
| 428 | break; |
| 429 | |
| 430 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 431 | |
Bob Moore | 376a588 | 2017-08-03 14:27:28 +0800 | [diff] [blame] | 432 | ACPI_ERROR((AE_INFO, |
| 433 | "Invalid comparison opcode: %X", opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | status = AE_AML_INTERNAL; |
| 435 | break; |
| 436 | } |
| 437 | } |
| 438 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 439 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* New object was created if implicit conversion performed - delete */ |
| 442 | |
| 443 | if (local_operand1 != operand1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | acpi_ut_remove_reference(local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* Return the logical result and status */ |
| 448 | |
| 449 | *logical_result = local_result; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |