blob: 3af8de3fcea43824a635112871850c0c0d5e1f94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: exresop - AML Interpreter operand/object resolution
4 *
5 *****************************************************************************/
6
7/*
Bob Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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.
29 *
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.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "amlcode.h"
47#include "acparser.h"
48#include "acinterp.h"
49#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("exresop")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040055static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ex_check_object_type(acpi_object_type type_needed,
57 acpi_object_type this_type, void *object);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ex_check_object_type
62 *
63 * PARAMETERS: type_needed Object type needed
64 * this_type Actual object type
65 * Object Object pointer
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Check required type against actual type
70 *
71 ******************************************************************************/
72
Robert Moore44f6c012005-04-18 22:49:35 -040073static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040074acpi_ex_check_object_type(acpi_object_type type_needed,
75 acpi_object_type this_type, void *object)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Bob Moore4a90c7e2006-01-13 16:22:00 -050077 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 if (type_needed == ACPI_TYPE_ANY) {
Bob Moore52fc0b02006-10-02 00:00:00 -040080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* All types OK, so we don't perform any typechecks */
82
83 return (AE_OK);
84 }
85
86 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
87 /*
88 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
Bob Moore73a30902012-10-31 02:26:55 +000089 * objects and thus allow them to be targets. (As per the ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 * specification, a store to a constant is a noop.)
91 */
92 if ((this_type == ACPI_TYPE_INTEGER) &&
Len Brown4be44fc2005-08-05 00:44:28 -040093 (((union acpi_operand_object *)object)->common.
94 flags & AOPOBJ_AML_CONSTANT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return (AE_OK);
96 }
97 }
98
99 if (type_needed != this_type) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500100 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 return (AE_AML_OPERAND_TYPE);
106 }
107
108 return (AE_OK);
109}
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/*******************************************************************************
112 *
113 * FUNCTION: acpi_ex_resolve_operands
114 *
Bob Mooreba494be2012-07-12 09:40:10 +0800115 * PARAMETERS: opcode - Opcode being interpreted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * stack_ptr - Pointer to the operand stack to be
117 * resolved
118 * walk_state - Current state
119 *
120 * RETURN: Status
121 *
122 * DESCRIPTION: Convert multiple input operands to the types required by the
123 * target operator.
124 *
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.
129 *
130 ******************************************************************************/
131
132acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400133acpi_ex_resolve_operands(u16 opcode,
134 union acpi_operand_object ** stack_ptr,
135 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Len Brown4be44fc2005-08-05 00:44:28 -0400137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
139 u8 object_type;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Bob Mooreb229cf92006-04-21 17:15:00 -0400146 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 op_info = acpi_ps_get_opcode_info(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 if (op_info->class == AML_CLASS_UNKNOWN) {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
153 arg_types = op_info->runtime_args;
154 if (arg_types == ARGI_INVALID_OPCODE) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800155 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Len Brown4be44fc2005-08-05 00:44:28 -0400157 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400161 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400162 opcode, op_info->name, arg_types));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /*
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).
170 */
Len Brown4be44fc2005-08-05 00:44:28 -0400171 while (GET_CURRENT_ARG_TYPE(arg_types)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (!stack_ptr || !*stack_ptr) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500173 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
174 stack_ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 /* Extract useful items */
180
181 obj_desc = *stack_ptr;
182
183 /* Decode the descriptor type */
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 case ACPI_DESC_TYPE_NAMED:
187
Robert Moore44f6c012005-04-18 22:49:35 -0400188 /* Namespace Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 object_type =
191 ((struct acpi_namespace_node *)obj_desc)->type;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500192
193 /*
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
197 */
198 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
199 obj_desc =
200 acpi_ns_get_attached_object((struct
201 acpi_namespace_node
202 *)obj_desc);
203 *stack_ptr = obj_desc;
204 object_type =
205 ((struct acpi_namespace_node *)obj_desc)->
206 type;
207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 case ACPI_DESC_TYPE_OPERAND:
211
212 /* ACPI internal object */
213
Bob Moore3371c192009-02-18 14:44:03 +0800214 object_type = obj_desc->common.type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /* Check for bad acpi_object_type */
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 if (!acpi_ut_valid_object_type(object_type)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500219 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800220 "Bad operand object type [0x%X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500221 object_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
226 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400227
Bob Moore1044f1f2008-09-27 11:08:41 +0800228 /* Validate the Reference */
Robert Moore44f6c012005-04-18 22:49:35 -0400229
Bob Moore1044f1f2008-09-27 11:08:41 +0800230 switch (obj_desc->reference.class) {
231 case ACPI_REFCLASS_DEBUG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Robert Moore44f6c012005-04-18 22:49:35 -0400233 target_op = AML_DEBUG_OP;
234
235 /*lint -fallthrough */
236
Bob Moore1044f1f2008-09-27 11:08:41 +0800237 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Moore1044f1f2008-09-27 11:08:41 +0800244 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 break;
251
252 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800253
Bob Mooreb8e4d892006-01-27 16:43:00 -0500254 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800255 "Unknown Reference Class 0x%2.2X in %p",
Bob Moore1044f1f2008-09-27 11:08:41 +0800256 obj_desc->reference.class,
257 obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261 }
262 break;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 default:
265
266 /* Invalid descriptor */
267
Bob Moore1044f1f2008-09-27 11:08:41 +0800268 ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500269 obj_desc,
270 acpi_ut_get_descriptor_name(obj_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Len Brown4be44fc2005-08-05 00:44:28 -0400272 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
Robert Moore44f6c012005-04-18 22:49:35 -0400275 /* Get one argument type, point to the next */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
278 INCREMENT_ARG_LIST(arg_types);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 /*
281 * Handle cases where the object does not need to be
282 * resolved to a value
283 */
284 switch (this_arg_type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
288 ACPI_DESC_TYPE_OPERAND)
Bob Moore3371c192009-02-18 14:44:03 +0800289 && (obj_desc->common.type == ACPI_TYPE_STRING)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400291 * String found - the string references a named object and
292 * must be resolved to a node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 */
294 goto next_operand;
295 }
296
Robert Moore44f6c012005-04-18 22:49:35 -0400297 /*
298 * Else not a string - fall through to the normal Reference
299 * case below
300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 /*lint -fallthrough */
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 case ARGI_REFERENCE: /* References: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 case ARGI_INTEGER_REF:
305 case ARGI_OBJECT_REF:
306 case ARGI_DEVICE_REF:
Len Brown4be44fc2005-08-05 00:44:28 -0400307 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
308 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
Bob Mooreba494be2012-07-12 09:40:10 +0800309 case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */
Robert Moore44f6c012005-04-18 22:49:35 -0400310 /*
311 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
312 * A Namespace Node is OK as-is
313 */
Len Brown4be44fc2005-08-05 00:44:28 -0400314 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
315 ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 goto next_operand;
317 }
318
Len Brown4be44fc2005-08-05 00:44:28 -0400319 status =
320 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
321 object_type, obj_desc);
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 goto next_operand;
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 case ARGI_DATAREFOBJ: /* Store operator only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /*
329 * We don't want to resolve index_op reference objects during
330 * a store because this would be an implicit de_ref_of operation.
331 * Instead, we just want to store the reference object.
332 * -- All others must be resolved below.
333 */
334 if ((opcode == AML_STORE_OP) &&
Bob Moore3371c192009-02-18 14:44:03 +0800335 ((*stack_ptr)->common.type ==
Len Brown4be44fc2005-08-05 00:44:28 -0400336 ACPI_TYPE_LOCAL_REFERENCE)
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000337 && ((*stack_ptr)->reference.class ==
338 ACPI_REFCLASS_INDEX)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 goto next_operand;
340 }
341 break;
342
343 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* All cases covered above */
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 break;
348 }
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /*
351 * Resolve this object to a value
352 */
Len Brown4be44fc2005-08-05 00:44:28 -0400353 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* Get the resolved object */
359
360 obj_desc = *stack_ptr;
361
362 /*
363 * Check the resulting object (value) type
364 */
365 switch (this_arg_type) {
Len Brown4be44fc2005-08-05 00:44:28 -0400366 /*
367 * For the simple cases, only one type of resolved object
368 * is allowed
369 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 case ARGI_MUTEX:
371
372 /* Need an operand of type ACPI_TYPE_MUTEX */
373
374 type_needed = ACPI_TYPE_MUTEX;
375 break;
376
377 case ARGI_EVENT:
378
379 /* Need an operand of type ACPI_TYPE_EVENT */
380
381 type_needed = ACPI_TYPE_EVENT;
382 break;
383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 case ARGI_PACKAGE: /* Package */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 /* Need an operand of type ACPI_TYPE_PACKAGE */
387
388 type_needed = ACPI_TYPE_PACKAGE;
389 break;
390
391 case ARGI_ANYTYPE:
392
393 /* Any operand type will do */
394
395 type_needed = ACPI_TYPE_ANY;
396 break;
397
398 case ARGI_DDBHANDLE:
399
400 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
401
402 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
403 break;
404
Len Brown4be44fc2005-08-05 00:44:28 -0400405 /*
406 * The more complex cases allow multiple resolved object types
407 */
Robert Moore44f6c012005-04-18 22:49:35 -0400408 case ARGI_INTEGER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 /*
411 * Need an operand of type ACPI_TYPE_INTEGER,
412 * But we can implicitly convert from a STRING or BUFFER
Bob Mooreba494be2012-07-12 09:40:10 +0800413 * aka - "Implicit Source Operand Conversion"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 */
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status =
416 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
417 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (status == AE_TYPE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500419 ACPI_ERROR((AE_INFO,
420 "Needed [Integer/String/Buffer], found [%s] %p",
421 acpi_ut_get_object_type_name
422 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Len Brown4be44fc2005-08-05 00:44:28 -0400424 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
Robert Mooref9f46012005-07-08 00:00:00 -0400429
430 if (obj_desc != *stack_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400431 acpi_ut_remove_reference(obj_desc);
Robert Mooref9f46012005-07-08 00:00:00 -0400432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 goto next_operand;
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 case ARGI_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 /*
437 * Need an operand of type ACPI_TYPE_BUFFER,
438 * But we can implicitly convert from a STRING or INTEGER
Bob Mooreba494be2012-07-12 09:40:10 +0800439 * aka - "Implicit Source Operand Conversion"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 */
Len Brown4be44fc2005-08-05 00:44:28 -0400441 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
442 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (status == AE_TYPE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500444 ACPI_ERROR((AE_INFO,
445 "Needed [Integer/String/Buffer], found [%s] %p",
446 acpi_ut_get_object_type_name
447 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
Robert Mooref9f46012005-07-08 00:00:00 -0400454
455 if (obj_desc != *stack_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400456 acpi_ut_remove_reference(obj_desc);
Robert Mooref9f46012005-07-08 00:00:00 -0400457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 goto next_operand;
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 case ARGI_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 /*
462 * Need an operand of type ACPI_TYPE_STRING,
463 * But we can implicitly convert from a BUFFER or INTEGER
Bob Mooreba494be2012-07-12 09:40:10 +0800464 * aka - "Implicit Source Operand Conversion"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 */
Len Brown4be44fc2005-08-05 00:44:28 -0400466 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
467 ACPI_IMPLICIT_CONVERT_HEX);
468 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (status == AE_TYPE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500470 ACPI_ERROR((AE_INFO,
471 "Needed [Integer/String/Buffer], found [%s] %p",
472 acpi_ut_get_object_type_name
473 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
Len Brown4be44fc2005-08-05 00:44:28 -0400478 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
Robert Mooref9f46012005-07-08 00:00:00 -0400480
481 if (obj_desc != *stack_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400482 acpi_ut_remove_reference(obj_desc);
Robert Mooref9f46012005-07-08 00:00:00 -0400483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 goto next_operand;
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 case ARGI_COMPUTEDATA:
487
488 /* Need an operand of type INTEGER, STRING or BUFFER */
489
Bob Moore3371c192009-02-18 14:44:03 +0800490 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 case ACPI_TYPE_INTEGER:
492 case ACPI_TYPE_STRING:
493 case ACPI_TYPE_BUFFER:
494
495 /* Valid operand */
Len Brown4be44fc2005-08-05 00:44:28 -0400496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500499 ACPI_ERROR((AE_INFO,
500 "Needed [Integer/String/Buffer], found [%s] %p",
501 acpi_ut_get_object_type_name
502 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506 goto next_operand;
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 case ARGI_BUFFER_OR_STRING:
509
510 /* Need an operand of type STRING or BUFFER */
511
Bob Moore3371c192009-02-18 14:44:03 +0800512 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 case ACPI_TYPE_STRING:
514 case ACPI_TYPE_BUFFER:
515
516 /* Valid operand */
Len Brown4be44fc2005-08-05 00:44:28 -0400517 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 case ACPI_TYPE_INTEGER:
520
521 /* Highest priority conversion is to type Buffer */
522
Len Brown4be44fc2005-08-05 00:44:28 -0400523 status =
524 acpi_ex_convert_to_buffer(obj_desc,
525 stack_ptr);
526 if (ACPI_FAILURE(status)) {
527 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
Robert Mooref9f46012005-07-08 00:00:00 -0400529
530 if (obj_desc != *stack_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400531 acpi_ut_remove_reference(obj_desc);
Robert Mooref9f46012005-07-08 00:00:00 -0400532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 break;
534
535 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500536 ACPI_ERROR((AE_INFO,
537 "Needed [Integer/String/Buffer], found [%s] %p",
538 acpi_ut_get_object_type_name
539 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543 goto next_operand;
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 case ARGI_DATAOBJECT:
546 /*
547 * ARGI_DATAOBJECT is only used by the size_of operator.
548 * Need a buffer, string, package, or ref_of reference.
549 *
550 * The only reference allowed here is a direct reference to
551 * a namespace node.
552 */
Bob Moore3371c192009-02-18 14:44:03 +0800553 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 case ACPI_TYPE_PACKAGE:
555 case ACPI_TYPE_STRING:
556 case ACPI_TYPE_BUFFER:
557 case ACPI_TYPE_LOCAL_REFERENCE:
558
559 /* Valid operand */
560 break;
561
562 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000563
Bob Mooreb8e4d892006-01-27 16:43:00 -0500564 ACPI_ERROR((AE_INFO,
565 "Needed [Buffer/String/Package/Reference], found [%s] %p",
566 acpi_ut_get_object_type_name
567 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Len Brown4be44fc2005-08-05 00:44:28 -0400569 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571 goto next_operand;
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 case ARGI_COMPLEXOBJ:
574
575 /* Need a buffer or package or (ACPI 2.0) String */
576
Bob Moore3371c192009-02-18 14:44:03 +0800577 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 case ACPI_TYPE_PACKAGE:
579 case ACPI_TYPE_STRING:
580 case ACPI_TYPE_BUFFER:
581
582 /* Valid operand */
583 break;
584
585 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000586
Bob Mooreb8e4d892006-01-27 16:43:00 -0500587 ACPI_ERROR((AE_INFO,
588 "Needed [Buffer/String/Package], found [%s] %p",
589 acpi_ut_get_object_type_name
590 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Len Brown4be44fc2005-08-05 00:44:28 -0400592 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
594 goto next_operand;
595
Alexey Starikovskiya6823e12007-02-02 19:48:22 +0300596 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Alexey Starikovskiya6823e12007-02-02 19:48:22 +0300598 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Bob Moore3371c192009-02-18 14:44:03 +0800600 switch (obj_desc->common.type) {
Alexey Starikovskiya6823e12007-02-02 19:48:22 +0300601 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 case ACPI_TYPE_REGION:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 /* Valid operand */
605 break;
606
607 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000608
Bob Mooreb8e4d892006-01-27 16:43:00 -0500609 ACPI_ERROR((AE_INFO,
Alexey Starikovskiya6823e12007-02-02 19:48:22 +0300610 "Needed [Region/Buffer], found [%s] %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500611 acpi_ut_get_object_type_name
612 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Len Brown4be44fc2005-08-05 00:44:28 -0400614 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616 goto next_operand;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 case ARGI_DATAREFOBJ:
619
620 /* Used by the Store() operator only */
621
Bob Moore3371c192009-02-18 14:44:03 +0800622 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 case ACPI_TYPE_INTEGER:
624 case ACPI_TYPE_PACKAGE:
625 case ACPI_TYPE_STRING:
626 case ACPI_TYPE_BUFFER:
627 case ACPI_TYPE_BUFFER_FIELD:
628 case ACPI_TYPE_LOCAL_REFERENCE:
629 case ACPI_TYPE_LOCAL_REGION_FIELD:
630 case ACPI_TYPE_LOCAL_BANK_FIELD:
631 case ACPI_TYPE_LOCAL_INDEX_FIELD:
632 case ACPI_TYPE_DDB_HANDLE:
633
634 /* Valid operand */
635 break;
636
637 default:
638
639 if (acpi_gbl_enable_interpreter_slack) {
640 /*
641 * Enable original behavior of Store(), allowing any and all
Bob Moore73a30902012-10-31 02:26:55 +0000642 * objects as the source operand. The ACPI spec does not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 * allow this, however.
644 */
645 break;
646 }
647
Robert Moore44f6c012005-04-18 22:49:35 -0400648 if (target_op == AML_DEBUG_OP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400649
Robert Moore44f6c012005-04-18 22:49:35 -0400650 /* Allow store of any object to the Debug object */
651
652 break;
653 }
654
Bob Mooreb8e4d892006-01-27 16:43:00 -0500655 ACPI_ERROR((AE_INFO,
656 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
657 acpi_ut_get_object_type_name
658 (obj_desc), obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Len Brown4be44fc2005-08-05 00:44:28 -0400660 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662 goto next_operand;
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 default:
665
666 /* Unknown type */
667
Bob Mooreb8e4d892006-01-27 16:43:00 -0500668 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800669 "Internal - Unknown ARGI (required operand) type 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500670 this_arg_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 /*
676 * Make sure that the original object was resolved to the
677 * required object type (Simple cases only).
678 */
Len Brown4be44fc2005-08-05 00:44:28 -0400679 status = acpi_ex_check_object_type(type_needed,
Bob Moore3371c192009-02-18 14:44:03 +0800680 (*stack_ptr)->common.type,
681 *stack_ptr);
Len Brown4be44fc2005-08-05 00:44:28 -0400682 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
Lv Zheng10622bf2013-10-29 09:30:02 +0800686next_operand:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /*
688 * If more operands needed, decrement stack_ptr to point
689 * to next operand on stack
690 */
Len Brown4be44fc2005-08-05 00:44:28 -0400691 if (GET_CURRENT_ARG_TYPE(arg_types)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 stack_ptr--;
693 }
Robert Moore44f6c012005-04-18 22:49:35 -0400694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Bob Moore71d993e2008-06-10 14:25:05 +0800696 ACPI_DUMP_OPERANDS(walk_state->operands,
697 acpi_ps_get_opcode_name(opcode),
698 walk_state->num_operands);
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}