Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / utpredef.c
blobdd277f7e9f1022455c31946b27e58fc58a55a22c
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utpredef - support functions for predefined names
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acpredef.h"
14 #define _COMPONENT ACPI_UTILITIES
15 ACPI_MODULE_NAME("utpredef")
18 * Names for the types that can be returned by the predefined objects.
19 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
21 static const char *ut_rtype_names[] = {
22 "/Integer",
23 "/String",
24 "/Buffer",
25 "/Package",
26 "/Reference",
29 /*******************************************************************************
31 * FUNCTION: acpi_ut_get_next_predefined_method
33 * PARAMETERS: this_name - Entry in the predefined method/name table
35 * RETURN: Pointer to next entry in predefined table.
37 * DESCRIPTION: Get the next entry in the predefine method table. Handles the
38 * cases where a package info entry follows a method name that
39 * returns a package.
41 ******************************************************************************/
43 const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
44 acpi_predefined_info
45 *this_name)
49 * Skip next entry in the table if this name returns a Package
50 * (next entry contains the package info)
52 if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) &&
53 (this_name->info.expected_btypes != ACPI_RTYPE_ALL)) {
54 this_name++;
57 this_name++;
58 return (this_name);
61 /*******************************************************************************
63 * FUNCTION: acpi_ut_match_predefined_method
65 * PARAMETERS: name - Name to find
67 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
69 * DESCRIPTION: Check an object name against the predefined object list.
71 ******************************************************************************/
73 const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name)
75 const union acpi_predefined_info *this_name;
77 /* Quick check for a predefined name, first character must be underscore */
79 if (name[0] != '_') {
80 return (NULL);
83 /* Search info table for a predefined method/object name */
85 this_name = acpi_gbl_predefined_methods;
86 while (this_name->info.name[0]) {
87 if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) {
88 return (this_name);
91 this_name = acpi_ut_get_next_predefined_method(this_name);
94 return (NULL); /* Not found */
97 /*******************************************************************************
99 * FUNCTION: acpi_ut_get_expected_return_types
101 * PARAMETERS: buffer - Where the formatted string is returned
102 * expected_Btypes - Bitfield of expected data types
104 * RETURN: Formatted string in Buffer.
106 * DESCRIPTION: Format the expected object types into a printable string.
108 ******************************************************************************/
110 void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
112 u32 this_rtype;
113 u32 i;
114 u32 j;
116 if (!expected_btypes) {
117 strcpy(buffer, "NONE");
118 return;
121 j = 1;
122 buffer[0] = 0;
123 this_rtype = ACPI_RTYPE_INTEGER;
125 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
127 /* If one of the expected types, concatenate the name of this type */
129 if (expected_btypes & this_rtype) {
130 strcat(buffer, &ut_rtype_names[i][j]);
131 j = 0; /* Use name separator from now on */
134 this_rtype <<= 1; /* Next Rtype */
138 /*******************************************************************************
140 * The remaining functions are used by iASL and acpi_help only
142 ******************************************************************************/
144 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
146 /* Local prototypes */
148 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
150 /* Types that can be returned externally by a predefined name */
152 static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
154 ", Type_ANY",
155 ", Integer",
156 ", String",
157 ", Buffer",
158 ", Package"
161 /* 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",
174 /*******************************************************************************
176 * FUNCTION: acpi_ut_match_resource_name
178 * PARAMETERS: name - Name to find
180 * RETURN: Pointer to entry in the resource table. NULL indicates not
181 * found.
183 * DESCRIPTION: Check an object name against the predefined resource
184 * descriptor object list.
186 ******************************************************************************/
188 const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
190 const union acpi_predefined_info *this_name;
193 * Quick check for a predefined name, first character must
194 * be underscore
196 if (name[0] != '_') {
197 return (NULL);
200 /* Search info table for a predefined method/object name */
202 this_name = acpi_gbl_resource_names;
203 while (this_name->info.name[0]) {
204 if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) {
205 return (this_name);
208 this_name++;
211 return (NULL); /* Not found */
214 /*******************************************************************************
216 * FUNCTION: acpi_ut_display_predefined_method
218 * PARAMETERS: buffer - Scratch buffer for this function
219 * this_name - Entry in the predefined method/name table
220 * multi_line - TRUE if output should be on >1 line
222 * RETURN: None
224 * DESCRIPTION: Display information about a predefined method. Number and
225 * type of the input arguments, and expected type(s) for the
226 * return value, if any.
228 ******************************************************************************/
230 void
231 acpi_ut_display_predefined_method(char *buffer,
232 const union acpi_predefined_info *this_name,
233 u8 multi_line)
235 u32 arg_count;
238 * Get the argument count and the string buffer
239 * containing all argument types
241 arg_count = acpi_ut_get_argument_types(buffer,
242 this_name->info.argument_list);
244 if (multi_line) {
245 printf(" ");
248 printf("%4.4s Requires %s%u argument%s",
249 this_name->info.name,
250 (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
251 "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
253 /* Display the types for any arguments */
255 if (arg_count > 0) {
256 printf(" (%s)", buffer);
259 if (multi_line) {
260 printf("\n ");
263 /* Get the return value type(s) allowed */
265 if (this_name->info.expected_btypes) {
266 acpi_ut_get_expected_return_types(buffer,
267 this_name->info.
268 expected_btypes);
269 printf(" Return value types: %s\n", buffer);
270 } else {
271 printf(" No return value\n");
275 /*******************************************************************************
277 * FUNCTION: acpi_ut_get_argument_types
279 * PARAMETERS: buffer - Where to return the formatted types
280 * argument_types - Types field for this method
282 * RETURN: count - the number of arguments required for this method
284 * DESCRIPTION: Format the required data types for this method (Integer,
285 * String, Buffer, or Package) and return the required argument
286 * count.
288 ******************************************************************************/
290 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
292 u16 this_argument_type;
293 u16 sub_index;
294 u16 arg_count;
295 u32 i;
297 *buffer = 0;
298 sub_index = 2;
300 /* First field in the types list is the count of args to follow */
302 arg_count = METHOD_GET_ARG_COUNT(argument_types);
303 if (arg_count > METHOD_PREDEF_ARGS_MAX) {
304 printf("**** Invalid argument count (%u) "
305 "in predefined info structure\n", arg_count);
306 return (arg_count);
309 /* Get each argument from the list, convert to ascii, store to buffer */
311 for (i = 0; i < arg_count; i++) {
312 this_argument_type = METHOD_GET_NEXT_TYPE(argument_types);
314 if (this_argument_type > METHOD_MAX_ARG_TYPE) {
315 printf("**** Invalid argument type (%u) "
316 "in predefined info structure\n",
317 this_argument_type);
318 return (arg_count);
321 strcat(buffer,
322 ut_external_type_names[this_argument_type] + sub_index);
323 sub_index = 0;
326 return (arg_count);
329 /*******************************************************************************
331 * FUNCTION: acpi_ut_get_resource_bit_width
333 * PARAMETERS: buffer - Where the formatted string is returned
334 * types - Bitfield of expected data types
336 * RETURN: Count of return types. Formatted string in Buffer.
338 * DESCRIPTION: Format the resource bit widths into a printable string.
340 ******************************************************************************/
342 u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
344 u32 i;
345 u16 sub_index;
346 u32 found;
348 *buffer = 0;
349 sub_index = 1;
350 found = 0;
352 for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
353 if (types & 1) {
354 strcat(buffer, &(ut_resource_type_names[i][sub_index]));
355 sub_index = 0;
356 found++;
359 types >>= 1;
362 return (found);
364 #endif