exresolv.c revision 306536
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: exresolv - AML Interpreter object resolution
477424Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
767754Smsmith/*
8217365Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
9229989Sjkim * All rights reserved.
1070243Smsmith *
1167754Smsmith * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
25217365Sjkim *
2667754Smsmith * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
29217365Sjkim *
3067754Smsmith * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
43217365Sjkim
4467754Smsmith#include <contrib/dev/acpica/include/acpi.h>
4577424Smsmith#include <contrib/dev/acpica/include/accommon.h>
4667754Smsmith#include <contrib/dev/acpica/include/amlcode.h>
47193341Sjkim#include <contrib/dev/acpica/include/acdispat.h>
48193341Sjkim#include <contrib/dev/acpica/include/acinterp.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50193341Sjkim
51193341Sjkim
52193341Sjkim#define _COMPONENT          ACPI_EXECUTER
5367754Smsmith        ACPI_MODULE_NAME    ("exresolv")
5467754Smsmith
5577424Smsmith/* Local prototypes */
5691116Smsmith
5767754Smsmithstatic ACPI_STATUS
58151937SjkimAcpiExResolveObjectToValue (
5967754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
60151937Sjkim    ACPI_WALK_STATE         *WalkState);
61151937Sjkim
62151937Sjkim
63151937Sjkim/*******************************************************************************
64151937Sjkim *
65151937Sjkim * FUNCTION:    AcpiExResolveToValue
6667754Smsmith *
6767754Smsmith * PARAMETERS:  **StackPtr          - Points to entry on ObjStack, which can
6877424Smsmith *                                    be either an (ACPI_OPERAND_OBJECT *)
6967754Smsmith *                                    or an ACPI_HANDLE.
7067754Smsmith *              WalkState           - Current method state
7177424Smsmith *
7267754Smsmith * RETURN:      Status
7377424Smsmith *
7467754Smsmith * DESCRIPTION: Convert Reference objects to values
7567754Smsmith *
7667754Smsmith ******************************************************************************/
7771867Smsmith
7867754SmsmithACPI_STATUS
7967754SmsmithAcpiExResolveToValue (
8067754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
8167754Smsmith    ACPI_WALK_STATE         *WalkState)
8277424Smsmith{
8367754Smsmith    ACPI_STATUS             Status;
8467754Smsmith
8567754Smsmith
8677424Smsmith    ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);
8767754Smsmith
8867754Smsmith
89167802Sjkim    if (!StackPtr || !*StackPtr)
9067754Smsmith    {
9167754Smsmith        ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
9267754Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
9367754Smsmith    }
94167802Sjkim
9567754Smsmith    /*
9667754Smsmith     * The entity pointed to by the StackPtr can be either
9767754Smsmith     * 1) A valid ACPI_OPERAND_OBJECT, or
9867754Smsmith     * 2) A ACPI_NAMESPACE_NODE (NamedObj)
9967754Smsmith     */
10067754Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)
10167754Smsmith    {
10267754Smsmith        Status = AcpiExResolveObjectToValue (StackPtr, WalkState);
10399679Siwasaki        if (ACPI_FAILURE (Status))
10467754Smsmith        {
10577424Smsmith            return_ACPI_STATUS (Status);
10667754Smsmith        }
10767754Smsmith
10867754Smsmith        if (!*StackPtr)
10967754Smsmith        {
110151937Sjkim            ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
111151937Sjkim            return_ACPI_STATUS (AE_AML_NO_OPERAND);
112151937Sjkim        }
113167802Sjkim    }
114151937Sjkim
115151937Sjkim    /*
11667754Smsmith     * Object on the stack may have changed if AcpiExResolveObjectToValue()
11767754Smsmith     * was called (i.e., we can't use an _else_ here.)
11867754Smsmith     */
11977424Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)
12067754Smsmith    {
12167754Smsmith        Status = AcpiExResolveNodeToValue (
12291116Smsmith            ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),
12367754Smsmith            WalkState);
12499679Siwasaki        if (ACPI_FAILURE (Status))
12599679Siwasaki        {
12677424Smsmith            return_ACPI_STATUS (Status);
12777424Smsmith        }
12877424Smsmith    }
12977424Smsmith
13077424Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));
13167754Smsmith    return_ACPI_STATUS (AE_OK);
13267754Smsmith}
13399146Siwasaki
13477424Smsmith
13567754Smsmith/*******************************************************************************
13667754Smsmith *
13767754Smsmith * FUNCTION:    AcpiExResolveObjectToValue
13867754Smsmith *
13967754Smsmith * PARAMETERS:  StackPtr        - Pointer to an internal object
14077424Smsmith *              WalkState       - Current method state
14167754Smsmith *
142151937Sjkim * RETURN:      Status
14377424Smsmith *
14467754Smsmith * DESCRIPTION: Retrieve the value from an internal object. The Reference type
14567754Smsmith *              uses the associated AML opcode to determine the value.
14667754Smsmith *
147151937Sjkim ******************************************************************************/
14867754Smsmith
14967754Smsmithstatic ACPI_STATUS
15067754SmsmithAcpiExResolveObjectToValue (
15167754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
152151937Sjkim    ACPI_WALK_STATE         *WalkState)
15377424Smsmith{
15467754Smsmith    ACPI_STATUS             Status = AE_OK;
15567754Smsmith    ACPI_OPERAND_OBJECT     *StackDesc;
15667754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
15777424Smsmith    UINT8                   RefType;
15867754Smsmith
159167802Sjkim
160193267Sjkim    ACPI_FUNCTION_TRACE (ExResolveObjectToValue);
16167754Smsmith
16267754Smsmith
163167802Sjkim    StackDesc = *StackPtr;
16467754Smsmith
16567754Smsmith    /* This is an object of type ACPI_OPERAND_OBJECT */
16667754Smsmith
16767754Smsmith    switch (StackDesc->Common.Type)
168238381Sjkim    {
16967754Smsmith    case ACPI_TYPE_LOCAL_REFERENCE:
170193267Sjkim
17167754Smsmith        RefType = StackDesc->Reference.Class;
172107325Siwasaki
17367754Smsmith        switch (RefType)
174193267Sjkim        {
17567754Smsmith        case ACPI_REFCLASS_LOCAL:
176193267Sjkim        case ACPI_REFCLASS_ARG:
17767754Smsmith            /*
178193267Sjkim             * Get the local from the method's state info
179193267Sjkim             * Note: this increments the local's object reference count
18067754Smsmith             */
18167754Smsmith            Status = AcpiDsMethodDataGetValue (RefType,
18267754Smsmith                StackDesc->Reference.Value, WalkState, &ObjDesc);
18367754Smsmith            if (ACPI_FAILURE (Status))
18467754Smsmith            {
185193267Sjkim                return_ACPI_STATUS (Status);
186193267Sjkim            }
18767754Smsmith
18867754Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",
18967754Smsmith                StackDesc->Reference.Value, ObjDesc));
19067754Smsmith
19167754Smsmith            /*
192129684Snjl             * Now we can delete the original Reference Object and
193193267Sjkim             * replace it with the resolved value
194129684Snjl             */
19567754Smsmith            AcpiUtRemoveReference (StackDesc);
19667754Smsmith            *StackPtr = ObjDesc;
197129684Snjl            break;
19867754Smsmith
19977424Smsmith        case ACPI_REFCLASS_INDEX:
20067754Smsmith
20167754Smsmith            switch (StackDesc->Reference.TargetType)
20267754Smsmith            {
20367754Smsmith            case ACPI_TYPE_BUFFER_FIELD:
204193267Sjkim
20567754Smsmith                /* Just return - do not dereference */
20667754Smsmith                break;
20767754Smsmith
20867754Smsmith            case ACPI_TYPE_PACKAGE:
20967754Smsmith
210193267Sjkim                /* If method call or CopyObject - do not dereference */
21167754Smsmith
21267754Smsmith                if ((WalkState->Opcode == AML_INT_METHODCALL_OP) ||
21367754Smsmith                    (WalkState->Opcode == AML_COPY_OP))
21467754Smsmith                {
21599679Siwasaki                    break;
216193267Sjkim                }
217193267Sjkim
218193267Sjkim                /* Otherwise, dereference the PackageIndex to a package element */
219193267Sjkim
220193267Sjkim                ObjDesc = *StackDesc->Reference.Where;
221193267Sjkim                if (ObjDesc)
222193267Sjkim                {
223193267Sjkim                    /*
224193267Sjkim                     * Valid object descriptor, copy pointer to return value
225193267Sjkim                     * (i.e., dereference the package index)
22667754Smsmith                     * Delete the ref object, increment the returned object
22767754Smsmith                     */
22867754Smsmith                    AcpiUtAddReference (ObjDesc);
22967754Smsmith                    *StackPtr = ObjDesc;
230193267Sjkim                }
23167754Smsmith                else
23267754Smsmith                {
23367754Smsmith                    /*
23477424Smsmith                     * A NULL object descriptor means an uninitialized element of
23577424Smsmith                     * the package, can't dereference it
23667754Smsmith                     */
23767754Smsmith                    ACPI_ERROR ((AE_INFO,
23867754Smsmith                        "Attempt to dereference an Index to "
23967754Smsmith                        "NULL package element Idx=%p",
24067754Smsmith                        StackDesc));
241193267Sjkim                    Status = AE_AML_UNINITIALIZED_ELEMENT;
24277424Smsmith                }
24367754Smsmith                break;
244167802Sjkim
245193267Sjkim            default:
24677424Smsmith
24767754Smsmith                /* Invalid reference object */
24867754Smsmith
24967754Smsmith                ACPI_ERROR ((AE_INFO,
25067754Smsmith                    "Unknown TargetType 0x%X in Index/Reference object %p",
25199679Siwasaki                    StackDesc->Reference.TargetType, StackDesc));
25267754Smsmith                Status = AE_AML_INTERNAL;
25399679Siwasaki                break;
25477424Smsmith            }
25567754Smsmith            break;
256167802Sjkim
257204773Sjkim        case ACPI_REFCLASS_REFOF:
25867754Smsmith        case ACPI_REFCLASS_DEBUG:
25967754Smsmith        case ACPI_REFCLASS_TABLE:
26067754Smsmith
26167754Smsmith            /* Just leave the object as-is, do not dereference */
26267754Smsmith
26367754Smsmith            break;
26467754Smsmith
265193267Sjkim        case ACPI_REFCLASS_NAME:   /* Reference to a named object */
266193267Sjkim
267193267Sjkim            /* Dereference the name */
26867754Smsmith
269193267Sjkim            if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||
270100966Siwasaki                (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))
27167754Smsmith            {
27267754Smsmith                /* These node types do not have 'real' subobjects */
273193267Sjkim
27467754Smsmith                *StackPtr = (void *) StackDesc->Reference.Node;
275167802Sjkim            }
276151937Sjkim            else
277167802Sjkim            {
278167802Sjkim                /* Get the object pointed to by the namespace node */
279167802Sjkim
280167802Sjkim                *StackPtr = (StackDesc->Reference.Node)->Object;
281167802Sjkim                AcpiUtAddReference (*StackPtr);
282167802Sjkim            }
283167802Sjkim
284167802Sjkim            AcpiUtRemoveReference (StackDesc);
285167802Sjkim            break;
286167802Sjkim
287167802Sjkim        default:
288167802Sjkim
289167802Sjkim            ACPI_ERROR ((AE_INFO,
290167802Sjkim                "Unknown Reference type 0x%X in %p",
291167802Sjkim                RefType, StackDesc));
292151937Sjkim            Status = AE_AML_INTERNAL;
293151937Sjkim            break;
294151937Sjkim        }
29567754Smsmith        break;
29667754Smsmith
297167802Sjkim    case ACPI_TYPE_BUFFER:
298204773Sjkim
29967754Smsmith        Status = AcpiDsGetBufferArguments (StackDesc);
30077424Smsmith        break;
30199679Siwasaki
30299679Siwasaki    case ACPI_TYPE_PACKAGE:
30367754Smsmith
30467754Smsmith        Status = AcpiDsGetPackageArguments (StackDesc);
30599146Siwasaki        break;
30699146Siwasaki
30799146Siwasaki    case ACPI_TYPE_BUFFER_FIELD:
30899146Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
30999146Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
31099146Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
31199146Siwasaki
31299146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
31399146Siwasaki            "FieldRead SourceDesc=%p Type=%X\n",
31499146Siwasaki            StackDesc, StackDesc->Common.Type));
31599146Siwasaki
31699146Siwasaki        Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);
31777424Smsmith
318107325Siwasaki        /* Remove a reference to the original operand, then override */
319107325Siwasaki
320107325Siwasaki        AcpiUtRemoveReference (*StackPtr);
32167754Smsmith        *StackPtr = (void *) ObjDesc;
32287031Smsmith        break;
323193267Sjkim
32467754Smsmith    default:
32599146Siwasaki
326167802Sjkim        break;
327167802Sjkim    }
328167802Sjkim
329167802Sjkim    return_ACPI_STATUS (Status);
33067754Smsmith}
33167754Smsmith
33267754Smsmith
33367754Smsmith/*******************************************************************************
33467754Smsmith *
33587031Smsmith * FUNCTION:    AcpiExResolveMultiple
33667754Smsmith *
33767754Smsmith * PARAMETERS:  WalkState           - Current state (contains AML opcode)
33867754Smsmith *              Operand             - Starting point for resolution
33967754Smsmith *              ReturnType          - Where the object type is returned
34067754Smsmith *              ReturnDesc          - Where the resolved object is returned
341104470Siwasaki *
342104470Siwasaki * RETURN:      Status
343104470Siwasaki *
344104470Siwasaki * DESCRIPTION: Return the base object and type. Traverse a reference list if
345104470Siwasaki *              necessary to get to the base object.
346104470Siwasaki *
347104470Siwasaki ******************************************************************************/
348104470Siwasaki
349104470SiwasakiACPI_STATUS
350104470SiwasakiAcpiExResolveMultiple (
351104470Siwasaki    ACPI_WALK_STATE         *WalkState,
352104470Siwasaki    ACPI_OPERAND_OBJECT     *Operand,
353104470Siwasaki    ACPI_OBJECT_TYPE        *ReturnType,
354104470Siwasaki    ACPI_OPERAND_OBJECT     **ReturnDesc)
355104470Siwasaki{
356104470Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc = ACPI_CAST_PTR (void, Operand);
357104470Siwasaki    ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Operand);
358104470Siwasaki    ACPI_OBJECT_TYPE        Type;
359104470Siwasaki    ACPI_STATUS             Status;
360104470Siwasaki
361104470Siwasaki
362104470Siwasaki    ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);
363104470Siwasaki
364104470Siwasaki
365104470Siwasaki    /* Operand can be either a namespace node or an operand descriptor */
366104470Siwasaki
367138287Smarks    switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
368104470Siwasaki    {
369104470Siwasaki    case ACPI_DESC_TYPE_OPERAND:
370167802Sjkim
371104470Siwasaki        Type = ObjDesc->Common.Type;
372104470Siwasaki        break;
373151937Sjkim
374138287Smarks    case ACPI_DESC_TYPE_NAMED:
375138287Smarks
376138287Smarks        Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
377138287Smarks        ObjDesc = AcpiNsGetAttachedObject (Node);
378138287Smarks
379138287Smarks        /* If we had an Alias node, use the attached object for type info */
380138287Smarks
381138287Smarks        if (Type == ACPI_TYPE_LOCAL_ALIAS)
382138287Smarks        {
383138287Smarks            Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
384138287Smarks            ObjDesc = AcpiNsGetAttachedObject (
385138287Smarks                (ACPI_NAMESPACE_NODE *) ObjDesc);
386138287Smarks        }
387138287Smarks
388138287Smarks        if (!ObjDesc)
389138287Smarks        {
390138287Smarks            ACPI_ERROR ((AE_INFO,
391138287Smarks                "[%4.4s] Node is unresolved or uninitialized",
392138287Smarks                AcpiUtGetNodeName (Node)));
393138287Smarks            return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE);
394138287Smarks        }
395138287Smarks        break;
396138287Smarks
397138287Smarks    default:
398151937Sjkim        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
399138287Smarks    }
400138287Smarks
401138287Smarks    /* If type is anything other than a reference, we are done */
402138287Smarks
403138287Smarks    if (Type != ACPI_TYPE_LOCAL_REFERENCE)
404138287Smarks    {
405138287Smarks        goto Exit;
406193267Sjkim    }
407193267Sjkim
408193267Sjkim    /*
409193267Sjkim     * For reference objects created via the RefOf, Index, or Load/LoadTable
410104470Siwasaki     * operators, we need to get to the base object (as per the ACPI
411193267Sjkim     * specification of the ObjectType and SizeOf operators). This means
412104470Siwasaki     * traversing the list of possibly many nested references.
413193267Sjkim     */
414104470Siwasaki    while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
415193267Sjkim    {
416193267Sjkim        switch (ObjDesc->Reference.Class)
417104470Siwasaki        {
418104470Siwasaki        case ACPI_REFCLASS_REFOF:
419104470Siwasaki        case ACPI_REFCLASS_NAME:
420193267Sjkim
421167802Sjkim            /* Dereference the reference pointer */
422167802Sjkim
423167802Sjkim            if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)
424167802Sjkim            {
425167802Sjkim                Node = ObjDesc->Reference.Object;
426167802Sjkim            }
427167802Sjkim            else /* AML_INT_NAMEPATH_OP */
428104470Siwasaki            {
429104470Siwasaki                Node = ObjDesc->Reference.Node;
430104470Siwasaki            }
431104470Siwasaki
432104470Siwasaki            /* All "References" point to a NS node */
433167802Sjkim
434204773Sjkim            if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
435151937Sjkim            {
436104470Siwasaki                ACPI_ERROR ((AE_INFO,
437104470Siwasaki                    "Not a namespace node %p [%s]",
438104470Siwasaki                    Node, AcpiUtGetDescriptorName (Node)));
439104470Siwasaki                return_ACPI_STATUS (AE_AML_INTERNAL);
440104470Siwasaki            }
441104470Siwasaki
442104470Siwasaki            /* Get the attached object */
443104470Siwasaki
444104470Siwasaki            ObjDesc = AcpiNsGetAttachedObject (Node);
445104470Siwasaki            if (!ObjDesc)
446104470Siwasaki            {
447104470Siwasaki                /* No object, use the NS node type */
448104470Siwasaki
449104470Siwasaki                Type = AcpiNsGetType (Node);
450104470Siwasaki                goto Exit;
451104470Siwasaki            }
452104470Siwasaki
453104470Siwasaki            /* Check for circular references */
454104470Siwasaki
455104470Siwasaki            if (ObjDesc == Operand)
456104470Siwasaki            {
457104470Siwasaki                return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
458104470Siwasaki            }
459193267Sjkim            break;
460104470Siwasaki
461104470Siwasaki        case ACPI_REFCLASS_INDEX:
462104470Siwasaki
463104470Siwasaki            /* Get the type of this reference (index into another object) */
464104470Siwasaki
465104470Siwasaki            Type = ObjDesc->Reference.TargetType;
466104470Siwasaki            if (Type != ACPI_TYPE_PACKAGE)
467104470Siwasaki            {
468104470Siwasaki                goto Exit;
469104470Siwasaki            }
470104470Siwasaki
471104470Siwasaki            /*
472104470Siwasaki             * The main object is a package, we want to get the type
473104470Siwasaki             * of the individual package element that is referenced by
474104470Siwasaki             * the index.
475104470Siwasaki             *
476104470Siwasaki             * This could of course in turn be another reference object.
477151937Sjkim             */
478151937Sjkim            ObjDesc = *(ObjDesc->Reference.Where);
479151937Sjkim            if (!ObjDesc)
480151937Sjkim            {
481151937Sjkim                /* NULL package elements are allowed */
482151937Sjkim
483151937Sjkim                Type = 0; /* Uninitialized */
484104470Siwasaki                goto Exit;
485104470Siwasaki            }
486104470Siwasaki            break;
487193267Sjkim
488138287Smarks        case ACPI_REFCLASS_TABLE:
489193267Sjkim
490193267Sjkim            Type = ACPI_TYPE_DDB_HANDLE;
491193267Sjkim            goto Exit;
492193267Sjkim
493193267Sjkim        case ACPI_REFCLASS_LOCAL:
494193267Sjkim        case ACPI_REFCLASS_ARG:
495193267Sjkim
496138287Smarks            if (ReturnDesc)
497138287Smarks            {
498193267Sjkim                Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class,
499193267Sjkim                    ObjDesc->Reference.Value, WalkState, &ObjDesc);
500138287Smarks                if (ACPI_FAILURE (Status))
501138287Smarks                {
502138287Smarks                    return_ACPI_STATUS (Status);
503138287Smarks                }
504138287Smarks                AcpiUtRemoveReference (ObjDesc);
505138287Smarks            }
506138287Smarks            else
507138287Smarks            {
508193267Sjkim                Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class,
509193267Sjkim                    ObjDesc->Reference.Value, WalkState, &Node);
510138287Smarks                if (ACPI_FAILURE (Status))
511138287Smarks                {
512138287Smarks                    return_ACPI_STATUS (Status);
513138287Smarks                }
514138287Smarks
515138287Smarks                ObjDesc = AcpiNsGetAttachedObject (Node);
516138287Smarks                if (!ObjDesc)
517138287Smarks                {
518138287Smarks                    Type = ACPI_TYPE_ANY;
519138287Smarks                    goto Exit;
520138287Smarks                }
521138287Smarks            }
522138287Smarks            break;
523138287Smarks
524138287Smarks        case ACPI_REFCLASS_DEBUG:
525193267Sjkim
526104470Siwasaki            /* The Debug Object is of type "DebugObject" */
527104470Siwasaki
528104470Siwasaki            Type = ACPI_TYPE_DEBUG_OBJECT;
529104470Siwasaki            goto Exit;
530104470Siwasaki
531104470Siwasaki        default:
532104470Siwasaki
533104470Siwasaki            ACPI_ERROR ((AE_INFO,
534104470Siwasaki                "Unknown Reference Class 0x%2.2X",
535167802Sjkim                ObjDesc->Reference.Class));
536204773Sjkim            return_ACPI_STATUS (AE_AML_INTERNAL);
537104470Siwasaki        }
538104470Siwasaki    }
539104470Siwasaki
540104470Siwasaki    /*
541104470Siwasaki     * Now we are guaranteed to have an object that has not been created
542104470Siwasaki     * via the RefOf or Index operators.
543104470Siwasaki     */
544104470Siwasaki    Type = ObjDesc->Common.Type;
545193267Sjkim
546104470Siwasaki
547104470SiwasakiExit:
548104470Siwasaki    /* Convert internal types to external types */
549104470Siwasaki
550104470Siwasaki    switch (Type)
551104470Siwasaki    {
552104470Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
553107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
554107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
555107325Siwasaki
556104470Siwasaki        Type = ACPI_TYPE_FIELD_UNIT;
557104470Siwasaki        break;
558104470Siwasaki
559104470Siwasaki    case ACPI_TYPE_LOCAL_SCOPE:
560107325Siwasaki
561107325Siwasaki        /* Per ACPI Specification, Scope is untyped */
562107325Siwasaki
563107325Siwasaki        Type = ACPI_TYPE_ANY;
564107325Siwasaki        break;
565107325Siwasaki
566107325Siwasaki    default:
567104470Siwasaki
568104470Siwasaki        /* No change to Type required */
569104470Siwasaki
570104470Siwasaki        break;
571104470Siwasaki    }
572104470Siwasaki
573104470Siwasaki    *ReturnType = Type;
574104470Siwasaki    if (ReturnDesc)
575104470Siwasaki    {
576104470Siwasaki        *ReturnDesc = ObjDesc;
577104470Siwasaki    }
578104470Siwasaki    return_ACPI_STATUS (AE_OK);
579104470Siwasaki}
580104470Siwasaki