1 /****************************************************************************** 2 * 3 * Module Name: dsobject - Dispatcher object management routines 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2015, 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 #include "acpi.h" 117 #include "accommon.h" 118 #include "acparser.h" 119 #include "amlcode.h" 120 #include "acdispat.h" 121 #include "acnamesp.h" 122 #include "acinterp.h" 123 124 #define _COMPONENT ACPI_DISPATCHER 125 ACPI_MODULE_NAME ("dsobject") 126 127 /* Local prototypes */ 128 129 static ACPI_STATUS 130 AcpiDsBuildInternalObject ( 131 ACPI_WALK_STATE *WalkState, 132 ACPI_PARSE_OBJECT *Op, 133 ACPI_OPERAND_OBJECT **ObjDescPtr); 134 135 136 #ifndef ACPI_NO_METHOD_EXECUTION 137 /******************************************************************************* 138 * 139 * FUNCTION: AcpiDsBuildInternalObject 140 * 141 * PARAMETERS: WalkState - Current walk state 142 * Op - Parser object to be translated 143 * ObjDescPtr - Where the ACPI internal object is returned 144 * 145 * RETURN: Status 146 * 147 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object 148 * Simple objects are any objects other than a package object! 149 * 150 ******************************************************************************/ 151 152 static ACPI_STATUS 153 AcpiDsBuildInternalObject ( 154 ACPI_WALK_STATE *WalkState, 155 ACPI_PARSE_OBJECT *Op, 156 ACPI_OPERAND_OBJECT **ObjDescPtr) 157 { 158 ACPI_OPERAND_OBJECT *ObjDesc; 159 ACPI_STATUS Status; 160 ACPI_OBJECT_TYPE Type; 161 162 163 ACPI_FUNCTION_TRACE (DsBuildInternalObject); 164 165 166 *ObjDescPtr = NULL; 167 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP) 168 { 169 /* 170 * This is a named object reference. If this name was 171 * previously looked up in the namespace, it was stored in this op. 172 * Otherwise, go ahead and look it up now 173 */ 174 if (!Op->Common.Node) 175 { 176 Status = AcpiNsLookup (WalkState->ScopeInfo, 177 Op->Common.Value.String, 178 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 179 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, 180 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node))); 181 if (ACPI_FAILURE (Status)) 182 { 183 /* Check if we are resolving a named reference within a package */ 184 185 if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) && 186 187 ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 188 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))) 189 { 190 /* 191 * We didn't find the target and we are populating elements 192 * of a package - ignore if slack enabled. Some ASL code 193 * contains dangling invalid references in packages and 194 * expects that no exception will be issued. Leave the 195 * element as a null element. It cannot be used, but it 196 * can be overwritten by subsequent ASL code - this is 197 * typically the case. 198 */ 199 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 200 "Ignoring unresolved reference in package [%4.4s]\n", 201 WalkState->ScopeInfo->Scope.Node->Name.Ascii)); 202 203 return_ACPI_STATUS (AE_OK); 204 } 205 else 206 { 207 ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status); 208 } 209 210 return_ACPI_STATUS (Status); 211 } 212 } 213 214 /* Special object resolution for elements of a package */ 215 216 if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 217 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) 218 { 219 /* 220 * Attempt to resolve the node to a value before we insert it into 221 * the package. If this is a reference to a common data type, 222 * resolve it immediately. According to the ACPI spec, package 223 * elements can only be "data objects" or method references. 224 * Attempt to resolve to an Integer, Buffer, String or Package. 225 * If cannot, return the named reference (for things like Devices, 226 * Methods, etc.) Buffer Fields and Fields will resolve to simple 227 * objects (int/buf/str/pkg). 228 * 229 * NOTE: References to things like Devices, Methods, Mutexes, etc. 230 * will remain as named references. This behavior is not described 231 * in the ACPI spec, but it appears to be an oversight. 232 */ 233 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node); 234 235 Status = AcpiExResolveNodeToValue ( 236 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc), 237 WalkState); 238 if (ACPI_FAILURE (Status)) 239 { 240 return_ACPI_STATUS (Status); 241 } 242 243 /* 244 * Special handling for Alias objects. We need to setup the type 245 * and the Op->Common.Node to point to the Alias target. Note, 246 * Alias has at most one level of indirection internally. 247 */ 248 Type = Op->Common.Node->Type; 249 if (Type == ACPI_TYPE_LOCAL_ALIAS) 250 { 251 Type = ObjDesc->Common.Type; 252 Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 253 Op->Common.Node->Object); 254 } 255 256 switch (Type) 257 { 258 /* 259 * For these types, we need the actual node, not the subobject. 260 * However, the subobject did not get an extra reference count above. 261 * 262 * TBD: should ExResolveNodeToValue be changed to fix this? 263 */ 264 case ACPI_TYPE_DEVICE: 265 case ACPI_TYPE_THERMAL: 266 267 AcpiUtAddReference (Op->Common.Node->Object); 268 269 /*lint -fallthrough */ 270 /* 271 * For these types, we need the actual node, not the subobject. 272 * The subobject got an extra reference count in ExResolveNodeToValue. 273 */ 274 case ACPI_TYPE_MUTEX: 275 case ACPI_TYPE_METHOD: 276 case ACPI_TYPE_POWER: 277 case ACPI_TYPE_PROCESSOR: 278 case ACPI_TYPE_EVENT: 279 case ACPI_TYPE_REGION: 280 281 /* We will create a reference object for these types below */ 282 break; 283 284 default: 285 /* 286 * All other types - the node was resolved to an actual 287 * object, we are done. 288 */ 289 goto Exit; 290 } 291 } 292 } 293 294 /* Create and init a new internal ACPI object */ 295 296 ObjDesc = AcpiUtCreateInternalObject ( 297 (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType); 298 if (!ObjDesc) 299 { 300 return_ACPI_STATUS (AE_NO_MEMORY); 301 } 302 303 Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode, 304 &ObjDesc); 305 if (ACPI_FAILURE (Status)) 306 { 307 AcpiUtRemoveReference (ObjDesc); 308 return_ACPI_STATUS (Status); 309 } 310 311 Exit: 312 *ObjDescPtr = ObjDesc; 313 return_ACPI_STATUS (Status); 314 } 315 316 317 /******************************************************************************* 318 * 319 * FUNCTION: AcpiDsBuildInternalBufferObj 320 * 321 * PARAMETERS: WalkState - Current walk state 322 * Op - Parser object to be translated 323 * BufferLength - Length of the buffer 324 * ObjDescPtr - Where the ACPI internal object is returned 325 * 326 * RETURN: Status 327 * 328 * DESCRIPTION: Translate a parser Op package object to the equivalent 329 * namespace object 330 * 331 ******************************************************************************/ 332 333 ACPI_STATUS 334 AcpiDsBuildInternalBufferObj ( 335 ACPI_WALK_STATE *WalkState, 336 ACPI_PARSE_OBJECT *Op, 337 UINT32 BufferLength, 338 ACPI_OPERAND_OBJECT **ObjDescPtr) 339 { 340 ACPI_PARSE_OBJECT *Arg; 341 ACPI_OPERAND_OBJECT *ObjDesc; 342 ACPI_PARSE_OBJECT *ByteList; 343 UINT32 ByteListLength = 0; 344 345 346 ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj); 347 348 349 /* 350 * If we are evaluating a Named buffer object "Name (xxxx, Buffer)". 351 * The buffer object already exists (from the NS node), otherwise it must 352 * be created. 353 */ 354 ObjDesc = *ObjDescPtr; 355 if (!ObjDesc) 356 { 357 /* Create a new buffer object */ 358 359 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 360 *ObjDescPtr = ObjDesc; 361 if (!ObjDesc) 362 { 363 return_ACPI_STATUS (AE_NO_MEMORY); 364 } 365 } 366 367 /* 368 * Second arg is the buffer data (optional) ByteList can be either 369 * individual bytes or a string initializer. In either case, a 370 * ByteList appears in the AML. 371 */ 372 Arg = Op->Common.Value.Arg; /* skip first arg */ 373 374 ByteList = Arg->Named.Next; 375 if (ByteList) 376 { 377 if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP) 378 { 379 ACPI_ERROR ((AE_INFO, 380 "Expecting bytelist, found AML opcode 0x%X in op %p", 381 ByteList->Common.AmlOpcode, ByteList)); 382 383 AcpiUtRemoveReference (ObjDesc); 384 return (AE_TYPE); 385 } 386 387 ByteListLength = (UINT32) ByteList->Common.Value.Integer; 388 } 389 390 /* 391 * The buffer length (number of bytes) will be the larger of: 392 * 1) The specified buffer length and 393 * 2) The length of the initializer byte list 394 */ 395 ObjDesc->Buffer.Length = BufferLength; 396 if (ByteListLength > BufferLength) 397 { 398 ObjDesc->Buffer.Length = ByteListLength; 399 } 400 401 /* Allocate the buffer */ 402 403 if (ObjDesc->Buffer.Length == 0) 404 { 405 ObjDesc->Buffer.Pointer = NULL; 406 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 407 "Buffer defined with zero length in AML, creating\n")); 408 } 409 else 410 { 411 ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED ( 412 ObjDesc->Buffer.Length); 413 if (!ObjDesc->Buffer.Pointer) 414 { 415 AcpiUtDeleteObjectDesc (ObjDesc); 416 return_ACPI_STATUS (AE_NO_MEMORY); 417 } 418 419 /* Initialize buffer from the ByteList (if present) */ 420 421 if (ByteList) 422 { 423 memcpy (ObjDesc->Buffer.Pointer, ByteList->Named.Data, 424 ByteListLength); 425 } 426 } 427 428 ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID; 429 Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc); 430 return_ACPI_STATUS (AE_OK); 431 } 432 433 434 /******************************************************************************* 435 * 436 * FUNCTION: AcpiDsBuildInternalPackageObj 437 * 438 * PARAMETERS: WalkState - Current walk state 439 * Op - Parser object to be translated 440 * ElementCount - Number of elements in the package - this is 441 * the NumElements argument to Package() 442 * ObjDescPtr - Where the ACPI internal object is returned 443 * 444 * RETURN: Status 445 * 446 * DESCRIPTION: Translate a parser Op package object to the equivalent 447 * namespace object 448 * 449 * NOTE: The number of elements in the package will be always be the NumElements 450 * count, regardless of the number of elements in the package list. If 451 * NumElements is smaller, only that many package list elements are used. 452 * if NumElements is larger, the Package object is padded out with 453 * objects of type Uninitialized (as per ACPI spec.) 454 * 455 * Even though the ASL compilers do not allow NumElements to be smaller 456 * than the Package list length (for the fixed length package opcode), some 457 * BIOS code modifies the AML on the fly to adjust the NumElements, and 458 * this code compensates for that. This also provides compatibility with 459 * other AML interpreters. 460 * 461 ******************************************************************************/ 462 463 ACPI_STATUS 464 AcpiDsBuildInternalPackageObj ( 465 ACPI_WALK_STATE *WalkState, 466 ACPI_PARSE_OBJECT *Op, 467 UINT32 ElementCount, 468 ACPI_OPERAND_OBJECT **ObjDescPtr) 469 { 470 ACPI_PARSE_OBJECT *Arg; 471 ACPI_PARSE_OBJECT *Parent; 472 ACPI_OPERAND_OBJECT *ObjDesc = NULL; 473 ACPI_STATUS Status = AE_OK; 474 UINT32 i; 475 UINT16 Index; 476 UINT16 ReferenceCount; 477 478 479 ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj); 480 481 482 /* Find the parent of a possibly nested package */ 483 484 Parent = Op->Common.Parent; 485 while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 486 (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) 487 { 488 Parent = Parent->Common.Parent; 489 } 490 491 /* 492 * If we are evaluating a Named package object "Name (xxxx, Package)", 493 * the package object already exists, otherwise it must be created. 494 */ 495 ObjDesc = *ObjDescPtr; 496 if (!ObjDesc) 497 { 498 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE); 499 *ObjDescPtr = ObjDesc; 500 if (!ObjDesc) 501 { 502 return_ACPI_STATUS (AE_NO_MEMORY); 503 } 504 505 ObjDesc->Package.Node = Parent->Common.Node; 506 } 507 508 /* 509 * Allocate the element array (array of pointers to the individual 510 * objects) based on the NumElements parameter. Add an extra pointer slot 511 * so that the list is always null terminated. 512 */ 513 ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED ( 514 ((ACPI_SIZE) ElementCount + 1) * sizeof (void *)); 515 516 if (!ObjDesc->Package.Elements) 517 { 518 AcpiUtDeleteObjectDesc (ObjDesc); 519 return_ACPI_STATUS (AE_NO_MEMORY); 520 } 521 522 ObjDesc->Package.Count = ElementCount; 523 524 /* 525 * Initialize the elements of the package, up to the NumElements count. 526 * Package is automatically padded with uninitialized (NULL) elements 527 * if NumElements is greater than the package list length. Likewise, 528 * Package is truncated if NumElements is less than the list length. 529 */ 530 Arg = Op->Common.Value.Arg; 531 Arg = Arg->Common.Next; 532 for (i = 0; Arg && (i < ElementCount); i++) 533 { 534 if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP) 535 { 536 if (Arg->Common.Node->Type == ACPI_TYPE_METHOD) 537 { 538 /* 539 * A method reference "looks" to the parser to be a method 540 * invocation, so we special case it here 541 */ 542 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP; 543 Status = AcpiDsBuildInternalObject (WalkState, Arg, 544 &ObjDesc->Package.Elements[i]); 545 } 546 else 547 { 548 /* This package element is already built, just get it */ 549 550 ObjDesc->Package.Elements[i] = 551 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node); 552 } 553 } 554 else 555 { 556 Status = AcpiDsBuildInternalObject (WalkState, Arg, 557 &ObjDesc->Package.Elements[i]); 558 } 559 560 if (*ObjDescPtr) 561 { 562 /* Existing package, get existing reference count */ 563 564 ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount; 565 if (ReferenceCount > 1) 566 { 567 /* Make new element ref count match original ref count */ 568 569 for (Index = 0; Index < (ReferenceCount - 1); Index++) 570 { 571 AcpiUtAddReference ((ObjDesc->Package.Elements[i])); 572 } 573 } 574 } 575 576 Arg = Arg->Common.Next; 577 } 578 579 /* Check for match between NumElements and actual length of PackageList */ 580 581 if (Arg) 582 { 583 /* 584 * NumElements was exhausted, but there are remaining elements in the 585 * PackageList. Truncate the package to NumElements. 586 * 587 * Note: technically, this is an error, from ACPI spec: "It is an error 588 * for NumElements to be less than the number of elements in the 589 * PackageList". However, we just print a message and 590 * no exception is returned. This provides Windows compatibility. Some 591 * BIOSs will alter the NumElements on the fly, creating this type 592 * of ill-formed package object. 593 */ 594 while (Arg) 595 { 596 /* 597 * We must delete any package elements that were created earlier 598 * and are not going to be used because of the package truncation. 599 */ 600 if (Arg->Common.Node) 601 { 602 AcpiUtRemoveReference ( 603 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node)); 604 Arg->Common.Node = NULL; 605 } 606 607 /* Find out how many elements there really are */ 608 609 i++; 610 Arg = Arg->Common.Next; 611 } 612 613 ACPI_INFO ((AE_INFO, 614 "Actual Package length (%u) is larger than NumElements field (%u), truncated", 615 i, ElementCount)); 616 } 617 else if (i < ElementCount) 618 { 619 /* 620 * Arg list (elements) was exhausted, but we did not reach NumElements count. 621 * Note: this is not an error, the package is padded out with NULLs. 622 */ 623 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 624 "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n", 625 i, ElementCount)); 626 } 627 628 ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID; 629 Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc); 630 return_ACPI_STATUS (Status); 631 } 632 633 634 /******************************************************************************* 635 * 636 * FUNCTION: AcpiDsCreateNode 637 * 638 * PARAMETERS: WalkState - Current walk state 639 * Node - NS Node to be initialized 640 * Op - Parser object to be translated 641 * 642 * RETURN: Status 643 * 644 * DESCRIPTION: Create the object to be associated with a namespace node 645 * 646 ******************************************************************************/ 647 648 ACPI_STATUS 649 AcpiDsCreateNode ( 650 ACPI_WALK_STATE *WalkState, 651 ACPI_NAMESPACE_NODE *Node, 652 ACPI_PARSE_OBJECT *Op) 653 { 654 ACPI_STATUS Status; 655 ACPI_OPERAND_OBJECT *ObjDesc; 656 657 658 ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op); 659 660 661 /* 662 * Because of the execution pass through the non-control-method 663 * parts of the table, we can arrive here twice. Only init 664 * the named object node the first time through 665 */ 666 if (AcpiNsGetAttachedObject (Node)) 667 { 668 return_ACPI_STATUS (AE_OK); 669 } 670 671 if (!Op->Common.Value.Arg) 672 { 673 /* No arguments, there is nothing to do */ 674 675 return_ACPI_STATUS (AE_OK); 676 } 677 678 /* Build an internal object for the argument(s) */ 679 680 Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg, 681 &ObjDesc); 682 if (ACPI_FAILURE (Status)) 683 { 684 return_ACPI_STATUS (Status); 685 } 686 687 /* Re-type the object according to its argument */ 688 689 Node->Type = ObjDesc->Common.Type; 690 691 /* Attach obj to node */ 692 693 Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type); 694 695 /* Remove local reference to the object */ 696 697 AcpiUtRemoveReference (ObjDesc); 698 return_ACPI_STATUS (Status); 699 } 700 701 #endif /* ACPI_NO_METHOD_EXECUTION */ 702 703 704 /******************************************************************************* 705 * 706 * FUNCTION: AcpiDsInitObjectFromOp 707 * 708 * PARAMETERS: WalkState - Current walk state 709 * Op - Parser op used to init the internal object 710 * Opcode - AML opcode associated with the object 711 * RetObjDesc - Namespace object to be initialized 712 * 713 * RETURN: Status 714 * 715 * DESCRIPTION: Initialize a namespace object from a parser Op and its 716 * associated arguments. The namespace object is a more compact 717 * representation of the Op and its arguments. 718 * 719 ******************************************************************************/ 720 721 ACPI_STATUS 722 AcpiDsInitObjectFromOp ( 723 ACPI_WALK_STATE *WalkState, 724 ACPI_PARSE_OBJECT *Op, 725 UINT16 Opcode, 726 ACPI_OPERAND_OBJECT **RetObjDesc) 727 { 728 const ACPI_OPCODE_INFO *OpInfo; 729 ACPI_OPERAND_OBJECT *ObjDesc; 730 ACPI_STATUS Status = AE_OK; 731 732 733 ACPI_FUNCTION_TRACE (DsInitObjectFromOp); 734 735 736 ObjDesc = *RetObjDesc; 737 OpInfo = AcpiPsGetOpcodeInfo (Opcode); 738 if (OpInfo->Class == AML_CLASS_UNKNOWN) 739 { 740 /* Unknown opcode */ 741 742 return_ACPI_STATUS (AE_TYPE); 743 } 744 745 /* Perform per-object initialization */ 746 747 switch (ObjDesc->Common.Type) 748 { 749 case ACPI_TYPE_BUFFER: 750 /* 751 * Defer evaluation of Buffer TermArg operand 752 */ 753 ObjDesc->Buffer.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 754 WalkState->Operands[0]); 755 ObjDesc->Buffer.AmlStart = Op->Named.Data; 756 ObjDesc->Buffer.AmlLength = Op->Named.Length; 757 break; 758 759 case ACPI_TYPE_PACKAGE: 760 /* 761 * Defer evaluation of Package TermArg operand 762 */ 763 ObjDesc->Package.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 764 WalkState->Operands[0]); 765 ObjDesc->Package.AmlStart = Op->Named.Data; 766 ObjDesc->Package.AmlLength = Op->Named.Length; 767 break; 768 769 case ACPI_TYPE_INTEGER: 770 771 switch (OpInfo->Type) 772 { 773 case AML_TYPE_CONSTANT: 774 /* 775 * Resolve AML Constants here - AND ONLY HERE! 776 * All constants are integers. 777 * We mark the integer with a flag that indicates that it started 778 * life as a constant -- so that stores to constants will perform 779 * as expected (noop). ZeroOp is used as a placeholder for optional 780 * target operands. 781 */ 782 ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT; 783 784 switch (Opcode) 785 { 786 case AML_ZERO_OP: 787 788 ObjDesc->Integer.Value = 0; 789 break; 790 791 case AML_ONE_OP: 792 793 ObjDesc->Integer.Value = 1; 794 break; 795 796 case AML_ONES_OP: 797 798 ObjDesc->Integer.Value = ACPI_UINT64_MAX; 799 800 /* Truncate value if we are executing from a 32-bit ACPI table */ 801 802 #ifndef ACPI_NO_METHOD_EXECUTION 803 (void) AcpiExTruncateFor32bitTable (ObjDesc); 804 #endif 805 break; 806 807 case AML_REVISION_OP: 808 809 ObjDesc->Integer.Value = ACPI_CA_VERSION; 810 break; 811 812 default: 813 814 ACPI_ERROR ((AE_INFO, 815 "Unknown constant opcode 0x%X", Opcode)); 816 Status = AE_AML_OPERAND_TYPE; 817 break; 818 } 819 break; 820 821 case AML_TYPE_LITERAL: 822 823 ObjDesc->Integer.Value = Op->Common.Value.Integer; 824 825 #ifndef ACPI_NO_METHOD_EXECUTION 826 if (AcpiExTruncateFor32bitTable (ObjDesc)) 827 { 828 /* Warn if we found a 64-bit constant in a 32-bit table */ 829 830 ACPI_WARNING ((AE_INFO, 831 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X", 832 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer), 833 (UINT32) ObjDesc->Integer.Value)); 834 } 835 #endif 836 break; 837 838 default: 839 840 ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X", 841 OpInfo->Type)); 842 Status = AE_AML_OPERAND_TYPE; 843 break; 844 } 845 break; 846 847 case ACPI_TYPE_STRING: 848 849 ObjDesc->String.Pointer = Op->Common.Value.String; 850 ObjDesc->String.Length = (UINT32) strlen (Op->Common.Value.String); 851 852 /* 853 * The string is contained in the ACPI table, don't ever try 854 * to delete it 855 */ 856 ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER; 857 break; 858 859 case ACPI_TYPE_METHOD: 860 break; 861 862 case ACPI_TYPE_LOCAL_REFERENCE: 863 864 switch (OpInfo->Type) 865 { 866 case AML_TYPE_LOCAL_VARIABLE: 867 868 /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */ 869 870 ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP; 871 ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL; 872 873 #ifndef ACPI_NO_METHOD_EXECUTION 874 Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL, 875 ObjDesc->Reference.Value, WalkState, 876 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, 877 &ObjDesc->Reference.Object)); 878 #endif 879 break; 880 881 case AML_TYPE_METHOD_ARGUMENT: 882 883 /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */ 884 885 ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP; 886 ObjDesc->Reference.Class = ACPI_REFCLASS_ARG; 887 888 #ifndef ACPI_NO_METHOD_EXECUTION 889 Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG, 890 ObjDesc->Reference.Value, WalkState, 891 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, 892 &ObjDesc->Reference.Object)); 893 #endif 894 break; 895 896 default: /* Object name or Debug object */ 897 898 switch (Op->Common.AmlOpcode) 899 { 900 case AML_INT_NAMEPATH_OP: 901 902 /* Node was saved in Op */ 903 904 ObjDesc->Reference.Node = Op->Common.Node; 905 ObjDesc->Reference.Object = Op->Common.Node->Object; 906 ObjDesc->Reference.Class = ACPI_REFCLASS_NAME; 907 break; 908 909 case AML_DEBUG_OP: 910 911 ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG; 912 break; 913 914 default: 915 916 ACPI_ERROR ((AE_INFO, 917 "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode)); 918 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 919 } 920 break; 921 } 922 break; 923 924 default: 925 926 ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X", 927 ObjDesc->Common.Type)); 928 929 Status = AE_AML_OPERAND_TYPE; 930 break; 931 } 932 933 return_ACPI_STATUS (Status); 934 } 935