aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/executer/exresop.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/executer/exresop.c')
-rw-r--r--drivers/acpi/executer/exresop.c661
1 files changed, 661 insertions, 0 deletions
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
new file mode 100644
index 000000000000..c92890220c32
--- /dev/null
+++ b/drivers/acpi/executer/exresop.c
@@ -0,0 +1,661 @@
1
2/******************************************************************************
3 *
4 * Module Name: exresop - AML Interpreter operand/object resolution
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, 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
46#include <acpi/acpi.h>
47#include <acpi/amlcode.h>
48#include <acpi/acparser.h>
49#include <acpi/acinterp.h>
50
51
52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop")
54
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ex_check_object_type
59 *
60 * PARAMETERS: type_needed Object type needed
61 * this_type Actual object type
62 * Object Object pointer
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Check required type against actual type
67 *
68 ******************************************************************************/
69
70acpi_status
71acpi_ex_check_object_type (
72 acpi_object_type type_needed,
73 acpi_object_type this_type,
74 void *object)
75{
76 ACPI_FUNCTION_NAME ("ex_check_object_type");
77
78
79 if (type_needed == ACPI_TYPE_ANY) {
80 /* All types OK, so we don't perform any typechecks */
81
82 return (AE_OK);
83 }
84
85 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
86 /*
87 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
88 * objects and thus allow them to be targets. (As per the ACPI
89 * specification, a store to a constant is a noop.)
90 */
91 if ((this_type == ACPI_TYPE_INTEGER) &&
92 (((union acpi_operand_object *) object)->common.flags & AOPOBJ_AML_CONSTANT)) {
93 return (AE_OK);
94 }
95 }
96
97 if (type_needed != this_type) {
98 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
99 "Needed [%s], found [%s] %p\n",
100 acpi_ut_get_type_name (type_needed),
101 acpi_ut_get_type_name (this_type), object));
102
103 return (AE_AML_OPERAND_TYPE);
104 }
105
106 return (AE_OK);
107}
108
109
110/*******************************************************************************
111 *
112 * FUNCTION: acpi_ex_resolve_operands
113 *
114 * PARAMETERS: Opcode - Opcode being interpreted
115 * stack_ptr - Pointer to the operand stack to be
116 * resolved
117 * walk_state - Current state
118 *
119 * RETURN: Status
120 *
121 * DESCRIPTION: Convert multiple input operands to the types required by the
122 * target operator.
123 *
124 * Each 5-bit group in arg_types represents one required
125 * operand and indicates the required Type. The corresponding operand
126 * will be converted to the required type if possible, otherwise we
127 * abort with an exception.
128 *
129 ******************************************************************************/
130
131acpi_status
132acpi_ex_resolve_operands (
133 u16 opcode,
134 union acpi_operand_object **stack_ptr,
135 struct acpi_walk_state *walk_state)
136{
137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
139 u8 object_type;
140 void *temp_node;
141 u32 arg_types;
142 const struct acpi_opcode_info *op_info;
143 u32 this_arg_type;
144 acpi_object_type type_needed;
145
146
147 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
148
149
150 op_info = acpi_ps_get_opcode_info (opcode);
151 if (op_info->class == AML_CLASS_UNKNOWN) {
152 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
153 }
154
155 arg_types = op_info->runtime_args;
156 if (arg_types == ARGI_INVALID_OPCODE) {
157 ACPI_REPORT_ERROR (("resolve_operands: %X is not a valid AML opcode\n",
158 opcode));
159
160 return_ACPI_STATUS (AE_AML_INTERNAL);
161 }
162
163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] required_operand_types=%8.8X \n",
164 opcode, op_info->name, arg_types));
165
166 /*
167 * Normal exit is with (arg_types == 0) at end of argument list.
168 * Function will return an exception from within the loop upon
169 * finding an entry which is not (or cannot be converted
170 * to) the required type; if stack underflows; or upon
171 * finding a NULL stack entry (which should not happen).
172 */
173 while (GET_CURRENT_ARG_TYPE (arg_types)) {
174 if (!stack_ptr || !*stack_ptr) {
175 ACPI_REPORT_ERROR (("resolve_operands: Null stack entry at %p\n",
176 stack_ptr));
177
178 return_ACPI_STATUS (AE_AML_INTERNAL);
179 }
180
181 /* Extract useful items */
182
183 obj_desc = *stack_ptr;
184
185 /* Decode the descriptor type */
186
187 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
188 case ACPI_DESC_TYPE_NAMED:
189
190 /* Node */
191
192 object_type = ((struct acpi_namespace_node *) obj_desc)->type;
193 break;
194
195
196 case ACPI_DESC_TYPE_OPERAND:
197
198 /* ACPI internal object */
199
200 object_type = ACPI_GET_OBJECT_TYPE (obj_desc);
201
202 /* Check for bad acpi_object_type */
203
204 if (!acpi_ut_valid_object_type (object_type)) {
205 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n",
206 object_type));
207
208 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
209 }
210
211 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
212 /*
213 * Decode the Reference
214 */
215 op_info = acpi_ps_get_opcode_info (opcode);
216 if (op_info->class == AML_CLASS_UNKNOWN) {
217 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
218 }
219
220 switch (obj_desc->reference.opcode) {
221 case AML_DEBUG_OP:
222 case AML_NAME_OP:
223 case AML_INDEX_OP:
224 case AML_REF_OF_OP:
225 case AML_ARG_OP:
226 case AML_LOCAL_OP:
227 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
228
229 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "Operand is a Reference, ref_opcode [%s]\n",
231 (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name)));
232 break;
233
234 default:
235 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
236 "Operand is a Reference, Unknown Reference Opcode %X [%s]\n",
237 obj_desc->reference.opcode,
238 (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name));
239
240 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
241 }
242 }
243 break;
244
245
246 default:
247
248 /* Invalid descriptor */
249
250 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
251 "Invalid descriptor %p [%s]\n",
252 obj_desc, acpi_ut_get_descriptor_name (obj_desc)));
253
254 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
255 }
256
257
258 /*
259 * Get one argument type, point to the next
260 */
261 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types);
262 INCREMENT_ARG_LIST (arg_types);
263
264 /*
265 * Handle cases where the object does not need to be
266 * resolved to a value
267 */
268 switch (this_arg_type) {
269 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
270
271 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) &&
272 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) {
273 /*
274 * String found - the string references a named object and must be
275 * resolved to a node
276 */
277 goto next_operand;
278 }
279
280 /* Else not a string - fall through to the normal Reference case below */
281 /*lint -fallthrough */
282
283 case ARGI_REFERENCE: /* References: */
284 case ARGI_INTEGER_REF:
285 case ARGI_OBJECT_REF:
286 case ARGI_DEVICE_REF:
287 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
288 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
289 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
290
291 /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
292
293 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */ {
294 goto next_operand;
295 }
296
297 status = acpi_ex_check_object_type (ACPI_TYPE_LOCAL_REFERENCE,
298 object_type, obj_desc);
299 if (ACPI_FAILURE (status)) {
300 return_ACPI_STATUS (status);
301 }
302
303 if (AML_NAME_OP == obj_desc->reference.opcode) {
304 /*
305 * Convert an indirect name ptr to direct name ptr and put
306 * it on the stack
307 */
308 temp_node = obj_desc->reference.object;
309 acpi_ut_remove_reference (obj_desc);
310 (*stack_ptr) = temp_node;
311 }
312 goto next_operand;
313
314
315 case ARGI_DATAREFOBJ: /* Store operator only */
316
317 /*
318 * We don't want to resolve index_op reference objects during
319 * a store because this would be an implicit de_ref_of operation.
320 * Instead, we just want to store the reference object.
321 * -- All others must be resolved below.
322 */
323 if ((opcode == AML_STORE_OP) &&
324 (ACPI_GET_OBJECT_TYPE (*stack_ptr) == ACPI_TYPE_LOCAL_REFERENCE) &&
325 ((*stack_ptr)->reference.opcode == AML_INDEX_OP)) {
326 goto next_operand;
327 }
328 break;
329
330 default:
331 /* All cases covered above */
332 break;
333 }
334
335
336 /*
337 * Resolve this object to a value
338 */
339 status = acpi_ex_resolve_to_value (stack_ptr, walk_state);
340 if (ACPI_FAILURE (status)) {
341 return_ACPI_STATUS (status);
342 }
343
344 /* Get the resolved object */
345
346 obj_desc = *stack_ptr;
347
348 /*
349 * Check the resulting object (value) type
350 */
351 switch (this_arg_type) {
352 /*
353 * For the simple cases, only one type of resolved object
354 * is allowed
355 */
356 case ARGI_MUTEX:
357
358 /* Need an operand of type ACPI_TYPE_MUTEX */
359
360 type_needed = ACPI_TYPE_MUTEX;
361 break;
362
363 case ARGI_EVENT:
364
365 /* Need an operand of type ACPI_TYPE_EVENT */
366
367 type_needed = ACPI_TYPE_EVENT;
368 break;
369
370 case ARGI_PACKAGE: /* Package */
371
372 /* Need an operand of type ACPI_TYPE_PACKAGE */
373
374 type_needed = ACPI_TYPE_PACKAGE;
375 break;
376
377 case ARGI_ANYTYPE:
378
379 /* Any operand type will do */
380
381 type_needed = ACPI_TYPE_ANY;
382 break;
383
384 case ARGI_DDBHANDLE:
385
386 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
387
388 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
389 break;
390
391
392 /*
393 * The more complex cases allow multiple resolved object types
394 */
395 case ARGI_INTEGER: /* Number */
396
397 /*
398 * Need an operand of type ACPI_TYPE_INTEGER,
399 * But we can implicitly convert from a STRING or BUFFER
400 * Aka - "Implicit Source Operand Conversion"
401 */
402 status = acpi_ex_convert_to_integer (obj_desc, stack_ptr, 16);
403 if (ACPI_FAILURE (status)) {
404 if (status == AE_TYPE) {
405 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
406 "Needed [Integer/String/Buffer], found [%s] %p\n",
407 acpi_ut_get_object_type_name (obj_desc), obj_desc));
408
409 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
410 }
411
412 return_ACPI_STATUS (status);
413 }
414 goto next_operand;
415
416
417 case ARGI_BUFFER:
418
419 /*
420 * Need an operand of type ACPI_TYPE_BUFFER,
421 * But we can implicitly convert from a STRING or INTEGER
422 * Aka - "Implicit Source Operand Conversion"
423 */
424 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr);
425 if (ACPI_FAILURE (status)) {
426 if (status == AE_TYPE) {
427 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
428 "Needed [Integer/String/Buffer], found [%s] %p\n",
429 acpi_ut_get_object_type_name (obj_desc), obj_desc));
430
431 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
432 }
433
434 return_ACPI_STATUS (status);
435 }
436 goto next_operand;
437
438
439 case ARGI_STRING:
440
441 /*
442 * Need an operand of type ACPI_TYPE_STRING,
443 * But we can implicitly convert from a BUFFER or INTEGER
444 * Aka - "Implicit Source Operand Conversion"
445 */
446 status = acpi_ex_convert_to_string (obj_desc, stack_ptr,
447 ACPI_IMPLICIT_CONVERT_HEX);
448 if (ACPI_FAILURE (status)) {
449 if (status == AE_TYPE) {
450 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
451 "Needed [Integer/String/Buffer], found [%s] %p\n",
452 acpi_ut_get_object_type_name (obj_desc), obj_desc));
453
454 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
455 }
456
457 return_ACPI_STATUS (status);
458 }
459 goto next_operand;
460
461
462 case ARGI_COMPUTEDATA:
463
464 /* Need an operand of type INTEGER, STRING or BUFFER */
465
466 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
467 case ACPI_TYPE_INTEGER:
468 case ACPI_TYPE_STRING:
469 case ACPI_TYPE_BUFFER:
470
471 /* Valid operand */
472 break;
473
474 default:
475 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
476 "Needed [Integer/String/Buffer], found [%s] %p\n",
477 acpi_ut_get_object_type_name (obj_desc), obj_desc));
478
479 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
480 }
481 goto next_operand;
482
483
484 case ARGI_BUFFER_OR_STRING:
485
486 /* Need an operand of type STRING or BUFFER */
487
488 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
489 case ACPI_TYPE_STRING:
490 case ACPI_TYPE_BUFFER:
491
492 /* Valid operand */
493 break;
494
495 case ACPI_TYPE_INTEGER:
496
497 /* Highest priority conversion is to type Buffer */
498
499 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr);
500 if (ACPI_FAILURE (status)) {
501 return_ACPI_STATUS (status);
502 }
503 break;
504
505 default:
506 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
507 "Needed [Integer/String/Buffer], found [%s] %p\n",
508 acpi_ut_get_object_type_name (obj_desc), obj_desc));
509
510 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
511 }
512 goto next_operand;
513
514
515 case ARGI_DATAOBJECT:
516 /*
517 * ARGI_DATAOBJECT is only used by the size_of operator.
518 * Need a buffer, string, package, or ref_of reference.
519 *
520 * The only reference allowed here is a direct reference to
521 * a namespace node.
522 */
523 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
524 case ACPI_TYPE_PACKAGE:
525 case ACPI_TYPE_STRING:
526 case ACPI_TYPE_BUFFER:
527 case ACPI_TYPE_LOCAL_REFERENCE:
528
529 /* Valid operand */
530 break;
531
532 default:
533 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
534 "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
535 acpi_ut_get_object_type_name (obj_desc), obj_desc));
536
537 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
538 }
539 goto next_operand;
540
541
542 case ARGI_COMPLEXOBJ:
543
544 /* Need a buffer or package or (ACPI 2.0) String */
545
546 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
547 case ACPI_TYPE_PACKAGE:
548 case ACPI_TYPE_STRING:
549 case ACPI_TYPE_BUFFER:
550
551 /* Valid operand */
552 break;
553
554 default:
555 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
556 "Needed [Buffer/String/Package], found [%s] %p\n",
557 acpi_ut_get_object_type_name (obj_desc), obj_desc));
558
559 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
560 }
561 goto next_operand;
562
563
564 case ARGI_REGION_OR_FIELD:
565
566 /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */
567
568 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
569 case ACPI_TYPE_REGION:
570 case ACPI_TYPE_LOCAL_REGION_FIELD:
571 case ACPI_TYPE_LOCAL_BANK_FIELD:
572 case ACPI_TYPE_LOCAL_INDEX_FIELD:
573
574 /* Valid operand */
575 break;
576
577 default:
578 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
579 "Needed [Region/region_field], found [%s] %p\n",
580 acpi_ut_get_object_type_name (obj_desc), obj_desc));
581
582 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
583 }
584 goto next_operand;
585
586
587 case ARGI_DATAREFOBJ:
588
589 /* Used by the Store() operator only */
590
591 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
592 case ACPI_TYPE_INTEGER:
593 case ACPI_TYPE_PACKAGE:
594 case ACPI_TYPE_STRING:
595 case ACPI_TYPE_BUFFER:
596 case ACPI_TYPE_BUFFER_FIELD:
597 case ACPI_TYPE_LOCAL_REFERENCE:
598 case ACPI_TYPE_LOCAL_REGION_FIELD:
599 case ACPI_TYPE_LOCAL_BANK_FIELD:
600 case ACPI_TYPE_LOCAL_INDEX_FIELD:
601 case ACPI_TYPE_DDB_HANDLE:
602
603 /* Valid operand */
604 break;
605
606 default:
607
608 if (acpi_gbl_enable_interpreter_slack) {
609 /*
610 * Enable original behavior of Store(), allowing any and all
611 * objects as the source operand. The ACPI spec does not
612 * allow this, however.
613 */
614 break;
615 }
616
617 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
618 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
619 acpi_ut_get_object_type_name (obj_desc), obj_desc));
620
621 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
622 }
623 goto next_operand;
624
625
626 default:
627
628 /* Unknown type */
629
630 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
631 "Internal - Unknown ARGI (required operand) type %X\n",
632 this_arg_type));
633
634 return_ACPI_STATUS (AE_BAD_PARAMETER);
635 }
636
637 /*
638 * Make sure that the original object was resolved to the
639 * required object type (Simple cases only).
640 */
641 status = acpi_ex_check_object_type (type_needed,
642 ACPI_GET_OBJECT_TYPE (*stack_ptr), *stack_ptr);
643 if (ACPI_FAILURE (status)) {
644 return_ACPI_STATUS (status);
645 }
646
647next_operand:
648 /*
649 * If more operands needed, decrement stack_ptr to point
650 * to next operand on stack
651 */
652 if (GET_CURRENT_ARG_TYPE (arg_types)) {
653 stack_ptr--;
654 }
655
656 } /* while (*Types) */
657
658 return_ACPI_STATUS (status);
659}
660
661