1 /******************************************************************************
2 *
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
127 if (!AcpiEvIsNotifyObject (Node))
128 {
129 ACPI_ERROR ((AE_INFO,
130 "Unexpected notify object type [%s]",
131 AcpiUtGetTypeName (Node->Type)));
132
133 Status = AE_AML_OPERAND_TYPE;
134 break;
135 }
136
137 /*
138 * Dispatch the notify to the appropriate handler
139 * NOTE: the request is queued for execution after this method
140 * completes. The notify handlers are NOT invoked synchronously
141 * from this thread -- because handlers may in turn run other
142 * control methods.
143 */
144 Status = AcpiEvQueueNotifyRequest (Node, Value);
145 break;
146
147
148 default:
149
150 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
151 WalkState->Opcode));
152 Status = AE_AML_BAD_OPCODE;
153 }
154
155 return_ACPI_STATUS (Status);
156 }
157
158
159 /*******************************************************************************
160 *
161 * FUNCTION: AcpiExOpcode_2A_2T_1R
162 *
163 * PARAMETERS: WalkState - Current walk state
164 *
165 * RETURN: Status
166 *
167 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
200
201 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
202 if (!ReturnDesc2)
203 {
204 Status = AE_NO_MEMORY;
205 goto Cleanup;
206 }
207
208 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
209
210 Status = AcpiUtDivide (Operand[0]->Integer.Value,
211 Operand[1]->Integer.Value,
212 &ReturnDesc1->Integer.Value,
213 &ReturnDesc2->Integer.Value);
214 if (ACPI_FAILURE (Status))
215 {
216 goto Cleanup;
217 }
218 break;
219
220
221 default:
222
223 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
224 WalkState->Opcode));
225 Status = AE_AML_BAD_OPCODE;
226 goto Cleanup;
227 }
228
229 /* Store the results to the target reference operands */
230
231 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
232 if (ACPI_FAILURE (Status))
233 {
234 goto Cleanup;
235 }
236
237 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
238 if (ACPI_FAILURE (Status))
239 {
240 goto Cleanup;
269 *
270 * FUNCTION: AcpiExOpcode_2A_1T_1R
271 *
272 * PARAMETERS: WalkState - Current walk state
273 *
274 * RETURN: Status
275 *
276 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
277 * value.
278 *
279 ******************************************************************************/
280
281 ACPI_STATUS
282 AcpiExOpcode_2A_1T_1R (
283 ACPI_WALK_STATE *WalkState)
284 {
285 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
286 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
287 UINT64 Index;
288 ACPI_STATUS Status = AE_OK;
289 ACPI_SIZE Length;
290
291
292 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
293 AcpiPsGetOpcodeName (WalkState->Opcode));
294
295
296 /* Execute the opcode */
297
298 if (WalkState->OpInfo->Flags & AML_MATH)
299 {
300 /* All simple math opcodes (add, etc.) */
301
302 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
303 if (!ReturnDesc)
304 {
305 Status = AE_NO_MEMORY;
306 goto Cleanup;
307 }
308
309 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
314
315 switch (WalkState->Opcode)
316 {
317 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
318
319 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
320 if (!ReturnDesc)
321 {
322 Status = AE_NO_MEMORY;
323 goto Cleanup;
324 }
325
326 /* ReturnDesc will contain the remainder */
327
328 Status = AcpiUtDivide (Operand[0]->Integer.Value,
329 Operand[1]->Integer.Value,
330 NULL,
331 &ReturnDesc->Integer.Value);
332 break;
333
334
335 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
336
337 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
338 &ReturnDesc, WalkState);
339 break;
340
341
342 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
343
344 /*
345 * Input object is guaranteed to be a buffer at this point (it may have
346 * been converted.) Copy the raw buffer data to a new object of
347 * type String.
348 */
349
350 /*
351 * Get the length of the new string. It is the smallest of:
352 * 1) Length of the input buffer
353 * 2) Max length as specified in the ToString operator
354 * 3) Length of input buffer up to a zero byte (null terminator)
355 *
356 * NOTE: A length of zero is ok, and will create a zero-length, null
357 * terminated string.
358 */
359 Length = 0;
360 while ((Length < Operand[0]->Buffer.Length) &&
361 (Length < Operand[1]->Integer.Value) &&
362 (Operand[0]->Buffer.Pointer[Length]))
363 {
364 Length++;
365 }
366
367 /* Allocate a new string object */
368
369 ReturnDesc = AcpiUtCreateStringObject (Length);
370 if (!ReturnDesc)
371 {
372 Status = AE_NO_MEMORY;
373 goto Cleanup;
374 }
375
376 /*
377 * Copy the raw buffer data with no transform.
378 * (NULL terminated already)
379 */
380 ACPI_MEMCPY (ReturnDesc->String.Pointer,
381 Operand[0]->Buffer.Pointer, Length);
382 break;
383
384
385 case AML_CONCAT_RES_OP:
386
387 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
388
389 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
390 &ReturnDesc, WalkState);
391 break;
392
393
394 case AML_INDEX_OP: /* Index (Source Index Result) */
395
396 /* Create the internal return object */
397
398 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
399 if (!ReturnDesc)
400 {
401 Status = AE_NO_MEMORY;
402 goto Cleanup;
403 }
404
405 /* Initialize the Index reference object */
406
407 Index = Operand[1]->Integer.Value;
408 ReturnDesc->Reference.Value = (UINT32) Index;
409 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
410
411 /*
412 * At this point, the Source operand is a String, Buffer, or Package.
413 * Verify that the index is within range.
414 */
415 switch ((Operand[0])->Common.Type)
416 {
417 case ACPI_TYPE_STRING:
418
419 if (Index >= Operand[0]->String.Length)
420 {
421 Status = AE_AML_STRING_LIMIT;
422 }
423
424 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
425 break;
426
427 case ACPI_TYPE_BUFFER:
428
429 if (Index >= Operand[0]->Buffer.Length)
430 {
431 Status = AE_AML_BUFFER_LIMIT;
432 }
433
434 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
435 break;
436
437 case ACPI_TYPE_PACKAGE:
438
439 if (Index >= Operand[0]->Package.Count)
440 {
441 Status = AE_AML_PACKAGE_LIMIT;
442 }
443
444 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
445 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
446 break;
447
448 default:
449
450 Status = AE_AML_INTERNAL;
451 goto Cleanup;
452 }
453
454 /* Failure means that the Index was beyond the end of the object */
455
456 if (ACPI_FAILURE (Status))
457 {
458 ACPI_EXCEPTION ((AE_INFO, Status,
459 "Index (0x%8.8X%8.8X) is beyond end of object",
460 ACPI_FORMAT_UINT64 (Index)));
461 goto Cleanup;
462 }
463
464 /*
465 * Save the target object and add a reference to it for the life
466 * of the index
467 */
468 ReturnDesc->Reference.Object = Operand[0];
469 AcpiUtAddReference (Operand[0]);
470
471 /* Store the reference to the Target */
472
473 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
474
475 /* Return the reference */
476
477 WalkState->ResultObj = ReturnDesc;
478 goto Cleanup;
479
480
481 default:
482
483 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
484 WalkState->Opcode));
485 Status = AE_AML_BAD_OPCODE;
486 break;
487 }
488
489
490 StoreResultToTarget:
491
492 if (ACPI_SUCCESS (Status))
493 {
494 /*
495 * Store the result of the operation (which is now in ReturnDesc) into
496 * the Target descriptor.
497 */
498 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
499 if (ACPI_FAILURE (Status))
500 {
583
584 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
585 if (Status == AE_TIME)
586 {
587 LogicalResult = TRUE; /* TRUE = Acquire timed out */
588 Status = AE_OK;
589 }
590 break;
591
592
593 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
594
595 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
596 if (Status == AE_TIME)
597 {
598 LogicalResult = TRUE; /* TRUE, Wait timed out */
599 Status = AE_OK;
600 }
601 break;
602
603
604 default:
605
606 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
607 WalkState->Opcode));
608 Status = AE_AML_BAD_OPCODE;
609 goto Cleanup;
610 }
611
612
613 StoreLogicalResult:
614 /*
615 * Set return value to according to LogicalResult. logical TRUE (all ones)
616 * Default is FALSE (zero)
617 */
618 if (LogicalResult)
619 {
620 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
621 }
622
623 Cleanup:
624
625 /* Delete return object on error */
626
627 if (ACPI_FAILURE (Status))
628 {
629 AcpiUtRemoveReference (ReturnDesc);
630 }
631
632 /* Save return object on success */
633
634 else
635 {
636 WalkState->ResultObj = ReturnDesc;
637 }
638
639 return_ACPI_STATUS (Status);
640 }
641
642
|
1 /******************************************************************************
2 *
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
127 if (!AcpiEvIsNotifyObject (Node))
128 {
129 ACPI_ERROR ((AE_INFO,
130 "Unexpected notify object type [%s]",
131 AcpiUtGetTypeName (Node->Type)));
132
133 Status = AE_AML_OPERAND_TYPE;
134 break;
135 }
136
137 /*
138 * Dispatch the notify to the appropriate handler
139 * NOTE: the request is queued for execution after this method
140 * completes. The notify handlers are NOT invoked synchronously
141 * from this thread -- because handlers may in turn run other
142 * control methods.
143 */
144 Status = AcpiEvQueueNotifyRequest (Node, Value);
145 break;
146
147 default:
148
149 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
150 WalkState->Opcode));
151 Status = AE_AML_BAD_OPCODE;
152 }
153
154 return_ACPI_STATUS (Status);
155 }
156
157
158 /*******************************************************************************
159 *
160 * FUNCTION: AcpiExOpcode_2A_2T_1R
161 *
162 * PARAMETERS: WalkState - Current walk state
163 *
164 * RETURN: Status
165 *
166 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
199
200 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
201 if (!ReturnDesc2)
202 {
203 Status = AE_NO_MEMORY;
204 goto Cleanup;
205 }
206
207 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
208
209 Status = AcpiUtDivide (Operand[0]->Integer.Value,
210 Operand[1]->Integer.Value,
211 &ReturnDesc1->Integer.Value,
212 &ReturnDesc2->Integer.Value);
213 if (ACPI_FAILURE (Status))
214 {
215 goto Cleanup;
216 }
217 break;
218
219 default:
220
221 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
222 WalkState->Opcode));
223 Status = AE_AML_BAD_OPCODE;
224 goto Cleanup;
225 }
226
227 /* Store the results to the target reference operands */
228
229 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
230 if (ACPI_FAILURE (Status))
231 {
232 goto Cleanup;
233 }
234
235 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
236 if (ACPI_FAILURE (Status))
237 {
238 goto Cleanup;
267 *
268 * FUNCTION: AcpiExOpcode_2A_1T_1R
269 *
270 * PARAMETERS: WalkState - Current walk state
271 *
272 * RETURN: Status
273 *
274 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
275 * value.
276 *
277 ******************************************************************************/
278
279 ACPI_STATUS
280 AcpiExOpcode_2A_1T_1R (
281 ACPI_WALK_STATE *WalkState)
282 {
283 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
284 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
285 UINT64 Index;
286 ACPI_STATUS Status = AE_OK;
287 ACPI_SIZE Length = 0;
288
289
290 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
291 AcpiPsGetOpcodeName (WalkState->Opcode));
292
293
294 /* Execute the opcode */
295
296 if (WalkState->OpInfo->Flags & AML_MATH)
297 {
298 /* All simple math opcodes (add, etc.) */
299
300 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
301 if (!ReturnDesc)
302 {
303 Status = AE_NO_MEMORY;
304 goto Cleanup;
305 }
306
307 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
312
313 switch (WalkState->Opcode)
314 {
315 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
316
317 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
318 if (!ReturnDesc)
319 {
320 Status = AE_NO_MEMORY;
321 goto Cleanup;
322 }
323
324 /* ReturnDesc will contain the remainder */
325
326 Status = AcpiUtDivide (Operand[0]->Integer.Value,
327 Operand[1]->Integer.Value,
328 NULL,
329 &ReturnDesc->Integer.Value);
330 break;
331
332 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
333
334 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
335 &ReturnDesc, WalkState);
336 break;
337
338 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
339 /*
340 * Input object is guaranteed to be a buffer at this point (it may have
341 * been converted.) Copy the raw buffer data to a new object of
342 * type String.
343 */
344
345 /*
346 * Get the length of the new string. It is the smallest of:
347 * 1) Length of the input buffer
348 * 2) Max length as specified in the ToString operator
349 * 3) Length of input buffer up to a zero byte (null terminator)
350 *
351 * NOTE: A length of zero is ok, and will create a zero-length, null
352 * terminated string.
353 */
354 while ((Length < Operand[0]->Buffer.Length) &&
355 (Length < Operand[1]->Integer.Value) &&
356 (Operand[0]->Buffer.Pointer[Length]))
357 {
358 Length++;
359 }
360
361 /* Allocate a new string object */
362
363 ReturnDesc = AcpiUtCreateStringObject (Length);
364 if (!ReturnDesc)
365 {
366 Status = AE_NO_MEMORY;
367 goto Cleanup;
368 }
369
370 /*
371 * Copy the raw buffer data with no transform.
372 * (NULL terminated already)
373 */
374 ACPI_MEMCPY (ReturnDesc->String.Pointer,
375 Operand[0]->Buffer.Pointer, Length);
376 break;
377
378 case AML_CONCAT_RES_OP:
379
380 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
381
382 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
383 &ReturnDesc, WalkState);
384 break;
385
386 case AML_INDEX_OP: /* Index (Source Index Result) */
387
388 /* Create the internal return object */
389
390 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
391 if (!ReturnDesc)
392 {
393 Status = AE_NO_MEMORY;
394 goto Cleanup;
395 }
396
397 /* Initialize the Index reference object */
398
399 Index = Operand[1]->Integer.Value;
400 ReturnDesc->Reference.Value = (UINT32) Index;
401 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
402
403 /*
404 * At this point, the Source operand is a String, Buffer, or Package.
405 * Verify that the index is within range.
406 */
407 switch ((Operand[0])->Common.Type)
408 {
409 case ACPI_TYPE_STRING:
410
411 if (Index >= Operand[0]->String.Length)
412 {
413 Length = Operand[0]->String.Length;
414 Status = AE_AML_STRING_LIMIT;
415 }
416
417 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
418 break;
419
420 case ACPI_TYPE_BUFFER:
421
422 if (Index >= Operand[0]->Buffer.Length)
423 {
424 Length = Operand[0]->Buffer.Length;
425 Status = AE_AML_BUFFER_LIMIT;
426 }
427
428 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
429 break;
430
431 case ACPI_TYPE_PACKAGE:
432
433 if (Index >= Operand[0]->Package.Count)
434 {
435 Length = Operand[0]->Package.Count;
436 Status = AE_AML_PACKAGE_LIMIT;
437 }
438
439 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
440 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
441 break;
442
443 default:
444
445 Status = AE_AML_INTERNAL;
446 goto Cleanup;
447 }
448
449 /* Failure means that the Index was beyond the end of the object */
450
451 if (ACPI_FAILURE (Status))
452 {
453 ACPI_EXCEPTION ((AE_INFO, Status,
454 "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
455 ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
456 goto Cleanup;
457 }
458
459 /*
460 * Save the target object and add a reference to it for the life
461 * of the index
462 */
463 ReturnDesc->Reference.Object = Operand[0];
464 AcpiUtAddReference (Operand[0]);
465
466 /* Store the reference to the Target */
467
468 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
469
470 /* Return the reference */
471
472 WalkState->ResultObj = ReturnDesc;
473 goto Cleanup;
474
475 default:
476
477 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
478 WalkState->Opcode));
479 Status = AE_AML_BAD_OPCODE;
480 break;
481 }
482
483
484 StoreResultToTarget:
485
486 if (ACPI_SUCCESS (Status))
487 {
488 /*
489 * Store the result of the operation (which is now in ReturnDesc) into
490 * the Target descriptor.
491 */
492 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
493 if (ACPI_FAILURE (Status))
494 {
577
578 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
579 if (Status == AE_TIME)
580 {
581 LogicalResult = TRUE; /* TRUE = Acquire timed out */
582 Status = AE_OK;
583 }
584 break;
585
586
587 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
588
589 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
590 if (Status == AE_TIME)
591 {
592 LogicalResult = TRUE; /* TRUE, Wait timed out */
593 Status = AE_OK;
594 }
595 break;
596
597 default:
598
599 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
600 WalkState->Opcode));
601 Status = AE_AML_BAD_OPCODE;
602 goto Cleanup;
603 }
604
605
606 StoreLogicalResult:
607 /*
608 * Set return value to according to LogicalResult. logical TRUE (all ones)
609 * Default is FALSE (zero)
610 */
611 if (LogicalResult)
612 {
613 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
614 }
615
616 Cleanup:
617
618 /* Delete return object on error */
619
620 if (ACPI_FAILURE (Status))
621 {
622 AcpiUtRemoveReference (ReturnDesc);
623 }
624
625 /* Save return object on success */
626
627 else
628 {
629 WalkState->ResultObj = ReturnDesc;
630 }
631
632 return_ACPI_STATUS (Status);
633 }
|