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 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2015, 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" |
| 48 | #include "amlresrc.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("exmisc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
| 55 | * FUNCTION: acpi_ex_get_object_reference |
| 56 | * |
| 57 | * PARAMETERS: obj_desc - Create a reference to this object |
| 58 | * return_desc - Where to store the reference |
| 59 | * walk_state - Current state |
| 60 | * |
| 61 | * RETURN: Status |
| 62 | * |
| 63 | * DESCRIPTION: Obtain and return a "reference" to the target object |
| 64 | * Common code for the ref_of_op and the cond_ref_of_op. |
| 65 | * |
| 66 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | acpi_ex_get_object_reference(union acpi_operand_object *obj_desc, |
| 69 | union acpi_operand_object **return_desc, |
| 70 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | union acpi_operand_object *reference_obj; |
| 73 | union acpi_operand_object *referenced_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 75 | ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | *return_desc = NULL; |
| 78 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | case ACPI_DESC_TYPE_OPERAND: |
| 81 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 82 | if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Must be a reference to a Local or Arg |
| 88 | */ |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 89 | switch (obj_desc->reference.class) { |
| 90 | case ACPI_REFCLASS_LOCAL: |
| 91 | case ACPI_REFCLASS_ARG: |
| 92 | case ACPI_REFCLASS_DEBUG: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* The referenced object is the pseudo-node for the local/arg */ |
| 95 | |
| 96 | referenced_obj = obj_desc->reference.object; |
| 97 | break; |
| 98 | |
| 99 | default: |
| 100 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 101 | ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X", |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 102 | obj_desc->reference.class)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | return_ACPI_STATUS(AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | break; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | case ACPI_DESC_TYPE_NAMED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* |
| 109 | * A named reference that has already been resolved to a Node |
| 110 | */ |
| 111 | referenced_obj = obj_desc; |
| 112 | break; |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | default: |
| 115 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 116 | ACPI_ERROR((AE_INFO, "Invalid descriptor type 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 117 | ACPI_GET_DESCRIPTOR_TYPE(obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /* Create a new reference object */ |
| 122 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | reference_obj = |
| 124 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (!reference_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 129 | reference_obj->reference.class = ACPI_REFCLASS_REFOF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | reference_obj->reference.object = referenced_obj; |
| 131 | *return_desc = reference_obj; |
| 132 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 134 | "Object %p Type [%s], returning Reference %p\n", |
| 135 | obj_desc, acpi_ut_get_object_type_name(obj_desc), |
| 136 | *return_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /******************************************************************************* |
| 142 | * |
| 143 | * FUNCTION: acpi_ex_concat_template |
| 144 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 145 | * PARAMETERS: operand0 - First source object |
| 146 | * operand1 - Second source object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | * actual_return_desc - Where to place the return object |
| 148 | * walk_state - Current walk state |
| 149 | * |
| 150 | * RETURN: Status |
| 151 | * |
| 152 | * DESCRIPTION: Concatenate two resource templates |
| 153 | * |
| 154 | ******************************************************************************/ |
| 155 | |
| 156 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | acpi_ex_concat_template(union acpi_operand_object *operand0, |
| 158 | union acpi_operand_object *operand1, |
| 159 | union acpi_operand_object **actual_return_desc, |
| 160 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 162 | acpi_status status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | union acpi_operand_object *return_desc; |
| 164 | u8 *new_buf; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 165 | u8 *end_tag; |
| 166 | acpi_size length0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | acpi_size length1; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 168 | acpi_size new_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 170 | ACPI_FUNCTION_TRACE(ex_concat_template); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 172 | /* |
| 173 | * Find the end_tag descriptor in each resource template. |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 174 | * Note1: returned pointers point TO the end_tag, not past it. |
| 175 | * Note2: zero-length buffers are allowed; treated like one end_tag |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 176 | */ |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 177 | |
| 178 | /* Get the length of the first resource template */ |
| 179 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 180 | status = acpi_ut_get_resource_end_tag(operand0, &end_tag); |
| 181 | if (ACPI_FAILURE(status)) { |
| 182 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 185 | length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 187 | /* Get the length of the second resource template */ |
| 188 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 189 | status = acpi_ut_get_resource_end_tag(operand1, &end_tag); |
| 190 | if (ACPI_FAILURE(status)) { |
| 191 | return_ACPI_STATUS(status); |
| 192 | } |
| 193 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 194 | length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 195 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 196 | /* Combine both lengths, minimum size will be 2 for end_tag */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 198 | new_length = length0 + length1 + sizeof(struct aml_resource_end_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 200 | /* Create a new buffer object for the result (with one end_tag) */ |
| 201 | |
| 202 | return_desc = acpi_ut_create_buffer_object(new_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (!return_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 207 | /* |
| 208 | * Copy the templates to the new buffer, 0 first, then 1 follows. One |
| 209 | * end_tag descriptor is copied from Operand1. |
| 210 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | new_buf = return_desc->buffer.pointer; |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 212 | memcpy(new_buf, operand0->buffer.pointer, length0); |
| 213 | memcpy(new_buf + length0, operand1->buffer.pointer, length1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 215 | /* Insert end_tag and set the checksum to zero, means "ignore checksum" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 217 | new_buf[new_length - 1] = 0; |
| 218 | new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 220 | /* Return the completed resource template */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | *actual_return_desc = return_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | /******************************************************************************* |
| 227 | * |
| 228 | * FUNCTION: acpi_ex_do_concatenate |
| 229 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 230 | * PARAMETERS: operand0 - First source object |
| 231 | * operand1 - Second source object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * actual_return_desc - Where to place the return object |
| 233 | * walk_state - Current walk state |
| 234 | * |
| 235 | * RETURN: Status |
| 236 | * |
| 237 | * DESCRIPTION: Concatenate two objects OF THE SAME TYPE. |
| 238 | * |
| 239 | ******************************************************************************/ |
| 240 | |
| 241 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | acpi_ex_do_concatenate(union acpi_operand_object *operand0, |
| 243 | union acpi_operand_object *operand1, |
| 244 | union acpi_operand_object **actual_return_desc, |
| 245 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | union acpi_operand_object *local_operand1 = operand1; |
| 248 | union acpi_operand_object *return_desc; |
| 249 | char *new_buf; |
| 250 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 252 | ACPI_FUNCTION_TRACE(ex_do_concatenate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | /* |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 255 | * Convert the second operand if necessary. The first operand |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | * determines the type of the second operand, (See the Data Types |
| 257 | * section of the ACPI specification.) Both object types are |
| 258 | * guaranteed to be either Integer/String/Buffer by the operand |
| 259 | * resolution mechanism. |
| 260 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 261 | switch (operand0->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | case ACPI_TYPE_INTEGER: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | status = |
| 265 | acpi_ex_convert_to_integer(operand1, &local_operand1, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | break; |
| 267 | |
| 268 | case ACPI_TYPE_STRING: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 269 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | status = acpi_ex_convert_to_string(operand1, &local_operand1, |
| 271 | ACPI_IMPLICIT_CONVERT_HEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | break; |
| 273 | |
| 274 | case ACPI_TYPE_BUFFER: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 275 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | status = acpi_ex_convert_to_buffer(operand1, &local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 280 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 281 | ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X", |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 282 | operand0->common.type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | status = AE_AML_INTERNAL; |
| 284 | } |
| 285 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | goto cleanup; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Both operands are now known to be the same object type |
| 292 | * (Both are Integer, String, or Buffer), and we can now perform the |
| 293 | * concatenation. |
| 294 | */ |
| 295 | |
| 296 | /* |
| 297 | * There are three cases to handle: |
| 298 | * |
| 299 | * 1) Two Integers concatenated to produce a new Buffer |
| 300 | * 2) Two Strings concatenated to produce a new String |
| 301 | * 3) Two Buffers concatenated to produce a new Buffer |
| 302 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 303 | switch (operand0->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | case ACPI_TYPE_INTEGER: |
| 305 | |
| 306 | /* Result of two Integers is a Buffer */ |
| 307 | /* Need enough buffer space for two integers */ |
| 308 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | return_desc = acpi_ut_create_buffer_object((acpi_size) |
| 310 | ACPI_MUL_2 |
| 311 | (acpi_gbl_integer_byte_width)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (!return_desc) { |
| 313 | status = AE_NO_MEMORY; |
| 314 | goto cleanup; |
| 315 | } |
| 316 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | new_buf = (char *)return_desc->buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | /* Copy the first integer, LSB first */ |
| 320 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 321 | memcpy(new_buf, &operand0->integer.value, |
| 322 | acpi_gbl_integer_byte_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* Copy the second integer (LSB first) after the first */ |
| 325 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 326 | memcpy(new_buf + acpi_gbl_integer_byte_width, |
| 327 | &local_operand1->integer.value, |
| 328 | acpi_gbl_integer_byte_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | break; |
| 330 | |
| 331 | case ACPI_TYPE_STRING: |
| 332 | |
| 333 | /* Result of two Strings is a String */ |
| 334 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 335 | return_desc = acpi_ut_create_string_object(((acpi_size) |
| 336 | operand0->string. |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 337 | length + |
| 338 | local_operand1-> |
| 339 | string.length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | if (!return_desc) { |
| 341 | status = AE_NO_MEMORY; |
| 342 | goto cleanup; |
| 343 | } |
| 344 | |
| 345 | new_buf = return_desc->string.pointer; |
| 346 | |
| 347 | /* Concatenate the strings */ |
| 348 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 349 | strcpy(new_buf, operand0->string.pointer); |
| 350 | strcpy(new_buf + operand0->string.length, |
| 351 | local_operand1->string.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | break; |
| 353 | |
| 354 | case ACPI_TYPE_BUFFER: |
| 355 | |
| 356 | /* Result of two Buffers is a Buffer */ |
| 357 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 358 | return_desc = acpi_ut_create_buffer_object(((acpi_size) |
| 359 | operand0->buffer. |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 360 | length + |
| 361 | local_operand1-> |
| 362 | buffer.length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (!return_desc) { |
| 364 | status = AE_NO_MEMORY; |
| 365 | goto cleanup; |
| 366 | } |
| 367 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | new_buf = (char *)return_desc->buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | /* Concatenate the buffers */ |
| 371 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 372 | memcpy(new_buf, operand0->buffer.pointer, |
| 373 | operand0->buffer.length); |
| 374 | memcpy(new_buf + operand0->buffer.length, |
| 375 | local_operand1->buffer.pointer, |
| 376 | local_operand1->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | break; |
| 378 | |
| 379 | default: |
| 380 | |
| 381 | /* Invalid object type, should not happen here */ |
| 382 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 383 | ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X", |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 384 | operand0->common.type)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | status = AE_AML_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | goto cleanup; |
| 387 | } |
| 388 | |
| 389 | *actual_return_desc = return_desc; |
| 390 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 391 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (local_operand1 != operand1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | acpi_ut_remove_reference(local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /******************************************************************************* |
| 399 | * |
| 400 | * FUNCTION: acpi_ex_do_math_op |
| 401 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 402 | * PARAMETERS: opcode - AML opcode |
| 403 | * integer0 - Integer operand #0 |
| 404 | * integer1 - Integer operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | * |
| 406 | * RETURN: Integer result of the operation |
| 407 | * |
| 408 | * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the |
| 409 | * math functions here is to prevent a lot of pointer dereferencing |
| 410 | * to obtain the operands. |
| 411 | * |
| 412 | ******************************************************************************/ |
| 413 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 414 | u64 acpi_ex_do_math_op(u16 opcode, u64 integer0, u64 integer1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | switch (opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | return (integer0 + integer1); |
| 423 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | return (integer0 & integer1); |
| 427 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | return (~(integer0 & integer1)); |
| 431 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | return (integer0 | integer1); |
| 435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | return (~(integer0 | integer1)); |
| 439 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | return (integer0 ^ integer1); |
| 443 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | return (integer0 * integer1); |
| 447 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 450 | /* |
| 451 | * We need to check if the shiftcount is larger than the integer bit |
| 452 | * width since the behavior of this is not well-defined in the C language. |
| 453 | */ |
| 454 | if (integer1 >= acpi_gbl_integer_bit_width) { |
| 455 | return (0); |
| 456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return (integer0 << integer1); |
| 458 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 459 | case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 461 | /* |
| 462 | * We need to check if the shiftcount is larger than the integer bit |
| 463 | * width since the behavior of this is not well-defined in the C language. |
| 464 | */ |
| 465 | if (integer1 >= acpi_gbl_integer_bit_width) { |
| 466 | return (0); |
| 467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return (integer0 >> integer1); |
| 469 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 470 | case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | return (integer0 - integer1); |
| 473 | |
| 474 | default: |
| 475 | |
| 476 | return (0); |
| 477 | } |
| 478 | } |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | /******************************************************************************* |
| 481 | * |
| 482 | * FUNCTION: acpi_ex_do_logical_numeric_op |
| 483 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 484 | * PARAMETERS: opcode - AML opcode |
| 485 | * integer0 - Integer operand #0 |
| 486 | * integer1 - Integer operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | * logical_result - TRUE/FALSE result of the operation |
| 488 | * |
| 489 | * RETURN: Status |
| 490 | * |
| 491 | * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric |
| 492 | * operators (LAnd and LOr), both operands must be integers. |
| 493 | * |
| 494 | * Note: cleanest machine code seems to be produced by the code |
| 495 | * below, rather than using statements of the form: |
| 496 | * Result = (Integer0 && Integer1); |
| 497 | * |
| 498 | ******************************************************************************/ |
| 499 | |
| 500 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | acpi_ex_do_logical_numeric_op(u16 opcode, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 502 | u64 integer0, u64 integer1, u8 *logical_result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | acpi_status status = AE_OK; |
| 505 | u8 local_result = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 507 | ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | switch (opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | case AML_LAND_OP: /* LAnd (Integer0, Integer1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | if (integer0 && integer1) { |
| 513 | local_result = TRUE; |
| 514 | } |
| 515 | break; |
| 516 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | case AML_LOR_OP: /* LOr (Integer0, Integer1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | if (integer0 || integer1) { |
| 520 | local_result = TRUE; |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | status = AE_AML_INTERNAL; |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | /* Return the logical result and status */ |
| 531 | |
| 532 | *logical_result = local_result; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 533 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | /******************************************************************************* |
| 537 | * |
| 538 | * FUNCTION: acpi_ex_do_logical_op |
| 539 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 540 | * PARAMETERS: opcode - AML opcode |
| 541 | * operand0 - operand #0 |
| 542 | * operand1 - operand #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * logical_result - TRUE/FALSE result of the operation |
| 544 | * |
| 545 | * RETURN: Status |
| 546 | * |
| 547 | * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the |
| 548 | * functions here is to prevent a lot of pointer dereferencing |
| 549 | * to obtain the operands and to simplify the generation of the |
| 550 | * logical value. For the Numeric operators (LAnd and LOr), both |
| 551 | * operands must be integers. For the other logical operators, |
| 552 | * operands can be any combination of Integer/String/Buffer. The |
| 553 | * first operand determines the type to which the second operand |
| 554 | * will be converted. |
| 555 | * |
| 556 | * Note: cleanest machine code seems to be produced by the code |
| 557 | * below, rather than using statements of the form: |
| 558 | * Result = (Operand0 == Operand1); |
| 559 | * |
| 560 | ******************************************************************************/ |
| 561 | |
| 562 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | acpi_ex_do_logical_op(u16 opcode, |
| 564 | union acpi_operand_object *operand0, |
| 565 | union acpi_operand_object *operand1, u8 * logical_result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | union acpi_operand_object *local_operand1 = operand1; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 568 | u64 integer0; |
| 569 | u64 integer1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | u32 length0; |
| 571 | u32 length1; |
| 572 | acpi_status status = AE_OK; |
| 573 | u8 local_result = FALSE; |
| 574 | int compare; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 576 | ACPI_FUNCTION_TRACE(ex_do_logical_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | /* |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 579 | * Convert the second operand if necessary. The first operand |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | * determines the type of the second operand, (See the Data Types |
| 581 | * section of the ACPI 3.0+ specification.) Both object types are |
| 582 | * guaranteed to be either Integer/String/Buffer by the operand |
| 583 | * resolution mechanism. |
| 584 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 585 | switch (operand0->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | case ACPI_TYPE_INTEGER: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 587 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 588 | status = |
| 589 | acpi_ex_convert_to_integer(operand1, &local_operand1, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | break; |
| 591 | |
| 592 | case ACPI_TYPE_STRING: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 593 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | status = acpi_ex_convert_to_string(operand1, &local_operand1, |
| 595 | ACPI_IMPLICIT_CONVERT_HEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
| 598 | case ACPI_TYPE_BUFFER: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 599 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 600 | status = acpi_ex_convert_to_buffer(operand1, &local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | status = AE_AML_INTERNAL; |
| 606 | break; |
| 607 | } |
| 608 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 609 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | goto cleanup; |
| 611 | } |
| 612 | |
| 613 | /* |
| 614 | * Two cases: 1) Both Integers, 2) Both Strings or Buffers |
| 615 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 616 | if (operand0->common.type == ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* |
| 618 | * 1) Both operands are of type integer |
| 619 | * Note: local_operand1 may have changed above |
| 620 | */ |
| 621 | integer0 = operand0->integer.value; |
| 622 | integer1 = local_operand1->integer.value; |
| 623 | |
| 624 | switch (opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | if (integer0 == integer1) { |
| 628 | local_result = TRUE; |
| 629 | } |
| 630 | break; |
| 631 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | if (integer0 > integer1) { |
| 635 | local_result = TRUE; |
| 636 | } |
| 637 | break; |
| 638 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | case AML_LLESS_OP: /* LLess (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | if (integer0 < integer1) { |
| 642 | local_result = TRUE; |
| 643 | } |
| 644 | break; |
| 645 | |
| 646 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | status = AE_AML_INTERNAL; |
| 649 | break; |
| 650 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | /* |
| 653 | * 2) Both operands are Strings or both are Buffers |
| 654 | * Note: Code below takes advantage of common Buffer/String |
| 655 | * object fields. local_operand1 may have changed above. Use |
| 656 | * memcmp to handle nulls in buffers. |
| 657 | */ |
| 658 | length0 = operand0->buffer.length; |
| 659 | length1 = local_operand1->buffer.length; |
| 660 | |
| 661 | /* Lexicographic compare: compare the data bytes */ |
| 662 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 663 | compare = memcmp(operand0->buffer.pointer, |
| 664 | local_operand1->buffer.pointer, |
| 665 | (length0 > length1) ? length1 : length0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | switch (opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 668 | case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | /* Length and all bytes must be equal */ |
| 671 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | if ((length0 == length1) && (compare == 0)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | /* Length and all bytes match ==> TRUE */ |
| 675 | |
| 676 | local_result = TRUE; |
| 677 | } |
| 678 | break; |
| 679 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | if (compare > 0) { |
| 683 | local_result = TRUE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 684 | goto cleanup; /* TRUE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | if (compare < 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 687 | goto cleanup; /* FALSE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /* Bytes match (to shortest length), compare lengths */ |
| 691 | |
| 692 | if (length0 > length1) { |
| 693 | local_result = TRUE; |
| 694 | } |
| 695 | break; |
| 696 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | case AML_LLESS_OP: /* LLess (Operand0, Operand1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | if (compare > 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 700 | goto cleanup; /* FALSE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | if (compare < 0) { |
| 703 | local_result = TRUE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 704 | goto cleanup; /* TRUE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | /* Bytes match (to shortest length), compare lengths */ |
| 708 | |
| 709 | if (length0 < length1) { |
| 710 | local_result = TRUE; |
| 711 | } |
| 712 | break; |
| 713 | |
| 714 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | status = AE_AML_INTERNAL; |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 721 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | /* New object was created if implicit conversion performed - delete */ |
| 724 | |
| 725 | if (local_operand1 != operand1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 726 | acpi_ut_remove_reference(local_operand1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /* Return the logical result and status */ |
| 730 | |
| 731 | *logical_result = local_result; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |