xref: /minix3/minix/drivers/power/acpi/executer/exresop.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: exresop - AML Interpreter operand/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 "amlcode.h"
47433d6423SLionel Sambuc #include "acparser.h"
48433d6423SLionel Sambuc #include "acinterp.h"
49433d6423SLionel Sambuc #include "acnamesp.h"
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc #define _COMPONENT          ACPI_EXECUTER
53433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("exresop")
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc /* Local prototypes */
56433d6423SLionel Sambuc 
57433d6423SLionel Sambuc static ACPI_STATUS
58433d6423SLionel Sambuc AcpiExCheckObjectType (
59433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        TypeNeeded,
60433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        ThisType,
61433d6423SLionel Sambuc     void                    *Object);
62433d6423SLionel Sambuc 
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc /*******************************************************************************
65433d6423SLionel Sambuc  *
66433d6423SLionel Sambuc  * FUNCTION:    AcpiExCheckObjectType
67433d6423SLionel Sambuc  *
68433d6423SLionel Sambuc  * PARAMETERS:  TypeNeeded          Object type needed
69433d6423SLionel Sambuc  *              ThisType            Actual object type
70433d6423SLionel Sambuc  *              Object              Object pointer
71433d6423SLionel Sambuc  *
72433d6423SLionel Sambuc  * RETURN:      Status
73433d6423SLionel Sambuc  *
74433d6423SLionel Sambuc  * DESCRIPTION: Check required type against actual type
75433d6423SLionel Sambuc  *
76433d6423SLionel Sambuc  ******************************************************************************/
77433d6423SLionel Sambuc 
78433d6423SLionel Sambuc static ACPI_STATUS
AcpiExCheckObjectType(ACPI_OBJECT_TYPE TypeNeeded,ACPI_OBJECT_TYPE ThisType,void * Object)79433d6423SLionel Sambuc AcpiExCheckObjectType (
80433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        TypeNeeded,
81433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        ThisType,
82433d6423SLionel Sambuc     void                    *Object)
83433d6423SLionel Sambuc {
84433d6423SLionel Sambuc     ACPI_FUNCTION_ENTRY ();
85433d6423SLionel Sambuc 
86433d6423SLionel Sambuc 
87433d6423SLionel Sambuc     if (TypeNeeded == ACPI_TYPE_ANY)
88433d6423SLionel Sambuc     {
89433d6423SLionel Sambuc         /* All types OK, so we don't perform any typechecks */
90433d6423SLionel Sambuc 
91433d6423SLionel Sambuc         return (AE_OK);
92433d6423SLionel Sambuc     }
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc     if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
95433d6423SLionel Sambuc     {
96433d6423SLionel Sambuc         /*
97433d6423SLionel Sambuc          * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
98433d6423SLionel Sambuc          * objects and thus allow them to be targets. (As per the ACPI
99433d6423SLionel Sambuc          * specification, a store to a constant is a noop.)
100433d6423SLionel Sambuc          */
101433d6423SLionel Sambuc         if ((ThisType == ACPI_TYPE_INTEGER) &&
102433d6423SLionel Sambuc             (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
103433d6423SLionel Sambuc         {
104433d6423SLionel Sambuc             return (AE_OK);
105433d6423SLionel Sambuc         }
106433d6423SLionel Sambuc     }
107433d6423SLionel Sambuc 
108433d6423SLionel Sambuc     if (TypeNeeded != ThisType)
109433d6423SLionel Sambuc     {
110433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
111433d6423SLionel Sambuc             "Needed type [%s], found [%s] %p",
112433d6423SLionel Sambuc             AcpiUtGetTypeName (TypeNeeded),
113433d6423SLionel Sambuc             AcpiUtGetTypeName (ThisType), Object));
114433d6423SLionel Sambuc 
115433d6423SLionel Sambuc         return (AE_AML_OPERAND_TYPE);
116433d6423SLionel Sambuc     }
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc     return (AE_OK);
119433d6423SLionel Sambuc }
120433d6423SLionel Sambuc 
121433d6423SLionel Sambuc 
122433d6423SLionel Sambuc /*******************************************************************************
123433d6423SLionel Sambuc  *
124433d6423SLionel Sambuc  * FUNCTION:    AcpiExResolveOperands
125433d6423SLionel Sambuc  *
126433d6423SLionel Sambuc  * PARAMETERS:  Opcode              - Opcode being interpreted
127433d6423SLionel Sambuc  *              StackPtr            - Pointer to the operand stack to be
128433d6423SLionel Sambuc  *                                    resolved
129433d6423SLionel Sambuc  *              WalkState           - Current state
130433d6423SLionel Sambuc  *
131433d6423SLionel Sambuc  * RETURN:      Status
132433d6423SLionel Sambuc  *
133433d6423SLionel Sambuc  * DESCRIPTION: Convert multiple input operands to the types required by the
134433d6423SLionel Sambuc  *              target operator.
135433d6423SLionel Sambuc  *
136433d6423SLionel Sambuc  *      Each 5-bit group in ArgTypes represents one required
137433d6423SLionel Sambuc  *      operand and indicates the required Type. The corresponding operand
138433d6423SLionel Sambuc  *      will be converted to the required type if possible, otherwise we
139433d6423SLionel Sambuc  *      abort with an exception.
140433d6423SLionel Sambuc  *
141433d6423SLionel Sambuc  ******************************************************************************/
142433d6423SLionel Sambuc 
143433d6423SLionel Sambuc ACPI_STATUS
AcpiExResolveOperands(UINT16 Opcode,ACPI_OPERAND_OBJECT ** StackPtr,ACPI_WALK_STATE * WalkState)144433d6423SLionel Sambuc AcpiExResolveOperands (
145433d6423SLionel Sambuc     UINT16                  Opcode,
146433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **StackPtr,
147433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
148433d6423SLionel Sambuc {
149433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
150433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
151433d6423SLionel Sambuc     UINT8                   ObjectType;
152433d6423SLionel Sambuc     UINT32                  ArgTypes;
153433d6423SLionel Sambuc     const ACPI_OPCODE_INFO  *OpInfo;
154433d6423SLionel Sambuc     UINT32                  ThisArgType;
155433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        TypeNeeded;
156433d6423SLionel Sambuc     UINT16                  TargetOp = 0;
157433d6423SLionel Sambuc 
158433d6423SLionel Sambuc 
159433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_U32 (ExResolveOperands, Opcode);
160433d6423SLionel Sambuc 
161433d6423SLionel Sambuc 
162433d6423SLionel Sambuc     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
163433d6423SLionel Sambuc     if (OpInfo->Class == AML_CLASS_UNKNOWN)
164433d6423SLionel Sambuc     {
165433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_BAD_OPCODE);
166433d6423SLionel Sambuc     }
167433d6423SLionel Sambuc 
168433d6423SLionel Sambuc     ArgTypes = OpInfo->RuntimeArgs;
169433d6423SLionel Sambuc     if (ArgTypes == ARGI_INVALID_OPCODE)
170433d6423SLionel Sambuc     {
171433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
172433d6423SLionel Sambuc             Opcode));
173433d6423SLionel Sambuc 
174433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_INTERNAL);
175433d6423SLionel Sambuc     }
176433d6423SLionel Sambuc 
177433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
178433d6423SLionel Sambuc         "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
179433d6423SLionel Sambuc         Opcode, OpInfo->Name, ArgTypes));
180433d6423SLionel Sambuc 
181433d6423SLionel Sambuc     /*
182433d6423SLionel Sambuc      * Normal exit is with (ArgTypes == 0) at end of argument list.
183433d6423SLionel Sambuc      * Function will return an exception from within the loop upon
184433d6423SLionel Sambuc      * finding an entry which is not (or cannot be converted
185433d6423SLionel Sambuc      * to) the required type; if stack underflows; or upon
186433d6423SLionel Sambuc      * finding a NULL stack entry (which should not happen).
187433d6423SLionel Sambuc      */
188433d6423SLionel Sambuc     while (GET_CURRENT_ARG_TYPE (ArgTypes))
189433d6423SLionel Sambuc     {
190433d6423SLionel Sambuc         if (!StackPtr || !*StackPtr)
191433d6423SLionel Sambuc         {
192433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Null stack entry at %p",
193433d6423SLionel Sambuc                 StackPtr));
194433d6423SLionel Sambuc 
195433d6423SLionel Sambuc             return_ACPI_STATUS (AE_AML_INTERNAL);
196433d6423SLionel Sambuc         }
197433d6423SLionel Sambuc 
198433d6423SLionel Sambuc         /* Extract useful items */
199433d6423SLionel Sambuc 
200433d6423SLionel Sambuc         ObjDesc = *StackPtr;
201433d6423SLionel Sambuc 
202433d6423SLionel Sambuc         /* Decode the descriptor type */
203433d6423SLionel Sambuc 
204433d6423SLionel Sambuc         switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
205433d6423SLionel Sambuc         {
206433d6423SLionel Sambuc         case ACPI_DESC_TYPE_NAMED:
207433d6423SLionel Sambuc 
208433d6423SLionel Sambuc             /* Namespace Node */
209433d6423SLionel Sambuc 
210433d6423SLionel Sambuc             ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
211433d6423SLionel Sambuc 
212433d6423SLionel Sambuc             /*
213433d6423SLionel Sambuc              * Resolve an alias object. The construction of these objects
214433d6423SLionel Sambuc              * guarantees that there is only one level of alias indirection;
215433d6423SLionel Sambuc              * thus, the attached object is always the aliased namespace node
216433d6423SLionel Sambuc              */
217433d6423SLionel Sambuc             if (ObjectType == ACPI_TYPE_LOCAL_ALIAS)
218433d6423SLionel Sambuc             {
219433d6423SLionel Sambuc                 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
220433d6423SLionel Sambuc                 *StackPtr = ObjDesc;
221433d6423SLionel Sambuc                 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
222433d6423SLionel Sambuc             }
223433d6423SLionel Sambuc             break;
224433d6423SLionel Sambuc 
225433d6423SLionel Sambuc         case ACPI_DESC_TYPE_OPERAND:
226433d6423SLionel Sambuc 
227433d6423SLionel Sambuc             /* ACPI internal object */
228433d6423SLionel Sambuc 
229433d6423SLionel Sambuc             ObjectType = ObjDesc->Common.Type;
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc             /* Check for bad ACPI_OBJECT_TYPE */
232433d6423SLionel Sambuc 
233433d6423SLionel Sambuc             if (!AcpiUtValidObjectType (ObjectType))
234433d6423SLionel Sambuc             {
235433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
236433d6423SLionel Sambuc                     "Bad operand object type [0x%X]", ObjectType));
237433d6423SLionel Sambuc 
238433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
239433d6423SLionel Sambuc             }
240433d6423SLionel Sambuc 
241433d6423SLionel Sambuc             if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
242433d6423SLionel Sambuc             {
243433d6423SLionel Sambuc                 /* Validate the Reference */
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc                 switch (ObjDesc->Reference.Class)
246433d6423SLionel Sambuc                 {
247433d6423SLionel Sambuc                 case ACPI_REFCLASS_DEBUG:
248433d6423SLionel Sambuc 
249433d6423SLionel Sambuc                     TargetOp = AML_DEBUG_OP;
250433d6423SLionel Sambuc 
251433d6423SLionel Sambuc                     /*lint -fallthrough */
252433d6423SLionel Sambuc 
253433d6423SLionel Sambuc                 case ACPI_REFCLASS_ARG:
254433d6423SLionel Sambuc                 case ACPI_REFCLASS_LOCAL:
255433d6423SLionel Sambuc                 case ACPI_REFCLASS_INDEX:
256433d6423SLionel Sambuc                 case ACPI_REFCLASS_REFOF:
257433d6423SLionel Sambuc                 case ACPI_REFCLASS_TABLE:    /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
258433d6423SLionel Sambuc                 case ACPI_REFCLASS_NAME:     /* Reference to a named object */
259433d6423SLionel Sambuc 
260433d6423SLionel Sambuc                     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
261433d6423SLionel Sambuc                         "Operand is a Reference, Class [%s] %2.2X\n",
262433d6423SLionel Sambuc                         AcpiUtGetReferenceName (ObjDesc),
263433d6423SLionel Sambuc                         ObjDesc->Reference.Class));
264433d6423SLionel Sambuc                     break;
265433d6423SLionel Sambuc 
266433d6423SLionel Sambuc                 default:
267433d6423SLionel Sambuc 
268433d6423SLionel Sambuc                     ACPI_ERROR ((AE_INFO,
269433d6423SLionel Sambuc                         "Unknown Reference Class 0x%2.2X in %p",
270433d6423SLionel Sambuc                         ObjDesc->Reference.Class, ObjDesc));
271433d6423SLionel Sambuc 
272433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
273433d6423SLionel Sambuc                 }
274433d6423SLionel Sambuc             }
275433d6423SLionel Sambuc             break;
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc         default:
278433d6423SLionel Sambuc 
279433d6423SLionel Sambuc             /* Invalid descriptor */
280433d6423SLionel Sambuc 
281433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Invalid descriptor %p [%s]",
282433d6423SLionel Sambuc                 ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
283433d6423SLionel Sambuc 
284433d6423SLionel Sambuc             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
285433d6423SLionel Sambuc         }
286433d6423SLionel Sambuc 
287433d6423SLionel Sambuc         /* Get one argument type, point to the next */
288433d6423SLionel Sambuc 
289433d6423SLionel Sambuc         ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
290433d6423SLionel Sambuc         INCREMENT_ARG_LIST (ArgTypes);
291433d6423SLionel Sambuc 
292433d6423SLionel Sambuc         /*
293433d6423SLionel Sambuc          * Handle cases where the object does not need to be
294433d6423SLionel Sambuc          * resolved to a value
295433d6423SLionel Sambuc          */
296433d6423SLionel Sambuc         switch (ThisArgType)
297433d6423SLionel Sambuc         {
298433d6423SLionel Sambuc         case ARGI_REF_OR_STRING:        /* Can be a String or Reference */
299433d6423SLionel Sambuc 
300433d6423SLionel Sambuc             if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
301433d6423SLionel Sambuc                 (ObjDesc->Common.Type == ACPI_TYPE_STRING))
302433d6423SLionel Sambuc             {
303433d6423SLionel Sambuc                 /*
304433d6423SLionel Sambuc                  * String found - the string references a named object and
305433d6423SLionel Sambuc                  * must be resolved to a node
306433d6423SLionel Sambuc                  */
307433d6423SLionel Sambuc                 goto NextOperand;
308433d6423SLionel Sambuc             }
309433d6423SLionel Sambuc 
310433d6423SLionel Sambuc             /*
311433d6423SLionel Sambuc              * Else not a string - fall through to the normal Reference
312433d6423SLionel Sambuc              * case below
313433d6423SLionel Sambuc              */
314433d6423SLionel Sambuc             /*lint -fallthrough */
315433d6423SLionel Sambuc 
316433d6423SLionel Sambuc         case ARGI_REFERENCE:            /* References: */
317433d6423SLionel Sambuc         case ARGI_INTEGER_REF:
318433d6423SLionel Sambuc         case ARGI_OBJECT_REF:
319433d6423SLionel Sambuc         case ARGI_DEVICE_REF:
320433d6423SLionel Sambuc         case ARGI_TARGETREF:     /* Allows implicit conversion rules before store */
321433d6423SLionel Sambuc         case ARGI_FIXED_TARGET:  /* No implicit conversion before store to target */
322433d6423SLionel Sambuc         case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion  */
323433d6423SLionel Sambuc             /*
324433d6423SLionel Sambuc              * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
325433d6423SLionel Sambuc              * A Namespace Node is OK as-is
326433d6423SLionel Sambuc              */
327433d6423SLionel Sambuc             if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
328433d6423SLionel Sambuc             {
329433d6423SLionel Sambuc                 goto NextOperand;
330433d6423SLionel Sambuc             }
331433d6423SLionel Sambuc 
332433d6423SLionel Sambuc             Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
333433d6423SLionel Sambuc                             ObjectType, ObjDesc);
334433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
335433d6423SLionel Sambuc             {
336433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
337433d6423SLionel Sambuc             }
338433d6423SLionel Sambuc             goto NextOperand;
339433d6423SLionel Sambuc 
340433d6423SLionel Sambuc         case ARGI_DATAREFOBJ:  /* Store operator only */
341433d6423SLionel Sambuc             /*
342433d6423SLionel Sambuc              * We don't want to resolve IndexOp reference objects during
343433d6423SLionel Sambuc              * a store because this would be an implicit DeRefOf operation.
344433d6423SLionel Sambuc              * Instead, we just want to store the reference object.
345433d6423SLionel Sambuc              * -- All others must be resolved below.
346433d6423SLionel Sambuc              */
347433d6423SLionel Sambuc             if ((Opcode == AML_STORE_OP) &&
348433d6423SLionel Sambuc                 ((*StackPtr)->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
349433d6423SLionel Sambuc                 ((*StackPtr)->Reference.Class == ACPI_REFCLASS_INDEX))
350433d6423SLionel Sambuc             {
351433d6423SLionel Sambuc                 goto NextOperand;
352433d6423SLionel Sambuc             }
353433d6423SLionel Sambuc             break;
354433d6423SLionel Sambuc 
355433d6423SLionel Sambuc         default:
356*29492bb7SDavid van Moolenbroek 
357433d6423SLionel Sambuc             /* All cases covered above */
358*29492bb7SDavid van Moolenbroek 
359433d6423SLionel Sambuc             break;
360433d6423SLionel Sambuc         }
361433d6423SLionel Sambuc 
362433d6423SLionel Sambuc         /*
363433d6423SLionel Sambuc          * Resolve this object to a value
364433d6423SLionel Sambuc          */
365433d6423SLionel Sambuc         Status = AcpiExResolveToValue (StackPtr, WalkState);
366433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
367433d6423SLionel Sambuc         {
368433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
369433d6423SLionel Sambuc         }
370433d6423SLionel Sambuc 
371433d6423SLionel Sambuc         /* Get the resolved object */
372433d6423SLionel Sambuc 
373433d6423SLionel Sambuc         ObjDesc = *StackPtr;
374433d6423SLionel Sambuc 
375433d6423SLionel Sambuc         /*
376433d6423SLionel Sambuc          * Check the resulting object (value) type
377433d6423SLionel Sambuc          */
378433d6423SLionel Sambuc         switch (ThisArgType)
379433d6423SLionel Sambuc         {
380433d6423SLionel Sambuc         /*
381433d6423SLionel Sambuc          * For the simple cases, only one type of resolved object
382433d6423SLionel Sambuc          * is allowed
383433d6423SLionel Sambuc          */
384433d6423SLionel Sambuc         case ARGI_MUTEX:
385433d6423SLionel Sambuc 
386433d6423SLionel Sambuc             /* Need an operand of type ACPI_TYPE_MUTEX */
387433d6423SLionel Sambuc 
388433d6423SLionel Sambuc             TypeNeeded = ACPI_TYPE_MUTEX;
389433d6423SLionel Sambuc             break;
390433d6423SLionel Sambuc 
391433d6423SLionel Sambuc         case ARGI_EVENT:
392433d6423SLionel Sambuc 
393433d6423SLionel Sambuc             /* Need an operand of type ACPI_TYPE_EVENT */
394433d6423SLionel Sambuc 
395433d6423SLionel Sambuc             TypeNeeded = ACPI_TYPE_EVENT;
396433d6423SLionel Sambuc             break;
397433d6423SLionel Sambuc 
398433d6423SLionel Sambuc         case ARGI_PACKAGE:   /* Package */
399433d6423SLionel Sambuc 
400433d6423SLionel Sambuc             /* Need an operand of type ACPI_TYPE_PACKAGE */
401433d6423SLionel Sambuc 
402433d6423SLionel Sambuc             TypeNeeded = ACPI_TYPE_PACKAGE;
403433d6423SLionel Sambuc             break;
404433d6423SLionel Sambuc 
405433d6423SLionel Sambuc         case ARGI_ANYTYPE:
406433d6423SLionel Sambuc 
407433d6423SLionel Sambuc             /* Any operand type will do */
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc             TypeNeeded = ACPI_TYPE_ANY;
410433d6423SLionel Sambuc             break;
411433d6423SLionel Sambuc 
412433d6423SLionel Sambuc         case ARGI_DDBHANDLE:
413433d6423SLionel Sambuc 
414433d6423SLionel Sambuc             /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
415433d6423SLionel Sambuc 
416433d6423SLionel Sambuc             TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
417433d6423SLionel Sambuc             break;
418433d6423SLionel Sambuc 
419433d6423SLionel Sambuc 
420433d6423SLionel Sambuc         /*
421433d6423SLionel Sambuc          * The more complex cases allow multiple resolved object types
422433d6423SLionel Sambuc          */
423433d6423SLionel Sambuc         case ARGI_INTEGER:
424433d6423SLionel Sambuc 
425433d6423SLionel Sambuc             /*
426433d6423SLionel Sambuc              * Need an operand of type ACPI_TYPE_INTEGER,
427433d6423SLionel Sambuc              * But we can implicitly convert from a STRING or BUFFER
428433d6423SLionel Sambuc              * Aka - "Implicit Source Operand Conversion"
429433d6423SLionel Sambuc              */
430433d6423SLionel Sambuc             Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
431433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
432433d6423SLionel Sambuc             {
433433d6423SLionel Sambuc                 if (Status == AE_TYPE)
434433d6423SLionel Sambuc                 {
435433d6423SLionel Sambuc                     ACPI_ERROR ((AE_INFO,
436433d6423SLionel Sambuc                         "Needed [Integer/String/Buffer], found [%s] %p",
437433d6423SLionel Sambuc                         AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
438433d6423SLionel Sambuc 
439433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
440433d6423SLionel Sambuc                 }
441433d6423SLionel Sambuc 
442433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
443433d6423SLionel Sambuc             }
444433d6423SLionel Sambuc 
445433d6423SLionel Sambuc             if (ObjDesc != *StackPtr)
446433d6423SLionel Sambuc             {
447433d6423SLionel Sambuc                 AcpiUtRemoveReference (ObjDesc);
448433d6423SLionel Sambuc             }
449433d6423SLionel Sambuc             goto NextOperand;
450433d6423SLionel Sambuc 
451433d6423SLionel Sambuc         case ARGI_BUFFER:
452433d6423SLionel Sambuc             /*
453433d6423SLionel Sambuc              * Need an operand of type ACPI_TYPE_BUFFER,
454433d6423SLionel Sambuc              * But we can implicitly convert from a STRING or INTEGER
455433d6423SLionel Sambuc              * Aka - "Implicit Source Operand Conversion"
456433d6423SLionel Sambuc              */
457433d6423SLionel Sambuc             Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
458433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
459433d6423SLionel Sambuc             {
460433d6423SLionel Sambuc                 if (Status == AE_TYPE)
461433d6423SLionel Sambuc                 {
462433d6423SLionel Sambuc                     ACPI_ERROR ((AE_INFO,
463433d6423SLionel Sambuc                         "Needed [Integer/String/Buffer], found [%s] %p",
464433d6423SLionel Sambuc                         AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
465433d6423SLionel Sambuc 
466433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
467433d6423SLionel Sambuc                 }
468433d6423SLionel Sambuc 
469433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
470433d6423SLionel Sambuc             }
471433d6423SLionel Sambuc 
472433d6423SLionel Sambuc             if (ObjDesc != *StackPtr)
473433d6423SLionel Sambuc             {
474433d6423SLionel Sambuc                 AcpiUtRemoveReference (ObjDesc);
475433d6423SLionel Sambuc             }
476433d6423SLionel Sambuc             goto NextOperand;
477433d6423SLionel Sambuc 
478433d6423SLionel Sambuc         case ARGI_STRING:
479433d6423SLionel Sambuc             /*
480433d6423SLionel Sambuc              * Need an operand of type ACPI_TYPE_STRING,
481433d6423SLionel Sambuc              * But we can implicitly convert from a BUFFER or INTEGER
482433d6423SLionel Sambuc              * Aka - "Implicit Source Operand Conversion"
483433d6423SLionel Sambuc              */
484433d6423SLionel Sambuc             Status = AcpiExConvertToString (ObjDesc, StackPtr,
485433d6423SLionel Sambuc                         ACPI_IMPLICIT_CONVERT_HEX);
486433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
487433d6423SLionel Sambuc             {
488433d6423SLionel Sambuc                 if (Status == AE_TYPE)
489433d6423SLionel Sambuc                 {
490433d6423SLionel Sambuc                     ACPI_ERROR ((AE_INFO,
491433d6423SLionel Sambuc                         "Needed [Integer/String/Buffer], found [%s] %p",
492433d6423SLionel Sambuc                         AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
493433d6423SLionel Sambuc 
494433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
495433d6423SLionel Sambuc                 }
496433d6423SLionel Sambuc 
497433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
498433d6423SLionel Sambuc             }
499433d6423SLionel Sambuc 
500433d6423SLionel Sambuc             if (ObjDesc != *StackPtr)
501433d6423SLionel Sambuc             {
502433d6423SLionel Sambuc                 AcpiUtRemoveReference (ObjDesc);
503433d6423SLionel Sambuc             }
504433d6423SLionel Sambuc             goto NextOperand;
505433d6423SLionel Sambuc 
506433d6423SLionel Sambuc         case ARGI_COMPUTEDATA:
507433d6423SLionel Sambuc 
508433d6423SLionel Sambuc             /* Need an operand of type INTEGER, STRING or BUFFER */
509433d6423SLionel Sambuc 
510433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
511433d6423SLionel Sambuc             {
512433d6423SLionel Sambuc             case ACPI_TYPE_INTEGER:
513433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
514433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
515433d6423SLionel Sambuc 
516433d6423SLionel Sambuc                 /* Valid operand */
517433d6423SLionel Sambuc                break;
518433d6423SLionel Sambuc 
519433d6423SLionel Sambuc             default:
520433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
521433d6423SLionel Sambuc                     "Needed [Integer/String/Buffer], found [%s] %p",
522433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
523433d6423SLionel Sambuc 
524433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
525433d6423SLionel Sambuc             }
526433d6423SLionel Sambuc             goto NextOperand;
527433d6423SLionel Sambuc 
528433d6423SLionel Sambuc         case ARGI_BUFFER_OR_STRING:
529433d6423SLionel Sambuc 
530433d6423SLionel Sambuc             /* Need an operand of type STRING or BUFFER */
531433d6423SLionel Sambuc 
532433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
533433d6423SLionel Sambuc             {
534433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
535433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
536433d6423SLionel Sambuc 
537433d6423SLionel Sambuc                 /* Valid operand */
538433d6423SLionel Sambuc                break;
539433d6423SLionel Sambuc 
540433d6423SLionel Sambuc             case ACPI_TYPE_INTEGER:
541433d6423SLionel Sambuc 
542433d6423SLionel Sambuc                 /* Highest priority conversion is to type Buffer */
543433d6423SLionel Sambuc 
544433d6423SLionel Sambuc                 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
545433d6423SLionel Sambuc                 if (ACPI_FAILURE (Status))
546433d6423SLionel Sambuc                 {
547433d6423SLionel Sambuc                     return_ACPI_STATUS (Status);
548433d6423SLionel Sambuc                 }
549433d6423SLionel Sambuc 
550433d6423SLionel Sambuc                 if (ObjDesc != *StackPtr)
551433d6423SLionel Sambuc                 {
552433d6423SLionel Sambuc                     AcpiUtRemoveReference (ObjDesc);
553433d6423SLionel Sambuc                 }
554433d6423SLionel Sambuc                 break;
555433d6423SLionel Sambuc 
556433d6423SLionel Sambuc             default:
557433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
558433d6423SLionel Sambuc                     "Needed [Integer/String/Buffer], found [%s] %p",
559433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
560433d6423SLionel Sambuc 
561433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
562433d6423SLionel Sambuc             }
563433d6423SLionel Sambuc             goto NextOperand;
564433d6423SLionel Sambuc 
565433d6423SLionel Sambuc         case ARGI_DATAOBJECT:
566433d6423SLionel Sambuc             /*
567433d6423SLionel Sambuc              * ARGI_DATAOBJECT is only used by the SizeOf operator.
568433d6423SLionel Sambuc              * Need a buffer, string, package, or RefOf reference.
569433d6423SLionel Sambuc              *
570433d6423SLionel Sambuc              * The only reference allowed here is a direct reference to
571433d6423SLionel Sambuc              * a namespace node.
572433d6423SLionel Sambuc              */
573433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
574433d6423SLionel Sambuc             {
575433d6423SLionel Sambuc             case ACPI_TYPE_PACKAGE:
576433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
577433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
578433d6423SLionel Sambuc             case ACPI_TYPE_LOCAL_REFERENCE:
579433d6423SLionel Sambuc 
580433d6423SLionel Sambuc                 /* Valid operand */
581433d6423SLionel Sambuc                 break;
582433d6423SLionel Sambuc 
583433d6423SLionel Sambuc             default:
584*29492bb7SDavid van Moolenbroek 
585433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
586433d6423SLionel Sambuc                     "Needed [Buffer/String/Package/Reference], found [%s] %p",
587433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
588433d6423SLionel Sambuc 
589433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
590433d6423SLionel Sambuc             }
591433d6423SLionel Sambuc             goto NextOperand;
592433d6423SLionel Sambuc 
593433d6423SLionel Sambuc         case ARGI_COMPLEXOBJ:
594433d6423SLionel Sambuc 
595433d6423SLionel Sambuc             /* Need a buffer or package or (ACPI 2.0) String */
596433d6423SLionel Sambuc 
597433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
598433d6423SLionel Sambuc             {
599433d6423SLionel Sambuc             case ACPI_TYPE_PACKAGE:
600433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
601433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
602433d6423SLionel Sambuc 
603433d6423SLionel Sambuc                 /* Valid operand */
604433d6423SLionel Sambuc                 break;
605433d6423SLionel Sambuc 
606433d6423SLionel Sambuc             default:
607*29492bb7SDavid van Moolenbroek 
608433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
609433d6423SLionel Sambuc                     "Needed [Buffer/String/Package], found [%s] %p",
610433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
611433d6423SLionel Sambuc 
612433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
613433d6423SLionel Sambuc             }
614433d6423SLionel Sambuc             goto NextOperand;
615433d6423SLionel Sambuc 
616433d6423SLionel Sambuc         case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
617433d6423SLionel Sambuc 
618433d6423SLionel Sambuc             /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
619433d6423SLionel Sambuc 
620433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
621433d6423SLionel Sambuc             {
622433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
623433d6423SLionel Sambuc             case ACPI_TYPE_REGION:
624433d6423SLionel Sambuc 
625433d6423SLionel Sambuc                 /* Valid operand */
626433d6423SLionel Sambuc                 break;
627433d6423SLionel Sambuc 
628433d6423SLionel Sambuc             default:
629*29492bb7SDavid van Moolenbroek 
630433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
631433d6423SLionel Sambuc                     "Needed [Region/Buffer], found [%s] %p",
632433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
633433d6423SLionel Sambuc 
634433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
635433d6423SLionel Sambuc             }
636433d6423SLionel Sambuc             goto NextOperand;
637433d6423SLionel Sambuc 
638433d6423SLionel Sambuc         case ARGI_DATAREFOBJ:
639433d6423SLionel Sambuc 
640433d6423SLionel Sambuc             /* Used by the Store() operator only */
641433d6423SLionel Sambuc 
642433d6423SLionel Sambuc             switch (ObjDesc->Common.Type)
643433d6423SLionel Sambuc             {
644433d6423SLionel Sambuc             case ACPI_TYPE_INTEGER:
645433d6423SLionel Sambuc             case ACPI_TYPE_PACKAGE:
646433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
647433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER:
648433d6423SLionel Sambuc             case ACPI_TYPE_BUFFER_FIELD:
649433d6423SLionel Sambuc             case ACPI_TYPE_LOCAL_REFERENCE:
650433d6423SLionel Sambuc             case ACPI_TYPE_LOCAL_REGION_FIELD:
651433d6423SLionel Sambuc             case ACPI_TYPE_LOCAL_BANK_FIELD:
652433d6423SLionel Sambuc             case ACPI_TYPE_LOCAL_INDEX_FIELD:
653433d6423SLionel Sambuc             case ACPI_TYPE_DDB_HANDLE:
654433d6423SLionel Sambuc 
655433d6423SLionel Sambuc                 /* Valid operand */
656433d6423SLionel Sambuc                 break;
657433d6423SLionel Sambuc 
658433d6423SLionel Sambuc             default:
659433d6423SLionel Sambuc 
660433d6423SLionel Sambuc                 if (AcpiGbl_EnableInterpreterSlack)
661433d6423SLionel Sambuc                 {
662433d6423SLionel Sambuc                     /*
663433d6423SLionel Sambuc                      * Enable original behavior of Store(), allowing any and all
664433d6423SLionel Sambuc                      * objects as the source operand. The ACPI spec does not
665433d6423SLionel Sambuc                      * allow this, however.
666433d6423SLionel Sambuc                      */
667433d6423SLionel Sambuc                     break;
668433d6423SLionel Sambuc                 }
669433d6423SLionel Sambuc 
670433d6423SLionel Sambuc                 if (TargetOp == AML_DEBUG_OP)
671433d6423SLionel Sambuc                 {
672433d6423SLionel Sambuc                     /* Allow store of any object to the Debug object */
673433d6423SLionel Sambuc 
674433d6423SLionel Sambuc                     break;
675433d6423SLionel Sambuc                 }
676433d6423SLionel Sambuc 
677433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
678433d6423SLionel Sambuc                     "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
679433d6423SLionel Sambuc                     AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
680433d6423SLionel Sambuc 
681433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
682433d6423SLionel Sambuc             }
683433d6423SLionel Sambuc             goto NextOperand;
684433d6423SLionel Sambuc 
685433d6423SLionel Sambuc         default:
686433d6423SLionel Sambuc 
687433d6423SLionel Sambuc             /* Unknown type */
688433d6423SLionel Sambuc 
689433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
690433d6423SLionel Sambuc                 "Internal - Unknown ARGI (required operand) type 0x%X",
691433d6423SLionel Sambuc                 ThisArgType));
692433d6423SLionel Sambuc 
693433d6423SLionel Sambuc             return_ACPI_STATUS (AE_BAD_PARAMETER);
694433d6423SLionel Sambuc         }
695433d6423SLionel Sambuc 
696433d6423SLionel Sambuc         /*
697433d6423SLionel Sambuc          * Make sure that the original object was resolved to the
698433d6423SLionel Sambuc          * required object type (Simple cases only).
699433d6423SLionel Sambuc          */
700433d6423SLionel Sambuc         Status = AcpiExCheckObjectType (TypeNeeded,
701433d6423SLionel Sambuc                         (*StackPtr)->Common.Type, *StackPtr);
702433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
703433d6423SLionel Sambuc         {
704433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
705433d6423SLionel Sambuc         }
706433d6423SLionel Sambuc 
707433d6423SLionel Sambuc NextOperand:
708433d6423SLionel Sambuc         /*
709433d6423SLionel Sambuc          * If more operands needed, decrement StackPtr to point
710433d6423SLionel Sambuc          * to next operand on stack
711433d6423SLionel Sambuc          */
712433d6423SLionel Sambuc         if (GET_CURRENT_ARG_TYPE (ArgTypes))
713433d6423SLionel Sambuc         {
714433d6423SLionel Sambuc             StackPtr--;
715433d6423SLionel Sambuc         }
716433d6423SLionel Sambuc     }
717433d6423SLionel Sambuc 
718433d6423SLionel Sambuc     ACPI_DUMP_OPERANDS (WalkState->Operands,
719433d6423SLionel Sambuc         AcpiPsGetOpcodeName (Opcode), WalkState->NumOperands);
720433d6423SLionel Sambuc 
721433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
722433d6423SLionel Sambuc }
723