xref: /minix3/minix/drivers/power/acpi/dispatcher/dsobject.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: dsobject - Dispatcher object management routines
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 "acparser.h"
47433d6423SLionel Sambuc #include "amlcode.h"
48433d6423SLionel Sambuc #include "acdispat.h"
49433d6423SLionel Sambuc #include "acnamesp.h"
50433d6423SLionel Sambuc #include "acinterp.h"
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc #define _COMPONENT          ACPI_DISPATCHER
53433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("dsobject")
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc /* Local prototypes */
56433d6423SLionel Sambuc 
57433d6423SLionel Sambuc static ACPI_STATUS
58433d6423SLionel Sambuc AcpiDsBuildInternalObject (
59433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
60433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
61433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ObjDescPtr);
62433d6423SLionel Sambuc 
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
65433d6423SLionel Sambuc /*******************************************************************************
66433d6423SLionel Sambuc  *
67433d6423SLionel Sambuc  * FUNCTION:    AcpiDsBuildInternalObject
68433d6423SLionel Sambuc  *
69433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - Current walk state
70433d6423SLionel Sambuc  *              Op              - Parser object to be translated
71433d6423SLionel Sambuc  *              ObjDescPtr      - Where the ACPI internal object is returned
72433d6423SLionel Sambuc  *
73433d6423SLionel Sambuc  * RETURN:      Status
74433d6423SLionel Sambuc  *
75433d6423SLionel Sambuc  * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
76433d6423SLionel Sambuc  *              Simple objects are any objects other than a package object!
77433d6423SLionel Sambuc  *
78433d6423SLionel Sambuc  ******************************************************************************/
79433d6423SLionel Sambuc 
80433d6423SLionel Sambuc static ACPI_STATUS
AcpiDsBuildInternalObject(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op,ACPI_OPERAND_OBJECT ** ObjDescPtr)81433d6423SLionel Sambuc AcpiDsBuildInternalObject (
82433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
83433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
84433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ObjDescPtr)
85433d6423SLionel Sambuc {
86433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
87433d6423SLionel Sambuc     ACPI_STATUS             Status;
88433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type;
89433d6423SLionel Sambuc 
90433d6423SLionel Sambuc 
91433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsBuildInternalObject);
92433d6423SLionel Sambuc 
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc     *ObjDescPtr = NULL;
95433d6423SLionel Sambuc     if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
96433d6423SLionel Sambuc     {
97433d6423SLionel Sambuc         /*
98433d6423SLionel Sambuc          * This is a named object reference. If this name was
99433d6423SLionel Sambuc          * previously looked up in the namespace, it was stored in this op.
100433d6423SLionel Sambuc          * Otherwise, go ahead and look it up now
101433d6423SLionel Sambuc          */
102433d6423SLionel Sambuc         if (!Op->Common.Node)
103433d6423SLionel Sambuc         {
104433d6423SLionel Sambuc             Status = AcpiNsLookup (WalkState->ScopeInfo,
105433d6423SLionel Sambuc                         Op->Common.Value.String,
106433d6423SLionel Sambuc                         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
107433d6423SLionel Sambuc                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
108433d6423SLionel Sambuc                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
109433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
110433d6423SLionel Sambuc             {
111433d6423SLionel Sambuc                 /* Check if we are resolving a named reference within a package */
112433d6423SLionel Sambuc 
113433d6423SLionel Sambuc                 if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
114433d6423SLionel Sambuc 
115433d6423SLionel Sambuc                     ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
116433d6423SLionel Sambuc                      (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
117433d6423SLionel Sambuc                 {
118433d6423SLionel Sambuc                     /*
119433d6423SLionel Sambuc                      * We didn't find the target and we are populating elements
120433d6423SLionel Sambuc                      * of a package - ignore if slack enabled. Some ASL code
121433d6423SLionel Sambuc                      * contains dangling invalid references in packages and
122433d6423SLionel Sambuc                      * expects that no exception will be issued. Leave the
123433d6423SLionel Sambuc                      * element as a null element. It cannot be used, but it
124433d6423SLionel Sambuc                      * can be overwritten by subsequent ASL code - this is
125433d6423SLionel Sambuc                      * typically the case.
126433d6423SLionel Sambuc                      */
127433d6423SLionel Sambuc                     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
128433d6423SLionel Sambuc                         "Ignoring unresolved reference in package [%4.4s]\n",
129433d6423SLionel Sambuc                         WalkState->ScopeInfo->Scope.Node->Name.Ascii));
130433d6423SLionel Sambuc 
131433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_OK);
132433d6423SLionel Sambuc                 }
133433d6423SLionel Sambuc                 else
134433d6423SLionel Sambuc                 {
135433d6423SLionel Sambuc                     ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
136433d6423SLionel Sambuc                 }
137433d6423SLionel Sambuc 
138433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
139433d6423SLionel Sambuc             }
140433d6423SLionel Sambuc         }
141433d6423SLionel Sambuc 
142433d6423SLionel Sambuc         /* Special object resolution for elements of a package */
143433d6423SLionel Sambuc 
144433d6423SLionel Sambuc         if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
145433d6423SLionel Sambuc             (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
146433d6423SLionel Sambuc         {
147433d6423SLionel Sambuc             /*
148433d6423SLionel Sambuc              * Attempt to resolve the node to a value before we insert it into
149433d6423SLionel Sambuc              * the package. If this is a reference to a common data type,
150433d6423SLionel Sambuc              * resolve it immediately. According to the ACPI spec, package
151433d6423SLionel Sambuc              * elements can only be "data objects" or method references.
152433d6423SLionel Sambuc              * Attempt to resolve to an Integer, Buffer, String or Package.
153433d6423SLionel Sambuc              * If cannot, return the named reference (for things like Devices,
154433d6423SLionel Sambuc              * Methods, etc.) Buffer Fields and Fields will resolve to simple
155433d6423SLionel Sambuc              * objects (int/buf/str/pkg).
156433d6423SLionel Sambuc              *
157433d6423SLionel Sambuc              * NOTE: References to things like Devices, Methods, Mutexes, etc.
158433d6423SLionel Sambuc              * will remain as named references. This behavior is not described
159433d6423SLionel Sambuc              * in the ACPI spec, but it appears to be an oversight.
160433d6423SLionel Sambuc              */
161433d6423SLionel Sambuc             ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
162433d6423SLionel Sambuc 
163433d6423SLionel Sambuc             Status = AcpiExResolveNodeToValue (
164433d6423SLionel Sambuc                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
165433d6423SLionel Sambuc                         WalkState);
166433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
167433d6423SLionel Sambuc             {
168433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
169433d6423SLionel Sambuc             }
170433d6423SLionel Sambuc 
171433d6423SLionel Sambuc             /*
172433d6423SLionel Sambuc              * Special handling for Alias objects. We need to setup the type
173433d6423SLionel Sambuc              * and the Op->Common.Node to point to the Alias target. Note,
174433d6423SLionel Sambuc              * Alias has at most one level of indirection internally.
175433d6423SLionel Sambuc              */
176433d6423SLionel Sambuc             Type = Op->Common.Node->Type;
177433d6423SLionel Sambuc             if (Type == ACPI_TYPE_LOCAL_ALIAS)
178433d6423SLionel Sambuc             {
179433d6423SLionel Sambuc                 Type = ObjDesc->Common.Type;
180433d6423SLionel Sambuc                 Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
181433d6423SLionel Sambuc                     Op->Common.Node->Object);
182433d6423SLionel Sambuc             }
183433d6423SLionel Sambuc 
184433d6423SLionel Sambuc             switch (Type)
185433d6423SLionel Sambuc             {
186433d6423SLionel Sambuc             /*
187433d6423SLionel Sambuc              * For these types, we need the actual node, not the subobject.
188433d6423SLionel Sambuc              * However, the subobject did not get an extra reference count above.
189433d6423SLionel Sambuc              *
190433d6423SLionel Sambuc              * TBD: should ExResolveNodeToValue be changed to fix this?
191433d6423SLionel Sambuc              */
192433d6423SLionel Sambuc             case ACPI_TYPE_DEVICE:
193433d6423SLionel Sambuc             case ACPI_TYPE_THERMAL:
194433d6423SLionel Sambuc 
195433d6423SLionel Sambuc                 AcpiUtAddReference (Op->Common.Node->Object);
196433d6423SLionel Sambuc 
197433d6423SLionel Sambuc                 /*lint -fallthrough */
198433d6423SLionel Sambuc             /*
199433d6423SLionel Sambuc              * For these types, we need the actual node, not the subobject.
200433d6423SLionel Sambuc              * The subobject got an extra reference count in ExResolveNodeToValue.
201433d6423SLionel Sambuc              */
202433d6423SLionel Sambuc             case ACPI_TYPE_MUTEX:
203433d6423SLionel Sambuc             case ACPI_TYPE_METHOD:
204433d6423SLionel Sambuc             case ACPI_TYPE_POWER:
205433d6423SLionel Sambuc             case ACPI_TYPE_PROCESSOR:
206433d6423SLionel Sambuc             case ACPI_TYPE_EVENT:
207433d6423SLionel Sambuc             case ACPI_TYPE_REGION:
208433d6423SLionel Sambuc 
209433d6423SLionel Sambuc                 /* We will create a reference object for these types below */
210433d6423SLionel Sambuc                 break;
211433d6423SLionel Sambuc 
212433d6423SLionel Sambuc             default:
213433d6423SLionel Sambuc                 /*
214433d6423SLionel Sambuc                  * All other types - the node was resolved to an actual
215433d6423SLionel Sambuc                  * object, we are done.
216433d6423SLionel Sambuc                  */
217433d6423SLionel Sambuc                 goto Exit;
218433d6423SLionel Sambuc             }
219433d6423SLionel Sambuc         }
220433d6423SLionel Sambuc     }
221433d6423SLionel Sambuc 
222433d6423SLionel Sambuc     /* Create and init a new internal ACPI object */
223433d6423SLionel Sambuc 
224433d6423SLionel Sambuc     ObjDesc = AcpiUtCreateInternalObject (
225433d6423SLionel Sambuc                 (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
226433d6423SLionel Sambuc     if (!ObjDesc)
227433d6423SLionel Sambuc     {
228433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NO_MEMORY);
229433d6423SLionel Sambuc     }
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc     Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
232433d6423SLionel Sambuc                 &ObjDesc);
233433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
234433d6423SLionel Sambuc     {
235433d6423SLionel Sambuc         AcpiUtRemoveReference (ObjDesc);
236433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
237433d6423SLionel Sambuc     }
238433d6423SLionel Sambuc 
239433d6423SLionel Sambuc Exit:
240433d6423SLionel Sambuc     *ObjDescPtr = ObjDesc;
241433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
242433d6423SLionel Sambuc }
243433d6423SLionel Sambuc 
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc /*******************************************************************************
246433d6423SLionel Sambuc  *
247433d6423SLionel Sambuc  * FUNCTION:    AcpiDsBuildInternalBufferObj
248433d6423SLionel Sambuc  *
249433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - Current walk state
250433d6423SLionel Sambuc  *              Op              - Parser object to be translated
251433d6423SLionel Sambuc  *              BufferLength    - Length of the buffer
252433d6423SLionel Sambuc  *              ObjDescPtr      - Where the ACPI internal object is returned
253433d6423SLionel Sambuc  *
254433d6423SLionel Sambuc  * RETURN:      Status
255433d6423SLionel Sambuc  *
256433d6423SLionel Sambuc  * DESCRIPTION: Translate a parser Op package object to the equivalent
257433d6423SLionel Sambuc  *              namespace object
258433d6423SLionel Sambuc  *
259433d6423SLionel Sambuc  ******************************************************************************/
260433d6423SLionel Sambuc 
261433d6423SLionel Sambuc ACPI_STATUS
AcpiDsBuildInternalBufferObj(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op,UINT32 BufferLength,ACPI_OPERAND_OBJECT ** ObjDescPtr)262433d6423SLionel Sambuc AcpiDsBuildInternalBufferObj (
263433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
264433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
265433d6423SLionel Sambuc     UINT32                  BufferLength,
266433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ObjDescPtr)
267433d6423SLionel Sambuc {
268433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Arg;
269433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
270433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *ByteList;
271433d6423SLionel Sambuc     UINT32                  ByteListLength = 0;
272433d6423SLionel Sambuc 
273433d6423SLionel Sambuc 
274433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
275433d6423SLionel Sambuc 
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc     /*
278433d6423SLionel Sambuc      * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
279433d6423SLionel Sambuc      * The buffer object already exists (from the NS node), otherwise it must
280433d6423SLionel Sambuc      * be created.
281433d6423SLionel Sambuc      */
282433d6423SLionel Sambuc     ObjDesc = *ObjDescPtr;
283433d6423SLionel Sambuc     if (!ObjDesc)
284433d6423SLionel Sambuc     {
285433d6423SLionel Sambuc         /* Create a new buffer object */
286433d6423SLionel Sambuc 
287433d6423SLionel Sambuc         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
288433d6423SLionel Sambuc         *ObjDescPtr = ObjDesc;
289433d6423SLionel Sambuc         if (!ObjDesc)
290433d6423SLionel Sambuc         {
291433d6423SLionel Sambuc             return_ACPI_STATUS (AE_NO_MEMORY);
292433d6423SLionel Sambuc         }
293433d6423SLionel Sambuc     }
294433d6423SLionel Sambuc 
295433d6423SLionel Sambuc     /*
296433d6423SLionel Sambuc      * Second arg is the buffer data (optional) ByteList can be either
297433d6423SLionel Sambuc      * individual bytes or a string initializer. In either case, a
298433d6423SLionel Sambuc      * ByteList appears in the AML.
299433d6423SLionel Sambuc      */
300433d6423SLionel Sambuc     Arg = Op->Common.Value.Arg;         /* skip first arg */
301433d6423SLionel Sambuc 
302433d6423SLionel Sambuc     ByteList = Arg->Named.Next;
303433d6423SLionel Sambuc     if (ByteList)
304433d6423SLionel Sambuc     {
305433d6423SLionel Sambuc         if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
306433d6423SLionel Sambuc         {
307433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
308433d6423SLionel Sambuc                 "Expecting bytelist, found AML opcode 0x%X in op %p",
309433d6423SLionel Sambuc                 ByteList->Common.AmlOpcode, ByteList));
310433d6423SLionel Sambuc 
311433d6423SLionel Sambuc             AcpiUtRemoveReference (ObjDesc);
312433d6423SLionel Sambuc             return (AE_TYPE);
313433d6423SLionel Sambuc         }
314433d6423SLionel Sambuc 
315433d6423SLionel Sambuc         ByteListLength = (UINT32) ByteList->Common.Value.Integer;
316433d6423SLionel Sambuc     }
317433d6423SLionel Sambuc 
318433d6423SLionel Sambuc     /*
319433d6423SLionel Sambuc      * The buffer length (number of bytes) will be the larger of:
320433d6423SLionel Sambuc      * 1) The specified buffer length and
321433d6423SLionel Sambuc      * 2) The length of the initializer byte list
322433d6423SLionel Sambuc      */
323433d6423SLionel Sambuc     ObjDesc->Buffer.Length = BufferLength;
324433d6423SLionel Sambuc     if (ByteListLength > BufferLength)
325433d6423SLionel Sambuc     {
326433d6423SLionel Sambuc         ObjDesc->Buffer.Length = ByteListLength;
327433d6423SLionel Sambuc     }
328433d6423SLionel Sambuc 
329433d6423SLionel Sambuc     /* Allocate the buffer */
330433d6423SLionel Sambuc 
331433d6423SLionel Sambuc     if (ObjDesc->Buffer.Length == 0)
332433d6423SLionel Sambuc     {
333433d6423SLionel Sambuc         ObjDesc->Buffer.Pointer = NULL;
334433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
335433d6423SLionel Sambuc             "Buffer defined with zero length in AML, creating\n"));
336433d6423SLionel Sambuc     }
337433d6423SLionel Sambuc     else
338433d6423SLionel Sambuc     {
339433d6423SLionel Sambuc         ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED (
340433d6423SLionel Sambuc                                         ObjDesc->Buffer.Length);
341433d6423SLionel Sambuc         if (!ObjDesc->Buffer.Pointer)
342433d6423SLionel Sambuc         {
343433d6423SLionel Sambuc             AcpiUtDeleteObjectDesc (ObjDesc);
344433d6423SLionel Sambuc             return_ACPI_STATUS (AE_NO_MEMORY);
345433d6423SLionel Sambuc         }
346433d6423SLionel Sambuc 
347433d6423SLionel Sambuc         /* Initialize buffer from the ByteList (if present) */
348433d6423SLionel Sambuc 
349433d6423SLionel Sambuc         if (ByteList)
350433d6423SLionel Sambuc         {
351433d6423SLionel Sambuc             ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
352433d6423SLionel Sambuc                          ByteListLength);
353433d6423SLionel Sambuc         }
354433d6423SLionel Sambuc     }
355433d6423SLionel Sambuc 
356433d6423SLionel Sambuc     ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
357433d6423SLionel Sambuc     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
358433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
359433d6423SLionel Sambuc }
360433d6423SLionel Sambuc 
361433d6423SLionel Sambuc 
362433d6423SLionel Sambuc /*******************************************************************************
363433d6423SLionel Sambuc  *
364433d6423SLionel Sambuc  * FUNCTION:    AcpiDsBuildInternalPackageObj
365433d6423SLionel Sambuc  *
366433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - Current walk state
367433d6423SLionel Sambuc  *              Op              - Parser object to be translated
368433d6423SLionel Sambuc  *              ElementCount    - Number of elements in the package - this is
369433d6423SLionel Sambuc  *                                the NumElements argument to Package()
370433d6423SLionel Sambuc  *              ObjDescPtr      - Where the ACPI internal object is returned
371433d6423SLionel Sambuc  *
372433d6423SLionel Sambuc  * RETURN:      Status
373433d6423SLionel Sambuc  *
374433d6423SLionel Sambuc  * DESCRIPTION: Translate a parser Op package object to the equivalent
375433d6423SLionel Sambuc  *              namespace object
376433d6423SLionel Sambuc  *
377433d6423SLionel Sambuc  * NOTE: The number of elements in the package will be always be the NumElements
378433d6423SLionel Sambuc  * count, regardless of the number of elements in the package list. If
379433d6423SLionel Sambuc  * NumElements is smaller, only that many package list elements are used.
380433d6423SLionel Sambuc  * if NumElements is larger, the Package object is padded out with
381433d6423SLionel Sambuc  * objects of type Uninitialized (as per ACPI spec.)
382433d6423SLionel Sambuc  *
383433d6423SLionel Sambuc  * Even though the ASL compilers do not allow NumElements to be smaller
384433d6423SLionel Sambuc  * than the Package list length (for the fixed length package opcode), some
385433d6423SLionel Sambuc  * BIOS code modifies the AML on the fly to adjust the NumElements, and
386433d6423SLionel Sambuc  * this code compensates for that. This also provides compatibility with
387433d6423SLionel Sambuc  * other AML interpreters.
388433d6423SLionel Sambuc  *
389433d6423SLionel Sambuc  ******************************************************************************/
390433d6423SLionel Sambuc 
391433d6423SLionel Sambuc ACPI_STATUS
AcpiDsBuildInternalPackageObj(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op,UINT32 ElementCount,ACPI_OPERAND_OBJECT ** ObjDescPtr)392433d6423SLionel Sambuc AcpiDsBuildInternalPackageObj (
393433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
394433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
395433d6423SLionel Sambuc     UINT32                  ElementCount,
396433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ObjDescPtr)
397433d6423SLionel Sambuc {
398433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Arg;
399433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Parent;
400433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
401433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
402433d6423SLionel Sambuc     UINT32                  i;
403433d6423SLionel Sambuc     UINT16                  Index;
404433d6423SLionel Sambuc     UINT16                  ReferenceCount;
405433d6423SLionel Sambuc 
406433d6423SLionel Sambuc 
407433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc 
410433d6423SLionel Sambuc     /* Find the parent of a possibly nested package */
411433d6423SLionel Sambuc 
412433d6423SLionel Sambuc     Parent = Op->Common.Parent;
413433d6423SLionel Sambuc     while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
414433d6423SLionel Sambuc            (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
415433d6423SLionel Sambuc     {
416433d6423SLionel Sambuc         Parent = Parent->Common.Parent;
417433d6423SLionel Sambuc     }
418433d6423SLionel Sambuc 
419433d6423SLionel Sambuc     /*
420433d6423SLionel Sambuc      * If we are evaluating a Named package object "Name (xxxx, Package)",
421433d6423SLionel Sambuc      * the package object already exists, otherwise it must be created.
422433d6423SLionel Sambuc      */
423433d6423SLionel Sambuc     ObjDesc = *ObjDescPtr;
424433d6423SLionel Sambuc     if (!ObjDesc)
425433d6423SLionel Sambuc     {
426433d6423SLionel Sambuc         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
427433d6423SLionel Sambuc         *ObjDescPtr = ObjDesc;
428433d6423SLionel Sambuc         if (!ObjDesc)
429433d6423SLionel Sambuc         {
430433d6423SLionel Sambuc             return_ACPI_STATUS (AE_NO_MEMORY);
431433d6423SLionel Sambuc         }
432433d6423SLionel Sambuc 
433433d6423SLionel Sambuc         ObjDesc->Package.Node = Parent->Common.Node;
434433d6423SLionel Sambuc     }
435433d6423SLionel Sambuc 
436433d6423SLionel Sambuc     /*
437433d6423SLionel Sambuc      * Allocate the element array (array of pointers to the individual
438433d6423SLionel Sambuc      * objects) based on the NumElements parameter. Add an extra pointer slot
439433d6423SLionel Sambuc      * so that the list is always null terminated.
440433d6423SLionel Sambuc      */
441433d6423SLionel Sambuc     ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
442433d6423SLionel Sambuc         ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
443433d6423SLionel Sambuc 
444433d6423SLionel Sambuc     if (!ObjDesc->Package.Elements)
445433d6423SLionel Sambuc     {
446433d6423SLionel Sambuc         AcpiUtDeleteObjectDesc (ObjDesc);
447433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NO_MEMORY);
448433d6423SLionel Sambuc     }
449433d6423SLionel Sambuc 
450433d6423SLionel Sambuc     ObjDesc->Package.Count = ElementCount;
451433d6423SLionel Sambuc 
452433d6423SLionel Sambuc     /*
453433d6423SLionel Sambuc      * Initialize the elements of the package, up to the NumElements count.
454433d6423SLionel Sambuc      * Package is automatically padded with uninitialized (NULL) elements
455433d6423SLionel Sambuc      * if NumElements is greater than the package list length. Likewise,
456433d6423SLionel Sambuc      * Package is truncated if NumElements is less than the list length.
457433d6423SLionel Sambuc      */
458433d6423SLionel Sambuc     Arg = Op->Common.Value.Arg;
459433d6423SLionel Sambuc     Arg = Arg->Common.Next;
460433d6423SLionel Sambuc     for (i = 0; Arg && (i < ElementCount); i++)
461433d6423SLionel Sambuc     {
462433d6423SLionel Sambuc         if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
463433d6423SLionel Sambuc         {
464433d6423SLionel Sambuc             if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
465433d6423SLionel Sambuc             {
466433d6423SLionel Sambuc                 /*
467433d6423SLionel Sambuc                  * A method reference "looks" to the parser to be a method
468433d6423SLionel Sambuc                  * invocation, so we special case it here
469433d6423SLionel Sambuc                  */
470433d6423SLionel Sambuc                 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
471433d6423SLionel Sambuc                 Status = AcpiDsBuildInternalObject (WalkState, Arg,
472433d6423SLionel Sambuc                             &ObjDesc->Package.Elements[i]);
473433d6423SLionel Sambuc             }
474433d6423SLionel Sambuc             else
475433d6423SLionel Sambuc             {
476433d6423SLionel Sambuc                 /* This package element is already built, just get it */
477433d6423SLionel Sambuc 
478433d6423SLionel Sambuc                 ObjDesc->Package.Elements[i] =
479433d6423SLionel Sambuc                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
480433d6423SLionel Sambuc             }
481433d6423SLionel Sambuc         }
482433d6423SLionel Sambuc         else
483433d6423SLionel Sambuc         {
484433d6423SLionel Sambuc             Status = AcpiDsBuildInternalObject (WalkState, Arg,
485433d6423SLionel Sambuc                         &ObjDesc->Package.Elements[i]);
486433d6423SLionel Sambuc         }
487433d6423SLionel Sambuc 
488433d6423SLionel Sambuc         if (*ObjDescPtr)
489433d6423SLionel Sambuc         {
490433d6423SLionel Sambuc             /* Existing package, get existing reference count */
491433d6423SLionel Sambuc 
492433d6423SLionel Sambuc             ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
493433d6423SLionel Sambuc             if (ReferenceCount > 1)
494433d6423SLionel Sambuc             {
495433d6423SLionel Sambuc                 /* Make new element ref count match original ref count */
496433d6423SLionel Sambuc 
497433d6423SLionel Sambuc                 for (Index = 0; Index < (ReferenceCount - 1); Index++)
498433d6423SLionel Sambuc                 {
499433d6423SLionel Sambuc                     AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
500433d6423SLionel Sambuc                 }
501433d6423SLionel Sambuc             }
502433d6423SLionel Sambuc         }
503433d6423SLionel Sambuc 
504433d6423SLionel Sambuc         Arg = Arg->Common.Next;
505433d6423SLionel Sambuc     }
506433d6423SLionel Sambuc 
507433d6423SLionel Sambuc     /* Check for match between NumElements and actual length of PackageList */
508433d6423SLionel Sambuc 
509433d6423SLionel Sambuc     if (Arg)
510433d6423SLionel Sambuc     {
511433d6423SLionel Sambuc         /*
512433d6423SLionel Sambuc          * NumElements was exhausted, but there are remaining elements in the
513433d6423SLionel Sambuc          * PackageList. Truncate the package to NumElements.
514433d6423SLionel Sambuc          *
515433d6423SLionel Sambuc          * Note: technically, this is an error, from ACPI spec: "It is an error
516433d6423SLionel Sambuc          * for NumElements to be less than the number of elements in the
517433d6423SLionel Sambuc          * PackageList". However, we just print a message and
518433d6423SLionel Sambuc          * no exception is returned. This provides Windows compatibility. Some
519433d6423SLionel Sambuc          * BIOSs will alter the NumElements on the fly, creating this type
520433d6423SLionel Sambuc          * of ill-formed package object.
521433d6423SLionel Sambuc          */
522433d6423SLionel Sambuc         while (Arg)
523433d6423SLionel Sambuc         {
524433d6423SLionel Sambuc             /*
525433d6423SLionel Sambuc              * We must delete any package elements that were created earlier
526433d6423SLionel Sambuc              * and are not going to be used because of the package truncation.
527433d6423SLionel Sambuc              */
528433d6423SLionel Sambuc             if (Arg->Common.Node)
529433d6423SLionel Sambuc             {
530433d6423SLionel Sambuc                 AcpiUtRemoveReference (
531433d6423SLionel Sambuc                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
532433d6423SLionel Sambuc                 Arg->Common.Node = NULL;
533433d6423SLionel Sambuc             }
534433d6423SLionel Sambuc 
535433d6423SLionel Sambuc             /* Find out how many elements there really are */
536433d6423SLionel Sambuc 
537433d6423SLionel Sambuc             i++;
538433d6423SLionel Sambuc             Arg = Arg->Common.Next;
539433d6423SLionel Sambuc         }
540433d6423SLionel Sambuc 
541433d6423SLionel Sambuc         ACPI_INFO ((AE_INFO,
542*29492bb7SDavid van Moolenbroek             "Actual Package length (%u) is larger than NumElements field (%u), truncated",
543433d6423SLionel Sambuc             i, ElementCount));
544433d6423SLionel Sambuc     }
545433d6423SLionel Sambuc     else if (i < ElementCount)
546433d6423SLionel Sambuc     {
547433d6423SLionel Sambuc         /*
548433d6423SLionel Sambuc          * Arg list (elements) was exhausted, but we did not reach NumElements count.
549433d6423SLionel Sambuc          * Note: this is not an error, the package is padded out with NULLs.
550433d6423SLionel Sambuc          */
551433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
552433d6423SLionel Sambuc             "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
553433d6423SLionel Sambuc             i, ElementCount));
554433d6423SLionel Sambuc     }
555433d6423SLionel Sambuc 
556433d6423SLionel Sambuc     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
557433d6423SLionel Sambuc     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
558433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
559433d6423SLionel Sambuc }
560433d6423SLionel Sambuc 
561433d6423SLionel Sambuc 
562433d6423SLionel Sambuc /*******************************************************************************
563433d6423SLionel Sambuc  *
564433d6423SLionel Sambuc  * FUNCTION:    AcpiDsCreateNode
565433d6423SLionel Sambuc  *
566433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - Current walk state
567433d6423SLionel Sambuc  *              Node            - NS Node to be initialized
568433d6423SLionel Sambuc  *              Op              - Parser object to be translated
569433d6423SLionel Sambuc  *
570433d6423SLionel Sambuc  * RETURN:      Status
571433d6423SLionel Sambuc  *
572433d6423SLionel Sambuc  * DESCRIPTION: Create the object to be associated with a namespace node
573433d6423SLionel Sambuc  *
574433d6423SLionel Sambuc  ******************************************************************************/
575433d6423SLionel Sambuc 
576433d6423SLionel Sambuc ACPI_STATUS
AcpiDsCreateNode(ACPI_WALK_STATE * WalkState,ACPI_NAMESPACE_NODE * Node,ACPI_PARSE_OBJECT * Op)577433d6423SLionel Sambuc AcpiDsCreateNode (
578433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
579433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
580433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op)
581433d6423SLionel Sambuc {
582433d6423SLionel Sambuc     ACPI_STATUS             Status;
583433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
584433d6423SLionel Sambuc 
585433d6423SLionel Sambuc 
586433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
587433d6423SLionel Sambuc 
588433d6423SLionel Sambuc 
589433d6423SLionel Sambuc     /*
590433d6423SLionel Sambuc      * Because of the execution pass through the non-control-method
591433d6423SLionel Sambuc      * parts of the table, we can arrive here twice. Only init
592433d6423SLionel Sambuc      * the named object node the first time through
593433d6423SLionel Sambuc      */
594433d6423SLionel Sambuc     if (AcpiNsGetAttachedObject (Node))
595433d6423SLionel Sambuc     {
596433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
597433d6423SLionel Sambuc     }
598433d6423SLionel Sambuc 
599433d6423SLionel Sambuc     if (!Op->Common.Value.Arg)
600433d6423SLionel Sambuc     {
601433d6423SLionel Sambuc         /* No arguments, there is nothing to do */
602433d6423SLionel Sambuc 
603433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
604433d6423SLionel Sambuc     }
605433d6423SLionel Sambuc 
606433d6423SLionel Sambuc     /* Build an internal object for the argument(s) */
607433d6423SLionel Sambuc 
608433d6423SLionel Sambuc     Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
609433d6423SLionel Sambuc                 &ObjDesc);
610433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
611433d6423SLionel Sambuc     {
612433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
613433d6423SLionel Sambuc     }
614433d6423SLionel Sambuc 
615433d6423SLionel Sambuc     /* Re-type the object according to its argument */
616433d6423SLionel Sambuc 
617433d6423SLionel Sambuc     Node->Type = ObjDesc->Common.Type;
618433d6423SLionel Sambuc 
619433d6423SLionel Sambuc     /* Attach obj to node */
620433d6423SLionel Sambuc 
621433d6423SLionel Sambuc     Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
622433d6423SLionel Sambuc 
623433d6423SLionel Sambuc     /* Remove local reference to the object */
624433d6423SLionel Sambuc 
625433d6423SLionel Sambuc     AcpiUtRemoveReference (ObjDesc);
626433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
627433d6423SLionel Sambuc }
628433d6423SLionel Sambuc 
629433d6423SLionel Sambuc #endif /* ACPI_NO_METHOD_EXECUTION */
630433d6423SLionel Sambuc 
631433d6423SLionel Sambuc 
632433d6423SLionel Sambuc /*******************************************************************************
633433d6423SLionel Sambuc  *
634433d6423SLionel Sambuc  * FUNCTION:    AcpiDsInitObjectFromOp
635433d6423SLionel Sambuc  *
636433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - Current walk state
637433d6423SLionel Sambuc  *              Op              - Parser op used to init the internal object
638433d6423SLionel Sambuc  *              Opcode          - AML opcode associated with the object
639433d6423SLionel Sambuc  *              RetObjDesc      - Namespace object to be initialized
640433d6423SLionel Sambuc  *
641433d6423SLionel Sambuc  * RETURN:      Status
642433d6423SLionel Sambuc  *
643433d6423SLionel Sambuc  * DESCRIPTION: Initialize a namespace object from a parser Op and its
644433d6423SLionel Sambuc  *              associated arguments. The namespace object is a more compact
645433d6423SLionel Sambuc  *              representation of the Op and its arguments.
646433d6423SLionel Sambuc  *
647433d6423SLionel Sambuc  ******************************************************************************/
648433d6423SLionel Sambuc 
649433d6423SLionel Sambuc ACPI_STATUS
AcpiDsInitObjectFromOp(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op,UINT16 Opcode,ACPI_OPERAND_OBJECT ** RetObjDesc)650433d6423SLionel Sambuc AcpiDsInitObjectFromOp (
651433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
652433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
653433d6423SLionel Sambuc     UINT16                  Opcode,
654433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **RetObjDesc)
655433d6423SLionel Sambuc {
656433d6423SLionel Sambuc     const ACPI_OPCODE_INFO  *OpInfo;
657433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
658433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
659433d6423SLionel Sambuc 
660433d6423SLionel Sambuc 
661433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
662433d6423SLionel Sambuc 
663433d6423SLionel Sambuc 
664433d6423SLionel Sambuc     ObjDesc = *RetObjDesc;
665433d6423SLionel Sambuc     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
666433d6423SLionel Sambuc     if (OpInfo->Class == AML_CLASS_UNKNOWN)
667433d6423SLionel Sambuc     {
668433d6423SLionel Sambuc         /* Unknown opcode */
669433d6423SLionel Sambuc 
670433d6423SLionel Sambuc         return_ACPI_STATUS (AE_TYPE);
671433d6423SLionel Sambuc     }
672433d6423SLionel Sambuc 
673433d6423SLionel Sambuc     /* Perform per-object initialization */
674433d6423SLionel Sambuc 
675433d6423SLionel Sambuc     switch (ObjDesc->Common.Type)
676433d6423SLionel Sambuc     {
677433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER:
678433d6423SLionel Sambuc         /*
679433d6423SLionel Sambuc          * Defer evaluation of Buffer TermArg operand
680433d6423SLionel Sambuc          */
681433d6423SLionel Sambuc         ObjDesc->Buffer.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
682433d6423SLionel Sambuc                                         WalkState->Operands[0]);
683433d6423SLionel Sambuc         ObjDesc->Buffer.AmlStart  = Op->Named.Data;
684433d6423SLionel Sambuc         ObjDesc->Buffer.AmlLength = Op->Named.Length;
685433d6423SLionel Sambuc         break;
686433d6423SLionel Sambuc 
687433d6423SLionel Sambuc     case ACPI_TYPE_PACKAGE:
688433d6423SLionel Sambuc         /*
689433d6423SLionel Sambuc          * Defer evaluation of Package TermArg operand
690433d6423SLionel Sambuc          */
691433d6423SLionel Sambuc         ObjDesc->Package.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
692433d6423SLionel Sambuc                                         WalkState->Operands[0]);
693433d6423SLionel Sambuc         ObjDesc->Package.AmlStart  = Op->Named.Data;
694433d6423SLionel Sambuc         ObjDesc->Package.AmlLength = Op->Named.Length;
695433d6423SLionel Sambuc         break;
696433d6423SLionel Sambuc 
697433d6423SLionel Sambuc     case ACPI_TYPE_INTEGER:
698433d6423SLionel Sambuc 
699433d6423SLionel Sambuc         switch (OpInfo->Type)
700433d6423SLionel Sambuc         {
701433d6423SLionel Sambuc         case AML_TYPE_CONSTANT:
702433d6423SLionel Sambuc             /*
703433d6423SLionel Sambuc              * Resolve AML Constants here - AND ONLY HERE!
704433d6423SLionel Sambuc              * All constants are integers.
705433d6423SLionel Sambuc              * We mark the integer with a flag that indicates that it started
706433d6423SLionel Sambuc              * life as a constant -- so that stores to constants will perform
707433d6423SLionel Sambuc              * as expected (noop). ZeroOp is used as a placeholder for optional
708433d6423SLionel Sambuc              * target operands.
709433d6423SLionel Sambuc              */
710433d6423SLionel Sambuc             ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
711433d6423SLionel Sambuc 
712433d6423SLionel Sambuc             switch (Opcode)
713433d6423SLionel Sambuc             {
714433d6423SLionel Sambuc             case AML_ZERO_OP:
715433d6423SLionel Sambuc 
716433d6423SLionel Sambuc                 ObjDesc->Integer.Value = 0;
717433d6423SLionel Sambuc                 break;
718433d6423SLionel Sambuc 
719433d6423SLionel Sambuc             case AML_ONE_OP:
720433d6423SLionel Sambuc 
721433d6423SLionel Sambuc                 ObjDesc->Integer.Value = 1;
722433d6423SLionel Sambuc                 break;
723433d6423SLionel Sambuc 
724433d6423SLionel Sambuc             case AML_ONES_OP:
725433d6423SLionel Sambuc 
726433d6423SLionel Sambuc                 ObjDesc->Integer.Value = ACPI_UINT64_MAX;
727433d6423SLionel Sambuc 
728433d6423SLionel Sambuc                 /* Truncate value if we are executing from a 32-bit ACPI table */
729433d6423SLionel Sambuc 
730433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
731*29492bb7SDavid van Moolenbroek                 (void) AcpiExTruncateFor32bitTable (ObjDesc);
732433d6423SLionel Sambuc #endif
733433d6423SLionel Sambuc                 break;
734433d6423SLionel Sambuc 
735433d6423SLionel Sambuc             case AML_REVISION_OP:
736433d6423SLionel Sambuc 
737433d6423SLionel Sambuc                 ObjDesc->Integer.Value = ACPI_CA_VERSION;
738433d6423SLionel Sambuc                 break;
739433d6423SLionel Sambuc 
740433d6423SLionel Sambuc             default:
741433d6423SLionel Sambuc 
742433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
743433d6423SLionel Sambuc                     "Unknown constant opcode 0x%X", Opcode));
744433d6423SLionel Sambuc                 Status = AE_AML_OPERAND_TYPE;
745433d6423SLionel Sambuc                 break;
746433d6423SLionel Sambuc             }
747433d6423SLionel Sambuc             break;
748433d6423SLionel Sambuc 
749433d6423SLionel Sambuc         case AML_TYPE_LITERAL:
750433d6423SLionel Sambuc 
751433d6423SLionel Sambuc             ObjDesc->Integer.Value = Op->Common.Value.Integer;
752*29492bb7SDavid van Moolenbroek 
753433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
754*29492bb7SDavid van Moolenbroek             if (AcpiExTruncateFor32bitTable (ObjDesc))
755*29492bb7SDavid van Moolenbroek             {
756*29492bb7SDavid van Moolenbroek                 /* Warn if we found a 64-bit constant in a 32-bit table */
757*29492bb7SDavid van Moolenbroek 
758*29492bb7SDavid van Moolenbroek                 ACPI_WARNING ((AE_INFO,
759*29492bb7SDavid van Moolenbroek                     "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
760*29492bb7SDavid van Moolenbroek                     ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
761*29492bb7SDavid van Moolenbroek                     (UINT32) ObjDesc->Integer.Value));
762*29492bb7SDavid van Moolenbroek             }
763433d6423SLionel Sambuc #endif
764433d6423SLionel Sambuc             break;
765433d6423SLionel Sambuc 
766433d6423SLionel Sambuc         default:
767*29492bb7SDavid van Moolenbroek 
768433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
769433d6423SLionel Sambuc                 OpInfo->Type));
770433d6423SLionel Sambuc             Status = AE_AML_OPERAND_TYPE;
771433d6423SLionel Sambuc             break;
772433d6423SLionel Sambuc         }
773433d6423SLionel Sambuc         break;
774433d6423SLionel Sambuc 
775433d6423SLionel Sambuc     case ACPI_TYPE_STRING:
776433d6423SLionel Sambuc 
777433d6423SLionel Sambuc         ObjDesc->String.Pointer = Op->Common.Value.String;
778433d6423SLionel Sambuc         ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
779433d6423SLionel Sambuc 
780433d6423SLionel Sambuc         /*
781433d6423SLionel Sambuc          * The string is contained in the ACPI table, don't ever try
782433d6423SLionel Sambuc          * to delete it
783433d6423SLionel Sambuc          */
784433d6423SLionel Sambuc         ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
785433d6423SLionel Sambuc         break;
786433d6423SLionel Sambuc 
787433d6423SLionel Sambuc     case ACPI_TYPE_METHOD:
788433d6423SLionel Sambuc         break;
789433d6423SLionel Sambuc 
790433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_REFERENCE:
791433d6423SLionel Sambuc 
792433d6423SLionel Sambuc         switch (OpInfo->Type)
793433d6423SLionel Sambuc         {
794433d6423SLionel Sambuc         case AML_TYPE_LOCAL_VARIABLE:
795433d6423SLionel Sambuc 
796433d6423SLionel Sambuc             /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
797433d6423SLionel Sambuc 
798433d6423SLionel Sambuc             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
799433d6423SLionel Sambuc             ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
800433d6423SLionel Sambuc 
801433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
802433d6423SLionel Sambuc             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
803433d6423SLionel Sambuc                         ObjDesc->Reference.Value, WalkState,
804433d6423SLionel Sambuc                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
805433d6423SLionel Sambuc                             &ObjDesc->Reference.Object));
806433d6423SLionel Sambuc #endif
807433d6423SLionel Sambuc             break;
808433d6423SLionel Sambuc 
809433d6423SLionel Sambuc         case AML_TYPE_METHOD_ARGUMENT:
810433d6423SLionel Sambuc 
811433d6423SLionel Sambuc             /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
812433d6423SLionel Sambuc 
813433d6423SLionel Sambuc             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
814433d6423SLionel Sambuc             ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
815433d6423SLionel Sambuc 
816433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
817433d6423SLionel Sambuc             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
818433d6423SLionel Sambuc                         ObjDesc->Reference.Value, WalkState,
819433d6423SLionel Sambuc                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
820433d6423SLionel Sambuc                             &ObjDesc->Reference.Object));
821433d6423SLionel Sambuc #endif
822433d6423SLionel Sambuc             break;
823433d6423SLionel Sambuc 
824433d6423SLionel Sambuc         default: /* Object name or Debug object */
825433d6423SLionel Sambuc 
826433d6423SLionel Sambuc             switch (Op->Common.AmlOpcode)
827433d6423SLionel Sambuc             {
828433d6423SLionel Sambuc             case AML_INT_NAMEPATH_OP:
829433d6423SLionel Sambuc 
830433d6423SLionel Sambuc                 /* Node was saved in Op */
831433d6423SLionel Sambuc 
832433d6423SLionel Sambuc                 ObjDesc->Reference.Node = Op->Common.Node;
833433d6423SLionel Sambuc                 ObjDesc->Reference.Object = Op->Common.Node->Object;
834433d6423SLionel Sambuc                 ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
835433d6423SLionel Sambuc                 break;
836433d6423SLionel Sambuc 
837433d6423SLionel Sambuc             case AML_DEBUG_OP:
838433d6423SLionel Sambuc 
839433d6423SLionel Sambuc                 ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
840433d6423SLionel Sambuc                 break;
841433d6423SLionel Sambuc 
842433d6423SLionel Sambuc             default:
843433d6423SLionel Sambuc 
844433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
845433d6423SLionel Sambuc                     "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
846433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
847433d6423SLionel Sambuc             }
848433d6423SLionel Sambuc             break;
849433d6423SLionel Sambuc         }
850433d6423SLionel Sambuc         break;
851433d6423SLionel Sambuc 
852433d6423SLionel Sambuc     default:
853433d6423SLionel Sambuc 
854433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
855433d6423SLionel Sambuc             ObjDesc->Common.Type));
856433d6423SLionel Sambuc 
857433d6423SLionel Sambuc         Status = AE_AML_OPERAND_TYPE;
858433d6423SLionel Sambuc         break;
859433d6423SLionel Sambuc     }
860433d6423SLionel Sambuc 
861433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
862433d6423SLionel Sambuc }
863