1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: exoparg1 - AML execution - opcodes with 1 argument
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 "acdispat.h"
48433d6423SLionel Sambuc #include "acinterp.h"
49433d6423SLionel Sambuc #include "amlcode.h"
50433d6423SLionel Sambuc #include "acnamesp.h"
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc #define _COMPONENT ACPI_EXECUTER
54433d6423SLionel Sambuc ACPI_MODULE_NAME ("exoparg1")
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc /*!
58433d6423SLionel Sambuc * Naming convention for AML interpreter execution routines.
59433d6423SLionel Sambuc *
60433d6423SLionel Sambuc * The routines that begin execution of AML opcodes are named with a common
61433d6423SLionel Sambuc * convention based upon the number of arguments, the number of target operands,
62433d6423SLionel Sambuc * and whether or not a value is returned:
63433d6423SLionel Sambuc *
64433d6423SLionel Sambuc * AcpiExOpcode_xA_yT_zR
65433d6423SLionel Sambuc *
66433d6423SLionel Sambuc * Where:
67433d6423SLionel Sambuc *
68433d6423SLionel Sambuc * xA - ARGUMENTS: The number of arguments (input operands) that are
69433d6423SLionel Sambuc * required for this opcode type (0 through 6 args).
70433d6423SLionel Sambuc * yT - TARGETS: The number of targets (output operands) that are required
71433d6423SLionel Sambuc * for this opcode type (0, 1, or 2 targets).
72433d6423SLionel Sambuc * zR - RETURN VALUE: Indicates whether this opcode type returns a value
73433d6423SLionel Sambuc * as the function return (0 or 1).
74433d6423SLionel Sambuc *
75433d6423SLionel Sambuc * The AcpiExOpcode* functions are called via the Dispatcher component with
76433d6423SLionel Sambuc * fully resolved operands.
77433d6423SLionel Sambuc !*/
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc /*******************************************************************************
80433d6423SLionel Sambuc *
81433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_0A_0T_1R
82433d6423SLionel Sambuc *
83433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state (contains AML opcode)
84433d6423SLionel Sambuc *
85433d6423SLionel Sambuc * RETURN: Status
86433d6423SLionel Sambuc *
87433d6423SLionel Sambuc * DESCRIPTION: Execute operator with no operands, one return value
88433d6423SLionel Sambuc *
89433d6423SLionel Sambuc ******************************************************************************/
90433d6423SLionel Sambuc
91433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_0A_0T_1R(ACPI_WALK_STATE * WalkState)92433d6423SLionel Sambuc AcpiExOpcode_0A_0T_1R (
93433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
94433d6423SLionel Sambuc {
95433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
96433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc
99433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
100433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
101433d6423SLionel Sambuc
102433d6423SLionel Sambuc
103433d6423SLionel Sambuc /* Examine the AML opcode */
104433d6423SLionel Sambuc
105433d6423SLionel Sambuc switch (WalkState->Opcode)
106433d6423SLionel Sambuc {
107433d6423SLionel Sambuc case AML_TIMER_OP: /* Timer () */
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc /* Create a return object of type Integer */
110433d6423SLionel Sambuc
111433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
112433d6423SLionel Sambuc if (!ReturnDesc)
113433d6423SLionel Sambuc {
114433d6423SLionel Sambuc Status = AE_NO_MEMORY;
115433d6423SLionel Sambuc goto Cleanup;
116433d6423SLionel Sambuc }
117433d6423SLionel Sambuc break;
118433d6423SLionel Sambuc
119433d6423SLionel Sambuc default: /* Unknown opcode */
120433d6423SLionel Sambuc
121433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
122433d6423SLionel Sambuc WalkState->Opcode));
123433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
124433d6423SLionel Sambuc break;
125433d6423SLionel Sambuc }
126433d6423SLionel Sambuc
127433d6423SLionel Sambuc Cleanup:
128433d6423SLionel Sambuc
129433d6423SLionel Sambuc /* Delete return object on error */
130433d6423SLionel Sambuc
131433d6423SLionel Sambuc if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
132433d6423SLionel Sambuc {
133433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc);
134433d6423SLionel Sambuc WalkState->ResultObj = NULL;
135433d6423SLionel Sambuc }
136433d6423SLionel Sambuc else
137433d6423SLionel Sambuc {
138433d6423SLionel Sambuc /* Save the return value */
139433d6423SLionel Sambuc
140433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
141433d6423SLionel Sambuc }
142433d6423SLionel Sambuc
143433d6423SLionel Sambuc return_ACPI_STATUS (Status);
144433d6423SLionel Sambuc }
145433d6423SLionel Sambuc
146433d6423SLionel Sambuc
147433d6423SLionel Sambuc /*******************************************************************************
148433d6423SLionel Sambuc *
149433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_1A_0T_0R
150433d6423SLionel Sambuc *
151433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state (contains AML opcode)
152433d6423SLionel Sambuc *
153433d6423SLionel Sambuc * RETURN: Status
154433d6423SLionel Sambuc *
155433d6423SLionel Sambuc * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
156433d6423SLionel Sambuc * object stack
157433d6423SLionel Sambuc *
158433d6423SLionel Sambuc ******************************************************************************/
159433d6423SLionel Sambuc
160433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_1A_0T_0R(ACPI_WALK_STATE * WalkState)161433d6423SLionel Sambuc AcpiExOpcode_1A_0T_0R (
162433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
163433d6423SLionel Sambuc {
164433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
165433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc
168433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
169433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
170433d6423SLionel Sambuc
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc /* Examine the AML opcode */
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc switch (WalkState->Opcode)
175433d6423SLionel Sambuc {
176433d6423SLionel Sambuc case AML_RELEASE_OP: /* Release (MutexObject) */
177433d6423SLionel Sambuc
178433d6423SLionel Sambuc Status = AcpiExReleaseMutex (Operand[0], WalkState);
179433d6423SLionel Sambuc break;
180433d6423SLionel Sambuc
181433d6423SLionel Sambuc case AML_RESET_OP: /* Reset (EventObject) */
182433d6423SLionel Sambuc
183433d6423SLionel Sambuc Status = AcpiExSystemResetEvent (Operand[0]);
184433d6423SLionel Sambuc break;
185433d6423SLionel Sambuc
186433d6423SLionel Sambuc case AML_SIGNAL_OP: /* Signal (EventObject) */
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc Status = AcpiExSystemSignalEvent (Operand[0]);
189433d6423SLionel Sambuc break;
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc case AML_SLEEP_OP: /* Sleep (MsecTime) */
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
194433d6423SLionel Sambuc break;
195433d6423SLionel Sambuc
196433d6423SLionel Sambuc case AML_STALL_OP: /* Stall (UsecTime) */
197433d6423SLionel Sambuc
198433d6423SLionel Sambuc Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
199433d6423SLionel Sambuc break;
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc case AML_UNLOAD_OP: /* Unload (Handle) */
202433d6423SLionel Sambuc
203433d6423SLionel Sambuc Status = AcpiExUnloadTable (Operand[0]);
204433d6423SLionel Sambuc break;
205433d6423SLionel Sambuc
206433d6423SLionel Sambuc default: /* Unknown opcode */
207433d6423SLionel Sambuc
208433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
209433d6423SLionel Sambuc WalkState->Opcode));
210433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
211433d6423SLionel Sambuc break;
212433d6423SLionel Sambuc }
213433d6423SLionel Sambuc
214433d6423SLionel Sambuc return_ACPI_STATUS (Status);
215433d6423SLionel Sambuc }
216433d6423SLionel Sambuc
217433d6423SLionel Sambuc
218433d6423SLionel Sambuc /*******************************************************************************
219433d6423SLionel Sambuc *
220433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_1A_1T_0R
221433d6423SLionel Sambuc *
222433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state (contains AML opcode)
223433d6423SLionel Sambuc *
224433d6423SLionel Sambuc * RETURN: Status
225433d6423SLionel Sambuc *
226433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with one argument, one target, and no
227433d6423SLionel Sambuc * return value.
228433d6423SLionel Sambuc *
229433d6423SLionel Sambuc ******************************************************************************/
230433d6423SLionel Sambuc
231433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_1A_1T_0R(ACPI_WALK_STATE * WalkState)232433d6423SLionel Sambuc AcpiExOpcode_1A_1T_0R (
233433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
234433d6423SLionel Sambuc {
235433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
236433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
237433d6423SLionel Sambuc
238433d6423SLionel Sambuc
239433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
240433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
241433d6423SLionel Sambuc
242433d6423SLionel Sambuc
243433d6423SLionel Sambuc /* Examine the AML opcode */
244433d6423SLionel Sambuc
245433d6423SLionel Sambuc switch (WalkState->Opcode)
246433d6423SLionel Sambuc {
247433d6423SLionel Sambuc case AML_LOAD_OP:
248433d6423SLionel Sambuc
249433d6423SLionel Sambuc Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
250433d6423SLionel Sambuc break;
251433d6423SLionel Sambuc
252433d6423SLionel Sambuc default: /* Unknown opcode */
253433d6423SLionel Sambuc
254433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
255433d6423SLionel Sambuc WalkState->Opcode));
256433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
257433d6423SLionel Sambuc goto Cleanup;
258433d6423SLionel Sambuc }
259433d6423SLionel Sambuc
260433d6423SLionel Sambuc
261433d6423SLionel Sambuc Cleanup:
262433d6423SLionel Sambuc
263433d6423SLionel Sambuc return_ACPI_STATUS (Status);
264433d6423SLionel Sambuc }
265433d6423SLionel Sambuc
266433d6423SLionel Sambuc
267433d6423SLionel Sambuc /*******************************************************************************
268433d6423SLionel Sambuc *
269433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_1A_1T_1R
270433d6423SLionel Sambuc *
271433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state (contains AML opcode)
272433d6423SLionel Sambuc *
273433d6423SLionel Sambuc * RETURN: Status
274433d6423SLionel Sambuc *
275433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with one argument, one target, and a
276433d6423SLionel Sambuc * return value.
277433d6423SLionel Sambuc *
278433d6423SLionel Sambuc ******************************************************************************/
279433d6423SLionel Sambuc
280433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_1A_1T_1R(ACPI_WALK_STATE * WalkState)281433d6423SLionel Sambuc AcpiExOpcode_1A_1T_1R (
282433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
283433d6423SLionel Sambuc {
284433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
285433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
286433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
287433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
288433d6423SLionel Sambuc UINT32 Temp32;
289433d6423SLionel Sambuc UINT32 i;
290433d6423SLionel Sambuc UINT64 PowerOfTen;
291433d6423SLionel Sambuc UINT64 Digit;
292433d6423SLionel Sambuc
293433d6423SLionel Sambuc
294433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
295433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
296433d6423SLionel Sambuc
297433d6423SLionel Sambuc
298433d6423SLionel Sambuc /* Examine the AML opcode */
299433d6423SLionel Sambuc
300433d6423SLionel Sambuc switch (WalkState->Opcode)
301433d6423SLionel Sambuc {
302433d6423SLionel Sambuc case AML_BIT_NOT_OP:
303433d6423SLionel Sambuc case AML_FIND_SET_LEFT_BIT_OP:
304433d6423SLionel Sambuc case AML_FIND_SET_RIGHT_BIT_OP:
305433d6423SLionel Sambuc case AML_FROM_BCD_OP:
306433d6423SLionel Sambuc case AML_TO_BCD_OP:
307433d6423SLionel Sambuc case AML_COND_REF_OF_OP:
308433d6423SLionel Sambuc
309433d6423SLionel Sambuc /* Create a return object of type Integer for these opcodes */
310433d6423SLionel Sambuc
311433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
312433d6423SLionel Sambuc if (!ReturnDesc)
313433d6423SLionel Sambuc {
314433d6423SLionel Sambuc Status = AE_NO_MEMORY;
315433d6423SLionel Sambuc goto Cleanup;
316433d6423SLionel Sambuc }
317433d6423SLionel Sambuc
318433d6423SLionel Sambuc switch (WalkState->Opcode)
319433d6423SLionel Sambuc {
320433d6423SLionel Sambuc case AML_BIT_NOT_OP: /* Not (Operand, Result) */
321433d6423SLionel Sambuc
322433d6423SLionel Sambuc ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
323433d6423SLionel Sambuc break;
324433d6423SLionel Sambuc
325433d6423SLionel Sambuc case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
326433d6423SLionel Sambuc
327433d6423SLionel Sambuc ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
328433d6423SLionel Sambuc
329433d6423SLionel Sambuc /*
330433d6423SLionel Sambuc * Acpi specification describes Integer type as a little
331433d6423SLionel Sambuc * endian unsigned value, so this boundary condition is valid.
332433d6423SLionel Sambuc */
333433d6423SLionel Sambuc for (Temp32 = 0; ReturnDesc->Integer.Value &&
334433d6423SLionel Sambuc Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
335433d6423SLionel Sambuc {
336433d6423SLionel Sambuc ReturnDesc->Integer.Value >>= 1;
337433d6423SLionel Sambuc }
338433d6423SLionel Sambuc
339433d6423SLionel Sambuc ReturnDesc->Integer.Value = Temp32;
340433d6423SLionel Sambuc break;
341433d6423SLionel Sambuc
342433d6423SLionel Sambuc case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
343433d6423SLionel Sambuc
344433d6423SLionel Sambuc ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
345433d6423SLionel Sambuc
346433d6423SLionel Sambuc /*
347433d6423SLionel Sambuc * The Acpi specification describes Integer type as a little
348433d6423SLionel Sambuc * endian unsigned value, so this boundary condition is valid.
349433d6423SLionel Sambuc */
350433d6423SLionel Sambuc for (Temp32 = 0; ReturnDesc->Integer.Value &&
351433d6423SLionel Sambuc Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
352433d6423SLionel Sambuc {
353433d6423SLionel Sambuc ReturnDesc->Integer.Value <<= 1;
354433d6423SLionel Sambuc }
355433d6423SLionel Sambuc
356433d6423SLionel Sambuc /* Since the bit position is one-based, subtract from 33 (65) */
357433d6423SLionel Sambuc
358433d6423SLionel Sambuc ReturnDesc->Integer.Value =
359433d6423SLionel Sambuc Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
360433d6423SLionel Sambuc break;
361433d6423SLionel Sambuc
362433d6423SLionel Sambuc case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
363433d6423SLionel Sambuc /*
364433d6423SLionel Sambuc * The 64-bit ACPI integer can hold 16 4-bit BCD characters
365433d6423SLionel Sambuc * (if table is 32-bit, integer can hold 8 BCD characters)
366433d6423SLionel Sambuc * Convert each 4-bit BCD value
367433d6423SLionel Sambuc */
368433d6423SLionel Sambuc PowerOfTen = 1;
369433d6423SLionel Sambuc ReturnDesc->Integer.Value = 0;
370433d6423SLionel Sambuc Digit = Operand[0]->Integer.Value;
371433d6423SLionel Sambuc
372433d6423SLionel Sambuc /* Convert each BCD digit (each is one nybble wide) */
373433d6423SLionel Sambuc
374433d6423SLionel Sambuc for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
375433d6423SLionel Sambuc {
376433d6423SLionel Sambuc /* Get the least significant 4-bit BCD digit */
377433d6423SLionel Sambuc
378433d6423SLionel Sambuc Temp32 = ((UINT32) Digit) & 0xF;
379433d6423SLionel Sambuc
380433d6423SLionel Sambuc /* Check the range of the digit */
381433d6423SLionel Sambuc
382433d6423SLionel Sambuc if (Temp32 > 9)
383433d6423SLionel Sambuc {
384433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
385433d6423SLionel Sambuc "BCD digit too large (not decimal): 0x%X",
386433d6423SLionel Sambuc Temp32));
387433d6423SLionel Sambuc
388433d6423SLionel Sambuc Status = AE_AML_NUMERIC_OVERFLOW;
389433d6423SLionel Sambuc goto Cleanup;
390433d6423SLionel Sambuc }
391433d6423SLionel Sambuc
392433d6423SLionel Sambuc /* Sum the digit into the result with the current power of 10 */
393433d6423SLionel Sambuc
394433d6423SLionel Sambuc ReturnDesc->Integer.Value +=
395433d6423SLionel Sambuc (((UINT64) Temp32) * PowerOfTen);
396433d6423SLionel Sambuc
397433d6423SLionel Sambuc /* Shift to next BCD digit */
398433d6423SLionel Sambuc
399433d6423SLionel Sambuc Digit >>= 4;
400433d6423SLionel Sambuc
401433d6423SLionel Sambuc /* Next power of 10 */
402433d6423SLionel Sambuc
403433d6423SLionel Sambuc PowerOfTen *= 10;
404433d6423SLionel Sambuc }
405433d6423SLionel Sambuc break;
406433d6423SLionel Sambuc
407433d6423SLionel Sambuc case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
408433d6423SLionel Sambuc
409433d6423SLionel Sambuc ReturnDesc->Integer.Value = 0;
410433d6423SLionel Sambuc Digit = Operand[0]->Integer.Value;
411433d6423SLionel Sambuc
412433d6423SLionel Sambuc /* Each BCD digit is one nybble wide */
413433d6423SLionel Sambuc
414433d6423SLionel Sambuc for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
415433d6423SLionel Sambuc {
416433d6423SLionel Sambuc (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
417433d6423SLionel Sambuc
418433d6423SLionel Sambuc /*
419433d6423SLionel Sambuc * Insert the BCD digit that resides in the
420433d6423SLionel Sambuc * remainder from above
421433d6423SLionel Sambuc */
422433d6423SLionel Sambuc ReturnDesc->Integer.Value |=
423433d6423SLionel Sambuc (((UINT64) Temp32) << ACPI_MUL_4 (i));
424433d6423SLionel Sambuc }
425433d6423SLionel Sambuc
426433d6423SLionel Sambuc /* Overflow if there is any data left in Digit */
427433d6423SLionel Sambuc
428433d6423SLionel Sambuc if (Digit > 0)
429433d6423SLionel Sambuc {
430433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
431433d6423SLionel Sambuc "Integer too large to convert to BCD: 0x%8.8X%8.8X",
432433d6423SLionel Sambuc ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
433433d6423SLionel Sambuc Status = AE_AML_NUMERIC_OVERFLOW;
434433d6423SLionel Sambuc goto Cleanup;
435433d6423SLionel Sambuc }
436433d6423SLionel Sambuc break;
437433d6423SLionel Sambuc
438433d6423SLionel Sambuc case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
439433d6423SLionel Sambuc /*
440433d6423SLionel Sambuc * This op is a little strange because the internal return value is
441433d6423SLionel Sambuc * different than the return value stored in the result descriptor
442433d6423SLionel Sambuc * (There are really two return values)
443433d6423SLionel Sambuc */
444433d6423SLionel Sambuc if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
445433d6423SLionel Sambuc {
446433d6423SLionel Sambuc /*
447433d6423SLionel Sambuc * This means that the object does not exist in the namespace,
448433d6423SLionel Sambuc * return FALSE
449433d6423SLionel Sambuc */
450433d6423SLionel Sambuc ReturnDesc->Integer.Value = 0;
451433d6423SLionel Sambuc goto Cleanup;
452433d6423SLionel Sambuc }
453433d6423SLionel Sambuc
454433d6423SLionel Sambuc /* Get the object reference, store it, and remove our reference */
455433d6423SLionel Sambuc
456433d6423SLionel Sambuc Status = AcpiExGetObjectReference (Operand[0],
457433d6423SLionel Sambuc &ReturnDesc2, WalkState);
458433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
459433d6423SLionel Sambuc {
460433d6423SLionel Sambuc goto Cleanup;
461433d6423SLionel Sambuc }
462433d6423SLionel Sambuc
463433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
464433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc2);
465433d6423SLionel Sambuc
466433d6423SLionel Sambuc /* The object exists in the namespace, return TRUE */
467433d6423SLionel Sambuc
468433d6423SLionel Sambuc ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
469433d6423SLionel Sambuc goto Cleanup;
470433d6423SLionel Sambuc
471433d6423SLionel Sambuc
472433d6423SLionel Sambuc default:
473*29492bb7SDavid van Moolenbroek
474433d6423SLionel Sambuc /* No other opcodes get here */
475*29492bb7SDavid van Moolenbroek
476433d6423SLionel Sambuc break;
477433d6423SLionel Sambuc }
478433d6423SLionel Sambuc break;
479433d6423SLionel Sambuc
480433d6423SLionel Sambuc case AML_STORE_OP: /* Store (Source, Target) */
481433d6423SLionel Sambuc /*
482433d6423SLionel Sambuc * A store operand is typically a number, string, buffer or lvalue
483433d6423SLionel Sambuc * Be careful about deleting the source object,
484433d6423SLionel Sambuc * since the object itself may have been stored.
485433d6423SLionel Sambuc */
486433d6423SLionel Sambuc Status = AcpiExStore (Operand[0], Operand[1], WalkState);
487433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
488433d6423SLionel Sambuc {
489433d6423SLionel Sambuc return_ACPI_STATUS (Status);
490433d6423SLionel Sambuc }
491433d6423SLionel Sambuc
492433d6423SLionel Sambuc /* It is possible that the Store already produced a return object */
493433d6423SLionel Sambuc
494433d6423SLionel Sambuc if (!WalkState->ResultObj)
495433d6423SLionel Sambuc {
496433d6423SLionel Sambuc /*
497433d6423SLionel Sambuc * Normally, we would remove a reference on the Operand[0]
498433d6423SLionel Sambuc * parameter; But since it is being used as the internal return
499433d6423SLionel Sambuc * object (meaning we would normally increment it), the two
500433d6423SLionel Sambuc * cancel out, and we simply don't do anything.
501433d6423SLionel Sambuc */
502433d6423SLionel Sambuc WalkState->ResultObj = Operand[0];
503433d6423SLionel Sambuc WalkState->Operands[0] = NULL; /* Prevent deletion */
504433d6423SLionel Sambuc }
505433d6423SLionel Sambuc return_ACPI_STATUS (Status);
506433d6423SLionel Sambuc
507433d6423SLionel Sambuc /*
508433d6423SLionel Sambuc * ACPI 2.0 Opcodes
509433d6423SLionel Sambuc */
510433d6423SLionel Sambuc case AML_COPY_OP: /* Copy (Source, Target) */
511433d6423SLionel Sambuc
512433d6423SLionel Sambuc Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc,
513433d6423SLionel Sambuc WalkState);
514433d6423SLionel Sambuc break;
515433d6423SLionel Sambuc
516433d6423SLionel Sambuc case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
517433d6423SLionel Sambuc
518433d6423SLionel Sambuc Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
519433d6423SLionel Sambuc ACPI_EXPLICIT_CONVERT_DECIMAL);
520433d6423SLionel Sambuc if (ReturnDesc == Operand[0])
521433d6423SLionel Sambuc {
522433d6423SLionel Sambuc /* No conversion performed, add ref to handle return value */
523433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
524433d6423SLionel Sambuc }
525433d6423SLionel Sambuc break;
526433d6423SLionel Sambuc
527433d6423SLionel Sambuc case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
528433d6423SLionel Sambuc
529433d6423SLionel Sambuc Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
530433d6423SLionel Sambuc ACPI_EXPLICIT_CONVERT_HEX);
531433d6423SLionel Sambuc if (ReturnDesc == Operand[0])
532433d6423SLionel Sambuc {
533433d6423SLionel Sambuc /* No conversion performed, add ref to handle return value */
534433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
535433d6423SLionel Sambuc }
536433d6423SLionel Sambuc break;
537433d6423SLionel Sambuc
538433d6423SLionel Sambuc case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
539433d6423SLionel Sambuc
540433d6423SLionel Sambuc Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
541433d6423SLionel Sambuc if (ReturnDesc == Operand[0])
542433d6423SLionel Sambuc {
543433d6423SLionel Sambuc /* No conversion performed, add ref to handle return value */
544433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
545433d6423SLionel Sambuc }
546433d6423SLionel Sambuc break;
547433d6423SLionel Sambuc
548433d6423SLionel Sambuc case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
549433d6423SLionel Sambuc
550433d6423SLionel Sambuc Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc,
551433d6423SLionel Sambuc ACPI_ANY_BASE);
552433d6423SLionel Sambuc if (ReturnDesc == Operand[0])
553433d6423SLionel Sambuc {
554433d6423SLionel Sambuc /* No conversion performed, add ref to handle return value */
555433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
556433d6423SLionel Sambuc }
557433d6423SLionel Sambuc break;
558433d6423SLionel Sambuc
559433d6423SLionel Sambuc case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
560433d6423SLionel Sambuc case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
561433d6423SLionel Sambuc
562433d6423SLionel Sambuc /* These are two obsolete opcodes */
563433d6423SLionel Sambuc
564433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
565433d6423SLionel Sambuc "%s is obsolete and not implemented",
566433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode)));
567433d6423SLionel Sambuc Status = AE_SUPPORT;
568433d6423SLionel Sambuc goto Cleanup;
569433d6423SLionel Sambuc
570433d6423SLionel Sambuc default: /* Unknown opcode */
571433d6423SLionel Sambuc
572433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
573433d6423SLionel Sambuc WalkState->Opcode));
574433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
575433d6423SLionel Sambuc goto Cleanup;
576433d6423SLionel Sambuc }
577433d6423SLionel Sambuc
578433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
579433d6423SLionel Sambuc {
580433d6423SLionel Sambuc /* Store the return value computed above into the target object */
581433d6423SLionel Sambuc
582433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
583433d6423SLionel Sambuc }
584433d6423SLionel Sambuc
585433d6423SLionel Sambuc
586433d6423SLionel Sambuc Cleanup:
587433d6423SLionel Sambuc
588433d6423SLionel Sambuc /* Delete return object on error */
589433d6423SLionel Sambuc
590433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
591433d6423SLionel Sambuc {
592433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc);
593433d6423SLionel Sambuc }
594433d6423SLionel Sambuc
595433d6423SLionel Sambuc /* Save return object on success */
596433d6423SLionel Sambuc
597433d6423SLionel Sambuc else if (!WalkState->ResultObj)
598433d6423SLionel Sambuc {
599433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
600433d6423SLionel Sambuc }
601433d6423SLionel Sambuc
602433d6423SLionel Sambuc return_ACPI_STATUS (Status);
603433d6423SLionel Sambuc }
604433d6423SLionel Sambuc
605433d6423SLionel Sambuc
606433d6423SLionel Sambuc /*******************************************************************************
607433d6423SLionel Sambuc *
608433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_1A_0T_1R
609433d6423SLionel Sambuc *
610433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state (contains AML opcode)
611433d6423SLionel Sambuc *
612433d6423SLionel Sambuc * RETURN: Status
613433d6423SLionel Sambuc *
614433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with one argument, no target, and a return value
615433d6423SLionel Sambuc *
616433d6423SLionel Sambuc ******************************************************************************/
617433d6423SLionel Sambuc
618433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_1A_0T_1R(ACPI_WALK_STATE * WalkState)619433d6423SLionel Sambuc AcpiExOpcode_1A_0T_1R (
620433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
621433d6423SLionel Sambuc {
622433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
623433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *TempDesc;
624433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
625433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
626433d6423SLionel Sambuc UINT32 Type;
627433d6423SLionel Sambuc UINT64 Value;
628433d6423SLionel Sambuc
629433d6423SLionel Sambuc
630433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
631433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
632433d6423SLionel Sambuc
633433d6423SLionel Sambuc
634433d6423SLionel Sambuc /* Examine the AML opcode */
635433d6423SLionel Sambuc
636433d6423SLionel Sambuc switch (WalkState->Opcode)
637433d6423SLionel Sambuc {
638433d6423SLionel Sambuc case AML_LNOT_OP: /* LNot (Operand) */
639433d6423SLionel Sambuc
640433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
641433d6423SLionel Sambuc if (!ReturnDesc)
642433d6423SLionel Sambuc {
643433d6423SLionel Sambuc Status = AE_NO_MEMORY;
644433d6423SLionel Sambuc goto Cleanup;
645433d6423SLionel Sambuc }
646433d6423SLionel Sambuc
647433d6423SLionel Sambuc /*
648433d6423SLionel Sambuc * Set result to ONES (TRUE) if Value == 0. Note:
649433d6423SLionel Sambuc * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
650433d6423SLionel Sambuc */
651433d6423SLionel Sambuc if (!Operand[0]->Integer.Value)
652433d6423SLionel Sambuc {
653433d6423SLionel Sambuc ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
654433d6423SLionel Sambuc }
655433d6423SLionel Sambuc break;
656433d6423SLionel Sambuc
657433d6423SLionel Sambuc case AML_DECREMENT_OP: /* Decrement (Operand) */
658433d6423SLionel Sambuc case AML_INCREMENT_OP: /* Increment (Operand) */
659433d6423SLionel Sambuc /*
660433d6423SLionel Sambuc * Create a new integer. Can't just get the base integer and
661433d6423SLionel Sambuc * increment it because it may be an Arg or Field.
662433d6423SLionel Sambuc */
663433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
664433d6423SLionel Sambuc if (!ReturnDesc)
665433d6423SLionel Sambuc {
666433d6423SLionel Sambuc Status = AE_NO_MEMORY;
667433d6423SLionel Sambuc goto Cleanup;
668433d6423SLionel Sambuc }
669433d6423SLionel Sambuc
670433d6423SLionel Sambuc /*
671433d6423SLionel Sambuc * Since we are expecting a Reference operand, it can be either a
672433d6423SLionel Sambuc * NS Node or an internal object.
673433d6423SLionel Sambuc */
674433d6423SLionel Sambuc TempDesc = Operand[0];
675433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
676433d6423SLionel Sambuc {
677433d6423SLionel Sambuc /* Internal reference object - prevent deletion */
678433d6423SLionel Sambuc
679433d6423SLionel Sambuc AcpiUtAddReference (TempDesc);
680433d6423SLionel Sambuc }
681433d6423SLionel Sambuc
682433d6423SLionel Sambuc /*
683433d6423SLionel Sambuc * Convert the Reference operand to an Integer (This removes a
684433d6423SLionel Sambuc * reference on the Operand[0] object)
685433d6423SLionel Sambuc *
686433d6423SLionel Sambuc * NOTE: We use LNOT_OP here in order to force resolution of the
687433d6423SLionel Sambuc * reference operand to an actual integer.
688433d6423SLionel Sambuc */
689433d6423SLionel Sambuc Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
690433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
691433d6423SLionel Sambuc {
692433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
693433d6423SLionel Sambuc "While resolving operands for [%s]",
694433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode)));
695433d6423SLionel Sambuc
696433d6423SLionel Sambuc goto Cleanup;
697433d6423SLionel Sambuc }
698433d6423SLionel Sambuc
699433d6423SLionel Sambuc /*
700433d6423SLionel Sambuc * TempDesc is now guaranteed to be an Integer object --
701433d6423SLionel Sambuc * Perform the actual increment or decrement
702433d6423SLionel Sambuc */
703433d6423SLionel Sambuc if (WalkState->Opcode == AML_INCREMENT_OP)
704433d6423SLionel Sambuc {
705433d6423SLionel Sambuc ReturnDesc->Integer.Value = TempDesc->Integer.Value +1;
706433d6423SLionel Sambuc }
707433d6423SLionel Sambuc else
708433d6423SLionel Sambuc {
709433d6423SLionel Sambuc ReturnDesc->Integer.Value = TempDesc->Integer.Value -1;
710433d6423SLionel Sambuc }
711433d6423SLionel Sambuc
712433d6423SLionel Sambuc /* Finished with this Integer object */
713433d6423SLionel Sambuc
714433d6423SLionel Sambuc AcpiUtRemoveReference (TempDesc);
715433d6423SLionel Sambuc
716433d6423SLionel Sambuc /*
717433d6423SLionel Sambuc * Store the result back (indirectly) through the original
718433d6423SLionel Sambuc * Reference object
719433d6423SLionel Sambuc */
720433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
721433d6423SLionel Sambuc break;
722433d6423SLionel Sambuc
723433d6423SLionel Sambuc case AML_TYPE_OP: /* ObjectType (SourceObject) */
724433d6423SLionel Sambuc /*
725433d6423SLionel Sambuc * Note: The operand is not resolved at this point because we want to
726433d6423SLionel Sambuc * get the associated object, not its value. For example, we don't
727433d6423SLionel Sambuc * want to resolve a FieldUnit to its value, we want the actual
728433d6423SLionel Sambuc * FieldUnit object.
729433d6423SLionel Sambuc */
730433d6423SLionel Sambuc
731433d6423SLionel Sambuc /* Get the type of the base object */
732433d6423SLionel Sambuc
733433d6423SLionel Sambuc Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
734433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
735433d6423SLionel Sambuc {
736433d6423SLionel Sambuc goto Cleanup;
737433d6423SLionel Sambuc }
738433d6423SLionel Sambuc
739433d6423SLionel Sambuc /* Allocate a descriptor to hold the type. */
740433d6423SLionel Sambuc
741433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
742433d6423SLionel Sambuc if (!ReturnDesc)
743433d6423SLionel Sambuc {
744433d6423SLionel Sambuc Status = AE_NO_MEMORY;
745433d6423SLionel Sambuc goto Cleanup;
746433d6423SLionel Sambuc }
747433d6423SLionel Sambuc break;
748433d6423SLionel Sambuc
749433d6423SLionel Sambuc case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
750433d6423SLionel Sambuc /*
751433d6423SLionel Sambuc * Note: The operand is not resolved at this point because we want to
752433d6423SLionel Sambuc * get the associated object, not its value.
753433d6423SLionel Sambuc */
754433d6423SLionel Sambuc
755433d6423SLionel Sambuc /* Get the base object */
756433d6423SLionel Sambuc
757433d6423SLionel Sambuc Status = AcpiExResolveMultiple (WalkState,
758433d6423SLionel Sambuc Operand[0], &Type, &TempDesc);
759433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
760433d6423SLionel Sambuc {
761433d6423SLionel Sambuc goto Cleanup;
762433d6423SLionel Sambuc }
763433d6423SLionel Sambuc
764433d6423SLionel Sambuc /*
765433d6423SLionel Sambuc * The type of the base object must be integer, buffer, string, or
766433d6423SLionel Sambuc * package. All others are not supported.
767433d6423SLionel Sambuc *
768433d6423SLionel Sambuc * NOTE: Integer is not specifically supported by the ACPI spec,
769433d6423SLionel Sambuc * but is supported implicitly via implicit operand conversion.
770433d6423SLionel Sambuc * rather than bother with conversion, we just use the byte width
771433d6423SLionel Sambuc * global (4 or 8 bytes).
772433d6423SLionel Sambuc */
773433d6423SLionel Sambuc switch (Type)
774433d6423SLionel Sambuc {
775433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
776*29492bb7SDavid van Moolenbroek
777433d6423SLionel Sambuc Value = AcpiGbl_IntegerByteWidth;
778433d6423SLionel Sambuc break;
779433d6423SLionel Sambuc
780433d6423SLionel Sambuc case ACPI_TYPE_STRING:
781*29492bb7SDavid van Moolenbroek
782433d6423SLionel Sambuc Value = TempDesc->String.Length;
783433d6423SLionel Sambuc break;
784433d6423SLionel Sambuc
785433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
786433d6423SLionel Sambuc
787433d6423SLionel Sambuc /* Buffer arguments may not be evaluated at this point */
788433d6423SLionel Sambuc
789433d6423SLionel Sambuc Status = AcpiDsGetBufferArguments (TempDesc);
790433d6423SLionel Sambuc Value = TempDesc->Buffer.Length;
791433d6423SLionel Sambuc break;
792433d6423SLionel Sambuc
793433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
794433d6423SLionel Sambuc
795433d6423SLionel Sambuc /* Package arguments may not be evaluated at this point */
796433d6423SLionel Sambuc
797433d6423SLionel Sambuc Status = AcpiDsGetPackageArguments (TempDesc);
798433d6423SLionel Sambuc Value = TempDesc->Package.Count;
799433d6423SLionel Sambuc break;
800433d6423SLionel Sambuc
801433d6423SLionel Sambuc default:
802*29492bb7SDavid van Moolenbroek
803433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
804433d6423SLionel Sambuc "Operand must be Buffer/Integer/String/Package - found type %s",
805433d6423SLionel Sambuc AcpiUtGetTypeName (Type)));
806433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
807433d6423SLionel Sambuc goto Cleanup;
808433d6423SLionel Sambuc }
809433d6423SLionel Sambuc
810433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
811433d6423SLionel Sambuc {
812433d6423SLionel Sambuc goto Cleanup;
813433d6423SLionel Sambuc }
814433d6423SLionel Sambuc
815433d6423SLionel Sambuc /*
816433d6423SLionel Sambuc * Now that we have the size of the object, create a result
817433d6423SLionel Sambuc * object to hold the value
818433d6423SLionel Sambuc */
819433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateIntegerObject (Value);
820433d6423SLionel Sambuc if (!ReturnDesc)
821433d6423SLionel Sambuc {
822433d6423SLionel Sambuc Status = AE_NO_MEMORY;
823433d6423SLionel Sambuc goto Cleanup;
824433d6423SLionel Sambuc }
825433d6423SLionel Sambuc break;
826433d6423SLionel Sambuc
827433d6423SLionel Sambuc
828433d6423SLionel Sambuc case AML_REF_OF_OP: /* RefOf (SourceObject) */
829433d6423SLionel Sambuc
830433d6423SLionel Sambuc Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
831433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
832433d6423SLionel Sambuc {
833433d6423SLionel Sambuc goto Cleanup;
834433d6423SLionel Sambuc }
835433d6423SLionel Sambuc break;
836433d6423SLionel Sambuc
837433d6423SLionel Sambuc
838433d6423SLionel Sambuc case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
839433d6423SLionel Sambuc
840433d6423SLionel Sambuc /* Check for a method local or argument, or standalone String */
841433d6423SLionel Sambuc
842433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
843433d6423SLionel Sambuc {
844433d6423SLionel Sambuc TempDesc = AcpiNsGetAttachedObject (
845433d6423SLionel Sambuc (ACPI_NAMESPACE_NODE *) Operand[0]);
846433d6423SLionel Sambuc if (TempDesc &&
847433d6423SLionel Sambuc ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
848433d6423SLionel Sambuc (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
849433d6423SLionel Sambuc {
850433d6423SLionel Sambuc Operand[0] = TempDesc;
851433d6423SLionel Sambuc AcpiUtAddReference (TempDesc);
852433d6423SLionel Sambuc }
853433d6423SLionel Sambuc else
854433d6423SLionel Sambuc {
855433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
856433d6423SLionel Sambuc goto Cleanup;
857433d6423SLionel Sambuc }
858433d6423SLionel Sambuc }
859433d6423SLionel Sambuc else
860433d6423SLionel Sambuc {
861433d6423SLionel Sambuc switch ((Operand[0])->Common.Type)
862433d6423SLionel Sambuc {
863433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_REFERENCE:
864433d6423SLionel Sambuc /*
865433d6423SLionel Sambuc * This is a DerefOf (LocalX | ArgX)
866433d6423SLionel Sambuc *
867433d6423SLionel Sambuc * Must resolve/dereference the local/arg reference first
868433d6423SLionel Sambuc */
869433d6423SLionel Sambuc switch (Operand[0]->Reference.Class)
870433d6423SLionel Sambuc {
871433d6423SLionel Sambuc case ACPI_REFCLASS_LOCAL:
872433d6423SLionel Sambuc case ACPI_REFCLASS_ARG:
873433d6423SLionel Sambuc
874433d6423SLionel Sambuc /* Set Operand[0] to the value of the local/arg */
875433d6423SLionel Sambuc
876433d6423SLionel Sambuc Status = AcpiDsMethodDataGetValue (
877433d6423SLionel Sambuc Operand[0]->Reference.Class,
878433d6423SLionel Sambuc Operand[0]->Reference.Value,
879433d6423SLionel Sambuc WalkState, &TempDesc);
880433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
881433d6423SLionel Sambuc {
882433d6423SLionel Sambuc goto Cleanup;
883433d6423SLionel Sambuc }
884433d6423SLionel Sambuc
885433d6423SLionel Sambuc /*
886433d6423SLionel Sambuc * Delete our reference to the input object and
887433d6423SLionel Sambuc * point to the object just retrieved
888433d6423SLionel Sambuc */
889433d6423SLionel Sambuc AcpiUtRemoveReference (Operand[0]);
890433d6423SLionel Sambuc Operand[0] = TempDesc;
891433d6423SLionel Sambuc break;
892433d6423SLionel Sambuc
893433d6423SLionel Sambuc case ACPI_REFCLASS_REFOF:
894433d6423SLionel Sambuc
895433d6423SLionel Sambuc /* Get the object to which the reference refers */
896433d6423SLionel Sambuc
897433d6423SLionel Sambuc TempDesc = Operand[0]->Reference.Object;
898433d6423SLionel Sambuc AcpiUtRemoveReference (Operand[0]);
899433d6423SLionel Sambuc Operand[0] = TempDesc;
900433d6423SLionel Sambuc break;
901433d6423SLionel Sambuc
902433d6423SLionel Sambuc default:
903433d6423SLionel Sambuc
904433d6423SLionel Sambuc /* Must be an Index op - handled below */
905433d6423SLionel Sambuc break;
906433d6423SLionel Sambuc }
907433d6423SLionel Sambuc break;
908433d6423SLionel Sambuc
909433d6423SLionel Sambuc case ACPI_TYPE_STRING:
910*29492bb7SDavid van Moolenbroek
911433d6423SLionel Sambuc break;
912433d6423SLionel Sambuc
913433d6423SLionel Sambuc default:
914*29492bb7SDavid van Moolenbroek
915433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
916433d6423SLionel Sambuc goto Cleanup;
917433d6423SLionel Sambuc }
918433d6423SLionel Sambuc }
919433d6423SLionel Sambuc
920433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
921433d6423SLionel Sambuc {
922433d6423SLionel Sambuc if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
923433d6423SLionel Sambuc {
924433d6423SLionel Sambuc /*
925433d6423SLionel Sambuc * This is a DerefOf (String). The string is a reference
926433d6423SLionel Sambuc * to a named ACPI object.
927433d6423SLionel Sambuc *
928433d6423SLionel Sambuc * 1) Find the owning Node
929433d6423SLionel Sambuc * 2) Dereference the node to an actual object. Could be a
930433d6423SLionel Sambuc * Field, so we need to resolve the node to a value.
931433d6423SLionel Sambuc */
932433d6423SLionel Sambuc Status = AcpiNsGetNode (WalkState->ScopeInfo->Scope.Node,
933433d6423SLionel Sambuc Operand[0]->String.Pointer,
934433d6423SLionel Sambuc ACPI_NS_SEARCH_PARENT,
935433d6423SLionel Sambuc ACPI_CAST_INDIRECT_PTR (
936433d6423SLionel Sambuc ACPI_NAMESPACE_NODE, &ReturnDesc));
937433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
938433d6423SLionel Sambuc {
939433d6423SLionel Sambuc goto Cleanup;
940433d6423SLionel Sambuc }
941433d6423SLionel Sambuc
942433d6423SLionel Sambuc Status = AcpiExResolveNodeToValue (
943433d6423SLionel Sambuc ACPI_CAST_INDIRECT_PTR (
944433d6423SLionel Sambuc ACPI_NAMESPACE_NODE, &ReturnDesc),
945433d6423SLionel Sambuc WalkState);
946433d6423SLionel Sambuc goto Cleanup;
947433d6423SLionel Sambuc }
948433d6423SLionel Sambuc }
949433d6423SLionel Sambuc
950433d6423SLionel Sambuc /* Operand[0] may have changed from the code above */
951433d6423SLionel Sambuc
952433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
953433d6423SLionel Sambuc {
954433d6423SLionel Sambuc /*
955433d6423SLionel Sambuc * This is a DerefOf (ObjectReference)
956433d6423SLionel Sambuc * Get the actual object from the Node (This is the dereference).
957433d6423SLionel Sambuc * This case may only happen when a LocalX or ArgX is
958433d6423SLionel Sambuc * dereferenced above.
959433d6423SLionel Sambuc */
960433d6423SLionel Sambuc ReturnDesc = AcpiNsGetAttachedObject (
961433d6423SLionel Sambuc (ACPI_NAMESPACE_NODE *) Operand[0]);
962433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
963433d6423SLionel Sambuc }
964433d6423SLionel Sambuc else
965433d6423SLionel Sambuc {
966433d6423SLionel Sambuc /*
967433d6423SLionel Sambuc * This must be a reference object produced by either the
968433d6423SLionel Sambuc * Index() or RefOf() operator
969433d6423SLionel Sambuc */
970433d6423SLionel Sambuc switch (Operand[0]->Reference.Class)
971433d6423SLionel Sambuc {
972433d6423SLionel Sambuc case ACPI_REFCLASS_INDEX:
973433d6423SLionel Sambuc /*
974433d6423SLionel Sambuc * The target type for the Index operator must be
975433d6423SLionel Sambuc * either a Buffer or a Package
976433d6423SLionel Sambuc */
977433d6423SLionel Sambuc switch (Operand[0]->Reference.TargetType)
978433d6423SLionel Sambuc {
979433d6423SLionel Sambuc case ACPI_TYPE_BUFFER_FIELD:
980433d6423SLionel Sambuc
981433d6423SLionel Sambuc TempDesc = Operand[0]->Reference.Object;
982433d6423SLionel Sambuc
983433d6423SLionel Sambuc /*
984433d6423SLionel Sambuc * Create a new object that contains one element of the
985433d6423SLionel Sambuc * buffer -- the element pointed to by the index.
986433d6423SLionel Sambuc *
987433d6423SLionel Sambuc * NOTE: index into a buffer is NOT a pointer to a
988433d6423SLionel Sambuc * sub-buffer of the main buffer, it is only a pointer to a
989433d6423SLionel Sambuc * single element (byte) of the buffer!
990433d6423SLionel Sambuc *
991433d6423SLionel Sambuc * Since we are returning the value of the buffer at the
992433d6423SLionel Sambuc * indexed location, we don't need to add an additional
993433d6423SLionel Sambuc * reference to the buffer itself.
994433d6423SLionel Sambuc */
995433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
996433d6423SLionel Sambuc TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
997433d6423SLionel Sambuc if (!ReturnDesc)
998433d6423SLionel Sambuc {
999433d6423SLionel Sambuc Status = AE_NO_MEMORY;
1000433d6423SLionel Sambuc goto Cleanup;
1001433d6423SLionel Sambuc }
1002433d6423SLionel Sambuc break;
1003433d6423SLionel Sambuc
1004433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
1005433d6423SLionel Sambuc /*
1006433d6423SLionel Sambuc * Return the referenced element of the package. We must
1007433d6423SLionel Sambuc * add another reference to the referenced object, however.
1008433d6423SLionel Sambuc */
1009433d6423SLionel Sambuc ReturnDesc = *(Operand[0]->Reference.Where);
1010*29492bb7SDavid van Moolenbroek if (!ReturnDesc)
1011433d6423SLionel Sambuc {
1012*29492bb7SDavid van Moolenbroek /*
1013*29492bb7SDavid van Moolenbroek * Element is NULL, do not allow the dereference.
1014*29492bb7SDavid van Moolenbroek * This provides compatibility with other ACPI
1015*29492bb7SDavid van Moolenbroek * implementations.
1016*29492bb7SDavid van Moolenbroek */
1017*29492bb7SDavid van Moolenbroek return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1018433d6423SLionel Sambuc }
1019433d6423SLionel Sambuc
1020*29492bb7SDavid van Moolenbroek AcpiUtAddReference (ReturnDesc);
1021*29492bb7SDavid van Moolenbroek break;
1022433d6423SLionel Sambuc
1023433d6423SLionel Sambuc default:
1024433d6423SLionel Sambuc
1025433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
1026433d6423SLionel Sambuc "Unknown Index TargetType 0x%X in reference object %p",
1027433d6423SLionel Sambuc Operand[0]->Reference.TargetType, Operand[0]));
1028433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
1029433d6423SLionel Sambuc goto Cleanup;
1030433d6423SLionel Sambuc }
1031433d6423SLionel Sambuc break;
1032433d6423SLionel Sambuc
1033433d6423SLionel Sambuc case ACPI_REFCLASS_REFOF:
1034433d6423SLionel Sambuc
1035433d6423SLionel Sambuc ReturnDesc = Operand[0]->Reference.Object;
1036433d6423SLionel Sambuc
1037433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1038433d6423SLionel Sambuc ACPI_DESC_TYPE_NAMED)
1039433d6423SLionel Sambuc {
1040433d6423SLionel Sambuc ReturnDesc = AcpiNsGetAttachedObject (
1041433d6423SLionel Sambuc (ACPI_NAMESPACE_NODE *) ReturnDesc);
1042*29492bb7SDavid van Moolenbroek if (!ReturnDesc)
1043*29492bb7SDavid van Moolenbroek {
1044*29492bb7SDavid van Moolenbroek break;
1045433d6423SLionel Sambuc }
1046433d6423SLionel Sambuc
1047*29492bb7SDavid van Moolenbroek /*
1048*29492bb7SDavid van Moolenbroek * June 2013:
1049*29492bb7SDavid van Moolenbroek * BufferFields/FieldUnits require additional resolution
1050*29492bb7SDavid van Moolenbroek */
1051*29492bb7SDavid van Moolenbroek switch (ReturnDesc->Common.Type)
1052*29492bb7SDavid van Moolenbroek {
1053*29492bb7SDavid van Moolenbroek case ACPI_TYPE_BUFFER_FIELD:
1054*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_REGION_FIELD:
1055*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_BANK_FIELD:
1056*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_INDEX_FIELD:
1057*29492bb7SDavid van Moolenbroek
1058*29492bb7SDavid van Moolenbroek Status = AcpiExReadDataFromField (WalkState,
1059*29492bb7SDavid van Moolenbroek ReturnDesc, &TempDesc);
1060*29492bb7SDavid van Moolenbroek if (ACPI_FAILURE (Status))
1061*29492bb7SDavid van Moolenbroek {
1062*29492bb7SDavid van Moolenbroek goto Cleanup;
1063*29492bb7SDavid van Moolenbroek }
1064*29492bb7SDavid van Moolenbroek
1065*29492bb7SDavid van Moolenbroek ReturnDesc = TempDesc;
1066*29492bb7SDavid van Moolenbroek break;
1067*29492bb7SDavid van Moolenbroek
1068*29492bb7SDavid van Moolenbroek default:
1069*29492bb7SDavid van Moolenbroek
1070*29492bb7SDavid van Moolenbroek /* Add another reference to the object */
1071433d6423SLionel Sambuc
1072433d6423SLionel Sambuc AcpiUtAddReference (ReturnDesc);
1073433d6423SLionel Sambuc break;
1074*29492bb7SDavid van Moolenbroek }
1075*29492bb7SDavid van Moolenbroek }
1076*29492bb7SDavid van Moolenbroek break;
1077433d6423SLionel Sambuc
1078433d6423SLionel Sambuc default:
1079*29492bb7SDavid van Moolenbroek
1080433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
1081433d6423SLionel Sambuc "Unknown class in reference(%p) - 0x%2.2X",
1082433d6423SLionel Sambuc Operand[0], Operand[0]->Reference.Class));
1083433d6423SLionel Sambuc
1084433d6423SLionel Sambuc Status = AE_TYPE;
1085433d6423SLionel Sambuc goto Cleanup;
1086433d6423SLionel Sambuc }
1087433d6423SLionel Sambuc }
1088433d6423SLionel Sambuc break;
1089433d6423SLionel Sambuc
1090433d6423SLionel Sambuc default:
1091433d6423SLionel Sambuc
1092433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1093433d6423SLionel Sambuc WalkState->Opcode));
1094433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
1095433d6423SLionel Sambuc goto Cleanup;
1096433d6423SLionel Sambuc }
1097433d6423SLionel Sambuc
1098433d6423SLionel Sambuc
1099433d6423SLionel Sambuc Cleanup:
1100433d6423SLionel Sambuc
1101433d6423SLionel Sambuc /* Delete return object on error */
1102433d6423SLionel Sambuc
1103433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
1104433d6423SLionel Sambuc {
1105433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc);
1106433d6423SLionel Sambuc }
1107433d6423SLionel Sambuc
1108433d6423SLionel Sambuc /* Save return object on success */
1109433d6423SLionel Sambuc
1110433d6423SLionel Sambuc else
1111433d6423SLionel Sambuc {
1112433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
1113433d6423SLionel Sambuc }
1114433d6423SLionel Sambuc
1115433d6423SLionel Sambuc return_ACPI_STATUS (Status);
1116433d6423SLionel Sambuc }
1117