utpredef.c revision 1.1 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: utpredef - support functions for predefined names
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #define __UTPREDEF_C__
45 1.1 christos
46 1.1 christos #include "acpi.h"
47 1.1 christos #include "accommon.h"
48 1.1 christos #include "acpredef.h"
49 1.1 christos
50 1.1 christos
51 1.1 christos #define _COMPONENT ACPI_UTILITIES
52 1.1 christos ACPI_MODULE_NAME ("utpredef")
53 1.1 christos
54 1.1 christos
55 1.1 christos /*
56 1.1 christos * Names for the types that can be returned by the predefined objects.
57 1.1 christos * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
58 1.1 christos */
59 1.1 christos static const char *UtRtypeNames[] =
60 1.1 christos {
61 1.1 christos "/Integer",
62 1.1 christos "/String",
63 1.1 christos "/Buffer",
64 1.1 christos "/Package",
65 1.1 christos "/Reference",
66 1.1 christos };
67 1.1 christos
68 1.1 christos
69 1.1 christos /*******************************************************************************
70 1.1 christos *
71 1.1 christos * FUNCTION: AcpiUtGetNextPredefinedMethod
72 1.1 christos *
73 1.1 christos * PARAMETERS: ThisName - Entry in the predefined method/name table
74 1.1 christos *
75 1.1 christos * RETURN: Pointer to next entry in predefined table.
76 1.1 christos *
77 1.1 christos * DESCRIPTION: Get the next entry in the predefine method table. Handles the
78 1.1 christos * cases where a package info entry follows a method name that
79 1.1 christos * returns a package.
80 1.1 christos *
81 1.1 christos ******************************************************************************/
82 1.1 christos
83 1.1 christos const ACPI_PREDEFINED_INFO *
84 1.1 christos AcpiUtGetNextPredefinedMethod (
85 1.1 christos const ACPI_PREDEFINED_INFO *ThisName)
86 1.1 christos {
87 1.1 christos
88 1.1 christos /*
89 1.1 christos * Skip next entry in the table if this name returns a Package
90 1.1 christos * (next entry contains the package info)
91 1.1 christos */
92 1.1 christos if ((ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE) &&
93 1.1 christos (ThisName->Info.ExpectedBtypes != ACPI_RTYPE_ALL))
94 1.1 christos {
95 1.1 christos ThisName++;
96 1.1 christos }
97 1.1 christos
98 1.1 christos ThisName++;
99 1.1 christos return (ThisName);
100 1.1 christos }
101 1.1 christos
102 1.1 christos
103 1.1 christos /*******************************************************************************
104 1.1 christos *
105 1.1 christos * FUNCTION: AcpiUtMatchPredefinedMethod
106 1.1 christos *
107 1.1 christos * PARAMETERS: Name - Name to find
108 1.1 christos *
109 1.1 christos * RETURN: Pointer to entry in predefined table. NULL indicates not found.
110 1.1 christos *
111 1.1 christos * DESCRIPTION: Check an object name against the predefined object list.
112 1.1 christos *
113 1.1 christos ******************************************************************************/
114 1.1 christos
115 1.1 christos const ACPI_PREDEFINED_INFO *
116 1.1 christos AcpiUtMatchPredefinedMethod (
117 1.1 christos char *Name)
118 1.1 christos {
119 1.1 christos const ACPI_PREDEFINED_INFO *ThisName;
120 1.1 christos
121 1.1 christos
122 1.1 christos /* Quick check for a predefined name, first character must be underscore */
123 1.1 christos
124 1.1 christos if (Name[0] != '_')
125 1.1 christos {
126 1.1 christos return (NULL);
127 1.1 christos }
128 1.1 christos
129 1.1 christos /* Search info table for a predefined method/object name */
130 1.1 christos
131 1.1 christos ThisName = AcpiGbl_PredefinedMethods;
132 1.1 christos while (ThisName->Info.Name[0])
133 1.1 christos {
134 1.1 christos if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
135 1.1 christos {
136 1.1 christos return (ThisName);
137 1.1 christos }
138 1.1 christos
139 1.1 christos ThisName = AcpiUtGetNextPredefinedMethod (ThisName);
140 1.1 christos }
141 1.1 christos
142 1.1 christos return (NULL); /* Not found */
143 1.1 christos }
144 1.1 christos
145 1.1 christos
146 1.1 christos /*******************************************************************************
147 1.1 christos *
148 1.1 christos * FUNCTION: AcpiUtGetExpectedReturnTypes
149 1.1 christos *
150 1.1 christos * PARAMETERS: Buffer - Where the formatted string is returned
151 1.1 christos * ExpectedBTypes - Bitfield of expected data types
152 1.1 christos *
153 1.1 christos * RETURN: Formatted string in Buffer.
154 1.1 christos *
155 1.1 christos * DESCRIPTION: Format the expected object types into a printable string.
156 1.1 christos *
157 1.1 christos ******************************************************************************/
158 1.1 christos
159 1.1 christos void
160 1.1 christos AcpiUtGetExpectedReturnTypes (
161 1.1 christos char *Buffer,
162 1.1 christos UINT32 ExpectedBtypes)
163 1.1 christos {
164 1.1 christos UINT32 ThisRtype;
165 1.1 christos UINT32 i;
166 1.1 christos UINT32 j;
167 1.1 christos
168 1.1 christos
169 1.1 christos if (!ExpectedBtypes)
170 1.1 christos {
171 1.1 christos ACPI_STRCPY (Buffer, "NONE");
172 1.1 christos return;
173 1.1 christos }
174 1.1 christos
175 1.1 christos j = 1;
176 1.1 christos Buffer[0] = 0;
177 1.1 christos ThisRtype = ACPI_RTYPE_INTEGER;
178 1.1 christos
179 1.1 christos for (i = 0; i < ACPI_NUM_RTYPES; i++)
180 1.1 christos {
181 1.1 christos /* If one of the expected types, concatenate the name of this type */
182 1.1 christos
183 1.1 christos if (ExpectedBtypes & ThisRtype)
184 1.1 christos {
185 1.1 christos ACPI_STRCAT (Buffer, &UtRtypeNames[i][j]);
186 1.1 christos j = 0; /* Use name separator from now on */
187 1.1 christos }
188 1.1 christos
189 1.1 christos ThisRtype <<= 1; /* Next Rtype */
190 1.1 christos }
191 1.1 christos }
192 1.1 christos
193 1.1 christos
194 1.1 christos /*******************************************************************************
195 1.1 christos *
196 1.1 christos * The remaining functions are used by iASL and AcpiHelp only
197 1.1 christos *
198 1.1 christos ******************************************************************************/
199 1.1 christos
200 1.1 christos #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
201 1.1 christos #include <stdio.h>
202 1.1 christos #include <string.h>
203 1.1 christos
204 1.1 christos /* Local prototypes */
205 1.1 christos
206 1.1 christos static UINT32
207 1.1 christos AcpiUtGetArgumentTypes (
208 1.1 christos char *Buffer,
209 1.1 christos UINT16 ArgumentTypes);
210 1.1 christos
211 1.1 christos
212 1.1 christos /* Types that can be returned externally by a predefined name */
213 1.1 christos
214 1.1 christos static const char *UtExternalTypeNames[] = /* Indexed by ACPI_TYPE_* */
215 1.1 christos {
216 1.1 christos ", UNSUPPORTED-TYPE",
217 1.1 christos ", Integer",
218 1.1 christos ", String",
219 1.1 christos ", Buffer",
220 1.1 christos ", Package"
221 1.1 christos };
222 1.1 christos
223 1.1 christos /* Bit widths for resource descriptor predefined names */
224 1.1 christos
225 1.1 christos static const char *UtResourceTypeNames[] =
226 1.1 christos {
227 1.1 christos "/1",
228 1.1 christos "/2",
229 1.1 christos "/3",
230 1.1 christos "/8",
231 1.1 christos "/16",
232 1.1 christos "/32",
233 1.1 christos "/64",
234 1.1 christos "/variable",
235 1.1 christos };
236 1.1 christos
237 1.1 christos
238 1.1 christos /*******************************************************************************
239 1.1 christos *
240 1.1 christos * FUNCTION: AcpiUtMatchResourceName
241 1.1 christos *
242 1.1 christos * PARAMETERS: Name - Name to find
243 1.1 christos *
244 1.1 christos * RETURN: Pointer to entry in the resource table. NULL indicates not
245 1.1 christos * found.
246 1.1 christos *
247 1.1 christos * DESCRIPTION: Check an object name against the predefined resource
248 1.1 christos * descriptor object list.
249 1.1 christos *
250 1.1 christos ******************************************************************************/
251 1.1 christos
252 1.1 christos const ACPI_PREDEFINED_INFO *
253 1.1 christos AcpiUtMatchResourceName (
254 1.1 christos char *Name)
255 1.1 christos {
256 1.1 christos const ACPI_PREDEFINED_INFO *ThisName;
257 1.1 christos
258 1.1 christos
259 1.1 christos /* Quick check for a predefined name, first character must be underscore */
260 1.1 christos
261 1.1 christos if (Name[0] != '_')
262 1.1 christos {
263 1.1 christos return (NULL);
264 1.1 christos }
265 1.1 christos
266 1.1 christos /* Search info table for a predefined method/object name */
267 1.1 christos
268 1.1 christos ThisName = AcpiGbl_ResourceNames;
269 1.1 christos while (ThisName->Info.Name[0])
270 1.1 christos {
271 1.1 christos if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
272 1.1 christos {
273 1.1 christos return (ThisName);
274 1.1 christos }
275 1.1 christos
276 1.1 christos ThisName++;
277 1.1 christos }
278 1.1 christos
279 1.1 christos return (NULL); /* Not found */
280 1.1 christos }
281 1.1 christos
282 1.1 christos
283 1.1 christos /*******************************************************************************
284 1.1 christos *
285 1.1 christos * FUNCTION: AcpiUtDisplayPredefinedMethod
286 1.1 christos *
287 1.1 christos * PARAMETERS: Buffer - Scratch buffer for this function
288 1.1 christos * ThisName - Entry in the predefined method/name table
289 1.1 christos * MultiLine - TRUE if output should be on >1 line
290 1.1 christos *
291 1.1 christos * RETURN: None
292 1.1 christos *
293 1.1 christos * DESCRIPTION: Display information about a predefined method. Number and
294 1.1 christos * type of the input arguments, and expected type(s) for the
295 1.1 christos * return value, if any.
296 1.1 christos *
297 1.1 christos ******************************************************************************/
298 1.1 christos
299 1.1 christos void
300 1.1 christos AcpiUtDisplayPredefinedMethod (
301 1.1 christos char *Buffer,
302 1.1 christos const ACPI_PREDEFINED_INFO *ThisName,
303 1.1 christos BOOLEAN MultiLine)
304 1.1 christos {
305 1.1 christos UINT32 ArgCount;
306 1.1 christos
307 1.1 christos /*
308 1.1 christos * Get the argument count and the string buffer
309 1.1 christos * containing all argument types
310 1.1 christos */
311 1.1 christos ArgCount = AcpiUtGetArgumentTypes (Buffer,
312 1.1 christos ThisName->Info.ArgumentList);
313 1.1 christos
314 1.1 christos if (MultiLine)
315 1.1 christos {
316 1.1 christos printf (" ");
317 1.1 christos }
318 1.1 christos
319 1.1 christos printf ("%4.4s Requires %s%u argument%s",
320 1.1 christos ThisName->Info.Name,
321 1.1 christos (ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM) ?
322 1.1 christos "(at least) " : "",
323 1.1 christos ArgCount, ArgCount != 1 ? "s" : "");
324 1.1 christos
325 1.1 christos /* Display the types for any arguments */
326 1.1 christos
327 1.1 christos if (ArgCount > 0)
328 1.1 christos {
329 1.1 christos printf (" (%s)", Buffer);
330 1.1 christos }
331 1.1 christos
332 1.1 christos if (MultiLine)
333 1.1 christos {
334 1.1 christos printf ("\n ");
335 1.1 christos }
336 1.1 christos
337 1.1 christos /* Get the return value type(s) allowed */
338 1.1 christos
339 1.1 christos if (ThisName->Info.ExpectedBtypes)
340 1.1 christos {
341 1.1 christos AcpiUtGetExpectedReturnTypes (Buffer, ThisName->Info.ExpectedBtypes);
342 1.1 christos printf (" Return value types: %s\n", Buffer);
343 1.1 christos }
344 1.1 christos else
345 1.1 christos {
346 1.1 christos printf (" No return value\n");
347 1.1 christos }
348 1.1 christos }
349 1.1 christos
350 1.1 christos
351 1.1 christos /*******************************************************************************
352 1.1 christos *
353 1.1 christos * FUNCTION: AcpiUtGetArgumentTypes
354 1.1 christos *
355 1.1 christos * PARAMETERS: Buffer - Where to return the formatted types
356 1.1 christos * ArgumentTypes - Types field for this method
357 1.1 christos *
358 1.1 christos * RETURN: Count - the number of arguments required for this method
359 1.1 christos *
360 1.1 christos * DESCRIPTION: Format the required data types for this method (Integer,
361 1.1 christos * String, Buffer, or Package) and return the required argument
362 1.1 christos * count.
363 1.1 christos *
364 1.1 christos ******************************************************************************/
365 1.1 christos
366 1.1 christos static UINT32
367 1.1 christos AcpiUtGetArgumentTypes (
368 1.1 christos char *Buffer,
369 1.1 christos UINT16 ArgumentTypes)
370 1.1 christos {
371 1.1 christos UINT16 ThisArgumentType;
372 1.1 christos UINT16 SubIndex;
373 1.1 christos UINT16 ArgCount;
374 1.1 christos UINT32 i;
375 1.1 christos
376 1.1 christos
377 1.1 christos *Buffer = 0;
378 1.1 christos SubIndex = 2;
379 1.1 christos
380 1.1 christos /* First field in the types list is the count of args to follow */
381 1.1 christos
382 1.1 christos ArgCount = METHOD_GET_ARG_COUNT (ArgumentTypes);
383 1.1 christos if (ArgCount > METHOD_PREDEF_ARGS_MAX)
384 1.1 christos {
385 1.1 christos printf ("**** Invalid argument count (%u) "
386 1.1 christos "in predefined info structure\n", ArgCount);
387 1.1 christos return (ArgCount);
388 1.1 christos }
389 1.1 christos
390 1.1 christos /* Get each argument from the list, convert to ascii, store to buffer */
391 1.1 christos
392 1.1 christos for (i = 0; i < ArgCount; i++)
393 1.1 christos {
394 1.1 christos ThisArgumentType = METHOD_GET_NEXT_TYPE (ArgumentTypes);
395 1.1 christos
396 1.1 christos if (!ThisArgumentType || (ThisArgumentType > METHOD_MAX_ARG_TYPE))
397 1.1 christos {
398 1.1 christos printf ("**** Invalid argument type (%u) "
399 1.1 christos "in predefined info structure\n", ThisArgumentType);
400 1.1 christos return (ArgCount);
401 1.1 christos }
402 1.1 christos
403 1.1 christos strcat (Buffer, UtExternalTypeNames[ThisArgumentType] + SubIndex);
404 1.1 christos SubIndex = 0;
405 1.1 christos }
406 1.1 christos
407 1.1 christos return (ArgCount);
408 1.1 christos }
409 1.1 christos
410 1.1 christos
411 1.1 christos /*******************************************************************************
412 1.1 christos *
413 1.1 christos * FUNCTION: AcpiUtGetResourceBitWidth
414 1.1 christos *
415 1.1 christos * PARAMETERS: Buffer - Where the formatted string is returned
416 1.1 christos * Types - Bitfield of expected data types
417 1.1 christos *
418 1.1 christos * RETURN: Count of return types. Formatted string in Buffer.
419 1.1 christos *
420 1.1 christos * DESCRIPTION: Format the resource bit widths into a printable string.
421 1.1 christos *
422 1.1 christos ******************************************************************************/
423 1.1 christos
424 1.1 christos UINT32
425 1.1 christos AcpiUtGetResourceBitWidth (
426 1.1 christos char *Buffer,
427 1.1 christos UINT16 Types)
428 1.1 christos {
429 1.1 christos UINT32 i;
430 1.1 christos UINT16 SubIndex;
431 1.1 christos UINT32 Found;
432 1.1 christos
433 1.1 christos
434 1.1 christos *Buffer = 0;
435 1.1 christos SubIndex = 1;
436 1.1 christos Found = 0;
437 1.1 christos
438 1.1 christos for (i = 0; i < NUM_RESOURCE_WIDTHS; i++)
439 1.1 christos {
440 1.1 christos if (Types & 1)
441 1.1 christos {
442 1.1 christos strcat (Buffer, &(UtResourceTypeNames[i][SubIndex]));
443 1.1 christos SubIndex = 0;
444 1.1 christos Found++;
445 1.1 christos }
446 1.1 christos
447 1.1 christos Types >>= 1;
448 1.1 christos }
449 1.1 christos
450 1.1 christos return (Found);
451 1.1 christos }
452 1.1 christos #endif
453