blob: 36f724085dcaa91849725db7208897af3960822d [file] [log] [blame]
Bob Mooree8707b32008-09-28 15:26:17 +08001/******************************************************************************
2 *
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
Bob Mooree8707b32008-09-28 15:26:17 +08004 *
5 *****************************************************************************/
6
7/*
Bob Moore25f044e2013-01-25 05:38:56 +00008 * Copyright (C) 2000 - 2013, Intel Corp.
Bob Mooree8707b32008-09-28 15:26:17 +08009 * 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
Bob Moore999e08f2009-08-13 14:30:16 +080044#define ACPI_CREATE_PREDEFINED_TABLE
45
Bob Mooree8707b32008-09-28 15:26:17 +080046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
49#include "acpredef.h"
Bob Mooree8707b32008-09-28 15:26:17 +080050
51#define _COMPONENT ACPI_NAMESPACE
52ACPI_MODULE_NAME("nspredef")
53
54/*******************************************************************************
55 *
56 * This module validates predefined ACPI objects that appear in the namespace,
57 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
58 * validation is to detect problems with BIOS-exposed predefined ACPI objects
59 * before the results are returned to the ACPI-related drivers.
60 *
61 * There are several areas that are validated:
62 *
63 * 1) The number of input arguments as defined by the method/object in the
64 * ASL is validated against the ACPI specification.
65 * 2) The type of the return object (if any) is validated against the ACPI
66 * specification.
67 * 3) For returned package objects, the count of package elements is
68 * validated, as well as the type of each package element. Nested
69 * packages are supported.
70 *
71 * For any problems found, a warning message is issued.
72 *
73 ******************************************************************************/
74/* Local prototypes */
75static acpi_status
Bob Moore0444e8f2009-06-24 13:38:02 +080076acpi_ns_check_reference(struct acpi_predefined_data *data,
Bob Mooree8707b32008-09-28 15:26:17 +080077 union acpi_operand_object *return_object);
78
Bob Moore0444e8f2009-06-24 13:38:02 +080079static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
80
Bob Moored5a36102013-03-08 09:23:03 +000081static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
82
Bob Mooree8707b32008-09-28 15:26:17 +080083/*
84 * Names for the types that can be returned by the predefined objects.
85 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
86 */
87static const char *acpi_rtype_names[] = {
88 "/Integer",
89 "/String",
90 "/Buffer",
91 "/Package",
92 "/Reference",
93};
94
Bob Mooree8707b32008-09-28 15:26:17 +080095/*******************************************************************************
96 *
97 * FUNCTION: acpi_ns_check_predefined_names
98 *
Bob Mooreba494be2012-07-12 09:40:10 +080099 * PARAMETERS: node - Namespace node for the method/object
Bob Moore0444e8f2009-06-24 13:38:02 +0800100 * user_param_count - Number of parameters actually passed
101 * return_status - Status from the object evaluation
Bob Moorea647b5c2008-11-14 08:44:39 +0800102 * return_object_ptr - Pointer to the object returned from the
103 * evaluation of a method or object
Bob Mooree8707b32008-09-28 15:26:17 +0800104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
108 *
109 ******************************************************************************/
110
111acpi_status
112acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
Bob Mooreeeb44372008-11-13 11:19:24 +0800113 u32 user_param_count,
114 acpi_status return_status,
Bob Moorea647b5c2008-11-14 08:44:39 +0800115 union acpi_operand_object **return_object_ptr)
Bob Mooree8707b32008-09-28 15:26:17 +0800116{
117 acpi_status status = AE_OK;
118 const union acpi_predefined_info *predefined;
119 char *pathname;
Bob Moore0444e8f2009-06-24 13:38:02 +0800120 struct acpi_predefined_data *data;
Bob Mooree8707b32008-09-28 15:26:17 +0800121
122 /* Match the name for this method/object against the predefined list */
123
124 predefined = acpi_ns_check_for_predefined_name(node);
Bob Mooree8707b32008-09-28 15:26:17 +0800125
Bob Moore0444e8f2009-06-24 13:38:02 +0800126 /* Get the full pathname to the object, for use in warning messages */
Bob Mooree8707b32008-09-28 15:26:17 +0800127
128 pathname = acpi_ns_get_external_pathname(node);
129 if (!pathname) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000130 return (AE_OK); /* Could not get pathname, ignore */
Bob Mooree8707b32008-09-28 15:26:17 +0800131 }
132
133 /*
Bob Mooreeeb44372008-11-13 11:19:24 +0800134 * Check that the parameter count for this method matches the ASL
135 * definition. For predefined names, ensure that both the caller and
136 * the method itself are in accordance with the ACPI specification.
Bob Mooree8707b32008-09-28 15:26:17 +0800137 */
Bob Mooreeeb44372008-11-13 11:19:24 +0800138 acpi_ns_check_parameter_count(pathname, node, user_param_count,
139 predefined);
140
141 /* If not a predefined name, we cannot validate the return object */
142
143 if (!predefined) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800144 goto cleanup;
Bob Mooreeeb44372008-11-13 11:19:24 +0800145 }
146
147 /*
Bob Moore0444e8f2009-06-24 13:38:02 +0800148 * If the method failed or did not actually return an object, we cannot
149 * validate the return object
Bob Mooreeeb44372008-11-13 11:19:24 +0800150 */
Bob Moore0444e8f2009-06-24 13:38:02 +0800151 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
152 goto cleanup;
Bob Mooreeeb44372008-11-13 11:19:24 +0800153 }
154
Bob Mooree8707b32008-09-28 15:26:17 +0800155 /*
Bob Moored57b23a2011-07-04 08:24:03 +0000156 * Return value validation and possible repair.
Bob Moore307a0422009-09-03 09:55:40 +0800157 *
Bob Moored57b23a2011-07-04 08:24:03 +0000158 * 1) Don't perform return value validation/repair if this feature
159 * has been disabled via a global option.
160 *
161 * 2) We have a return value, but if one wasn't expected, just exit,
162 * this is not a problem. For example, if the "Implicit Return"
163 * feature is enabled, methods will always return a value.
164 *
165 * 3) If the return value can be of any type, then we cannot perform
166 * any validation, just exit.
Bob Mooree8707b32008-09-28 15:26:17 +0800167 */
Bob Moored57b23a2011-07-04 08:24:03 +0000168 if (acpi_gbl_disable_auto_repair ||
169 (!predefined->info.expected_btypes) ||
Bob Moore307a0422009-09-03 09:55:40 +0800170 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800171 goto cleanup;
Bob Mooree8707b32008-09-28 15:26:17 +0800172 }
173
Bob Moore0444e8f2009-06-24 13:38:02 +0800174 /* Create the parameter data block for object validation */
175
176 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
177 if (!data) {
178 goto cleanup;
179 }
180 data->predefined = predefined;
Fenghua Yu8f9c9122011-07-04 08:36:16 +0000181 data->node = node;
Bob Moore0444e8f2009-06-24 13:38:02 +0800182 data->node_flags = node->flags;
183 data->pathname = pathname;
184
Bob Mooree8707b32008-09-28 15:26:17 +0800185 /*
Bob Moore465da9e2009-12-11 15:26:13 +0800186 * Check that the type of the main return object is what is expected
187 * for this predefined name
Bob Mooree8707b32008-09-28 15:26:17 +0800188 */
Bob Moore0444e8f2009-06-24 13:38:02 +0800189 status = acpi_ns_check_object_type(data, return_object_ptr,
Bob Mooree8707b32008-09-28 15:26:17 +0800190 predefined->info.expected_btypes,
Bob Moore0444e8f2009-06-24 13:38:02 +0800191 ACPI_NOT_PACKAGE_ELEMENT);
Bob Moore465da9e2009-12-11 15:26:13 +0800192 if (ACPI_FAILURE(status)) {
193 goto exit;
194 }
195
196 /*
197 * For returned Package objects, check the type of all sub-objects.
198 * Note: Package may have been newly created by call above.
199 */
200 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore091f4d72010-01-21 09:28:32 +0800201 data->parent_package = *return_object_ptr;
Bob Moore465da9e2009-12-11 15:26:13 +0800202 status = acpi_ns_check_package(data, return_object_ptr);
203 if (ACPI_FAILURE(status)) {
204 goto exit;
Bob Moore34c39c72009-12-11 14:53:11 +0800205 }
Bob Mooree8707b32008-09-28 15:26:17 +0800206 }
207
Bob Mooread5babe2009-11-12 09:44:06 +0800208 /*
Bob Moore465da9e2009-12-11 15:26:13 +0800209 * The return object was OK, or it was successfully repaired above.
210 * Now make some additional checks such as verifying that package
211 * objects are sorted correctly (if required) or buffer objects have
212 * the correct data width (bytes vs. dwords). These repairs are
213 * performed on a per-name basis, i.e., the code is specific to
214 * particular predefined names.
Bob Mooread5babe2009-11-12 09:44:06 +0800215 */
216 status = acpi_ns_complex_repairs(data, node, status, return_object_ptr);
217
Bob Moore465da9e2009-12-11 15:26:13 +0800218exit:
Bob Moore0444e8f2009-06-24 13:38:02 +0800219 /*
220 * If the object validation failed or if we successfully repaired one
221 * or more objects, mark the parent node to suppress further warning
222 * messages during the next evaluation of the same method/object.
223 */
224 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) {
225 node->flags |= ANOBJ_EVALUATED;
226 }
227 ACPI_FREE(data);
228
229cleanup:
Bob Moore65259092009-04-22 12:57:40 +0800230 ACPI_FREE(pathname);
Bob Mooree8707b32008-09-28 15:26:17 +0800231 return (status);
232}
233
234/*******************************************************************************
235 *
236 * FUNCTION: acpi_ns_check_parameter_count
237 *
Bob Mooreba494be2012-07-12 09:40:10 +0800238 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
239 * node - Namespace node for the method/object
Bob Mooreeeb44372008-11-13 11:19:24 +0800240 * user_param_count - Number of args passed in by the caller
Bob Mooreba494be2012-07-12 09:40:10 +0800241 * predefined - Pointer to entry in predefined name table
Bob Mooree8707b32008-09-28 15:26:17 +0800242 *
243 * RETURN: None
244 *
245 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
246 * predefined name is what is expected (i.e., what is defined in
247 * the ACPI specification for this predefined name.)
248 *
249 ******************************************************************************/
250
251void
252acpi_ns_check_parameter_count(char *pathname,
253 struct acpi_namespace_node *node,
Bob Mooreeeb44372008-11-13 11:19:24 +0800254 u32 user_param_count,
Bob Mooree8707b32008-09-28 15:26:17 +0800255 const union acpi_predefined_info *predefined)
256{
257 u32 param_count;
258 u32 required_params_current;
259 u32 required_params_old;
260
Bob Mooreeeb44372008-11-13 11:19:24 +0800261 /* Methods have 0-7 parameters. All other types have zero. */
262
Bob Mooree8707b32008-09-28 15:26:17 +0800263 param_count = 0;
264 if (node->type == ACPI_TYPE_METHOD) {
265 param_count = node->object->method.param_count;
266 }
267
Bob Mooreeeb44372008-11-13 11:19:24 +0800268 if (!predefined) {
269 /*
Bob Moore0444e8f2009-06-24 13:38:02 +0800270 * Check the parameter count for non-predefined methods/objects.
271 *
Bob Mooreeeb44372008-11-13 11:19:24 +0800272 * Warning if too few or too many arguments have been passed by the
273 * caller. An incorrect number of arguments may not cause the method
274 * to fail. However, the method will fail if there are too few
275 * arguments and the method attempts to use one of the missing ones.
276 */
277 if (user_param_count < param_count) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800278 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
279 ACPI_WARN_ALWAYS,
280 "Insufficient arguments - needs %u, found %u",
281 param_count, user_param_count));
Bob Mooreeeb44372008-11-13 11:19:24 +0800282 } else if (user_param_count > param_count) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800283 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
284 ACPI_WARN_ALWAYS,
285 "Excess arguments - needs %u, found %u",
286 param_count, user_param_count));
Bob Mooreeeb44372008-11-13 11:19:24 +0800287 }
288 return;
289 }
290
Bob Moore0444e8f2009-06-24 13:38:02 +0800291 /*
292 * Validate the user-supplied parameter count.
293 * Allow two different legal argument counts (_SCP, etc.)
294 */
Bob Mooree8707b32008-09-28 15:26:17 +0800295 required_params_current = predefined->info.param_count & 0x0F;
296 required_params_old = predefined->info.param_count >> 4;
297
Bob Mooreeeb44372008-11-13 11:19:24 +0800298 if (user_param_count != ACPI_UINT32_MAX) {
Bob Mooreeeb44372008-11-13 11:19:24 +0800299 if ((user_param_count != required_params_current) &&
300 (user_param_count != required_params_old)) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800301 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
302 ACPI_WARN_ALWAYS,
303 "Parameter count mismatch - "
304 "caller passed %u, ACPI requires %u",
305 user_param_count,
306 required_params_current));
Bob Mooreeeb44372008-11-13 11:19:24 +0800307 }
308 }
309
310 /*
Bob Mooreeeb44372008-11-13 11:19:24 +0800311 * Check that the ASL-defined parameter count is what is expected for
Bob Moore0444e8f2009-06-24 13:38:02 +0800312 * this predefined name (parameter count as defined by the ACPI
313 * specification)
Bob Mooreeeb44372008-11-13 11:19:24 +0800314 */
Bob Mooree8707b32008-09-28 15:26:17 +0800315 if ((param_count != required_params_current) &&
316 (param_count != required_params_old)) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800317 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags,
318 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
319 param_count, required_params_current));
Bob Mooree8707b32008-09-28 15:26:17 +0800320 }
321}
322
323/*******************************************************************************
324 *
325 * FUNCTION: acpi_ns_check_for_predefined_name
326 *
Bob Mooreba494be2012-07-12 09:40:10 +0800327 * PARAMETERS: node - Namespace node for the method/object
Bob Mooree8707b32008-09-28 15:26:17 +0800328 *
329 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
330 *
331 * DESCRIPTION: Check an object name against the predefined object list.
332 *
333 ******************************************************************************/
334
335const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
336 acpi_namespace_node
337 *node)
338{
339 const union acpi_predefined_info *this_name;
340
341 /* Quick check for a predefined name, first character must be underscore */
342
343 if (node->name.ascii[0] != '_') {
344 return (NULL);
345 }
346
347 /* Search info table for a predefined method/object name */
348
349 this_name = predefined_names;
350 while (this_name->info.name[0]) {
351 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
Bob Mooree8707b32008-09-28 15:26:17 +0800352 return (this_name);
353 }
354
355 /*
356 * Skip next entry in the table if this name returns a Package
357 * (next entry contains the package info)
358 */
359 if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
360 this_name++;
361 }
362
363 this_name++;
364 }
365
Bob Moore0444e8f2009-06-24 13:38:02 +0800366 return (NULL); /* Not found */
Bob Mooree8707b32008-09-28 15:26:17 +0800367}
368
369/*******************************************************************************
370 *
Bob Mooree8707b32008-09-28 15:26:17 +0800371 * FUNCTION: acpi_ns_check_object_type
372 *
Bob Mooreba494be2012-07-12 09:40:10 +0800373 * PARAMETERS: data - Pointer to validation data structure
Bob Moorea647b5c2008-11-14 08:44:39 +0800374 * return_object_ptr - Pointer to the object returned from the
375 * evaluation of a method or object
Bob Mooree8707b32008-09-28 15:26:17 +0800376 * expected_btypes - Bitmap of expected return type(s)
377 * package_index - Index of object within parent package (if
Bob Moore0444e8f2009-06-24 13:38:02 +0800378 * applicable - ACPI_NOT_PACKAGE_ELEMENT
379 * otherwise)
Bob Mooree8707b32008-09-28 15:26:17 +0800380 *
381 * RETURN: Status
382 *
383 * DESCRIPTION: Check the type of the return object against the expected object
384 * type(s). Use of Btype allows multiple expected object types.
385 *
386 ******************************************************************************/
387
Bob Moore42f8fb72013-01-11 13:08:51 +0100388acpi_status
Bob Moore0444e8f2009-06-24 13:38:02 +0800389acpi_ns_check_object_type(struct acpi_predefined_data *data,
Bob Moorea647b5c2008-11-14 08:44:39 +0800390 union acpi_operand_object **return_object_ptr,
Bob Mooree8707b32008-09-28 15:26:17 +0800391 u32 expected_btypes, u32 package_index)
392{
Bob Moorea647b5c2008-11-14 08:44:39 +0800393 union acpi_operand_object *return_object = *return_object_ptr;
Bob Mooree8707b32008-09-28 15:26:17 +0800394 acpi_status status = AE_OK;
Bob Mooree8707b32008-09-28 15:26:17 +0800395 char type_buffer[48]; /* Room for 5 types */
Bob Mooree8707b32008-09-28 15:26:17 +0800396
Bob Mooree8707b32008-09-28 15:26:17 +0800397 /* A Namespace node should not get here, but make sure */
398
Bob Moored5a36102013-03-08 09:23:03 +0000399 if (return_object &&
400 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800401 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
402 "Invalid return type - Found a Namespace node [%4.4s] type %s",
403 return_object->node.name.ascii,
404 acpi_ut_get_type_name(return_object->node.
405 type)));
Bob Mooree8707b32008-09-28 15:26:17 +0800406 return (AE_AML_OPERAND_TYPE);
407 }
408
409 /*
410 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
411 * The bitmapped type allows multiple possible return types.
412 *
413 * Note, the cases below must handle all of the possible types returned
414 * from all of the predefined names (including elements of returned
415 * packages)
416 */
Bob Moored5a36102013-03-08 09:23:03 +0000417 data->return_btype = acpi_ns_get_bitmapped_type(return_object);
418 if (data->return_btype == ACPI_RTYPE_ANY) {
Bob Mooree8707b32008-09-28 15:26:17 +0800419
Bob Mooree8707b32008-09-28 15:26:17 +0800420 /* Not one of the supported objects, must be incorrect */
Bob Mooree8707b32008-09-28 15:26:17 +0800421 goto type_error_exit;
422 }
423
Bob Moored5a36102013-03-08 09:23:03 +0000424 /* For reference objects, check that the reference type is correct */
Bob Mooree8707b32008-09-28 15:26:17 +0800425
Bob Moored5a36102013-03-08 09:23:03 +0000426 if ((data->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
427 status = acpi_ns_check_reference(data, return_object);
Bob Moore2147d3f2010-01-21 09:08:31 +0800428 return (status);
Bob Mooree8707b32008-09-28 15:26:17 +0800429 }
430
Bob Moored5a36102013-03-08 09:23:03 +0000431 /* Attempt simple repair of the returned object if necessary */
Bob Mooree8707b32008-09-28 15:26:17 +0800432
Bob Moored5a36102013-03-08 09:23:03 +0000433 status = acpi_ns_simple_repair(data, expected_btypes,
Bob Moore2147d3f2010-01-21 09:08:31 +0800434 package_index, return_object_ptr);
Bob Moored5a36102013-03-08 09:23:03 +0000435 return (status);
Bob Mooree8707b32008-09-28 15:26:17 +0800436
Bob Mooree8707b32008-09-28 15:26:17 +0800437 type_error_exit:
438
439 /* Create a string with all expected types for this predefined object */
440
Bob Moore0444e8f2009-06-24 13:38:02 +0800441 acpi_ns_get_expected_types(type_buffer, expected_btypes);
Bob Mooree8707b32008-09-28 15:26:17 +0800442
Bob Moore0444e8f2009-06-24 13:38:02 +0800443 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
444 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
445 "Return type mismatch - found %s, expected %s",
446 acpi_ut_get_object_type_name
447 (return_object), type_buffer));
Bob Mooree8707b32008-09-28 15:26:17 +0800448 } else {
Bob Moore0444e8f2009-06-24 13:38:02 +0800449 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
450 "Return Package type mismatch at index %u - "
451 "found %s, expected %s", package_index,
452 acpi_ut_get_object_type_name
453 (return_object), type_buffer));
Bob Mooree8707b32008-09-28 15:26:17 +0800454 }
455
456 return (AE_AML_OPERAND_TYPE);
457}
458
459/*******************************************************************************
460 *
461 * FUNCTION: acpi_ns_check_reference
462 *
Bob Mooreba494be2012-07-12 09:40:10 +0800463 * PARAMETERS: data - Pointer to validation data structure
Bob Mooree8707b32008-09-28 15:26:17 +0800464 * return_object - Object returned from the evaluation of a
465 * method or object
466 *
467 * RETURN: Status
468 *
469 * DESCRIPTION: Check a returned reference object for the correct reference
470 * type. The only reference type that can be returned from a
471 * predefined method is a named reference. All others are invalid.
472 *
473 ******************************************************************************/
474
475static acpi_status
Bob Moore0444e8f2009-06-24 13:38:02 +0800476acpi_ns_check_reference(struct acpi_predefined_data *data,
Bob Mooree8707b32008-09-28 15:26:17 +0800477 union acpi_operand_object *return_object)
478{
479
480 /*
481 * Check the reference object for the correct reference type (opcode).
482 * The only type of reference that can be converted to an union acpi_object is
483 * a reference to a named object (reference class: NAME)
484 */
485 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
486 return (AE_OK);
487 }
488
Bob Moore0444e8f2009-06-24 13:38:02 +0800489 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
490 "Return type mismatch - unexpected reference object type [%s] %2.2X",
491 acpi_ut_get_reference_name(return_object),
492 return_object->reference.class));
Bob Mooree8707b32008-09-28 15:26:17 +0800493
494 return (AE_AML_OPERAND_TYPE);
495}
Bob Moorea647b5c2008-11-14 08:44:39 +0800496
497/*******************************************************************************
498 *
Bob Moored5a36102013-03-08 09:23:03 +0000499 * FUNCTION: acpi_ns_get_bitmapped_type
500 *
501 * PARAMETERS: return_object - Object returned from method/obj evaluation
502 *
503 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
504 * type is not supported. ACPI_RTYPE_NONE indicates that no
505 * object was returned (return_object is NULL).
506 *
507 * DESCRIPTION: Convert object type into a bitmapped object return type.
508 *
509 ******************************************************************************/
510
511static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
512{
513 u32 return_btype;
514
515 if (!return_object) {
516 return (ACPI_RTYPE_NONE);
517 }
518
519 /* Map acpi_object_type to internal bitmapped type */
520
521 switch (return_object->common.type) {
522 case ACPI_TYPE_INTEGER:
523 return_btype = ACPI_RTYPE_INTEGER;
524 break;
525
526 case ACPI_TYPE_BUFFER:
527 return_btype = ACPI_RTYPE_BUFFER;
528 break;
529
530 case ACPI_TYPE_STRING:
531 return_btype = ACPI_RTYPE_STRING;
532 break;
533
534 case ACPI_TYPE_PACKAGE:
535 return_btype = ACPI_RTYPE_PACKAGE;
536 break;
537
538 case ACPI_TYPE_LOCAL_REFERENCE:
539 return_btype = ACPI_RTYPE_REFERENCE;
540 break;
541
542 default:
543 /* Not one of the supported objects, must be incorrect */
544
545 return_btype = ACPI_RTYPE_ANY;
546 break;
547 }
548
549 return (return_btype);
550}
551
552/*******************************************************************************
553 *
Bob Moore0444e8f2009-06-24 13:38:02 +0800554 * FUNCTION: acpi_ns_get_expected_types
555 *
Bob Mooreba494be2012-07-12 09:40:10 +0800556 * PARAMETERS: buffer - Pointer to where the string is returned
Bob Moore0444e8f2009-06-24 13:38:02 +0800557 * expected_btypes - Bitmap of expected return type(s)
558 *
559 * RETURN: Buffer is populated with type names.
560 *
561 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
562 * names of expected types, for use in warning messages.
563 *
564 ******************************************************************************/
565
566static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
567{
568 u32 this_rtype;
569 u32 i;
570 u32 j;
571
572 j = 1;
573 buffer[0] = 0;
574 this_rtype = ACPI_RTYPE_INTEGER;
575
576 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
577
578 /* If one of the expected types, concatenate the name of this type */
579
580 if (expected_btypes & this_rtype) {
581 ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
582 j = 0; /* Use name separator from now on */
583 }
584 this_rtype <<= 1; /* Next Rtype */
585 }
586}