Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /*******************************************************************************
0002  *
0003  * Module Name: dsmthdat - control method arguments and local variables
0004  *
0005  ******************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acdispat.h"
0155 #include "acnamesp.h"
0156 #include "acinterp.h"
0157 
0158 
0159 #define _COMPONENT          ACPI_DISPATCHER
0160         ACPI_MODULE_NAME    ("dsmthdat")
0161 
0162 /* Local prototypes */
0163 
0164 static void
0165 AcpiDsMethodDataDeleteValue (
0166     UINT8                   Type,
0167     UINT32                  Index,
0168     ACPI_WALK_STATE         *WalkState);
0169 
0170 static ACPI_STATUS
0171 AcpiDsMethodDataSetValue (
0172     UINT8                   Type,
0173     UINT32                  Index,
0174     ACPI_OPERAND_OBJECT     *Object,
0175     ACPI_WALK_STATE         *WalkState);
0176 
0177 #ifdef ACPI_OBSOLETE_FUNCTIONS
0178 ACPI_OBJECT_TYPE
0179 AcpiDsMethodDataGetType (
0180     UINT16                  Opcode,
0181     UINT32                  Index,
0182     ACPI_WALK_STATE         *WalkState);
0183 #endif
0184 
0185 
0186 /*******************************************************************************
0187  *
0188  * FUNCTION:    AcpiDsMethodDataInit
0189  *
0190  * PARAMETERS:  WalkState           - Current walk state object
0191  *
0192  * RETURN:      Status
0193  *
0194  * DESCRIPTION: Initialize the data structures that hold the method's arguments
0195  *              and locals. The data struct is an array of namespace nodes for
0196  *              each - this allows RefOf and DeRefOf to work properly for these
0197  *              special data types.
0198  *
0199  * NOTES:       WalkState fields are initialized to zero by the
0200  *              ACPI_ALLOCATE_ZEROED().
0201  *
0202  *              A pseudo-Namespace Node is assigned to each argument and local
0203  *              so that RefOf() can return a pointer to the Node.
0204  *
0205  ******************************************************************************/
0206 
0207 void
0208 AcpiDsMethodDataInit (
0209     ACPI_WALK_STATE         *WalkState)
0210 {
0211     UINT32                  i;
0212 
0213 
0214     ACPI_FUNCTION_TRACE (DsMethodDataInit);
0215 
0216 
0217     /* Init the method arguments */
0218 
0219     for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
0220     {
0221         ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
0222             NAMEOF_ARG_NTE);
0223 
0224         WalkState->Arguments[i].Name.Integer |= (i << 24);
0225         WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
0226         WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
0227         WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
0228     }
0229 
0230     /* Init the method locals */
0231 
0232     for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
0233     {
0234         ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
0235             NAMEOF_LOCAL_NTE);
0236 
0237         WalkState->LocalVariables[i].Name.Integer |= (i << 24);
0238         WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
0239         WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
0240         WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
0241     }
0242 
0243     return_VOID;
0244 }
0245 
0246 
0247 /*******************************************************************************
0248  *
0249  * FUNCTION:    AcpiDsMethodDataDeleteAll
0250  *
0251  * PARAMETERS:  WalkState           - Current walk state object
0252  *
0253  * RETURN:      None
0254  *
0255  * DESCRIPTION: Delete method locals and arguments. Arguments are only
0256  *              deleted if this method was called from another method.
0257  *
0258  ******************************************************************************/
0259 
0260 void
0261 AcpiDsMethodDataDeleteAll (
0262     ACPI_WALK_STATE         *WalkState)
0263 {
0264     UINT32                  Index;
0265 
0266 
0267     ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
0268 
0269 
0270     /* Detach the locals */
0271 
0272     for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
0273     {
0274         if (WalkState->LocalVariables[Index].Object)
0275         {
0276             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
0277                 Index, WalkState->LocalVariables[Index].Object));
0278 
0279             /* Detach object (if present) and remove a reference */
0280 
0281             AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
0282         }
0283     }
0284 
0285     /* Detach the arguments */
0286 
0287     for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
0288     {
0289         if (WalkState->Arguments[Index].Object)
0290         {
0291             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
0292                 Index, WalkState->Arguments[Index].Object));
0293 
0294             /* Detach object (if present) and remove a reference */
0295 
0296             AcpiNsDetachObject (&WalkState->Arguments[Index]);
0297         }
0298     }
0299 
0300     return_VOID;
0301 }
0302 
0303 
0304 /*******************************************************************************
0305  *
0306  * FUNCTION:    AcpiDsMethodDataInitArgs
0307  *
0308  * PARAMETERS:  *Params         - Pointer to a parameter list for the method
0309  *              MaxParamCount   - The arg count for this method
0310  *              WalkState       - Current walk state object
0311  *
0312  * RETURN:      Status
0313  *
0314  * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
0315  *              of ACPI operand objects, either null terminated or whose length
0316  *              is defined by MaxParamCount.
0317  *
0318  ******************************************************************************/
0319 
0320 ACPI_STATUS
0321 AcpiDsMethodDataInitArgs (
0322     ACPI_OPERAND_OBJECT     **Params,
0323     UINT32                  MaxParamCount,
0324     ACPI_WALK_STATE         *WalkState)
0325 {
0326     ACPI_STATUS             Status;
0327     UINT32                  Index = 0;
0328 
0329 
0330     ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
0331 
0332 
0333     if (!Params)
0334     {
0335         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0336             "No parameter list passed to method\n"));
0337         return_ACPI_STATUS (AE_OK);
0338     }
0339 
0340     /* Copy passed parameters into the new method stack frame */
0341 
0342     while ((Index < ACPI_METHOD_NUM_ARGS) &&
0343            (Index < MaxParamCount)        &&
0344             Params[Index])
0345     {
0346         /*
0347          * A valid parameter.
0348          * Store the argument in the method/walk descriptor.
0349          * Do not copy the arg in order to implement call by reference
0350          */
0351         Status = AcpiDsMethodDataSetValue (
0352             ACPI_REFCLASS_ARG, Index, Params[Index], WalkState);
0353         if (ACPI_FAILURE (Status))
0354         {
0355             return_ACPI_STATUS (Status);
0356         }
0357 
0358         Index++;
0359     }
0360 
0361     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
0362     return_ACPI_STATUS (AE_OK);
0363 }
0364 
0365 
0366 /*******************************************************************************
0367  *
0368  * FUNCTION:    AcpiDsMethodDataGetNode
0369  *
0370  * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
0371  *                                    ACPI_REFCLASS_ARG
0372  *              Index               - Which Local or Arg whose type to get
0373  *              WalkState           - Current walk state object
0374  *              Node                - Where the node is returned.
0375  *
0376  * RETURN:      Status and node
0377  *
0378  * DESCRIPTION: Get the Node associated with a local or arg.
0379  *
0380  ******************************************************************************/
0381 
0382 ACPI_STATUS
0383 AcpiDsMethodDataGetNode (
0384     UINT8                   Type,
0385     UINT32                  Index,
0386     ACPI_WALK_STATE         *WalkState,
0387     ACPI_NAMESPACE_NODE     **Node)
0388 {
0389     ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
0390 
0391 
0392     /*
0393      * Method Locals and Arguments are supported
0394      */
0395     switch (Type)
0396     {
0397     case ACPI_REFCLASS_LOCAL:
0398 
0399         if (Index > ACPI_METHOD_MAX_LOCAL)
0400         {
0401             ACPI_ERROR ((AE_INFO,
0402                 "Local index %u is invalid (max %u)",
0403                 Index, ACPI_METHOD_MAX_LOCAL));
0404             return_ACPI_STATUS (AE_AML_INVALID_INDEX);
0405         }
0406 
0407         /* Return a pointer to the pseudo-node */
0408 
0409         *Node = &WalkState->LocalVariables[Index];
0410         break;
0411 
0412     case ACPI_REFCLASS_ARG:
0413 
0414         if (Index > ACPI_METHOD_MAX_ARG)
0415         {
0416             ACPI_ERROR ((AE_INFO,
0417                 "Arg index %u is invalid (max %u)",
0418                 Index, ACPI_METHOD_MAX_ARG));
0419             return_ACPI_STATUS (AE_AML_INVALID_INDEX);
0420         }
0421 
0422         /* Return a pointer to the pseudo-node */
0423 
0424         *Node = &WalkState->Arguments[Index];
0425         break;
0426 
0427     default:
0428 
0429         ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
0430         return_ACPI_STATUS (AE_TYPE);
0431     }
0432 
0433     return_ACPI_STATUS (AE_OK);
0434 }
0435 
0436 
0437 /*******************************************************************************
0438  *
0439  * FUNCTION:    AcpiDsMethodDataSetValue
0440  *
0441  * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
0442  *                                    ACPI_REFCLASS_ARG
0443  *              Index               - Which Local or Arg to get
0444  *              Object              - Object to be inserted into the stack entry
0445  *              WalkState           - Current walk state object
0446  *
0447  * RETURN:      Status
0448  *
0449  * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
0450  *              Note: There is no "implicit conversion" for locals.
0451  *
0452  ******************************************************************************/
0453 
0454 static ACPI_STATUS
0455 AcpiDsMethodDataSetValue (
0456     UINT8                   Type,
0457     UINT32                  Index,
0458     ACPI_OPERAND_OBJECT     *Object,
0459     ACPI_WALK_STATE         *WalkState)
0460 {
0461     ACPI_STATUS             Status;
0462     ACPI_NAMESPACE_NODE     *Node;
0463 
0464 
0465     ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
0466 
0467 
0468     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0469         "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
0470         Type, Object->Common.ReferenceCount,
0471         AcpiUtGetTypeName (Object->Common.Type)));
0472 
0473     /* Get the namespace node for the arg/local */
0474 
0475     Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
0476     if (ACPI_FAILURE (Status))
0477     {
0478         return_ACPI_STATUS (Status);
0479     }
0480 
0481     /*
0482      * Increment ref count so object can't be deleted while installed.
0483      * NOTE: We do not copy the object in order to preserve the call by
0484      * reference semantics of ACPI Control Method invocation.
0485      * (See ACPI Specification 2.0C)
0486      */
0487     AcpiUtAddReference (Object);
0488 
0489     /* Install the object */
0490 
0491     Node->Object = Object;
0492     return_ACPI_STATUS (Status);
0493 }
0494 
0495 
0496 /*******************************************************************************
0497  *
0498  * FUNCTION:    AcpiDsMethodDataGetValue
0499  *
0500  * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
0501  *                                    ACPI_REFCLASS_ARG
0502  *              Index               - Which localVar or argument to get
0503  *              WalkState           - Current walk state object
0504  *              DestDesc            - Where Arg or Local value is returned
0505  *
0506  * RETURN:      Status
0507  *
0508  * DESCRIPTION: Retrieve value of selected Arg or Local for this method
0509  *              Used only in AcpiExResolveToValue().
0510  *
0511  ******************************************************************************/
0512 
0513 ACPI_STATUS
0514 AcpiDsMethodDataGetValue (
0515     UINT8                   Type,
0516     UINT32                  Index,
0517     ACPI_WALK_STATE         *WalkState,
0518     ACPI_OPERAND_OBJECT     **DestDesc)
0519 {
0520     ACPI_STATUS             Status;
0521     ACPI_NAMESPACE_NODE     *Node;
0522     ACPI_OPERAND_OBJECT     *Object;
0523 
0524 
0525     ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
0526 
0527 
0528     /* Validate the object descriptor */
0529 
0530     if (!DestDesc)
0531     {
0532         ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
0533         return_ACPI_STATUS (AE_BAD_PARAMETER);
0534     }
0535 
0536     /* Get the namespace node for the arg/local */
0537 
0538     Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
0539     if (ACPI_FAILURE (Status))
0540     {
0541         return_ACPI_STATUS (Status);
0542     }
0543 
0544     /* Get the object from the node */
0545 
0546     Object = Node->Object;
0547 
0548     /* Examine the returned object, it must be valid. */
0549 
0550     if (!Object)
0551     {
0552         /*
0553          * Index points to uninitialized object.
0554          * This means that either 1) The expected argument was
0555          * not passed to the method, or 2) A local variable
0556          * was referenced by the method (via the ASL)
0557          * before it was initialized. Either case is an error.
0558          */
0559 
0560         /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
0561 
0562         if (AcpiGbl_EnableInterpreterSlack)
0563         {
0564             Object = AcpiUtCreateIntegerObject ((UINT64) 0);
0565             if (!Object)
0566             {
0567                 return_ACPI_STATUS (AE_NO_MEMORY);
0568             }
0569 
0570             Node->Object = Object;
0571         }
0572 
0573         /* Otherwise, return the error */
0574 
0575         else switch (Type)
0576         {
0577         case ACPI_REFCLASS_ARG:
0578 
0579             ACPI_ERROR ((AE_INFO,
0580                 "Uninitialized Arg[%u] at node %p",
0581                 Index, Node));
0582 
0583             return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
0584 
0585         case ACPI_REFCLASS_LOCAL:
0586             /*
0587              * No error message for this case, will be trapped again later to
0588              * detect and ignore cases of Store(LocalX,LocalX)
0589              */
0590             return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
0591 
0592         default:
0593 
0594             ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
0595             return_ACPI_STATUS (AE_AML_INTERNAL);
0596         }
0597     }
0598 
0599     /*
0600      * The Index points to an initialized and valid object.
0601      * Return an additional reference to the object
0602      */
0603     *DestDesc = Object;
0604     AcpiUtAddReference (Object);
0605 
0606     return_ACPI_STATUS (AE_OK);
0607 }
0608 
0609 
0610 /*******************************************************************************
0611  *
0612  * FUNCTION:    AcpiDsMethodDataDeleteValue
0613  *
0614  * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
0615  *                                    ACPI_REFCLASS_ARG
0616  *              Index               - Which localVar or argument to delete
0617  *              WalkState           - Current walk state object
0618  *
0619  * RETURN:      None
0620  *
0621  * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
0622  *              a null into the stack slot after the object is deleted.
0623  *
0624  ******************************************************************************/
0625 
0626 static void
0627 AcpiDsMethodDataDeleteValue (
0628     UINT8                   Type,
0629     UINT32                  Index,
0630     ACPI_WALK_STATE         *WalkState)
0631 {
0632     ACPI_STATUS             Status;
0633     ACPI_NAMESPACE_NODE     *Node;
0634     ACPI_OPERAND_OBJECT     *Object;
0635 
0636 
0637     ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
0638 
0639 
0640     /* Get the namespace node for the arg/local */
0641 
0642     Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
0643     if (ACPI_FAILURE (Status))
0644     {
0645         return_VOID;
0646     }
0647 
0648     /* Get the associated object */
0649 
0650     Object = AcpiNsGetAttachedObject (Node);
0651 
0652     /*
0653      * Undefine the Arg or Local by setting its descriptor
0654      * pointer to NULL. Locals/Args can contain both
0655      * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
0656      */
0657     Node->Object = NULL;
0658 
0659     if ((Object) &&
0660         (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
0661     {
0662         /*
0663          * There is a valid object.
0664          * Decrement the reference count by one to balance the
0665          * increment when the object was stored.
0666          */
0667         AcpiUtRemoveReference (Object);
0668     }
0669 
0670     return_VOID;
0671 }
0672 
0673 
0674 /*******************************************************************************
0675  *
0676  * FUNCTION:    AcpiDsStoreObjectToLocal
0677  *
0678  * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
0679  *                                    ACPI_REFCLASS_ARG
0680  *              Index               - Which Local or Arg to set
0681  *              ObjDesc             - Value to be stored
0682  *              WalkState           - Current walk state
0683  *
0684  * RETURN:      Status
0685  *
0686  * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
0687  *              as the new value for the Arg or Local and the reference count
0688  *              for ObjDesc is incremented.
0689  *
0690  ******************************************************************************/
0691 
0692 ACPI_STATUS
0693 AcpiDsStoreObjectToLocal (
0694     UINT8                   Type,
0695     UINT32                  Index,
0696     ACPI_OPERAND_OBJECT     *ObjDesc,
0697     ACPI_WALK_STATE         *WalkState)
0698 {
0699     ACPI_STATUS             Status;
0700     ACPI_NAMESPACE_NODE     *Node;
0701     ACPI_OPERAND_OBJECT     *CurrentObjDesc;
0702     ACPI_OPERAND_OBJECT     *NewObjDesc;
0703 
0704 
0705     ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
0706     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
0707         Type, Index, ObjDesc));
0708 
0709     /* Parameter validation */
0710 
0711     if (!ObjDesc)
0712     {
0713         return_ACPI_STATUS (AE_BAD_PARAMETER);
0714     }
0715 
0716     /* Get the namespace node for the arg/local */
0717 
0718     Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
0719     if (ACPI_FAILURE (Status))
0720     {
0721         return_ACPI_STATUS (Status);
0722     }
0723 
0724     CurrentObjDesc = AcpiNsGetAttachedObject (Node);
0725     if (CurrentObjDesc == ObjDesc)
0726     {
0727         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
0728             ObjDesc));
0729         return_ACPI_STATUS (Status);
0730     }
0731 
0732     /*
0733      * If the reference count on the object is more than one, we must
0734      * take a copy of the object before we store. A reference count
0735      * of exactly 1 means that the object was just created during the
0736      * evaluation of an expression, and we can safely use it since it
0737      * is not used anywhere else.
0738      */
0739     NewObjDesc = ObjDesc;
0740     if (ObjDesc->Common.ReferenceCount > 1)
0741     {
0742         Status = AcpiUtCopyIobjectToIobject (
0743             ObjDesc, &NewObjDesc, WalkState);
0744         if (ACPI_FAILURE (Status))
0745         {
0746             return_ACPI_STATUS (Status);
0747         }
0748     }
0749 
0750     /*
0751      * If there is an object already in this slot, we either
0752      * have to delete it, or if this is an argument and there
0753      * is an object reference stored there, we have to do
0754      * an indirect store!
0755      */
0756     if (CurrentObjDesc)
0757     {
0758         /*
0759          * Check for an indirect store if an argument
0760          * contains an object reference (stored as an Node).
0761          * We don't allow this automatic dereferencing for
0762          * locals, since a store to a local should overwrite
0763          * anything there, including an object reference.
0764          *
0765          * If both Arg0 and Local0 contain RefOf (Local4):
0766          *
0767          * Store (1, Arg0)             - Causes indirect store to local4
0768          * Store (1, Local0)           - Stores 1 in local0, overwriting
0769          *                                  the reference to local4
0770          * Store (1, DeRefof (Local0)) - Causes indirect store to local4
0771          *
0772          * Weird, but true.
0773          */
0774         if (Type == ACPI_REFCLASS_ARG)
0775         {
0776             /*
0777              * If we have a valid reference object that came from RefOf(),
0778              * do the indirect store
0779              */
0780             if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) ==
0781                     ACPI_DESC_TYPE_OPERAND) &&
0782                 (CurrentObjDesc->Common.Type ==
0783                     ACPI_TYPE_LOCAL_REFERENCE) &&
0784                 (CurrentObjDesc->Reference.Class ==
0785                     ACPI_REFCLASS_REFOF))
0786             {
0787                 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0788                     "Arg (%p) is an ObjRef(Node), storing in node %p\n",
0789                     NewObjDesc, CurrentObjDesc));
0790 
0791                 /*
0792                  * Store this object to the Node (perform the indirect store)
0793                  * NOTE: No implicit conversion is performed, as per the ACPI
0794                  * specification rules on storing to Locals/Args.
0795                  */
0796                 Status = AcpiExStoreObjectToNode (NewObjDesc,
0797                     CurrentObjDesc->Reference.Object, WalkState,
0798                     ACPI_NO_IMPLICIT_CONVERSION);
0799 
0800                 /* Remove local reference if we copied the object above */
0801 
0802                 if (NewObjDesc != ObjDesc)
0803                 {
0804                     AcpiUtRemoveReference (NewObjDesc);
0805                 }
0806 
0807                 return_ACPI_STATUS (Status);
0808             }
0809         }
0810 
0811         /* Delete the existing object before storing the new one */
0812 
0813         AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
0814     }
0815 
0816     /*
0817      * Install the Obj descriptor (*NewObjDesc) into
0818      * the descriptor for the Arg or Local.
0819      * (increments the object reference count by one)
0820      */
0821     Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
0822 
0823     /* Remove local reference if we copied the object above */
0824 
0825     if (NewObjDesc != ObjDesc)
0826     {
0827         AcpiUtRemoveReference (NewObjDesc);
0828     }
0829 
0830     return_ACPI_STATUS (Status);
0831 }
0832 
0833 
0834 #ifdef ACPI_OBSOLETE_FUNCTIONS
0835 /*******************************************************************************
0836  *
0837  * FUNCTION:    AcpiDsMethodDataGetType
0838  *
0839  * PARAMETERS:  Opcode              - Either AML_FIRST LOCAL_OP or
0840  *                                    AML_FIRST_ARG_OP
0841  *              Index               - Which Local or Arg whose type to get
0842  *              WalkState           - Current walk state object
0843  *
0844  * RETURN:      Data type of current value of the selected Arg or Local
0845  *
0846  * DESCRIPTION: Get the type of the object stored in the Local or Arg
0847  *
0848  ******************************************************************************/
0849 
0850 ACPI_OBJECT_TYPE
0851 AcpiDsMethodDataGetType (
0852     UINT16                  Opcode,
0853     UINT32                  Index,
0854     ACPI_WALK_STATE         *WalkState)
0855 {
0856     ACPI_STATUS             Status;
0857     ACPI_NAMESPACE_NODE     *Node;
0858     ACPI_OPERAND_OBJECT     *Object;
0859 
0860 
0861     ACPI_FUNCTION_TRACE (DsMethodDataGetType);
0862 
0863 
0864     /* Get the namespace node for the arg/local */
0865 
0866     Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
0867     if (ACPI_FAILURE (Status))
0868     {
0869         return_VALUE ((ACPI_TYPE_NOT_FOUND));
0870     }
0871 
0872     /* Get the object */
0873 
0874     Object = AcpiNsGetAttachedObject (Node);
0875     if (!Object)
0876     {
0877         /* Uninitialized local/arg, return TYPE_ANY */
0878 
0879         return_VALUE (ACPI_TYPE_ANY);
0880     }
0881 
0882     /* Get the object type */
0883 
0884     return_VALUE (Object->Type);
0885 }
0886 #endif