nspredef.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /******************************************************************************
  2. *
  3. * Module Name: nspredef - Validation of ACPI predefined methods and objects
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. *
  141. * 4) If there is no return value and it is optional, just return
  142. * AE_OK (_WAK).
  143. */
  144. if (!(*return_object_ptr)) {
  145. goto exit;
  146. }
  147. /*
  148. * For returned Package objects, check the type of all sub-objects.
  149. * Note: Package may have been newly created by call above.
  150. */
  151. if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
  152. info->parent_package = *return_object_ptr;
  153. status = acpi_ns_check_package(info, return_object_ptr);
  154. if (ACPI_FAILURE(status)) {
  155. /* We might be able to fix some errors */
  156. if ((status != AE_AML_OPERAND_TYPE) &&
  157. (status != AE_AML_OPERAND_VALUE)) {
  158. goto exit;
  159. }
  160. }
  161. }
  162. /*
  163. * The return object was OK, or it was successfully repaired above.
  164. * Now make some additional checks such as verifying that package
  165. * objects are sorted correctly (if required) or buffer objects have
  166. * the correct data width (bytes vs. dwords). These repairs are
  167. * performed on a per-name basis, i.e., the code is specific to
  168. * particular predefined names.
  169. */
  170. status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
  171. exit:
  172. /*
  173. * If the object validation failed or if we successfully repaired one
  174. * or more objects, mark the parent node to suppress further warning
  175. * messages during the next evaluation of the same method/object.
  176. */
  177. if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
  178. node->flags |= ANOBJ_EVALUATED;
  179. }
  180. return (status);
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_ns_check_object_type
  185. *
  186. * PARAMETERS: info - Method execution information block
  187. * return_object_ptr - Pointer to the object returned from the
  188. * evaluation of a method or object
  189. * expected_btypes - Bitmap of expected return type(s)
  190. * package_index - Index of object within parent package (if
  191. * applicable - ACPI_NOT_PACKAGE_ELEMENT
  192. * otherwise)
  193. *
  194. * RETURN: Status
  195. *
  196. * DESCRIPTION: Check the type of the return object against the expected object
  197. * type(s). Use of Btype allows multiple expected object types.
  198. *
  199. ******************************************************************************/
  200. acpi_status
  201. acpi_ns_check_object_type(struct acpi_evaluate_info *info,
  202. union acpi_operand_object **return_object_ptr,
  203. u32 expected_btypes, u32 package_index)
  204. {
  205. union acpi_operand_object *return_object = *return_object_ptr;
  206. acpi_status status = AE_OK;
  207. char type_buffer[96]; /* Room for 10 types */
  208. /* A Namespace node should not get here, but make sure */
  209. if (return_object &&
  210. ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
  211. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  212. info->node_flags,
  213. "Invalid return type - Found a Namespace node [%4.4s] type %s",
  214. return_object->node.name.ascii,
  215. acpi_ut_get_type_name(return_object->node.
  216. type)));
  217. return (AE_AML_OPERAND_TYPE);
  218. }
  219. /*
  220. * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
  221. * The bitmapped type allows multiple possible return types.
  222. *
  223. * Note, the cases below must handle all of the possible types returned
  224. * from all of the predefined names (including elements of returned
  225. * packages)
  226. */
  227. info->return_btype = acpi_ns_get_bitmapped_type(return_object);
  228. if (info->return_btype == ACPI_RTYPE_ANY) {
  229. /* Not one of the supported objects, must be incorrect */
  230. goto type_error_exit;
  231. }
  232. /* For reference objects, check that the reference type is correct */
  233. if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
  234. status = acpi_ns_check_reference(info, return_object);
  235. return (status);
  236. }
  237. /* Attempt simple repair of the returned object if necessary */
  238. status = acpi_ns_simple_repair(info, expected_btypes,
  239. package_index, return_object_ptr);
  240. if (ACPI_SUCCESS(status)) {
  241. return (AE_OK); /* Successful repair */
  242. }
  243. type_error_exit:
  244. /* Create a string with all expected types for this predefined object */
  245. acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
  246. if (!return_object) {
  247. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  248. info->node_flags,
  249. "Expected return object of type %s",
  250. type_buffer));
  251. } else if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
  252. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  253. info->node_flags,
  254. "Return type mismatch - found %s, expected %s",
  255. acpi_ut_get_object_type_name
  256. (return_object), type_buffer));
  257. } else {
  258. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  259. info->node_flags,
  260. "Return Package type mismatch at index %u - "
  261. "found %s, expected %s", package_index,
  262. acpi_ut_get_object_type_name
  263. (return_object), type_buffer));
  264. }
  265. return (AE_AML_OPERAND_TYPE);
  266. }
  267. /*******************************************************************************
  268. *
  269. * FUNCTION: acpi_ns_check_reference
  270. *
  271. * PARAMETERS: info - Method execution information block
  272. * return_object - Object returned from the evaluation of a
  273. * method or object
  274. *
  275. * RETURN: Status
  276. *
  277. * DESCRIPTION: Check a returned reference object for the correct reference
  278. * type. The only reference type that can be returned from a
  279. * predefined method is a named reference. All others are invalid.
  280. *
  281. ******************************************************************************/
  282. static acpi_status
  283. acpi_ns_check_reference(struct acpi_evaluate_info *info,
  284. union acpi_operand_object *return_object)
  285. {
  286. /*
  287. * Check the reference object for the correct reference type (opcode).
  288. * The only type of reference that can be converted to an union acpi_object is
  289. * a reference to a named object (reference class: NAME)
  290. */
  291. if (return_object->reference.class == ACPI_REFCLASS_NAME) {
  292. return (AE_OK);
  293. }
  294. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
  295. "Return type mismatch - unexpected reference object type [%s] %2.2X",
  296. acpi_ut_get_reference_name(return_object),
  297. return_object->reference.class));
  298. return (AE_AML_OPERAND_TYPE);
  299. }
  300. /*******************************************************************************
  301. *
  302. * FUNCTION: acpi_ns_get_bitmapped_type
  303. *
  304. * PARAMETERS: return_object - Object returned from method/obj evaluation
  305. *
  306. * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
  307. * type is not supported. ACPI_RTYPE_NONE indicates that no
  308. * object was returned (return_object is NULL).
  309. *
  310. * DESCRIPTION: Convert object type into a bitmapped object return type.
  311. *
  312. ******************************************************************************/
  313. static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
  314. {
  315. u32 return_btype;
  316. if (!return_object) {
  317. return (ACPI_RTYPE_NONE);
  318. }
  319. /* Map acpi_object_type to internal bitmapped type */
  320. switch (return_object->common.type) {
  321. case ACPI_TYPE_INTEGER:
  322. return_btype = ACPI_RTYPE_INTEGER;
  323. break;
  324. case ACPI_TYPE_BUFFER:
  325. return_btype = ACPI_RTYPE_BUFFER;
  326. break;
  327. case ACPI_TYPE_STRING:
  328. return_btype = ACPI_RTYPE_STRING;
  329. break;
  330. case ACPI_TYPE_PACKAGE:
  331. return_btype = ACPI_RTYPE_PACKAGE;
  332. break;
  333. case ACPI_TYPE_LOCAL_REFERENCE:
  334. return_btype = ACPI_RTYPE_REFERENCE;
  335. break;
  336. default:
  337. /* Not one of the supported objects, must be incorrect */
  338. return_btype = ACPI_RTYPE_ANY;
  339. break;
  340. }
  341. return (return_btype);
  342. }