[ACPI] ACPICA 20060113
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / executer / exoparg1.c
1
2 /******************************************************************************
3 *
4 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2006, R. Byron Moore
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/amlcode.h>
50 #include <acpi/acnamesp.h>
51
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME("exoparg1")
54
55 /*!
56 * Naming convention for AML interpreter execution routines.
57 *
58 * The routines that begin execution of AML opcodes are named with a common
59 * convention based upon the number of arguments, the number of target operands,
60 * and whether or not a value is returned:
61 *
62 * AcpiExOpcode_xA_yT_zR
63 *
64 * Where:
65 *
66 * xA - ARGUMENTS: The number of arguments (input operands) that are
67 * required for this opcode type (0 through 6 args).
68 * yT - TARGETS: The number of targets (output operands) that are required
69 * for this opcode type (0, 1, or 2 targets).
70 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
71 * as the function return (0 or 1).
72 *
73 * The AcpiExOpcode* functions are called via the Dispatcher component with
74 * fully resolved operands.
75 !*/
76 /*******************************************************************************
77 *
78 * FUNCTION: acpi_ex_opcode_0A_0T_1R
79 *
80 * PARAMETERS: walk_state - Current state (contains AML opcode)
81 *
82 * RETURN: Status
83 *
84 * DESCRIPTION: Execute operator with no operands, one return value
85 *
86 ******************************************************************************/
87 acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
88 {
89 acpi_status status = AE_OK;
90 union acpi_operand_object *return_desc = NULL;
91
92 ACPI_FUNCTION_TRACE_STR("ex_opcode_0A_0T_1R",
93 acpi_ps_get_opcode_name(walk_state->opcode));
94
95 /* Examine the AML opcode */
96
97 switch (walk_state->opcode) {
98 case AML_TIMER_OP: /* Timer () */
99
100 /* Create a return object of type Integer */
101
102 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
103 if (!return_desc) {
104 status = AE_NO_MEMORY;
105 goto cleanup;
106 }
107 #if ACPI_MACHINE_WIDTH != 16
108 return_desc->integer.value = acpi_os_get_timer();
109 #endif
110 break;
111
112 default: /* Unknown opcode */
113
114 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n",
115 walk_state->opcode));
116 status = AE_AML_BAD_OPCODE;
117 break;
118 }
119
120 cleanup:
121
122 /* Delete return object on error */
123
124 if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
125 acpi_ut_remove_reference(return_desc);
126 } else {
127 /* Save the return value */
128
129 walk_state->result_obj = return_desc;
130 }
131
132 return_ACPI_STATUS(status);
133 }
134
135 /*******************************************************************************
136 *
137 * FUNCTION: acpi_ex_opcode_1A_0T_0R
138 *
139 * PARAMETERS: walk_state - Current state (contains AML opcode)
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
144 * object stack
145 *
146 ******************************************************************************/
147
148 acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
149 {
150 union acpi_operand_object **operand = &walk_state->operands[0];
151 acpi_status status = AE_OK;
152
153 ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_0R",
154 acpi_ps_get_opcode_name(walk_state->opcode));
155
156 /* Examine the AML opcode */
157
158 switch (walk_state->opcode) {
159 case AML_RELEASE_OP: /* Release (mutex_object) */
160
161 status = acpi_ex_release_mutex(operand[0], walk_state);
162 break;
163
164 case AML_RESET_OP: /* Reset (event_object) */
165
166 status = acpi_ex_system_reset_event(operand[0]);
167 break;
168
169 case AML_SIGNAL_OP: /* Signal (event_object) */
170
171 status = acpi_ex_system_signal_event(operand[0]);
172 break;
173
174 case AML_SLEEP_OP: /* Sleep (msec_time) */
175
176 status = acpi_ex_system_do_suspend(operand[0]->integer.value);
177 break;
178
179 case AML_STALL_OP: /* Stall (usec_time) */
180
181 status =
182 acpi_ex_system_do_stall((u32) operand[0]->integer.value);
183 break;
184
185 case AML_UNLOAD_OP: /* Unload (Handle) */
186
187 status = acpi_ex_unload_table(operand[0]);
188 break;
189
190 default: /* Unknown opcode */
191
192 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n",
193 walk_state->opcode));
194 status = AE_AML_BAD_OPCODE;
195 break;
196 }
197
198 return_ACPI_STATUS(status);
199 }
200
201 /*******************************************************************************
202 *
203 * FUNCTION: acpi_ex_opcode_1A_1T_0R
204 *
205 * PARAMETERS: walk_state - Current state (contains AML opcode)
206 *
207 * RETURN: Status
208 *
209 * DESCRIPTION: Execute opcode with one argument, one target, and no
210 * return value.
211 *
212 ******************************************************************************/
213
214 acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
215 {
216 acpi_status status = AE_OK;
217 union acpi_operand_object **operand = &walk_state->operands[0];
218
219 ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_1T_0R",
220 acpi_ps_get_opcode_name(walk_state->opcode));
221
222 /* Examine the AML opcode */
223
224 switch (walk_state->opcode) {
225 case AML_LOAD_OP:
226
227 status = acpi_ex_load_op(operand[0], operand[1], walk_state);
228 break;
229
230 default: /* Unknown opcode */
231
232 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n",
233 walk_state->opcode));
234 status = AE_AML_BAD_OPCODE;
235 goto cleanup;
236 }
237
238 cleanup:
239
240 return_ACPI_STATUS(status);
241 }
242
243 /*******************************************************************************
244 *
245 * FUNCTION: acpi_ex_opcode_1A_1T_1R
246 *
247 * PARAMETERS: walk_state - Current state (contains AML opcode)
248 *
249 * RETURN: Status
250 *
251 * DESCRIPTION: Execute opcode with one argument, one target, and a
252 * return value.
253 *
254 ******************************************************************************/
255
256 acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
257 {
258 acpi_status status = AE_OK;
259 union acpi_operand_object **operand = &walk_state->operands[0];
260 union acpi_operand_object *return_desc = NULL;
261 union acpi_operand_object *return_desc2 = NULL;
262 u32 temp32;
263 u32 i;
264 acpi_integer power_of_ten;
265 acpi_integer digit;
266
267 ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_1T_1R",
268 acpi_ps_get_opcode_name(walk_state->opcode));
269
270 /* Examine the AML opcode */
271
272 switch (walk_state->opcode) {
273 case AML_BIT_NOT_OP:
274 case AML_FIND_SET_LEFT_BIT_OP:
275 case AML_FIND_SET_RIGHT_BIT_OP:
276 case AML_FROM_BCD_OP:
277 case AML_TO_BCD_OP:
278 case AML_COND_REF_OF_OP:
279
280 /* Create a return object of type Integer for these opcodes */
281
282 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
283 if (!return_desc) {
284 status = AE_NO_MEMORY;
285 goto cleanup;
286 }
287
288 switch (walk_state->opcode) {
289 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
290
291 return_desc->integer.value = ~operand[0]->integer.value;
292 break;
293
294 case AML_FIND_SET_LEFT_BIT_OP: /* find_set_left_bit (Operand, Result) */
295
296 return_desc->integer.value = operand[0]->integer.value;
297
298 /*
299 * Acpi specification describes Integer type as a little
300 * endian unsigned value, so this boundary condition is valid.
301 */
302 for (temp32 = 0; return_desc->integer.value &&
303 temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
304 return_desc->integer.value >>= 1;
305 }
306
307 return_desc->integer.value = temp32;
308 break;
309
310 case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
311
312 return_desc->integer.value = operand[0]->integer.value;
313
314 /*
315 * The Acpi specification describes Integer type as a little
316 * endian unsigned value, so this boundary condition is valid.
317 */
318 for (temp32 = 0; return_desc->integer.value &&
319 temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
320 return_desc->integer.value <<= 1;
321 }
322
323 /* Since the bit position is one-based, subtract from 33 (65) */
324
325 return_desc->integer.value = temp32 == 0 ? 0 :
326 (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
327 break;
328
329 case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */
330
331 /*
332 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
333 * (if table is 32-bit, integer can hold 8 BCD characters)
334 * Convert each 4-bit BCD value
335 */
336 power_of_ten = 1;
337 return_desc->integer.value = 0;
338 digit = operand[0]->integer.value;
339
340 /* Convert each BCD digit (each is one nybble wide) */
341
342 for (i = 0;
343 (i < acpi_gbl_integer_nybble_width) && (digit > 0);
344 i++) {
345 /* Get the least significant 4-bit BCD digit */
346
347 temp32 = ((u32) digit) & 0xF;
348
349 /* Check the range of the digit */
350
351 if (temp32 > 9) {
352 ACPI_REPORT_ERROR(("BCD digit too large (not decimal): 0x%X\n", temp32));
353
354 status = AE_AML_NUMERIC_OVERFLOW;
355 goto cleanup;
356 }
357
358 /* Sum the digit into the result with the current power of 10 */
359
360 return_desc->integer.value +=
361 (((acpi_integer) temp32) * power_of_ten);
362
363 /* Shift to next BCD digit */
364
365 digit >>= 4;
366
367 /* Next power of 10 */
368
369 power_of_ten *= 10;
370 }
371 break;
372
373 case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */
374
375 return_desc->integer.value = 0;
376 digit = operand[0]->integer.value;
377
378 /* Each BCD digit is one nybble wide */
379
380 for (i = 0;
381 (i < acpi_gbl_integer_nybble_width) && (digit > 0);
382 i++) {
383 (void)acpi_ut_short_divide(digit, 10, &digit,
384 &temp32);
385
386 /*
387 * Insert the BCD digit that resides in the
388 * remainder from above
389 */
390 return_desc->integer.value |=
391 (((acpi_integer) temp32) << ACPI_MUL_4(i));
392 }
393
394 /* Overflow if there is any data left in Digit */
395
396 if (digit > 0) {
397 ACPI_REPORT_ERROR(("Integer too large to convert to BCD: %8.8X%8.8X\n", ACPI_FORMAT_UINT64(operand[0]->integer.value)));
398 status = AE_AML_NUMERIC_OVERFLOW;
399 goto cleanup;
400 }
401 break;
402
403 case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */
404
405 /*
406 * This op is a little strange because the internal return value is
407 * different than the return value stored in the result descriptor
408 * (There are really two return values)
409 */
410 if ((struct acpi_namespace_node *)operand[0] ==
411 acpi_gbl_root_node) {
412 /*
413 * This means that the object does not exist in the namespace,
414 * return FALSE
415 */
416 return_desc->integer.value = 0;
417 goto cleanup;
418 }
419
420 /* Get the object reference, store it, and remove our reference */
421
422 status = acpi_ex_get_object_reference(operand[0],
423 &return_desc2,
424 walk_state);
425 if (ACPI_FAILURE(status)) {
426 goto cleanup;
427 }
428
429 status =
430 acpi_ex_store(return_desc2, operand[1], walk_state);
431 acpi_ut_remove_reference(return_desc2);
432
433 /* The object exists in the namespace, return TRUE */
434
435 return_desc->integer.value = ACPI_INTEGER_MAX;
436 goto cleanup;
437
438 default:
439 /* No other opcodes get here */
440 break;
441 }
442 break;
443
444 case AML_STORE_OP: /* Store (Source, Target) */
445
446 /*
447 * A store operand is typically a number, string, buffer or lvalue
448 * Be careful about deleting the source object,
449 * since the object itself may have been stored.
450 */
451 status = acpi_ex_store(operand[0], operand[1], walk_state);
452 if (ACPI_FAILURE(status)) {
453 return_ACPI_STATUS(status);
454 }
455
456 /* It is possible that the Store already produced a return object */
457
458 if (!walk_state->result_obj) {
459 /*
460 * Normally, we would remove a reference on the Operand[0]
461 * parameter; But since it is being used as the internal return
462 * object (meaning we would normally increment it), the two
463 * cancel out, and we simply don't do anything.
464 */
465 walk_state->result_obj = operand[0];
466 walk_state->operands[0] = NULL; /* Prevent deletion */
467 }
468 return_ACPI_STATUS(status);
469
470 /*
471 * ACPI 2.0 Opcodes
472 */
473 case AML_COPY_OP: /* Copy (Source, Target) */
474
475 status =
476 acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
477 walk_state);
478 break;
479
480 case AML_TO_DECSTRING_OP: /* to_decimal_string (Data, Result) */
481
482 status = acpi_ex_convert_to_string(operand[0], &return_desc,
483 ACPI_EXPLICIT_CONVERT_DECIMAL);
484 if (return_desc == operand[0]) {
485 /* No conversion performed, add ref to handle return value */
486 acpi_ut_add_reference(return_desc);
487 }
488 break;
489
490 case AML_TO_HEXSTRING_OP: /* to_hex_string (Data, Result) */
491
492 status = acpi_ex_convert_to_string(operand[0], &return_desc,
493 ACPI_EXPLICIT_CONVERT_HEX);
494 if (return_desc == operand[0]) {
495 /* No conversion performed, add ref to handle return value */
496 acpi_ut_add_reference(return_desc);
497 }
498 break;
499
500 case AML_TO_BUFFER_OP: /* to_buffer (Data, Result) */
501
502 status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
503 if (return_desc == operand[0]) {
504 /* No conversion performed, add ref to handle return value */
505 acpi_ut_add_reference(return_desc);
506 }
507 break;
508
509 case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
510
511 status = acpi_ex_convert_to_integer(operand[0], &return_desc,
512 ACPI_ANY_BASE);
513 if (return_desc == operand[0]) {
514 /* No conversion performed, add ref to handle return value */
515 acpi_ut_add_reference(return_desc);
516 }
517 break;
518
519 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
520 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
521
522 /* These are two obsolete opcodes */
523
524 ACPI_REPORT_ERROR(("%s is obsolete and not implemented\n",
525 acpi_ps_get_opcode_name(walk_state->
526 opcode)));
527 status = AE_SUPPORT;
528 goto cleanup;
529
530 default: /* Unknown opcode */
531
532 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n",
533 walk_state->opcode));
534 status = AE_AML_BAD_OPCODE;
535 goto cleanup;
536 }
537
538 if (ACPI_SUCCESS(status)) {
539 /* Store the return value computed above into the target object */
540
541 status = acpi_ex_store(return_desc, operand[1], walk_state);
542 }
543
544 cleanup:
545
546 if (!walk_state->result_obj) {
547 walk_state->result_obj = return_desc;
548 }
549
550 /* Delete return object on error */
551
552 if (ACPI_FAILURE(status)) {
553 acpi_ut_remove_reference(return_desc);
554 }
555
556 return_ACPI_STATUS(status);
557 }
558
559 /*******************************************************************************
560 *
561 * FUNCTION: acpi_ex_opcode_1A_0T_1R
562 *
563 * PARAMETERS: walk_state - Current state (contains AML opcode)
564 *
565 * RETURN: Status
566 *
567 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
568 *
569 ******************************************************************************/
570
571 acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
572 {
573 union acpi_operand_object **operand = &walk_state->operands[0];
574 union acpi_operand_object *temp_desc;
575 union acpi_operand_object *return_desc = NULL;
576 acpi_status status = AE_OK;
577 u32 type;
578 acpi_integer value;
579
580 ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_1R",
581 acpi_ps_get_opcode_name(walk_state->opcode));
582
583 /* Examine the AML opcode */
584
585 switch (walk_state->opcode) {
586 case AML_LNOT_OP: /* LNot (Operand) */
587
588 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
589 if (!return_desc) {
590 status = AE_NO_MEMORY;
591 goto cleanup;
592 }
593
594 /*
595 * Set result to ONES (TRUE) if Value == 0. Note:
596 * return_desc->Integer.Value is initially == 0 (FALSE) from above.
597 */
598 if (!operand[0]->integer.value) {
599 return_desc->integer.value = ACPI_INTEGER_MAX;
600 }
601 break;
602
603 case AML_DECREMENT_OP: /* Decrement (Operand) */
604 case AML_INCREMENT_OP: /* Increment (Operand) */
605
606 /*
607 * Create a new integer. Can't just get the base integer and
608 * increment it because it may be an Arg or Field.
609 */
610 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
611 if (!return_desc) {
612 status = AE_NO_MEMORY;
613 goto cleanup;
614 }
615
616 /*
617 * Since we are expecting a Reference operand, it can be either a
618 * NS Node or an internal object.
619 */
620 temp_desc = operand[0];
621 if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
622 ACPI_DESC_TYPE_OPERAND) {
623 /* Internal reference object - prevent deletion */
624
625 acpi_ut_add_reference(temp_desc);
626 }
627
628 /*
629 * Convert the Reference operand to an Integer (This removes a
630 * reference on the Operand[0] object)
631 *
632 * NOTE: We use LNOT_OP here in order to force resolution of the
633 * reference operand to an actual integer.
634 */
635 status =
636 acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
637 walk_state);
638 if (ACPI_FAILURE(status)) {
639 ACPI_REPORT_ERROR(("%s: bad operand(s) %s\n",
640 acpi_ps_get_opcode_name(walk_state->
641 opcode),
642 acpi_format_exception(status)));
643
644 goto cleanup;
645 }
646
647 /*
648 * temp_desc is now guaranteed to be an Integer object --
649 * Perform the actual increment or decrement
650 */
651 if (walk_state->opcode == AML_INCREMENT_OP) {
652 return_desc->integer.value =
653 temp_desc->integer.value + 1;
654 } else {
655 return_desc->integer.value =
656 temp_desc->integer.value - 1;
657 }
658
659 /* Finished with this Integer object */
660
661 acpi_ut_remove_reference(temp_desc);
662
663 /*
664 * Store the result back (indirectly) through the original
665 * Reference object
666 */
667 status = acpi_ex_store(return_desc, operand[0], walk_state);
668 break;
669
670 case AML_TYPE_OP: /* object_type (source_object) */
671
672 /*
673 * Note: The operand is not resolved at this point because we want to
674 * get the associated object, not its value. For example, we don't
675 * want to resolve a field_unit to its value, we want the actual
676 * field_unit object.
677 */
678
679 /* Get the type of the base object */
680
681 status =
682 acpi_ex_resolve_multiple(walk_state, operand[0], &type,
683 NULL);
684 if (ACPI_FAILURE(status)) {
685 goto cleanup;
686 }
687 /* Allocate a descriptor to hold the type. */
688
689 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
690 if (!return_desc) {
691 status = AE_NO_MEMORY;
692 goto cleanup;
693 }
694
695 return_desc->integer.value = type;
696 break;
697
698 case AML_SIZE_OF_OP: /* size_of (source_object) */
699
700 /*
701 * Note: The operand is not resolved at this point because we want to
702 * get the associated object, not its value.
703 */
704
705 /* Get the base object */
706
707 status = acpi_ex_resolve_multiple(walk_state,
708 operand[0], &type,
709 &temp_desc);
710 if (ACPI_FAILURE(status)) {
711 goto cleanup;
712 }
713
714 /*
715 * The type of the base object must be integer, buffer, string, or
716 * package. All others are not supported.
717 *
718 * NOTE: Integer is not specifically supported by the ACPI spec,
719 * but is supported implicitly via implicit operand conversion.
720 * rather than bother with conversion, we just use the byte width
721 * global (4 or 8 bytes).
722 */
723 switch (type) {
724 case ACPI_TYPE_INTEGER:
725 value = acpi_gbl_integer_byte_width;
726 break;
727
728 case ACPI_TYPE_BUFFER:
729 value = temp_desc->buffer.length;
730 break;
731
732 case ACPI_TYPE_STRING:
733 value = temp_desc->string.length;
734 break;
735
736 case ACPI_TYPE_PACKAGE:
737 value = temp_desc->package.count;
738 break;
739
740 default:
741 ACPI_REPORT_ERROR(("Operand is not Buf/Int/Str/Pkg - found type %s\n", acpi_ut_get_type_name(type)));
742 status = AE_AML_OPERAND_TYPE;
743 goto cleanup;
744 }
745
746 /*
747 * Now that we have the size of the object, create a result
748 * object to hold the value
749 */
750 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
751 if (!return_desc) {
752 status = AE_NO_MEMORY;
753 goto cleanup;
754 }
755
756 return_desc->integer.value = value;
757 break;
758
759 case AML_REF_OF_OP: /* ref_of (source_object) */
760
761 status =
762 acpi_ex_get_object_reference(operand[0], &return_desc,
763 walk_state);
764 if (ACPI_FAILURE(status)) {
765 goto cleanup;
766 }
767 break;
768
769 case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */
770
771 /* Check for a method local or argument, or standalone String */
772
773 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
774 ACPI_DESC_TYPE_NAMED) {
775 switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
776 case ACPI_TYPE_LOCAL_REFERENCE:
777 /*
778 * This is a deref_of (local_x | arg_x)
779 *
780 * Must resolve/dereference the local/arg reference first
781 */
782 switch (operand[0]->reference.opcode) {
783 case AML_LOCAL_OP:
784 case AML_ARG_OP:
785
786 /* Set Operand[0] to the value of the local/arg */
787
788 status =
789 acpi_ds_method_data_get_value
790 (operand[0]->reference.opcode,
791 operand[0]->reference.offset,
792 walk_state, &temp_desc);
793 if (ACPI_FAILURE(status)) {
794 goto cleanup;
795 }
796
797 /*
798 * Delete our reference to the input object and
799 * point to the object just retrieved
800 */
801 acpi_ut_remove_reference(operand[0]);
802 operand[0] = temp_desc;
803 break;
804
805 case AML_REF_OF_OP:
806
807 /* Get the object to which the reference refers */
808
809 temp_desc =
810 operand[0]->reference.object;
811 acpi_ut_remove_reference(operand[0]);
812 operand[0] = temp_desc;
813 break;
814
815 default:
816
817 /* Must be an Index op - handled below */
818 break;
819 }
820 break;
821
822 case ACPI_TYPE_STRING:
823
824 /*
825 * This is a deref_of (String). The string is a reference
826 * to a named ACPI object.
827 *
828 * 1) Find the owning Node
829 * 2) Dereference the node to an actual object. Could be a
830 * Field, so we need to resolve the node to a value.
831 */
832 status =
833 acpi_ns_get_node_by_path(operand[0]->string.
834 pointer,
835 walk_state->
836 scope_info->scope.
837 node,
838 ACPI_NS_SEARCH_PARENT,
839 ACPI_CAST_INDIRECT_PTR
840 (struct
841 acpi_namespace_node,
842 &return_desc));
843 if (ACPI_FAILURE(status)) {
844 goto cleanup;
845 }
846
847 status =
848 acpi_ex_resolve_node_to_value
849 (ACPI_CAST_INDIRECT_PTR
850 (struct acpi_namespace_node, &return_desc),
851 walk_state);
852 goto cleanup;
853
854 default:
855
856 status = AE_AML_OPERAND_TYPE;
857 goto cleanup;
858 }
859 }
860
861 /* Operand[0] may have changed from the code above */
862
863 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
864 ACPI_DESC_TYPE_NAMED) {
865 /*
866 * This is a deref_of (object_reference)
867 * Get the actual object from the Node (This is the dereference).
868 * This case may only happen when a local_x or arg_x is
869 * dereferenced above.
870 */
871 return_desc = acpi_ns_get_attached_object((struct
872 acpi_namespace_node
873 *)
874 operand[0]);
875 acpi_ut_add_reference(return_desc);
876 } else {
877 /*
878 * This must be a reference object produced by either the
879 * Index() or ref_of() operator
880 */
881 switch (operand[0]->reference.opcode) {
882 case AML_INDEX_OP:
883
884 /*
885 * The target type for the Index operator must be
886 * either a Buffer or a Package
887 */
888 switch (operand[0]->reference.target_type) {
889 case ACPI_TYPE_BUFFER_FIELD:
890
891 temp_desc =
892 operand[0]->reference.object;
893
894 /*
895 * Create a new object that contains one element of the
896 * buffer -- the element pointed to by the index.
897 *
898 * NOTE: index into a buffer is NOT a pointer to a
899 * sub-buffer of the main buffer, it is only a pointer to a
900 * single element (byte) of the buffer!
901 */
902 return_desc =
903 acpi_ut_create_internal_object
904 (ACPI_TYPE_INTEGER);
905 if (!return_desc) {
906 status = AE_NO_MEMORY;
907 goto cleanup;
908 }
909
910 /*
911 * Since we are returning the value of the buffer at the
912 * indexed location, we don't need to add an additional
913 * reference to the buffer itself.
914 */
915 return_desc->integer.value =
916 temp_desc->buffer.
917 pointer[operand[0]->reference.
918 offset];
919 break;
920
921 case ACPI_TYPE_PACKAGE:
922
923 /*
924 * Return the referenced element of the package. We must
925 * add another reference to the referenced object, however.
926 */
927 return_desc =
928 *(operand[0]->reference.where);
929 if (return_desc) {
930 acpi_ut_add_reference
931 (return_desc);
932 }
933
934 break;
935
936 default:
937
938 ACPI_REPORT_ERROR(("Unknown Index target_type %X in obj %p\n", operand[0]->reference.target_type, operand[0]));
939 status = AE_AML_OPERAND_TYPE;
940 goto cleanup;
941 }
942 break;
943
944 case AML_REF_OF_OP:
945
946 return_desc = operand[0]->reference.object;
947
948 if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
949 ACPI_DESC_TYPE_NAMED) {
950
951 return_desc =
952 acpi_ns_get_attached_object((struct
953 acpi_namespace_node
954 *)
955 return_desc);
956 }
957
958 /* Add another reference to the object! */
959
960 acpi_ut_add_reference(return_desc);
961 break;
962
963 default:
964 ACPI_REPORT_ERROR(("Unknown opcode in ref(%p) - %X\n", operand[0], operand[0]->reference.opcode));
965
966 status = AE_TYPE;
967 goto cleanup;
968 }
969 }
970 break;
971
972 default:
973
974 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n",
975 walk_state->opcode));
976 status = AE_AML_BAD_OPCODE;
977 goto cleanup;
978 }
979
980 cleanup:
981
982 /* Delete return object on error */
983
984 if (ACPI_FAILURE(status)) {
985 acpi_ut_remove_reference(return_desc);
986 }
987
988 walk_state->result_obj = return_desc;
989 return_ACPI_STATUS(status);
990 }