1 /******************************************************************************
3 * Module Name: utpredef - support functions for predefined names
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 #define __UTPREDEF_C__
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utpredef")
56 * Names for the types that can be returned by the predefined objects.
57 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
59 static const char *UtRtypeNames
[] =
69 /*******************************************************************************
71 * FUNCTION: AcpiUtGetNextPredefinedMethod
73 * PARAMETERS: ThisName - Entry in the predefined method/name table
75 * RETURN: Pointer to next entry in predefined table.
77 * DESCRIPTION: Get the next entry in the predefine method table. Handles the
78 * cases where a package info entry follows a method name that
81 ******************************************************************************/
83 const ACPI_PREDEFINED_INFO
*
84 AcpiUtGetNextPredefinedMethod (
85 const ACPI_PREDEFINED_INFO
*ThisName
)
89 * Skip next entry in the table if this name returns a Package
90 * (next entry contains the package info)
92 if ((ThisName
->Info
.ExpectedBtypes
& ACPI_RTYPE_PACKAGE
) &&
93 (ThisName
->Info
.ExpectedBtypes
!= ACPI_RTYPE_ALL
))
103 /*******************************************************************************
105 * FUNCTION: AcpiUtMatchPredefinedMethod
107 * PARAMETERS: Name - Name to find
109 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
111 * DESCRIPTION: Check an object name against the predefined object list.
113 ******************************************************************************/
115 const ACPI_PREDEFINED_INFO
*
116 AcpiUtMatchPredefinedMethod (
119 const ACPI_PREDEFINED_INFO
*ThisName
;
122 /* Quick check for a predefined name, first character must be underscore */
129 /* Search info table for a predefined method/object name */
131 ThisName
= AcpiGbl_PredefinedMethods
;
132 while (ThisName
->Info
.Name
[0])
134 if (ACPI_COMPARE_NAME (Name
, ThisName
->Info
.Name
))
139 ThisName
= AcpiUtGetNextPredefinedMethod (ThisName
);
142 return (NULL
); /* Not found */
146 /*******************************************************************************
148 * FUNCTION: AcpiUtGetExpectedReturnTypes
150 * PARAMETERS: Buffer - Where the formatted string is returned
151 * ExpectedBTypes - Bitfield of expected data types
153 * RETURN: Formatted string in Buffer.
155 * DESCRIPTION: Format the expected object types into a printable string.
157 ******************************************************************************/
160 AcpiUtGetExpectedReturnTypes (
162 UINT32 ExpectedBtypes
)
171 ACPI_STRCPY (Buffer
, "NONE");
177 ThisRtype
= ACPI_RTYPE_INTEGER
;
179 for (i
= 0; i
< ACPI_NUM_RTYPES
; i
++)
181 /* If one of the expected types, concatenate the name of this type */
183 if (ExpectedBtypes
& ThisRtype
)
185 ACPI_STRCAT (Buffer
, &UtRtypeNames
[i
][j
]);
186 j
= 0; /* Use name separator from now on */
189 ThisRtype
<<= 1; /* Next Rtype */
194 /*******************************************************************************
196 * The remaining functions are used by iASL and AcpiHelp only
198 ******************************************************************************/
200 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
204 /* Local prototypes */
207 AcpiUtGetArgumentTypes (
209 UINT16 ArgumentTypes
);
212 /* Types that can be returned externally by a predefined name */
214 static const char *UtExternalTypeNames
[] = /* Indexed by ACPI_TYPE_* */
216 ", UNSUPPORTED-TYPE",
223 /* Bit widths for resource descriptor predefined names */
225 static const char *UtResourceTypeNames
[] =
238 /*******************************************************************************
240 * FUNCTION: AcpiUtMatchResourceName
242 * PARAMETERS: Name - Name to find
244 * RETURN: Pointer to entry in the resource table. NULL indicates not
247 * DESCRIPTION: Check an object name against the predefined resource
248 * descriptor object list.
250 ******************************************************************************/
252 const ACPI_PREDEFINED_INFO
*
253 AcpiUtMatchResourceName (
256 const ACPI_PREDEFINED_INFO
*ThisName
;
259 /* Quick check for a predefined name, first character must be underscore */
266 /* Search info table for a predefined method/object name */
268 ThisName
= AcpiGbl_ResourceNames
;
269 while (ThisName
->Info
.Name
[0])
271 if (ACPI_COMPARE_NAME (Name
, ThisName
->Info
.Name
))
279 return (NULL
); /* Not found */
283 /*******************************************************************************
285 * FUNCTION: AcpiUtDisplayPredefinedMethod
287 * PARAMETERS: Buffer - Scratch buffer for this function
288 * ThisName - Entry in the predefined method/name table
289 * MultiLine - TRUE if output should be on >1 line
293 * DESCRIPTION: Display information about a predefined method. Number and
294 * type of the input arguments, and expected type(s) for the
295 * return value, if any.
297 ******************************************************************************/
300 AcpiUtDisplayPredefinedMethod (
302 const ACPI_PREDEFINED_INFO
*ThisName
,
308 * Get the argument count and the string buffer
309 * containing all argument types
311 ArgCount
= AcpiUtGetArgumentTypes (Buffer
,
312 ThisName
->Info
.ArgumentList
);
319 printf ("%4.4s Requires %s%u argument%s",
321 (ThisName
->Info
.ArgumentList
& ARG_COUNT_IS_MINIMUM
) ?
323 ArgCount
, ArgCount
!= 1 ? "s" : "");
325 /* Display the types for any arguments */
329 printf (" (%s)", Buffer
);
337 /* Get the return value type(s) allowed */
339 if (ThisName
->Info
.ExpectedBtypes
)
341 AcpiUtGetExpectedReturnTypes (Buffer
, ThisName
->Info
.ExpectedBtypes
);
342 printf (" Return value types: %s\n", Buffer
);
346 printf (" No return value\n");
351 /*******************************************************************************
353 * FUNCTION: AcpiUtGetArgumentTypes
355 * PARAMETERS: Buffer - Where to return the formatted types
356 * ArgumentTypes - Types field for this method
358 * RETURN: Count - the number of arguments required for this method
360 * DESCRIPTION: Format the required data types for this method (Integer,
361 * String, Buffer, or Package) and return the required argument
364 ******************************************************************************/
367 AcpiUtGetArgumentTypes (
369 UINT16 ArgumentTypes
)
371 UINT16 ThisArgumentType
;
380 /* First field in the types list is the count of args to follow */
382 ArgCount
= METHOD_GET_ARG_COUNT (ArgumentTypes
);
383 if (ArgCount
> METHOD_PREDEF_ARGS_MAX
)
385 printf ("**** Invalid argument count (%u) "
386 "in predefined info structure\n", ArgCount
);
390 /* Get each argument from the list, convert to ascii, store to buffer */
392 for (i
= 0; i
< ArgCount
; i
++)
394 ThisArgumentType
= METHOD_GET_NEXT_TYPE (ArgumentTypes
);
396 if (!ThisArgumentType
|| (ThisArgumentType
> METHOD_MAX_ARG_TYPE
))
398 printf ("**** Invalid argument type (%u) "
399 "in predefined info structure\n", ThisArgumentType
);
403 strcat (Buffer
, UtExternalTypeNames
[ThisArgumentType
] + SubIndex
);
411 /*******************************************************************************
413 * FUNCTION: AcpiUtGetResourceBitWidth
415 * PARAMETERS: Buffer - Where the formatted string is returned
416 * Types - Bitfield of expected data types
418 * RETURN: Count of return types. Formatted string in Buffer.
420 * DESCRIPTION: Format the resource bit widths into a printable string.
422 ******************************************************************************/
425 AcpiUtGetResourceBitWidth (
438 for (i
= 0; i
< NUM_RESOURCE_WIDTHS
; i
++)
442 strcat (Buffer
, &(UtResourceTypeNames
[i
][SubIndex
]));