nsarguments.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: nsarguments - Validation of args for ACPI predefined methods
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #include "acpredef.h"
  13. #define _COMPONENT ACPI_NAMESPACE
  14. ACPI_MODULE_NAME("nsarguments")
  15. /*******************************************************************************
  16. *
  17. * FUNCTION: acpi_ns_check_argument_types
  18. *
  19. * PARAMETERS: info - Method execution information block
  20. *
  21. * RETURN: None
  22. *
  23. * DESCRIPTION: Check the incoming argument count and all argument types
  24. * against the argument type list for a predefined name.
  25. *
  26. ******************************************************************************/
  27. void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
  28. {
  29. u16 arg_type_list;
  30. u8 arg_count;
  31. u8 arg_type;
  32. u8 user_arg_type;
  33. u32 i;
  34. /*
  35. * If not a predefined name, cannot typecheck args, because
  36. * we have no idea what argument types are expected.
  37. * Also, ignore typecheck if warnings/errors if this method
  38. * has already been evaluated at least once -- in order
  39. * to suppress repetitive messages.
  40. */
  41. if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) {
  42. return;
  43. }
  44. arg_type_list = info->predefined->info.argument_list;
  45. arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
  46. /* Typecheck all arguments */
  47. for (i = 0; ((i < arg_count) && (i < info->param_count)); i++) {
  48. arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
  49. user_arg_type = info->parameters[i]->common.type;
  50. if (user_arg_type != arg_type) {
  51. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  52. ACPI_WARN_ALWAYS,
  53. "Argument #%u type mismatch - "
  54. "Found [%s], ACPI requires [%s]",
  55. (i + 1),
  56. acpi_ut_get_type_name
  57. (user_arg_type),
  58. acpi_ut_get_type_name(arg_type)));
  59. /* Prevent any additional typechecking for this method */
  60. info->node->flags |= ANOBJ_EVALUATED;
  61. }
  62. }
  63. }
  64. /*******************************************************************************
  65. *
  66. * FUNCTION: acpi_ns_check_acpi_compliance
  67. *
  68. * PARAMETERS: pathname - Full pathname to the node (for error msgs)
  69. * node - Namespace node for the method/object
  70. * predefined - Pointer to entry in predefined name table
  71. *
  72. * RETURN: None
  73. *
  74. * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
  75. * predefined name is what is expected (matches what is defined in
  76. * the ACPI specification for this predefined name.)
  77. *
  78. ******************************************************************************/
  79. void
  80. acpi_ns_check_acpi_compliance(char *pathname,
  81. struct acpi_namespace_node *node,
  82. const union acpi_predefined_info *predefined)
  83. {
  84. u32 aml_param_count;
  85. u32 required_param_count;
  86. if (!predefined || (node->flags & ANOBJ_EVALUATED)) {
  87. return;
  88. }
  89. /* Get the ACPI-required arg count from the predefined info table */
  90. required_param_count =
  91. METHOD_GET_ARG_COUNT(predefined->info.argument_list);
  92. /*
  93. * If this object is not a control method, we can check if the ACPI
  94. * spec requires that it be a method.
  95. */
  96. if (node->type != ACPI_TYPE_METHOD) {
  97. if (required_param_count > 0) {
  98. /* Object requires args, must be implemented as a method */
  99. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
  100. ACPI_WARN_ALWAYS,
  101. "Object (%s) must be a control method with %u arguments",
  102. acpi_ut_get_type_name(node->
  103. type),
  104. required_param_count));
  105. } else if (!required_param_count
  106. && !predefined->info.expected_btypes) {
  107. /* Object requires no args and no return value, must be a method */
  108. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
  109. ACPI_WARN_ALWAYS,
  110. "Object (%s) must be a control method "
  111. "with no arguments and no return value",
  112. acpi_ut_get_type_name(node->
  113. type)));
  114. }
  115. return;
  116. }
  117. /*
  118. * This is a control method.
  119. * Check that the ASL/AML-defined parameter count for this method
  120. * matches the ACPI-required parameter count
  121. *
  122. * Some methods are allowed to have a "minimum" number of args (_SCP)
  123. * because their definition in ACPI has changed over time.
  124. *
  125. * Note: These are BIOS errors in the declaration of the object
  126. */
  127. aml_param_count = node->object->method.param_count;
  128. if (aml_param_count < required_param_count) {
  129. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  130. "Insufficient arguments - "
  131. "ASL declared %u, ACPI requires %u",
  132. aml_param_count,
  133. required_param_count));
  134. } else if ((aml_param_count > required_param_count)
  135. && !(predefined->info.
  136. argument_list & ARG_COUNT_IS_MINIMUM)) {
  137. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  138. "Excess arguments - "
  139. "ASL declared %u, ACPI requires %u",
  140. aml_param_count,
  141. required_param_count));
  142. }
  143. }
  144. /*******************************************************************************
  145. *
  146. * FUNCTION: acpi_ns_check_argument_count
  147. *
  148. * PARAMETERS: pathname - Full pathname to the node (for error msgs)
  149. * node - Namespace node for the method/object
  150. * user_param_count - Number of args passed in by the caller
  151. * predefined - Pointer to entry in predefined name table
  152. *
  153. * RETURN: None
  154. *
  155. * DESCRIPTION: Check that incoming argument count matches the declared
  156. * parameter count (in the ASL/AML) for an object.
  157. *
  158. ******************************************************************************/
  159. void
  160. acpi_ns_check_argument_count(char *pathname,
  161. struct acpi_namespace_node *node,
  162. u32 user_param_count,
  163. const union acpi_predefined_info *predefined)
  164. {
  165. u32 aml_param_count;
  166. u32 required_param_count;
  167. if (node->flags & ANOBJ_EVALUATED) {
  168. return;
  169. }
  170. if (!predefined) {
  171. /*
  172. * Not a predefined name. Check the incoming user argument count
  173. * against the count that is specified in the method/object.
  174. */
  175. if (node->type != ACPI_TYPE_METHOD) {
  176. if (user_param_count) {
  177. ACPI_INFO_PREDEFINED((AE_INFO, pathname,
  178. ACPI_WARN_ALWAYS,
  179. "%u arguments were passed to a non-method ACPI object (%s)",
  180. user_param_count,
  181. acpi_ut_get_type_name
  182. (node->type)));
  183. }
  184. return;
  185. }
  186. /*
  187. * This is a control method. Check the parameter count.
  188. * We can only check the incoming argument count against the
  189. * argument count declared for the method in the ASL/AML.
  190. *
  191. * Emit a message if too few or too many arguments have been passed
  192. * by the caller.
  193. *
  194. * Note: Too many arguments will not cause the method to
  195. * fail. However, the method will fail if there are too few
  196. * arguments and the method attempts to use one of the missing ones.
  197. */
  198. aml_param_count = node->object->method.param_count;
  199. if (user_param_count < aml_param_count) {
  200. ACPI_WARN_PREDEFINED((AE_INFO, pathname,
  201. ACPI_WARN_ALWAYS,
  202. "Insufficient arguments - "
  203. "Caller passed %u, method requires %u",
  204. user_param_count,
  205. aml_param_count));
  206. } else if (user_param_count > aml_param_count) {
  207. ACPI_INFO_PREDEFINED((AE_INFO, pathname,
  208. ACPI_WARN_ALWAYS,
  209. "Excess arguments - "
  210. "Caller passed %u, method requires %u",
  211. user_param_count,
  212. aml_param_count));
  213. }
  214. return;
  215. }
  216. /*
  217. * This is a predefined name. Validate the user-supplied parameter
  218. * count against the ACPI specification. We don't validate against
  219. * the method itself because what is important here is that the
  220. * caller is in conformance with the spec. (The arg count for the
  221. * method was checked against the ACPI spec earlier.)
  222. *
  223. * Some methods are allowed to have a "minimum" number of args (_SCP)
  224. * because their definition in ACPI has changed over time.
  225. */
  226. required_param_count =
  227. METHOD_GET_ARG_COUNT(predefined->info.argument_list);
  228. if (user_param_count < required_param_count) {
  229. ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  230. "Insufficient arguments - "
  231. "Caller passed %u, ACPI requires %u",
  232. user_param_count, required_param_count));
  233. } else if ((user_param_count > required_param_count) &&
  234. !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) {
  235. ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  236. "Excess arguments - "
  237. "Caller passed %u, ACPI requires %u",
  238. user_param_count, required_param_count));
  239. }
  240. }