nsarguments.c 10 KB

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