blob: 8d59ac2399e02c5352247da749d2978a7c8be14c [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
Bob Moore29a241c2013-05-30 10:00:01 +080064 * ASL is validated against the ACPI specification.
Bob Mooree8707b32008-09-28 15:26:17 +080065 * 2) The type of the return object (if any) is validated against the ACPI
Bob Moore29a241c2013-05-30 10:00:01 +080066 * specification.
Bob Mooree8707b32008-09-28 15:26:17 +080067 * 3) For returned package objects, the count of package elements is
Bob Moore29a241c2013-05-30 10:00:01 +080068 * validated, as well as the type of each package element. Nested
69 * packages are supported.
Bob Mooree8707b32008-09-28 15:26:17 +080070 *
71 * For any problems found, a warning message is issued.
72 *
73 ******************************************************************************/
74/* Local prototypes */
75static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080076acpi_ns_check_reference(struct acpi_evaluate_info *info,
Bob Mooree8707b32008-09-28 15:26:17 +080077 union acpi_operand_object *return_object);
78
Bob Moored5a36102013-03-08 09:23:03 +000079static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
80
Bob Mooree8707b32008-09-28 15:26:17 +080081/*******************************************************************************
82 *
Bob Moore29a241c2013-05-30 10:00:01 +080083 * FUNCTION: acpi_ns_check_return_value
Bob Mooree8707b32008-09-28 15:26:17 +080084 *
Bob Mooreba494be2012-07-12 09:40:10 +080085 * PARAMETERS: node - Namespace node for the method/object
Bob Moore29a241c2013-05-30 10:00:01 +080086 * info - Method execution information block
Bob Moore0444e8f2009-06-24 13:38:02 +080087 * user_param_count - Number of parameters actually passed
88 * return_status - Status from the object evaluation
Bob Moorea647b5c2008-11-14 08:44:39 +080089 * return_object_ptr - Pointer to the object returned from the
90 * evaluation of a method or object
Bob Mooree8707b32008-09-28 15:26:17 +080091 *
92 * RETURN: Status
93 *
Bob Moore29a241c2013-05-30 10:00:01 +080094 * DESCRIPTION: Check the value returned from a predefined name.
Bob Mooree8707b32008-09-28 15:26:17 +080095 *
96 ******************************************************************************/
97
98acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +080099acpi_ns_check_return_value(struct acpi_namespace_node *node,
100 struct acpi_evaluate_info *info,
101 u32 user_param_count,
102 acpi_status return_status,
103 union acpi_operand_object **return_object_ptr)
Bob Mooree8707b32008-09-28 15:26:17 +0800104{
Bob Moore29a241c2013-05-30 10:00:01 +0800105 acpi_status status;
Bob Mooree8707b32008-09-28 15:26:17 +0800106 const union acpi_predefined_info *predefined;
Bob Mooreeeb44372008-11-13 11:19:24 +0800107
108 /* If not a predefined name, we cannot validate the return object */
109
Bob Moore43e53182013-05-30 10:00:53 +0800110 predefined = info->predefined;
Bob Mooreeeb44372008-11-13 11:19:24 +0800111 if (!predefined) {
Bob Moore29a241c2013-05-30 10:00:01 +0800112 return (AE_OK);
Bob Mooreeeb44372008-11-13 11:19:24 +0800113 }
114
115 /*
Bob Moore0444e8f2009-06-24 13:38:02 +0800116 * If the method failed or did not actually return an object, we cannot
117 * validate the return object
Bob Mooreeeb44372008-11-13 11:19:24 +0800118 */
Bob Moore0444e8f2009-06-24 13:38:02 +0800119 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
Bob Moore29a241c2013-05-30 10:00:01 +0800120 return (AE_OK);
Bob Mooreeeb44372008-11-13 11:19:24 +0800121 }
122
Bob Mooree8707b32008-09-28 15:26:17 +0800123 /*
Bob Moored57b23a2011-07-04 08:24:03 +0000124 * Return value validation and possible repair.
Bob Moore307a0422009-09-03 09:55:40 +0800125 *
Bob Moored57b23a2011-07-04 08:24:03 +0000126 * 1) Don't perform return value validation/repair if this feature
127 * has been disabled via a global option.
128 *
129 * 2) We have a return value, but if one wasn't expected, just exit,
130 * this is not a problem. For example, if the "Implicit Return"
131 * feature is enabled, methods will always return a value.
132 *
133 * 3) If the return value can be of any type, then we cannot perform
134 * any validation, just exit.
Bob Mooree8707b32008-09-28 15:26:17 +0800135 */
Bob Moored57b23a2011-07-04 08:24:03 +0000136 if (acpi_gbl_disable_auto_repair ||
137 (!predefined->info.expected_btypes) ||
Bob Moore307a0422009-09-03 09:55:40 +0800138 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
Bob Moore29a241c2013-05-30 10:00:01 +0800139 return (AE_OK);
Bob Mooree8707b32008-09-28 15:26:17 +0800140 }
141
142 /*
Bob Moore465da9e2009-12-11 15:26:13 +0800143 * Check that the type of the main return object is what is expected
144 * for this predefined name
Bob Mooree8707b32008-09-28 15:26:17 +0800145 */
Bob Moore29a241c2013-05-30 10:00:01 +0800146 status = acpi_ns_check_object_type(info, return_object_ptr,
Bob Mooree8707b32008-09-28 15:26:17 +0800147 predefined->info.expected_btypes,
Bob Moore0444e8f2009-06-24 13:38:02 +0800148 ACPI_NOT_PACKAGE_ELEMENT);
Bob Moore465da9e2009-12-11 15:26:13 +0800149 if (ACPI_FAILURE(status)) {
150 goto exit;
151 }
152
153 /*
154 * For returned Package objects, check the type of all sub-objects.
155 * Note: Package may have been newly created by call above.
156 */
157 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore29a241c2013-05-30 10:00:01 +0800158 info->parent_package = *return_object_ptr;
159 status = acpi_ns_check_package(info, return_object_ptr);
Bob Moore465da9e2009-12-11 15:26:13 +0800160 if (ACPI_FAILURE(status)) {
Lv Zhengaa6329c2013-06-08 09:01:01 +0800161
162 /* We might be able to fix an operand type error (_PRT) */
163
164 if (status != AE_AML_OPERAND_TYPE) {
165 goto exit;
166 }
Bob Moore34c39c72009-12-11 14:53:11 +0800167 }
Bob Mooree8707b32008-09-28 15:26:17 +0800168 }
169
Bob Mooread5babe2009-11-12 09:44:06 +0800170 /*
Bob Moore465da9e2009-12-11 15:26:13 +0800171 * The return object was OK, or it was successfully repaired above.
172 * Now make some additional checks such as verifying that package
173 * objects are sorted correctly (if required) or buffer objects have
174 * the correct data width (bytes vs. dwords). These repairs are
175 * performed on a per-name basis, i.e., the code is specific to
176 * particular predefined names.
Bob Mooread5babe2009-11-12 09:44:06 +0800177 */
Bob Moore29a241c2013-05-30 10:00:01 +0800178 status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
Bob Mooread5babe2009-11-12 09:44:06 +0800179
Bob Moore465da9e2009-12-11 15:26:13 +0800180exit:
Bob Moore0444e8f2009-06-24 13:38:02 +0800181 /*
182 * If the object validation failed or if we successfully repaired one
183 * or more objects, mark the parent node to suppress further warning
184 * messages during the next evaluation of the same method/object.
185 */
Bob Moore29a241c2013-05-30 10:00:01 +0800186 if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
Bob Moore0444e8f2009-06-24 13:38:02 +0800187 node->flags |= ANOBJ_EVALUATED;
188 }
Bob Moore0444e8f2009-06-24 13:38:02 +0800189
Bob Mooree8707b32008-09-28 15:26:17 +0800190 return (status);
191}
192
193/*******************************************************************************
194 *
Bob Mooree8707b32008-09-28 15:26:17 +0800195 * FUNCTION: acpi_ns_check_object_type
196 *
Bob Moore29a241c2013-05-30 10:00:01 +0800197 * PARAMETERS: info - Method execution information block
Bob Moorea647b5c2008-11-14 08:44:39 +0800198 * return_object_ptr - Pointer to the object returned from the
199 * evaluation of a method or object
Bob Mooree8707b32008-09-28 15:26:17 +0800200 * expected_btypes - Bitmap of expected return type(s)
201 * package_index - Index of object within parent package (if
Bob Moore0444e8f2009-06-24 13:38:02 +0800202 * applicable - ACPI_NOT_PACKAGE_ELEMENT
203 * otherwise)
Bob Mooree8707b32008-09-28 15:26:17 +0800204 *
205 * RETURN: Status
206 *
207 * DESCRIPTION: Check the type of the return object against the expected object
208 * type(s). Use of Btype allows multiple expected object types.
209 *
210 ******************************************************************************/
211
Bob Moore42f8fb72013-01-11 13:08:51 +0100212acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800213acpi_ns_check_object_type(struct acpi_evaluate_info *info,
Bob Moorea647b5c2008-11-14 08:44:39 +0800214 union acpi_operand_object **return_object_ptr,
Bob Mooree8707b32008-09-28 15:26:17 +0800215 u32 expected_btypes, u32 package_index)
216{
Bob Moorea647b5c2008-11-14 08:44:39 +0800217 union acpi_operand_object *return_object = *return_object_ptr;
Bob Mooree8707b32008-09-28 15:26:17 +0800218 acpi_status status = AE_OK;
Bob Mooree8707b32008-09-28 15:26:17 +0800219 char type_buffer[48]; /* Room for 5 types */
Bob Mooree8707b32008-09-28 15:26:17 +0800220
Bob Mooree8707b32008-09-28 15:26:17 +0800221 /* A Namespace node should not get here, but make sure */
222
Bob Moored5a36102013-03-08 09:23:03 +0000223 if (return_object &&
224 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
Bob Moore29a241c2013-05-30 10:00:01 +0800225 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
226 info->node_flags,
Bob Moore0444e8f2009-06-24 13:38:02 +0800227 "Invalid return type - Found a Namespace node [%4.4s] type %s",
228 return_object->node.name.ascii,
229 acpi_ut_get_type_name(return_object->node.
230 type)));
Bob Mooree8707b32008-09-28 15:26:17 +0800231 return (AE_AML_OPERAND_TYPE);
232 }
233
234 /*
235 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
236 * The bitmapped type allows multiple possible return types.
237 *
238 * Note, the cases below must handle all of the possible types returned
239 * from all of the predefined names (including elements of returned
240 * packages)
241 */
Bob Moore29a241c2013-05-30 10:00:01 +0800242 info->return_btype = acpi_ns_get_bitmapped_type(return_object);
243 if (info->return_btype == ACPI_RTYPE_ANY) {
Bob Mooree8707b32008-09-28 15:26:17 +0800244
Bob Mooree8707b32008-09-28 15:26:17 +0800245 /* Not one of the supported objects, must be incorrect */
Bob Mooree8707b32008-09-28 15:26:17 +0800246 goto type_error_exit;
247 }
248
Bob Moored5a36102013-03-08 09:23:03 +0000249 /* For reference objects, check that the reference type is correct */
Bob Mooree8707b32008-09-28 15:26:17 +0800250
Bob Moore29a241c2013-05-30 10:00:01 +0800251 if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
252 status = acpi_ns_check_reference(info, return_object);
Bob Moore2147d3f2010-01-21 09:08:31 +0800253 return (status);
Bob Mooree8707b32008-09-28 15:26:17 +0800254 }
255
Bob Moored5a36102013-03-08 09:23:03 +0000256 /* Attempt simple repair of the returned object if necessary */
Bob Mooree8707b32008-09-28 15:26:17 +0800257
Bob Moore29a241c2013-05-30 10:00:01 +0800258 status = acpi_ns_simple_repair(info, expected_btypes,
Bob Moore2147d3f2010-01-21 09:08:31 +0800259 package_index, return_object_ptr);
Bob Moore29a241c2013-05-30 10:00:01 +0800260 if (ACPI_SUCCESS(status)) {
261 return (AE_OK); /* Successful repair */
262 }
Bob Mooree8707b32008-09-28 15:26:17 +0800263
Bob Mooree8707b32008-09-28 15:26:17 +0800264 type_error_exit:
265
266 /* Create a string with all expected types for this predefined object */
267
Bob Moorec34c82b2013-04-12 00:24:22 +0000268 acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
Bob Mooree8707b32008-09-28 15:26:17 +0800269
Bob Moore0444e8f2009-06-24 13:38:02 +0800270 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
Bob Moore29a241c2013-05-30 10:00:01 +0800271 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
272 info->node_flags,
Bob Moore0444e8f2009-06-24 13:38:02 +0800273 "Return type mismatch - found %s, expected %s",
274 acpi_ut_get_object_type_name
275 (return_object), type_buffer));
Bob Mooree8707b32008-09-28 15:26:17 +0800276 } else {
Bob Moore29a241c2013-05-30 10:00:01 +0800277 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
278 info->node_flags,
Bob Moore0444e8f2009-06-24 13:38:02 +0800279 "Return Package type mismatch at index %u - "
280 "found %s, expected %s", package_index,
281 acpi_ut_get_object_type_name
282 (return_object), type_buffer));
Bob Mooree8707b32008-09-28 15:26:17 +0800283 }
284
285 return (AE_AML_OPERAND_TYPE);
286}
287
288/*******************************************************************************
289 *
290 * FUNCTION: acpi_ns_check_reference
291 *
Bob Moore29a241c2013-05-30 10:00:01 +0800292 * PARAMETERS: info - Method execution information block
Bob Mooree8707b32008-09-28 15:26:17 +0800293 * return_object - Object returned from the evaluation of a
294 * method or object
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Check a returned reference object for the correct reference
299 * type. The only reference type that can be returned from a
300 * predefined method is a named reference. All others are invalid.
301 *
302 ******************************************************************************/
303
304static acpi_status
Bob Moore29a241c2013-05-30 10:00:01 +0800305acpi_ns_check_reference(struct acpi_evaluate_info *info,
Bob Mooree8707b32008-09-28 15:26:17 +0800306 union acpi_operand_object *return_object)
307{
308
309 /*
310 * Check the reference object for the correct reference type (opcode).
311 * The only type of reference that can be converted to an union acpi_object is
312 * a reference to a named object (reference class: NAME)
313 */
314 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
315 return (AE_OK);
316 }
317
Bob Moore29a241c2013-05-30 10:00:01 +0800318 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
Bob Moore0444e8f2009-06-24 13:38:02 +0800319 "Return type mismatch - unexpected reference object type [%s] %2.2X",
320 acpi_ut_get_reference_name(return_object),
321 return_object->reference.class));
Bob Mooree8707b32008-09-28 15:26:17 +0800322
323 return (AE_AML_OPERAND_TYPE);
324}
Bob Moorea647b5c2008-11-14 08:44:39 +0800325
326/*******************************************************************************
327 *
Bob Moored5a36102013-03-08 09:23:03 +0000328 * FUNCTION: acpi_ns_get_bitmapped_type
329 *
330 * PARAMETERS: return_object - Object returned from method/obj evaluation
331 *
332 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
333 * type is not supported. ACPI_RTYPE_NONE indicates that no
334 * object was returned (return_object is NULL).
335 *
336 * DESCRIPTION: Convert object type into a bitmapped object return type.
337 *
338 ******************************************************************************/
339
340static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
341{
342 u32 return_btype;
343
344 if (!return_object) {
345 return (ACPI_RTYPE_NONE);
346 }
347
348 /* Map acpi_object_type to internal bitmapped type */
349
350 switch (return_object->common.type) {
351 case ACPI_TYPE_INTEGER:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000352
Bob Moored5a36102013-03-08 09:23:03 +0000353 return_btype = ACPI_RTYPE_INTEGER;
354 break;
355
356 case ACPI_TYPE_BUFFER:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000357
Bob Moored5a36102013-03-08 09:23:03 +0000358 return_btype = ACPI_RTYPE_BUFFER;
359 break;
360
361 case ACPI_TYPE_STRING:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000362
Bob Moored5a36102013-03-08 09:23:03 +0000363 return_btype = ACPI_RTYPE_STRING;
364 break;
365
366 case ACPI_TYPE_PACKAGE:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000367
Bob Moored5a36102013-03-08 09:23:03 +0000368 return_btype = ACPI_RTYPE_PACKAGE;
369 break;
370
371 case ACPI_TYPE_LOCAL_REFERENCE:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000372
Bob Moored5a36102013-03-08 09:23:03 +0000373 return_btype = ACPI_RTYPE_REFERENCE;
374 break;
375
376 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000377
Bob Moored5a36102013-03-08 09:23:03 +0000378 /* Not one of the supported objects, must be incorrect */
379
380 return_btype = ACPI_RTYPE_ANY;
381 break;
382 }
383
384 return (return_btype);
385}