1 /****************************************************************************** 2 * 3 * Module Name: exresolv - AML Interpreter object resolution 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 #define __EXRESOLV_C__ 117 118 #include "acpi.h" 119 #include "accommon.h" 120 #include "amlcode.h" 121 #include "acdispat.h" 122 #include "acinterp.h" 123 #include "acnamesp.h" 124 125 126 #define _COMPONENT ACPI_EXECUTER 127 ACPI_MODULE_NAME ("exresolv") 128 129 /* Local prototypes */ 130 131 static ACPI_STATUS 132 AcpiExResolveObjectToValue ( 133 ACPI_OPERAND_OBJECT **StackPtr, 134 ACPI_WALK_STATE *WalkState); 135 136 137 /******************************************************************************* 138 * 139 * FUNCTION: AcpiExResolveToValue 140 * 141 * PARAMETERS: **StackPtr - Points to entry on ObjStack, which can 142 * be either an (ACPI_OPERAND_OBJECT *) 143 * or an ACPI_HANDLE. 144 * WalkState - Current method state 145 * 146 * RETURN: Status 147 * 148 * DESCRIPTION: Convert Reference objects to values 149 * 150 ******************************************************************************/ 151 152 ACPI_STATUS 153 AcpiExResolveToValue ( 154 ACPI_OPERAND_OBJECT **StackPtr, 155 ACPI_WALK_STATE *WalkState) 156 { 157 ACPI_STATUS Status; 158 159 160 ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr); 161 162 163 if (!StackPtr || !*StackPtr) 164 { 165 ACPI_ERROR ((AE_INFO, "Internal - null pointer")); 166 return_ACPI_STATUS (AE_AML_NO_OPERAND); 167 } 168 169 /* 170 * The entity pointed to by the StackPtr can be either 171 * 1) A valid ACPI_OPERAND_OBJECT, or 172 * 2) A ACPI_NAMESPACE_NODE (NamedObj) 173 */ 174 if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND) 175 { 176 Status = AcpiExResolveObjectToValue (StackPtr, WalkState); 177 if (ACPI_FAILURE (Status)) 178 { 179 return_ACPI_STATUS (Status); 180 } 181 182 if (!*StackPtr) 183 { 184 ACPI_ERROR ((AE_INFO, "Internal - null pointer")); 185 return_ACPI_STATUS (AE_AML_NO_OPERAND); 186 } 187 } 188 189 /* 190 * Object on the stack may have changed if AcpiExResolveObjectToValue() 191 * was called (i.e., we can't use an _else_ here.) 192 */ 193 if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED) 194 { 195 Status = AcpiExResolveNodeToValue ( 196 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr), 197 WalkState); 198 if (ACPI_FAILURE (Status)) 199 { 200 return_ACPI_STATUS (Status); 201 } 202 } 203 204 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr)); 205 return_ACPI_STATUS (AE_OK); 206 } 207 208 209 /******************************************************************************* 210 * 211 * FUNCTION: AcpiExResolveObjectToValue 212 * 213 * PARAMETERS: StackPtr - Pointer to an internal object 214 * WalkState - Current method state 215 * 216 * RETURN: Status 217 * 218 * DESCRIPTION: Retrieve the value from an internal object. The Reference type 219 * uses the associated AML opcode to determine the value. 220 * 221 ******************************************************************************/ 222 223 static ACPI_STATUS 224 AcpiExResolveObjectToValue ( 225 ACPI_OPERAND_OBJECT **StackPtr, 226 ACPI_WALK_STATE *WalkState) 227 { 228 ACPI_STATUS Status = AE_OK; 229 ACPI_OPERAND_OBJECT *StackDesc; 230 ACPI_OPERAND_OBJECT *ObjDesc = NULL; 231 UINT8 RefType; 232 233 234 ACPI_FUNCTION_TRACE (ExResolveObjectToValue); 235 236 237 StackDesc = *StackPtr; 238 239 /* This is an object of type ACPI_OPERAND_OBJECT */ 240 241 switch (StackDesc->Common.Type) 242 { 243 case ACPI_TYPE_LOCAL_REFERENCE: 244 245 RefType = StackDesc->Reference.Class; 246 247 switch (RefType) 248 { 249 case ACPI_REFCLASS_LOCAL: 250 case ACPI_REFCLASS_ARG: 251 /* 252 * Get the local from the method's state info 253 * Note: this increments the local's object reference count 254 */ 255 Status = AcpiDsMethodDataGetValue (RefType, 256 StackDesc->Reference.Value, WalkState, &ObjDesc); 257 if (ACPI_FAILURE (Status)) 258 { 259 return_ACPI_STATUS (Status); 260 } 261 262 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n", 263 StackDesc->Reference.Value, ObjDesc)); 264 265 /* 266 * Now we can delete the original Reference Object and 267 * replace it with the resolved value 268 */ 269 AcpiUtRemoveReference (StackDesc); 270 *StackPtr = ObjDesc; 271 break; 272 273 case ACPI_REFCLASS_INDEX: 274 275 switch (StackDesc->Reference.TargetType) 276 { 277 case ACPI_TYPE_BUFFER_FIELD: 278 279 /* Just return - do not dereference */ 280 break; 281 282 case ACPI_TYPE_PACKAGE: 283 284 /* If method call or CopyObject - do not dereference */ 285 286 if ((WalkState->Opcode == AML_INT_METHODCALL_OP) || 287 (WalkState->Opcode == AML_COPY_OP)) 288 { 289 break; 290 } 291 292 /* Otherwise, dereference the PackageIndex to a package element */ 293 294 ObjDesc = *StackDesc->Reference.Where; 295 if (ObjDesc) 296 { 297 /* 298 * Valid object descriptor, copy pointer to return value 299 * (i.e., dereference the package index) 300 * Delete the ref object, increment the returned object 301 */ 302 AcpiUtRemoveReference (StackDesc); 303 AcpiUtAddReference (ObjDesc); 304 *StackPtr = ObjDesc; 305 } 306 else 307 { 308 /* 309 * A NULL object descriptor means an uninitialized element of 310 * the package, can't dereference it 311 */ 312 ACPI_ERROR ((AE_INFO, 313 "Attempt to dereference an Index to NULL package element Idx=%p", 314 StackDesc)); 315 Status = AE_AML_UNINITIALIZED_ELEMENT; 316 } 317 break; 318 319 default: 320 321 /* Invalid reference object */ 322 323 ACPI_ERROR ((AE_INFO, 324 "Unknown TargetType 0x%X in Index/Reference object %p", 325 StackDesc->Reference.TargetType, StackDesc)); 326 Status = AE_AML_INTERNAL; 327 break; 328 } 329 break; 330 331 case ACPI_REFCLASS_REFOF: 332 case ACPI_REFCLASS_DEBUG: 333 case ACPI_REFCLASS_TABLE: 334 335 /* Just leave the object as-is, do not dereference */ 336 337 break; 338 339 case ACPI_REFCLASS_NAME: /* Reference to a named object */ 340 341 /* Dereference the name */ 342 343 if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) || 344 (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL)) 345 { 346 /* These node types do not have 'real' subobjects */ 347 348 *StackPtr = (void *) StackDesc->Reference.Node; 349 } 350 else 351 { 352 /* Get the object pointed to by the namespace node */ 353 354 *StackPtr = (StackDesc->Reference.Node)->Object; 355 AcpiUtAddReference (*StackPtr); 356 } 357 358 AcpiUtRemoveReference (StackDesc); 359 break; 360 361 default: 362 363 ACPI_ERROR ((AE_INFO, 364 "Unknown Reference type 0x%X in %p", RefType, StackDesc)); 365 Status = AE_AML_INTERNAL; 366 break; 367 } 368 break; 369 370 case ACPI_TYPE_BUFFER: 371 372 Status = AcpiDsGetBufferArguments (StackDesc); 373 break; 374 375 case ACPI_TYPE_PACKAGE: 376 377 Status = AcpiDsGetPackageArguments (StackDesc); 378 break; 379 380 case ACPI_TYPE_BUFFER_FIELD: 381 case ACPI_TYPE_LOCAL_REGION_FIELD: 382 case ACPI_TYPE_LOCAL_BANK_FIELD: 383 case ACPI_TYPE_LOCAL_INDEX_FIELD: 384 385 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead SourceDesc=%p Type=%X\n", 386 StackDesc, StackDesc->Common.Type)); 387 388 Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc); 389 390 /* Remove a reference to the original operand, then override */ 391 392 AcpiUtRemoveReference (*StackPtr); 393 *StackPtr = (void *) ObjDesc; 394 break; 395 396 default: 397 398 break; 399 } 400 401 return_ACPI_STATUS (Status); 402 } 403 404 405 /******************************************************************************* 406 * 407 * FUNCTION: AcpiExResolveMultiple 408 * 409 * PARAMETERS: WalkState - Current state (contains AML opcode) 410 * Operand - Starting point for resolution 411 * ReturnType - Where the object type is returned 412 * ReturnDesc - Where the resolved object is returned 413 * 414 * RETURN: Status 415 * 416 * DESCRIPTION: Return the base object and type. Traverse a reference list if 417 * necessary to get to the base object. 418 * 419 ******************************************************************************/ 420 421 ACPI_STATUS 422 AcpiExResolveMultiple ( 423 ACPI_WALK_STATE *WalkState, 424 ACPI_OPERAND_OBJECT *Operand, 425 ACPI_OBJECT_TYPE *ReturnType, 426 ACPI_OPERAND_OBJECT **ReturnDesc) 427 { 428 ACPI_OPERAND_OBJECT *ObjDesc = (void *) Operand; 429 ACPI_NAMESPACE_NODE *Node; 430 ACPI_OBJECT_TYPE Type; 431 ACPI_STATUS Status; 432 433 434 ACPI_FUNCTION_TRACE (AcpiExResolveMultiple); 435 436 437 /* Operand can be either a namespace node or an operand descriptor */ 438 439 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)) 440 { 441 case ACPI_DESC_TYPE_OPERAND: 442 443 Type = ObjDesc->Common.Type; 444 break; 445 446 case ACPI_DESC_TYPE_NAMED: 447 448 Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type; 449 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc); 450 451 /* If we had an Alias node, use the attached object for type info */ 452 453 if (Type == ACPI_TYPE_LOCAL_ALIAS) 454 { 455 Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type; 456 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc); 457 } 458 break; 459 460 default: 461 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 462 } 463 464 /* If type is anything other than a reference, we are done */ 465 466 if (Type != ACPI_TYPE_LOCAL_REFERENCE) 467 { 468 goto Exit; 469 } 470 471 /* 472 * For reference objects created via the RefOf, Index, or Load/LoadTable 473 * operators, we need to get to the base object (as per the ACPI 474 * specification of the ObjectType and SizeOf operators). This means 475 * traversing the list of possibly many nested references. 476 */ 477 while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) 478 { 479 switch (ObjDesc->Reference.Class) 480 { 481 case ACPI_REFCLASS_REFOF: 482 case ACPI_REFCLASS_NAME: 483 484 /* Dereference the reference pointer */ 485 486 if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF) 487 { 488 Node = ObjDesc->Reference.Object; 489 } 490 else /* AML_INT_NAMEPATH_OP */ 491 { 492 Node = ObjDesc->Reference.Node; 493 } 494 495 /* All "References" point to a NS node */ 496 497 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED) 498 { 499 ACPI_ERROR ((AE_INFO, 500 "Not a namespace node %p [%s]", 501 Node, AcpiUtGetDescriptorName (Node))); 502 return_ACPI_STATUS (AE_AML_INTERNAL); 503 } 504 505 /* Get the attached object */ 506 507 ObjDesc = AcpiNsGetAttachedObject (Node); 508 if (!ObjDesc) 509 { 510 /* No object, use the NS node type */ 511 512 Type = AcpiNsGetType (Node); 513 goto Exit; 514 } 515 516 /* Check for circular references */ 517 518 if (ObjDesc == Operand) 519 { 520 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE); 521 } 522 break; 523 524 case ACPI_REFCLASS_INDEX: 525 526 /* Get the type of this reference (index into another object) */ 527 528 Type = ObjDesc->Reference.TargetType; 529 if (Type != ACPI_TYPE_PACKAGE) 530 { 531 goto Exit; 532 } 533 534 /* 535 * The main object is a package, we want to get the type 536 * of the individual package element that is referenced by 537 * the index. 538 * 539 * This could of course in turn be another reference object. 540 */ 541 ObjDesc = *(ObjDesc->Reference.Where); 542 if (!ObjDesc) 543 { 544 /* NULL package elements are allowed */ 545 546 Type = 0; /* Uninitialized */ 547 goto Exit; 548 } 549 break; 550 551 case ACPI_REFCLASS_TABLE: 552 553 Type = ACPI_TYPE_DDB_HANDLE; 554 goto Exit; 555 556 case ACPI_REFCLASS_LOCAL: 557 case ACPI_REFCLASS_ARG: 558 559 if (ReturnDesc) 560 { 561 Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class, 562 ObjDesc->Reference.Value, WalkState, &ObjDesc); 563 if (ACPI_FAILURE (Status)) 564 { 565 return_ACPI_STATUS (Status); 566 } 567 AcpiUtRemoveReference (ObjDesc); 568 } 569 else 570 { 571 Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class, 572 ObjDesc->Reference.Value, WalkState, &Node); 573 if (ACPI_FAILURE (Status)) 574 { 575 return_ACPI_STATUS (Status); 576 } 577 578 ObjDesc = AcpiNsGetAttachedObject (Node); 579 if (!ObjDesc) 580 { 581 Type = ACPI_TYPE_ANY; 582 goto Exit; 583 } 584 } 585 break; 586 587 case ACPI_REFCLASS_DEBUG: 588 589 /* The Debug Object is of type "DebugObject" */ 590 591 Type = ACPI_TYPE_DEBUG_OBJECT; 592 goto Exit; 593 594 default: 595 596 ACPI_ERROR ((AE_INFO, 597 "Unknown Reference Class 0x%2.2X", ObjDesc->Reference.Class)); 598 return_ACPI_STATUS (AE_AML_INTERNAL); 599 } 600 } 601 602 /* 603 * Now we are guaranteed to have an object that has not been created 604 * via the RefOf or Index operators. 605 */ 606 Type = ObjDesc->Common.Type; 607 608 609 Exit: 610 /* Convert internal types to external types */ 611 612 switch (Type) 613 { 614 case ACPI_TYPE_LOCAL_REGION_FIELD: 615 case ACPI_TYPE_LOCAL_BANK_FIELD: 616 case ACPI_TYPE_LOCAL_INDEX_FIELD: 617 618 Type = ACPI_TYPE_FIELD_UNIT; 619 break; 620 621 case ACPI_TYPE_LOCAL_SCOPE: 622 623 /* Per ACPI Specification, Scope is untyped */ 624 625 Type = ACPI_TYPE_ANY; 626 break; 627 628 default: 629 630 /* No change to Type required */ 631 632 break; 633 } 634 635 *ReturnType = Type; 636 if (ReturnDesc) 637 { 638 *ReturnDesc = ObjDesc; 639 } 640 return_ACPI_STATUS (AE_OK); 641 } 642