exstorob.c revision 69746
1218885Sdim 2218885Sdim/****************************************************************************** 3353358Sdim * 4353358Sdim * Module Name: amstorob - AML Interpreter object store support, store to object 5353358Sdim * $Revision: 18 $ 6218885Sdim * 7218885Sdim *****************************************************************************/ 8218885Sdim 9218885Sdim/****************************************************************************** 10218885Sdim * 11218885Sdim * 1. Copyright Notice 12218885Sdim * 13280031Sdim * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights 14280031Sdim * reserved. 15218885Sdim * 16218885Sdim * 2. License 17327952Sdim * 18218885Sdim * 2.1. This is your license from Intel Corp. under its intellectual property 19218885Sdim * rights. You may have additional license terms from the party that provided 20218885Sdim * you this software, covering your right to use that party's intellectual 21218885Sdim * property rights. 22218885Sdim * 23218885Sdim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24276479Sdim * copy of the source code appearing in this file ("Covered Code") an 25360784Sdim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26360784Sdim * base code distributed originally by Intel ("Original Intel Code") to copy, 27218885Sdim * make derivatives, distribute, use and display any portion of the Covered 28218885Sdim * Code in any form, with the right to sublicense such rights; and 29218885Sdim * 30288943Sdim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31276479Sdim * license (with the right to sublicense), under only those claims of Intel 32218885Sdim * patents that are infringed by the Original Intel Code, to make, use, sell, 33309124Sdim * offer to sell, and import the Covered Code and derivative works thereof 34309124Sdim * solely to the minimum extent necessary to exercise the above copyright 35309124Sdim * license, and in no event shall the patent license extend to any additions 36249423Sdim * to or modifications of the Original Intel Code. No other license or right 37218885Sdim * is granted directly or by implication, estoppel or otherwise; 38218885Sdim * 39218885Sdim * The above copyright and patent license is granted only if the following 40276479Sdim * conditions are met: 41218885Sdim * 42276479Sdim * 3. Conditions 43327952Sdim * 44276479Sdim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45218885Sdim * Redistribution of source code of any substantial portion of the Covered 46276479Sdim * Code or modification with rights to further distribute source must include 47276479Sdim * the above Copyright Notice, the above License, this list of Conditions, 48249423Sdim * and the following Disclaimer and Export Compliance provision. In addition, 49276479Sdim * Licensee must cause all Covered Code to which Licensee contributes to 50218885Sdim * contain a file documenting the changes Licensee made to create that Covered 51218885Sdim * Code and the date of any change. Licensee must include in that file the 52218885Sdim * documentation of any changes made by any predecessor Licensee. Licensee 53218885Sdim * must include a prominent statement that the modification is derived, 54218885Sdim * directly or indirectly, from Original Intel Code. 55 * 56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57 * Redistribution of source code of any substantial portion of the Covered 58 * Code or modification without rights to further distribute source must 59 * include the following Disclaimer and Export Compliance provision in the 60 * documentation and/or other materials provided with distribution. In 61 * addition, Licensee may not authorize further sublicense of source of any 62 * portion of the Covered Code, and must include terms to the effect that the 63 * license from Licensee to its licensee is limited to the intellectual 64 * property embodied in the software Licensee provides to its licensee, and 65 * not to intellectual property embodied in modifications its licensee may 66 * make. 67 * 68 * 3.3. Redistribution of Executable. Redistribution in executable form of any 69 * substantial portion of the Covered Code or modification must reproduce the 70 * above Copyright Notice, and the following Disclaimer and Export Compliance 71 * provision in the documentation and/or other materials provided with the 72 * distribution. 73 * 74 * 3.4. Intel retains all right, title, and interest in and to the Original 75 * Intel Code. 76 * 77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78 * Intel shall be used in advertising or otherwise to promote the sale, use or 79 * other dealings in products derived from or relating to the Covered Code 80 * without prior written authorization from Intel. 81 * 82 * 4. Disclaimer and Export Compliance 83 * 84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90 * PARTICULAR PURPOSE. 91 * 92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99 * LIMITED REMEDY. 100 * 101 * 4.3. Licensee shall not export, either directly or indirectly, any of this 102 * software or system incorporating such software without first obtaining any 103 * required license or other approval from the U. S. Department of Commerce or 104 * any other agency or department of the United States Government. In the 105 * event Licensee exports any such software from the United States or 106 * re-exports any such software from a foreign destination, Licensee shall 107 * ensure that the distribution and export/re-export of the software is in 108 * compliance with all laws, regulations, orders, or other restrictions of the 109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110 * any of its subsidiaries will export/re-export any technical data, process, 111 * software, or service, directly or indirectly, to any country for which the 112 * United States government or any agency thereof requires an export license, 113 * other governmental approval, or letter of assurance, without first obtaining 114 * such license, approval or letter. 115 * 116 *****************************************************************************/ 117 118#define __AMSTOROB_C__ 119 120#include "acpi.h" 121#include "acparser.h" 122#include "acdispat.h" 123#include "acinterp.h" 124#include "amlcode.h" 125#include "acnamesp.h" 126#include "actables.h" 127 128 129#define _COMPONENT INTERPRETER 130 MODULE_NAME ("amstorob") 131 132 133/******************************************************************************* 134 * 135 * FUNCTION: AcpiAmlStoreObjectToObject 136 * 137 * PARAMETERS: *ValDesc - Value to be stored 138 * *DestDesc - Object to receive the value 139 * 140 * RETURN: Status 141 * 142 * DESCRIPTION: Store an object to another object. 143 * 144 * The Assignment of an object to another (not named) object 145 * is handled here. 146 * The val passed in will replace the current value (if any) 147 * with the input value. 148 * 149 * When storing into an object the data is converted to the 150 * target object type then stored in the object. This means 151 * that the target object type (for an initialized target) will 152 * not be changed by a store operation. 153 * 154 * This module allows destination types of Number, String, 155 * and Buffer. 156 * 157 ******************************************************************************/ 158 159ACPI_STATUS 160AcpiAmlStoreObjectToObject ( 161 ACPI_OPERAND_OBJECT *ValDesc, 162 ACPI_OPERAND_OBJECT *DestDesc, 163 ACPI_WALK_STATE *WalkState) 164{ 165 ACPI_STATUS Status = AE_OK; 166 UINT8 *Buffer = NULL; 167 UINT32 Length = 0; 168 OBJECT_TYPE_INTERNAL DestinationType = DestDesc->Common.Type; 169 170 171 FUNCTION_TRACE ("AmlStoreObjectToObject"); 172 173 DEBUG_PRINT (ACPI_INFO, 174 ("entered AcpiAmlStoreObjectToObject: Dest=%p, Val=%p\n", 175 DestDesc, ValDesc)); 176 177 /* 178 * Assuming the parameters are valid!!! 179 */ 180 ACPI_ASSERT((DestDesc) && (ValDesc)); 181 182 DEBUG_PRINT (ACPI_INFO, ("AmlStoreObjectToObject: Storing %s into %s\n", 183 AcpiCmGetTypeName (ValDesc->Common.Type), 184 AcpiCmGetTypeName (DestDesc->Common.Type))); 185 186 /* 187 * First ensure we have a value that can be stored in the target 188 */ 189 switch (DestinationType) 190 { 191 /* Type of Name's existing value */ 192 193 case ACPI_TYPE_NUMBER: 194 195 /* 196 * These cases all require only number values or values that 197 * can be converted to numbers. 198 * 199 * If value is not a Number, try to resolve it to one. 200 */ 201 202 if (ValDesc->Common.Type != ACPI_TYPE_NUMBER) 203 { 204 /* 205 * Initially not a number, convert 206 */ 207 Status = AcpiAmlResolveToValue (&ValDesc, WalkState); 208 if (ACPI_SUCCESS (Status) && 209 (ValDesc->Common.Type != ACPI_TYPE_NUMBER)) 210 { 211 /* 212 * Conversion successful but still not a number 213 */ 214 DEBUG_PRINT (ACPI_ERROR, 215 ("AmlStoreObjectToObject: Value assigned to %s must be Number, not %s\n", 216 AcpiCmGetTypeName (DestinationType), 217 AcpiCmGetTypeName (ValDesc->Common.Type))); 218 Status = AE_AML_OPERAND_TYPE; 219 } 220 } 221 222 break; 223 224 case ACPI_TYPE_STRING: 225 case ACPI_TYPE_BUFFER: 226 227 /* 228 * Storing into a Field in a region or into a buffer or into 229 * a string all is essentially the same. 230 * 231 * If value is not a valid type, try to resolve it to one. 232 */ 233 234 if ((ValDesc->Common.Type != ACPI_TYPE_NUMBER) && 235 (ValDesc->Common.Type != ACPI_TYPE_BUFFER) && 236 (ValDesc->Common.Type != ACPI_TYPE_STRING)) 237 { 238 /* 239 * Initially not a valid type, convert 240 */ 241 Status = AcpiAmlResolveToValue (&ValDesc, WalkState); 242 if (ACPI_SUCCESS (Status) && 243 (ValDesc->Common.Type != ACPI_TYPE_NUMBER) && 244 (ValDesc->Common.Type != ACPI_TYPE_BUFFER) && 245 (ValDesc->Common.Type != ACPI_TYPE_STRING)) 246 { 247 /* 248 * Conversion successful but still not a valid type 249 */ 250 DEBUG_PRINT (ACPI_ERROR, 251 ("AmlStoreObjectToObject: Assign wrong type %s to %s (must be type Num/Str/Buf)\n", 252 AcpiCmGetTypeName (ValDesc->Common.Type), 253 AcpiCmGetTypeName (DestinationType))); 254 Status = AE_AML_OPERAND_TYPE; 255 } 256 } 257 break; 258 259 260 default: 261 262 /* 263 * TBD: [Unhandled] What other combinations must be implemented? 264 */ 265 Status = AE_NOT_IMPLEMENTED; 266 break; 267 } 268 269 /* Exit now if failure above */ 270 271 if (ACPI_FAILURE (Status)) 272 { 273 goto CleanUpAndBailOut; 274 } 275 276 /* 277 * AcpiEverything is ready to execute now, We have 278 * a value we can handle, just perform the update 279 */ 280 281 switch (DestinationType) 282 { 283 284 case ACPI_TYPE_STRING: 285 286 /* 287 * Perform the update 288 */ 289 290 switch (ValDesc->Common.Type) 291 { 292 case ACPI_TYPE_NUMBER: 293 Buffer = (UINT8 *) &ValDesc->Number.Value; 294 Length = sizeof (ValDesc->Number.Value); 295 break; 296 297 case ACPI_TYPE_BUFFER: 298 Buffer = (UINT8 *) ValDesc->Buffer.Pointer; 299 Length = ValDesc->Buffer.Length; 300 break; 301 302 case ACPI_TYPE_STRING: 303 Buffer = (UINT8 *) ValDesc->String.Pointer; 304 Length = ValDesc->String.Length; 305 break; 306 } 307 308 /* 309 * Setting a string value replaces the old string 310 */ 311 312 if (Length < DestDesc->String.Length) 313 { 314 /* 315 * Zero fill, not willing to do pointer arithmetic for 316 * architecture independence. Just clear the whole thing 317 */ 318 MEMSET(DestDesc->String.Pointer, 0, DestDesc->String.Length); 319 MEMCPY(DestDesc->String.Pointer, Buffer, Length); 320 } 321 else 322 { 323 /* 324 * Free the current buffer, then allocate a buffer 325 * large enough to hold the value 326 */ 327 if ( DestDesc->String.Pointer && 328 !AcpiTbSystemTablePointer (DestDesc->String.Pointer)) 329 { 330 /* 331 * Only free if not a pointer into the DSDT 332 */ 333 334 AcpiCmFree(DestDesc->String.Pointer); 335 } 336 337 DestDesc->String.Pointer = AcpiCmAllocate (Length + 1); 338 DestDesc->String.Length = Length; 339 340 if (!DestDesc->String.Pointer) 341 { 342 Status = AE_NO_MEMORY; 343 goto CleanUpAndBailOut; 344 } 345 346 MEMCPY(DestDesc->String.Pointer, Buffer, Length); 347 } 348 break; 349 350 351 case ACPI_TYPE_BUFFER: 352 353 /* 354 * Perform the update to the buffer 355 */ 356 357 switch (ValDesc->Common.Type) 358 { 359 case ACPI_TYPE_NUMBER: 360 Buffer = (UINT8 *) &ValDesc->Number.Value; 361 Length = sizeof (ValDesc->Number.Value); 362 break; 363 364 case ACPI_TYPE_BUFFER: 365 Buffer = (UINT8 *) ValDesc->Buffer.Pointer; 366 Length = ValDesc->Buffer.Length; 367 break; 368 369 case ACPI_TYPE_STRING: 370 Buffer = (UINT8 *) ValDesc->String.Pointer; 371 Length = ValDesc->String.Length; 372 break; 373 } 374 375 /* 376 * If the buffer is uninitialized, 377 * memory needs to be allocated for the copy. 378 */ 379 if(0 == DestDesc->Buffer.Length) 380 { 381 DestDesc->Buffer.Pointer = AcpiCmCallocate(Length); 382 DestDesc->Buffer.Length = Length; 383 384 if (!DestDesc->Buffer.Pointer) 385 { 386 Status = AE_NO_MEMORY; 387 goto CleanUpAndBailOut; 388 } 389 } 390 391 /* 392 * Buffer is a static allocation, 393 * only place what will fit in the buffer. 394 */ 395 if (Length <= DestDesc->Buffer.Length) 396 { 397 /* 398 * Zero fill first, not willing to do pointer arithmetic for 399 * architecture independence. Just clear the whole thing 400 */ 401 MEMSET(DestDesc->Buffer.Pointer, 0, DestDesc->Buffer.Length); 402 MEMCPY(DestDesc->Buffer.Pointer, Buffer, Length); 403 } 404 else 405 { 406 /* 407 * truncate, copy only what will fit 408 */ 409 MEMCPY(DestDesc->Buffer.Pointer, Buffer, DestDesc->Buffer.Length); 410 DEBUG_PRINT (ACPI_INFO, 411 ("AmlStoreObjectToObject: Truncating src buffer from %X to %X\n", 412 Length, DestDesc->Buffer.Length)); 413 } 414 break; 415 416 case ACPI_TYPE_NUMBER: 417 418 DestDesc->Number.Value = ValDesc->Number.Value; 419 420 /* Truncate value if we are executing from a 32-bit ACPI table */ 421 422 AcpiAmlTruncateFor32bitTable (DestDesc, WalkState); 423 break; 424 425 default: 426 427 /* 428 * All other types than Alias and the various Fields come here. 429 * Store ValDesc as the new value of the Name, and set 430 * the Name's type to that of the value being stored in it. 431 * ValDesc reference count is incremented by AttachObject. 432 */ 433 434 DEBUG_PRINT (ACPI_WARN, 435 ("AmlStoreObjectToObject: Store into %s not implemented\n", 436 AcpiCmGetTypeName (DestDesc->Common.Type))); 437 438 Status = AE_NOT_IMPLEMENTED; 439 break; 440 } 441 442CleanUpAndBailOut: 443 444 return_ACPI_STATUS (Status); 445} 446 447