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