Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exoparg1 - AML execution - opcodes with 1 argument |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acparser.h> |
| 47 | #include <acpi/acdispat.h> |
| 48 | #include <acpi/acinterp.h> |
| 49 | #include <acpi/amlcode.h> |
| 50 | #include <acpi/acnamesp.h> |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | ACPI_MODULE_NAME("exoparg1") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /*! |
| 56 | * Naming convention for AML interpreter execution routines. |
| 57 | * |
| 58 | * The routines that begin execution of AML opcodes are named with a common |
| 59 | * convention based upon the number of arguments, the number of target operands, |
| 60 | * and whether or not a value is returned: |
| 61 | * |
| 62 | * AcpiExOpcode_xA_yT_zR |
| 63 | * |
| 64 | * Where: |
| 65 | * |
| 66 | * xA - ARGUMENTS: The number of arguments (input operands) that are |
| 67 | * required for this opcode type (0 through 6 args). |
| 68 | * yT - TARGETS: The number of targets (output operands) that are required |
| 69 | * for this opcode type (0, 1, or 2 targets). |
| 70 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value |
| 71 | * as the function return (0 or 1). |
| 72 | * |
| 73 | * The AcpiExOpcode* functions are called via the Dispatcher component with |
| 74 | * fully resolved operands. |
| 75 | !*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /******************************************************************************* |
| 77 | * |
| 78 | * FUNCTION: acpi_ex_opcode_0A_0T_1R |
| 79 | * |
| 80 | * PARAMETERS: walk_state - Current state (contains AML opcode) |
| 81 | * |
| 82 | * RETURN: Status |
| 83 | * |
| 84 | * DESCRIPTION: Execute operator with no operands, one return value |
| 85 | * |
| 86 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | acpi_status status = AE_OK; |
| 90 | union acpi_operand_object *return_desc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | ACPI_FUNCTION_TRACE_STR("ex_opcode_0A_0T_1R", |
| 93 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* Examine the AML opcode */ |
| 96 | |
| 97 | switch (walk_state->opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | case AML_TIMER_OP: /* Timer () */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* Create a return object of type Integer */ |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if (!return_desc) { |
| 104 | status = AE_NO_MEMORY; |
| 105 | goto cleanup; |
| 106 | } |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 107 | #if ACPI_MACHINE_WIDTH != 16 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | return_desc->integer.value = acpi_os_get_timer(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 109 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | break; |
| 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | default: /* Unknown opcode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 114 | ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", |
| 115 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | status = AE_AML_BAD_OPCODE; |
| 117 | break; |
| 118 | } |
| 119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* Delete return object on error */ |
| 123 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | if ((ACPI_FAILURE(status)) || walk_state->result_obj) { |
| 125 | acpi_ut_remove_reference(return_desc); |
| 126 | } else { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 127 | /* Save the return value */ |
| 128 | |
| 129 | walk_state->result_obj = return_desc; |
| 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /******************************************************************************* |
| 136 | * |
| 137 | * FUNCTION: acpi_ex_opcode_1A_0T_0R |
| 138 | * |
| 139 | * PARAMETERS: walk_state - Current state (contains AML opcode) |
| 140 | * |
| 141 | * RETURN: Status |
| 142 | * |
| 143 | * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on |
| 144 | * object stack |
| 145 | * |
| 146 | ******************************************************************************/ |
| 147 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 151 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_0R", |
| 154 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* Examine the AML opcode */ |
| 157 | |
| 158 | switch (walk_state->opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | case AML_RELEASE_OP: /* Release (mutex_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | status = acpi_ex_release_mutex(operand[0], walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | case AML_RESET_OP: /* Reset (event_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | status = acpi_ex_system_reset_event(operand[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | break; |
| 168 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | case AML_SIGNAL_OP: /* Signal (event_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | status = acpi_ex_system_signal_event(operand[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | break; |
| 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | case AML_SLEEP_OP: /* Sleep (msec_time) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | status = acpi_ex_system_do_suspend(operand[0]->integer.value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | break; |
| 178 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | case AML_STALL_OP: /* Stall (usec_time) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | status = |
| 182 | acpi_ex_system_do_stall((u32) operand[0]->integer.value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | break; |
| 184 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | case AML_UNLOAD_OP: /* Unload (Handle) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | status = acpi_ex_unload_table(operand[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | break; |
| 189 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | default: /* Unknown opcode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 192 | ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", |
| 193 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | status = AE_AML_BAD_OPCODE; |
| 195 | break; |
| 196 | } |
| 197 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /******************************************************************************* |
| 202 | * |
| 203 | * FUNCTION: acpi_ex_opcode_1A_1T_0R |
| 204 | * |
| 205 | * PARAMETERS: walk_state - Current state (contains AML opcode) |
| 206 | * |
| 207 | * RETURN: Status |
| 208 | * |
| 209 | * DESCRIPTION: Execute opcode with one argument, one target, and no |
| 210 | * return value. |
| 211 | * |
| 212 | ******************************************************************************/ |
| 213 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | acpi_status status = AE_OK; |
| 217 | union acpi_operand_object **operand = &walk_state->operands[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_1T_0R", |
| 220 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* Examine the AML opcode */ |
| 223 | |
| 224 | switch (walk_state->opcode) { |
| 225 | case AML_LOAD_OP: |
| 226 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | status = acpi_ex_load_op(operand[0], operand[1], walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | break; |
| 229 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | default: /* Unknown opcode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 232 | ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", |
| 233 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | status = AE_AML_BAD_OPCODE; |
| 235 | goto cleanup; |
| 236 | } |
| 237 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /******************************************************************************* |
| 244 | * |
| 245 | * FUNCTION: acpi_ex_opcode_1A_1T_1R |
| 246 | * |
| 247 | * PARAMETERS: walk_state - Current state (contains AML opcode) |
| 248 | * |
| 249 | * RETURN: Status |
| 250 | * |
| 251 | * DESCRIPTION: Execute opcode with one argument, one target, and a |
| 252 | * return value. |
| 253 | * |
| 254 | ******************************************************************************/ |
| 255 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | acpi_status status = AE_OK; |
| 259 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 260 | union acpi_operand_object *return_desc = NULL; |
| 261 | union acpi_operand_object *return_desc2 = NULL; |
| 262 | u32 temp32; |
| 263 | u32 i; |
| 264 | acpi_integer power_of_ten; |
| 265 | acpi_integer digit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_1T_1R", |
| 268 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | /* Examine the AML opcode */ |
| 271 | |
| 272 | switch (walk_state->opcode) { |
| 273 | case AML_BIT_NOT_OP: |
| 274 | case AML_FIND_SET_LEFT_BIT_OP: |
| 275 | case AML_FIND_SET_RIGHT_BIT_OP: |
| 276 | case AML_FROM_BCD_OP: |
| 277 | case AML_TO_BCD_OP: |
| 278 | case AML_COND_REF_OF_OP: |
| 279 | |
| 280 | /* Create a return object of type Integer for these opcodes */ |
| 281 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (!return_desc) { |
| 284 | status = AE_NO_MEMORY; |
| 285 | goto cleanup; |
| 286 | } |
| 287 | |
| 288 | switch (walk_state->opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | case AML_BIT_NOT_OP: /* Not (Operand, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | return_desc->integer.value = ~operand[0]->integer.value; |
| 292 | break; |
| 293 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | case AML_FIND_SET_LEFT_BIT_OP: /* find_set_left_bit (Operand, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | return_desc->integer.value = operand[0]->integer.value; |
| 297 | |
| 298 | /* |
| 299 | * Acpi specification describes Integer type as a little |
| 300 | * endian unsigned value, so this boundary condition is valid. |
| 301 | */ |
| 302 | for (temp32 = 0; return_desc->integer.value && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return_desc->integer.value >>= 1; |
| 305 | } |
| 306 | |
| 307 | return_desc->integer.value = temp32; |
| 308 | break; |
| 309 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | return_desc->integer.value = operand[0]->integer.value; |
| 313 | |
| 314 | /* |
| 315 | * The Acpi specification describes Integer type as a little |
| 316 | * endian unsigned value, so this boundary condition is valid. |
| 317 | */ |
| 318 | for (temp32 = 0; return_desc->integer.value && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return_desc->integer.value <<= 1; |
| 321 | } |
| 322 | |
| 323 | /* Since the bit position is one-based, subtract from 33 (65) */ |
| 324 | |
| 325 | return_desc->integer.value = temp32 == 0 ? 0 : |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | (ACPI_INTEGER_BIT_SIZE + 1) - temp32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
| 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* |
| 332 | * The 64-bit ACPI integer can hold 16 4-bit BCD characters |
| 333 | * (if table is 32-bit, integer can hold 8 BCD characters) |
| 334 | * Convert each 4-bit BCD value |
| 335 | */ |
| 336 | power_of_ten = 1; |
| 337 | return_desc->integer.value = 0; |
| 338 | digit = operand[0]->integer.value; |
| 339 | |
| 340 | /* Convert each BCD digit (each is one nybble wide) */ |
| 341 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | for (i = 0; |
| 343 | (i < acpi_gbl_integer_nybble_width) && (digit > 0); |
| 344 | i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | /* Get the least significant 4-bit BCD digit */ |
| 346 | |
| 347 | temp32 = ((u32) digit) & 0xF; |
| 348 | |
| 349 | /* Check the range of the digit */ |
| 350 | |
| 351 | if (temp32 > 9) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 352 | ACPI_REPORT_ERROR(("BCD digit too large (not decimal): 0x%X\n", temp32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | status = AE_AML_NUMERIC_OVERFLOW; |
| 355 | goto cleanup; |
| 356 | } |
| 357 | |
| 358 | /* Sum the digit into the result with the current power of 10 */ |
| 359 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | return_desc->integer.value += |
| 361 | (((acpi_integer) temp32) * power_of_ten); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* Shift to next BCD digit */ |
| 364 | |
| 365 | digit >>= 4; |
| 366 | |
| 367 | /* Next power of 10 */ |
| 368 | |
| 369 | power_of_ten *= 10; |
| 370 | } |
| 371 | break; |
| 372 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
| 375 | return_desc->integer.value = 0; |
| 376 | digit = operand[0]->integer.value; |
| 377 | |
| 378 | /* Each BCD digit is one nybble wide */ |
| 379 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 380 | for (i = 0; |
| 381 | (i < acpi_gbl_integer_nybble_width) && (digit > 0); |
| 382 | i++) { |
| 383 | (void)acpi_ut_short_divide(digit, 10, &digit, |
| 384 | &temp32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 386 | /* |
| 387 | * Insert the BCD digit that resides in the |
| 388 | * remainder from above |
| 389 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | return_desc->integer.value |= |
| 391 | (((acpi_integer) temp32) << ACPI_MUL_4(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* Overflow if there is any data left in Digit */ |
| 395 | |
| 396 | if (digit > 0) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 397 | ACPI_REPORT_ERROR(("Integer too large to convert to BCD: %8.8X%8.8X\n", ACPI_FORMAT_UINT64(operand[0]->integer.value))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | status = AE_AML_NUMERIC_OVERFLOW; |
| 399 | goto cleanup; |
| 400 | } |
| 401 | break; |
| 402 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * This op is a little strange because the internal return value is |
| 407 | * different than the return value stored in the result descriptor |
| 408 | * (There are really two return values) |
| 409 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | if ((struct acpi_namespace_node *)operand[0] == |
| 411 | acpi_gbl_root_node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | /* |
| 413 | * This means that the object does not exist in the namespace, |
| 414 | * return FALSE |
| 415 | */ |
| 416 | return_desc->integer.value = 0; |
| 417 | goto cleanup; |
| 418 | } |
| 419 | |
| 420 | /* Get the object reference, store it, and remove our reference */ |
| 421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | status = acpi_ex_get_object_reference(operand[0], |
| 423 | &return_desc2, |
| 424 | walk_state); |
| 425 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | goto cleanup; |
| 427 | } |
| 428 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | status = |
| 430 | acpi_ex_store(return_desc2, operand[1], walk_state); |
| 431 | acpi_ut_remove_reference(return_desc2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | /* The object exists in the namespace, return TRUE */ |
| 434 | |
| 435 | return_desc->integer.value = ACPI_INTEGER_MAX; |
| 436 | goto cleanup; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | default: |
| 439 | /* No other opcodes get here */ |
| 440 | break; |
| 441 | } |
| 442 | break; |
| 443 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | case AML_STORE_OP: /* Store (Source, Target) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * A store operand is typically a number, string, buffer or lvalue |
| 448 | * Be careful about deleting the source object, |
| 449 | * since the object itself may have been stored. |
| 450 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | status = acpi_ex_store(operand[0], operand[1], walk_state); |
| 452 | if (ACPI_FAILURE(status)) { |
| 453 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* It is possible that the Store already produced a return object */ |
| 457 | |
| 458 | if (!walk_state->result_obj) { |
| 459 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 460 | * Normally, we would remove a reference on the Operand[0] |
| 461 | * parameter; But since it is being used as the internal return |
| 462 | * object (meaning we would normally increment it), the two |
| 463 | * cancel out, and we simply don't do anything. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | */ |
| 465 | walk_state->result_obj = operand[0]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | walk_state->operands[0] = NULL; /* Prevent deletion */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 470 | /* |
| 471 | * ACPI 2.0 Opcodes |
| 472 | */ |
| 473 | case AML_COPY_OP: /* Copy (Source, Target) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | status = |
| 476 | acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc, |
| 477 | walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | break; |
| 479 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | case AML_TO_DECSTRING_OP: /* to_decimal_string (Data, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | status = acpi_ex_convert_to_string(operand[0], &return_desc, |
| 483 | ACPI_EXPLICIT_CONVERT_DECIMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (return_desc == operand[0]) { |
| 485 | /* No conversion performed, add ref to handle return value */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | acpi_ut_add_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | break; |
| 489 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | case AML_TO_HEXSTRING_OP: /* to_hex_string (Data, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | status = acpi_ex_convert_to_string(operand[0], &return_desc, |
| 493 | ACPI_EXPLICIT_CONVERT_HEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (return_desc == operand[0]) { |
| 495 | /* No conversion performed, add ref to handle return value */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | acpi_ut_add_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | break; |
| 499 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | case AML_TO_BUFFER_OP: /* to_buffer (Data, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | status = acpi_ex_convert_to_buffer(operand[0], &return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (return_desc == operand[0]) { |
| 504 | /* No conversion performed, add ref to handle return value */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | acpi_ut_add_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | break; |
| 508 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | status = acpi_ex_convert_to_integer(operand[0], &return_desc, |
| 512 | ACPI_ANY_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (return_desc == operand[0]) { |
| 514 | /* No conversion performed, add ref to handle return value */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | acpi_ut_add_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | break; |
| 518 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 519 | case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */ |
| 520 | case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 522 | /* These are two obsolete opcodes */ |
| 523 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 524 | ACPI_REPORT_ERROR(("%s is obsolete and not implemented\n", |
| 525 | acpi_ps_get_opcode_name(walk_state-> |
| 526 | opcode))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | status = AE_SUPPORT; |
| 528 | goto cleanup; |
| 529 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 530 | default: /* Unknown opcode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 532 | ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", |
| 533 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | status = AE_AML_BAD_OPCODE; |
| 535 | goto cleanup; |
| 536 | } |
| 537 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 538 | if (ACPI_SUCCESS(status)) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 539 | /* Store the return value computed above into the target object */ |
| 540 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 541 | status = acpi_ex_store(return_desc, operand[1], walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 544 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | if (!walk_state->result_obj) { |
| 547 | walk_state->result_obj = return_desc; |
| 548 | } |
| 549 | |
| 550 | /* Delete return object on error */ |
| 551 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | if (ACPI_FAILURE(status)) { |
| 553 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 556 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | /******************************************************************************* |
| 560 | * |
| 561 | * FUNCTION: acpi_ex_opcode_1A_0T_1R |
| 562 | * |
| 563 | * PARAMETERS: walk_state - Current state (contains AML opcode) |
| 564 | * |
| 565 | * RETURN: Status |
| 566 | * |
| 567 | * DESCRIPTION: Execute opcode with one argument, no target, and a return value |
| 568 | * |
| 569 | ******************************************************************************/ |
| 570 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | union acpi_operand_object **operand = &walk_state->operands[0]; |
| 574 | union acpi_operand_object *temp_desc; |
| 575 | union acpi_operand_object *return_desc = NULL; |
| 576 | acpi_status status = AE_OK; |
| 577 | u32 type; |
| 578 | acpi_integer value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 580 | ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_1R", |
| 581 | acpi_ps_get_opcode_name(walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | /* Examine the AML opcode */ |
| 584 | |
| 585 | switch (walk_state->opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | case AML_LNOT_OP: /* LNot (Operand) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 588 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (!return_desc) { |
| 590 | status = AE_NO_MEMORY; |
| 591 | goto cleanup; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Set result to ONES (TRUE) if Value == 0. Note: |
| 596 | * return_desc->Integer.Value is initially == 0 (FALSE) from above. |
| 597 | */ |
| 598 | if (!operand[0]->integer.value) { |
| 599 | return_desc->integer.value = ACPI_INTEGER_MAX; |
| 600 | } |
| 601 | break; |
| 602 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | case AML_DECREMENT_OP: /* Decrement (Operand) */ |
| 604 | case AML_INCREMENT_OP: /* Increment (Operand) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | /* |
| 607 | * Create a new integer. Can't just get the base integer and |
| 608 | * increment it because it may be an Arg or Field. |
| 609 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | if (!return_desc) { |
| 612 | status = AE_NO_MEMORY; |
| 613 | goto cleanup; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Since we are expecting a Reference operand, it can be either a |
| 618 | * NS Node or an internal object. |
| 619 | */ |
| 620 | temp_desc = operand[0]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) == |
| 622 | ACPI_DESC_TYPE_OPERAND) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | /* Internal reference object - prevent deletion */ |
| 624 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | acpi_ut_add_reference(temp_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* |
| 629 | * Convert the Reference operand to an Integer (This removes a |
| 630 | * reference on the Operand[0] object) |
| 631 | * |
| 632 | * NOTE: We use LNOT_OP here in order to force resolution of the |
| 633 | * reference operand to an actual integer. |
| 634 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | status = |
| 636 | acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc, |
| 637 | walk_state); |
| 638 | if (ACPI_FAILURE(status)) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 639 | ACPI_REPORT_ERROR(("%s: bad operand(s) %s\n", |
| 640 | acpi_ps_get_opcode_name(walk_state-> |
| 641 | opcode), |
| 642 | acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | goto cleanup; |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * temp_desc is now guaranteed to be an Integer object -- |
| 649 | * Perform the actual increment or decrement |
| 650 | */ |
| 651 | if (walk_state->opcode == AML_INCREMENT_OP) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 652 | return_desc->integer.value = |
| 653 | temp_desc->integer.value + 1; |
| 654 | } else { |
| 655 | return_desc->integer.value = |
| 656 | temp_desc->integer.value - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /* Finished with this Integer object */ |
| 660 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | acpi_ut_remove_reference(temp_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Store the result back (indirectly) through the original |
| 665 | * Reference object |
| 666 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 667 | status = acpi_ex_store(return_desc, operand[0], walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | break; |
| 669 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 670 | case AML_TYPE_OP: /* object_type (source_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | /* |
| 673 | * Note: The operand is not resolved at this point because we want to |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 674 | * get the associated object, not its value. For example, we don't |
| 675 | * want to resolve a field_unit to its value, we want the actual |
| 676 | * field_unit object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | */ |
| 678 | |
| 679 | /* Get the type of the base object */ |
| 680 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | status = |
| 682 | acpi_ex_resolve_multiple(walk_state, operand[0], &type, |
| 683 | NULL); |
| 684 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | goto cleanup; |
| 686 | } |
| 687 | /* Allocate a descriptor to hold the type. */ |
| 688 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 689 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | if (!return_desc) { |
| 691 | status = AE_NO_MEMORY; |
| 692 | goto cleanup; |
| 693 | } |
| 694 | |
| 695 | return_desc->integer.value = type; |
| 696 | break; |
| 697 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | case AML_SIZE_OF_OP: /* size_of (source_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | /* |
| 701 | * Note: The operand is not resolved at this point because we want to |
| 702 | * get the associated object, not its value. |
| 703 | */ |
| 704 | |
| 705 | /* Get the base object */ |
| 706 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 707 | status = acpi_ex_resolve_multiple(walk_state, |
| 708 | operand[0], &type, |
| 709 | &temp_desc); |
| 710 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | goto cleanup; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * The type of the base object must be integer, buffer, string, or |
| 716 | * package. All others are not supported. |
| 717 | * |
| 718 | * NOTE: Integer is not specifically supported by the ACPI spec, |
| 719 | * but is supported implicitly via implicit operand conversion. |
| 720 | * rather than bother with conversion, we just use the byte width |
| 721 | * global (4 or 8 bytes). |
| 722 | */ |
| 723 | switch (type) { |
| 724 | case ACPI_TYPE_INTEGER: |
| 725 | value = acpi_gbl_integer_byte_width; |
| 726 | break; |
| 727 | |
| 728 | case ACPI_TYPE_BUFFER: |
| 729 | value = temp_desc->buffer.length; |
| 730 | break; |
| 731 | |
| 732 | case ACPI_TYPE_STRING: |
| 733 | value = temp_desc->string.length; |
| 734 | break; |
| 735 | |
| 736 | case ACPI_TYPE_PACKAGE: |
| 737 | value = temp_desc->package.count; |
| 738 | break; |
| 739 | |
| 740 | default: |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 741 | ACPI_REPORT_ERROR(("Operand is not Buf/Int/Str/Pkg - found type %s\n", acpi_ut_get_type_name(type))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | status = AE_AML_OPERAND_TYPE; |
| 743 | goto cleanup; |
| 744 | } |
| 745 | |
| 746 | /* |
| 747 | * Now that we have the size of the object, create a result |
| 748 | * object to hold the value |
| 749 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (!return_desc) { |
| 752 | status = AE_NO_MEMORY; |
| 753 | goto cleanup; |
| 754 | } |
| 755 | |
| 756 | return_desc->integer.value = value; |
| 757 | break; |
| 758 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 759 | case AML_REF_OF_OP: /* ref_of (source_object) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | status = |
| 762 | acpi_ex_get_object_reference(operand[0], &return_desc, |
| 763 | walk_state); |
| 764 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | goto cleanup; |
| 766 | } |
| 767 | break; |
| 768 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 769 | case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | /* Check for a method local or argument, or standalone String */ |
| 772 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 773 | if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) != |
| 774 | ACPI_DESC_TYPE_NAMED) { |
| 775 | switch (ACPI_GET_OBJECT_TYPE(operand[0])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 777 | /* |
| 778 | * This is a deref_of (local_x | arg_x) |
| 779 | * |
| 780 | * Must resolve/dereference the local/arg reference first |
| 781 | */ |
| 782 | switch (operand[0]->reference.opcode) { |
| 783 | case AML_LOCAL_OP: |
| 784 | case AML_ARG_OP: |
| 785 | |
| 786 | /* Set Operand[0] to the value of the local/arg */ |
| 787 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 788 | status = |
| 789 | acpi_ds_method_data_get_value |
| 790 | (operand[0]->reference.opcode, |
| 791 | operand[0]->reference.offset, |
| 792 | walk_state, &temp_desc); |
| 793 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | goto cleanup; |
| 795 | } |
| 796 | |
| 797 | /* |
| 798 | * Delete our reference to the input object and |
| 799 | * point to the object just retrieved |
| 800 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 801 | acpi_ut_remove_reference(operand[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | operand[0] = temp_desc; |
| 803 | break; |
| 804 | |
| 805 | case AML_REF_OF_OP: |
| 806 | |
| 807 | /* Get the object to which the reference refers */ |
| 808 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 809 | temp_desc = |
| 810 | operand[0]->reference.object; |
| 811 | acpi_ut_remove_reference(operand[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | operand[0] = temp_desc; |
| 813 | break; |
| 814 | |
| 815 | default: |
| 816 | |
| 817 | /* Must be an Index op - handled below */ |
| 818 | break; |
| 819 | } |
| 820 | break; |
| 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | case ACPI_TYPE_STRING: |
| 823 | |
| 824 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 825 | * This is a deref_of (String). The string is a reference |
| 826 | * to a named ACPI object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | * |
| 828 | * 1) Find the owning Node |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 829 | * 2) Dereference the node to an actual object. Could be a |
| 830 | * Field, so we need to resolve the node to a value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | status = |
| 833 | acpi_ns_get_node_by_path(operand[0]->string. |
| 834 | pointer, |
| 835 | walk_state-> |
| 836 | scope_info->scope. |
| 837 | node, |
| 838 | ACPI_NS_SEARCH_PARENT, |
| 839 | ACPI_CAST_INDIRECT_PTR |
| 840 | (struct |
| 841 | acpi_namespace_node, |
| 842 | &return_desc)); |
| 843 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | goto cleanup; |
| 845 | } |
| 846 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 847 | status = |
| 848 | acpi_ex_resolve_node_to_value |
| 849 | (ACPI_CAST_INDIRECT_PTR |
| 850 | (struct acpi_namespace_node, &return_desc), |
| 851 | walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | goto cleanup; |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | default: |
| 855 | |
| 856 | status = AE_AML_OPERAND_TYPE; |
| 857 | goto cleanup; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | /* Operand[0] may have changed from the code above */ |
| 862 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 863 | if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) == |
| 864 | ACPI_DESC_TYPE_NAMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | /* |
| 866 | * This is a deref_of (object_reference) |
| 867 | * Get the actual object from the Node (This is the dereference). |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 868 | * This case may only happen when a local_x or arg_x is |
| 869 | * dereferenced above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | return_desc = acpi_ns_get_attached_object((struct |
| 872 | acpi_namespace_node |
| 873 | *) |
| 874 | operand[0]); |
| 875 | acpi_ut_add_reference(return_desc); |
| 876 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 878 | * This must be a reference object produced by either the |
| 879 | * Index() or ref_of() operator |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | */ |
| 881 | switch (operand[0]->reference.opcode) { |
| 882 | case AML_INDEX_OP: |
| 883 | |
| 884 | /* |
| 885 | * The target type for the Index operator must be |
| 886 | * either a Buffer or a Package |
| 887 | */ |
| 888 | switch (operand[0]->reference.target_type) { |
| 889 | case ACPI_TYPE_BUFFER_FIELD: |
| 890 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 891 | temp_desc = |
| 892 | operand[0]->reference.object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * Create a new object that contains one element of the |
| 896 | * buffer -- the element pointed to by the index. |
| 897 | * |
| 898 | * NOTE: index into a buffer is NOT a pointer to a |
| 899 | * sub-buffer of the main buffer, it is only a pointer to a |
| 900 | * single element (byte) of the buffer! |
| 901 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 902 | return_desc = |
| 903 | acpi_ut_create_internal_object |
| 904 | (ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | if (!return_desc) { |
| 906 | status = AE_NO_MEMORY; |
| 907 | goto cleanup; |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * Since we are returning the value of the buffer at the |
| 912 | * indexed location, we don't need to add an additional |
| 913 | * reference to the buffer itself. |
| 914 | */ |
| 915 | return_desc->integer.value = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 916 | temp_desc->buffer. |
| 917 | pointer[operand[0]->reference. |
| 918 | offset]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | break; |
| 920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | case ACPI_TYPE_PACKAGE: |
| 922 | |
| 923 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 924 | * Return the referenced element of the package. We must |
| 925 | * add another reference to the referenced object, however. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 927 | return_desc = |
| 928 | *(operand[0]->reference.where); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 929 | if (return_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 930 | acpi_ut_add_reference |
| 931 | (return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | break; |
| 935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | default: |
| 937 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 938 | ACPI_REPORT_ERROR(("Unknown Index target_type %X in obj %p\n", operand[0]->reference.target_type, operand[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | status = AE_AML_OPERAND_TYPE; |
| 940 | goto cleanup; |
| 941 | } |
| 942 | break; |
| 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | case AML_REF_OF_OP: |
| 945 | |
| 946 | return_desc = operand[0]->reference.object; |
| 947 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 948 | if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) == |
| 949 | ACPI_DESC_TYPE_NAMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 951 | return_desc = |
| 952 | acpi_ns_get_attached_object((struct |
| 953 | acpi_namespace_node |
| 954 | *) |
| 955 | return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | /* Add another reference to the object! */ |
| 959 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 960 | acpi_ut_add_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | break; |
| 962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | default: |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 964 | ACPI_REPORT_ERROR(("Unknown opcode in ref(%p) - %X\n", operand[0], operand[0]->reference.opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | status = AE_TYPE; |
| 967 | goto cleanup; |
| 968 | } |
| 969 | } |
| 970 | break; |
| 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | default: |
| 973 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 974 | ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", |
| 975 | walk_state->opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | status = AE_AML_BAD_OPCODE; |
| 977 | goto cleanup; |
| 978 | } |
| 979 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 980 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | /* Delete return object on error */ |
| 983 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 984 | if (ACPI_FAILURE(status)) { |
| 985 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | walk_state->result_obj = return_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 989 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |