1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: exresnte - AML Interpreter object resolution
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc *****************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acdispat.h"
47433d6423SLionel Sambuc #include "acinterp.h"
48433d6423SLionel Sambuc #include "acnamesp.h"
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc #define _COMPONENT ACPI_EXECUTER
52433d6423SLionel Sambuc ACPI_MODULE_NAME ("exresnte")
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc
55433d6423SLionel Sambuc /*******************************************************************************
56433d6423SLionel Sambuc *
57433d6423SLionel Sambuc * FUNCTION: AcpiExResolveNodeToValue
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * PARAMETERS: ObjectPtr - Pointer to a location that contains
60433d6423SLionel Sambuc * a pointer to a NS node, and will receive a
61433d6423SLionel Sambuc * pointer to the resolved object.
62433d6423SLionel Sambuc * WalkState - Current state. Valid only if executing AML
63433d6423SLionel Sambuc * code. NULL if simply resolving an object
64433d6423SLionel Sambuc *
65433d6423SLionel Sambuc * RETURN: Status
66433d6423SLionel Sambuc *
67433d6423SLionel Sambuc * DESCRIPTION: Resolve a Namespace node to a valued object
68433d6423SLionel Sambuc *
69433d6423SLionel Sambuc * Note: for some of the data types, the pointer attached to the Node
70433d6423SLionel Sambuc * can be either a pointer to an actual internal object or a pointer into the
71433d6423SLionel Sambuc * AML stream itself. These types are currently:
72433d6423SLionel Sambuc *
73433d6423SLionel Sambuc * ACPI_TYPE_INTEGER
74433d6423SLionel Sambuc * ACPI_TYPE_STRING
75433d6423SLionel Sambuc * ACPI_TYPE_BUFFER
76433d6423SLionel Sambuc * ACPI_TYPE_MUTEX
77433d6423SLionel Sambuc * ACPI_TYPE_PACKAGE
78433d6423SLionel Sambuc *
79433d6423SLionel Sambuc ******************************************************************************/
80433d6423SLionel Sambuc
81433d6423SLionel Sambuc ACPI_STATUS
AcpiExResolveNodeToValue(ACPI_NAMESPACE_NODE ** ObjectPtr,ACPI_WALK_STATE * WalkState)82433d6423SLionel Sambuc AcpiExResolveNodeToValue (
83433d6423SLionel Sambuc ACPI_NAMESPACE_NODE **ObjectPtr,
84433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc {
87433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
88433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *SourceDesc;
89433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ObjDesc = NULL;
90433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
91433d6423SLionel Sambuc ACPI_OBJECT_TYPE EntryType;
92433d6423SLionel Sambuc
93433d6423SLionel Sambuc
94433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExResolveNodeToValue);
95433d6423SLionel Sambuc
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc /*
98433d6423SLionel Sambuc * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the
99433d6423SLionel Sambuc * object that is attached to the Node.
100433d6423SLionel Sambuc */
101433d6423SLionel Sambuc Node = *ObjectPtr;
102433d6423SLionel Sambuc SourceDesc = AcpiNsGetAttachedObject (Node);
103433d6423SLionel Sambuc EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
104433d6423SLionel Sambuc
105433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
106433d6423SLionel Sambuc Node, SourceDesc, AcpiUtGetTypeName (EntryType)));
107433d6423SLionel Sambuc
108433d6423SLionel Sambuc if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) ||
109433d6423SLionel Sambuc (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS))
110433d6423SLionel Sambuc {
111433d6423SLionel Sambuc /* There is always exactly one level of indirection */
112433d6423SLionel Sambuc
113433d6423SLionel Sambuc Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
114433d6423SLionel Sambuc SourceDesc = AcpiNsGetAttachedObject (Node);
115433d6423SLionel Sambuc EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
116433d6423SLionel Sambuc *ObjectPtr = Node;
117433d6423SLionel Sambuc }
118433d6423SLionel Sambuc
119433d6423SLionel Sambuc /*
120433d6423SLionel Sambuc * Several object types require no further processing:
121433d6423SLionel Sambuc * 1) Device/Thermal objects don't have a "real" subobject, return the Node
122433d6423SLionel Sambuc * 2) Method locals and arguments have a pseudo-Node
123433d6423SLionel Sambuc * 3) 10/2007: Added method type to assist with Package construction.
124433d6423SLionel Sambuc */
125433d6423SLionel Sambuc if ((EntryType == ACPI_TYPE_DEVICE) ||
126433d6423SLionel Sambuc (EntryType == ACPI_TYPE_THERMAL) ||
127433d6423SLionel Sambuc (EntryType == ACPI_TYPE_METHOD) ||
128433d6423SLionel Sambuc (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL)))
129433d6423SLionel Sambuc {
130433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
131433d6423SLionel Sambuc }
132433d6423SLionel Sambuc
133433d6423SLionel Sambuc if (!SourceDesc)
134433d6423SLionel Sambuc {
135*29492bb7SDavid van Moolenbroek ACPI_ERROR ((AE_INFO, "No object attached to node [%4.4s] %p",
136*29492bb7SDavid van Moolenbroek Node->Name.Ascii, Node));
137433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_NO_OPERAND);
138433d6423SLionel Sambuc }
139433d6423SLionel Sambuc
140433d6423SLionel Sambuc /*
141433d6423SLionel Sambuc * Action is based on the type of the Node, which indicates the type
142433d6423SLionel Sambuc * of the attached object or pointer
143433d6423SLionel Sambuc */
144433d6423SLionel Sambuc switch (EntryType)
145433d6423SLionel Sambuc {
146433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
147433d6423SLionel Sambuc
148433d6423SLionel Sambuc if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE)
149433d6423SLionel Sambuc {
150433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Object not a Package, type %s",
151433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc)));
152433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
153433d6423SLionel Sambuc }
154433d6423SLionel Sambuc
155433d6423SLionel Sambuc Status = AcpiDsGetPackageArguments (SourceDesc);
156433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
157433d6423SLionel Sambuc {
158433d6423SLionel Sambuc /* Return an additional reference to the object */
159433d6423SLionel Sambuc
160433d6423SLionel Sambuc ObjDesc = SourceDesc;
161433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
162433d6423SLionel Sambuc }
163433d6423SLionel Sambuc break;
164433d6423SLionel Sambuc
165433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
168433d6423SLionel Sambuc {
169433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s",
170433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc)));
171433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
172433d6423SLionel Sambuc }
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc Status = AcpiDsGetBufferArguments (SourceDesc);
175433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
176433d6423SLionel Sambuc {
177433d6423SLionel Sambuc /* Return an additional reference to the object */
178433d6423SLionel Sambuc
179433d6423SLionel Sambuc ObjDesc = SourceDesc;
180433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
181433d6423SLionel Sambuc }
182433d6423SLionel Sambuc break;
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc case ACPI_TYPE_STRING:
185433d6423SLionel Sambuc
186433d6423SLionel Sambuc if (SourceDesc->Common.Type != ACPI_TYPE_STRING)
187433d6423SLionel Sambuc {
188433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Object not a String, type %s",
189433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc)));
190433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
191433d6423SLionel Sambuc }
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc /* Return an additional reference to the object */
194433d6423SLionel Sambuc
195433d6423SLionel Sambuc ObjDesc = SourceDesc;
196433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
197433d6423SLionel Sambuc break;
198433d6423SLionel Sambuc
199433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
202433d6423SLionel Sambuc {
203433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s",
204433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc)));
205433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
206433d6423SLionel Sambuc }
207433d6423SLionel Sambuc
208433d6423SLionel Sambuc /* Return an additional reference to the object */
209433d6423SLionel Sambuc
210433d6423SLionel Sambuc ObjDesc = SourceDesc;
211433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
212433d6423SLionel Sambuc break;
213433d6423SLionel Sambuc
214433d6423SLionel Sambuc case ACPI_TYPE_BUFFER_FIELD:
215433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_REGION_FIELD:
216433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_BANK_FIELD:
217433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_INDEX_FIELD:
218433d6423SLionel Sambuc
219433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
220433d6423SLionel Sambuc "FieldRead Node=%p SourceDesc=%p Type=%X\n",
221433d6423SLionel Sambuc Node, SourceDesc, EntryType));
222433d6423SLionel Sambuc
223433d6423SLionel Sambuc Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc);
224433d6423SLionel Sambuc break;
225433d6423SLionel Sambuc
226433d6423SLionel Sambuc /* For these objects, just return the object attached to the Node */
227433d6423SLionel Sambuc
228433d6423SLionel Sambuc case ACPI_TYPE_MUTEX:
229433d6423SLionel Sambuc case ACPI_TYPE_POWER:
230433d6423SLionel Sambuc case ACPI_TYPE_PROCESSOR:
231433d6423SLionel Sambuc case ACPI_TYPE_EVENT:
232433d6423SLionel Sambuc case ACPI_TYPE_REGION:
233433d6423SLionel Sambuc
234433d6423SLionel Sambuc /* Return an additional reference to the object */
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc ObjDesc = SourceDesc;
237433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
238433d6423SLionel Sambuc break;
239433d6423SLionel Sambuc
240433d6423SLionel Sambuc /* TYPE_ANY is untyped, and thus there is no object associated with it */
241433d6423SLionel Sambuc
242433d6423SLionel Sambuc case ACPI_TYPE_ANY:
243433d6423SLionel Sambuc
244433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
245433d6423SLionel Sambuc "Untyped entry %p, no attached object!", Node));
246433d6423SLionel Sambuc
247433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
248433d6423SLionel Sambuc
249433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_REFERENCE:
250433d6423SLionel Sambuc
251433d6423SLionel Sambuc switch (SourceDesc->Reference.Class)
252433d6423SLionel Sambuc {
253433d6423SLionel Sambuc case ACPI_REFCLASS_TABLE: /* This is a DdbHandle */
254433d6423SLionel Sambuc case ACPI_REFCLASS_REFOF:
255433d6423SLionel Sambuc case ACPI_REFCLASS_INDEX:
256433d6423SLionel Sambuc
257433d6423SLionel Sambuc /* Return an additional reference to the object */
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc ObjDesc = SourceDesc;
260433d6423SLionel Sambuc AcpiUtAddReference (ObjDesc);
261433d6423SLionel Sambuc break;
262433d6423SLionel Sambuc
263433d6423SLionel Sambuc default:
264*29492bb7SDavid van Moolenbroek
265433d6423SLionel Sambuc /* No named references are allowed here */
266433d6423SLionel Sambuc
267433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
268433d6423SLionel Sambuc "Unsupported Reference type 0x%X",
269433d6423SLionel Sambuc SourceDesc->Reference.Class));
270433d6423SLionel Sambuc
271433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
272433d6423SLionel Sambuc }
273433d6423SLionel Sambuc break;
274433d6423SLionel Sambuc
275433d6423SLionel Sambuc default:
276433d6423SLionel Sambuc
277433d6423SLionel Sambuc /* Default case is for unknown types */
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
280433d6423SLionel Sambuc "Node %p - Unknown object type 0x%X",
281433d6423SLionel Sambuc Node, EntryType));
282433d6423SLionel Sambuc
283433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
284433d6423SLionel Sambuc
285433d6423SLionel Sambuc } /* switch (EntryType) */
286433d6423SLionel Sambuc
287433d6423SLionel Sambuc
288433d6423SLionel Sambuc /* Return the object descriptor */
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc *ObjectPtr = (void *) ObjDesc;
291433d6423SLionel Sambuc return_ACPI_STATUS (Status);
292433d6423SLionel Sambuc }
293