nspredef.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /******************************************************************************
  2. *
  3. * Module Name: nspredef - Validation of ACPI predefined methods and objects
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #define ACPI_CREATE_PREDEFINED_TABLE
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acnamesp.h"
  46. #include "acpredef.h"
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nspredef")
  49. /*******************************************************************************
  50. *
  51. * This module validates predefined ACPI objects that appear in the namespace,
  52. * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
  53. * validation is to detect problems with BIOS-exposed predefined ACPI objects
  54. * before the results are returned to the ACPI-related drivers.
  55. *
  56. * There are several areas that are validated:
  57. *
  58. * 1) The number of input arguments as defined by the method/object in the
  59. * ASL is validated against the ACPI specification.
  60. * 2) The type of the return object (if any) is validated against the ACPI
  61. * specification.
  62. * 3) For returned package objects, the count of package elements is
  63. * validated, as well as the type of each package element. Nested
  64. * packages are supported.
  65. *
  66. * For any problems found, a warning message is issued.
  67. *
  68. ******************************************************************************/
  69. /* Local prototypes */
  70. static acpi_status
  71. acpi_ns_check_reference(struct acpi_evaluate_info *info,
  72. union acpi_operand_object *return_object);
  73. static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
  74. /*******************************************************************************
  75. *
  76. * FUNCTION: acpi_ns_check_return_value
  77. *
  78. * PARAMETERS: node - Namespace node for the method/object
  79. * info - Method execution information block
  80. * user_param_count - Number of parameters actually passed
  81. * return_status - Status from the object evaluation
  82. * return_object_ptr - Pointer to the object returned from the
  83. * evaluation of a method or object
  84. *
  85. * RETURN: Status
  86. *
  87. * DESCRIPTION: Check the value returned from a predefined name.
  88. *
  89. ******************************************************************************/
  90. acpi_status
  91. acpi_ns_check_return_value(struct acpi_namespace_node *node,
  92. struct acpi_evaluate_info *info,
  93. u32 user_param_count,
  94. acpi_status return_status,
  95. union acpi_operand_object **return_object_ptr)
  96. {
  97. acpi_status status;
  98. const union acpi_predefined_info *predefined;
  99. /* If not a predefined name, we cannot validate the return object */
  100. predefined = info->predefined;
  101. if (!predefined) {
  102. return (AE_OK);
  103. }
  104. /*
  105. * If the method failed or did not actually return an object, we cannot
  106. * validate the return object
  107. */
  108. if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
  109. return (AE_OK);
  110. }
  111. /*
  112. * Return value validation and possible repair.
  113. *
  114. * 1) Don't perform return value validation/repair if this feature
  115. * has been disabled via a global option.
  116. *
  117. * 2) We have a return value, but if one wasn't expected, just exit,
  118. * this is not a problem. For example, if the "Implicit Return"
  119. * feature is enabled, methods will always return a value.
  120. *
  121. * 3) If the return value can be of any type, then we cannot perform
  122. * any validation, just exit.
  123. */
  124. if (acpi_gbl_disable_auto_repair ||
  125. (!predefined->info.expected_btypes) ||
  126. (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
  127. return (AE_OK);
  128. }
  129. /*
  130. * Check that the type of the main return object is what is expected
  131. * for this predefined name
  132. */
  133. status = acpi_ns_check_object_type(info, return_object_ptr,
  134. predefined->info.expected_btypes,
  135. ACPI_NOT_PACKAGE_ELEMENT);
  136. if (ACPI_FAILURE(status)) {
  137. goto exit;
  138. }
  139. /*
  140. * For returned Package objects, check the type of all sub-objects.
  141. * Note: Package may have been newly created by call above.
  142. */
  143. if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
  144. info->parent_package = *return_object_ptr;
  145. status = acpi_ns_check_package(info, return_object_ptr);
  146. if (ACPI_FAILURE(status)) {
  147. /* We might be able to fix some errors */
  148. if ((status != AE_AML_OPERAND_TYPE) &&
  149. (status != AE_AML_OPERAND_VALUE)) {
  150. goto exit;
  151. }
  152. }
  153. }
  154. /*
  155. * The return object was OK, or it was successfully repaired above.
  156. * Now make some additional checks such as verifying that package
  157. * objects are sorted correctly (if required) or buffer objects have
  158. * the correct data width (bytes vs. dwords). These repairs are
  159. * performed on a per-name basis, i.e., the code is specific to
  160. * particular predefined names.
  161. */
  162. status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
  163. exit:
  164. /*
  165. * If the object validation failed or if we successfully repaired one
  166. * or more objects, mark the parent node to suppress further warning
  167. * messages during the next evaluation of the same method/object.
  168. */
  169. if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
  170. node->flags |= ANOBJ_EVALUATED;
  171. }
  172. return (status);
  173. }
  174. /*******************************************************************************
  175. *
  176. * FUNCTION: acpi_ns_check_object_type
  177. *
  178. * PARAMETERS: info - Method execution information block
  179. * return_object_ptr - Pointer to the object returned from the
  180. * evaluation of a method or object
  181. * expected_btypes - Bitmap of expected return type(s)
  182. * package_index - Index of object within parent package (if
  183. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  184. * otherwise)
  185. *
  186. * RETURN: Status
  187. *
  188. * DESCRIPTION: Check the type of the return object against the expected object
  189. * type(s). Use of Btype allows multiple expected object types.
  190. *
  191. ******************************************************************************/
  192. acpi_status
  193. acpi_ns_check_object_type(struct acpi_evaluate_info *info,
  194. union acpi_operand_object **return_object_ptr,
  195. u32 expected_btypes, u32 package_index)
  196. {
  197. union acpi_operand_object *return_object = *return_object_ptr;
  198. acpi_status status = AE_OK;
  199. char type_buffer[48]; /* Room for 5 types */
  200. /* A Namespace node should not get here, but make sure */
  201. if (return_object &&
  202. ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
  203. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  204. info->node_flags,
  205. "Invalid return type - Found a Namespace node [%4.4s] type %s",
  206. return_object->node.name.ascii,
  207. acpi_ut_get_type_name(return_object->node.
  208. type)));
  209. return (AE_AML_OPERAND_TYPE);
  210. }
  211. /*
  212. * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
  213. * The bitmapped type allows multiple possible return types.
  214. *
  215. * Note, the cases below must handle all of the possible types returned
  216. * from all of the predefined names (including elements of returned
  217. * packages)
  218. */
  219. info->return_btype = acpi_ns_get_bitmapped_type(return_object);
  220. if (info->return_btype == ACPI_RTYPE_ANY) {
  221. /* Not one of the supported objects, must be incorrect */
  222. goto type_error_exit;
  223. }
  224. /* For reference objects, check that the reference type is correct */
  225. if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
  226. status = acpi_ns_check_reference(info, return_object);
  227. return (status);
  228. }
  229. /* Attempt simple repair of the returned object if necessary */
  230. status = acpi_ns_simple_repair(info, expected_btypes,
  231. package_index, return_object_ptr);
  232. if (ACPI_SUCCESS(status)) {
  233. return (AE_OK); /* Successful repair */
  234. }
  235. type_error_exit:
  236. /* Create a string with all expected types for this predefined object */
  237. acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
  238. if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
  239. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  240. info->node_flags,
  241. "Return type mismatch - found %s, expected %s",
  242. acpi_ut_get_object_type_name
  243. (return_object), type_buffer));
  244. } else {
  245. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  246. info->node_flags,
  247. "Return Package type mismatch at index %u - "
  248. "found %s, expected %s", package_index,
  249. acpi_ut_get_object_type_name
  250. (return_object), type_buffer));
  251. }
  252. return (AE_AML_OPERAND_TYPE);
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_ns_check_reference
  257. *
  258. * PARAMETERS: info - Method execution information block
  259. * return_object - Object returned from the evaluation of a
  260. * method or object
  261. *
  262. * RETURN: Status
  263. *
  264. * DESCRIPTION: Check a returned reference object for the correct reference
  265. * type. The only reference type that can be returned from a
  266. * predefined method is a named reference. All others are invalid.
  267. *
  268. ******************************************************************************/
  269. static acpi_status
  270. acpi_ns_check_reference(struct acpi_evaluate_info *info,
  271. union acpi_operand_object *return_object)
  272. {
  273. /*
  274. * Check the reference object for the correct reference type (opcode).
  275. * The only type of reference that can be converted to an union acpi_object is
  276. * a reference to a named object (reference class: NAME)
  277. */
  278. if (return_object->reference.class == ACPI_REFCLASS_NAME) {
  279. return (AE_OK);
  280. }
  281. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
  282. "Return type mismatch - unexpected reference object type [%s] %2.2X",
  283. acpi_ut_get_reference_name(return_object),
  284. return_object->reference.class));
  285. return (AE_AML_OPERAND_TYPE);
  286. }
  287. /*******************************************************************************
  288. *
  289. * FUNCTION: acpi_ns_get_bitmapped_type
  290. *
  291. * PARAMETERS: return_object - Object returned from method/obj evaluation
  292. *
  293. * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
  294. * type is not supported. ACPI_RTYPE_NONE indicates that no
  295. * object was returned (return_object is NULL).
  296. *
  297. * DESCRIPTION: Convert object type into a bitmapped object return type.
  298. *
  299. ******************************************************************************/
  300. static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
  301. {
  302. u32 return_btype;
  303. if (!return_object) {
  304. return (ACPI_RTYPE_NONE);
  305. }
  306. /* Map acpi_object_type to internal bitmapped type */
  307. switch (return_object->common.type) {
  308. case ACPI_TYPE_INTEGER:
  309. return_btype = ACPI_RTYPE_INTEGER;
  310. break;
  311. case ACPI_TYPE_BUFFER:
  312. return_btype = ACPI_RTYPE_BUFFER;
  313. break;
  314. case ACPI_TYPE_STRING:
  315. return_btype = ACPI_RTYPE_STRING;
  316. break;
  317. case ACPI_TYPE_PACKAGE:
  318. return_btype = ACPI_RTYPE_PACKAGE;
  319. break;
  320. case ACPI_TYPE_LOCAL_REFERENCE:
  321. return_btype = ACPI_RTYPE_REFERENCE;
  322. break;
  323. default:
  324. /* Not one of the supported objects, must be incorrect */
  325. return_btype = ACPI_RTYPE_ANY;
  326. break;
  327. }
  328. return (return_btype);
  329. }