]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/acpi/acpica/nspredef.c
ACPICA: Add argument typechecking for all predefined ACPI names
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / nspredef.c
1 /******************************************************************************
2 *
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * 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
44 #define ACPI_CREATE_PREDEFINED_TABLE
45
46 #include <acpi/acpi.h>
47 #include "accommon.h"
48 #include "acnamesp.h"
49 #include "acpredef.h"
50
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_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 */
75 static acpi_status
76 acpi_ns_check_reference(struct acpi_evaluate_info *info,
77 union acpi_operand_object *return_object);
78
79 static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
80
81 /*******************************************************************************
82 *
83 * FUNCTION: acpi_ns_check_return_value
84 *
85 * PARAMETERS: node - Namespace node for the method/object
86 * info - Method execution information block
87 * user_param_count - Number of parameters actually passed
88 * return_status - Status from the object evaluation
89 * return_object_ptr - Pointer to the object returned from the
90 * evaluation of a method or object
91 *
92 * RETURN: Status
93 *
94 * DESCRIPTION: Check the value returned from a predefined name.
95 *
96 ******************************************************************************/
97
98 acpi_status
99 acpi_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)
104 {
105 acpi_status status;
106 const union acpi_predefined_info *predefined;
107 char *pathname;
108
109 predefined = info->predefined;
110 pathname = info->full_pathname;
111
112 /* If not a predefined name, we cannot validate the return object */
113
114 if (!predefined) {
115 return (AE_OK);
116 }
117
118 /*
119 * If the method failed or did not actually return an object, we cannot
120 * validate the return object
121 */
122 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
123 return (AE_OK);
124 }
125
126 /*
127 * Return value validation and possible repair.
128 *
129 * 1) Don't perform return value validation/repair if this feature
130 * has been disabled via a global option.
131 *
132 * 2) We have a return value, but if one wasn't expected, just exit,
133 * this is not a problem. For example, if the "Implicit Return"
134 * feature is enabled, methods will always return a value.
135 *
136 * 3) If the return value can be of any type, then we cannot perform
137 * any validation, just exit.
138 */
139 if (acpi_gbl_disable_auto_repair ||
140 (!predefined->info.expected_btypes) ||
141 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
142 return (AE_OK);
143 }
144
145 /*
146 * Check that the type of the main return object is what is expected
147 * for this predefined name
148 */
149 status = acpi_ns_check_object_type(info, return_object_ptr,
150 predefined->info.expected_btypes,
151 ACPI_NOT_PACKAGE_ELEMENT);
152 if (ACPI_FAILURE(status)) {
153 goto exit;
154 }
155
156 /*
157 * For returned Package objects, check the type of all sub-objects.
158 * Note: Package may have been newly created by call above.
159 */
160 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
161 info->parent_package = *return_object_ptr;
162 status = acpi_ns_check_package(info, return_object_ptr);
163 if (ACPI_FAILURE(status)) {
164 goto exit;
165 }
166 }
167
168 /*
169 * The return object was OK, or it was successfully repaired above.
170 * Now make some additional checks such as verifying that package
171 * objects are sorted correctly (if required) or buffer objects have
172 * the correct data width (bytes vs. dwords). These repairs are
173 * performed on a per-name basis, i.e., the code is specific to
174 * particular predefined names.
175 */
176 status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
177
178 exit:
179 /*
180 * If the object validation failed or if we successfully repaired one
181 * or more objects, mark the parent node to suppress further warning
182 * messages during the next evaluation of the same method/object.
183 */
184 if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
185 node->flags |= ANOBJ_EVALUATED;
186 }
187
188 return (status);
189 }
190
191 /*******************************************************************************
192 *
193 * FUNCTION: acpi_ns_check_object_type
194 *
195 * PARAMETERS: info - Method execution information block
196 * return_object_ptr - Pointer to the object returned from the
197 * evaluation of a method or object
198 * expected_btypes - Bitmap of expected return type(s)
199 * package_index - Index of object within parent package (if
200 * applicable - ACPI_NOT_PACKAGE_ELEMENT
201 * otherwise)
202 *
203 * RETURN: Status
204 *
205 * DESCRIPTION: Check the type of the return object against the expected object
206 * type(s). Use of Btype allows multiple expected object types.
207 *
208 ******************************************************************************/
209
210 acpi_status
211 acpi_ns_check_object_type(struct acpi_evaluate_info *info,
212 union acpi_operand_object **return_object_ptr,
213 u32 expected_btypes, u32 package_index)
214 {
215 union acpi_operand_object *return_object = *return_object_ptr;
216 acpi_status status = AE_OK;
217 char type_buffer[48]; /* Room for 5 types */
218
219 /* A Namespace node should not get here, but make sure */
220
221 if (return_object &&
222 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
223 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
224 info->node_flags,
225 "Invalid return type - Found a Namespace node [%4.4s] type %s",
226 return_object->node.name.ascii,
227 acpi_ut_get_type_name(return_object->node.
228 type)));
229 return (AE_AML_OPERAND_TYPE);
230 }
231
232 /*
233 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
234 * The bitmapped type allows multiple possible return types.
235 *
236 * Note, the cases below must handle all of the possible types returned
237 * from all of the predefined names (including elements of returned
238 * packages)
239 */
240 info->return_btype = acpi_ns_get_bitmapped_type(return_object);
241 if (info->return_btype == ACPI_RTYPE_ANY) {
242
243 /* Not one of the supported objects, must be incorrect */
244 goto type_error_exit;
245 }
246
247 /* For reference objects, check that the reference type is correct */
248
249 if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
250 status = acpi_ns_check_reference(info, return_object);
251 return (status);
252 }
253
254 /* Attempt simple repair of the returned object if necessary */
255
256 status = acpi_ns_simple_repair(info, expected_btypes,
257 package_index, return_object_ptr);
258 if (ACPI_SUCCESS(status)) {
259 return (AE_OK); /* Successful repair */
260 }
261
262 type_error_exit:
263
264 /* Create a string with all expected types for this predefined object */
265
266 acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
267
268 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
269 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
270 info->node_flags,
271 "Return type mismatch - found %s, expected %s",
272 acpi_ut_get_object_type_name
273 (return_object), type_buffer));
274 } else {
275 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
276 info->node_flags,
277 "Return Package type mismatch at index %u - "
278 "found %s, expected %s", package_index,
279 acpi_ut_get_object_type_name
280 (return_object), type_buffer));
281 }
282
283 return (AE_AML_OPERAND_TYPE);
284 }
285
286 /*******************************************************************************
287 *
288 * FUNCTION: acpi_ns_check_reference
289 *
290 * PARAMETERS: info - Method execution information block
291 * return_object - Object returned from the evaluation of a
292 * method or object
293 *
294 * RETURN: Status
295 *
296 * DESCRIPTION: Check a returned reference object for the correct reference
297 * type. The only reference type that can be returned from a
298 * predefined method is a named reference. All others are invalid.
299 *
300 ******************************************************************************/
301
302 static acpi_status
303 acpi_ns_check_reference(struct acpi_evaluate_info *info,
304 union acpi_operand_object *return_object)
305 {
306
307 /*
308 * Check the reference object for the correct reference type (opcode).
309 * The only type of reference that can be converted to an union acpi_object is
310 * a reference to a named object (reference class: NAME)
311 */
312 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
313 return (AE_OK);
314 }
315
316 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
317 "Return type mismatch - unexpected reference object type [%s] %2.2X",
318 acpi_ut_get_reference_name(return_object),
319 return_object->reference.class));
320
321 return (AE_AML_OPERAND_TYPE);
322 }
323
324 /*******************************************************************************
325 *
326 * FUNCTION: acpi_ns_get_bitmapped_type
327 *
328 * PARAMETERS: return_object - Object returned from method/obj evaluation
329 *
330 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
331 * type is not supported. ACPI_RTYPE_NONE indicates that no
332 * object was returned (return_object is NULL).
333 *
334 * DESCRIPTION: Convert object type into a bitmapped object return type.
335 *
336 ******************************************************************************/
337
338 static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
339 {
340 u32 return_btype;
341
342 if (!return_object) {
343 return (ACPI_RTYPE_NONE);
344 }
345
346 /* Map acpi_object_type to internal bitmapped type */
347
348 switch (return_object->common.type) {
349 case ACPI_TYPE_INTEGER:
350 return_btype = ACPI_RTYPE_INTEGER;
351 break;
352
353 case ACPI_TYPE_BUFFER:
354 return_btype = ACPI_RTYPE_BUFFER;
355 break;
356
357 case ACPI_TYPE_STRING:
358 return_btype = ACPI_RTYPE_STRING;
359 break;
360
361 case ACPI_TYPE_PACKAGE:
362 return_btype = ACPI_RTYPE_PACKAGE;
363 break;
364
365 case ACPI_TYPE_LOCAL_REFERENCE:
366 return_btype = ACPI_RTYPE_REFERENCE;
367 break;
368
369 default:
370 /* Not one of the supported objects, must be incorrect */
371
372 return_btype = ACPI_RTYPE_ANY;
373 break;
374 }
375
376 return (return_btype);
377 }