exresnte.c revision 107325
1258343Sdes
2258343Sdes/******************************************************************************
3258343Sdes *
4258343Sdes * Module Name: exresnte - AML Interpreter object resolution
5258343Sdes *              $Revision: 61 $
6258343Sdes *
7258343Sdes *****************************************************************************/
8258343Sdes
9258343Sdes/******************************************************************************
10258343Sdes *
11258343Sdes * 1. Copyright Notice
12258343Sdes *
13258343Sdes * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
14258343Sdes * All rights reserved.
15258343Sdes *
16258343Sdes * 2. License
17258343Sdes *
18255767Sdes * 2.1. This is your license from Intel Corp. under its intellectual property
19255767Sdes * rights.  You may have additional license terms from the party that provided
20255767Sdes * you this software, covering your right to use that party's intellectual
21255767Sdes * property rights.
22255767Sdes *
23255767Sdes * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24255767Sdes * copy of the source code appearing in this file ("Covered Code") an
25255767Sdes * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26255767Sdes * base code distributed originally by Intel ("Original Intel Code") to copy,
27255767Sdes * make derivatives, distribute, use and display any portion of the Covered
28255767Sdes * Code in any form, with the right to sublicense such rights; and
29255767Sdes *
30255767Sdes * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31255767Sdes * license (with the right to sublicense), under only those claims of Intel
32255767Sdes * patents that are infringed by the Original Intel Code, to make, use, sell,
33255767Sdes * offer to sell, and import the Covered Code and derivative works thereof
34255767Sdes * solely to the minimum extent necessary to exercise the above copyright
35255767Sdes * license, and in no event shall the patent license extend to any additions
36255767Sdes * to or modifications of the Original Intel Code.  No other license or right
37255767Sdes * is granted directly or by implication, estoppel or otherwise;
38255767Sdes *
39255767Sdes * The above copyright and patent license is granted only if the following
40255767Sdes * conditions are met:
41255767Sdes *
42255767Sdes * 3. Conditions
43255767Sdes *
44255767Sdes * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45255767Sdes * Redistribution of source code of any substantial portion of the Covered
46255767Sdes * Code or modification with rights to further distribute source must include
47255767Sdes * the above Copyright Notice, the above License, this list of Conditions,
48255767Sdes * and the following Disclaimer and Export Compliance provision.  In addition,
49255767Sdes * Licensee must cause all Covered Code to which Licensee contributes to
50255767Sdes * contain a file documenting the changes Licensee made to create that Covered
51255767Sdes * Code and the date of any change.  Licensee must include in that file the
52255767Sdes * documentation of any changes made by any predecessor Licensee.  Licensee
53255767Sdes * must include a prominent statement that the modification is derived,
54255767Sdes * directly or indirectly, from Original Intel Code.
55255767Sdes *
56255767Sdes * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57255767Sdes * Redistribution of source code of any substantial portion of the Covered
58255767Sdes * Code or modification without rights to further distribute source must
59255767Sdes * include the following Disclaimer and Export Compliance provision in the
60255767Sdes * documentation and/or other materials provided with distribution.  In
61255767Sdes * addition, Licensee may not authorize further sublicense of source of any
62255767Sdes * portion of the Covered Code, and must include terms to the effect that the
63255767Sdes * license from Licensee to its licensee is limited to the intellectual
64255767Sdes * property embodied in the software Licensee provides to its licensee, and
65255767Sdes * not to intellectual property embodied in modifications its licensee may
66255767Sdes * make.
67255767Sdes *
68255767Sdes * 3.3. Redistribution of Executable. Redistribution in executable form of any
69255767Sdes * substantial portion of the Covered Code or modification must reproduce the
70255767Sdes * above Copyright Notice, and the following Disclaimer and Export Compliance
71255767Sdes * provision in the documentation and/or other materials provided with the
72255767Sdes * distribution.
73255767Sdes *
74255767Sdes * 3.4. Intel retains all right, title, and interest in and to the Original
75255767Sdes * Intel Code.
76255767Sdes *
77255767Sdes * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78255767Sdes * Intel shall be used in advertising or otherwise to promote the sale, use or
79255767Sdes * other dealings in products derived from or relating to the Covered Code
80255767Sdes * without prior written authorization from Intel.
81255767Sdes *
82255767Sdes * 4. Disclaimer and Export Compliance
83255767Sdes *
84255767Sdes * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85255767Sdes * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86255767Sdes * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87255767Sdes * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88255767Sdes * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89255767Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90255767Sdes * PARTICULAR PURPOSE.
91255767Sdes *
92255767Sdes * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93255767Sdes * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94255767Sdes * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95255767Sdes * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96255767Sdes * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97255767Sdes * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98255767Sdes * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99255767Sdes * LIMITED REMEDY.
100255767Sdes *
101255767Sdes * 4.3. Licensee shall not export, either directly or indirectly, any of this
102255767Sdes * software or system incorporating such software without first obtaining any
103255767Sdes * required license or other approval from the U. S. Department of Commerce or
104255767Sdes * any other agency or department of the United States Government.  In the
105255767Sdes * event Licensee exports any such software from the United States or
106255767Sdes * re-exports any such software from a foreign destination, Licensee shall
107255767Sdes * ensure that the distribution and export/re-export of the software is in
108255767Sdes * compliance with all laws, regulations, orders, or other restrictions of the
109255767Sdes * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110255767Sdes * any of its subsidiaries will export/re-export any technical data, process,
111255767Sdes * software, or service, directly or indirectly, to any country for which the
112255767Sdes * United States government or any agency thereof requires an export license,
113255767Sdes * other governmental approval, or letter of assurance, without first obtaining
114255767Sdes * such license, approval or letter.
115255767Sdes *
116255767Sdes *****************************************************************************/
117255767Sdes
118255767Sdes#define __EXRESNTE_C__
119255767Sdes
120255767Sdes#include "acpi.h"
121255767Sdes#include "acdispat.h"
122255767Sdes#include "acinterp.h"
123255767Sdes#include "acnamesp.h"
124255767Sdes
125255767Sdes
126255767Sdes#define _COMPONENT          ACPI_EXECUTER
127255767Sdes        ACPI_MODULE_NAME    ("exresnte")
128255767Sdes
129255767Sdes
130255767Sdes/*******************************************************************************
131255767Sdes *
132255767Sdes * FUNCTION:    AcpiExResolveNodeToValue
133255767Sdes *
134255767Sdes * PARAMETERS:  ObjectPtr       - Pointer to a location that contains
135255767Sdes *                                a pointer to a NS node, and will receive a
136255767Sdes *                                pointer to the resolved object.
137255767Sdes *              WalkState       - Current state.  Valid only if executing AML
138255767Sdes *                                code.  NULL if simply resolving an object
139255767Sdes *
140255767Sdes * RETURN:      Status
141255767Sdes *
142255767Sdes * DESCRIPTION: Resolve a Namespace node to a valued object
143255767Sdes *
144255767Sdes * Note: for some of the data types, the pointer attached to the Node
145255767Sdes * can be either a pointer to an actual internal object or a pointer into the
146255767Sdes * AML stream itself.  These types are currently:
147255767Sdes *
148255767Sdes *      ACPI_TYPE_INTEGER
149255767Sdes *      ACPI_TYPE_STRING
150255767Sdes *      ACPI_TYPE_BUFFER
151255767Sdes *      ACPI_TYPE_MUTEX
152255767Sdes *      ACPI_TYPE_PACKAGE
153255767Sdes *
154255767Sdes ******************************************************************************/
155255767Sdes
156255767SdesACPI_STATUS
157255767SdesAcpiExResolveNodeToValue (
158255767Sdes    ACPI_NAMESPACE_NODE     **ObjectPtr,
159255767Sdes    ACPI_WALK_STATE         *WalkState)
160255767Sdes
161255767Sdes{
162255767Sdes    ACPI_STATUS             Status = AE_OK;
163255767Sdes    ACPI_OPERAND_OBJECT     *SourceDesc;
164255767Sdes    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
165255767Sdes    ACPI_NAMESPACE_NODE     *Node;
166255767Sdes    ACPI_OBJECT_TYPE        EntryType;
167255767Sdes
168255767Sdes
169255767Sdes    ACPI_FUNCTION_TRACE ("ExResolveNodeToValue");
170255767Sdes
171255767Sdes
172255767Sdes    /*
173255767Sdes     * The stack pointer points to a ACPI_NAMESPACE_NODE (Node).  Get the
174255767Sdes     * object that is attached to the Node.
175255767Sdes     */
176255767Sdes    Node       = *ObjectPtr;
177255767Sdes    SourceDesc = AcpiNsGetAttachedObject (Node);
178255767Sdes    EntryType  = AcpiNsGetType ((ACPI_HANDLE) Node);
179255767Sdes
180255767Sdes    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
181255767Sdes         Node, SourceDesc, AcpiUtGetTypeName (EntryType)));
182255767Sdes
183255767Sdes    if (EntryType == ACPI_TYPE_LOCAL_ALIAS)
184255767Sdes    {
185255767Sdes        /* There is always exactly one level of indirection */
186255767Sdes
187255767Sdes        Node       = (ACPI_NAMESPACE_NODE *) Node->Object;
188255767Sdes        SourceDesc = AcpiNsGetAttachedObject (Node);
189255767Sdes        EntryType  = AcpiNsGetType ((ACPI_HANDLE) Node);
190255767Sdes        *ObjectPtr = Node;
191255767Sdes    }
192255767Sdes
193255767Sdes    /*
194255767Sdes     * Several object types require no further processing:
195255767Sdes     * 1) Devices rarely have an attached object, return the Node
196255767Sdes     * 2) Method locals and arguments have a pseudo-Node
197255767Sdes     */
198255767Sdes    if (EntryType == ACPI_TYPE_DEVICE ||
199255767Sdes        (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL)))
200255767Sdes    {
201255767Sdes        return_ACPI_STATUS (AE_OK);
202255767Sdes    }
203255767Sdes
204255767Sdes    if (!SourceDesc)
205255767Sdes    {
206255767Sdes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object attached to node %p\n",
207255767Sdes            Node));
208255767Sdes        return_ACPI_STATUS (AE_AML_NO_OPERAND);
209255767Sdes    }
210255767Sdes
211255767Sdes    /*
212255767Sdes     * Action is based on the type of the Node, which indicates the type
213255767Sdes     * of the attached object or pointer
214255767Sdes     */
215255767Sdes    switch (EntryType)
216255767Sdes    {
217255767Sdes    case ACPI_TYPE_PACKAGE:
218255767Sdes
219255767Sdes        if (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_PACKAGE)
220255767Sdes        {
221255767Sdes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Package, type %s\n",
222255767Sdes                AcpiUtGetObjectTypeName (SourceDesc)));
223255767Sdes            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
224255767Sdes        }
225255767Sdes
226255767Sdes        Status = AcpiDsGetPackageArguments (SourceDesc);
227255767Sdes        if (ACPI_SUCCESS (Status))
228255767Sdes        {
229255767Sdes            /* Return an additional reference to the object */
230255767Sdes
231255767Sdes            ObjDesc = SourceDesc;
232255767Sdes            AcpiUtAddReference (ObjDesc);
233255767Sdes        }
234255767Sdes        break;
235255767Sdes
236255767Sdes
237255767Sdes    case ACPI_TYPE_BUFFER:
238255767Sdes
239255767Sdes        if (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_BUFFER)
240255767Sdes        {
241255767Sdes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Buffer, type %s\n",
242255767Sdes                AcpiUtGetObjectTypeName (SourceDesc)));
243255767Sdes            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
244255767Sdes        }
245255767Sdes
246255767Sdes        Status = AcpiDsGetBufferArguments (SourceDesc);
247255767Sdes        if (ACPI_SUCCESS (Status))
248255767Sdes        {
249255767Sdes            /* Return an additional reference to the object */
250255767Sdes
251255767Sdes            ObjDesc = SourceDesc;
252255767Sdes            AcpiUtAddReference (ObjDesc);
253255767Sdes        }
254255767Sdes        break;
255255767Sdes
256255767Sdes
257255767Sdes    case ACPI_TYPE_STRING:
258255767Sdes
259255767Sdes        if (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_STRING)
260255767Sdes        {
261255767Sdes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a String, type %s\n",
262255767Sdes                AcpiUtGetObjectTypeName (SourceDesc)));
263255767Sdes            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
264255767Sdes        }
265255767Sdes
266255767Sdes        /* Return an additional reference to the object */
267255767Sdes
268255767Sdes        ObjDesc = SourceDesc;
269255767Sdes        AcpiUtAddReference (ObjDesc);
270255767Sdes        break;
271255767Sdes
272255767Sdes
273255767Sdes    case ACPI_TYPE_INTEGER:
274255767Sdes
275255767Sdes        if (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_INTEGER)
276255767Sdes        {
277255767Sdes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Integer, type %s\n",
278255767Sdes                AcpiUtGetObjectTypeName (SourceDesc)));
279255767Sdes            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
280255767Sdes        }
281255767Sdes
282255767Sdes        /* Return an additional reference to the object */
283255767Sdes
284255767Sdes        ObjDesc = SourceDesc;
285255767Sdes        AcpiUtAddReference (ObjDesc);
286255767Sdes        break;
287255767Sdes
288255767Sdes
289255767Sdes    case ACPI_TYPE_BUFFER_FIELD:
290255767Sdes    case ACPI_TYPE_LOCAL_REGION_FIELD:
291255767Sdes    case ACPI_TYPE_LOCAL_BANK_FIELD:
292255767Sdes    case ACPI_TYPE_LOCAL_INDEX_FIELD:
293255767Sdes
294255767Sdes        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead Node=%p SourceDesc=%p Type=%X\n",
295255767Sdes            Node, SourceDesc, EntryType));
296255767Sdes
297255767Sdes        Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc);
298255767Sdes        break;
299255767Sdes
300255767Sdes    /*
301255767Sdes     * For these objects, just return the object attached to the Node
302255767Sdes     */
303255767Sdes    case ACPI_TYPE_MUTEX:
304255767Sdes    case ACPI_TYPE_METHOD:
305255767Sdes    case ACPI_TYPE_POWER:
306255767Sdes    case ACPI_TYPE_PROCESSOR:
307255767Sdes    case ACPI_TYPE_THERMAL:
308255767Sdes    case ACPI_TYPE_EVENT:
309255767Sdes    case ACPI_TYPE_REGION:
310255767Sdes
311255767Sdes        /* Return an additional reference to the object */
312255767Sdes
313255767Sdes        ObjDesc = SourceDesc;
314255767Sdes        AcpiUtAddReference (ObjDesc);
315255767Sdes        break;
316255767Sdes
317255767Sdes
318255767Sdes    /* TYPE_ANY is untyped, and thus there is no object associated with it */
319255767Sdes
320255767Sdes    case ACPI_TYPE_ANY:
321255767Sdes
322255767Sdes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Untyped entry %p, no attached object!\n",
323255767Sdes            Node));
324255767Sdes
325255767Sdes        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);  /* Cannot be AE_TYPE */
326255767Sdes
327255767Sdes
328255767Sdes    case ACPI_TYPE_LOCAL_REFERENCE:
329255767Sdes
330255767Sdes        /* No named references are allowed here */
331255767Sdes
332255767Sdes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported Reference opcode %X\n",
333255767Sdes            SourceDesc->Reference.Opcode));
334255767Sdes
335255767Sdes        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
336255767Sdes
337255767Sdes
338255767Sdes    /* Default case is for unknown types */
339255767Sdes
340255767Sdes    default:
341255767Sdes
342255767Sdes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Node %p - Unknown object type %X\n",
343255767Sdes            Node, EntryType));
344255767Sdes
345255767Sdes        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
346255767Sdes
347255767Sdes    } /* switch (EntryType) */
348255767Sdes
349255767Sdes
350255767Sdes    /* Put the object descriptor on the stack */
351255767Sdes
352255767Sdes    *ObjectPtr = (void *) ObjDesc;
353255767Sdes    return_ACPI_STATUS (Status);
354255767Sdes}
355255767Sdes
356255767Sdes
357255767Sdes