exresolv.c revision 193267
167754Smsmith
267754Smsmith/******************************************************************************
367754Smsmith *
477424Smsmith * Module Name: exresolv - AML Interpreter object resolution
567754Smsmith *
667754Smsmith *****************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11777424Smsmith#define __EXRESOLV_C__
11867754Smsmith
119193251Sjkim#include "acpi.h"
120193267Sjkim#include "accommon.h"
121193251Sjkim#include "amlcode.h"
122193251Sjkim#include "acdispat.h"
123193251Sjkim#include "acinterp.h"
124193251Sjkim#include "acnamesp.h"
12567754Smsmith
12667754Smsmith
12777424Smsmith#define _COMPONENT          ACPI_EXECUTER
12891116Smsmith        ACPI_MODULE_NAME    ("exresolv")
12967754Smsmith
130151937Sjkim/* Local prototypes */
13167754Smsmith
132151937Sjkimstatic ACPI_STATUS
133151937SjkimAcpiExResolveObjectToValue (
134151937Sjkim    ACPI_OPERAND_OBJECT     **StackPtr,
135151937Sjkim    ACPI_WALK_STATE         *WalkState);
136151937Sjkim
137151937Sjkim
13867754Smsmith/*******************************************************************************
13967754Smsmith *
14077424Smsmith * FUNCTION:    AcpiExResolveToValue
14167754Smsmith *
14267754Smsmith * PARAMETERS:  **StackPtr          - Points to entry on ObjStack, which can
14377424Smsmith *                                    be either an (ACPI_OPERAND_OBJECT *)
14467754Smsmith *                                    or an ACPI_HANDLE.
14577424Smsmith *              WalkState           - Current method state
14667754Smsmith *
14767754Smsmith * RETURN:      Status
14867754Smsmith *
14971867Smsmith * DESCRIPTION: Convert Reference objects to values
15067754Smsmith *
15167754Smsmith ******************************************************************************/
15267754Smsmith
15367754SmsmithACPI_STATUS
15477424SmsmithAcpiExResolveToValue (
15567754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
15667754Smsmith    ACPI_WALK_STATE         *WalkState)
15767754Smsmith{
15877424Smsmith    ACPI_STATUS             Status;
15967754Smsmith
16067754Smsmith
161167802Sjkim    ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);
16267754Smsmith
16367754Smsmith
16467754Smsmith    if (!StackPtr || !*StackPtr)
16567754Smsmith    {
166167802Sjkim        ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
16767754Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
16867754Smsmith    }
16967754Smsmith
17067754Smsmith    /*
17167754Smsmith     * The entity pointed to by the StackPtr can be either
17267754Smsmith     * 1) A valid ACPI_OPERAND_OBJECT, or
17367754Smsmith     * 2) A ACPI_NAMESPACE_NODE (NamedObj)
17467754Smsmith     */
17599679Siwasaki    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)
17667754Smsmith    {
17777424Smsmith        Status = AcpiExResolveObjectToValue (StackPtr, WalkState);
17867754Smsmith        if (ACPI_FAILURE (Status))
17967754Smsmith        {
18067754Smsmith            return_ACPI_STATUS (Status);
18167754Smsmith        }
182151937Sjkim
183151937Sjkim        if (!*StackPtr)
184151937Sjkim        {
185167802Sjkim            ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
186151937Sjkim            return_ACPI_STATUS (AE_AML_NO_OPERAND);
187151937Sjkim        }
18867754Smsmith    }
18967754Smsmith
19067754Smsmith    /*
19177424Smsmith     * Object on the stack may have changed if AcpiExResolveObjectToValue()
19267754Smsmith     * was called (i.e., we can't use an _else_ here.)
19367754Smsmith     */
19491116Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)
19567754Smsmith    {
19699679Siwasaki        Status = AcpiExResolveNodeToValue (
19799679Siwasaki                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),
19877424Smsmith                        WalkState);
19977424Smsmith        if (ACPI_FAILURE (Status))
20077424Smsmith        {
20177424Smsmith            return_ACPI_STATUS (Status);
20277424Smsmith        }
20367754Smsmith    }
20467754Smsmith
20599146Siwasaki    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));
20677424Smsmith    return_ACPI_STATUS (AE_OK);
20767754Smsmith}
20867754Smsmith
20967754Smsmith
21067754Smsmith/*******************************************************************************
21167754Smsmith *
21277424Smsmith * FUNCTION:    AcpiExResolveObjectToValue
21367754Smsmith *
214151937Sjkim * PARAMETERS:  StackPtr        - Pointer to an internal object
21577424Smsmith *              WalkState       - Current method state
21667754Smsmith *
21767754Smsmith * RETURN:      Status
21867754Smsmith *
219151937Sjkim * DESCRIPTION: Retrieve the value from an internal object. The Reference type
22067754Smsmith *              uses the associated AML opcode to determine the value.
22167754Smsmith *
22267754Smsmith ******************************************************************************/
22367754Smsmith
224151937Sjkimstatic ACPI_STATUS
22577424SmsmithAcpiExResolveObjectToValue (
22667754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
22767754Smsmith    ACPI_WALK_STATE         *WalkState)
22867754Smsmith{
22977424Smsmith    ACPI_STATUS             Status = AE_OK;
23067754Smsmith    ACPI_OPERAND_OBJECT     *StackDesc;
231167802Sjkim    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
232193267Sjkim    UINT8                   RefType;
23367754Smsmith
23467754Smsmith
235167802Sjkim    ACPI_FUNCTION_TRACE (ExResolveObjectToValue);
23667754Smsmith
23767754Smsmith
23867754Smsmith    StackDesc = *StackPtr;
23967754Smsmith
24067754Smsmith    /* This is an ACPI_OPERAND_OBJECT  */
24167754Smsmith
242193267Sjkim    switch (StackDesc->Common.Type)
24367754Smsmith    {
244107325Siwasaki    case ACPI_TYPE_LOCAL_REFERENCE:
24567754Smsmith
246193267Sjkim        RefType = StackDesc->Reference.Class;
24767754Smsmith
248193267Sjkim        switch (RefType)
24967754Smsmith        {
250193267Sjkim        case ACPI_REFCLASS_LOCAL:
251193267Sjkim        case ACPI_REFCLASS_ARG:
25267754Smsmith
25367754Smsmith            /*
25467754Smsmith             * Get the local from the method's state info
25567754Smsmith             * Note: this increments the local's object reference count
25667754Smsmith             */
257193267Sjkim            Status = AcpiDsMethodDataGetValue (RefType,
258193267Sjkim                            StackDesc->Reference.Value, WalkState, &ObjDesc);
25967754Smsmith            if (ACPI_FAILURE (Status))
26067754Smsmith            {
26167754Smsmith                return_ACPI_STATUS (Status);
26267754Smsmith            }
26367754Smsmith
264129684Snjl            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",
265193267Sjkim                StackDesc->Reference.Value, ObjDesc));
266129684Snjl
26767754Smsmith            /*
26867754Smsmith             * Now we can delete the original Reference Object and
269129684Snjl             * replace it with the resolved value
27067754Smsmith             */
27177424Smsmith            AcpiUtRemoveReference (StackDesc);
27267754Smsmith            *StackPtr = ObjDesc;
27367754Smsmith            break;
27467754Smsmith
27567754Smsmith
276193267Sjkim        case ACPI_REFCLASS_INDEX:
27767754Smsmith
27867754Smsmith            switch (StackDesc->Reference.TargetType)
27967754Smsmith            {
28067754Smsmith            case ACPI_TYPE_BUFFER_FIELD:
28167754Smsmith
282193267Sjkim                /* Just return - do not dereference */
28367754Smsmith                break;
28467754Smsmith
28567754Smsmith
28667754Smsmith            case ACPI_TYPE_PACKAGE:
28799679Siwasaki
288193267Sjkim                /* If method call or CopyObject - do not dereference */
289193267Sjkim
290193267Sjkim                if ((WalkState->Opcode == AML_INT_METHODCALL_OP) ||
291193267Sjkim                    (WalkState->Opcode == AML_COPY_OP))
292193267Sjkim                {
293193267Sjkim                    break;
294193267Sjkim                }
295193267Sjkim
296193267Sjkim                /* Otherwise, dereference the PackageIndex to a package element */
297193267Sjkim
29867754Smsmith                ObjDesc = *StackDesc->Reference.Where;
29967754Smsmith                if (ObjDesc)
30067754Smsmith                {
30167754Smsmith                    /*
302193267Sjkim                     * Valid object descriptor, copy pointer to return value
30367754Smsmith                     * (i.e., dereference the package index)
30467754Smsmith                     * Delete the ref object, increment the returned object
30567754Smsmith                     */
30677424Smsmith                    AcpiUtRemoveReference (StackDesc);
30777424Smsmith                    AcpiUtAddReference (ObjDesc);
30867754Smsmith                    *StackPtr = ObjDesc;
30967754Smsmith                }
31067754Smsmith                else
31167754Smsmith                {
31267754Smsmith                    /*
313193267Sjkim                     * A NULL object descriptor means an uninitialized element of
31477424Smsmith                     * the package, can't dereference it
31567754Smsmith                     */
316167802Sjkim                    ACPI_ERROR ((AE_INFO,
317193267Sjkim                        "Attempt to dereference an Index to NULL package element Idx=%p",
31877424Smsmith                        StackDesc));
31967754Smsmith                    Status = AE_AML_UNINITIALIZED_ELEMENT;
32067754Smsmith                }
32167754Smsmith                break;
32267754Smsmith
32399679Siwasaki
32467754Smsmith            default:
32599679Siwasaki
32677424Smsmith                /* Invalid reference object */
32767754Smsmith
328167802Sjkim                ACPI_ERROR ((AE_INFO,
329193267Sjkim                    "Unknown TargetType %X in Index/Reference object %p",
33067754Smsmith                    StackDesc->Reference.TargetType, StackDesc));
33167754Smsmith                Status = AE_AML_INTERNAL;
33267754Smsmith                break;
33367754Smsmith            }
33467754Smsmith            break;
33567754Smsmith
33667754Smsmith
337193267Sjkim        case ACPI_REFCLASS_REFOF:
338193267Sjkim        case ACPI_REFCLASS_DEBUG:
339193267Sjkim        case ACPI_REFCLASS_TABLE:
34067754Smsmith
341193267Sjkim            /* Just leave the object as-is, do not dereference */
342100966Siwasaki
34367754Smsmith            break;
34467754Smsmith
345193267Sjkim        case ACPI_REFCLASS_NAME:   /* Reference to a named object */
34667754Smsmith
347167802Sjkim            /* Dereference the name */
348151937Sjkim
349167802Sjkim            if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||
350167802Sjkim                (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))
351167802Sjkim            {
352167802Sjkim                /* These node types do not have 'real' subobjects */
353167802Sjkim
354167802Sjkim                *StackPtr = (void *) StackDesc->Reference.Node;
355167802Sjkim            }
356167802Sjkim            else
357167802Sjkim            {
358167802Sjkim                /* Get the object pointed to by the namespace node */
359167802Sjkim
360167802Sjkim                *StackPtr = (StackDesc->Reference.Node)->Object;
361167802Sjkim                AcpiUtAddReference (*StackPtr);
362167802Sjkim            }
363167802Sjkim
364151937Sjkim            AcpiUtRemoveReference (StackDesc);
365151937Sjkim            break;
366151937Sjkim
36767754Smsmith        default:
36867754Smsmith
369167802Sjkim            ACPI_ERROR ((AE_INFO,
370193267Sjkim                "Unknown Reference type %X in %p", RefType, StackDesc));
37167754Smsmith            Status = AE_AML_INTERNAL;
37277424Smsmith            break;
37399679Siwasaki        }
37499679Siwasaki        break;
37567754Smsmith
37667754Smsmith
37799146Siwasaki    case ACPI_TYPE_BUFFER:
37899146Siwasaki
37999146Siwasaki        Status = AcpiDsGetBufferArguments (StackDesc);
38099146Siwasaki        break;
38199146Siwasaki
38299146Siwasaki
38399146Siwasaki    case ACPI_TYPE_PACKAGE:
38499146Siwasaki
38599146Siwasaki        Status = AcpiDsGetPackageArguments (StackDesc);
38699146Siwasaki        break;
38799146Siwasaki
38899146Siwasaki
38977424Smsmith    case ACPI_TYPE_BUFFER_FIELD:
390107325Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
391107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
392107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
39367754Smsmith
39487031Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead SourceDesc=%p Type=%X\n",
395193267Sjkim            StackDesc, StackDesc->Common.Type));
39667754Smsmith
39799146Siwasaki        Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);
398167802Sjkim
399167802Sjkim        /* Remove a reference to the original operand, then override */
400167802Sjkim
401167802Sjkim        AcpiUtRemoveReference (*StackPtr);
40267754Smsmith        *StackPtr = (void *) ObjDesc;
40367754Smsmith        break;
40467754Smsmith
40567754Smsmith    default:
40667754Smsmith        break;
40787031Smsmith    }
40867754Smsmith
40967754Smsmith    return_ACPI_STATUS (Status);
41067754Smsmith}
41167754Smsmith
41267754Smsmith
413104470Siwasaki/*******************************************************************************
414104470Siwasaki *
415104470Siwasaki * FUNCTION:    AcpiExResolveMultiple
416104470Siwasaki *
417104470Siwasaki * PARAMETERS:  WalkState           - Current state (contains AML opcode)
418104470Siwasaki *              Operand             - Starting point for resolution
419104470Siwasaki *              ReturnType          - Where the object type is returned
420104470Siwasaki *              ReturnDesc          - Where the resolved object is returned
421104470Siwasaki *
422104470Siwasaki * RETURN:      Status
423104470Siwasaki *
424104470Siwasaki * DESCRIPTION: Return the base object and type.  Traverse a reference list if
425104470Siwasaki *              necessary to get to the base object.
426104470Siwasaki *
427104470Siwasaki ******************************************************************************/
428104470Siwasaki
429104470SiwasakiACPI_STATUS
430104470SiwasakiAcpiExResolveMultiple (
431104470Siwasaki    ACPI_WALK_STATE         *WalkState,
432104470Siwasaki    ACPI_OPERAND_OBJECT     *Operand,
433104470Siwasaki    ACPI_OBJECT_TYPE        *ReturnType,
434104470Siwasaki    ACPI_OPERAND_OBJECT     **ReturnDesc)
435104470Siwasaki{
436104470Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc = (void *) Operand;
437104470Siwasaki    ACPI_NAMESPACE_NODE     *Node;
438104470Siwasaki    ACPI_OBJECT_TYPE        Type;
439138287Smarks    ACPI_STATUS             Status;
440104470Siwasaki
441104470Siwasaki
442167802Sjkim    ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);
443104470Siwasaki
444104470Siwasaki
445151937Sjkim    /* Operand can be either a namespace node or an operand descriptor */
446138287Smarks
447138287Smarks    switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
448138287Smarks    {
449138287Smarks    case ACPI_DESC_TYPE_OPERAND:
450138287Smarks        Type = ObjDesc->Common.Type;
451138287Smarks        break;
452138287Smarks
453138287Smarks    case ACPI_DESC_TYPE_NAMED:
454138287Smarks        Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
455138287Smarks        ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
456138287Smarks
457138287Smarks        /* If we had an Alias node, use the attached object for type info */
458138287Smarks
459138287Smarks        if (Type == ACPI_TYPE_LOCAL_ALIAS)
460138287Smarks        {
461138287Smarks            Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
462138287Smarks            ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
463138287Smarks        }
464138287Smarks        break;
465138287Smarks
466138287Smarks    default:
467138287Smarks        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
468138287Smarks    }
469138287Smarks
470151937Sjkim    /* If type is anything other than a reference, we are done */
471138287Smarks
472138287Smarks    if (Type != ACPI_TYPE_LOCAL_REFERENCE)
473138287Smarks    {
474138287Smarks        goto Exit;
475138287Smarks    }
476138287Smarks
477138287Smarks    /*
478193267Sjkim     * For reference objects created via the RefOf, Index, or Load/LoadTable
479193267Sjkim     * operators, we need to get to the base object (as per the ACPI
480193267Sjkim     * specification of the ObjectType and SizeOf operators). This means
481193267Sjkim     * traversing the list of possibly many nested references.
482104470Siwasaki     */
483193267Sjkim    while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
484104470Siwasaki    {
485193267Sjkim        switch (ObjDesc->Reference.Class)
486104470Siwasaki        {
487193267Sjkim        case ACPI_REFCLASS_REFOF:
488193267Sjkim        case ACPI_REFCLASS_NAME:
489104470Siwasaki
490104470Siwasaki            /* Dereference the reference pointer */
491104470Siwasaki
492193267Sjkim            if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)
493167802Sjkim            {
494167802Sjkim                Node = ObjDesc->Reference.Object;
495167802Sjkim            }
496167802Sjkim            else /* AML_INT_NAMEPATH_OP */
497167802Sjkim            {
498167802Sjkim                Node = ObjDesc->Reference.Node;
499167802Sjkim            }
500104470Siwasaki
501104470Siwasaki            /* All "References" point to a NS node */
502104470Siwasaki
503104470Siwasaki            if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
504104470Siwasaki            {
505167802Sjkim                ACPI_ERROR ((AE_INFO,
506167802Sjkim                    "Not a NS node %p [%s]",
507151937Sjkim                    Node, AcpiUtGetDescriptorName (Node)));
508104470Siwasaki                return_ACPI_STATUS (AE_AML_INTERNAL);
509104470Siwasaki            }
510104470Siwasaki
511104470Siwasaki            /* Get the attached object */
512104470Siwasaki
513104470Siwasaki            ObjDesc = AcpiNsGetAttachedObject (Node);
514104470Siwasaki            if (!ObjDesc)
515104470Siwasaki            {
516104470Siwasaki                /* No object, use the NS node type */
517104470Siwasaki
518104470Siwasaki                Type = AcpiNsGetType (Node);
519104470Siwasaki                goto Exit;
520104470Siwasaki            }
521104470Siwasaki
522104470Siwasaki            /* Check for circular references */
523104470Siwasaki
524104470Siwasaki            if (ObjDesc == Operand)
525104470Siwasaki            {
526104470Siwasaki                return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
527104470Siwasaki            }
528104470Siwasaki            break;
529104470Siwasaki
530104470Siwasaki
531193267Sjkim        case ACPI_REFCLASS_INDEX:
532104470Siwasaki
533104470Siwasaki            /* Get the type of this reference (index into another object) */
534104470Siwasaki
535104470Siwasaki            Type = ObjDesc->Reference.TargetType;
536104470Siwasaki            if (Type != ACPI_TYPE_PACKAGE)
537104470Siwasaki            {
538104470Siwasaki                goto Exit;
539104470Siwasaki            }
540104470Siwasaki
541104470Siwasaki            /*
542104470Siwasaki             * The main object is a package, we want to get the type
543104470Siwasaki             * of the individual package element that is referenced by
544104470Siwasaki             * the index.
545104470Siwasaki             *
546104470Siwasaki             * This could of course in turn be another reference object.
547104470Siwasaki             */
548104470Siwasaki            ObjDesc = *(ObjDesc->Reference.Where);
549151937Sjkim            if (!ObjDesc)
550151937Sjkim            {
551151937Sjkim                /* NULL package elements are allowed */
552151937Sjkim
553151937Sjkim                Type = 0; /* Uninitialized */
554151937Sjkim                goto Exit;
555151937Sjkim            }
556104470Siwasaki            break;
557104470Siwasaki
558104470Siwasaki
559193267Sjkim        case ACPI_REFCLASS_TABLE:
560138287Smarks
561193267Sjkim            Type = ACPI_TYPE_DDB_HANDLE;
562193267Sjkim            goto Exit;
563193267Sjkim
564193267Sjkim
565193267Sjkim        case ACPI_REFCLASS_LOCAL:
566193267Sjkim        case ACPI_REFCLASS_ARG:
567193267Sjkim
568138287Smarks            if (ReturnDesc)
569138287Smarks            {
570193267Sjkim                Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class,
571193267Sjkim                            ObjDesc->Reference.Value, WalkState, &ObjDesc);
572138287Smarks                if (ACPI_FAILURE (Status))
573138287Smarks                {
574138287Smarks                    return_ACPI_STATUS (Status);
575138287Smarks                }
576138287Smarks                AcpiUtRemoveReference (ObjDesc);
577138287Smarks            }
578138287Smarks            else
579138287Smarks            {
580193267Sjkim                Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class,
581193267Sjkim                            ObjDesc->Reference.Value, WalkState, &Node);
582138287Smarks                if (ACPI_FAILURE (Status))
583138287Smarks                {
584138287Smarks                    return_ACPI_STATUS (Status);
585138287Smarks                }
586138287Smarks
587138287Smarks                ObjDesc = AcpiNsGetAttachedObject (Node);
588138287Smarks                if (!ObjDesc)
589138287Smarks                {
590138287Smarks                    Type = ACPI_TYPE_ANY;
591138287Smarks                    goto Exit;
592138287Smarks                }
593138287Smarks            }
594138287Smarks            break;
595138287Smarks
596138287Smarks
597193267Sjkim        case ACPI_REFCLASS_DEBUG:
598104470Siwasaki
599104470Siwasaki            /* The Debug Object is of type "DebugObject" */
600104470Siwasaki
601104470Siwasaki            Type = ACPI_TYPE_DEBUG_OBJECT;
602104470Siwasaki            goto Exit;
603104470Siwasaki
604104470Siwasaki
605104470Siwasaki        default:
606104470Siwasaki
607167802Sjkim            ACPI_ERROR ((AE_INFO,
608193267Sjkim                "Unknown Reference Class %2.2X", ObjDesc->Reference.Class));
609104470Siwasaki            return_ACPI_STATUS (AE_AML_INTERNAL);
610104470Siwasaki        }
611104470Siwasaki    }
612104470Siwasaki
613104470Siwasaki    /*
614104470Siwasaki     * Now we are guaranteed to have an object that has not been created
615104470Siwasaki     * via the RefOf or Index operators.
616104470Siwasaki     */
617193267Sjkim    Type = ObjDesc->Common.Type;
618104470Siwasaki
619104470Siwasaki
620104470SiwasakiExit:
621104470Siwasaki    /* Convert internal types to external types */
622104470Siwasaki
623104470Siwasaki    switch (Type)
624104470Siwasaki    {
625107325Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
626107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
627107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
628104470Siwasaki
629104470Siwasaki        Type = ACPI_TYPE_FIELD_UNIT;
630104470Siwasaki        break;
631104470Siwasaki
632107325Siwasaki    case ACPI_TYPE_LOCAL_SCOPE:
633107325Siwasaki
634107325Siwasaki        /* Per ACPI Specification, Scope is untyped */
635107325Siwasaki
636107325Siwasaki        Type = ACPI_TYPE_ANY;
637107325Siwasaki        break;
638107325Siwasaki
639104470Siwasaki    default:
640104470Siwasaki        /* No change to Type required */
641104470Siwasaki        break;
642104470Siwasaki    }
643104470Siwasaki
644104470Siwasaki    *ReturnType = Type;
645104470Siwasaki    if (ReturnDesc)
646104470Siwasaki    {
647104470Siwasaki        *ReturnDesc = ObjDesc;
648104470Siwasaki    }
649104470Siwasaki    return_ACPI_STATUS (AE_OK);
650104470Siwasaki}
651104470Siwasaki
652104470Siwasaki
653