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