exoparg2.c revision 1.1.1.13 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.13 christos * Copyright (C) 2000 - 2019, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acparser.h"
47 1.1 jruoho #include "acinterp.h"
48 1.1 jruoho #include "acevents.h"
49 1.1 jruoho #include "amlcode.h"
50 1.1 jruoho
51 1.1 jruoho
52 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
53 1.1 jruoho ACPI_MODULE_NAME ("exoparg2")
54 1.1 jruoho
55 1.1 jruoho
56 1.1 jruoho /*!
57 1.1 jruoho * Naming convention for AML interpreter execution routines.
58 1.1 jruoho *
59 1.1 jruoho * The routines that begin execution of AML opcodes are named with a common
60 1.1 jruoho * convention based upon the number of arguments, the number of target operands,
61 1.1 jruoho * and whether or not a value is returned:
62 1.1 jruoho *
63 1.1 jruoho * AcpiExOpcode_xA_yT_zR
64 1.1 jruoho *
65 1.1 jruoho * Where:
66 1.1 jruoho *
67 1.1 jruoho * xA - ARGUMENTS: The number of arguments (input operands) that are
68 1.1 jruoho * required for this opcode type (1 through 6 args).
69 1.1 jruoho * yT - TARGETS: The number of targets (output operands) that are required
70 1.1 jruoho * for this opcode type (0, 1, or 2 targets).
71 1.1 jruoho * zR - RETURN VALUE: Indicates whether this opcode type returns a value
72 1.1 jruoho * as the function return (0 or 1).
73 1.1 jruoho *
74 1.1 jruoho * The AcpiExOpcode* functions are called via the Dispatcher component with
75 1.1 jruoho * fully resolved operands.
76 1.1 jruoho !*/
77 1.1 jruoho
78 1.1 jruoho
79 1.1 jruoho /*******************************************************************************
80 1.1 jruoho *
81 1.1 jruoho * FUNCTION: AcpiExOpcode_2A_0T_0R
82 1.1 jruoho *
83 1.1 jruoho * PARAMETERS: WalkState - Current walk state
84 1.1 jruoho *
85 1.1 jruoho * RETURN: Status
86 1.1 jruoho *
87 1.1 jruoho * DESCRIPTION: Execute opcode with two arguments, no target, and no return
88 1.1 jruoho * value.
89 1.1 jruoho *
90 1.1 jruoho * ALLOCATION: Deletes both operands
91 1.1 jruoho *
92 1.1 jruoho ******************************************************************************/
93 1.1 jruoho
94 1.1 jruoho ACPI_STATUS
95 1.1 jruoho AcpiExOpcode_2A_0T_0R (
96 1.1 jruoho ACPI_WALK_STATE *WalkState)
97 1.1 jruoho {
98 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
99 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
100 1.1 jruoho UINT32 Value;
101 1.1 jruoho ACPI_STATUS Status = AE_OK;
102 1.1 jruoho
103 1.1 jruoho
104 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
105 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
106 1.1 jruoho
107 1.1 jruoho
108 1.1 jruoho /* Examine the opcode */
109 1.1 jruoho
110 1.1 jruoho switch (WalkState->Opcode)
111 1.1 jruoho {
112 1.1 jruoho case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
113 1.1 jruoho
114 1.1 jruoho /* The first operand is a namespace node */
115 1.1 jruoho
116 1.1 jruoho Node = (ACPI_NAMESPACE_NODE *) Operand[0];
117 1.1 jruoho
118 1.1 jruoho /* Second value is the notify value */
119 1.1 jruoho
120 1.1 jruoho Value = (UINT32) Operand[1]->Integer.Value;
121 1.1 jruoho
122 1.1 jruoho /* Are notifies allowed on this object? */
123 1.1 jruoho
124 1.1 jruoho if (!AcpiEvIsNotifyObject (Node))
125 1.1 jruoho {
126 1.1 jruoho ACPI_ERROR ((AE_INFO,
127 1.1 jruoho "Unexpected notify object type [%s]",
128 1.1 jruoho AcpiUtGetTypeName (Node->Type)));
129 1.1 jruoho
130 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
131 1.1 jruoho break;
132 1.1 jruoho }
133 1.1 jruoho
134 1.1 jruoho /*
135 1.1 jruoho * Dispatch the notify to the appropriate handler
136 1.1 jruoho * NOTE: the request is queued for execution after this method
137 1.1.1.3 christos * completes. The notify handlers are NOT invoked synchronously
138 1.1 jruoho * from this thread -- because handlers may in turn run other
139 1.1 jruoho * control methods.
140 1.1 jruoho */
141 1.1 jruoho Status = AcpiEvQueueNotifyRequest (Node, Value);
142 1.1 jruoho break;
143 1.1 jruoho
144 1.1 jruoho default:
145 1.1 jruoho
146 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
147 1.1 jruoho WalkState->Opcode));
148 1.1 jruoho Status = AE_AML_BAD_OPCODE;
149 1.1 jruoho }
150 1.1 jruoho
151 1.1 jruoho return_ACPI_STATUS (Status);
152 1.1 jruoho }
153 1.1 jruoho
154 1.1 jruoho
155 1.1 jruoho /*******************************************************************************
156 1.1 jruoho *
157 1.1 jruoho * FUNCTION: AcpiExOpcode_2A_2T_1R
158 1.1 jruoho *
159 1.1 jruoho * PARAMETERS: WalkState - Current walk state
160 1.1 jruoho *
161 1.1 jruoho * RETURN: Status
162 1.1 jruoho *
163 1.1 jruoho * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
164 1.1 jruoho * and one implicit return value.
165 1.1 jruoho *
166 1.1 jruoho ******************************************************************************/
167 1.1 jruoho
168 1.1 jruoho ACPI_STATUS
169 1.1 jruoho AcpiExOpcode_2A_2T_1R (
170 1.1 jruoho ACPI_WALK_STATE *WalkState)
171 1.1 jruoho {
172 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
173 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
174 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
175 1.1 jruoho ACPI_STATUS Status;
176 1.1 jruoho
177 1.1 jruoho
178 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
179 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
180 1.1 jruoho
181 1.1 jruoho
182 1.1 jruoho /* Execute the opcode */
183 1.1 jruoho
184 1.1 jruoho switch (WalkState->Opcode)
185 1.1 jruoho {
186 1.1 jruoho case AML_DIVIDE_OP:
187 1.1 jruoho
188 1.1 jruoho /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
189 1.1 jruoho
190 1.1 jruoho ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
191 1.1 jruoho if (!ReturnDesc1)
192 1.1 jruoho {
193 1.1 jruoho Status = AE_NO_MEMORY;
194 1.1 jruoho goto Cleanup;
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
198 1.1 jruoho if (!ReturnDesc2)
199 1.1 jruoho {
200 1.1 jruoho Status = AE_NO_MEMORY;
201 1.1 jruoho goto Cleanup;
202 1.1 jruoho }
203 1.1 jruoho
204 1.1 jruoho /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
205 1.1 jruoho
206 1.1.1.7 christos Status = AcpiUtDivide (
207 1.1.1.7 christos Operand[0]->Integer.Value,
208 1.1.1.7 christos Operand[1]->Integer.Value,
209 1.1.1.7 christos &ReturnDesc1->Integer.Value,
210 1.1.1.7 christos &ReturnDesc2->Integer.Value);
211 1.1 jruoho if (ACPI_FAILURE (Status))
212 1.1 jruoho {
213 1.1 jruoho goto Cleanup;
214 1.1 jruoho }
215 1.1 jruoho break;
216 1.1 jruoho
217 1.1 jruoho default:
218 1.1 jruoho
219 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
220 1.1 jruoho WalkState->Opcode));
221 1.1.1.7 christos
222 1.1 jruoho Status = AE_AML_BAD_OPCODE;
223 1.1 jruoho goto Cleanup;
224 1.1 jruoho }
225 1.1 jruoho
226 1.1 jruoho /* Store the results to the target reference operands */
227 1.1 jruoho
228 1.1 jruoho Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
229 1.1 jruoho if (ACPI_FAILURE (Status))
230 1.1 jruoho {
231 1.1 jruoho goto Cleanup;
232 1.1 jruoho }
233 1.1 jruoho
234 1.1 jruoho Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
235 1.1 jruoho if (ACPI_FAILURE (Status))
236 1.1 jruoho {
237 1.1 jruoho goto Cleanup;
238 1.1 jruoho }
239 1.1 jruoho
240 1.1 jruoho Cleanup:
241 1.1 jruoho /*
242 1.1 jruoho * Since the remainder is not returned indirectly, remove a reference to
243 1.1 jruoho * it. Only the quotient is returned indirectly.
244 1.1 jruoho */
245 1.1 jruoho AcpiUtRemoveReference (ReturnDesc2);
246 1.1 jruoho
247 1.1 jruoho if (ACPI_FAILURE (Status))
248 1.1 jruoho {
249 1.1 jruoho /* Delete the return object */
250 1.1 jruoho
251 1.1 jruoho AcpiUtRemoveReference (ReturnDesc1);
252 1.1 jruoho }
253 1.1 jruoho
254 1.1 jruoho /* Save return object (the remainder) on success */
255 1.1 jruoho
256 1.1 jruoho else
257 1.1 jruoho {
258 1.1 jruoho WalkState->ResultObj = ReturnDesc1;
259 1.1 jruoho }
260 1.1 jruoho
261 1.1 jruoho return_ACPI_STATUS (Status);
262 1.1 jruoho }
263 1.1 jruoho
264 1.1 jruoho
265 1.1 jruoho /*******************************************************************************
266 1.1 jruoho *
267 1.1 jruoho * FUNCTION: AcpiExOpcode_2A_1T_1R
268 1.1 jruoho *
269 1.1 jruoho * PARAMETERS: WalkState - Current walk state
270 1.1 jruoho *
271 1.1 jruoho * RETURN: Status
272 1.1 jruoho *
273 1.1 jruoho * DESCRIPTION: Execute opcode with two arguments, one target, and a return
274 1.1 jruoho * value.
275 1.1 jruoho *
276 1.1 jruoho ******************************************************************************/
277 1.1 jruoho
278 1.1 jruoho ACPI_STATUS
279 1.1 jruoho AcpiExOpcode_2A_1T_1R (
280 1.1 jruoho ACPI_WALK_STATE *WalkState)
281 1.1 jruoho {
282 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
283 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
284 1.1 jruoho UINT64 Index;
285 1.1 jruoho ACPI_STATUS Status = AE_OK;
286 1.1.1.3 christos ACPI_SIZE Length = 0;
287 1.1 jruoho
288 1.1 jruoho
289 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
290 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
291 1.1 jruoho
292 1.1 jruoho
293 1.1 jruoho /* Execute the opcode */
294 1.1 jruoho
295 1.1 jruoho if (WalkState->OpInfo->Flags & AML_MATH)
296 1.1 jruoho {
297 1.1 jruoho /* All simple math opcodes (add, etc.) */
298 1.1 jruoho
299 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
300 1.1 jruoho if (!ReturnDesc)
301 1.1 jruoho {
302 1.1 jruoho Status = AE_NO_MEMORY;
303 1.1 jruoho goto Cleanup;
304 1.1 jruoho }
305 1.1 jruoho
306 1.1.1.7 christos ReturnDesc->Integer.Value = AcpiExDoMathOp (
307 1.1.1.7 christos WalkState->Opcode,
308 1.1.1.7 christos Operand[0]->Integer.Value,
309 1.1.1.7 christos Operand[1]->Integer.Value);
310 1.1 jruoho goto StoreResultToTarget;
311 1.1 jruoho }
312 1.1 jruoho
313 1.1 jruoho switch (WalkState->Opcode)
314 1.1 jruoho {
315 1.1 jruoho case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
316 1.1 jruoho
317 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
318 1.1 jruoho if (!ReturnDesc)
319 1.1 jruoho {
320 1.1 jruoho Status = AE_NO_MEMORY;
321 1.1 jruoho goto Cleanup;
322 1.1 jruoho }
323 1.1 jruoho
324 1.1 jruoho /* ReturnDesc will contain the remainder */
325 1.1 jruoho
326 1.1.1.7 christos Status = AcpiUtDivide (
327 1.1.1.7 christos Operand[0]->Integer.Value,
328 1.1.1.7 christos Operand[1]->Integer.Value,
329 1.1.1.7 christos NULL,
330 1.1.1.7 christos &ReturnDesc->Integer.Value);
331 1.1 jruoho break;
332 1.1 jruoho
333 1.1.1.9 christos case AML_CONCATENATE_OP: /* Concatenate (Data1, Data2, Result) */
334 1.1 jruoho
335 1.1.1.7 christos Status = AcpiExDoConcatenate (
336 1.1.1.7 christos Operand[0], Operand[1], &ReturnDesc, WalkState);
337 1.1 jruoho break;
338 1.1 jruoho
339 1.1 jruoho case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
340 1.1 jruoho /*
341 1.1 jruoho * Input object is guaranteed to be a buffer at this point (it may have
342 1.1 jruoho * been converted.) Copy the raw buffer data to a new object of
343 1.1 jruoho * type String.
344 1.1 jruoho */
345 1.1 jruoho
346 1.1 jruoho /*
347 1.1 jruoho * Get the length of the new string. It is the smallest of:
348 1.1 jruoho * 1) Length of the input buffer
349 1.1 jruoho * 2) Max length as specified in the ToString operator
350 1.1 jruoho * 3) Length of input buffer up to a zero byte (null terminator)
351 1.1 jruoho *
352 1.1 jruoho * NOTE: A length of zero is ok, and will create a zero-length, null
353 1.1 jruoho * terminated string.
354 1.1 jruoho */
355 1.1.1.12 christos while ((Length < Operand[0]->Buffer.Length) && /* Length of input buffer */
356 1.1.1.12 christos (Length < Operand[1]->Integer.Value) && /* Length operand */
357 1.1.1.12 christos (Operand[0]->Buffer.Pointer[Length])) /* Null terminator */
358 1.1 jruoho {
359 1.1 jruoho Length++;
360 1.1 jruoho }
361 1.1 jruoho
362 1.1 jruoho /* Allocate a new string object */
363 1.1 jruoho
364 1.1 jruoho ReturnDesc = AcpiUtCreateStringObject (Length);
365 1.1 jruoho if (!ReturnDesc)
366 1.1 jruoho {
367 1.1 jruoho Status = AE_NO_MEMORY;
368 1.1 jruoho goto Cleanup;
369 1.1 jruoho }
370 1.1 jruoho
371 1.1 jruoho /*
372 1.1 jruoho * Copy the raw buffer data with no transform.
373 1.1 jruoho * (NULL terminated already)
374 1.1 jruoho */
375 1.1.1.6 christos memcpy (ReturnDesc->String.Pointer,
376 1.1 jruoho Operand[0]->Buffer.Pointer, Length);
377 1.1 jruoho break;
378 1.1 jruoho
379 1.1.1.9 christos case AML_CONCATENATE_TEMPLATE_OP:
380 1.1 jruoho
381 1.1 jruoho /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
382 1.1 jruoho
383 1.1.1.7 christos Status = AcpiExConcatTemplate (
384 1.1.1.7 christos Operand[0], Operand[1], &ReturnDesc, WalkState);
385 1.1 jruoho break;
386 1.1 jruoho
387 1.1 jruoho case AML_INDEX_OP: /* Index (Source Index Result) */
388 1.1 jruoho
389 1.1 jruoho /* Create the internal return object */
390 1.1 jruoho
391 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
392 1.1 jruoho if (!ReturnDesc)
393 1.1 jruoho {
394 1.1 jruoho Status = AE_NO_MEMORY;
395 1.1 jruoho goto Cleanup;
396 1.1 jruoho }
397 1.1 jruoho
398 1.1 jruoho /* Initialize the Index reference object */
399 1.1 jruoho
400 1.1 jruoho Index = Operand[1]->Integer.Value;
401 1.1 jruoho ReturnDesc->Reference.Value = (UINT32) Index;
402 1.1 jruoho ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
403 1.1 jruoho
404 1.1 jruoho /*
405 1.1 jruoho * At this point, the Source operand is a String, Buffer, or Package.
406 1.1 jruoho * Verify that the index is within range.
407 1.1 jruoho */
408 1.1 jruoho switch ((Operand[0])->Common.Type)
409 1.1 jruoho {
410 1.1 jruoho case ACPI_TYPE_STRING:
411 1.1 jruoho
412 1.1 jruoho if (Index >= Operand[0]->String.Length)
413 1.1 jruoho {
414 1.1.1.3 christos Length = Operand[0]->String.Length;
415 1.1 jruoho Status = AE_AML_STRING_LIMIT;
416 1.1 jruoho }
417 1.1 jruoho
418 1.1 jruoho ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
419 1.1.1.6 christos ReturnDesc->Reference.IndexPointer =
420 1.1.1.6 christos &(Operand[0]->Buffer.Pointer [Index]);
421 1.1 jruoho break;
422 1.1 jruoho
423 1.1 jruoho case ACPI_TYPE_BUFFER:
424 1.1 jruoho
425 1.1 jruoho if (Index >= Operand[0]->Buffer.Length)
426 1.1 jruoho {
427 1.1.1.3 christos Length = Operand[0]->Buffer.Length;
428 1.1 jruoho Status = AE_AML_BUFFER_LIMIT;
429 1.1 jruoho }
430 1.1 jruoho
431 1.1 jruoho ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
432 1.1.1.6 christos ReturnDesc->Reference.IndexPointer =
433 1.1.1.6 christos &(Operand[0]->Buffer.Pointer [Index]);
434 1.1 jruoho break;
435 1.1 jruoho
436 1.1 jruoho case ACPI_TYPE_PACKAGE:
437 1.1 jruoho
438 1.1 jruoho if (Index >= Operand[0]->Package.Count)
439 1.1 jruoho {
440 1.1.1.3 christos Length = Operand[0]->Package.Count;
441 1.1 jruoho Status = AE_AML_PACKAGE_LIMIT;
442 1.1 jruoho }
443 1.1 jruoho
444 1.1 jruoho ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
445 1.1.1.6 christos ReturnDesc->Reference.Where =
446 1.1.1.6 christos &Operand[0]->Package.Elements [Index];
447 1.1 jruoho break;
448 1.1 jruoho
449 1.1 jruoho default:
450 1.1 jruoho
451 1.1.1.10 christos ACPI_ERROR ((AE_INFO,
452 1.1.1.10 christos "Invalid object type: %X", (Operand[0])->Common.Type));
453 1.1 jruoho Status = AE_AML_INTERNAL;
454 1.1 jruoho goto Cleanup;
455 1.1 jruoho }
456 1.1 jruoho
457 1.1 jruoho /* Failure means that the Index was beyond the end of the object */
458 1.1 jruoho
459 1.1 jruoho if (ACPI_FAILURE (Status))
460 1.1 jruoho {
461 1.1.1.13 christos ACPI_BIOS_EXCEPTION ((AE_INFO, Status,
462 1.1.1.3 christos "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
463 1.1.1.3 christos ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
464 1.1 jruoho goto Cleanup;
465 1.1 jruoho }
466 1.1 jruoho
467 1.1 jruoho /*
468 1.1 jruoho * Save the target object and add a reference to it for the life
469 1.1 jruoho * of the index
470 1.1 jruoho */
471 1.1 jruoho ReturnDesc->Reference.Object = Operand[0];
472 1.1 jruoho AcpiUtAddReference (Operand[0]);
473 1.1 jruoho
474 1.1 jruoho /* Store the reference to the Target */
475 1.1 jruoho
476 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
477 1.1 jruoho
478 1.1 jruoho /* Return the reference */
479 1.1 jruoho
480 1.1 jruoho WalkState->ResultObj = ReturnDesc;
481 1.1 jruoho goto Cleanup;
482 1.1 jruoho
483 1.1 jruoho default:
484 1.1 jruoho
485 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
486 1.1 jruoho WalkState->Opcode));
487 1.1 jruoho Status = AE_AML_BAD_OPCODE;
488 1.1 jruoho break;
489 1.1 jruoho }
490 1.1 jruoho
491 1.1 jruoho
492 1.1 jruoho StoreResultToTarget:
493 1.1 jruoho
494 1.1 jruoho if (ACPI_SUCCESS (Status))
495 1.1 jruoho {
496 1.1 jruoho /*
497 1.1 jruoho * Store the result of the operation (which is now in ReturnDesc) into
498 1.1 jruoho * the Target descriptor.
499 1.1 jruoho */
500 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
501 1.1 jruoho if (ACPI_FAILURE (Status))
502 1.1 jruoho {
503 1.1 jruoho goto Cleanup;
504 1.1 jruoho }
505 1.1 jruoho
506 1.1 jruoho if (!WalkState->ResultObj)
507 1.1 jruoho {
508 1.1 jruoho WalkState->ResultObj = ReturnDesc;
509 1.1 jruoho }
510 1.1 jruoho }
511 1.1 jruoho
512 1.1 jruoho
513 1.1 jruoho Cleanup:
514 1.1 jruoho
515 1.1 jruoho /* Delete return object on error */
516 1.1 jruoho
517 1.1 jruoho if (ACPI_FAILURE (Status))
518 1.1 jruoho {
519 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
520 1.1 jruoho WalkState->ResultObj = NULL;
521 1.1 jruoho }
522 1.1 jruoho
523 1.1 jruoho return_ACPI_STATUS (Status);
524 1.1 jruoho }
525 1.1 jruoho
526 1.1 jruoho
527 1.1 jruoho /*******************************************************************************
528 1.1 jruoho *
529 1.1 jruoho * FUNCTION: AcpiExOpcode_2A_0T_1R
530 1.1 jruoho *
531 1.1 jruoho * PARAMETERS: WalkState - Current walk state
532 1.1 jruoho *
533 1.1 jruoho * RETURN: Status
534 1.1 jruoho *
535 1.1 jruoho * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
536 1.1 jruoho *
537 1.1 jruoho ******************************************************************************/
538 1.1 jruoho
539 1.1 jruoho ACPI_STATUS
540 1.1 jruoho AcpiExOpcode_2A_0T_1R (
541 1.1 jruoho ACPI_WALK_STATE *WalkState)
542 1.1 jruoho {
543 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
544 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
545 1.1 jruoho ACPI_STATUS Status = AE_OK;
546 1.1 jruoho BOOLEAN LogicalResult = FALSE;
547 1.1 jruoho
548 1.1 jruoho
549 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
550 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
551 1.1 jruoho
552 1.1 jruoho
553 1.1 jruoho /* Create the internal return object */
554 1.1 jruoho
555 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
556 1.1 jruoho if (!ReturnDesc)
557 1.1 jruoho {
558 1.1 jruoho Status = AE_NO_MEMORY;
559 1.1 jruoho goto Cleanup;
560 1.1 jruoho }
561 1.1 jruoho
562 1.1 jruoho /* Execute the Opcode */
563 1.1 jruoho
564 1.1 jruoho if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
565 1.1 jruoho {
566 1.1 jruoho /* LogicalOp (Operand0, Operand1) */
567 1.1 jruoho
568 1.1 jruoho Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
569 1.1.1.7 christos Operand[0]->Integer.Value, Operand[1]->Integer.Value,
570 1.1.1.7 christos &LogicalResult);
571 1.1 jruoho goto StoreLogicalResult;
572 1.1 jruoho }
573 1.1 jruoho else if (WalkState->OpInfo->Flags & AML_LOGICAL)
574 1.1 jruoho {
575 1.1 jruoho /* LogicalOp (Operand0, Operand1) */
576 1.1 jruoho
577 1.1 jruoho Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
578 1.1.1.7 christos Operand[1], &LogicalResult);
579 1.1 jruoho goto StoreLogicalResult;
580 1.1 jruoho }
581 1.1 jruoho
582 1.1 jruoho switch (WalkState->Opcode)
583 1.1 jruoho {
584 1.1 jruoho case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
585 1.1 jruoho
586 1.1 jruoho Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
587 1.1 jruoho if (Status == AE_TIME)
588 1.1 jruoho {
589 1.1 jruoho LogicalResult = TRUE; /* TRUE = Acquire timed out */
590 1.1 jruoho Status = AE_OK;
591 1.1 jruoho }
592 1.1 jruoho break;
593 1.1 jruoho
594 1.1 jruoho
595 1.1 jruoho case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
596 1.1 jruoho
597 1.1 jruoho Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
598 1.1 jruoho if (Status == AE_TIME)
599 1.1 jruoho {
600 1.1 jruoho LogicalResult = TRUE; /* TRUE, Wait timed out */
601 1.1 jruoho Status = AE_OK;
602 1.1 jruoho }
603 1.1 jruoho break;
604 1.1 jruoho
605 1.1 jruoho default:
606 1.1 jruoho
607 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
608 1.1 jruoho WalkState->Opcode));
609 1.1.1.7 christos
610 1.1 jruoho Status = AE_AML_BAD_OPCODE;
611 1.1 jruoho goto Cleanup;
612 1.1 jruoho }
613 1.1 jruoho
614 1.1 jruoho
615 1.1 jruoho StoreLogicalResult:
616 1.1 jruoho /*
617 1.1 jruoho * Set return value to according to LogicalResult. logical TRUE (all ones)
618 1.1 jruoho * Default is FALSE (zero)
619 1.1 jruoho */
620 1.1 jruoho if (LogicalResult)
621 1.1 jruoho {
622 1.1 jruoho ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
623 1.1 jruoho }
624 1.1 jruoho
625 1.1 jruoho Cleanup:
626 1.1 jruoho
627 1.1 jruoho /* Delete return object on error */
628 1.1 jruoho
629 1.1 jruoho if (ACPI_FAILURE (Status))
630 1.1 jruoho {
631 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
632 1.1 jruoho }
633 1.1 jruoho
634 1.1 jruoho /* Save return object on success */
635 1.1 jruoho
636 1.1 jruoho else
637 1.1 jruoho {
638 1.1 jruoho WalkState->ResultObj = ReturnDesc;
639 1.1 jruoho }
640 1.1 jruoho
641 1.1 jruoho return_ACPI_STATUS (Status);
642 1.1 jruoho }
643