ACPICA: Split large utglobal into utdecode.c.
[firefly-linux-kernel-4.4.55.git] / drivers / acpi / acpica / utdecode.c
1 /******************************************************************************
2  *
3  * Module Name: utdecode - Utility decoding routines (value-to-string)
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2011, 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 "acnamesp.h"
47
48 #define _COMPONENT          ACPI_UTILITIES
49 ACPI_MODULE_NAME("utdecode")
50
51 /*******************************************************************************
52  *
53  * FUNCTION:    acpi_format_exception
54  *
55  * PARAMETERS:  Status       - The acpi_status code to be formatted
56  *
57  * RETURN:      A string containing the exception text. A valid pointer is
58  *              always returned.
59  *
60  * DESCRIPTION: This function translates an ACPI exception into an ASCII string
61  *              It is here instead of utxface.c so it is always present.
62  *
63  ******************************************************************************/
64 const char *acpi_format_exception(acpi_status status)
65 {
66         const char *exception = NULL;
67
68         ACPI_FUNCTION_ENTRY();
69
70         exception = acpi_ut_validate_exception(status);
71         if (!exception) {
72
73                 /* Exception code was not recognized */
74
75                 ACPI_ERROR((AE_INFO,
76                             "Unknown exception code: 0x%8.8X", status));
77
78                 exception = "UNKNOWN_STATUS_CODE";
79         }
80
81         return (ACPI_CAST_PTR(const char, exception));
82 }
83
84 ACPI_EXPORT_SYMBOL(acpi_format_exception)
85
86 /*
87  * Properties of the ACPI Object Types, both internal and external.
88  * The table is indexed by values of acpi_object_type
89  */
90 const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES] = {
91         ACPI_NS_NORMAL,         /* 00 Any              */
92         ACPI_NS_NORMAL,         /* 01 Number           */
93         ACPI_NS_NORMAL,         /* 02 String           */
94         ACPI_NS_NORMAL,         /* 03 Buffer           */
95         ACPI_NS_NORMAL,         /* 04 Package          */
96         ACPI_NS_NORMAL,         /* 05 field_unit       */
97         ACPI_NS_NEWSCOPE,       /* 06 Device           */
98         ACPI_NS_NORMAL,         /* 07 Event            */
99         ACPI_NS_NEWSCOPE,       /* 08 Method           */
100         ACPI_NS_NORMAL,         /* 09 Mutex            */
101         ACPI_NS_NORMAL,         /* 10 Region           */
102         ACPI_NS_NEWSCOPE,       /* 11 Power            */
103         ACPI_NS_NEWSCOPE,       /* 12 Processor        */
104         ACPI_NS_NEWSCOPE,       /* 13 Thermal          */
105         ACPI_NS_NORMAL,         /* 14 buffer_field     */
106         ACPI_NS_NORMAL,         /* 15 ddb_handle       */
107         ACPI_NS_NORMAL,         /* 16 Debug Object     */
108         ACPI_NS_NORMAL,         /* 17 def_field        */
109         ACPI_NS_NORMAL,         /* 18 bank_field       */
110         ACPI_NS_NORMAL,         /* 19 index_field      */
111         ACPI_NS_NORMAL,         /* 20 Reference        */
112         ACPI_NS_NORMAL,         /* 21 Alias            */
113         ACPI_NS_NORMAL,         /* 22 method_alias     */
114         ACPI_NS_NORMAL,         /* 23 Notify           */
115         ACPI_NS_NORMAL,         /* 24 Address Handler  */
116         ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,       /* 25 Resource Desc    */
117         ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,       /* 26 Resource Field   */
118         ACPI_NS_NEWSCOPE,       /* 27 Scope            */
119         ACPI_NS_NORMAL,         /* 28 Extra            */
120         ACPI_NS_NORMAL,         /* 29 Data             */
121         ACPI_NS_NORMAL          /* 30 Invalid          */
122 };
123
124 /*******************************************************************************
125  *
126  * FUNCTION:    acpi_ut_hex_to_ascii_char
127  *
128  * PARAMETERS:  Integer             - Contains the hex digit
129  *              Position            - bit position of the digit within the
130  *                                    integer (multiple of 4)
131  *
132  * RETURN:      The converted Ascii character
133  *
134  * DESCRIPTION: Convert a hex digit to an Ascii character
135  *
136  ******************************************************************************/
137
138 /* Hex to ASCII conversion table */
139
140 static const char acpi_gbl_hex_to_ascii[] = {
141         '0', '1', '2', '3', '4', '5', '6', '7',
142         '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
143 };
144
145 char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
146 {
147
148         return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
149 }
150
151 /*******************************************************************************
152  *
153  * FUNCTION:    acpi_ut_get_region_name
154  *
155  * PARAMETERS:  Space ID            - ID for the region
156  *
157  * RETURN:      Decoded region space_id name
158  *
159  * DESCRIPTION: Translate a Space ID into a name string (Debug only)
160  *
161  ******************************************************************************/
162
163 /* Region type decoding */
164
165 const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = {
166         "SystemMemory",
167         "SystemIO",
168         "PCI_Config",
169         "EmbeddedControl",
170         "SMBus",
171         "SystemCMOS",
172         "PCIBARTarget",
173         "IPMI",
174         "DataTable"
175 };
176
177 char *acpi_ut_get_region_name(u8 space_id)
178 {
179
180         if (space_id >= ACPI_USER_REGION_BEGIN) {
181                 return ("UserDefinedRegion");
182         } else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) {
183                 return ("InvalidSpaceId");
184         }
185
186         return (ACPI_CAST_PTR(char, acpi_gbl_region_types[space_id]));
187 }
188
189 /*******************************************************************************
190  *
191  * FUNCTION:    acpi_ut_get_event_name
192  *
193  * PARAMETERS:  event_id            - Fixed event ID
194  *
195  * RETURN:      Decoded event ID name
196  *
197  * DESCRIPTION: Translate a Event ID into a name string (Debug only)
198  *
199  ******************************************************************************/
200
201 /* Event type decoding */
202
203 static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = {
204         "PM_Timer",
205         "GlobalLock",
206         "PowerButton",
207         "SleepButton",
208         "RealTimeClock",
209 };
210
211 char *acpi_ut_get_event_name(u32 event_id)
212 {
213
214         if (event_id > ACPI_EVENT_MAX) {
215                 return ("InvalidEventID");
216         }
217
218         return (ACPI_CAST_PTR(char, acpi_gbl_event_types[event_id]));
219 }
220
221 /*******************************************************************************
222  *
223  * FUNCTION:    acpi_ut_get_type_name
224  *
225  * PARAMETERS:  Type                - An ACPI object type
226  *
227  * RETURN:      Decoded ACPI object type name
228  *
229  * DESCRIPTION: Translate a Type ID into a name string (Debug only)
230  *
231  ******************************************************************************/
232
233 /*
234  * Elements of acpi_gbl_ns_type_names below must match
235  * one-to-one with values of acpi_object_type
236  *
237  * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
238  * when stored in a table it really means that we have thus far seen no
239  * evidence to indicate what type is actually going to be stored for this entry.
240  */
241 static const char acpi_gbl_bad_type[] = "UNDEFINED";
242
243 /* Printable names of the ACPI object types */
244
245 static const char *acpi_gbl_ns_type_names[] = {
246         /* 00 */ "Untyped",
247         /* 01 */ "Integer",
248         /* 02 */ "String",
249         /* 03 */ "Buffer",
250         /* 04 */ "Package",
251         /* 05 */ "FieldUnit",
252         /* 06 */ "Device",
253         /* 07 */ "Event",
254         /* 08 */ "Method",
255         /* 09 */ "Mutex",
256         /* 10 */ "Region",
257         /* 11 */ "Power",
258         /* 12 */ "Processor",
259         /* 13 */ "Thermal",
260         /* 14 */ "BufferField",
261         /* 15 */ "DdbHandle",
262         /* 16 */ "DebugObject",
263         /* 17 */ "RegionField",
264         /* 18 */ "BankField",
265         /* 19 */ "IndexField",
266         /* 20 */ "Reference",
267         /* 21 */ "Alias",
268         /* 22 */ "MethodAlias",
269         /* 23 */ "Notify",
270         /* 24 */ "AddrHandler",
271         /* 25 */ "ResourceDesc",
272         /* 26 */ "ResourceFld",
273         /* 27 */ "Scope",
274         /* 28 */ "Extra",
275         /* 29 */ "Data",
276         /* 30 */ "Invalid"
277 };
278
279 char *acpi_ut_get_type_name(acpi_object_type type)
280 {
281
282         if (type > ACPI_TYPE_INVALID) {
283                 return (ACPI_CAST_PTR(char, acpi_gbl_bad_type));
284         }
285
286         return (ACPI_CAST_PTR(char, acpi_gbl_ns_type_names[type]));
287 }
288
289 char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc)
290 {
291
292         if (!obj_desc) {
293                 return ("[NULL Object Descriptor]");
294         }
295
296         return (acpi_ut_get_type_name(obj_desc->common.type));
297 }
298
299 /*******************************************************************************
300  *
301  * FUNCTION:    acpi_ut_get_node_name
302  *
303  * PARAMETERS:  Object               - A namespace node
304  *
305  * RETURN:      ASCII name of the node
306  *
307  * DESCRIPTION: Validate the node and return the node's ACPI name.
308  *
309  ******************************************************************************/
310
311 char *acpi_ut_get_node_name(void *object)
312 {
313         struct acpi_namespace_node *node = (struct acpi_namespace_node *)object;
314
315         /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
316
317         if (!object) {
318                 return ("NULL");
319         }
320
321         /* Check for Root node */
322
323         if ((object == ACPI_ROOT_OBJECT) || (object == acpi_gbl_root_node)) {
324                 return ("\"\\\" ");
325         }
326
327         /* Descriptor must be a namespace node */
328
329         if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
330                 return ("####");
331         }
332
333         /*
334          * Ensure name is valid. The name was validated/repaired when the node
335          * was created, but make sure it has not been corrupted.
336          */
337         acpi_ut_repair_name(node->name.ascii);
338
339         /* Return the name */
340
341         return (node->name.ascii);
342 }
343
344 /*******************************************************************************
345  *
346  * FUNCTION:    acpi_ut_get_descriptor_name
347  *
348  * PARAMETERS:  Object               - An ACPI object
349  *
350  * RETURN:      Decoded name of the descriptor type
351  *
352  * DESCRIPTION: Validate object and return the descriptor type
353  *
354  ******************************************************************************/
355
356 /* Printable names of object descriptor types */
357
358 static const char *acpi_gbl_desc_type_names[] = {
359         /* 00 */ "Not a Descriptor",
360         /* 01 */ "Cached",
361         /* 02 */ "State-Generic",
362         /* 03 */ "State-Update",
363         /* 04 */ "State-Package",
364         /* 05 */ "State-Control",
365         /* 06 */ "State-RootParseScope",
366         /* 07 */ "State-ParseScope",
367         /* 08 */ "State-WalkScope",
368         /* 09 */ "State-Result",
369         /* 10 */ "State-Notify",
370         /* 11 */ "State-Thread",
371         /* 12 */ "Walk",
372         /* 13 */ "Parser",
373         /* 14 */ "Operand",
374         /* 15 */ "Node"
375 };
376
377 char *acpi_ut_get_descriptor_name(void *object)
378 {
379
380         if (!object) {
381                 return ("NULL OBJECT");
382         }
383
384         if (ACPI_GET_DESCRIPTOR_TYPE(object) > ACPI_DESC_TYPE_MAX) {
385                 return ("Not a Descriptor");
386         }
387
388         return (ACPI_CAST_PTR(char,
389                               acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE
390                                                        (object)]));
391
392 }
393
394 /*******************************************************************************
395  *
396  * FUNCTION:    acpi_ut_get_reference_name
397  *
398  * PARAMETERS:  Object               - An ACPI reference object
399  *
400  * RETURN:      Decoded name of the type of reference
401  *
402  * DESCRIPTION: Decode a reference object sub-type to a string.
403  *
404  ******************************************************************************/
405
406 /* Printable names of reference object sub-types */
407
408 static const char *acpi_gbl_ref_class_names[] = {
409         /* 00 */ "Local",
410         /* 01 */ "Argument",
411         /* 02 */ "RefOf",
412         /* 03 */ "Index",
413         /* 04 */ "DdbHandle",
414         /* 05 */ "Named Object",
415         /* 06 */ "Debug"
416 };
417
418 const char *acpi_ut_get_reference_name(union acpi_operand_object *object)
419 {
420
421         if (!object) {
422                 return ("NULL Object");
423         }
424
425         if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
426                 return ("Not an Operand object");
427         }
428
429         if (object->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
430                 return ("Not a Reference object");
431         }
432
433         if (object->reference.class > ACPI_REFCLASS_MAX) {
434                 return ("Unknown Reference class");
435         }
436
437         return (acpi_gbl_ref_class_names[object->reference.class]);
438 }
439
440 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
441 /*
442  * Strings and procedures used for debug only
443  */
444
445 /*******************************************************************************
446  *
447  * FUNCTION:    acpi_ut_get_mutex_name
448  *
449  * PARAMETERS:  mutex_id        - The predefined ID for this mutex.
450  *
451  * RETURN:      Decoded name of the internal mutex
452  *
453  * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
454  *
455  ******************************************************************************/
456
457 /* Names for internal mutex objects, used for debug output */
458
459 static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
460         "ACPI_MTX_Interpreter",
461         "ACPI_MTX_Namespace",
462         "ACPI_MTX_Tables",
463         "ACPI_MTX_Events",
464         "ACPI_MTX_Caches",
465         "ACPI_MTX_Memory",
466         "ACPI_MTX_CommandComplete",
467         "ACPI_MTX_CommandReady"
468 };
469
470 char *acpi_ut_get_mutex_name(u32 mutex_id)
471 {
472
473         if (mutex_id > ACPI_MAX_MUTEX) {
474                 return ("Invalid Mutex ID");
475         }
476
477         return (acpi_gbl_mutex_names[mutex_id]);
478 }
479
480 /*******************************************************************************
481  *
482  * FUNCTION:    acpi_ut_get_notify_name
483  *
484  * PARAMETERS:  notify_value    - Value from the Notify() request
485  *
486  * RETURN:      Decoded name for the notify value
487  *
488  * DESCRIPTION: Translate a Notify Value to a notify namestring.
489  *
490  ******************************************************************************/
491
492 /* Names for Notify() values, used for debug output */
493
494 static const char *acpi_gbl_notify_value_names[] = {
495         "Bus Check",
496         "Device Check",
497         "Device Wake",
498         "Eject Request",
499         "Device Check Light",
500         "Frequency Mismatch",
501         "Bus Mode Mismatch",
502         "Power Fault",
503         "Capabilities Check",
504         "Device PLD Check",
505         "Reserved",
506         "System Locality Update"
507 };
508
509 const char *acpi_ut_get_notify_name(u32 notify_value)
510 {
511
512         if (notify_value <= ACPI_NOTIFY_MAX) {
513                 return (acpi_gbl_notify_value_names[notify_value]);
514         } else if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
515                 return ("Reserved");
516         } else {                /* Greater or equal to 0x80 */
517
518                 return ("**Device Specific**");
519         }
520 }
521 #endif
522
523 /*******************************************************************************
524  *
525  * FUNCTION:    acpi_ut_valid_object_type
526  *
527  * PARAMETERS:  Type            - Object type to be validated
528  *
529  * RETURN:      TRUE if valid object type, FALSE otherwise
530  *
531  * DESCRIPTION: Validate an object type
532  *
533  ******************************************************************************/
534
535 u8 acpi_ut_valid_object_type(acpi_object_type type)
536 {
537
538         if (type > ACPI_TYPE_LOCAL_MAX) {
539
540                 /* Note: Assumes all TYPEs are contiguous (external/local) */
541
542                 return (FALSE);
543         }
544
545         return (TRUE);
546 }