1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
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 "acinterp.h"
48433d6423SLionel Sambuc #include "acevents.h"
49433d6423SLionel Sambuc #include "amlcode.h"
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc #define _COMPONENT ACPI_EXECUTER
53433d6423SLionel Sambuc ACPI_MODULE_NAME ("exoparg2")
54433d6423SLionel Sambuc
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc /*!
57433d6423SLionel Sambuc * Naming convention for AML interpreter execution routines.
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * The routines that begin execution of AML opcodes are named with a common
60433d6423SLionel Sambuc * convention based upon the number of arguments, the number of target operands,
61433d6423SLionel Sambuc * and whether or not a value is returned:
62433d6423SLionel Sambuc *
63433d6423SLionel Sambuc * AcpiExOpcode_xA_yT_zR
64433d6423SLionel Sambuc *
65433d6423SLionel Sambuc * Where:
66433d6423SLionel Sambuc *
67433d6423SLionel Sambuc * xA - ARGUMENTS: The number of arguments (input operands) that are
68433d6423SLionel Sambuc * required for this opcode type (1 through 6 args).
69433d6423SLionel Sambuc * yT - TARGETS: The number of targets (output operands) that are required
70433d6423SLionel Sambuc * for this opcode type (0, 1, or 2 targets).
71433d6423SLionel Sambuc * zR - RETURN VALUE: Indicates whether this opcode type returns a value
72433d6423SLionel Sambuc * as the function return (0 or 1).
73433d6423SLionel Sambuc *
74433d6423SLionel Sambuc * The AcpiExOpcode* functions are called via the Dispatcher component with
75433d6423SLionel Sambuc * fully resolved operands.
76433d6423SLionel Sambuc !*/
77433d6423SLionel Sambuc
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc /*******************************************************************************
80433d6423SLionel Sambuc *
81433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_2A_0T_0R
82433d6423SLionel Sambuc *
83433d6423SLionel Sambuc * PARAMETERS: WalkState - Current walk state
84433d6423SLionel Sambuc *
85433d6423SLionel Sambuc * RETURN: Status
86433d6423SLionel Sambuc *
87433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with two arguments, no target, and no return
88433d6423SLionel Sambuc * value.
89433d6423SLionel Sambuc *
90433d6423SLionel Sambuc * ALLOCATION: Deletes both operands
91433d6423SLionel Sambuc *
92433d6423SLionel Sambuc ******************************************************************************/
93433d6423SLionel Sambuc
94433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_2A_0T_0R(ACPI_WALK_STATE * WalkState)95433d6423SLionel Sambuc AcpiExOpcode_2A_0T_0R (
96433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
97433d6423SLionel Sambuc {
98433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
99433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
100433d6423SLionel Sambuc UINT32 Value;
101433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
102433d6423SLionel Sambuc
103433d6423SLionel Sambuc
104433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
105433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
106433d6423SLionel Sambuc
107433d6423SLionel Sambuc
108433d6423SLionel Sambuc /* Examine the opcode */
109433d6423SLionel Sambuc
110433d6423SLionel Sambuc switch (WalkState->Opcode)
111433d6423SLionel Sambuc {
112433d6423SLionel Sambuc case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
113433d6423SLionel Sambuc
114433d6423SLionel Sambuc /* The first operand is a namespace node */
115433d6423SLionel Sambuc
116433d6423SLionel Sambuc Node = (ACPI_NAMESPACE_NODE *) Operand[0];
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc /* Second value is the notify value */
119433d6423SLionel Sambuc
120433d6423SLionel Sambuc Value = (UINT32) Operand[1]->Integer.Value;
121433d6423SLionel Sambuc
122433d6423SLionel Sambuc /* Are notifies allowed on this object? */
123433d6423SLionel Sambuc
124433d6423SLionel Sambuc if (!AcpiEvIsNotifyObject (Node))
125433d6423SLionel Sambuc {
126433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
127433d6423SLionel Sambuc "Unexpected notify object type [%s]",
128433d6423SLionel Sambuc AcpiUtGetTypeName (Node->Type)));
129433d6423SLionel Sambuc
130433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
131433d6423SLionel Sambuc break;
132433d6423SLionel Sambuc }
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc /*
135433d6423SLionel Sambuc * Dispatch the notify to the appropriate handler
136433d6423SLionel Sambuc * NOTE: the request is queued for execution after this method
137433d6423SLionel Sambuc * completes. The notify handlers are NOT invoked synchronously
138433d6423SLionel Sambuc * from this thread -- because handlers may in turn run other
139433d6423SLionel Sambuc * control methods.
140433d6423SLionel Sambuc */
141433d6423SLionel Sambuc Status = AcpiEvQueueNotifyRequest (Node, Value);
142433d6423SLionel Sambuc break;
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc default:
145433d6423SLionel Sambuc
146433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
147433d6423SLionel Sambuc WalkState->Opcode));
148433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
149433d6423SLionel Sambuc }
150433d6423SLionel Sambuc
151433d6423SLionel Sambuc return_ACPI_STATUS (Status);
152433d6423SLionel Sambuc }
153433d6423SLionel Sambuc
154433d6423SLionel Sambuc
155433d6423SLionel Sambuc /*******************************************************************************
156433d6423SLionel Sambuc *
157433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_2A_2T_1R
158433d6423SLionel Sambuc *
159433d6423SLionel Sambuc * PARAMETERS: WalkState - Current walk state
160433d6423SLionel Sambuc *
161433d6423SLionel Sambuc * RETURN: Status
162433d6423SLionel Sambuc *
163433d6423SLionel Sambuc * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
164433d6423SLionel Sambuc * and one implicit return value.
165433d6423SLionel Sambuc *
166433d6423SLionel Sambuc ******************************************************************************/
167433d6423SLionel Sambuc
168433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_2A_2T_1R(ACPI_WALK_STATE * WalkState)169433d6423SLionel Sambuc AcpiExOpcode_2A_2T_1R (
170433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
171433d6423SLionel Sambuc {
172433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
173433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
174433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
175433d6423SLionel Sambuc ACPI_STATUS Status;
176433d6423SLionel Sambuc
177433d6423SLionel Sambuc
178433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
179433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
180433d6423SLionel Sambuc
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc /* Execute the opcode */
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc switch (WalkState->Opcode)
185433d6423SLionel Sambuc {
186433d6423SLionel Sambuc case AML_DIVIDE_OP:
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
189433d6423SLionel Sambuc
190433d6423SLionel Sambuc ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
191433d6423SLionel Sambuc if (!ReturnDesc1)
192433d6423SLionel Sambuc {
193433d6423SLionel Sambuc Status = AE_NO_MEMORY;
194433d6423SLionel Sambuc goto Cleanup;
195433d6423SLionel Sambuc }
196433d6423SLionel Sambuc
197433d6423SLionel Sambuc ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
198433d6423SLionel Sambuc if (!ReturnDesc2)
199433d6423SLionel Sambuc {
200433d6423SLionel Sambuc Status = AE_NO_MEMORY;
201433d6423SLionel Sambuc goto Cleanup;
202433d6423SLionel Sambuc }
203433d6423SLionel Sambuc
204433d6423SLionel Sambuc /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
205433d6423SLionel Sambuc
206433d6423SLionel Sambuc Status = AcpiUtDivide (Operand[0]->Integer.Value,
207433d6423SLionel Sambuc Operand[1]->Integer.Value,
208433d6423SLionel Sambuc &ReturnDesc1->Integer.Value,
209433d6423SLionel Sambuc &ReturnDesc2->Integer.Value);
210433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
211433d6423SLionel Sambuc {
212433d6423SLionel Sambuc goto Cleanup;
213433d6423SLionel Sambuc }
214433d6423SLionel Sambuc break;
215433d6423SLionel Sambuc
216433d6423SLionel Sambuc default:
217433d6423SLionel Sambuc
218433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
219433d6423SLionel Sambuc WalkState->Opcode));
220433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
221433d6423SLionel Sambuc goto Cleanup;
222433d6423SLionel Sambuc }
223433d6423SLionel Sambuc
224433d6423SLionel Sambuc /* Store the results to the target reference operands */
225433d6423SLionel Sambuc
226433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
227433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
228433d6423SLionel Sambuc {
229433d6423SLionel Sambuc goto Cleanup;
230433d6423SLionel Sambuc }
231433d6423SLionel Sambuc
232433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
233433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
234433d6423SLionel Sambuc {
235433d6423SLionel Sambuc goto Cleanup;
236433d6423SLionel Sambuc }
237433d6423SLionel Sambuc
238433d6423SLionel Sambuc Cleanup:
239433d6423SLionel Sambuc /*
240433d6423SLionel Sambuc * Since the remainder is not returned indirectly, remove a reference to
241433d6423SLionel Sambuc * it. Only the quotient is returned indirectly.
242433d6423SLionel Sambuc */
243433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc2);
244433d6423SLionel Sambuc
245433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
246433d6423SLionel Sambuc {
247433d6423SLionel Sambuc /* Delete the return object */
248433d6423SLionel Sambuc
249433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc1);
250433d6423SLionel Sambuc }
251433d6423SLionel Sambuc
252433d6423SLionel Sambuc /* Save return object (the remainder) on success */
253433d6423SLionel Sambuc
254433d6423SLionel Sambuc else
255433d6423SLionel Sambuc {
256433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc1;
257433d6423SLionel Sambuc }
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc return_ACPI_STATUS (Status);
260433d6423SLionel Sambuc }
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc
263433d6423SLionel Sambuc /*******************************************************************************
264433d6423SLionel Sambuc *
265433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_2A_1T_1R
266433d6423SLionel Sambuc *
267433d6423SLionel Sambuc * PARAMETERS: WalkState - Current walk state
268433d6423SLionel Sambuc *
269433d6423SLionel Sambuc * RETURN: Status
270433d6423SLionel Sambuc *
271433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with two arguments, one target, and a return
272433d6423SLionel Sambuc * value.
273433d6423SLionel Sambuc *
274433d6423SLionel Sambuc ******************************************************************************/
275433d6423SLionel Sambuc
276433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_2A_1T_1R(ACPI_WALK_STATE * WalkState)277433d6423SLionel Sambuc AcpiExOpcode_2A_1T_1R (
278433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
279433d6423SLionel Sambuc {
280433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
281433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
282433d6423SLionel Sambuc UINT64 Index;
283433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
284*29492bb7SDavid van Moolenbroek ACPI_SIZE Length = 0;
285433d6423SLionel Sambuc
286433d6423SLionel Sambuc
287433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
288433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc
291433d6423SLionel Sambuc /* Execute the opcode */
292433d6423SLionel Sambuc
293433d6423SLionel Sambuc if (WalkState->OpInfo->Flags & AML_MATH)
294433d6423SLionel Sambuc {
295433d6423SLionel Sambuc /* All simple math opcodes (add, etc.) */
296433d6423SLionel Sambuc
297433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
298433d6423SLionel Sambuc if (!ReturnDesc)
299433d6423SLionel Sambuc {
300433d6423SLionel Sambuc Status = AE_NO_MEMORY;
301433d6423SLionel Sambuc goto Cleanup;
302433d6423SLionel Sambuc }
303433d6423SLionel Sambuc
304433d6423SLionel Sambuc ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
305433d6423SLionel Sambuc Operand[0]->Integer.Value,
306433d6423SLionel Sambuc Operand[1]->Integer.Value);
307433d6423SLionel Sambuc goto StoreResultToTarget;
308433d6423SLionel Sambuc }
309433d6423SLionel Sambuc
310433d6423SLionel Sambuc switch (WalkState->Opcode)
311433d6423SLionel Sambuc {
312433d6423SLionel Sambuc case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
313433d6423SLionel Sambuc
314433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
315433d6423SLionel Sambuc if (!ReturnDesc)
316433d6423SLionel Sambuc {
317433d6423SLionel Sambuc Status = AE_NO_MEMORY;
318433d6423SLionel Sambuc goto Cleanup;
319433d6423SLionel Sambuc }
320433d6423SLionel Sambuc
321433d6423SLionel Sambuc /* ReturnDesc will contain the remainder */
322433d6423SLionel Sambuc
323433d6423SLionel Sambuc Status = AcpiUtDivide (Operand[0]->Integer.Value,
324433d6423SLionel Sambuc Operand[1]->Integer.Value,
325433d6423SLionel Sambuc NULL,
326433d6423SLionel Sambuc &ReturnDesc->Integer.Value);
327433d6423SLionel Sambuc break;
328433d6423SLionel Sambuc
329433d6423SLionel Sambuc case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
330433d6423SLionel Sambuc
331433d6423SLionel Sambuc Status = AcpiExDoConcatenate (Operand[0], Operand[1],
332433d6423SLionel Sambuc &ReturnDesc, WalkState);
333433d6423SLionel Sambuc break;
334433d6423SLionel Sambuc
335433d6423SLionel Sambuc case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
336433d6423SLionel Sambuc /*
337433d6423SLionel Sambuc * Input object is guaranteed to be a buffer at this point (it may have
338433d6423SLionel Sambuc * been converted.) Copy the raw buffer data to a new object of
339433d6423SLionel Sambuc * type String.
340433d6423SLionel Sambuc */
341433d6423SLionel Sambuc
342433d6423SLionel Sambuc /*
343433d6423SLionel Sambuc * Get the length of the new string. It is the smallest of:
344433d6423SLionel Sambuc * 1) Length of the input buffer
345433d6423SLionel Sambuc * 2) Max length as specified in the ToString operator
346433d6423SLionel Sambuc * 3) Length of input buffer up to a zero byte (null terminator)
347433d6423SLionel Sambuc *
348433d6423SLionel Sambuc * NOTE: A length of zero is ok, and will create a zero-length, null
349433d6423SLionel Sambuc * terminated string.
350433d6423SLionel Sambuc */
351433d6423SLionel Sambuc while ((Length < Operand[0]->Buffer.Length) &&
352433d6423SLionel Sambuc (Length < Operand[1]->Integer.Value) &&
353433d6423SLionel Sambuc (Operand[0]->Buffer.Pointer[Length]))
354433d6423SLionel Sambuc {
355433d6423SLionel Sambuc Length++;
356433d6423SLionel Sambuc }
357433d6423SLionel Sambuc
358433d6423SLionel Sambuc /* Allocate a new string object */
359433d6423SLionel Sambuc
360433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateStringObject (Length);
361433d6423SLionel Sambuc if (!ReturnDesc)
362433d6423SLionel Sambuc {
363433d6423SLionel Sambuc Status = AE_NO_MEMORY;
364433d6423SLionel Sambuc goto Cleanup;
365433d6423SLionel Sambuc }
366433d6423SLionel Sambuc
367433d6423SLionel Sambuc /*
368433d6423SLionel Sambuc * Copy the raw buffer data with no transform.
369433d6423SLionel Sambuc * (NULL terminated already)
370433d6423SLionel Sambuc */
371433d6423SLionel Sambuc ACPI_MEMCPY (ReturnDesc->String.Pointer,
372433d6423SLionel Sambuc Operand[0]->Buffer.Pointer, Length);
373433d6423SLionel Sambuc break;
374433d6423SLionel Sambuc
375433d6423SLionel Sambuc case AML_CONCAT_RES_OP:
376433d6423SLionel Sambuc
377433d6423SLionel Sambuc /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
378433d6423SLionel Sambuc
379433d6423SLionel Sambuc Status = AcpiExConcatTemplate (Operand[0], Operand[1],
380433d6423SLionel Sambuc &ReturnDesc, WalkState);
381433d6423SLionel Sambuc break;
382433d6423SLionel Sambuc
383433d6423SLionel Sambuc case AML_INDEX_OP: /* Index (Source Index Result) */
384433d6423SLionel Sambuc
385433d6423SLionel Sambuc /* Create the internal return object */
386433d6423SLionel Sambuc
387433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
388433d6423SLionel Sambuc if (!ReturnDesc)
389433d6423SLionel Sambuc {
390433d6423SLionel Sambuc Status = AE_NO_MEMORY;
391433d6423SLionel Sambuc goto Cleanup;
392433d6423SLionel Sambuc }
393433d6423SLionel Sambuc
394433d6423SLionel Sambuc /* Initialize the Index reference object */
395433d6423SLionel Sambuc
396433d6423SLionel Sambuc Index = Operand[1]->Integer.Value;
397433d6423SLionel Sambuc ReturnDesc->Reference.Value = (UINT32) Index;
398433d6423SLionel Sambuc ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
399433d6423SLionel Sambuc
400433d6423SLionel Sambuc /*
401433d6423SLionel Sambuc * At this point, the Source operand is a String, Buffer, or Package.
402433d6423SLionel Sambuc * Verify that the index is within range.
403433d6423SLionel Sambuc */
404433d6423SLionel Sambuc switch ((Operand[0])->Common.Type)
405433d6423SLionel Sambuc {
406433d6423SLionel Sambuc case ACPI_TYPE_STRING:
407433d6423SLionel Sambuc
408433d6423SLionel Sambuc if (Index >= Operand[0]->String.Length)
409433d6423SLionel Sambuc {
410*29492bb7SDavid van Moolenbroek Length = Operand[0]->String.Length;
411433d6423SLionel Sambuc Status = AE_AML_STRING_LIMIT;
412433d6423SLionel Sambuc }
413433d6423SLionel Sambuc
414433d6423SLionel Sambuc ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
415433d6423SLionel Sambuc break;
416433d6423SLionel Sambuc
417433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
418433d6423SLionel Sambuc
419433d6423SLionel Sambuc if (Index >= Operand[0]->Buffer.Length)
420433d6423SLionel Sambuc {
421*29492bb7SDavid van Moolenbroek Length = Operand[0]->Buffer.Length;
422433d6423SLionel Sambuc Status = AE_AML_BUFFER_LIMIT;
423433d6423SLionel Sambuc }
424433d6423SLionel Sambuc
425433d6423SLionel Sambuc ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
426433d6423SLionel Sambuc break;
427433d6423SLionel Sambuc
428433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
429433d6423SLionel Sambuc
430433d6423SLionel Sambuc if (Index >= Operand[0]->Package.Count)
431433d6423SLionel Sambuc {
432*29492bb7SDavid van Moolenbroek Length = Operand[0]->Package.Count;
433433d6423SLionel Sambuc Status = AE_AML_PACKAGE_LIMIT;
434433d6423SLionel Sambuc }
435433d6423SLionel Sambuc
436433d6423SLionel Sambuc ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
437433d6423SLionel Sambuc ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
438433d6423SLionel Sambuc break;
439433d6423SLionel Sambuc
440433d6423SLionel Sambuc default:
441433d6423SLionel Sambuc
442433d6423SLionel Sambuc Status = AE_AML_INTERNAL;
443433d6423SLionel Sambuc goto Cleanup;
444433d6423SLionel Sambuc }
445433d6423SLionel Sambuc
446433d6423SLionel Sambuc /* Failure means that the Index was beyond the end of the object */
447433d6423SLionel Sambuc
448433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
449433d6423SLionel Sambuc {
450433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
451*29492bb7SDavid van Moolenbroek "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
452*29492bb7SDavid van Moolenbroek ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
453433d6423SLionel Sambuc goto Cleanup;
454433d6423SLionel Sambuc }
455433d6423SLionel Sambuc
456433d6423SLionel Sambuc /*
457433d6423SLionel Sambuc * Save the target object and add a reference to it for the life
458433d6423SLionel Sambuc * of the index
459433d6423SLionel Sambuc */
460433d6423SLionel Sambuc ReturnDesc->Reference.Object = Operand[0];
461433d6423SLionel Sambuc AcpiUtAddReference (Operand[0]);
462433d6423SLionel Sambuc
463433d6423SLionel Sambuc /* Store the reference to the Target */
464433d6423SLionel Sambuc
465433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
466433d6423SLionel Sambuc
467433d6423SLionel Sambuc /* Return the reference */
468433d6423SLionel Sambuc
469433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
470433d6423SLionel Sambuc goto Cleanup;
471433d6423SLionel Sambuc
472433d6423SLionel Sambuc default:
473433d6423SLionel Sambuc
474433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
475433d6423SLionel Sambuc WalkState->Opcode));
476433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
477433d6423SLionel Sambuc break;
478433d6423SLionel Sambuc }
479433d6423SLionel Sambuc
480433d6423SLionel Sambuc
481433d6423SLionel Sambuc StoreResultToTarget:
482433d6423SLionel Sambuc
483433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
484433d6423SLionel Sambuc {
485433d6423SLionel Sambuc /*
486433d6423SLionel Sambuc * Store the result of the operation (which is now in ReturnDesc) into
487433d6423SLionel Sambuc * the Target descriptor.
488433d6423SLionel Sambuc */
489433d6423SLionel Sambuc Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
490433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
491433d6423SLionel Sambuc {
492433d6423SLionel Sambuc goto Cleanup;
493433d6423SLionel Sambuc }
494433d6423SLionel Sambuc
495433d6423SLionel Sambuc if (!WalkState->ResultObj)
496433d6423SLionel Sambuc {
497433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
498433d6423SLionel Sambuc }
499433d6423SLionel Sambuc }
500433d6423SLionel Sambuc
501433d6423SLionel Sambuc
502433d6423SLionel Sambuc Cleanup:
503433d6423SLionel Sambuc
504433d6423SLionel Sambuc /* Delete return object on error */
505433d6423SLionel Sambuc
506433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
507433d6423SLionel Sambuc {
508433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc);
509433d6423SLionel Sambuc WalkState->ResultObj = NULL;
510433d6423SLionel Sambuc }
511433d6423SLionel Sambuc
512433d6423SLionel Sambuc return_ACPI_STATUS (Status);
513433d6423SLionel Sambuc }
514433d6423SLionel Sambuc
515433d6423SLionel Sambuc
516433d6423SLionel Sambuc /*******************************************************************************
517433d6423SLionel Sambuc *
518433d6423SLionel Sambuc * FUNCTION: AcpiExOpcode_2A_0T_1R
519433d6423SLionel Sambuc *
520433d6423SLionel Sambuc * PARAMETERS: WalkState - Current walk state
521433d6423SLionel Sambuc *
522433d6423SLionel Sambuc * RETURN: Status
523433d6423SLionel Sambuc *
524433d6423SLionel Sambuc * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
525433d6423SLionel Sambuc *
526433d6423SLionel Sambuc ******************************************************************************/
527433d6423SLionel Sambuc
528433d6423SLionel Sambuc ACPI_STATUS
AcpiExOpcode_2A_0T_1R(ACPI_WALK_STATE * WalkState)529433d6423SLionel Sambuc AcpiExOpcode_2A_0T_1R (
530433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
531433d6423SLionel Sambuc {
532433d6423SLionel Sambuc ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
533433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
534433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
535433d6423SLionel Sambuc BOOLEAN LogicalResult = FALSE;
536433d6423SLionel Sambuc
537433d6423SLionel Sambuc
538433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
539433d6423SLionel Sambuc AcpiPsGetOpcodeName (WalkState->Opcode));
540433d6423SLionel Sambuc
541433d6423SLionel Sambuc
542433d6423SLionel Sambuc /* Create the internal return object */
543433d6423SLionel Sambuc
544433d6423SLionel Sambuc ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
545433d6423SLionel Sambuc if (!ReturnDesc)
546433d6423SLionel Sambuc {
547433d6423SLionel Sambuc Status = AE_NO_MEMORY;
548433d6423SLionel Sambuc goto Cleanup;
549433d6423SLionel Sambuc }
550433d6423SLionel Sambuc
551433d6423SLionel Sambuc /* Execute the Opcode */
552433d6423SLionel Sambuc
553433d6423SLionel Sambuc if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
554433d6423SLionel Sambuc {
555433d6423SLionel Sambuc /* LogicalOp (Operand0, Operand1) */
556433d6423SLionel Sambuc
557433d6423SLionel Sambuc Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
558433d6423SLionel Sambuc Operand[0]->Integer.Value, Operand[1]->Integer.Value,
559433d6423SLionel Sambuc &LogicalResult);
560433d6423SLionel Sambuc goto StoreLogicalResult;
561433d6423SLionel Sambuc }
562433d6423SLionel Sambuc else if (WalkState->OpInfo->Flags & AML_LOGICAL)
563433d6423SLionel Sambuc {
564433d6423SLionel Sambuc /* LogicalOp (Operand0, Operand1) */
565433d6423SLionel Sambuc
566433d6423SLionel Sambuc Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
567433d6423SLionel Sambuc Operand[1], &LogicalResult);
568433d6423SLionel Sambuc goto StoreLogicalResult;
569433d6423SLionel Sambuc }
570433d6423SLionel Sambuc
571433d6423SLionel Sambuc switch (WalkState->Opcode)
572433d6423SLionel Sambuc {
573433d6423SLionel Sambuc case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
574433d6423SLionel Sambuc
575433d6423SLionel Sambuc Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
576433d6423SLionel Sambuc if (Status == AE_TIME)
577433d6423SLionel Sambuc {
578433d6423SLionel Sambuc LogicalResult = TRUE; /* TRUE = Acquire timed out */
579433d6423SLionel Sambuc Status = AE_OK;
580433d6423SLionel Sambuc }
581433d6423SLionel Sambuc break;
582433d6423SLionel Sambuc
583433d6423SLionel Sambuc
584433d6423SLionel Sambuc case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
585433d6423SLionel Sambuc
586433d6423SLionel Sambuc Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
587433d6423SLionel Sambuc if (Status == AE_TIME)
588433d6423SLionel Sambuc {
589433d6423SLionel Sambuc LogicalResult = TRUE; /* TRUE, Wait timed out */
590433d6423SLionel Sambuc Status = AE_OK;
591433d6423SLionel Sambuc }
592433d6423SLionel Sambuc break;
593433d6423SLionel Sambuc
594433d6423SLionel Sambuc default:
595433d6423SLionel Sambuc
596433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
597433d6423SLionel Sambuc WalkState->Opcode));
598433d6423SLionel Sambuc Status = AE_AML_BAD_OPCODE;
599433d6423SLionel Sambuc goto Cleanup;
600433d6423SLionel Sambuc }
601433d6423SLionel Sambuc
602433d6423SLionel Sambuc
603433d6423SLionel Sambuc StoreLogicalResult:
604433d6423SLionel Sambuc /*
605433d6423SLionel Sambuc * Set return value to according to LogicalResult. logical TRUE (all ones)
606433d6423SLionel Sambuc * Default is FALSE (zero)
607433d6423SLionel Sambuc */
608433d6423SLionel Sambuc if (LogicalResult)
609433d6423SLionel Sambuc {
610433d6423SLionel Sambuc ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
611433d6423SLionel Sambuc }
612433d6423SLionel Sambuc
613433d6423SLionel Sambuc Cleanup:
614433d6423SLionel Sambuc
615433d6423SLionel Sambuc /* Delete return object on error */
616433d6423SLionel Sambuc
617433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
618433d6423SLionel Sambuc {
619433d6423SLionel Sambuc AcpiUtRemoveReference (ReturnDesc);
620433d6423SLionel Sambuc }
621433d6423SLionel Sambuc
622433d6423SLionel Sambuc /* Save return object on success */
623433d6423SLionel Sambuc
624433d6423SLionel Sambuc else
625433d6423SLionel Sambuc {
626433d6423SLionel Sambuc WalkState->ResultObj = ReturnDesc;
627433d6423SLionel Sambuc }
628433d6423SLionel Sambuc
629433d6423SLionel Sambuc return_ACPI_STATUS (Status);
630433d6423SLionel Sambuc }
631