nsarguments.c 10.0 KB

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