exstore.c revision 129684
1 2/****************************************************************************** 3 * 4 * Module Name: exstore - AML Interpreter object store support 5 * $Revision: 182 $ 6 * 7 *****************************************************************************/ 8 9/****************************************************************************** 10 * 11 * 1. Copyright Notice 12 * 13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp. 14 * All rights reserved. 15 * 16 * 2. License 17 * 18 * 2.1. This is your license from Intel Corp. under its intellectual property 19 * rights. You may have additional license terms from the party that provided 20 * you this software, covering your right to use that party's intellectual 21 * property rights. 22 * 23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24 * copy of the source code appearing in this file ("Covered Code") an 25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26 * base code distributed originally by Intel ("Original Intel Code") to copy, 27 * make derivatives, distribute, use and display any portion of the Covered 28 * Code in any form, with the right to sublicense such rights; and 29 * 30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31 * license (with the right to sublicense), under only those claims of Intel 32 * patents that are infringed by the Original Intel Code, to make, use, sell, 33 * offer to sell, and import the Covered Code and derivative works thereof 34 * solely to the minimum extent necessary to exercise the above copyright 35 * license, and in no event shall the patent license extend to any additions 36 * to or modifications of the Original Intel Code. No other license or right 37 * is granted directly or by implication, estoppel or otherwise; 38 * 39 * The above copyright and patent license is granted only if the following 40 * conditions are met: 41 * 42 * 3. Conditions 43 * 44 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45 * Redistribution of source code of any substantial portion of the Covered 46 * Code or modification with rights to further distribute source must include 47 * the above Copyright Notice, the above License, this list of Conditions, 48 * and the following Disclaimer and Export Compliance provision. In addition, 49 * Licensee must cause all Covered Code to which Licensee contributes to 50 * contain a file documenting the changes Licensee made to create that Covered 51 * Code and the date of any change. Licensee must include in that file the 52 * documentation of any changes made by any predecessor Licensee. Licensee 53 * must include a prominent statement that the modification is derived, 54 * 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 __EXSTORE_C__ 119 120#include "acpi.h" 121#include "acdispat.h" 122#include "acinterp.h" 123#include "amlcode.h" 124#include "acnamesp.h" 125 126 127#define _COMPONENT ACPI_EXECUTER 128 ACPI_MODULE_NAME ("exstore") 129 130 131/******************************************************************************* 132 * 133 * FUNCTION: AcpiExStore 134 * 135 * PARAMETERS: *SourceDesc - Value to be stored 136 * *DestDesc - Where to store it. Must be an NS node 137 * or an ACPI_OPERAND_OBJECT of type 138 * Reference; 139 * WalkState - Current walk state 140 * 141 * RETURN: Status 142 * 143 * DESCRIPTION: Store the value described by SourceDesc into the location 144 * described by DestDesc. Called by various interpreter 145 * functions to store the result of an operation into 146 * the destination operand -- not just simply the actual "Store" 147 * ASL operator. 148 * 149 ******************************************************************************/ 150 151ACPI_STATUS 152AcpiExStore ( 153 ACPI_OPERAND_OBJECT *SourceDesc, 154 ACPI_OPERAND_OBJECT *DestDesc, 155 ACPI_WALK_STATE *WalkState) 156{ 157 ACPI_STATUS Status = AE_OK; 158 ACPI_OPERAND_OBJECT *RefDesc = DestDesc; 159 160 161 ACPI_FUNCTION_TRACE_PTR ("ExStore", DestDesc); 162 163 164 /* Validate parameters */ 165 166 if (!SourceDesc || !DestDesc) 167 { 168 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null parameter\n")); 169 return_ACPI_STATUS (AE_AML_NO_OPERAND); 170 } 171 172 /* DestDesc can be either a namespace node or an ACPI object */ 173 174 if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED) 175 { 176 /* 177 * Dest is a namespace node, 178 * Storing an object into a Named node. 179 */ 180 Status = AcpiExStoreObjectToNode (SourceDesc, 181 (ACPI_NAMESPACE_NODE *) DestDesc, WalkState, 182 ACPI_IMPLICIT_CONVERSION); 183 184 return_ACPI_STATUS (Status); 185 } 186 187 /* Destination object must be a Reference or a Constant object */ 188 189 switch (ACPI_GET_OBJECT_TYPE (DestDesc)) 190 { 191 case ACPI_TYPE_LOCAL_REFERENCE: 192 break; 193 194 case ACPI_TYPE_INTEGER: 195 196 /* Allow stores to Constants -- a Noop as per ACPI spec */ 197 198 if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT) 199 { 200 return_ACPI_STATUS (AE_OK); 201 } 202 203 /*lint -fallthrough */ 204 205 default: 206 207 /* Destination is not a Reference object */ 208 209 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 210 "Destination is not a Reference or Constant object [%p]\n", DestDesc)); 211 212 ACPI_DUMP_STACK_ENTRY (SourceDesc); 213 ACPI_DUMP_STACK_ENTRY (DestDesc); 214 ACPI_DUMP_OPERANDS (&DestDesc, ACPI_IMODE_EXECUTE, "ExStore", 215 2, "Target is not a Reference or Constant object"); 216 217 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 218 } 219 220 /* 221 * Examine the Reference opcode. These cases are handled: 222 * 223 * 1) Store to Name (Change the object associated with a name) 224 * 2) Store to an indexed area of a Buffer or Package 225 * 3) Store to a Method Local or Arg 226 * 4) Store to the debug object 227 */ 228 switch (RefDesc->Reference.Opcode) 229 { 230 case AML_NAME_OP: 231 case AML_REF_OF_OP: 232 233 /* Storing an object into a Name "container" */ 234 235 Status = AcpiExStoreObjectToNode (SourceDesc, RefDesc->Reference.Object, 236 WalkState, ACPI_IMPLICIT_CONVERSION); 237 break; 238 239 240 case AML_INDEX_OP: 241 242 /* Storing to an Index (pointer into a packager or buffer) */ 243 244 Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState); 245 break; 246 247 248 case AML_LOCAL_OP: 249 case AML_ARG_OP: 250 251 /* Store to a method local/arg */ 252 253 Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode, 254 RefDesc->Reference.Offset, SourceDesc, WalkState); 255 break; 256 257 258 case AML_DEBUG_OP: 259 260 /* 261 * Storing to the Debug object causes the value stored to be 262 * displayed and otherwise has no effect -- see ACPI Specification 263 */ 264 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Write to Debug Object: ****:\n\n")); 265 266 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ", 267 AcpiUtGetObjectTypeName (SourceDesc))); 268 269 switch (ACPI_GET_OBJECT_TYPE (SourceDesc)) 270 { 271 case ACPI_TYPE_INTEGER: 272 273 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n", 274 ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value))); 275 break; 276 277 278 case ACPI_TYPE_BUFFER: 279 280 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Length 0x%.2X", 281 (UINT32) SourceDesc->Buffer.Length)); 282 ACPI_DUMP_BUFFER (SourceDesc->Buffer.Pointer, 283 (SourceDesc->Buffer.Length < 32) ? SourceDesc->Buffer.Length : 32); 284 break; 285 286 287 case ACPI_TYPE_STRING: 288 289 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Length 0x%.2X, \"%s\"\n", 290 SourceDesc->String.Length, SourceDesc->String.Pointer)); 291 break; 292 293 294 case ACPI_TYPE_PACKAGE: 295 296 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Size 0x%.2X Elements Ptr - %p\n", 297 SourceDesc->Package.Count, SourceDesc->Package.Elements)); 298 break; 299 300 301 default: 302 303 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n", 304 SourceDesc)); 305 break; 306 } 307 308 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n")); 309 break; 310 311 312 default: 313 314 ACPI_REPORT_ERROR (("ExStore: Unknown Reference opcode %X\n", 315 RefDesc->Reference.Opcode)); 316 ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR); 317 318 Status = AE_AML_INTERNAL; 319 break; 320 } 321 322 return_ACPI_STATUS (Status); 323} 324 325 326/******************************************************************************* 327 * 328 * FUNCTION: AcpiExStoreObjectToIndex 329 * 330 * PARAMETERS: *SourceDesc - Value to be stored 331 * *DestDesc - Named object to receive the value 332 * WalkState - Current walk state 333 * 334 * RETURN: Status 335 * 336 * DESCRIPTION: Store the object to indexed Buffer or Package element 337 * 338 ******************************************************************************/ 339 340ACPI_STATUS 341AcpiExStoreObjectToIndex ( 342 ACPI_OPERAND_OBJECT *SourceDesc, 343 ACPI_OPERAND_OBJECT *IndexDesc, 344 ACPI_WALK_STATE *WalkState) 345{ 346 ACPI_STATUS Status = AE_OK; 347 ACPI_OPERAND_OBJECT *ObjDesc; 348 ACPI_OPERAND_OBJECT *NewDesc; 349 UINT8 Value = 0; 350 UINT32 i; 351 352 353 ACPI_FUNCTION_TRACE ("ExStoreObjectToIndex"); 354 355 356 /* 357 * Destination must be a reference pointer, and 358 * must point to either a buffer or a package 359 */ 360 switch (IndexDesc->Reference.TargetType) 361 { 362 case ACPI_TYPE_PACKAGE: 363 /* 364 * Storing to a package element is not simple. The source must be 365 * evaluated and converted to the type of the destination and then the 366 * source is copied into the destination - we can't just point to the 367 * source object. 368 */ 369 /* 370 * The object at *(IndexDesc->Reference.Where) is the 371 * element within the package that is to be modified. 372 * The parent package object is at IndexDesc->Reference.Object 373 */ 374 ObjDesc = *(IndexDesc->Reference.Where); 375 376 /* Do the conversion/store */ 377 378 Status = AcpiExStoreObjectToObject (SourceDesc, ObjDesc, &NewDesc, 379 WalkState); 380 if (ACPI_FAILURE (Status)) 381 { 382 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 383 "Could not store object to indexed package element\n")); 384 return_ACPI_STATUS (Status); 385 } 386 387 /* 388 * If a new object was created, we must install it as the new 389 * package element 390 */ 391 if (NewDesc != ObjDesc) 392 { 393 AcpiUtRemoveReference (ObjDesc); 394 *(IndexDesc->Reference.Where) = NewDesc; 395 396 /* If same as the original source, add a reference */ 397 398 if (NewDesc == SourceDesc) 399 { 400 AcpiUtAddReference (NewDesc); 401 } 402 403 /* Increment reference count by the ref count of the parent package -1 */ 404 405 for (i = 1; i < ((ACPI_OPERAND_OBJECT *) IndexDesc->Reference.Object)->Common.ReferenceCount; i++) 406 { 407 AcpiUtAddReference (NewDesc); 408 } 409 } 410 break; 411 412 413 case ACPI_TYPE_BUFFER_FIELD: 414 415 /* 416 * Store into a Buffer (not actually a real BufferField) at a 417 * location defined by an Index. 418 * 419 * The first 8-bit element of the source object is written to the 420 * 8-bit Buffer location defined by the Index destination object, 421 * according to the ACPI 2.0 specification. 422 */ 423 424 /* 425 * Make sure the target is a Buffer 426 */ 427 ObjDesc = IndexDesc->Reference.Object; 428 if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER) 429 { 430 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 431 } 432 433 /* 434 * The assignment of the individual elements will be slightly 435 * different for each source type. 436 */ 437 switch (ACPI_GET_OBJECT_TYPE (SourceDesc)) 438 { 439 case ACPI_TYPE_INTEGER: 440 441 /* Use the least-significant byte of the integer */ 442 443 Value = (UINT8) (SourceDesc->Integer.Value); 444 break; 445 446 case ACPI_TYPE_BUFFER: 447 448 Value = SourceDesc->Buffer.Pointer[0]; 449 break; 450 451 case ACPI_TYPE_STRING: 452 453 Value = (UINT8) SourceDesc->String.Pointer[0]; 454 break; 455 456 default: 457 458 /* All other types are invalid */ 459 460 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 461 "Source must be Integer/Buffer/String type, not %s\n", 462 AcpiUtGetObjectTypeName (SourceDesc))); 463 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 464 } 465 466 /* Store the source value into the target buffer byte */ 467 468 ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value; 469 break; 470 471 472 default: 473 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 474 "Target is not a Package or BufferField\n")); 475 Status = AE_AML_OPERAND_TYPE; 476 break; 477 } 478 479 return_ACPI_STATUS (Status); 480} 481 482 483/******************************************************************************* 484 * 485 * FUNCTION: AcpiExStoreObjectToNode 486 * 487 * PARAMETERS: SourceDesc - Value to be stored 488 * Node - Named object to receive the value 489 * WalkState - Current walk state 490 * ImplicitConversion - Perform implicit conversion (yes/no) 491 * 492 * RETURN: Status 493 * 494 * DESCRIPTION: Store the object to the named object. 495 * 496 * The Assignment of an object to a named object is handled here 497 * The value passed in will replace the current value (if any) 498 * with the input value. 499 * 500 * When storing into an object the data is converted to the 501 * target object type then stored in the object. This means 502 * that the target object type (for an initialized target) will 503 * not be changed by a store operation. 504 * 505 * Assumes parameters are already validated. 506 * 507 ******************************************************************************/ 508 509ACPI_STATUS 510AcpiExStoreObjectToNode ( 511 ACPI_OPERAND_OBJECT *SourceDesc, 512 ACPI_NAMESPACE_NODE *Node, 513 ACPI_WALK_STATE *WalkState, 514 UINT8 ImplicitConversion) 515{ 516 ACPI_STATUS Status = AE_OK; 517 ACPI_OPERAND_OBJECT *TargetDesc; 518 ACPI_OPERAND_OBJECT *NewDesc; 519 ACPI_OBJECT_TYPE TargetType; 520 521 522 ACPI_FUNCTION_TRACE_PTR ("ExStoreObjectToNode", SourceDesc); 523 524 525 /* 526 * Get current type of the node, and object attached to Node 527 */ 528 TargetType = AcpiNsGetType (Node); 529 TargetDesc = AcpiNsGetAttachedObject (Node); 530 531 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", 532 SourceDesc, AcpiUtGetObjectTypeName (SourceDesc), 533 Node, AcpiUtGetTypeName (TargetType))); 534 535 /* 536 * Resolve the source object to an actual value 537 * (If it is a reference object) 538 */ 539 Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState); 540 if (ACPI_FAILURE (Status)) 541 { 542 return_ACPI_STATUS (Status); 543 } 544 545 /* If no implicit conversion, drop into the default case below */ 546 547 if (!ImplicitConversion) 548 { 549 /* Force execution of default (no implicit conversion) */ 550 551 TargetType = ACPI_TYPE_ANY; 552 } 553 554 /* 555 * Do the actual store operation 556 */ 557 switch (TargetType) 558 { 559 case ACPI_TYPE_BUFFER_FIELD: 560 case ACPI_TYPE_LOCAL_REGION_FIELD: 561 case ACPI_TYPE_LOCAL_BANK_FIELD: 562 case ACPI_TYPE_LOCAL_INDEX_FIELD: 563 564 /* 565 * For fields, copy the source data to the target field. 566 */ 567 Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, &WalkState->ResultObj); 568 break; 569 570 571 case ACPI_TYPE_INTEGER: 572 case ACPI_TYPE_STRING: 573 case ACPI_TYPE_BUFFER: 574 575 /* 576 * These target types are all of type Integer/String/Buffer, and 577 * therefore support implicit conversion before the store. 578 * 579 * Copy and/or convert the source object to a new target object 580 */ 581 Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState); 582 if (ACPI_FAILURE (Status)) 583 { 584 return_ACPI_STATUS (Status); 585 } 586 587 if (NewDesc != TargetDesc) 588 { 589 /* 590 * Store the new NewDesc as the new value of the Name, and set 591 * the Name's type to that of the value being stored in it. 592 * SourceDesc reference count is incremented by AttachObject. 593 * 594 * Note: This may change the type of the node if an explicit store 595 * has been performed such that the node/object type has been 596 * changed. 597 */ 598 Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type); 599 600 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 601 "Store %s into %s via Convert/Attach\n", 602 AcpiUtGetObjectTypeName (SourceDesc), 603 AcpiUtGetObjectTypeName (NewDesc))); 604 } 605 break; 606 607 608 default: 609 610 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 611 "Storing %s (%p) directly into node (%p), no implicit conversion\n", 612 AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node)); 613 614 /* No conversions for all other types. Just attach the source object */ 615 616 Status = AcpiNsAttachObject (Node, SourceDesc, ACPI_GET_OBJECT_TYPE (SourceDesc)); 617 break; 618 } 619 620 return_ACPI_STATUS (Status); 621} 622 623 624