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 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.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
[] = {
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
41 ******************************************************************************/
43 const union acpi_predefined_info
*acpi_ut_get_next_predefined_method(const union
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
)) {
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 */
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_NAME(name
, this_name
->info
.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
)
116 if (!expected_btypes
) {
117 strcpy(buffer
, "NONE");
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 ", UNSUPPORTED-TYPE",
161 /* Bit widths for resource descriptor predefined names */
163 static const char *ut_resource_type_names
[] = {
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
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
196 if (name
[0] != '_') {
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_NAME(name
, this_name
->info
.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
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 ******************************************************************************/
231 acpi_ut_display_predefined_method(char *buffer
,
232 const union acpi_predefined_info
*this_name
,
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
);
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 */
256 printf(" (%s)", buffer
);
263 /* Get the return value type(s) allowed */
265 if (this_name
->info
.expected_btypes
) {
266 acpi_ut_get_expected_return_types(buffer
,
269 printf(" Return value types: %s\n", buffer
);
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
288 ******************************************************************************/
290 static u32
acpi_ut_get_argument_types(char *buffer
, u16 argument_types
)
292 u16 this_argument_type
;
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
);
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
315 || (this_argument_type
> METHOD_MAX_ARG_TYPE
)) {
316 printf("**** Invalid argument type (%u) "
317 "in predefined info structure\n",
323 ut_external_type_names
[this_argument_type
] + sub_index
);
330 /*******************************************************************************
332 * FUNCTION: acpi_ut_get_resource_bit_width
334 * PARAMETERS: buffer - Where the formatted string is returned
335 * types - Bitfield of expected data types
337 * RETURN: Count of return types. Formatted string in Buffer.
339 * DESCRIPTION: Format the resource bit widths into a printable string.
341 ******************************************************************************/
343 u32
acpi_ut_get_resource_bit_width(char *buffer
, u16 types
)
353 for (i
= 0; i
< NUM_RESOURCE_WIDTHS
; i
++) {
355 strcat(buffer
, &(ut_resource_type_names
[i
][sub_index
]));