utpredef.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /******************************************************************************
  2. *
  3. * Module Name: utpredef - support functions for predefined names
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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 "acpredef.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utpredef")
  47. /*
  48. * Names for the types that can be returned by the predefined objects.
  49. * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
  50. */
  51. static const char *ut_rtype_names[] = {
  52. "/Integer",
  53. "/String",
  54. "/Buffer",
  55. "/Package",
  56. "/Reference",
  57. };
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: acpi_ut_get_next_predefined_method
  61. *
  62. * PARAMETERS: this_name - Entry in the predefined method/name table
  63. *
  64. * RETURN: Pointer to next entry in predefined table.
  65. *
  66. * DESCRIPTION: Get the next entry in the predefine method table. Handles the
  67. * cases where a package info entry follows a method name that
  68. * returns a package.
  69. *
  70. ******************************************************************************/
  71. const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
  72. acpi_predefined_info
  73. *this_name)
  74. {
  75. /*
  76. * Skip next entry in the table if this name returns a Package
  77. * (next entry contains the package info)
  78. */
  79. if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) &&
  80. (this_name->info.expected_btypes != ACPI_RTYPE_ALL)) {
  81. this_name++;
  82. }
  83. this_name++;
  84. return (this_name);
  85. }
  86. /*******************************************************************************
  87. *
  88. * FUNCTION: acpi_ut_match_predefined_method
  89. *
  90. * PARAMETERS: name - Name to find
  91. *
  92. * RETURN: Pointer to entry in predefined table. NULL indicates not found.
  93. *
  94. * DESCRIPTION: Check an object name against the predefined object list.
  95. *
  96. ******************************************************************************/
  97. const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name)
  98. {
  99. const union acpi_predefined_info *this_name;
  100. /* Quick check for a predefined name, first character must be underscore */
  101. if (name[0] != '_') {
  102. return (NULL);
  103. }
  104. /* Search info table for a predefined method/object name */
  105. this_name = acpi_gbl_predefined_methods;
  106. while (this_name->info.name[0]) {
  107. if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
  108. return (this_name);
  109. }
  110. this_name = acpi_ut_get_next_predefined_method(this_name);
  111. }
  112. return (NULL); /* Not found */
  113. }
  114. /*******************************************************************************
  115. *
  116. * FUNCTION: acpi_ut_get_expected_return_types
  117. *
  118. * PARAMETERS: buffer - Where the formatted string is returned
  119. * expected_Btypes - Bitfield of expected data types
  120. *
  121. * RETURN: Formatted string in Buffer.
  122. *
  123. * DESCRIPTION: Format the expected object types into a printable string.
  124. *
  125. ******************************************************************************/
  126. void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
  127. {
  128. u32 this_rtype;
  129. u32 i;
  130. u32 j;
  131. if (!expected_btypes) {
  132. strcpy(buffer, "NONE");
  133. return;
  134. }
  135. j = 1;
  136. buffer[0] = 0;
  137. this_rtype = ACPI_RTYPE_INTEGER;
  138. for (i = 0; i < ACPI_NUM_RTYPES; i++) {
  139. /* If one of the expected types, concatenate the name of this type */
  140. if (expected_btypes & this_rtype) {
  141. strcat(buffer, &ut_rtype_names[i][j]);
  142. j = 0; /* Use name separator from now on */
  143. }
  144. this_rtype <<= 1; /* Next Rtype */
  145. }
  146. }
  147. /*******************************************************************************
  148. *
  149. * The remaining functions are used by iASL and acpi_help only
  150. *
  151. ******************************************************************************/
  152. #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
  153. /* Local prototypes */
  154. static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
  155. /* Types that can be returned externally by a predefined name */
  156. static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
  157. {
  158. ", UNSUPPORTED-TYPE",
  159. ", Integer",
  160. ", String",
  161. ", Buffer",
  162. ", Package"
  163. };
  164. /* Bit widths for resource descriptor predefined names */
  165. static const char *ut_resource_type_names[] = {
  166. "/1",
  167. "/2",
  168. "/3",
  169. "/8",
  170. "/16",
  171. "/32",
  172. "/64",
  173. "/variable",
  174. };
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_ut_match_resource_name
  178. *
  179. * PARAMETERS: name - Name to find
  180. *
  181. * RETURN: Pointer to entry in the resource table. NULL indicates not
  182. * found.
  183. *
  184. * DESCRIPTION: Check an object name against the predefined resource
  185. * descriptor object list.
  186. *
  187. ******************************************************************************/
  188. const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
  189. {
  190. const union acpi_predefined_info *this_name;
  191. /*
  192. * Quick check for a predefined name, first character must
  193. * be underscore
  194. */
  195. if (name[0] != '_') {
  196. return (NULL);
  197. }
  198. /* Search info table for a predefined method/object name */
  199. this_name = acpi_gbl_resource_names;
  200. while (this_name->info.name[0]) {
  201. if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
  202. return (this_name);
  203. }
  204. this_name++;
  205. }
  206. return (NULL); /* Not found */
  207. }
  208. /*******************************************************************************
  209. *
  210. * FUNCTION: acpi_ut_display_predefined_method
  211. *
  212. * PARAMETERS: buffer - Scratch buffer for this function
  213. * this_name - Entry in the predefined method/name table
  214. * multi_line - TRUE if output should be on >1 line
  215. *
  216. * RETURN: None
  217. *
  218. * DESCRIPTION: Display information about a predefined method. Number and
  219. * type of the input arguments, and expected type(s) for the
  220. * return value, if any.
  221. *
  222. ******************************************************************************/
  223. void
  224. acpi_ut_display_predefined_method(char *buffer,
  225. const union acpi_predefined_info *this_name,
  226. u8 multi_line)
  227. {
  228. u32 arg_count;
  229. /*
  230. * Get the argument count and the string buffer
  231. * containing all argument types
  232. */
  233. arg_count = acpi_ut_get_argument_types(buffer,
  234. this_name->info.argument_list);
  235. if (multi_line) {
  236. printf(" ");
  237. }
  238. printf("%4.4s Requires %s%u argument%s",
  239. this_name->info.name,
  240. (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
  241. "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
  242. /* Display the types for any arguments */
  243. if (arg_count > 0) {
  244. printf(" (%s)", buffer);
  245. }
  246. if (multi_line) {
  247. printf("\n ");
  248. }
  249. /* Get the return value type(s) allowed */
  250. if (this_name->info.expected_btypes) {
  251. acpi_ut_get_expected_return_types(buffer,
  252. this_name->info.
  253. expected_btypes);
  254. printf(" Return value types: %s\n", buffer);
  255. } else {
  256. printf(" No return value\n");
  257. }
  258. }
  259. /*******************************************************************************
  260. *
  261. * FUNCTION: acpi_ut_get_argument_types
  262. *
  263. * PARAMETERS: buffer - Where to return the formatted types
  264. * argument_types - Types field for this method
  265. *
  266. * RETURN: count - the number of arguments required for this method
  267. *
  268. * DESCRIPTION: Format the required data types for this method (Integer,
  269. * String, Buffer, or Package) and return the required argument
  270. * count.
  271. *
  272. ******************************************************************************/
  273. static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
  274. {
  275. u16 this_argument_type;
  276. u16 sub_index;
  277. u16 arg_count;
  278. u32 i;
  279. *buffer = 0;
  280. sub_index = 2;
  281. /* First field in the types list is the count of args to follow */
  282. arg_count = METHOD_GET_ARG_COUNT(argument_types);
  283. if (arg_count > METHOD_PREDEF_ARGS_MAX) {
  284. printf("**** Invalid argument count (%u) "
  285. "in predefined info structure\n", arg_count);
  286. return (arg_count);
  287. }
  288. /* Get each argument from the list, convert to ascii, store to buffer */
  289. for (i = 0; i < arg_count; i++) {
  290. this_argument_type = METHOD_GET_NEXT_TYPE(argument_types);
  291. if (!this_argument_type
  292. || (this_argument_type > METHOD_MAX_ARG_TYPE)) {
  293. printf("**** Invalid argument type (%u) "
  294. "in predefined info structure\n",
  295. this_argument_type);
  296. return (arg_count);
  297. }
  298. strcat(buffer,
  299. ut_external_type_names[this_argument_type] + sub_index);
  300. sub_index = 0;
  301. }
  302. return (arg_count);
  303. }
  304. /*******************************************************************************
  305. *
  306. * FUNCTION: acpi_ut_get_resource_bit_width
  307. *
  308. * PARAMETERS: buffer - Where the formatted string is returned
  309. * types - Bitfield of expected data types
  310. *
  311. * RETURN: Count of return types. Formatted string in Buffer.
  312. *
  313. * DESCRIPTION: Format the resource bit widths into a printable string.
  314. *
  315. ******************************************************************************/
  316. u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
  317. {
  318. u32 i;
  319. u16 sub_index;
  320. u32 found;
  321. *buffer = 0;
  322. sub_index = 1;
  323. found = 0;
  324. for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
  325. if (types & 1) {
  326. strcat(buffer, &(ut_resource_type_names[i][sub_index]));
  327. sub_index = 0;
  328. found++;
  329. }
  330. types >>= 1;
  331. }
  332. return (found);
  333. }
  334. #endif