1c2c66affSColin Finck /******************************************************************************
2c2c66affSColin Finck  *
3c2c66affSColin Finck  * Module Name: exresnte - AML Interpreter object resolution
4c2c66affSColin Finck  *
5c2c66affSColin Finck  *****************************************************************************/
6c2c66affSColin Finck 
7c2c66affSColin Finck /*
8*03b24380SThomas Faber  * Copyright (C) 2000 - 2022, Intel Corp.
9c2c66affSColin Finck  * All rights reserved.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * Redistribution and use in source and binary forms, with or without
12c2c66affSColin Finck  * modification, are permitted provided that the following conditions
13c2c66affSColin Finck  * are met:
14c2c66affSColin Finck  * 1. Redistributions of source code must retain the above copyright
15c2c66affSColin Finck  *    notice, this list of conditions, and the following disclaimer,
16c2c66affSColin Finck  *    without modification.
17c2c66affSColin Finck  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18c2c66affSColin Finck  *    substantially similar to the "NO WARRANTY" disclaimer below
19c2c66affSColin Finck  *    ("Disclaimer") and any redistribution must be conditioned upon
20c2c66affSColin Finck  *    including a substantially similar Disclaimer requirement for further
21c2c66affSColin Finck  *    binary redistribution.
22c2c66affSColin Finck  * 3. Neither the names of the above-listed copyright holders nor the names
23c2c66affSColin Finck  *    of any contributors may be used to endorse or promote products derived
24c2c66affSColin Finck  *    from this software without specific prior written permission.
25c2c66affSColin Finck  *
26c2c66affSColin Finck  * Alternatively, this software may be distributed under the terms of the
27c2c66affSColin Finck  * GNU General Public License ("GPL") version 2 as published by the Free
28c2c66affSColin Finck  * Software Foundation.
29c2c66affSColin Finck  *
30c2c66affSColin Finck  * NO WARRANTY
31c2c66affSColin Finck  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32c2c66affSColin Finck  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
336eb8cc49SThomas Faber  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34c2c66affSColin Finck  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35c2c66affSColin Finck  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36c2c66affSColin Finck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37c2c66affSColin Finck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38c2c66affSColin Finck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39c2c66affSColin Finck  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40c2c66affSColin Finck  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41c2c66affSColin Finck  * POSSIBILITY OF SUCH DAMAGES.
42c2c66affSColin Finck  */
43c2c66affSColin Finck 
44c2c66affSColin Finck #include "acpi.h"
45c2c66affSColin Finck #include "accommon.h"
46c2c66affSColin Finck #include "acdispat.h"
47c2c66affSColin Finck #include "acinterp.h"
48c2c66affSColin Finck #include "acnamesp.h"
49c2c66affSColin Finck 
50c2c66affSColin Finck 
51c2c66affSColin Finck #define _COMPONENT          ACPI_EXECUTER
52c2c66affSColin Finck         ACPI_MODULE_NAME    ("exresnte")
53c2c66affSColin Finck 
54c2c66affSColin Finck 
55c2c66affSColin Finck /*******************************************************************************
56c2c66affSColin Finck  *
57c2c66affSColin Finck  * FUNCTION:    AcpiExResolveNodeToValue
58c2c66affSColin Finck  *
59c2c66affSColin Finck  * PARAMETERS:  ObjectPtr       - Pointer to a location that contains
60c2c66affSColin Finck  *                                a pointer to a NS node, and will receive a
61c2c66affSColin Finck  *                                pointer to the resolved object.
62c2c66affSColin Finck  *              WalkState       - Current state. Valid only if executing AML
63c2c66affSColin Finck  *                                code. NULL if simply resolving an object
64c2c66affSColin Finck  *
65c2c66affSColin Finck  * RETURN:      Status
66c2c66affSColin Finck  *
67c2c66affSColin Finck  * DESCRIPTION: Resolve a Namespace node to a valued object
68c2c66affSColin Finck  *
69c2c66affSColin Finck  * Note: for some of the data types, the pointer attached to the Node
70c2c66affSColin Finck  * can be either a pointer to an actual internal object or a pointer into the
71c2c66affSColin Finck  * AML stream itself. These types are currently:
72c2c66affSColin Finck  *
73c2c66affSColin Finck  *      ACPI_TYPE_INTEGER
74c2c66affSColin Finck  *      ACPI_TYPE_STRING
75c2c66affSColin Finck  *      ACPI_TYPE_BUFFER
76c2c66affSColin Finck  *      ACPI_TYPE_MUTEX
77c2c66affSColin Finck  *      ACPI_TYPE_PACKAGE
78c2c66affSColin Finck  *
79c2c66affSColin Finck  ******************************************************************************/
80c2c66affSColin Finck 
81c2c66affSColin Finck ACPI_STATUS
AcpiExResolveNodeToValue(ACPI_NAMESPACE_NODE ** ObjectPtr,ACPI_WALK_STATE * WalkState)82c2c66affSColin Finck AcpiExResolveNodeToValue (
83c2c66affSColin Finck     ACPI_NAMESPACE_NODE     **ObjectPtr,
84c2c66affSColin Finck     ACPI_WALK_STATE         *WalkState)
85c2c66affSColin Finck 
86c2c66affSColin Finck {
87c2c66affSColin Finck     ACPI_STATUS             Status = AE_OK;
88c2c66affSColin Finck     ACPI_OPERAND_OBJECT     *SourceDesc;
89c2c66affSColin Finck     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
90c2c66affSColin Finck     ACPI_NAMESPACE_NODE     *Node;
91c2c66affSColin Finck     ACPI_OBJECT_TYPE        EntryType;
92c2c66affSColin Finck 
93c2c66affSColin Finck 
94c2c66affSColin Finck     ACPI_FUNCTION_TRACE (ExResolveNodeToValue);
95c2c66affSColin Finck 
96c2c66affSColin Finck 
97c2c66affSColin Finck     /*
98c2c66affSColin Finck      * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the
99c2c66affSColin Finck      * object that is attached to the Node.
100c2c66affSColin Finck      */
101c2c66affSColin Finck     Node = *ObjectPtr;
102c2c66affSColin Finck     SourceDesc = AcpiNsGetAttachedObject (Node);
103c2c66affSColin Finck     EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
104c2c66affSColin Finck 
105c2c66affSColin Finck     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
106c2c66affSColin Finck          Node, SourceDesc, AcpiUtGetTypeName (EntryType)));
107c2c66affSColin Finck 
108c2c66affSColin Finck     if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) ||
109c2c66affSColin Finck         (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS))
110c2c66affSColin Finck     {
111c2c66affSColin Finck         /* There is always exactly one level of indirection */
112c2c66affSColin Finck 
113c2c66affSColin Finck         Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
114c2c66affSColin Finck         SourceDesc = AcpiNsGetAttachedObject (Node);
115c2c66affSColin Finck         EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
116c2c66affSColin Finck         *ObjectPtr = Node;
117c2c66affSColin Finck     }
118c2c66affSColin Finck 
119c2c66affSColin Finck     /*
120c2c66affSColin Finck      * Several object types require no further processing:
121c2c66affSColin Finck      * 1) Device/Thermal objects don't have a "real" subobject, return Node
122c2c66affSColin Finck      * 2) Method locals and arguments have a pseudo-Node
123c2c66affSColin Finck      * 3) 10/2007: Added method type to assist with Package construction.
124c2c66affSColin Finck      */
125c2c66affSColin Finck     if ((EntryType == ACPI_TYPE_DEVICE)  ||
126c2c66affSColin Finck         (EntryType == ACPI_TYPE_THERMAL) ||
127c2c66affSColin Finck         (EntryType == ACPI_TYPE_METHOD)  ||
128c2c66affSColin Finck         (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL)))
129c2c66affSColin Finck     {
130c2c66affSColin Finck         return_ACPI_STATUS (AE_OK);
131c2c66affSColin Finck     }
132c2c66affSColin Finck 
133c2c66affSColin Finck     if (!SourceDesc)
134c2c66affSColin Finck     {
135c2c66affSColin Finck         ACPI_ERROR ((AE_INFO, "No object attached to node [%4.4s] %p",
136c2c66affSColin Finck             Node->Name.Ascii, Node));
137c2c66affSColin Finck         return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE);
138c2c66affSColin Finck     }
139c2c66affSColin Finck 
140c2c66affSColin Finck     /*
141c2c66affSColin Finck      * Action is based on the type of the Node, which indicates the type
142c2c66affSColin Finck      * of the attached object or pointer
143c2c66affSColin Finck      */
144c2c66affSColin Finck     switch (EntryType)
145c2c66affSColin Finck     {
146c2c66affSColin Finck     case ACPI_TYPE_PACKAGE:
147c2c66affSColin Finck 
148c2c66affSColin Finck         if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE)
149c2c66affSColin Finck         {
150c2c66affSColin Finck             ACPI_ERROR ((AE_INFO, "Object not a Package, type %s",
151c2c66affSColin Finck                 AcpiUtGetObjectTypeName (SourceDesc)));
152c2c66affSColin Finck             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
153c2c66affSColin Finck         }
154c2c66affSColin Finck 
155c2c66affSColin Finck         Status = AcpiDsGetPackageArguments (SourceDesc);
156c2c66affSColin Finck         if (ACPI_SUCCESS (Status))
157c2c66affSColin Finck         {
158c2c66affSColin Finck             /* Return an additional reference to the object */
159c2c66affSColin Finck 
160c2c66affSColin Finck             ObjDesc = SourceDesc;
161c2c66affSColin Finck             AcpiUtAddReference (ObjDesc);
162c2c66affSColin Finck         }
163c2c66affSColin Finck         break;
164c2c66affSColin Finck 
165c2c66affSColin Finck     case ACPI_TYPE_BUFFER:
166c2c66affSColin Finck 
167c2c66affSColin Finck         if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
168c2c66affSColin Finck         {
169c2c66affSColin Finck             ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s",
170c2c66affSColin Finck                 AcpiUtGetObjectTypeName (SourceDesc)));
171c2c66affSColin Finck             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
172c2c66affSColin Finck         }
173c2c66affSColin Finck 
174c2c66affSColin Finck         Status = AcpiDsGetBufferArguments (SourceDesc);
175c2c66affSColin Finck         if (ACPI_SUCCESS (Status))
176c2c66affSColin Finck         {
177c2c66affSColin Finck             /* Return an additional reference to the object */
178c2c66affSColin Finck 
179c2c66affSColin Finck             ObjDesc = SourceDesc;
180c2c66affSColin Finck             AcpiUtAddReference (ObjDesc);
181c2c66affSColin Finck         }
182c2c66affSColin Finck         break;
183c2c66affSColin Finck 
184c2c66affSColin Finck     case ACPI_TYPE_STRING:
185c2c66affSColin Finck 
186c2c66affSColin Finck         if (SourceDesc->Common.Type != ACPI_TYPE_STRING)
187c2c66affSColin Finck         {
188c2c66affSColin Finck             ACPI_ERROR ((AE_INFO, "Object not a String, type %s",
189c2c66affSColin Finck                 AcpiUtGetObjectTypeName (SourceDesc)));
190c2c66affSColin Finck             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
191c2c66affSColin Finck         }
192c2c66affSColin Finck 
193c2c66affSColin Finck         /* Return an additional reference to the object */
194c2c66affSColin Finck 
195c2c66affSColin Finck         ObjDesc = SourceDesc;
196c2c66affSColin Finck         AcpiUtAddReference (ObjDesc);
197c2c66affSColin Finck         break;
198c2c66affSColin Finck 
199c2c66affSColin Finck     case ACPI_TYPE_INTEGER:
200c2c66affSColin Finck 
201c2c66affSColin Finck         if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
202c2c66affSColin Finck         {
203c2c66affSColin Finck             ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s",
204c2c66affSColin Finck                 AcpiUtGetObjectTypeName (SourceDesc)));
205c2c66affSColin Finck             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
206c2c66affSColin Finck         }
207c2c66affSColin Finck 
208c2c66affSColin Finck         /* Return an additional reference to the object */
209c2c66affSColin Finck 
210c2c66affSColin Finck         ObjDesc = SourceDesc;
211c2c66affSColin Finck         AcpiUtAddReference (ObjDesc);
212c2c66affSColin Finck         break;
213c2c66affSColin Finck 
214c2c66affSColin Finck     case ACPI_TYPE_BUFFER_FIELD:
215c2c66affSColin Finck     case ACPI_TYPE_LOCAL_REGION_FIELD:
216c2c66affSColin Finck     case ACPI_TYPE_LOCAL_BANK_FIELD:
217c2c66affSColin Finck     case ACPI_TYPE_LOCAL_INDEX_FIELD:
218c2c66affSColin Finck 
219c2c66affSColin Finck         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
220c2c66affSColin Finck             "FieldRead Node=%p SourceDesc=%p Type=%X\n",
221c2c66affSColin Finck             Node, SourceDesc, EntryType));
222c2c66affSColin Finck 
223c2c66affSColin Finck         Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc);
224c2c66affSColin Finck         break;
225c2c66affSColin Finck 
226c2c66affSColin Finck     /* For these objects, just return the object attached to the Node */
227c2c66affSColin Finck 
228c2c66affSColin Finck     case ACPI_TYPE_MUTEX:
229c2c66affSColin Finck     case ACPI_TYPE_POWER:
230c2c66affSColin Finck     case ACPI_TYPE_PROCESSOR:
231c2c66affSColin Finck     case ACPI_TYPE_EVENT:
232c2c66affSColin Finck     case ACPI_TYPE_REGION:
233c2c66affSColin Finck 
234c2c66affSColin Finck         /* Return an additional reference to the object */
235c2c66affSColin Finck 
236c2c66affSColin Finck         ObjDesc = SourceDesc;
237c2c66affSColin Finck         AcpiUtAddReference (ObjDesc);
238c2c66affSColin Finck         break;
239c2c66affSColin Finck 
240c2c66affSColin Finck     /* TYPE_ANY is untyped, and thus there is no object associated with it */
241c2c66affSColin Finck 
242c2c66affSColin Finck     case ACPI_TYPE_ANY:
243c2c66affSColin Finck 
244c2c66affSColin Finck         ACPI_ERROR ((AE_INFO,
245c2c66affSColin Finck             "Untyped entry %p, no attached object!", Node));
246c2c66affSColin Finck 
247c2c66affSColin Finck         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);  /* Cannot be AE_TYPE */
248c2c66affSColin Finck 
249c2c66affSColin Finck     case ACPI_TYPE_LOCAL_REFERENCE:
250c2c66affSColin Finck 
251c2c66affSColin Finck         switch (SourceDesc->Reference.Class)
252c2c66affSColin Finck         {
253c2c66affSColin Finck         case ACPI_REFCLASS_TABLE:   /* This is a DdbHandle */
254c2c66affSColin Finck         case ACPI_REFCLASS_REFOF:
255c2c66affSColin Finck         case ACPI_REFCLASS_INDEX:
256c2c66affSColin Finck 
257c2c66affSColin Finck             /* Return an additional reference to the object */
258c2c66affSColin Finck 
259c2c66affSColin Finck             ObjDesc = SourceDesc;
260c2c66affSColin Finck             AcpiUtAddReference (ObjDesc);
261c2c66affSColin Finck             break;
262c2c66affSColin Finck 
263c2c66affSColin Finck         default:
264c2c66affSColin Finck 
265c2c66affSColin Finck             /* No named references are allowed here */
266c2c66affSColin Finck 
267c2c66affSColin Finck             ACPI_ERROR ((AE_INFO,
268c2c66affSColin Finck                 "Unsupported Reference type 0x%X",
269c2c66affSColin Finck                 SourceDesc->Reference.Class));
270c2c66affSColin Finck 
271c2c66affSColin Finck             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
272c2c66affSColin Finck         }
273c2c66affSColin Finck         break;
274c2c66affSColin Finck 
275c2c66affSColin Finck     default:
276c2c66affSColin Finck 
277c2c66affSColin Finck         /* Default case is for unknown types */
278c2c66affSColin Finck 
279c2c66affSColin Finck         ACPI_ERROR ((AE_INFO,
280c2c66affSColin Finck             "Node %p - Unknown object type 0x%X",
281c2c66affSColin Finck             Node, EntryType));
282c2c66affSColin Finck 
283c2c66affSColin Finck         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
284c2c66affSColin Finck 
285c2c66affSColin Finck     } /* switch (EntryType) */
286c2c66affSColin Finck 
287c2c66affSColin Finck 
288c2c66affSColin Finck     /* Return the object descriptor */
289c2c66affSColin Finck 
290c2c66affSColin Finck     *ObjectPtr = (void *) ObjDesc;
291c2c66affSColin Finck     return_ACPI_STATUS (Status);
292c2c66affSColin Finck }
293