x86/boot: Rename overlapping memcpy() to memmove()
[linux/fpc-iii.git] / drivers / acpi / acpica / exresop.c
blobcc2c26c46a6d6aa4a75224834da742acaf588e5b
1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "amlcode.h"
47 #include "acparser.h"
48 #include "acinterp.h"
49 #include "acnamesp.h"
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME("exresop")
54 /* Local prototypes */
55 static acpi_status
56 acpi_ex_check_object_type(acpi_object_type type_needed,
57 acpi_object_type this_type, void *object);
59 /*******************************************************************************
61 * FUNCTION: acpi_ex_check_object_type
63 * PARAMETERS: type_needed Object type needed
64 * this_type Actual object type
65 * Object Object pointer
67 * RETURN: Status
69 * DESCRIPTION: Check required type against actual type
71 ******************************************************************************/
73 static acpi_status
74 acpi_ex_check_object_type(acpi_object_type type_needed,
75 acpi_object_type this_type, void *object)
77 ACPI_FUNCTION_ENTRY();
79 if (type_needed == ACPI_TYPE_ANY) {
81 /* All types OK, so we don't perform any typechecks */
83 return (AE_OK);
86 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
88 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
89 * objects and thus allow them to be targets. (As per the ACPI
90 * specification, a store to a constant is a noop.)
92 if ((this_type == ACPI_TYPE_INTEGER) &&
93 (((union acpi_operand_object *)object)->common.flags &
94 AOPOBJ_AML_CONSTANT)) {
95 return (AE_OK);
99 if (type_needed != this_type) {
100 ACPI_ERROR((AE_INFO,
101 "Needed type [%s], found [%s] %p",
102 acpi_ut_get_type_name(type_needed),
103 acpi_ut_get_type_name(this_type), object));
105 return (AE_AML_OPERAND_TYPE);
108 return (AE_OK);
111 /*******************************************************************************
113 * FUNCTION: acpi_ex_resolve_operands
115 * PARAMETERS: opcode - Opcode being interpreted
116 * stack_ptr - Pointer to the operand stack to be
117 * resolved
118 * walk_state - Current state
120 * RETURN: Status
122 * DESCRIPTION: Convert multiple input operands to the types required by the
123 * target operator.
125 * Each 5-bit group in arg_types represents one required
126 * operand and indicates the required Type. The corresponding operand
127 * will be converted to the required type if possible, otherwise we
128 * abort with an exception.
130 ******************************************************************************/
132 acpi_status
133 acpi_ex_resolve_operands(u16 opcode,
134 union acpi_operand_object ** stack_ptr,
135 struct acpi_walk_state * walk_state)
137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
139 u8 object_type;
140 u32 arg_types;
141 const struct acpi_opcode_info *op_info;
142 u32 this_arg_type;
143 acpi_object_type type_needed;
144 u16 target_op = 0;
146 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
148 op_info = acpi_ps_get_opcode_info(opcode);
149 if (op_info->class == AML_CLASS_UNKNOWN) {
150 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
153 arg_types = op_info->runtime_args;
154 if (arg_types == ARGI_INVALID_OPCODE) {
155 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
157 return_ACPI_STATUS(AE_AML_INTERNAL);
160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
161 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
162 opcode, op_info->name, arg_types));
165 * Normal exit is with (arg_types == 0) at end of argument list.
166 * Function will return an exception from within the loop upon
167 * finding an entry which is not (or cannot be converted
168 * to) the required type; if stack underflows; or upon
169 * finding a NULL stack entry (which should not happen).
171 while (GET_CURRENT_ARG_TYPE(arg_types)) {
172 if (!stack_ptr || !*stack_ptr) {
173 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
174 stack_ptr));
176 return_ACPI_STATUS(AE_AML_INTERNAL);
179 /* Extract useful items */
181 obj_desc = *stack_ptr;
183 /* Decode the descriptor type */
185 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
186 case ACPI_DESC_TYPE_NAMED:
188 /* Namespace Node */
190 object_type =
191 ((struct acpi_namespace_node *)obj_desc)->type;
194 * Resolve an alias object. The construction of these objects
195 * guarantees that there is only one level of alias indirection;
196 * thus, the attached object is always the aliased namespace node
198 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
199 obj_desc = acpi_ns_get_attached_object((struct
200 acpi_namespace_node
202 obj_desc);
203 *stack_ptr = obj_desc;
204 object_type =
205 ((struct acpi_namespace_node *)obj_desc)->
206 type;
208 break;
210 case ACPI_DESC_TYPE_OPERAND:
212 /* ACPI internal object */
214 object_type = obj_desc->common.type;
216 /* Check for bad acpi_object_type */
218 if (!acpi_ut_valid_object_type(object_type)) {
219 ACPI_ERROR((AE_INFO,
220 "Bad operand object type [0x%X]",
221 object_type));
223 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
226 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
228 /* Validate the Reference */
230 switch (obj_desc->reference.class) {
231 case ACPI_REFCLASS_DEBUG:
233 target_op = AML_DEBUG_OP;
235 /*lint -fallthrough */
237 case ACPI_REFCLASS_ARG:
238 case ACPI_REFCLASS_LOCAL:
239 case ACPI_REFCLASS_INDEX:
240 case ACPI_REFCLASS_REFOF:
241 case ACPI_REFCLASS_TABLE: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
242 case ACPI_REFCLASS_NAME: /* Reference to a named object */
244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
245 "Operand is a Reference, Class [%s] %2.2X\n",
246 acpi_ut_get_reference_name
247 (obj_desc),
248 obj_desc->reference.
249 class));
250 break;
252 default:
254 ACPI_ERROR((AE_INFO,
255 "Unknown Reference Class 0x%2.2X in %p",
256 obj_desc->reference.class,
257 obj_desc));
259 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
262 break;
264 default:
266 /* Invalid descriptor */
268 ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
269 obj_desc,
270 acpi_ut_get_descriptor_name(obj_desc)));
272 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
275 /* Get one argument type, point to the next */
277 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
278 INCREMENT_ARG_LIST(arg_types);
281 * Handle cases where the object does not need to be
282 * resolved to a value
284 switch (this_arg_type) {
285 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
287 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
288 ACPI_DESC_TYPE_OPERAND) &&
289 (obj_desc->common.type == ACPI_TYPE_STRING)) {
291 * String found - the string references a named object and
292 * must be resolved to a node
294 goto next_operand;
298 * Else not a string - fall through to the normal Reference
299 * case below
301 /*lint -fallthrough */
303 case ARGI_REFERENCE: /* References: */
304 case ARGI_INTEGER_REF:
305 case ARGI_OBJECT_REF:
306 case ARGI_DEVICE_REF:
307 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
308 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
309 case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */
310 case ARGI_STORE_TARGET:
313 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
314 * A Namespace Node is OK as-is
316 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
317 ACPI_DESC_TYPE_NAMED) {
318 goto next_operand;
321 status =
322 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
323 object_type, obj_desc);
324 if (ACPI_FAILURE(status)) {
325 return_ACPI_STATUS(status);
327 goto next_operand;
329 case ARGI_DATAREFOBJ: /* Store operator only */
331 * We don't want to resolve index_op reference objects during
332 * a store because this would be an implicit de_ref_of operation.
333 * Instead, we just want to store the reference object.
334 * -- All others must be resolved below.
336 if ((opcode == AML_STORE_OP) &&
337 ((*stack_ptr)->common.type ==
338 ACPI_TYPE_LOCAL_REFERENCE)
339 && ((*stack_ptr)->reference.class ==
340 ACPI_REFCLASS_INDEX)) {
341 goto next_operand;
343 break;
345 default:
347 /* All cases covered above */
349 break;
353 * Resolve this object to a value
355 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
356 if (ACPI_FAILURE(status)) {
357 return_ACPI_STATUS(status);
360 /* Get the resolved object */
362 obj_desc = *stack_ptr;
365 * Check the resulting object (value) type
367 switch (this_arg_type) {
369 * For the simple cases, only one type of resolved object
370 * is allowed
372 case ARGI_MUTEX:
374 /* Need an operand of type ACPI_TYPE_MUTEX */
376 type_needed = ACPI_TYPE_MUTEX;
377 break;
379 case ARGI_EVENT:
381 /* Need an operand of type ACPI_TYPE_EVENT */
383 type_needed = ACPI_TYPE_EVENT;
384 break;
386 case ARGI_PACKAGE: /* Package */
388 /* Need an operand of type ACPI_TYPE_PACKAGE */
390 type_needed = ACPI_TYPE_PACKAGE;
391 break;
393 case ARGI_ANYTYPE:
395 /* Any operand type will do */
397 type_needed = ACPI_TYPE_ANY;
398 break;
400 case ARGI_DDBHANDLE:
402 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
404 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
405 break;
408 * The more complex cases allow multiple resolved object types
410 case ARGI_INTEGER:
413 * Need an operand of type ACPI_TYPE_INTEGER,
414 * But we can implicitly convert from a STRING or BUFFER
415 * aka - "Implicit Source Operand Conversion"
417 status =
418 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
419 if (ACPI_FAILURE(status)) {
420 if (status == AE_TYPE) {
421 ACPI_ERROR((AE_INFO,
422 "Needed [Integer/String/Buffer], found [%s] %p",
423 acpi_ut_get_object_type_name
424 (obj_desc), obj_desc));
426 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
429 return_ACPI_STATUS(status);
432 if (obj_desc != *stack_ptr) {
433 acpi_ut_remove_reference(obj_desc);
435 goto next_operand;
437 case ARGI_BUFFER:
439 * Need an operand of type ACPI_TYPE_BUFFER,
440 * But we can implicitly convert from a STRING or INTEGER
441 * aka - "Implicit Source Operand Conversion"
443 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
444 if (ACPI_FAILURE(status)) {
445 if (status == AE_TYPE) {
446 ACPI_ERROR((AE_INFO,
447 "Needed [Integer/String/Buffer], found [%s] %p",
448 acpi_ut_get_object_type_name
449 (obj_desc), obj_desc));
451 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
454 return_ACPI_STATUS(status);
457 if (obj_desc != *stack_ptr) {
458 acpi_ut_remove_reference(obj_desc);
460 goto next_operand;
462 case ARGI_STRING:
464 * Need an operand of type ACPI_TYPE_STRING,
465 * But we can implicitly convert from a BUFFER or INTEGER
466 * aka - "Implicit Source Operand Conversion"
468 status =
469 acpi_ex_convert_to_string(obj_desc, stack_ptr,
470 ACPI_IMPLICIT_CONVERT_HEX);
471 if (ACPI_FAILURE(status)) {
472 if (status == AE_TYPE) {
473 ACPI_ERROR((AE_INFO,
474 "Needed [Integer/String/Buffer], found [%s] %p",
475 acpi_ut_get_object_type_name
476 (obj_desc), obj_desc));
478 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
481 return_ACPI_STATUS(status);
484 if (obj_desc != *stack_ptr) {
485 acpi_ut_remove_reference(obj_desc);
487 goto next_operand;
489 case ARGI_COMPUTEDATA:
491 /* Need an operand of type INTEGER, STRING or BUFFER */
493 switch (obj_desc->common.type) {
494 case ACPI_TYPE_INTEGER:
495 case ACPI_TYPE_STRING:
496 case ACPI_TYPE_BUFFER:
498 /* Valid operand */
499 break;
501 default:
502 ACPI_ERROR((AE_INFO,
503 "Needed [Integer/String/Buffer], found [%s] %p",
504 acpi_ut_get_object_type_name
505 (obj_desc), obj_desc));
507 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
509 goto next_operand;
511 case ARGI_BUFFER_OR_STRING:
513 /* Need an operand of type STRING or BUFFER */
515 switch (obj_desc->common.type) {
516 case ACPI_TYPE_STRING:
517 case ACPI_TYPE_BUFFER:
519 /* Valid operand */
520 break;
522 case ACPI_TYPE_INTEGER:
524 /* Highest priority conversion is to type Buffer */
526 status =
527 acpi_ex_convert_to_buffer(obj_desc,
528 stack_ptr);
529 if (ACPI_FAILURE(status)) {
530 return_ACPI_STATUS(status);
533 if (obj_desc != *stack_ptr) {
534 acpi_ut_remove_reference(obj_desc);
536 break;
538 default:
539 ACPI_ERROR((AE_INFO,
540 "Needed [Integer/String/Buffer], found [%s] %p",
541 acpi_ut_get_object_type_name
542 (obj_desc), obj_desc));
544 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
546 goto next_operand;
548 case ARGI_DATAOBJECT:
550 * ARGI_DATAOBJECT is only used by the size_of operator.
551 * Need a buffer, string, package, or ref_of reference.
553 * The only reference allowed here is a direct reference to
554 * a namespace node.
556 switch (obj_desc->common.type) {
557 case ACPI_TYPE_PACKAGE:
558 case ACPI_TYPE_STRING:
559 case ACPI_TYPE_BUFFER:
560 case ACPI_TYPE_LOCAL_REFERENCE:
562 /* Valid operand */
563 break;
565 default:
567 ACPI_ERROR((AE_INFO,
568 "Needed [Buffer/String/Package/Reference], found [%s] %p",
569 acpi_ut_get_object_type_name
570 (obj_desc), obj_desc));
572 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
574 goto next_operand;
576 case ARGI_COMPLEXOBJ:
578 /* Need a buffer or package or (ACPI 2.0) String */
580 switch (obj_desc->common.type) {
581 case ACPI_TYPE_PACKAGE:
582 case ACPI_TYPE_STRING:
583 case ACPI_TYPE_BUFFER:
585 /* Valid operand */
586 break;
588 default:
590 ACPI_ERROR((AE_INFO,
591 "Needed [Buffer/String/Package], found [%s] %p",
592 acpi_ut_get_object_type_name
593 (obj_desc), obj_desc));
595 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
597 goto next_operand;
599 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
602 * Need an operand of type REGION or a BUFFER
603 * (which could be a resolved region field)
605 switch (obj_desc->common.type) {
606 case ACPI_TYPE_BUFFER:
607 case ACPI_TYPE_REGION:
609 /* Valid operand */
610 break;
612 default:
614 ACPI_ERROR((AE_INFO,
615 "Needed [Region/Buffer], found [%s] %p",
616 acpi_ut_get_object_type_name
617 (obj_desc), obj_desc));
619 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
621 goto next_operand;
623 case ARGI_DATAREFOBJ:
625 /* Used by the Store() operator only */
627 switch (obj_desc->common.type) {
628 case ACPI_TYPE_INTEGER:
629 case ACPI_TYPE_PACKAGE:
630 case ACPI_TYPE_STRING:
631 case ACPI_TYPE_BUFFER:
632 case ACPI_TYPE_BUFFER_FIELD:
633 case ACPI_TYPE_LOCAL_REFERENCE:
634 case ACPI_TYPE_LOCAL_REGION_FIELD:
635 case ACPI_TYPE_LOCAL_BANK_FIELD:
636 case ACPI_TYPE_LOCAL_INDEX_FIELD:
637 case ACPI_TYPE_DDB_HANDLE:
639 /* Valid operand */
640 break;
642 default:
644 if (acpi_gbl_enable_interpreter_slack) {
646 * Enable original behavior of Store(), allowing any
647 * and all objects as the source operand. The ACPI
648 * spec does not allow this, however.
650 break;
653 if (target_op == AML_DEBUG_OP) {
655 /* Allow store of any object to the Debug object */
657 break;
660 ACPI_ERROR((AE_INFO,
661 "Needed Integer/Buffer/String/Package/Ref/Ddb]"
662 ", found [%s] %p",
663 acpi_ut_get_object_type_name
664 (obj_desc), obj_desc));
666 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
668 goto next_operand;
670 default:
672 /* Unknown type */
674 ACPI_ERROR((AE_INFO,
675 "Internal - Unknown ARGI (required operand) type 0x%X",
676 this_arg_type));
678 return_ACPI_STATUS(AE_BAD_PARAMETER);
682 * Make sure that the original object was resolved to the
683 * required object type (Simple cases only).
685 status =
686 acpi_ex_check_object_type(type_needed,
687 (*stack_ptr)->common.type,
688 *stack_ptr);
689 if (ACPI_FAILURE(status)) {
690 return_ACPI_STATUS(status);
693 next_operand:
695 * If more operands needed, decrement stack_ptr to point
696 * to next operand on stack
698 if (GET_CURRENT_ARG_TYPE(arg_types)) {
699 stack_ptr--;
703 ACPI_DUMP_OPERANDS(walk_state->operands,
704 acpi_ps_get_opcode_name(opcode),
705 walk_state->num_operands);
707 return_ACPI_STATUS(status);