Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
[deliverable/linux.git] / drivers / acpi / acpica / utpredef.c
1 /******************************************************************************
2 *
3 * Module Name: utpredef - support functions for predefined names
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acpredef.h"
47
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utpredef")
50
51 /*
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
54 */
55 static const char *ut_rtype_names[] = {
56 "/Integer",
57 "/String",
58 "/Buffer",
59 "/Package",
60 "/Reference",
61 };
62
63 /*******************************************************************************
64 *
65 * FUNCTION: acpi_ut_get_next_predefined_method
66 *
67 * PARAMETERS: this_name - Entry in the predefined method/name table
68 *
69 * RETURN: Pointer to next entry in predefined table.
70 *
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
73 * returns a package.
74 *
75 ******************************************************************************/
76
77 const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
78 acpi_predefined_info
79 *this_name)
80 {
81
82 /*
83 * Skip next entry in the table if this name returns a Package
84 * (next entry contains the package info)
85 */
86 if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) &&
87 (this_name->info.expected_btypes != ACPI_RTYPE_ALL)) {
88 this_name++;
89 }
90
91 this_name++;
92 return (this_name);
93 }
94
95 /*******************************************************************************
96 *
97 * FUNCTION: acpi_ut_match_predefined_method
98 *
99 * PARAMETERS: name - Name to find
100 *
101 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
102 *
103 * DESCRIPTION: Check an object name against the predefined object list.
104 *
105 ******************************************************************************/
106
107 const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name)
108 {
109 const union acpi_predefined_info *this_name;
110
111 /* Quick check for a predefined name, first character must be underscore */
112
113 if (name[0] != '_') {
114 return (NULL);
115 }
116
117 /* Search info table for a predefined method/object name */
118
119 this_name = acpi_gbl_predefined_methods;
120 while (this_name->info.name[0]) {
121 if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
122 return (this_name);
123 }
124
125 this_name = acpi_ut_get_next_predefined_method(this_name);
126 }
127
128 return (NULL); /* Not found */
129 }
130
131 /*******************************************************************************
132 *
133 * FUNCTION: acpi_ut_get_expected_return_types
134 *
135 * PARAMETERS: buffer - Where the formatted string is returned
136 * expected_Btypes - Bitfield of expected data types
137 *
138 * RETURN: Formatted string in Buffer.
139 *
140 * DESCRIPTION: Format the expected object types into a printable string.
141 *
142 ******************************************************************************/
143
144 void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
145 {
146 u32 this_rtype;
147 u32 i;
148 u32 j;
149
150 if (!expected_btypes) {
151 strcpy(buffer, "NONE");
152 return;
153 }
154
155 j = 1;
156 buffer[0] = 0;
157 this_rtype = ACPI_RTYPE_INTEGER;
158
159 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
160
161 /* If one of the expected types, concatenate the name of this type */
162
163 if (expected_btypes & this_rtype) {
164 strcat(buffer, &ut_rtype_names[i][j]);
165 j = 0; /* Use name separator from now on */
166 }
167
168 this_rtype <<= 1; /* Next Rtype */
169 }
170 }
171
172 /*******************************************************************************
173 *
174 * The remaining functions are used by iASL and acpi_help only
175 *
176 ******************************************************************************/
177
178 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
179 #include <stdio.h>
180 #include <string.h>
181
182 /* Local prototypes */
183
184 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
185
186 /* Types that can be returned externally by a predefined name */
187
188 static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
189 {
190 ", UNSUPPORTED-TYPE",
191 ", Integer",
192 ", String",
193 ", Buffer",
194 ", Package"
195 };
196
197 /* Bit widths for resource descriptor predefined names */
198
199 static const char *ut_resource_type_names[] = {
200 "/1",
201 "/2",
202 "/3",
203 "/8",
204 "/16",
205 "/32",
206 "/64",
207 "/variable",
208 };
209
210 /*******************************************************************************
211 *
212 * FUNCTION: acpi_ut_match_resource_name
213 *
214 * PARAMETERS: name - Name to find
215 *
216 * RETURN: Pointer to entry in the resource table. NULL indicates not
217 * found.
218 *
219 * DESCRIPTION: Check an object name against the predefined resource
220 * descriptor object list.
221 *
222 ******************************************************************************/
223
224 const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
225 {
226 const union acpi_predefined_info *this_name;
227
228 /*
229 * Quick check for a predefined name, first character must
230 * be underscore
231 */
232 if (name[0] != '_') {
233 return (NULL);
234 }
235
236 /* Search info table for a predefined method/object name */
237
238 this_name = acpi_gbl_resource_names;
239 while (this_name->info.name[0]) {
240 if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
241 return (this_name);
242 }
243
244 this_name++;
245 }
246
247 return (NULL); /* Not found */
248 }
249
250 /*******************************************************************************
251 *
252 * FUNCTION: acpi_ut_display_predefined_method
253 *
254 * PARAMETERS: buffer - Scratch buffer for this function
255 * this_name - Entry in the predefined method/name table
256 * multi_line - TRUE if output should be on >1 line
257 *
258 * RETURN: None
259 *
260 * DESCRIPTION: Display information about a predefined method. Number and
261 * type of the input arguments, and expected type(s) for the
262 * return value, if any.
263 *
264 ******************************************************************************/
265
266 void
267 acpi_ut_display_predefined_method(char *buffer,
268 const union acpi_predefined_info *this_name,
269 u8 multi_line)
270 {
271 u32 arg_count;
272
273 /*
274 * Get the argument count and the string buffer
275 * containing all argument types
276 */
277 arg_count = acpi_ut_get_argument_types(buffer,
278 this_name->info.argument_list);
279
280 if (multi_line) {
281 printf(" ");
282 }
283
284 printf("%4.4s Requires %s%u argument%s",
285 this_name->info.name,
286 (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
287 "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
288
289 /* Display the types for any arguments */
290
291 if (arg_count > 0) {
292 printf(" (%s)", buffer);
293 }
294
295 if (multi_line) {
296 printf("\n ");
297 }
298
299 /* Get the return value type(s) allowed */
300
301 if (this_name->info.expected_btypes) {
302 acpi_ut_get_expected_return_types(buffer,
303 this_name->info.
304 expected_btypes);
305 printf(" Return value types: %s\n", buffer);
306 } else {
307 printf(" No return value\n");
308 }
309 }
310
311 /*******************************************************************************
312 *
313 * FUNCTION: acpi_ut_get_argument_types
314 *
315 * PARAMETERS: buffer - Where to return the formatted types
316 * argument_types - Types field for this method
317 *
318 * RETURN: count - the number of arguments required for this method
319 *
320 * DESCRIPTION: Format the required data types for this method (Integer,
321 * String, Buffer, or Package) and return the required argument
322 * count.
323 *
324 ******************************************************************************/
325
326 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
327 {
328 u16 this_argument_type;
329 u16 sub_index;
330 u16 arg_count;
331 u32 i;
332
333 *buffer = 0;
334 sub_index = 2;
335
336 /* First field in the types list is the count of args to follow */
337
338 arg_count = METHOD_GET_ARG_COUNT(argument_types);
339 if (arg_count > METHOD_PREDEF_ARGS_MAX) {
340 printf("**** Invalid argument count (%u) "
341 "in predefined info structure\n", arg_count);
342 return (arg_count);
343 }
344
345 /* Get each argument from the list, convert to ascii, store to buffer */
346
347 for (i = 0; i < arg_count; i++) {
348 this_argument_type = METHOD_GET_NEXT_TYPE(argument_types);
349
350 if (!this_argument_type
351 || (this_argument_type > METHOD_MAX_ARG_TYPE)) {
352 printf("**** Invalid argument type (%u) "
353 "in predefined info structure\n",
354 this_argument_type);
355 return (arg_count);
356 }
357
358 strcat(buffer,
359 ut_external_type_names[this_argument_type] + sub_index);
360 sub_index = 0;
361 }
362
363 return (arg_count);
364 }
365
366 /*******************************************************************************
367 *
368 * FUNCTION: acpi_ut_get_resource_bit_width
369 *
370 * PARAMETERS: buffer - Where the formatted string is returned
371 * types - Bitfield of expected data types
372 *
373 * RETURN: Count of return types. Formatted string in Buffer.
374 *
375 * DESCRIPTION: Format the resource bit widths into a printable string.
376 *
377 ******************************************************************************/
378
379 u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
380 {
381 u32 i;
382 u16 sub_index;
383 u32 found;
384
385 *buffer = 0;
386 sub_index = 1;
387 found = 0;
388
389 for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
390 if (types & 1) {
391 strcat(buffer, &(ut_resource_type_names[i][sub_index]));
392 sub_index = 0;
393 found++;
394 }
395
396 types >>= 1;
397 }
398
399 return (found);
400 }
401 #endif
This page took 0.040096 seconds and 6 git commands to generate.