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