| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
|  | 2 | /****************************************************************************** | 
|  | 3 | * | 
|  | 4 | * Module Name: exoparg3 - AML execution - opcodes with 3 arguments | 
|  | 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/acinterp.h> | 
|  | 47 | #include <acpi/acparser.h> | 
|  | 48 | #include <acpi/amlcode.h> | 
|  | 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("exoparg3") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | /*! | 
|  | 54 | * Naming convention for AML interpreter execution routines. | 
|  | 55 | * | 
|  | 56 | * The routines that begin execution of AML opcodes are named with a common | 
|  | 57 | * convention based upon the number of arguments, the number of target operands, | 
|  | 58 | * and whether or not a value is returned: | 
|  | 59 | * | 
|  | 60 | *      AcpiExOpcode_xA_yT_zR | 
|  | 61 | * | 
|  | 62 | * Where: | 
|  | 63 | * | 
|  | 64 | * xA - ARGUMENTS:    The number of arguments (input operands) that are | 
|  | 65 | *                    required for this opcode type (1 through 6 args). | 
|  | 66 | * yT - TARGETS:      The number of targets (output operands) that are required | 
|  | 67 | *                    for this opcode type (0, 1, or 2 targets). | 
|  | 68 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value | 
|  | 69 | *                    as the function return (0 or 1). | 
|  | 70 | * | 
|  | 71 | * The AcpiExOpcode* functions are called via the Dispatcher component with | 
|  | 72 | * fully resolved operands. | 
|  | 73 | !*/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /******************************************************************************* | 
|  | 75 | * | 
|  | 76 | * FUNCTION:    acpi_ex_opcode_3A_0T_0R | 
|  | 77 | * | 
|  | 78 | * PARAMETERS:  walk_state          - Current walk state | 
|  | 79 | * | 
|  | 80 | * RETURN:      Status | 
|  | 81 | * | 
|  | 82 | * DESCRIPTION: Execute Triadic operator (3 operands) | 
|  | 83 | * | 
|  | 84 | ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | union acpi_operand_object **operand = &walk_state->operands[0]; | 
|  | 88 | struct acpi_signal_fatal_info *fatal; | 
|  | 89 | acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | ACPI_FUNCTION_TRACE_STR("ex_opcode_3A_0T_0R", | 
|  | 92 | acpi_ps_get_opcode_name(walk_state->opcode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
|  | 94 | switch (walk_state->opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | case AML_FATAL_OP:	/* Fatal (fatal_type fatal_code fatal_arg) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 98 | "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", | 
|  | 99 | (u32) operand[0]->integer.value, | 
|  | 100 | (u32) operand[1]->integer.value, | 
|  | 101 | (u32) operand[2]->integer.value)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | fatal = | 
|  | 104 | ACPI_MEM_ALLOCATE(sizeof(struct acpi_signal_fatal_info)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (fatal) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | fatal->type = (u32) operand[0]->integer.value; | 
|  | 107 | fatal->code = (u32) operand[1]->integer.value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | fatal->argument = (u32) operand[2]->integer.value; | 
|  | 109 | } | 
|  | 110 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 111 | /* Always signal the OS! */ | 
|  | 112 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 |  | 
|  | 115 | /* Might return while OS is shutting down, just continue */ | 
|  | 116 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | ACPI_MEM_FREE(fatal); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | break; | 
|  | 119 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | default: | 
|  | 121 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 122 | ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", | 
|  | 123 | walk_state->opcode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | status = AE_AML_BAD_OPCODE; | 
|  | 125 | goto cleanup; | 
|  | 126 | } | 
|  | 127 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | cleanup: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /******************************************************************************* | 
|  | 134 | * | 
|  | 135 | * FUNCTION:    acpi_ex_opcode_3A_1T_1R | 
|  | 136 | * | 
|  | 137 | * PARAMETERS:  walk_state          - Current walk state | 
|  | 138 | * | 
|  | 139 | * RETURN:      Status | 
|  | 140 | * | 
|  | 141 | * DESCRIPTION: Execute Triadic operator (3 operands) | 
|  | 142 | * | 
|  | 143 | ******************************************************************************/ | 
|  | 144 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | union acpi_operand_object **operand = &walk_state->operands[0]; | 
|  | 148 | union acpi_operand_object *return_desc = NULL; | 
|  | 149 | char *buffer = NULL; | 
|  | 150 | acpi_status status = AE_OK; | 
|  | 151 | acpi_integer index; | 
|  | 152 | acpi_size length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | ACPI_FUNCTION_TRACE_STR("ex_opcode_3A_1T_1R", | 
|  | 155 | acpi_ps_get_opcode_name(walk_state->opcode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 |  | 
|  | 157 | switch (walk_state->opcode) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | case AML_MID_OP:	/* Mid (Source[0], Index[1], Length[2], Result[3]) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 |  | 
|  | 160 | /* | 
|  | 161 | * Create the return object.  The Source operand is guaranteed to be | 
|  | 162 | * either a String or a Buffer, so just use its type. | 
|  | 163 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | return_desc = | 
|  | 165 | acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE | 
|  | 166 | (operand[0])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (!return_desc) { | 
|  | 168 | status = AE_NO_MEMORY; | 
|  | 169 | goto cleanup; | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | /* Get the Integer values from the objects */ | 
|  | 173 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 174 | index = operand[1]->integer.value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | length = (acpi_size) operand[2]->integer.value; | 
|  | 176 |  | 
|  | 177 | /* | 
|  | 178 | * If the index is beyond the length of the String/Buffer, or if the | 
|  | 179 | * requested length is zero, return a zero-length String/Buffer | 
|  | 180 | */ | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 181 | if (index >= operand[0]->string.length) { | 
|  | 182 | length = 0; | 
|  | 183 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 185 | /* Truncate request if larger than the actual String/Buffer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 187 | else if ((index + length) > operand[0]->string.length) { | 
|  | 188 | length = (acpi_size) operand[0]->string.length - | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | (acpi_size) index; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
|  | 192 | /* Strings always have a sub-pointer, not so for buffers */ | 
|  | 193 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | switch (ACPI_GET_OBJECT_TYPE(operand[0])) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 195 | case ACPI_TYPE_STRING: | 
|  | 196 |  | 
|  | 197 | /* Always allocate a new buffer for the String */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | buffer = ACPI_MEM_CALLOCATE((acpi_size) length + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (!buffer) { | 
|  | 201 | status = AE_NO_MEMORY; | 
|  | 202 | goto cleanup; | 
|  | 203 | } | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 204 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 206 | case ACPI_TYPE_BUFFER: | 
|  | 207 |  | 
|  | 208 | /* If the requested length is zero, don't allocate a buffer */ | 
|  | 209 |  | 
|  | 210 | if (length > 0) { | 
|  | 211 | /* Allocate a new buffer for the Buffer */ | 
|  | 212 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | buffer = ACPI_MEM_CALLOCATE(length); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 214 | if (!buffer) { | 
|  | 215 | status = AE_NO_MEMORY; | 
|  | 216 | goto cleanup; | 
|  | 217 | } | 
|  | 218 | } | 
|  | 219 | break; | 
|  | 220 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | default:	/* Should not happen */ | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 222 |  | 
|  | 223 | status = AE_AML_OPERAND_TYPE; | 
|  | 224 | goto cleanup; | 
|  | 225 | } | 
|  | 226 |  | 
| Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 227 | if (buffer) { | 
|  | 228 | /* We have a buffer, copy the portion requested */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | ACPI_MEMCPY(buffer, operand[0]->string.pointer + index, | 
|  | 231 | length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } | 
|  | 233 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 234 | /* Set the length of the new String/Buffer */ | 
|  | 235 |  | 
|  | 236 | return_desc->string.pointer = buffer; | 
|  | 237 | return_desc->string.length = (u32) length; | 
|  | 238 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | /* Mark buffer initialized */ | 
|  | 240 |  | 
|  | 241 | return_desc->buffer.flags |= AOPOBJ_DATA_VALID; | 
|  | 242 | break; | 
|  | 243 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | default: | 
|  | 245 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 246 | ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", | 
|  | 247 | walk_state->opcode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | status = AE_AML_BAD_OPCODE; | 
|  | 249 | goto cleanup; | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | /* Store the result in the target */ | 
|  | 253 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | status = acpi_ex_store(return_desc, operand[3], walk_state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | cleanup: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
|  | 258 | /* Delete return object on error */ | 
|  | 259 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | if (ACPI_FAILURE(status) || walk_state->result_obj) { | 
|  | 261 | acpi_ut_remove_reference(return_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } | 
|  | 263 |  | 
|  | 264 | /* Set the return object and exit */ | 
|  | 265 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 266 | else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | walk_state->result_obj = return_desc; | 
|  | 268 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |