utpredef.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /******************************************************************************
  2. *
  3. * Module Name: utpredef - support functions for predefined names
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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. j = 1;
  132. buffer[0] = 0;
  133. this_rtype = ACPI_RTYPE_INTEGER;
  134. for (i = 0; i < ACPI_NUM_RTYPES; i++) {
  135. /* If one of the expected types, concatenate the name of this type */
  136. if (expected_btypes & this_rtype) {
  137. ACPI_STRCAT(buffer, &ut_rtype_names[i][j]);
  138. j = 0; /* Use name separator from now on */
  139. }
  140. this_rtype <<= 1; /* Next Rtype */
  141. }
  142. }
  143. /*******************************************************************************
  144. *
  145. * The remaining functions are used by iASL and acpi_help only
  146. *
  147. ******************************************************************************/
  148. #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
  149. #include <stdio.h>
  150. #include <string.h>
  151. /* Local prototypes */
  152. static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
  153. /* Types that can be returned externally by a predefined name */
  154. static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
  155. {
  156. ", UNSUPPORTED-TYPE",
  157. ", Integer",
  158. ", String",
  159. ", Buffer",
  160. ", Package"
  161. };
  162. /* Bit widths for resource descriptor predefined names */
  163. static const char *ut_resource_type_names[] = {
  164. "/1",
  165. "/2",
  166. "/3",
  167. "/8",
  168. "/16",
  169. "/32",
  170. "/64",
  171. "/variable",
  172. };
  173. /*******************************************************************************
  174. *
  175. * FUNCTION: acpi_ut_match_resource_name
  176. *
  177. * PARAMETERS: name - Name to find
  178. *
  179. * RETURN: Pointer to entry in the resource table. NULL indicates not
  180. * found.
  181. *
  182. * DESCRIPTION: Check an object name against the predefined resource
  183. * descriptor object list.
  184. *
  185. ******************************************************************************/
  186. const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
  187. {
  188. const union acpi_predefined_info *this_name;
  189. /* Quick check for a predefined name, first character must be underscore */
  190. if (name[0] != '_') {
  191. return (NULL);
  192. }
  193. /* Search info table for a predefined method/object name */
  194. this_name = acpi_gbl_resource_names;
  195. while (this_name->info.name[0]) {
  196. if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
  197. return (this_name);
  198. }
  199. this_name++;
  200. }
  201. return (NULL); /* Not found */
  202. }
  203. /*******************************************************************************
  204. *
  205. * FUNCTION: acpi_ut_display_predefined_method
  206. *
  207. * PARAMETERS: buffer - Scratch buffer for this function
  208. * this_name - Entry in the predefined method/name table
  209. * multi_line - TRUE if output should be on >1 line
  210. *
  211. * RETURN: None
  212. *
  213. * DESCRIPTION: Display information about a predefined method. Number and
  214. * type of the input arguments, and expected type(s) for the
  215. * return value, if any.
  216. *
  217. ******************************************************************************/
  218. void
  219. acpi_ut_display_predefined_method(char *buffer,
  220. const union acpi_predefined_info *this_name,
  221. u8 multi_line)
  222. {
  223. u32 arg_count;
  224. /*
  225. * Get the argument count and the string buffer
  226. * containing all argument types
  227. */
  228. arg_count = acpi_ut_get_argument_types(buffer,
  229. this_name->info.argument_list);
  230. if (multi_line) {
  231. printf(" ");
  232. }
  233. printf("%4.4s Requires %s%u argument%s",
  234. this_name->info.name,
  235. (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
  236. "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
  237. /* Display the types for any arguments */
  238. if (arg_count > 0) {
  239. printf(" (%s)", buffer);
  240. }
  241. if (multi_line) {
  242. printf("\n ");
  243. }
  244. /* Get the return value type(s) allowed */
  245. if (this_name->info.expected_btypes) {
  246. acpi_ut_get_expected_return_types(buffer,
  247. this_name->info.
  248. expected_btypes);
  249. printf(" Return value types: %s\n", buffer);
  250. } else {
  251. printf(" No return value\n");
  252. }
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_ut_get_argument_types
  257. *
  258. * PARAMETERS: buffer - Where to return the formatted types
  259. * argument_types - Types field for this method
  260. *
  261. * RETURN: count - the number of arguments required for this method
  262. *
  263. * DESCRIPTION: Format the required data types for this method (Integer,
  264. * String, Buffer, or Package) and return the required argument
  265. * count.
  266. *
  267. ******************************************************************************/
  268. static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
  269. {
  270. u16 this_argument_type;
  271. u16 sub_index;
  272. u16 arg_count;
  273. u32 i;
  274. *buffer = 0;
  275. sub_index = 2;
  276. /* First field in the types list is the count of args to follow */
  277. arg_count = (argument_types & METHOD_ARG_MASK);
  278. argument_types >>= METHOD_ARG_BIT_WIDTH;
  279. if (arg_count > METHOD_PREDEF_ARGS_MAX) {
  280. printf("**** Invalid argument count (%u) "
  281. "in predefined info structure\n", arg_count);
  282. return (arg_count);
  283. }
  284. /* Get each argument from the list, convert to ascii, store to buffer */
  285. for (i = 0; i < arg_count; i++) {
  286. this_argument_type = (argument_types & METHOD_ARG_MASK);
  287. if (!this_argument_type
  288. || (this_argument_type > METHOD_MAX_ARG_TYPE)) {
  289. printf("**** Invalid argument type (%u) "
  290. "in predefined info structure\n",
  291. this_argument_type);
  292. return (arg_count);
  293. }
  294. strcat(buffer,
  295. ut_external_type_names[this_argument_type] + sub_index);
  296. /* Shift to next argument type field */
  297. argument_types >>= METHOD_ARG_BIT_WIDTH;
  298. sub_index = 0;
  299. }
  300. return (arg_count);
  301. }
  302. /*******************************************************************************
  303. *
  304. * FUNCTION: acpi_ut_get_resource_bit_width
  305. *
  306. * PARAMETERS: buffer - Where the formatted string is returned
  307. * types - Bitfield of expected data types
  308. *
  309. * RETURN: Count of return types. Formatted string in Buffer.
  310. *
  311. * DESCRIPTION: Format the resource bit widths into a printable string.
  312. *
  313. ******************************************************************************/
  314. u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
  315. {
  316. u32 i;
  317. u16 sub_index;
  318. u32 found;
  319. *buffer = 0;
  320. sub_index = 1;
  321. found = 0;
  322. for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
  323. if (types & 1) {
  324. strcat(buffer, &(ut_resource_type_names[i][sub_index]));
  325. sub_index = 0;
  326. found++;
  327. }
  328. types >>= 1;
  329. }
  330. return (found);
  331. }
  332. #endif