exresolv.c revision 167802
167754Smsmith
267754Smsmith/******************************************************************************
367754Smsmith *
477424Smsmith * Module Name: exresolv - AML Interpreter object resolution
5167802Sjkim *              $Revision: 1.142 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
13167802Sjkim * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11877424Smsmith#define __EXRESOLV_C__
11967754Smsmith
120151600Sobrien#include <contrib/dev/acpica/acpi.h>
121151600Sobrien#include <contrib/dev/acpica/amlcode.h>
122151600Sobrien#include <contrib/dev/acpica/acdispat.h>
123151600Sobrien#include <contrib/dev/acpica/acinterp.h>
124151600Sobrien#include <contrib/dev/acpica/acnamesp.h>
125151600Sobrien#include <contrib/dev/acpica/acparser.h>
12667754Smsmith
12767754Smsmith
12877424Smsmith#define _COMPONENT          ACPI_EXECUTER
12991116Smsmith        ACPI_MODULE_NAME    ("exresolv")
13067754Smsmith
131151937Sjkim/* Local prototypes */
13267754Smsmith
133151937Sjkimstatic ACPI_STATUS
134151937SjkimAcpiExResolveObjectToValue (
135151937Sjkim    ACPI_OPERAND_OBJECT     **StackPtr,
136151937Sjkim    ACPI_WALK_STATE         *WalkState);
137151937Sjkim
138151937Sjkim
13967754Smsmith/*******************************************************************************
14067754Smsmith *
14177424Smsmith * FUNCTION:    AcpiExResolveToValue
14267754Smsmith *
14367754Smsmith * PARAMETERS:  **StackPtr          - Points to entry on ObjStack, which can
14477424Smsmith *                                    be either an (ACPI_OPERAND_OBJECT *)
14567754Smsmith *                                    or an ACPI_HANDLE.
14677424Smsmith *              WalkState           - Current method state
14767754Smsmith *
14867754Smsmith * RETURN:      Status
14967754Smsmith *
15071867Smsmith * DESCRIPTION: Convert Reference objects to values
15167754Smsmith *
15267754Smsmith ******************************************************************************/
15367754Smsmith
15467754SmsmithACPI_STATUS
15577424SmsmithAcpiExResolveToValue (
15667754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
15767754Smsmith    ACPI_WALK_STATE         *WalkState)
15867754Smsmith{
15977424Smsmith    ACPI_STATUS             Status;
16067754Smsmith
16167754Smsmith
162167802Sjkim    ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);
16367754Smsmith
16467754Smsmith
16567754Smsmith    if (!StackPtr || !*StackPtr)
16667754Smsmith    {
167167802Sjkim        ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
16867754Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
16967754Smsmith    }
17067754Smsmith
17167754Smsmith    /*
17267754Smsmith     * The entity pointed to by the StackPtr can be either
17367754Smsmith     * 1) A valid ACPI_OPERAND_OBJECT, or
17467754Smsmith     * 2) A ACPI_NAMESPACE_NODE (NamedObj)
17567754Smsmith     */
17699679Siwasaki    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)
17767754Smsmith    {
17877424Smsmith        Status = AcpiExResolveObjectToValue (StackPtr, WalkState);
17967754Smsmith        if (ACPI_FAILURE (Status))
18067754Smsmith        {
18167754Smsmith            return_ACPI_STATUS (Status);
18267754Smsmith        }
183151937Sjkim
184151937Sjkim        if (!*StackPtr)
185151937Sjkim        {
186167802Sjkim            ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
187151937Sjkim            return_ACPI_STATUS (AE_AML_NO_OPERAND);
188151937Sjkim        }
18967754Smsmith    }
19067754Smsmith
19167754Smsmith    /*
19277424Smsmith     * Object on the stack may have changed if AcpiExResolveObjectToValue()
19367754Smsmith     * was called (i.e., we can't use an _else_ here.)
19467754Smsmith     */
19591116Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)
19667754Smsmith    {
19799679Siwasaki        Status = AcpiExResolveNodeToValue (
19899679Siwasaki                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),
19977424Smsmith                        WalkState);
20077424Smsmith        if (ACPI_FAILURE (Status))
20177424Smsmith        {
20277424Smsmith            return_ACPI_STATUS (Status);
20377424Smsmith        }
20467754Smsmith    }
20567754Smsmith
20699146Siwasaki    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));
20777424Smsmith    return_ACPI_STATUS (AE_OK);
20867754Smsmith}
20967754Smsmith
21067754Smsmith
21167754Smsmith/*******************************************************************************
21267754Smsmith *
21377424Smsmith * FUNCTION:    AcpiExResolveObjectToValue
21467754Smsmith *
215151937Sjkim * PARAMETERS:  StackPtr        - Pointer to an internal object
21677424Smsmith *              WalkState       - Current method state
21767754Smsmith *
21867754Smsmith * RETURN:      Status
21967754Smsmith *
220151937Sjkim * DESCRIPTION: Retrieve the value from an internal object. The Reference type
22167754Smsmith *              uses the associated AML opcode to determine the value.
22267754Smsmith *
22367754Smsmith ******************************************************************************/
22467754Smsmith
225151937Sjkimstatic ACPI_STATUS
22677424SmsmithAcpiExResolveObjectToValue (
22767754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
22867754Smsmith    ACPI_WALK_STATE         *WalkState)
22967754Smsmith{
23077424Smsmith    ACPI_STATUS             Status = AE_OK;
23167754Smsmith    ACPI_OPERAND_OBJECT     *StackDesc;
232167802Sjkim    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
23367754Smsmith    UINT16                  Opcode;
23467754Smsmith
23567754Smsmith
236167802Sjkim    ACPI_FUNCTION_TRACE (ExResolveObjectToValue);
23767754Smsmith
23867754Smsmith
23967754Smsmith    StackDesc = *StackPtr;
24067754Smsmith
24167754Smsmith    /* This is an ACPI_OPERAND_OBJECT  */
24267754Smsmith
24399679Siwasaki    switch (ACPI_GET_OBJECT_TYPE (StackDesc))
24467754Smsmith    {
245107325Siwasaki    case ACPI_TYPE_LOCAL_REFERENCE:
24667754Smsmith
24777424Smsmith        Opcode = StackDesc->Reference.Opcode;
24867754Smsmith
24967754Smsmith        switch (Opcode)
25067754Smsmith        {
25167754Smsmith        case AML_LOCAL_OP:
25277424Smsmith        case AML_ARG_OP:
25367754Smsmith
25467754Smsmith            /*
25567754Smsmith             * Get the local from the method's state info
25667754Smsmith             * Note: this increments the local's object reference count
25767754Smsmith             */
25877424Smsmith            Status = AcpiDsMethodDataGetValue (Opcode,
25977424Smsmith                            StackDesc->Reference.Offset, WalkState, &ObjDesc);
26067754Smsmith            if (ACPI_FAILURE (Status))
26167754Smsmith            {
26267754Smsmith                return_ACPI_STATUS (Status);
26367754Smsmith            }
26467754Smsmith
265129684Snjl            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",
266129684Snjl                StackDesc->Reference.Offset, ObjDesc));
267129684Snjl
26867754Smsmith            /*
26967754Smsmith             * Now we can delete the original Reference Object and
270129684Snjl             * replace it with the resolved value
27167754Smsmith             */
27277424Smsmith            AcpiUtRemoveReference (StackDesc);
27367754Smsmith            *StackPtr = ObjDesc;
27467754Smsmith            break;
27567754Smsmith
27667754Smsmith
27767754Smsmith        case AML_INDEX_OP:
27867754Smsmith
27967754Smsmith            switch (StackDesc->Reference.TargetType)
28067754Smsmith            {
28167754Smsmith            case ACPI_TYPE_BUFFER_FIELD:
28267754Smsmith
28367754Smsmith                /* Just return - leave the Reference on the stack */
28467754Smsmith                break;
28567754Smsmith
28667754Smsmith
28767754Smsmith            case ACPI_TYPE_PACKAGE:
28899679Siwasaki
28967754Smsmith                ObjDesc = *StackDesc->Reference.Where;
29067754Smsmith                if (ObjDesc)
29167754Smsmith                {
29267754Smsmith                    /*
29367754Smsmith                     * Valid obj descriptor, copy pointer to return value
29467754Smsmith                     * (i.e., dereference the package index)
29567754Smsmith                     * Delete the ref object, increment the returned object
29667754Smsmith                     */
29777424Smsmith                    AcpiUtRemoveReference (StackDesc);
29877424Smsmith                    AcpiUtAddReference (ObjDesc);
29967754Smsmith                    *StackPtr = ObjDesc;
30067754Smsmith                }
30167754Smsmith                else
30267754Smsmith                {
30367754Smsmith                    /*
30467754Smsmith                     * A NULL object descriptor means an unitialized element of
30577424Smsmith                     * the package, can't dereference it
30667754Smsmith                     */
307167802Sjkim                    ACPI_ERROR ((AE_INFO,
308167802Sjkim                        "Attempt to deref an Index to NULL pkg element Idx=%p",
30977424Smsmith                        StackDesc));
31067754Smsmith                    Status = AE_AML_UNINITIALIZED_ELEMENT;
31167754Smsmith                }
31267754Smsmith                break;
31367754Smsmith
31499679Siwasaki
31567754Smsmith            default:
31699679Siwasaki
31777424Smsmith                /* Invalid reference object */
31867754Smsmith
319167802Sjkim                ACPI_ERROR ((AE_INFO,
320167802Sjkim                    "Unknown TargetType %X in Index/Reference obj %p",
32167754Smsmith                    StackDesc->Reference.TargetType, StackDesc));
32267754Smsmith                Status = AE_AML_INTERNAL;
32367754Smsmith                break;
32467754Smsmith            }
32567754Smsmith            break;
32667754Smsmith
32767754Smsmith
328100966Siwasaki        case AML_REF_OF_OP:
32967754Smsmith        case AML_DEBUG_OP:
330123315Snjl        case AML_LOAD_OP:
33167754Smsmith
33267754Smsmith            /* Just leave the object as-is */
333100966Siwasaki
33467754Smsmith            break;
33567754Smsmith
336151937Sjkim        case AML_INT_NAMEPATH_OP:   /* Reference to a named object */
33767754Smsmith
338167802Sjkim            /* Dereference the name */
339151937Sjkim
340167802Sjkim            if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||
341167802Sjkim                (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))
342167802Sjkim            {
343167802Sjkim                /* These node types do not have 'real' subobjects */
344167802Sjkim
345167802Sjkim                *StackPtr = (void *) StackDesc->Reference.Node;
346167802Sjkim            }
347167802Sjkim            else
348167802Sjkim            {
349167802Sjkim                /* Get the object pointed to by the namespace node */
350167802Sjkim
351167802Sjkim                *StackPtr = (StackDesc->Reference.Node)->Object;
352167802Sjkim                AcpiUtAddReference (*StackPtr);
353167802Sjkim            }
354167802Sjkim
355151937Sjkim            AcpiUtRemoveReference (StackDesc);
356151937Sjkim            break;
357151937Sjkim
35867754Smsmith        default:
35967754Smsmith
360167802Sjkim            ACPI_ERROR ((AE_INFO,
361167802Sjkim                "Unknown Reference opcode %X (%s) in %p",
362123315Snjl                Opcode, AcpiPsGetOpcodeName (Opcode), StackDesc));
36367754Smsmith            Status = AE_AML_INTERNAL;
36477424Smsmith            break;
36599679Siwasaki        }
36699679Siwasaki        break;
36767754Smsmith
36867754Smsmith
36999146Siwasaki    case ACPI_TYPE_BUFFER:
37099146Siwasaki
37199146Siwasaki        Status = AcpiDsGetBufferArguments (StackDesc);
37299146Siwasaki        break;
37399146Siwasaki
37499146Siwasaki
37599146Siwasaki    case ACPI_TYPE_PACKAGE:
37699146Siwasaki
37799146Siwasaki        Status = AcpiDsGetPackageArguments (StackDesc);
37899146Siwasaki        break;
37999146Siwasaki
38099146Siwasaki
38177424Smsmith    case ACPI_TYPE_BUFFER_FIELD:
382107325Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
383107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
384107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
38567754Smsmith
38687031Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead SourceDesc=%p Type=%X\n",
38799679Siwasaki            StackDesc, ACPI_GET_OBJECT_TYPE (StackDesc)));
38867754Smsmith
38999146Siwasaki        Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);
390167802Sjkim
391167802Sjkim        /* Remove a reference to the original operand, then override */
392167802Sjkim
393167802Sjkim        AcpiUtRemoveReference (*StackPtr);
39467754Smsmith        *StackPtr = (void *) ObjDesc;
39567754Smsmith        break;
39667754Smsmith
39767754Smsmith    default:
39867754Smsmith        break;
39987031Smsmith    }
40067754Smsmith
40167754Smsmith    return_ACPI_STATUS (Status);
40267754Smsmith}
40367754Smsmith
40467754Smsmith
405104470Siwasaki/*******************************************************************************
406104470Siwasaki *
407104470Siwasaki * FUNCTION:    AcpiExResolveMultiple
408104470Siwasaki *
409104470Siwasaki * PARAMETERS:  WalkState           - Current state (contains AML opcode)
410104470Siwasaki *              Operand             - Starting point for resolution
411104470Siwasaki *              ReturnType          - Where the object type is returned
412104470Siwasaki *              ReturnDesc          - Where the resolved object is returned
413104470Siwasaki *
414104470Siwasaki * RETURN:      Status
415104470Siwasaki *
416104470Siwasaki * DESCRIPTION: Return the base object and type.  Traverse a reference list if
417104470Siwasaki *              necessary to get to the base object.
418104470Siwasaki *
419104470Siwasaki ******************************************************************************/
420104470Siwasaki
421104470SiwasakiACPI_STATUS
422104470SiwasakiAcpiExResolveMultiple (
423104470Siwasaki    ACPI_WALK_STATE         *WalkState,
424104470Siwasaki    ACPI_OPERAND_OBJECT     *Operand,
425104470Siwasaki    ACPI_OBJECT_TYPE        *ReturnType,
426104470Siwasaki    ACPI_OPERAND_OBJECT     **ReturnDesc)
427104470Siwasaki{
428104470Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc = (void *) Operand;
429104470Siwasaki    ACPI_NAMESPACE_NODE     *Node;
430104470Siwasaki    ACPI_OBJECT_TYPE        Type;
431138287Smarks    ACPI_STATUS             Status;
432104470Siwasaki
433104470Siwasaki
434167802Sjkim    ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);
435104470Siwasaki
436104470Siwasaki
437151937Sjkim    /* Operand can be either a namespace node or an operand descriptor */
438138287Smarks
439138287Smarks    switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
440138287Smarks    {
441138287Smarks    case ACPI_DESC_TYPE_OPERAND:
442138287Smarks        Type = ObjDesc->Common.Type;
443138287Smarks        break;
444138287Smarks
445138287Smarks    case ACPI_DESC_TYPE_NAMED:
446138287Smarks        Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
447138287Smarks        ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
448138287Smarks
449138287Smarks        /* If we had an Alias node, use the attached object for type info */
450138287Smarks
451138287Smarks        if (Type == ACPI_TYPE_LOCAL_ALIAS)
452138287Smarks        {
453138287Smarks            Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
454138287Smarks            ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
455138287Smarks        }
456138287Smarks        break;
457138287Smarks
458138287Smarks    default:
459138287Smarks        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
460138287Smarks    }
461138287Smarks
462151937Sjkim    /* If type is anything other than a reference, we are done */
463138287Smarks
464138287Smarks    if (Type != ACPI_TYPE_LOCAL_REFERENCE)
465138287Smarks    {
466138287Smarks        goto Exit;
467138287Smarks    }
468138287Smarks
469138287Smarks    /*
470104470Siwasaki     * For reference objects created via the RefOf or Index operators,
471114237Snjl     * we need to get to the base object (as per the ACPI specification
472114237Snjl     * of the ObjectType and SizeOf operators).  This means traversing
473104470Siwasaki     * the list of possibly many nested references.
474104470Siwasaki     */
475107325Siwasaki    while (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_LOCAL_REFERENCE)
476104470Siwasaki    {
477104470Siwasaki        switch (ObjDesc->Reference.Opcode)
478104470Siwasaki        {
479104470Siwasaki        case AML_REF_OF_OP:
480167802Sjkim        case AML_INT_NAMEPATH_OP:
481104470Siwasaki
482104470Siwasaki            /* Dereference the reference pointer */
483104470Siwasaki
484167802Sjkim            if (ObjDesc->Reference.Opcode == AML_REF_OF_OP)
485167802Sjkim            {
486167802Sjkim                Node = ObjDesc->Reference.Object;
487167802Sjkim            }
488167802Sjkim            else /* AML_INT_NAMEPATH_OP */
489167802Sjkim            {
490167802Sjkim                Node = ObjDesc->Reference.Node;
491167802Sjkim            }
492104470Siwasaki
493104470Siwasaki            /* All "References" point to a NS node */
494104470Siwasaki
495104470Siwasaki            if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
496104470Siwasaki            {
497167802Sjkim                ACPI_ERROR ((AE_INFO,
498167802Sjkim                    "Not a NS node %p [%s]",
499151937Sjkim                    Node, AcpiUtGetDescriptorName (Node)));
500104470Siwasaki                return_ACPI_STATUS (AE_AML_INTERNAL);
501104470Siwasaki            }
502104470Siwasaki
503104470Siwasaki            /* Get the attached object */
504104470Siwasaki
505104470Siwasaki            ObjDesc = AcpiNsGetAttachedObject (Node);
506104470Siwasaki            if (!ObjDesc)
507104470Siwasaki            {
508104470Siwasaki                /* No object, use the NS node type */
509104470Siwasaki
510104470Siwasaki                Type = AcpiNsGetType (Node);
511104470Siwasaki                goto Exit;
512104470Siwasaki            }
513104470Siwasaki
514104470Siwasaki            /* Check for circular references */
515104470Siwasaki
516104470Siwasaki            if (ObjDesc == Operand)
517104470Siwasaki            {
518104470Siwasaki                return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
519104470Siwasaki            }
520104470Siwasaki            break;
521104470Siwasaki
522104470Siwasaki
523104470Siwasaki        case AML_INDEX_OP:
524104470Siwasaki
525104470Siwasaki            /* Get the type of this reference (index into another object) */
526104470Siwasaki
527104470Siwasaki            Type = ObjDesc->Reference.TargetType;
528104470Siwasaki            if (Type != ACPI_TYPE_PACKAGE)
529104470Siwasaki            {
530104470Siwasaki                goto Exit;
531104470Siwasaki            }
532104470Siwasaki
533104470Siwasaki            /*
534104470Siwasaki             * The main object is a package, we want to get the type
535104470Siwasaki             * of the individual package element that is referenced by
536104470Siwasaki             * the index.
537104470Siwasaki             *
538104470Siwasaki             * This could of course in turn be another reference object.
539104470Siwasaki             */
540104470Siwasaki            ObjDesc = *(ObjDesc->Reference.Where);
541151937Sjkim            if (!ObjDesc)
542151937Sjkim            {
543151937Sjkim                /* NULL package elements are allowed */
544151937Sjkim
545151937Sjkim                Type = 0; /* Uninitialized */
546151937Sjkim                goto Exit;
547151937Sjkim            }
548104470Siwasaki            break;
549104470Siwasaki
550104470Siwasaki
551138287Smarks        case AML_LOCAL_OP:
552138287Smarks        case AML_ARG_OP:
553138287Smarks
554138287Smarks            if (ReturnDesc)
555138287Smarks            {
556138287Smarks                Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Opcode,
557151937Sjkim                            ObjDesc->Reference.Offset, WalkState, &ObjDesc);
558138287Smarks                if (ACPI_FAILURE (Status))
559138287Smarks                {
560138287Smarks                    return_ACPI_STATUS (Status);
561138287Smarks                }
562138287Smarks                AcpiUtRemoveReference (ObjDesc);
563138287Smarks            }
564138287Smarks            else
565138287Smarks            {
566138287Smarks                Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Opcode,
567138287Smarks                            ObjDesc->Reference.Offset, WalkState, &Node);
568138287Smarks                if (ACPI_FAILURE (Status))
569138287Smarks                {
570138287Smarks                    return_ACPI_STATUS (Status);
571138287Smarks                }
572138287Smarks
573138287Smarks                ObjDesc = AcpiNsGetAttachedObject (Node);
574138287Smarks                if (!ObjDesc)
575138287Smarks                {
576138287Smarks                    Type = ACPI_TYPE_ANY;
577138287Smarks                    goto Exit;
578138287Smarks                }
579138287Smarks            }
580138287Smarks            break;
581138287Smarks
582138287Smarks
583104470Siwasaki        case AML_DEBUG_OP:
584104470Siwasaki
585104470Siwasaki            /* The Debug Object is of type "DebugObject" */
586104470Siwasaki
587104470Siwasaki            Type = ACPI_TYPE_DEBUG_OBJECT;
588104470Siwasaki            goto Exit;
589104470Siwasaki
590104470Siwasaki
591104470Siwasaki        default:
592104470Siwasaki
593167802Sjkim            ACPI_ERROR ((AE_INFO,
594167802Sjkim                "Unknown Reference subtype %X",
595104470Siwasaki                ObjDesc->Reference.Opcode));
596104470Siwasaki            return_ACPI_STATUS (AE_AML_INTERNAL);
597104470Siwasaki        }
598104470Siwasaki    }
599104470Siwasaki
600104470Siwasaki    /*
601104470Siwasaki     * Now we are guaranteed to have an object that has not been created
602104470Siwasaki     * via the RefOf or Index operators.
603104470Siwasaki     */
604104470Siwasaki    Type = ACPI_GET_OBJECT_TYPE (ObjDesc);
605104470Siwasaki
606104470Siwasaki
607104470SiwasakiExit:
608104470Siwasaki    /* Convert internal types to external types */
609104470Siwasaki
610104470Siwasaki    switch (Type)
611104470Siwasaki    {
612107325Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
613107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
614107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
615104470Siwasaki
616104470Siwasaki        Type = ACPI_TYPE_FIELD_UNIT;
617104470Siwasaki        break;
618104470Siwasaki
619107325Siwasaki    case ACPI_TYPE_LOCAL_SCOPE:
620107325Siwasaki
621107325Siwasaki        /* Per ACPI Specification, Scope is untyped */
622107325Siwasaki
623107325Siwasaki        Type = ACPI_TYPE_ANY;
624107325Siwasaki        break;
625107325Siwasaki
626104470Siwasaki    default:
627104470Siwasaki        /* No change to Type required */
628104470Siwasaki        break;
629104470Siwasaki    }
630104470Siwasaki
631104470Siwasaki    *ReturnType = Type;
632104470Siwasaki    if (ReturnDesc)
633104470Siwasaki    {
634104470Siwasaki        *ReturnDesc = ObjDesc;
635104470Siwasaki    }
636104470Siwasaki    return_ACPI_STATUS (AE_OK);
637104470Siwasaki}
638104470Siwasaki
639104470Siwasaki
640