dsmthdat.c revision 71867
1139790Simp/******************************************************************************* 2135783Smarcel * 3135783Smarcel * Module Name: dsmthdat - control method arguments and local variables 4135783Smarcel * $Revision: 39 $ 5135783Smarcel * 6135783Smarcel ******************************************************************************/ 7135783Smarcel 8135783Smarcel/****************************************************************************** 9135783Smarcel * 10135783Smarcel * 1. Copyright Notice 11135783Smarcel * 12135783Smarcel * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13135783Smarcel * All rights reserved. 14135783Smarcel * 15135783Smarcel * 2. License 16135783Smarcel * 17135783Smarcel * 2.1. This is your license from Intel Corp. under its intellectual property 18135783Smarcel * rights. You may have additional license terms from the party that provided 19135783Smarcel * you this software, covering your right to use that party's intellectual 20135783Smarcel * property rights. 21135783Smarcel * 22135783Smarcel * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23135783Smarcel * copy of the source code appearing in this file ("Covered Code") an 24135783Smarcel * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25135783Smarcel * base code distributed originally by Intel ("Original Intel Code") to copy, 26135783Smarcel * make derivatives, distribute, use and display any portion of the Covered 27135783Smarcel * Code in any form, with the right to sublicense such rights; and 28135783Smarcel * 29135783Smarcel * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30135783Smarcel * license (with the right to sublicense), under only those claims of Intel 31135783Smarcel * patents that are infringed by the Original Intel Code, to make, use, sell, 32135783Smarcel * offer to sell, and import the Covered Code and derivative works thereof 33135783Smarcel * solely to the minimum extent necessary to exercise the above copyright 34135783Smarcel * license, and in no event shall the patent license extend to any additions 35135783Smarcel * to or modifications of the Original Intel Code. No other license or right 36135783Smarcel * is granted directly or by implication, estoppel or otherwise; 37135783Smarcel * 38135783Smarcel * The above copyright and patent license is granted only if the following 39160764Sjhb * conditions are met: 40135783Smarcel * 41135783Smarcel * 3. Conditions 42135783Smarcel * 43135798Smarcel * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44135783Smarcel * Redistribution of source code of any substantial portion of the Covered 45135783Smarcel * Code or modification with rights to further distribute source must include 46135783Smarcel * the above Copyright Notice, the above License, this list of Conditions, 47233204Stijl * and the following Disclaimer and Export Compliance provision. In addition, 48135783Smarcel * Licensee must cause all Covered Code to which Licensee contributes to 49162361Srwatson * contain a file documenting the changes Licensee made to create that Covered 50162361Srwatson * Code and the date of any change. Licensee must include in that file the 51208453Skib * documentation of any changes made by any predecessor Licensee. Licensee 52135832Smarcel * must include a prominent statement that the modification is derived, 53208453Skib * directly or indirectly, from Original Intel Code. 54208453Skib * 55135783Smarcel * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56135783Smarcel * Redistribution of source code of any substantial portion of the Covered 57208453Skib * Code or modification without rights to further distribute source must 58135783Smarcel * include the following Disclaimer and Export Compliance provision in the 59208453Skib * documentation and/or other materials provided with distribution. In 60135783Smarcel * addition, Licensee may not authorize further sublicense of source of any 61135783Smarcel * portion of the Covered Code, and must include terms to the effect that the 62135783Smarcel * license from Licensee to its licensee is limited to the intellectual 63135783Smarcel * property embodied in the software Licensee provides to its licensee, and 64135783Smarcel * not to intellectual property embodied in modifications its licensee may 65135783Smarcel * make. 66135783Smarcel * 67135783Smarcel * 3.3. Redistribution of Executable. Redistribution in executable form of any 68135783Smarcel * substantial portion of the Covered Code or modification must reproduce the 69135783Smarcel * above Copyright Notice, and the following Disclaimer and Export Compliance 70135783Smarcel * provision in the documentation and/or other materials provided with the 71135783Smarcel * distribution. 72135783Smarcel * 73135783Smarcel * 3.4. Intel retains all right, title, and interest in and to the Original 74135783Smarcel * Intel Code. 75135783Smarcel * 76135783Smarcel * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77135783Smarcel * Intel shall be used in advertising or otherwise to promote the sale, use or 78135783Smarcel * other dealings in products derived from or relating to the Covered Code 79135783Smarcel * without prior written authorization from Intel. 80208453Skib * 81135783Smarcel * 4. Disclaimer and Export Compliance 82135783Smarcel * 83135783Smarcel * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84135783Smarcel * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85135783Smarcel * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86135783Smarcel * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87135783Smarcel * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88135783Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89135783Smarcel * PARTICULAR PURPOSE. 90135783Smarcel * 91208453Skib * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92135783Smarcel * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93208453Skib * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94208453Skib * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95208453Skib * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96208453Skib * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97208453Skib * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98208453Skib * LIMITED REMEDY. 99208453Skib * 100208453Skib * 4.3. Licensee shall not export, either directly or indirectly, any of this 101208453Skib * software or system incorporating such software without first obtaining any 102208453Skib * required license or other approval from the U. S. Department of Commerce or 103208453Skib * any other agency or department of the United States Government. In the 104208453Skib * event Licensee exports any such software from the United States or 105208453Skib * re-exports any such software from a foreign destination, Licensee shall 106208453Skib * ensure that the distribution and export/re-export of the software is in 107208453Skib * compliance with all laws, regulations, orders, or other restrictions of the 108208453Skib * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109208453Skib * any of its subsidiaries will export/re-export any technical data, process, 110208453Skib * software, or service, directly or indirectly, to any country for which the 111208453Skib * United States government or any agency thereof requires an export license, 112208453Skib * other governmental approval, or letter of assurance, without first obtaining 113208453Skib * such license, approval or letter. 114208453Skib * 115208453Skib *****************************************************************************/ 116208453Skib 117208453Skib#define __DSMTHDAT_C__ 118208453Skib 119208453Skib#include "acpi.h" 120208453Skib#include "acparser.h" 121208453Skib#include "acdispat.h" 122208453Skib#include "acinterp.h" 123208453Skib#include "amlcode.h" 124208453Skib#include "acnamesp.h" 125208453Skib 126208453Skib 127208453Skib#define _COMPONENT DISPATCHER 128208453Skib MODULE_NAME ("dsmthdat") 129208453Skib 130208453Skib 131208453Skib/******************************************************************************* 132208453Skib * 133208453Skib * FUNCTION: AcpiDsMethodDataInit 134208453Skib * 135208514Skib * PARAMETERS: WalkState - Current walk state object 136208453Skib * 137208453Skib * RETURN: Status 138208453Skib * 139208514Skib * DESCRIPTION: Initialize the data structures that hold the method's arguments 140208453Skib * and locals. The data struct is an array of NTEs for each. 141208453Skib * This allows RefOf and DeRefOf to work properly for these 142208453Skib * special data types. 143208453Skib * 144208453Skib ******************************************************************************/ 145208453Skib 146208453SkibACPI_STATUS 147225474SkibAcpiDsMethodDataInit ( 148225474Skib ACPI_WALK_STATE *WalkState) 149208453Skib{ 150208453Skib UINT32 i; 151208453Skib 152208453Skib 153208453Skib FUNCTION_TRACE ("DsMethodDataInit"); 154208453Skib 155208453Skib /* 156208453Skib * WalkState fields are initialized to zero by the 157208453Skib * AcpiCmCallocate(). 158208453Skib * 159208453Skib * An Node is assigned to each argument and local so 160208453Skib * that RefOf() can return a pointer to the Node. 161208453Skib */ 162208453Skib 163135783Smarcel /* Init the method arguments */ 164135783Smarcel 165135783Smarcel for (i = 0; i < MTH_NUM_ARGS; i++) 166135783Smarcel { 167135783Smarcel MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name, 168151316Sdavidxu NAMEOF_ARG_NTE); 169151316Sdavidxu WalkState->Arguments[i].Name |= (i << 24); 170151316Sdavidxu WalkState->Arguments[i].DataType = ACPI_DESC_TYPE_NAMED; 171151316Sdavidxu WalkState->Arguments[i].Type = ACPI_TYPE_ANY; 172151316Sdavidxu WalkState->Arguments[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 173135783Smarcel } 174135783Smarcel 175208453Skib /* Init the method locals */ 176135783Smarcel 177135783Smarcel for (i = 0; i < MTH_NUM_LOCALS; i++) 178135783Smarcel { 179135783Smarcel MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name, 180135783Smarcel NAMEOF_LOCAL_NTE); 181135783Smarcel 182135783Smarcel WalkState->LocalVariables[i].Name |= (i << 24); 183135783Smarcel WalkState->LocalVariables[i].DataType = ACPI_DESC_TYPE_NAMED; 184135783Smarcel WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY; 185135783Smarcel WalkState->LocalVariables[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 186135783Smarcel } 187135783Smarcel 188135783Smarcel return_ACPI_STATUS (AE_OK); 189151316Sdavidxu} 190135783Smarcel 191135783Smarcel 192135783Smarcel/******************************************************************************* 193135783Smarcel * 194170291Sattilio * FUNCTION: AcpiDsMethodDataDeleteAll 195135783Smarcel * 196135783Smarcel * PARAMETERS: WalkState - Current walk state object 197135783Smarcel * 198155455Sphk * RETURN: Status 199135783Smarcel * 200135783Smarcel * DESCRIPTION: Delete method locals and arguments. Arguments are only 201135783Smarcel * deleted if this method was called from another method. 202135783Smarcel * 203135783Smarcel ******************************************************************************/ 204135783Smarcel 205135783SmarcelACPI_STATUS 206135783SmarcelAcpiDsMethodDataDeleteAll ( 207135783Smarcel ACPI_WALK_STATE *WalkState) 208135783Smarcel{ 209135783Smarcel UINT32 Index; 210135783Smarcel ACPI_OPERAND_OBJECT *Object; 211135783Smarcel 212135783Smarcel 213135783Smarcel FUNCTION_TRACE ("DsMethodDataDeleteAll"); 214135783Smarcel 215135783Smarcel 216135783Smarcel /* Delete the locals */ 217135783Smarcel 218135783Smarcel DEBUG_PRINT (ACPI_INFO, 219135783Smarcel ("MethodDeleteAll: Deleting local variables in %p\n", WalkState)); 220135783Smarcel 221135783Smarcel for (Index = 0; Index < MTH_NUM_LOCALS; Index++) 222135783Smarcel { 223135783Smarcel Object = WalkState->LocalVariables[Index].Object; 224135783Smarcel if (Object) 225135783Smarcel { 226135783Smarcel DEBUG_PRINT (TRACE_EXEC, 227135783Smarcel ("MethodDeleteAll: Deleting Local%d=%p\n", Index, Object)); 228135783Smarcel 229135783Smarcel /* Remove first */ 230135783Smarcel 231135783Smarcel WalkState->LocalVariables[Index].Object = NULL; 232135783Smarcel 233135783Smarcel /* Was given a ref when stored */ 234135783Smarcel 235135783Smarcel AcpiCmRemoveReference (Object); 236135783Smarcel } 237135783Smarcel } 238135783Smarcel 239135783Smarcel 240135783Smarcel /* Delete the arguments */ 241135783Smarcel 242135783Smarcel DEBUG_PRINT (ACPI_INFO, 243135783Smarcel ("MethodDeleteAll: Deleting arguments in %p\n", WalkState)); 244135783Smarcel 245135783Smarcel for (Index = 0; Index < MTH_NUM_ARGS; Index++) 246135783Smarcel { 247135783Smarcel Object = WalkState->Arguments[Index].Object; 248135783Smarcel if (Object) 249135783Smarcel { 250135783Smarcel DEBUG_PRINT (TRACE_EXEC, 251135783Smarcel ("MethodDeleteAll: Deleting Arg%d=%p\n", Index, Object)); 252135783Smarcel 253135783Smarcel /* Remove first */ 254135783Smarcel 255135783Smarcel WalkState->Arguments[Index].Object = NULL; 256135783Smarcel 257135783Smarcel /* Was given a ref when stored */ 258135783Smarcel 259135783Smarcel AcpiCmRemoveReference (Object); 260135783Smarcel } 261135783Smarcel } 262135783Smarcel 263135783Smarcel return_ACPI_STATUS (AE_OK); 264135783Smarcel} 265135783Smarcel 266135783Smarcel 267135783Smarcel/******************************************************************************* 268135783Smarcel * 269135783Smarcel * FUNCTION: AcpiDsMethodDataInitArgs 270135783Smarcel * 271135783Smarcel * PARAMETERS: *Params - Pointer to a parameter list for the method 272135783Smarcel * MaxParamCount - The arg count for this method 273151316Sdavidxu * WalkState - Current walk state object 274151316Sdavidxu * 275151316Sdavidxu * RETURN: Status 276151316Sdavidxu * 277151316Sdavidxu * DESCRIPTION: Initialize arguments for a method 278135783Smarcel * 279135783Smarcel ******************************************************************************/ 280155455Sphk 281135783SmarcelACPI_STATUS 282135783SmarcelAcpiDsMethodDataInitArgs ( 283135783Smarcel ACPI_OPERAND_OBJECT **Params, 284 UINT32 MaxParamCount, 285 ACPI_WALK_STATE *WalkState) 286{ 287 ACPI_STATUS Status; 288 UINT32 Mindex; 289 UINT32 Pindex; 290 291 292 FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params); 293 294 295 if (!Params) 296 { 297 DEBUG_PRINT (TRACE_EXEC, 298 ("DsMethodDataInitArgs: No param list passed to method\n")); 299 return_ACPI_STATUS (AE_OK); 300 } 301 302 /* Copy passed parameters into the new method stack frame */ 303 304 for (Pindex = Mindex = 0; 305 (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount); 306 Mindex++) 307 { 308 if (Params[Pindex]) 309 { 310 /* 311 * A valid parameter. 312 * Set the current method argument to the 313 * Params[Pindex++] argument object descriptor 314 */ 315 Status = AcpiDsMethodDataSetValue (MTH_TYPE_ARG, Mindex, 316 Params[Pindex], WalkState); 317 if (ACPI_FAILURE (Status)) 318 { 319 break; 320 } 321 322 Pindex++; 323 } 324 325 else 326 { 327 break; 328 } 329 } 330 331 DEBUG_PRINT (TRACE_EXEC, 332 ("DsMethodDataInitArgs: %d args passed to method\n", Pindex)); 333 return_ACPI_STATUS (AE_OK); 334} 335 336 337/******************************************************************************* 338 * 339 * FUNCTION: AcpiDsMethodDataGetEntry 340 * 341 * PARAMETERS: Type - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG 342 * Index - Which localVar or argument to get 343 * Entry - Pointer to where a pointer to the stack 344 * entry is returned. 345 * WalkState - Current walk state object 346 * 347 * RETURN: Status 348 * 349 * DESCRIPTION: Get the address of the stack entry given by Type:Index 350 * 351 ******************************************************************************/ 352 353ACPI_STATUS 354AcpiDsMethodDataGetEntry ( 355 UINT32 Type, 356 UINT32 Index, 357 ACPI_WALK_STATE *WalkState, 358 ACPI_OPERAND_OBJECT ***Entry) 359{ 360 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