disable some mediatekl custom warnings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / acpica / utpredef.c
CommitLineData
c34c82bc
BM
1/******************************************************************************
2 *
3 * Module Name: utpredef - support functions for predefined names
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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
49ACPI_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 */
55static 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
77const 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
107const 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
144void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
145{
146 u32 this_rtype;
147 u32 i;
148 u32 j;
149
150 j = 1;
151 buffer[0] = 0;
152 this_rtype = ACPI_RTYPE_INTEGER;
153
154 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
155
156 /* If one of the expected types, concatenate the name of this type */
157
158 if (expected_btypes & this_rtype) {
159 ACPI_STRCAT(buffer, &ut_rtype_names[i][j]);
160 j = 0; /* Use name separator from now on */
161 }
162
163 this_rtype <<= 1; /* Next Rtype */
164 }
165}
166
167/*******************************************************************************
168 *
169 * The remaining functions are used by iASL and acpi_help only
170 *
171 ******************************************************************************/
172
173#if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
174#include <stdio.h>
175#include <string.h>
176
177/* Local prototypes */
178
179static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
180
181/* Types that can be returned externally by a predefined name */
182
183static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
184{
185 ", UNSUPPORTED-TYPE",
186 ", Integer",
187 ", String",
188 ", Buffer",
189 ", Package"
190};
191
192/* Bit widths for resource descriptor predefined names */
193
194static const char *ut_resource_type_names[] = {
195 "/1",
196 "/2",
197 "/3",
198 "/8",
199 "/16",
200 "/32",
201 "/64",
202 "/variable",
203};
204
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ut_match_resource_name
208 *
209 * PARAMETERS: name - Name to find
210 *
211 * RETURN: Pointer to entry in the resource table. NULL indicates not
212 * found.
213 *
214 * DESCRIPTION: Check an object name against the predefined resource
215 * descriptor object list.
216 *
217 ******************************************************************************/
218
219const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
220{
221 const union acpi_predefined_info *this_name;
222
223 /* Quick check for a predefined name, first character must be underscore */
224
225 if (name[0] != '_') {
226 return (NULL);
227 }
228
229 /* Search info table for a predefined method/object name */
230
231 this_name = acpi_gbl_resource_names;
232 while (this_name->info.name[0]) {
233 if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
234 return (this_name);
235 }
236
237 this_name++;
238 }
239
240 return (NULL); /* Not found */
241}
242
243/*******************************************************************************
244 *
245 * FUNCTION: acpi_ut_display_predefined_method
246 *
247 * PARAMETERS: buffer - Scratch buffer for this function
248 * this_name - Entry in the predefined method/name table
249 * multi_line - TRUE if output should be on >1 line
250 *
251 * RETURN: None
252 *
253 * DESCRIPTION: Display information about a predefined method. Number and
254 * type of the input arguments, and expected type(s) for the
255 * return value, if any.
256 *
257 ******************************************************************************/
258
259void
260acpi_ut_display_predefined_method(char *buffer,
261 const union acpi_predefined_info *this_name,
262 u8 multi_line)
263{
264 u32 arg_count;
265
266 /*
267 * Get the argument count and the string buffer
268 * containing all argument types
269 */
270 arg_count = acpi_ut_get_argument_types(buffer,
271 this_name->info.argument_list);
272
273 if (multi_line) {
274 printf(" ");
275 }
276
277 printf("%4.4s Requires %s%u argument%s",
278 this_name->info.name,
279 (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
280 "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
281
282 /* Display the types for any arguments */
283
284 if (arg_count > 0) {
285 printf(" (%s)", buffer);
286 }
287
288 if (multi_line) {
289 printf("\n ");
290 }
291
292 /* Get the return value type(s) allowed */
293
294 if (this_name->info.expected_btypes) {
295 acpi_ut_get_expected_return_types(buffer,
296 this_name->info.
297 expected_btypes);
298 printf(" Return value types: %s\n", buffer);
299 } else {
300 printf(" No return value\n");
301 }
302}
303
304/*******************************************************************************
305 *
306 * FUNCTION: acpi_ut_get_argument_types
307 *
308 * PARAMETERS: buffer - Where to return the formatted types
309 * argument_types - Types field for this method
310 *
311 * RETURN: count - the number of arguments required for this method
312 *
313 * DESCRIPTION: Format the required data types for this method (Integer,
314 * String, Buffer, or Package) and return the required argument
315 * count.
316 *
317 ******************************************************************************/
318
319static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
320{
321 u16 this_argument_type;
322 u16 sub_index;
323 u16 arg_count;
324 u32 i;
325
326 *buffer = 0;
327 sub_index = 2;
328
329 /* First field in the types list is the count of args to follow */
330
331 arg_count = (argument_types & METHOD_ARG_MASK);
332 argument_types >>= METHOD_ARG_BIT_WIDTH;
333
334 if (arg_count > METHOD_PREDEF_ARGS_MAX) {
335 printf("**** Invalid argument count (%u) "
336 "in predefined info structure\n", arg_count);
337 return (arg_count);
338 }
339
340 /* Get each argument from the list, convert to ascii, store to buffer */
341
342 for (i = 0; i < arg_count; i++) {
343 this_argument_type = (argument_types & METHOD_ARG_MASK);
344 if (!this_argument_type
345 || (this_argument_type > METHOD_MAX_ARG_TYPE)) {
346 printf("**** Invalid argument type (%u) "
347 "in predefined info structure\n",
348 this_argument_type);
349 return (arg_count);
350 }
351
352 strcat(buffer,
353 ut_external_type_names[this_argument_type] + sub_index);
354
355 /* Shift to next argument type field */
356
357 argument_types >>= METHOD_ARG_BIT_WIDTH;
358 sub_index = 0;
359 }
360
361 return (arg_count);
362}
363
364/*******************************************************************************
365 *
366 * FUNCTION: acpi_ut_get_resource_bit_width
367 *
368 * PARAMETERS: buffer - Where the formatted string is returned
369 * types - Bitfield of expected data types
370 *
371 * RETURN: Count of return types. Formatted string in Buffer.
372 *
373 * DESCRIPTION: Format the resource bit widths into a printable string.
374 *
375 ******************************************************************************/
376
377u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
378{
379 u32 i;
380 u16 sub_index;
381 u32 found;
382
383 *buffer = 0;
384 sub_index = 1;
385 found = 0;
386
387 for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
388 if (types & 1) {
389 strcat(buffer, &(ut_resource_type_names[i][sub_index]));
390 sub_index = 0;
391 found++;
392 }
393
394 types >>= 1;
395 }
396
397 return (found);
398}
399#endif