dsmthdat.c revision 71867
1331722Seadler/******************************************************************************* 211814Swpaul * 311814Swpaul * Module Name: dsmthdat - control method arguments and local variables 411814Swpaul * $Revision: 39 $ 511814Swpaul * 611814Swpaul ******************************************************************************/ 711814Swpaul 811814Swpaul/****************************************************************************** 911814Swpaul * 1011814Swpaul * 1. Copyright Notice 1111814Swpaul * 1211814Swpaul * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 1311814Swpaul * All rights reserved. 1411814Swpaul * 1511814Swpaul * 2. License 16262136Sbrueffer * 1711814Swpaul * 2.1. This is your license from Intel Corp. under its intellectual property 1811814Swpaul * rights. You may have additional license terms from the party that provided 1911814Swpaul * you this software, covering your right to use that party's intellectual 2011814Swpaul * property rights. 2111814Swpaul * 2211814Swpaul * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2311814Swpaul * copy of the source code appearing in this file ("Covered Code") an 2411814Swpaul * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2511814Swpaul * base code distributed originally by Intel ("Original Intel Code") to copy, 2611814Swpaul * make derivatives, distribute, use and display any portion of the Covered 2711814Swpaul * Code in any form, with the right to sublicense such rights; and 2811814Swpaul * 2911814Swpaul * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3011814Swpaul * license (with the right to sublicense), under only those claims of Intel 3111814Swpaul * patents that are infringed by the Original Intel Code, to make, use, sell, 3211814Swpaul * offer to sell, and import the Covered Code and derivative works thereof 3331404Scharnier * solely to the minimum extent necessary to exercise the above copyright 3431404Scharnier * license, and in no event shall the patent license extend to any additions 3550476Speter * to or modifications of the Original Intel Code. No other license or right 3631404Scharnier * is granted directly or by implication, estoppel or otherwise; 3711814Swpaul * 3811814Swpaul * The above copyright and patent license is granted only if the following 3911814Swpaul * conditions are met: 4011814Swpaul * 4111814Swpaul * 3. Conditions 4211814Swpaul * 4311814Swpaul * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4411814Swpaul * Redistribution of source code of any substantial portion of the Covered 4511814Swpaul * Code or modification with rights to further distribute source must include 4693590Smike * the above Copyright Notice, the above License, this list of Conditions, 4711814Swpaul * and the following Disclaimer and Export Compliance provision. In addition, 4811814Swpaul * Licensee must cause all Covered Code to which Licensee contributes to 4911814Swpaul * contain a file documenting the changes Licensee made to create that Covered 5011814Swpaul * Code and the date of any change. Licensee must include in that file the 5111814Swpaul * documentation of any changes made by any predecessor Licensee. Licensee 5211814Swpaul * must include a prominent statement that the modification is derived, 5311814Swpaul * directly or indirectly, from Original Intel Code. 5411814Swpaul * 5511814Swpaul * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5611814Swpaul * Redistribution of source code of any substantial portion of the Covered 5711814Swpaul * Code or modification without rights to further distribute source must 5811814Swpaul * include the following Disclaimer and Export Compliance provision in the 5911814Swpaul * documentation and/or other materials provided with distribution. In 6011814Swpaul * addition, Licensee may not authorize further sublicense of source of any 6111814Swpaul * portion of the Covered Code, and must include terms to the effect that the 6211814Swpaul * license from Licensee to its licensee is limited to the intellectual 6311814Swpaul * property embodied in the software Licensee provides to its licensee, and 6411814Swpaul * not to intellectual property embodied in modifications its licensee may 6511814Swpaul * make. 6611814Swpaul * 6711814Swpaul * 3.3. Redistribution of Executable. Redistribution in executable form of any 6811814Swpaul * substantial portion of the Covered Code or modification must reproduce the 6911814Swpaul * above Copyright Notice, and the following Disclaimer and Export Compliance 7011814Swpaul * provision in the documentation and/or other materials provided with the 7111814Swpaul * distribution. 7211814Swpaul * 7311814Swpaul * 3.4. Intel retains all right, title, and interest in and to the Original 7411814Swpaul * Intel Code. 7511814Swpaul * 7611814Swpaul * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7711814Swpaul * Intel shall be used in advertising or otherwise to promote the sale, use or 7811814Swpaul * other dealings in products derived from or relating to the Covered Code 7911814Swpaul * without prior written authorization from Intel. 8011814Swpaul * 8111814Swpaul * 4. Disclaimer and Export Compliance 8211814Swpaul * 8311814Swpaul * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8490377Simp * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8590377Simp * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8611814Swpaul * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8711814Swpaul * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8811814Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8911814Swpaul * PARTICULAR PURPOSE. 9011814Swpaul * 9111814Swpaul * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9211814Swpaul * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9311814Swpaul * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9411814Swpaul * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9590377Simp * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9611814Swpaul * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9711814Swpaul * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9811814Swpaul * LIMITED REMEDY. 9911814Swpaul * 10011814Swpaul * 4.3. Licensee shall not export, either directly or indirectly, any of this 10111814Swpaul * software or system incorporating such software without first obtaining any 10211814Swpaul * required license or other approval from the U. S. Department of Commerce or 10311814Swpaul * any other agency or department of the United States Government. In the 10411814Swpaul * event Licensee exports any such software from the United States or 10511814Swpaul * re-exports any such software from a foreign destination, Licensee shall 10611814Swpaul * ensure that the distribution and export/re-export of the software is in 10711814Swpaul * compliance with all laws, regulations, orders, or other restrictions of the 10811814Swpaul * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10911814Swpaul * any of its subsidiaries will export/re-export any technical data, process, 11011814Swpaul * software, or service, directly or indirectly, to any country for which the 11111814Swpaul * United States government or any agency thereof requires an export license, 11211814Swpaul * other governmental approval, or letter of assurance, without first obtaining 11311814Swpaul * such license, approval or letter. 11411814Swpaul * 11511814Swpaul *****************************************************************************/ 11611814Swpaul 11711814Swpaul#define __DSMTHDAT_C__ 11811814Swpaul 11911814Swpaul#include "acpi.h" 12090377Simp#include "acparser.h" 12111814Swpaul#include "acdispat.h" 12211814Swpaul#include "acinterp.h" 12311814Swpaul#include "amlcode.h" 12411814Swpaul#include "acnamesp.h" 12511814Swpaul 12611814Swpaul 12711814Swpaul#define _COMPONENT DISPATCHER 12811814Swpaul MODULE_NAME ("dsmthdat") 12911814Swpaul 13011814Swpaul 13111814Swpaul/******************************************************************************* 13211814Swpaul * 13311814Swpaul * FUNCTION: AcpiDsMethodDataInit 13411814Swpaul * 13511814Swpaul * PARAMETERS: WalkState - Current walk state object 13690377Simp * 13711814Swpaul * RETURN: Status 13890377Simp * 13990377Simp * DESCRIPTION: Initialize the data structures that hold the method's arguments 14011814Swpaul * and locals. The data struct is an array of NTEs for each. 14111814Swpaul * This allows RefOf and DeRefOf to work properly for these 14211814Swpaul * special data types. 14311814Swpaul * 14411814Swpaul ******************************************************************************/ 14511814Swpaul 14611814SwpaulACPI_STATUS 14711814SwpaulAcpiDsMethodDataInit ( 14811814Swpaul ACPI_WALK_STATE *WalkState) 14911814Swpaul{ 15011814Swpaul UINT32 i; 15111814Swpaul 15211814Swpaul 15311814Swpaul FUNCTION_TRACE ("DsMethodDataInit"); 15411814Swpaul 15511814Swpaul /* 15611814Swpaul * WalkState fields are initialized to zero by the 15711814Swpaul * AcpiCmCallocate(). 15811814Swpaul * 15911814Swpaul * An Node is assigned to each argument and local so 16011814Swpaul * that RefOf() can return a pointer to the Node. 16111814Swpaul */ 16211814Swpaul 16311814Swpaul /* Init the method arguments */ 16411814Swpaul 16511814Swpaul for (i = 0; i < MTH_NUM_ARGS; i++) 16611814Swpaul { 16711814Swpaul MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name, 16811814Swpaul NAMEOF_ARG_NTE); 16911814Swpaul WalkState->Arguments[i].Name |= (i << 24); 17011814Swpaul WalkState->Arguments[i].DataType = ACPI_DESC_TYPE_NAMED; 17111814Swpaul WalkState->Arguments[i].Type = ACPI_TYPE_ANY; 17211814Swpaul WalkState->Arguments[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 17390377Simp } 17411814Swpaul 17590377Simp /* Init the method locals */ 17690377Simp 17711814Swpaul for (i = 0; i < MTH_NUM_LOCALS; i++) 17890377Simp { 17911814Swpaul MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name, 18011814Swpaul NAMEOF_LOCAL_NTE); 18111814Swpaul 18211814Swpaul WalkState->LocalVariables[i].Name |= (i << 24); 18311814Swpaul WalkState->LocalVariables[i].DataType = ACPI_DESC_TYPE_NAMED; 18411814Swpaul WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY; 18511814Swpaul WalkState->LocalVariables[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 18611814Swpaul } 18711814Swpaul 18811814Swpaul return_ACPI_STATUS (AE_OK); 18911814Swpaul} 19011814Swpaul 19111814Swpaul 19211814Swpaul/******************************************************************************* 19311814Swpaul * 19411814Swpaul * FUNCTION: AcpiDsMethodDataDeleteAll 19511814Swpaul * 19611814Swpaul * PARAMETERS: WalkState - Current walk state object 19711814Swpaul * 198229780Suqs * RETURN: Status 199229780Suqs * 20011814Swpaul * DESCRIPTION: Delete method locals and arguments. Arguments are only 20111814Swpaul * deleted if this method was called from another method. 20211814Swpaul * 20331404Scharnier ******************************************************************************/ 20411814Swpaul 20511814SwpaulACPI_STATUS 20611814SwpaulAcpiDsMethodDataDeleteAll ( 20711814Swpaul ACPI_WALK_STATE *WalkState) 20811814Swpaul{ 20911814Swpaul UINT32 Index; 21011814Swpaul ACPI_OPERAND_OBJECT *Object; 21111814Swpaul 21211814Swpaul 21311814Swpaul FUNCTION_TRACE ("DsMethodDataDeleteAll"); 21411814Swpaul 21511814Swpaul 21611814Swpaul /* Delete the locals */ 21711814Swpaul 21811814Swpaul DEBUG_PRINT (ACPI_INFO, 21911814Swpaul ("MethodDeleteAll: Deleting local variables in %p\n", WalkState)); 22011814Swpaul 22111814Swpaul for (Index = 0; Index < MTH_NUM_LOCALS; Index++) 22211814Swpaul { 22311814Swpaul Object = WalkState->LocalVariables[Index].Object; 22411814Swpaul if (Object) 22511814Swpaul { 22611814Swpaul DEBUG_PRINT (TRACE_EXEC, 22711814Swpaul ("MethodDeleteAll: Deleting Local%d=%p\n", Index, Object)); 22811814Swpaul 22911814Swpaul /* Remove first */ 23011814Swpaul 23111814Swpaul WalkState->LocalVariables[Index].Object = NULL; 23211814Swpaul 23311814Swpaul /* Was given a ref when stored */ 23411814Swpaul 23511814Swpaul AcpiCmRemoveReference (Object); 23611814Swpaul } 23711814Swpaul } 23811814Swpaul 23911814Swpaul 24011814Swpaul /* Delete the arguments */ 24111814Swpaul 24211814Swpaul DEBUG_PRINT (ACPI_INFO, 24311814Swpaul ("MethodDeleteAll: Deleting arguments in %p\n", WalkState)); 24411814Swpaul 24511814Swpaul for (Index = 0; Index < MTH_NUM_ARGS; Index++) 24611814Swpaul { 24711814Swpaul Object = WalkState->Arguments[Index].Object; 24811814Swpaul if (Object) 24911814Swpaul { 25011814Swpaul DEBUG_PRINT (TRACE_EXEC, 25111814Swpaul ("MethodDeleteAll: Deleting Arg%d=%p\n", Index, Object)); 25211814Swpaul 25311814Swpaul /* Remove first */ 25411814Swpaul 25511814Swpaul WalkState->Arguments[Index].Object = NULL; 25611814Swpaul 25731404Scharnier /* Was given a ref when stored */ 25811814Swpaul 25911814Swpaul AcpiCmRemoveReference (Object); 26011814Swpaul } 26111814Swpaul } 26211814Swpaul 26311814Swpaul return_ACPI_STATUS (AE_OK); 26411814Swpaul} 26511814Swpaul 26611814Swpaul 26711814Swpaul/******************************************************************************* 26811814Swpaul * 26911814Swpaul * FUNCTION: AcpiDsMethodDataInitArgs 27011814Swpaul * 27111814Swpaul * PARAMETERS: *Params - Pointer to a parameter list for the method 27211814Swpaul * MaxParamCount - The arg count for this method 27311814Swpaul * WalkState - Current walk state object 27411814Swpaul * 27511814Swpaul * RETURN: Status 27611814Swpaul * 27711814Swpaul * DESCRIPTION: Initialize arguments for a method 27811814Swpaul * 27911814Swpaul ******************************************************************************/ 28011814Swpaul 28111814SwpaulACPI_STATUS 28211814SwpaulAcpiDsMethodDataInitArgs ( 28390377Simp ACPI_OPERAND_OBJECT **Params, 28411814Swpaul UINT32 MaxParamCount, 28590377Simp ACPI_WALK_STATE *WalkState) 28690377Simp{ 28711814Swpaul ACPI_STATUS Status; 28811814Swpaul UINT32 Mindex; 28911814Swpaul UINT32 Pindex; 29020387Swpaul 29111814Swpaul 29211814Swpaul FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params); 29311814Swpaul 29411814Swpaul 29511814Swpaul if (!Params) 29611814Swpaul { 29711814Swpaul DEBUG_PRINT (TRACE_EXEC, 29811814Swpaul ("DsMethodDataInitArgs: No param list passed to method\n")); 29911814Swpaul return_ACPI_STATUS (AE_OK); 30011814Swpaul } 30111814Swpaul 30211814Swpaul /* Copy passed parameters into the new method stack frame */ 30311814Swpaul 30411814Swpaul for (Pindex = Mindex = 0; 30511814Swpaul (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount); 30611814Swpaul Mindex++) 30711814Swpaul { 30811814Swpaul if (Params[Pindex]) 30911814Swpaul { 31011814Swpaul /* 31111814Swpaul * A valid parameter. 31211814Swpaul * Set the current method argument to the 31311814Swpaul * Params[Pindex++] argument object descriptor 31411814Swpaul */ 31511814Swpaul Status = AcpiDsMethodDataSetValue (MTH_TYPE_ARG, Mindex, 31611814Swpaul Params[Pindex], WalkState); 31711814Swpaul if (ACPI_FAILURE (Status)) 31811814Swpaul { 31911814Swpaul break; 32011814Swpaul } 32111814Swpaul 32211814Swpaul Pindex++; 32311814Swpaul } 32411814Swpaul 32511814Swpaul else 32611814Swpaul { 32711814Swpaul break; 32811814Swpaul } 32911814Swpaul } 33011814Swpaul 33111814Swpaul DEBUG_PRINT (TRACE_EXEC, 33211814Swpaul ("DsMethodDataInitArgs: %d args passed to method\n", Pindex)); 33311814Swpaul return_ACPI_STATUS (AE_OK); 33411814Swpaul} 33511814Swpaul 33611814Swpaul 33711814Swpaul/******************************************************************************* 33811814Swpaul * 33911814Swpaul * FUNCTION: AcpiDsMethodDataGetEntry 34011814Swpaul * 34111814Swpaul * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 34211814Swpaul * Index - Which localVar or argument to get 34311814Swpaul * Entry - Pointer to where a pointer to the stack 34411814Swpaul * entry is returned. 34511814Swpaul * WalkState - Current walk state object 34611814Swpaul * 34711814Swpaul * RETURN: Status 34811814Swpaul * 34911814Swpaul * DESCRIPTION: Get the address of the stack entry given by Type:Index 35011814Swpaul * 35111814Swpaul ******************************************************************************/ 35211814Swpaul 35311814SwpaulACPI_STATUS 35411814SwpaulAcpiDsMethodDataGetEntry ( 35511814Swpaul UINT32 Type, 35611814Swpaul UINT32 Index, 35711814Swpaul ACPI_WALK_STATE *WalkState, 35811814Swpaul ACPI_OPERAND_OBJECT ***Entry) 35911814Swpaul{ 36011814Swpaul 361 FUNCTION_TRACE_U32 ("DsMethodDataGetEntry", Index); 362 363 364 /* 365 * Get the requested object. 366 * The stack "Type" is either a LocalVariable or an Argument 367 */ 368 369 switch (Type) 370 { 371 372 case MTH_TYPE_LOCAL: 373 374 if (Index > MTH_MAX_LOCAL) 375 { 376 DEBUG_PRINT (ACPI_ERROR, 377 ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n", 378 Index, MTH_MAX_LOCAL)); 379 return_ACPI_STATUS (AE_BAD_PARAMETER); 380 } 381 382 *Entry = 383 (ACPI_OPERAND_OBJECT **) &WalkState->LocalVariables[Index].Object; 384 break; 385 386 387 case MTH_TYPE_ARG: 388 389 if (Index > MTH_MAX_ARG) 390 { 391 DEBUG_PRINT (ACPI_ERROR, 392 ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n", 393 Index, MTH_MAX_ARG)); 394 return_ACPI_STATUS (AE_BAD_PARAMETER); 395 } 396 397 *Entry = 398 (ACPI_OPERAND_OBJECT **) &WalkState->Arguments[Index].Object; 399 break; 400 401 402 default: 403 DEBUG_PRINT (ACPI_ERROR, 404 ("DsMethodDataGetEntry: Stack type %d is invalid\n", 405 Type)); 406 return_ACPI_STATUS (AE_BAD_PARAMETER); 407 } 408 409 410 return_ACPI_STATUS (AE_OK); 411} 412 413 414/******************************************************************************* 415 * 416 * FUNCTION: AcpiDsMethodDataSetEntry 417 * 418 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 419 * Index - Which localVar or argument to get 420 * Object - Object to be inserted into the stack entry 421 * WalkState - Current walk state object 422 * 423 * RETURN: Status 424 * 425 * DESCRIPTION: Insert an object onto the method stack at entry Type:Index. 426 * 427 ******************************************************************************/ 428 429ACPI_STATUS 430AcpiDsMethodDataSetEntry ( 431 UINT32 Type, 432 UINT32 Index, 433 ACPI_OPERAND_OBJECT *Object, 434 ACPI_WALK_STATE *WalkState) 435{ 436 ACPI_STATUS Status; 437 ACPI_OPERAND_OBJECT **Entry; 438 439 440 FUNCTION_TRACE ("DsMethodDataSetEntry"); 441 442 /* Get a pointer to the stack entry to set */ 443 444 Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry); 445 if (ACPI_FAILURE (Status)) 446 { 447 return_ACPI_STATUS (Status); 448 } 449 450 /* Increment ref count so object can't be deleted while installed */ 451 452 AcpiCmAddReference (Object); 453 454 /* Install the object into the stack entry */ 455 456 *Entry = Object; 457 458 return_ACPI_STATUS (AE_OK); 459} 460 461 462/******************************************************************************* 463 * 464 * FUNCTION: AcpiDsMethodDataGetType 465 * 466 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 467 * Index - Which localVar or argument whose type 468 * to get 469 * WalkState - Current walk state object 470 * 471 * RETURN: Data type of selected Arg or Local 472 * Used only in ExecMonadic2()/TypeOp. 473 * 474 ******************************************************************************/ 475 476OBJECT_TYPE_INTERNAL 477AcpiDsMethodDataGetType ( 478 UINT32 Type, 479 UINT32 Index, 480 ACPI_WALK_STATE *WalkState) 481{ 482 ACPI_STATUS Status; 483 ACPI_OPERAND_OBJECT **Entry; 484 ACPI_OPERAND_OBJECT *Object; 485 486 487 FUNCTION_TRACE ("DsMethodDataGetType"); 488 489 490 /* Get a pointer to the requested stack entry */ 491 492 Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry); 493 if (ACPI_FAILURE (Status)) 494 { 495 return_VALUE ((ACPI_TYPE_NOT_FOUND)); 496 } 497 498 /* Get the object from the method stack */ 499 500 Object = *Entry; 501 502 /* Get the object type */ 503 504 if (!Object) 505 { 506 /* Any == 0 => "uninitialized" -- see spec 15.2.3.5.2.28 */ 507 return_VALUE (ACPI_TYPE_ANY); 508 } 509 510 return_VALUE (Object->Common.Type); 511} 512 513 514/******************************************************************************* 515 * 516 * FUNCTION: AcpiDsMethodDataGetNte 517 * 518 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 519 * Index - Which localVar or argument whose type 520 * to get 521 * WalkState - Current walk state object 522 * 523 * RETURN: Get the Node associated with a local or arg. 524 * 525 ******************************************************************************/ 526 527ACPI_NAMESPACE_NODE * 528AcpiDsMethodDataGetNte ( 529 UINT32 Type, 530 UINT32 Index, 531 ACPI_WALK_STATE *WalkState) 532{ 533 ACPI_NAMESPACE_NODE *Node = NULL; 534 535 536 FUNCTION_TRACE ("DsMethodDataGetNte"); 537 538 539 switch (Type) 540 { 541 542 case MTH_TYPE_LOCAL: 543 544 if (Index > MTH_MAX_LOCAL) 545 { 546 DEBUG_PRINT (ACPI_ERROR, 547 ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n", 548 Index, MTH_MAX_LOCAL)); 549 return_PTR (Node); 550 } 551 552 Node = &WalkState->LocalVariables[Index]; 553 break; 554 555 556 case MTH_TYPE_ARG: 557 558 if (Index > MTH_MAX_ARG) 559 { 560 DEBUG_PRINT (ACPI_ERROR, 561 ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n", 562 Index, MTH_MAX_ARG)); 563 return_PTR (Node); 564 } 565 566 Node = &WalkState->Arguments[Index]; 567 break; 568 569 570 default: 571 DEBUG_PRINT (ACPI_ERROR, 572 ("DsMethodDataGetEntry: Stack type %d is invalid\n", 573 Type)); 574 break; 575 } 576 577 578 return_PTR (Node); 579} 580 581 582/******************************************************************************* 583 * 584 * FUNCTION: AcpiDsMethodDataGetValue 585 * 586 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 587 * Index - Which localVar or argument to get 588 * WalkState - Current walk state object 589 * *DestDesc - Ptr to Descriptor into which selected Arg 590 * or Local value should be copied 591 * 592 * RETURN: Status 593 * 594 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame 595 * at the current top of the method stack. 596 * Used only in AcpiAmlResolveToValue(). 597 * 598 ******************************************************************************/ 599 600ACPI_STATUS 601AcpiDsMethodDataGetValue ( 602 UINT32 Type, 603 UINT32 Index, 604 ACPI_WALK_STATE *WalkState, 605 ACPI_OPERAND_OBJECT **DestDesc) 606{ 607 ACPI_STATUS Status; 608 ACPI_OPERAND_OBJECT **Entry; 609 ACPI_OPERAND_OBJECT *Object; 610 611 612 FUNCTION_TRACE ("DsMethodDataGetValue"); 613 614 615 /* Validate the object descriptor */ 616 617 if (!DestDesc) 618 { 619 DEBUG_PRINT (ACPI_ERROR, 620 ("DsMethodDataGetValue: NULL object descriptor pointer\n")); 621 return_ACPI_STATUS (AE_BAD_PARAMETER); 622 } 623 624 625 /* Get a pointer to the requested method stack entry */ 626 627 Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry); 628 if (ACPI_FAILURE (Status)) 629 { 630 return_ACPI_STATUS (Status); 631 } 632 633 /* Get the object from the method stack */ 634 635 Object = *Entry; 636 637 638 /* Examine the returned object, it must be valid. */ 639 640 if (!Object) 641 { 642 /* 643 * Index points to uninitialized object stack value. 644 * This means that either 1) The expected argument was 645 * not passed to the method, or 2) A local variable 646 * was referenced by the method (via the ASL) 647 * before it was initialized. Either case is an error. 648 */ 649 650 switch (Type) 651 { 652 case MTH_TYPE_ARG: 653 654 DEBUG_PRINT (ACPI_ERROR, 655 ("DsMethodDataGetValue: Uninitialized Arg[%d] at entry %p\n", 656 Index, Entry)); 657 658 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 659 break; 660 661 case MTH_TYPE_LOCAL: 662 663 DEBUG_PRINT (ACPI_ERROR, 664 ("DsMethodDataGetValue: Uninitialized Local[%d] at entry %p\n", 665 Index, Entry)); 666 667 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 668 break; 669 } 670 } 671 672 673 /* 674 * Index points to initialized and valid object stack value. 675 * Return an additional reference to the object 676 */ 677 678 *DestDesc = Object; 679 AcpiCmAddReference (Object); 680 681 return_ACPI_STATUS (AE_OK); 682} 683 684 685/******************************************************************************* 686 * 687 * FUNCTION: AcpiDsMethodDataDeleteValue 688 * 689 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 690 * Index - Which localVar or argument to delete 691 * WalkState - Current walk state object 692 * 693 * RETURN: Status 694 * 695 * DESCRIPTION: Delete the entry at Type:Index on the method stack. Inserts 696 * a null into the stack slot after the object is deleted. 697 * 698 ******************************************************************************/ 699 700ACPI_STATUS 701AcpiDsMethodDataDeleteValue ( 702 UINT32 Type, 703 UINT32 Index, 704 ACPI_WALK_STATE *WalkState) 705{ 706 ACPI_STATUS Status; 707 ACPI_OPERAND_OBJECT **Entry; 708 ACPI_OPERAND_OBJECT *Object; 709 710 711 FUNCTION_TRACE ("DsMethodDataDeleteValue"); 712 713 714 /* Get a pointer to the requested entry */ 715 716 Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry); 717 if (ACPI_FAILURE (Status)) 718 { 719 return_ACPI_STATUS (Status); 720 } 721 722 /* Get the current entry in this slot k */ 723 724 Object = *Entry; 725 726 /* 727 * Undefine the Arg or Local by setting its descriptor 728 * pointer to NULL. Locals/Args can contain both 729 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs 730 */ 731 *Entry = NULL; 732 733 734 if ((Object) && 735 (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_INTERNAL))) 736 { 737 /* 738 * There is a valid object in this slot 739 * Decrement the reference count by one to balance the 740 * increment when the object was stored in the slot. 741 */ 742 AcpiCmRemoveReference (Object); 743 } 744 745 746 return_ACPI_STATUS (AE_OK); 747} 748 749 750/******************************************************************************* 751 * 752 * FUNCTION: AcpiDsMethodDataSetValue 753 * 754 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 755 * Index - Which localVar or argument to set 756 * SrcDesc - Value to be stored 757 * WalkState - Current walk state 758 * 759 * RETURN: Status 760 * 761 * DESCRIPTION: Store a value in an Arg or Local. The SrcDesc is installed 762 * as the new value for the Arg or Local and the reference count 763 * for SrcDesc is incremented. 764 * 765 ******************************************************************************/ 766 767ACPI_STATUS 768AcpiDsMethodDataSetValue ( 769 UINT32 Type, 770 UINT32 Index, 771 ACPI_OPERAND_OBJECT *SrcDesc, 772 ACPI_WALK_STATE *WalkState) 773{ 774 ACPI_STATUS Status; 775 ACPI_OPERAND_OBJECT **Entry; 776 777 778 FUNCTION_TRACE ("DsMethodDataSetValue"); 779 DEBUG_PRINT (TRACE_EXEC, 780 ("DsMethodDataSetValue: Type=%d Idx=%d Obj=%p\n", 781 Type, Index, SrcDesc)); 782 783 784 /* Parameter validation */ 785 786 if (!SrcDesc) 787 { 788 return_ACPI_STATUS (AE_BAD_PARAMETER); 789 } 790 791 792 /* Get a pointer to the requested method stack entry */ 793 794 Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry); 795 if (ACPI_FAILURE (Status)) 796 { 797 goto Cleanup; 798 } 799 800 if (*Entry == SrcDesc) 801 { 802 DEBUG_PRINT (TRACE_EXEC, 803 ("DsMethodDataSetValue: Obj=%p already installed!\n", 804 SrcDesc)); 805 goto Cleanup; 806 } 807 808 809 /* 810 * If there is an object already in this slot, we either 811 * have to delete it, or if this is an argument and there 812 * is an object reference stored there, we have to do 813 * an indirect store! 814 */ 815 816 if (*Entry) 817 { 818 /* 819 * Check for an indirect store if an argument 820 * contains an object reference (stored as an Node). 821 * We don't allow this automatic dereferencing for 822 * locals, since a store to a local should overwrite 823 * anything there, including an object reference. 824 * 825 * If both Arg0 and Local0 contain RefOf (Local4): 826 * 827 * Store (1, Arg0) - Causes indirect store to local4 828 * Store (1, Local0) - Stores 1 in local0, overwriting 829 * the reference to local4 830 * Store (1, DeRefof (Local0)) - Causes indirect store to local4 831 * 832 * Weird, but true. 833 */ 834 835 if ((Type == MTH_TYPE_ARG) && 836 (VALID_DESCRIPTOR_TYPE (*Entry, ACPI_DESC_TYPE_NAMED))) 837 { 838 DEBUG_PRINT (TRACE_EXEC, 839 ("DsMethodDataSetValue: Arg (%p) is an ObjRef(Node), storing in %p\n", 840 SrcDesc, *Entry)); 841 842 /* Detach an existing object from the Node */ 843 844 AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) *Entry); 845 846 /* 847 * Store this object into the Node 848 * (do the indirect store) 849 */ 850 Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) *Entry, SrcDesc, 851 SrcDesc->Common.Type); 852 return_ACPI_STATUS (Status); 853 } 854 855 856 /* 857 * Perform "Implicit conversion" of the new object to the type of the 858 * existing object 859 */ 860 Status = AcpiAmlConvertToTargetType ((*Entry)->Common.Type, &SrcDesc, WalkState); 861 if (ACPI_FAILURE (Status)) 862 { 863 goto Cleanup; 864 } 865 866 /* 867 * Delete the existing object 868 * before storing the new one 869 */ 870 AcpiDsMethodDataDeleteValue (Type, Index, WalkState); 871 } 872 873 874 /* 875 * Install the ObjStack descriptor (*SrcDesc) into 876 * the descriptor for the Arg or Local. 877 * Install the new object in the stack entry 878 * (increments the object reference count by one) 879 */ 880 Status = AcpiDsMethodDataSetEntry (Type, Index, SrcDesc, WalkState); 881 if (ACPI_FAILURE (Status)) 882 { 883 goto Cleanup; 884 } 885 886 /* Normal exit */ 887 888 return_ACPI_STATUS (AE_OK); 889 890 891 /* Error exit */ 892 893Cleanup: 894 895 return_ACPI_STATUS (Status); 896} 897 898