1 /******************************************************************************
3 * Module Name: utpredef - support functions for predefined names
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utpredef")
52 * Names for the types that can be returned by the predefined objects.
53 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
55 static const char *ut_rtype_names
[] = {
63 /*******************************************************************************
65 * FUNCTION: acpi_ut_get_next_predefined_method
67 * PARAMETERS: this_name - Entry in the predefined method/name table
69 * RETURN: Pointer to next entry in predefined table.
71 * DESCRIPTION: Get the next entry in the predefine method table. Handles the
72 * cases where a package info entry follows a method name that
75 ******************************************************************************/
77 const union acpi_predefined_info
*acpi_ut_get_next_predefined_method(const union
83 * Skip next entry in the table if this name returns a Package
84 * (next entry contains the package info)
86 if ((this_name
->info
.expected_btypes
& ACPI_RTYPE_PACKAGE
) &&
87 (this_name
->info
.expected_btypes
!= ACPI_RTYPE_ALL
)) {
95 /*******************************************************************************
97 * FUNCTION: acpi_ut_match_predefined_method
99 * PARAMETERS: name - Name to find
101 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
103 * DESCRIPTION: Check an object name against the predefined object list.
105 ******************************************************************************/
107 const union acpi_predefined_info
*acpi_ut_match_predefined_method(char *name
)
109 const union acpi_predefined_info
*this_name
;
111 /* Quick check for a predefined name, first character must be underscore */
113 if (name
[0] != '_') {
117 /* Search info table for a predefined method/object name */
119 this_name
= acpi_gbl_predefined_methods
;
120 while (this_name
->info
.name
[0]) {
121 if (ACPI_COMPARE_NAME(name
, this_name
->info
.name
)) {
125 this_name
= acpi_ut_get_next_predefined_method(this_name
);
128 return (NULL
); /* Not found */
131 /*******************************************************************************
133 * FUNCTION: acpi_ut_get_expected_return_types
135 * PARAMETERS: buffer - Where the formatted string is returned
136 * expected_Btypes - Bitfield of expected data types
138 * RETURN: Formatted string in Buffer.
140 * DESCRIPTION: Format the expected object types into a printable string.
142 ******************************************************************************/
144 void acpi_ut_get_expected_return_types(char *buffer
, u32 expected_btypes
)
150 if (!expected_btypes
) {
151 ACPI_STRCPY(buffer
, "NONE");
157 this_rtype
= ACPI_RTYPE_INTEGER
;
159 for (i
= 0; i
< ACPI_NUM_RTYPES
; i
++) {
161 /* If one of the expected types, concatenate the name of this type */
163 if (expected_btypes
& this_rtype
) {
164 ACPI_STRCAT(buffer
, &ut_rtype_names
[i
][j
]);
165 j
= 0; /* Use name separator from now on */
168 this_rtype
<<= 1; /* Next Rtype */
172 /*******************************************************************************
174 * The remaining functions are used by iASL and acpi_help only
176 ******************************************************************************/
178 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
182 /* Local prototypes */
184 static u32
acpi_ut_get_argument_types(char *buffer
, u16 argument_types
);
186 /* Types that can be returned externally by a predefined name */
188 static const char *ut_external_type_names
[] = /* Indexed by ACPI_TYPE_* */
190 ", UNSUPPORTED-TYPE",
197 /* Bit widths for resource descriptor predefined names */
199 static const char *ut_resource_type_names
[] = {
210 /*******************************************************************************
212 * FUNCTION: acpi_ut_match_resource_name
214 * PARAMETERS: name - Name to find
216 * RETURN: Pointer to entry in the resource table. NULL indicates not
219 * DESCRIPTION: Check an object name against the predefined resource
220 * descriptor object list.
222 ******************************************************************************/
224 const union acpi_predefined_info
*acpi_ut_match_resource_name(char *name
)
226 const union acpi_predefined_info
*this_name
;
228 /* Quick check for a predefined name, first character must be underscore */
230 if (name
[0] != '_') {
234 /* Search info table for a predefined method/object name */
236 this_name
= acpi_gbl_resource_names
;
237 while (this_name
->info
.name
[0]) {
238 if (ACPI_COMPARE_NAME(name
, this_name
->info
.name
)) {
245 return (NULL
); /* Not found */
248 /*******************************************************************************
250 * FUNCTION: acpi_ut_display_predefined_method
252 * PARAMETERS: buffer - Scratch buffer for this function
253 * this_name - Entry in the predefined method/name table
254 * multi_line - TRUE if output should be on >1 line
258 * DESCRIPTION: Display information about a predefined method. Number and
259 * type of the input arguments, and expected type(s) for the
260 * return value, if any.
262 ******************************************************************************/
265 acpi_ut_display_predefined_method(char *buffer
,
266 const union acpi_predefined_info
*this_name
,
272 * Get the argument count and the string buffer
273 * containing all argument types
275 arg_count
= acpi_ut_get_argument_types(buffer
,
276 this_name
->info
.argument_list
);
282 printf("%4.4s Requires %s%u argument%s",
283 this_name
->info
.name
,
284 (this_name
->info
.argument_list
& ARG_COUNT_IS_MINIMUM
) ?
285 "(at least) " : "", arg_count
, arg_count
!= 1 ? "s" : "");
287 /* Display the types for any arguments */
290 printf(" (%s)", buffer
);
297 /* Get the return value type(s) allowed */
299 if (this_name
->info
.expected_btypes
) {
300 acpi_ut_get_expected_return_types(buffer
,
303 printf(" Return value types: %s\n", buffer
);
305 printf(" No return value\n");
309 /*******************************************************************************
311 * FUNCTION: acpi_ut_get_argument_types
313 * PARAMETERS: buffer - Where to return the formatted types
314 * argument_types - Types field for this method
316 * RETURN: count - the number of arguments required for this method
318 * DESCRIPTION: Format the required data types for this method (Integer,
319 * String, Buffer, or Package) and return the required argument
322 ******************************************************************************/
324 static u32
acpi_ut_get_argument_types(char *buffer
, u16 argument_types
)
326 u16 this_argument_type
;
334 /* First field in the types list is the count of args to follow */
336 arg_count
= METHOD_GET_ARG_COUNT(argument_types
);
337 if (arg_count
> METHOD_PREDEF_ARGS_MAX
) {
338 printf("**** Invalid argument count (%u) "
339 "in predefined info structure\n", arg_count
);
343 /* Get each argument from the list, convert to ascii, store to buffer */
345 for (i
= 0; i
< arg_count
; i
++) {
346 this_argument_type
= METHOD_GET_NEXT_TYPE(argument_types
);
348 if (!this_argument_type
349 || (this_argument_type
> METHOD_MAX_ARG_TYPE
)) {
350 printf("**** Invalid argument type (%u) "
351 "in predefined info structure\n",
357 ut_external_type_names
[this_argument_type
] + sub_index
);
364 /*******************************************************************************
366 * FUNCTION: acpi_ut_get_resource_bit_width
368 * PARAMETERS: buffer - Where the formatted string is returned
369 * types - Bitfield of expected data types
371 * RETURN: Count of return types. Formatted string in Buffer.
373 * DESCRIPTION: Format the resource bit widths into a printable string.
375 ******************************************************************************/
377 u32
acpi_ut_get_resource_bit_width(char *buffer
, u16 types
)
387 for (i
= 0; i
< NUM_RESOURCE_WIDTHS
; i
++) {
389 strcat(buffer
, &(ut_resource_type_names
[i
][sub_index
]));