nsarguments.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 - 2022, 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. /* No typechecking for ACPI_TYPE_ANY */
  51. if ((user_arg_type != arg_type) && (arg_type != ACPI_TYPE_ANY)) {
  52. ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
  53. ACPI_WARN_ALWAYS,
  54. "Argument #%u type mismatch - "
  55. "Found [%s], ACPI requires [%s]",
  56. (i + 1),
  57. acpi_ut_get_type_name
  58. (user_arg_type),
  59. acpi_ut_get_type_name(arg_type)));
  60. /* Prevent any additional typechecking for this method */
  61. info->node->flags |= ANOBJ_EVALUATED;
  62. }
  63. }
  64. }
  65. /*******************************************************************************
  66. *
  67. * FUNCTION: acpi_ns_check_acpi_compliance
  68. *
  69. * PARAMETERS: pathname - Full pathname to the node (for error msgs)
  70. * node - Namespace node for the method/object
  71. * predefined - Pointer to entry in predefined name table
  72. *
  73. * RETURN: None
  74. *
  75. * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
  76. * predefined name is what is expected (matches what is defined in
  77. * the ACPI specification for this predefined name.)
  78. *
  79. ******************************************************************************/
  80. void
  81. acpi_ns_check_acpi_compliance(char *pathname,
  82. struct acpi_namespace_node *node,
  83. const union acpi_predefined_info *predefined)
  84. {
  85. u32 aml_param_count;
  86. u32 required_param_count;
  87. if (!predefined || (node->flags & ANOBJ_EVALUATED)) {
  88. return;
  89. }
  90. /* Get the ACPI-required arg count from the predefined info table */
  91. required_param_count =
  92. METHOD_GET_ARG_COUNT(predefined->info.argument_list);
  93. /*
  94. * If this object is not a control method, we can check if the ACPI
  95. * spec requires that it be a method.
  96. */
  97. if (node->type != ACPI_TYPE_METHOD) {
  98. if (required_param_count > 0) {
  99. /* Object requires args, must be implemented as a method */
  100. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
  101. ACPI_WARN_ALWAYS,
  102. "Object (%s) must be a control method with %u arguments",
  103. acpi_ut_get_type_name(node->
  104. type),
  105. required_param_count));
  106. } else if (!required_param_count
  107. && !predefined->info.expected_btypes) {
  108. /* Object requires no args and no return value, must be a method */
  109. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
  110. ACPI_WARN_ALWAYS,
  111. "Object (%s) must be a control method "
  112. "with no arguments and no return value",
  113. acpi_ut_get_type_name(node->
  114. type)));
  115. }
  116. return;
  117. }
  118. /*
  119. * This is a control method.
  120. * Check that the ASL/AML-defined parameter count for this method
  121. * matches the ACPI-required parameter count
  122. *
  123. * Some methods are allowed to have a "minimum" number of args (_SCP)
  124. * because their definition in ACPI has changed over time.
  125. *
  126. * Note: These are BIOS errors in the declaration of the object
  127. */
  128. aml_param_count = node->object->method.param_count;
  129. if (aml_param_count < required_param_count) {
  130. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  131. "Insufficient arguments - "
  132. "ASL declared %u, ACPI requires %u",
  133. aml_param_count,
  134. required_param_count));
  135. } else if ((aml_param_count > required_param_count)
  136. && !(predefined->info.
  137. argument_list & ARG_COUNT_IS_MINIMUM)) {
  138. ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  139. "Excess arguments - "
  140. "ASL declared %u, ACPI requires %u",
  141. aml_param_count,
  142. required_param_count));
  143. }
  144. }
  145. /*******************************************************************************
  146. *
  147. * FUNCTION: acpi_ns_check_argument_count
  148. *
  149. * PARAMETERS: pathname - Full pathname to the node (for error msgs)
  150. * node - Namespace node for the method/object
  151. * user_param_count - Number of args passed in by the caller
  152. * predefined - Pointer to entry in predefined name table
  153. *
  154. * RETURN: None
  155. *
  156. * DESCRIPTION: Check that incoming argument count matches the declared
  157. * parameter count (in the ASL/AML) for an object.
  158. *
  159. ******************************************************************************/
  160. void
  161. acpi_ns_check_argument_count(char *pathname,
  162. struct acpi_namespace_node *node,
  163. u32 user_param_count,
  164. const union acpi_predefined_info *predefined)
  165. {
  166. u32 aml_param_count;
  167. u32 required_param_count;
  168. if (node->flags & ANOBJ_EVALUATED) {
  169. return;
  170. }
  171. if (!predefined) {
  172. /*
  173. * Not a predefined name. Check the incoming user argument count
  174. * against the count that is specified in the method/object.
  175. */
  176. if (node->type != ACPI_TYPE_METHOD) {
  177. if (user_param_count) {
  178. ACPI_INFO_PREDEFINED((AE_INFO, pathname,
  179. ACPI_WARN_ALWAYS,
  180. "%u arguments were passed to a non-method ACPI object (%s)",
  181. user_param_count,
  182. acpi_ut_get_type_name
  183. (node->type)));
  184. }
  185. return;
  186. }
  187. /*
  188. * This is a control method. Check the parameter count.
  189. * We can only check the incoming argument count against the
  190. * argument count declared for the method in the ASL/AML.
  191. *
  192. * Emit a message if too few or too many arguments have been passed
  193. * by the caller.
  194. *
  195. * Note: Too many arguments will not cause the method to
  196. * fail. However, the method will fail if there are too few
  197. * arguments and the method attempts to use one of the missing ones.
  198. */
  199. aml_param_count = node->object->method.param_count;
  200. if (user_param_count < aml_param_count) {
  201. ACPI_WARN_PREDEFINED((AE_INFO, pathname,
  202. ACPI_WARN_ALWAYS,
  203. "Insufficient arguments - "
  204. "Caller passed %u, method requires %u",
  205. user_param_count,
  206. aml_param_count));
  207. } else if (user_param_count > aml_param_count) {
  208. ACPI_INFO_PREDEFINED((AE_INFO, pathname,
  209. ACPI_WARN_ALWAYS,
  210. "Excess arguments - "
  211. "Caller passed %u, method requires %u",
  212. user_param_count,
  213. aml_param_count));
  214. }
  215. return;
  216. }
  217. /*
  218. * This is a predefined name. Validate the user-supplied parameter
  219. * count against the ACPI specification. We don't validate against
  220. * the method itself because what is important here is that the
  221. * caller is in conformance with the spec. (The arg count for the
  222. * method was checked against the ACPI spec earlier.)
  223. *
  224. * Some methods are allowed to have a "minimum" number of args (_SCP)
  225. * because their definition in ACPI has changed over time.
  226. */
  227. required_param_count =
  228. METHOD_GET_ARG_COUNT(predefined->info.argument_list);
  229. if (user_param_count < required_param_count) {
  230. ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  231. "Insufficient arguments - "
  232. "Caller passed %u, ACPI requires %u",
  233. user_param_count, required_param_count));
  234. } else if ((user_param_count > required_param_count) &&
  235. !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) {
  236. ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
  237. "Excess arguments - "
  238. "Caller passed %u, ACPI requires %u",
  239. user_param_count, required_param_count));
  240. }
  241. }