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