1 /****************************************************************************** 2 * 3 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, Intel Corp. 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 44 #define __EXOPARG3_C__ 45 46 #include <contrib/dev/acpica/include/acpi.h> 47 #include <contrib/dev/acpica/include/accommon.h> 48 #include <contrib/dev/acpica/include/acinterp.h> 49 #include <contrib/dev/acpica/include/acparser.h> 50 #include <contrib/dev/acpica/include/amlcode.h> 51 52 53 #define _COMPONENT ACPI_EXECUTER 54 ACPI_MODULE_NAME ("exoparg3") 55 56 57 /*! 58 * Naming convention for AML interpreter execution routines. 59 * 60 * The routines that begin execution of AML opcodes are named with a common 61 * convention based upon the number of arguments, the number of target operands, 62 * and whether or not a value is returned: 63 * 64 * AcpiExOpcode_xA_yT_zR 65 * 66 * Where: 67 * 68 * xA - ARGUMENTS: The number of arguments (input operands) that are 69 * required for this opcode type (1 through 6 args). 70 * yT - TARGETS: The number of targets (output operands) that are required 71 * for this opcode type (0, 1, or 2 targets). 72 * zR - RETURN VALUE: Indicates whether this opcode type returns a value 73 * as the function return (0 or 1). 74 * 75 * The AcpiExOpcode* functions are called via the Dispatcher component with 76 * fully resolved operands. 77 !*/ 78 79 80 /******************************************************************************* 81 * 82 * FUNCTION: AcpiExOpcode_3A_0T_0R 83 * 84 * PARAMETERS: WalkState - Current walk state 85 * 86 * RETURN: Status 87 * 88 * DESCRIPTION: Execute Triadic operator (3 operands) 89 * 90 ******************************************************************************/ 91 92 ACPI_STATUS 93 AcpiExOpcode_3A_0T_0R ( 94 ACPI_WALK_STATE *WalkState) 95 { 96 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 97 ACPI_SIGNAL_FATAL_INFO *Fatal; 98 ACPI_STATUS Status = AE_OK; 99 100 101 ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_0T_0R, 102 AcpiPsGetOpcodeName (WalkState->Opcode)); 103 104 105 switch (WalkState->Opcode) 106 { 107 case AML_FATAL_OP: /* Fatal (FatalType FatalCode FatalArg) */ 108 109 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 110 "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", 111 (UINT32) Operand[0]->Integer.Value, 112 (UINT32) Operand[1]->Integer.Value, 113 (UINT32) Operand[2]->Integer.Value)); 114 115 Fatal = ACPI_ALLOCATE (sizeof (ACPI_SIGNAL_FATAL_INFO)); 116 if (Fatal) 117 { 118 Fatal->Type = (UINT32) Operand[0]->Integer.Value; 119 Fatal->Code = (UINT32) Operand[1]->Integer.Value; 120 Fatal->Argument = (UINT32) Operand[2]->Integer.Value; 121 } 122 123 /* Always signal the OS! */ 124 125 Status = AcpiOsSignal (ACPI_SIGNAL_FATAL, Fatal); 126 127 /* Might return while OS is shutting down, just continue */ 128 129 ACPI_FREE (Fatal); 130 break; 131 132 133 default: 134 135 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", 136 WalkState->Opcode)); 137 Status = AE_AML_BAD_OPCODE; 138 goto Cleanup; 139 } 140 141 142 Cleanup: 143 144 return_ACPI_STATUS (Status); 145 } 146 147 148 /******************************************************************************* 149 * 150 * FUNCTION: AcpiExOpcode_3A_1T_1R 151 * 152 * PARAMETERS: WalkState - Current walk state 153 * 154 * RETURN: Status 155 * 156 * DESCRIPTION: Execute Triadic operator (3 operands) 157 * 158 ******************************************************************************/ 159 160 ACPI_STATUS 161 AcpiExOpcode_3A_1T_1R ( 162 ACPI_WALK_STATE *WalkState) 163 { 164 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 165 ACPI_OPERAND_OBJECT *ReturnDesc = NULL; 166 char *Buffer = NULL; 167 ACPI_STATUS Status = AE_OK; 168 UINT64 Index; 169 ACPI_SIZE Length; 170 171 172 ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_1T_1R, 173 AcpiPsGetOpcodeName (WalkState->Opcode)); 174 175 176 switch (WalkState->Opcode) 177 { 178 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ 179 180 /* 181 * Create the return object. The Source operand is guaranteed to be 182 * either a String or a Buffer, so just use its type. 183 */ 184 ReturnDesc = AcpiUtCreateInternalObject ( 185 (Operand[0])->Common.Type); 186 if (!ReturnDesc) 187 { 188 Status = AE_NO_MEMORY; 189 goto Cleanup; 190 } 191 192 /* Get the Integer values from the objects */ 193 194 Index = Operand[1]->Integer.Value; 195 Length = (ACPI_SIZE) Operand[2]->Integer.Value; 196 197 /* 198 * If the index is beyond the length of the String/Buffer, or if the 199 * requested length is zero, return a zero-length String/Buffer 200 */ 201 if (Index >= Operand[0]->String.Length) 202 { 203 Length = 0; 204 } 205 206 /* Truncate request if larger than the actual String/Buffer */ 207 208 else if ((Index + Length) > Operand[0]->String.Length) 209 { 210 Length = (ACPI_SIZE) Operand[0]->String.Length - 211 (ACPI_SIZE) Index; 212 } 213 214 /* Strings always have a sub-pointer, not so for buffers */ 215 216 switch ((Operand[0])->Common.Type) 217 { 218 case ACPI_TYPE_STRING: 219 220 /* Always allocate a new buffer for the String */ 221 222 Buffer = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1); 223 if (!Buffer) 224 { 225 Status = AE_NO_MEMORY; 226 goto Cleanup; 227 } 228 break; 229 230 case ACPI_TYPE_BUFFER: 231 232 /* If the requested length is zero, don't allocate a buffer */ 233 234 if (Length > 0) 235 { 236 /* Allocate a new buffer for the Buffer */ 237 238 Buffer = ACPI_ALLOCATE_ZEROED (Length); 239 if (!Buffer) 240 { 241 Status = AE_NO_MEMORY; 242 goto Cleanup; 243 } 244 } 245 break; 246 247 default: /* Should not happen */ 248 249 Status = AE_AML_OPERAND_TYPE; 250 goto Cleanup; 251 } 252 253 if (Buffer) 254 { 255 /* We have a buffer, copy the portion requested */ 256 257 ACPI_MEMCPY (Buffer, Operand[0]->String.Pointer + Index, 258 Length); 259 } 260 261 /* Set the length of the new String/Buffer */ 262 263 ReturnDesc->String.Pointer = Buffer; 264 ReturnDesc->String.Length = (UINT32) Length; 265 266 /* Mark buffer initialized */ 267 268 ReturnDesc->Buffer.Flags |= AOPOBJ_DATA_VALID; 269 break; 270 271 272 default: 273 274 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", 275 WalkState->Opcode)); 276 Status = AE_AML_BAD_OPCODE; 277 goto Cleanup; 278 } 279 280 /* Store the result in the target */ 281 282 Status = AcpiExStore (ReturnDesc, Operand[3], WalkState); 283 284 Cleanup: 285 286 /* Delete return object on error */ 287 288 if (ACPI_FAILURE (Status) || WalkState->ResultObj) 289 { 290 AcpiUtRemoveReference (ReturnDesc); 291 WalkState->ResultObj = NULL; 292 } 293 294 /* Set the return object and exit */ 295 296 else 297 { 298 WalkState->ResultObj = ReturnDesc; 299 } 300 return_ACPI_STATUS (Status); 301 } 302