1 /******************************************************************************
3 * Module Name: utdecode - Utility decoding routines (value-to-string)
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 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utdecode")
52 * Properties of the ACPI Object Types, both internal and external.
53 * The table is indexed by values of acpi_object_type
55 const u8 acpi_gbl_ns_properties
[ACPI_NUM_NS_TYPES
] = {
56 ACPI_NS_NORMAL
, /* 00 Any */
57 ACPI_NS_NORMAL
, /* 01 Number */
58 ACPI_NS_NORMAL
, /* 02 String */
59 ACPI_NS_NORMAL
, /* 03 Buffer */
60 ACPI_NS_NORMAL
, /* 04 Package */
61 ACPI_NS_NORMAL
, /* 05 field_unit */
62 ACPI_NS_NEWSCOPE
, /* 06 Device */
63 ACPI_NS_NORMAL
, /* 07 Event */
64 ACPI_NS_NEWSCOPE
, /* 08 Method */
65 ACPI_NS_NORMAL
, /* 09 Mutex */
66 ACPI_NS_NORMAL
, /* 10 Region */
67 ACPI_NS_NEWSCOPE
, /* 11 Power */
68 ACPI_NS_NEWSCOPE
, /* 12 Processor */
69 ACPI_NS_NEWSCOPE
, /* 13 Thermal */
70 ACPI_NS_NORMAL
, /* 14 buffer_field */
71 ACPI_NS_NORMAL
, /* 15 ddb_handle */
72 ACPI_NS_NORMAL
, /* 16 Debug Object */
73 ACPI_NS_NORMAL
, /* 17 def_field */
74 ACPI_NS_NORMAL
, /* 18 bank_field */
75 ACPI_NS_NORMAL
, /* 19 index_field */
76 ACPI_NS_NORMAL
, /* 20 Reference */
77 ACPI_NS_NORMAL
, /* 21 Alias */
78 ACPI_NS_NORMAL
, /* 22 method_alias */
79 ACPI_NS_NORMAL
, /* 23 Notify */
80 ACPI_NS_NORMAL
, /* 24 Address Handler */
81 ACPI_NS_NEWSCOPE
| ACPI_NS_LOCAL
, /* 25 Resource Desc */
82 ACPI_NS_NEWSCOPE
| ACPI_NS_LOCAL
, /* 26 Resource Field */
83 ACPI_NS_NEWSCOPE
, /* 27 Scope */
84 ACPI_NS_NORMAL
, /* 28 Extra */
85 ACPI_NS_NORMAL
, /* 29 Data */
86 ACPI_NS_NORMAL
/* 30 Invalid */
89 /*******************************************************************************
91 * FUNCTION: acpi_ut_hex_to_ascii_char
93 * PARAMETERS: integer - Contains the hex digit
94 * position - bit position of the digit within the
95 * integer (multiple of 4)
97 * RETURN: The converted Ascii character
99 * DESCRIPTION: Convert a hex digit to an Ascii character
101 ******************************************************************************/
103 /* Hex to ASCII conversion table */
105 static const char acpi_gbl_hex_to_ascii
[] = {
106 '0', '1', '2', '3', '4', '5', '6', '7',
107 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
110 char acpi_ut_hex_to_ascii_char(u64 integer
, u32 position
)
113 return (acpi_gbl_hex_to_ascii
[(integer
>> position
) & 0xF]);
116 /*******************************************************************************
118 * FUNCTION: acpi_ut_get_region_name
120 * PARAMETERS: Space ID - ID for the region
122 * RETURN: Decoded region space_id name
124 * DESCRIPTION: Translate a Space ID into a name string (Debug only)
126 ******************************************************************************/
128 /* Region type decoding */
130 const char *acpi_gbl_region_types
[ACPI_NUM_PREDEFINED_REGIONS
] = {
131 "SystemMemory", /* 0x00 */
132 "SystemIO", /* 0x01 */
133 "PCI_Config", /* 0x02 */
134 "EmbeddedControl", /* 0x03 */
136 "SystemCMOS", /* 0x05 */
137 "PCIBARTarget", /* 0x06 */
139 "GeneralPurposeIo", /* 0x08 */
140 "GenericSerialBus", /* 0x09 */
144 char *acpi_ut_get_region_name(u8 space_id
)
147 if (space_id
>= ACPI_USER_REGION_BEGIN
) {
148 return ("UserDefinedRegion");
149 } else if (space_id
== ACPI_ADR_SPACE_DATA_TABLE
) {
150 return ("DataTable");
151 } else if (space_id
== ACPI_ADR_SPACE_FIXED_HARDWARE
) {
152 return ("FunctionalFixedHW");
153 } else if (space_id
>= ACPI_NUM_PREDEFINED_REGIONS
) {
154 return ("InvalidSpaceId");
157 return (ACPI_CAST_PTR(char, acpi_gbl_region_types
[space_id
]));
160 /*******************************************************************************
162 * FUNCTION: acpi_ut_get_event_name
164 * PARAMETERS: event_id - Fixed event ID
166 * RETURN: Decoded event ID name
168 * DESCRIPTION: Translate a Event ID into a name string (Debug only)
170 ******************************************************************************/
172 /* Event type decoding */
174 static const char *acpi_gbl_event_types
[ACPI_NUM_FIXED_EVENTS
] = {
182 char *acpi_ut_get_event_name(u32 event_id
)
185 if (event_id
> ACPI_EVENT_MAX
) {
186 return ("InvalidEventID");
189 return (ACPI_CAST_PTR(char, acpi_gbl_event_types
[event_id
]));
192 /*******************************************************************************
194 * FUNCTION: acpi_ut_get_type_name
196 * PARAMETERS: type - An ACPI object type
198 * RETURN: Decoded ACPI object type name
200 * DESCRIPTION: Translate a Type ID into a name string (Debug only)
202 ******************************************************************************/
205 * Elements of acpi_gbl_ns_type_names below must match
206 * one-to-one with values of acpi_object_type
208 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
209 * when stored in a table it really means that we have thus far seen no
210 * evidence to indicate what type is actually going to be stored for this entry.
212 static const char acpi_gbl_bad_type
[] = "UNDEFINED";
214 /* Printable names of the ACPI object types */
216 static const char *acpi_gbl_ns_type_names
[] = {
222 /* 05 */ "FieldUnit",
229 /* 12 */ "Processor",
231 /* 14 */ "BufferField",
232 /* 15 */ "DdbHandle",
233 /* 16 */ "DebugObject",
234 /* 17 */ "RegionField",
235 /* 18 */ "BankField",
236 /* 19 */ "IndexField",
237 /* 20 */ "Reference",
239 /* 22 */ "MethodAlias",
241 /* 24 */ "AddrHandler",
242 /* 25 */ "ResourceDesc",
243 /* 26 */ "ResourceFld",
250 char *acpi_ut_get_type_name(acpi_object_type type
)
253 if (type
> ACPI_TYPE_INVALID
) {
254 return (ACPI_CAST_PTR(char, acpi_gbl_bad_type
));
257 return (ACPI_CAST_PTR(char, acpi_gbl_ns_type_names
[type
]));
260 char *acpi_ut_get_object_type_name(union acpi_operand_object
*obj_desc
)
264 return ("[NULL Object Descriptor]");
267 return (acpi_ut_get_type_name(obj_desc
->common
.type
));
270 /*******************************************************************************
272 * FUNCTION: acpi_ut_get_node_name
274 * PARAMETERS: object - A namespace node
276 * RETURN: ASCII name of the node
278 * DESCRIPTION: Validate the node and return the node's ACPI name.
280 ******************************************************************************/
282 char *acpi_ut_get_node_name(void *object
)
284 struct acpi_namespace_node
*node
= (struct acpi_namespace_node
*)object
;
286 /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
292 /* Check for Root node */
294 if ((object
== ACPI_ROOT_OBJECT
) || (object
== acpi_gbl_root_node
)) {
298 /* Descriptor must be a namespace node */
300 if (ACPI_GET_DESCRIPTOR_TYPE(node
) != ACPI_DESC_TYPE_NAMED
) {
305 * Ensure name is valid. The name was validated/repaired when the node
306 * was created, but make sure it has not been corrupted.
308 acpi_ut_repair_name(node
->name
.ascii
);
310 /* Return the name */
312 return (node
->name
.ascii
);
315 /*******************************************************************************
317 * FUNCTION: acpi_ut_get_descriptor_name
319 * PARAMETERS: object - An ACPI object
321 * RETURN: Decoded name of the descriptor type
323 * DESCRIPTION: Validate object and return the descriptor type
325 ******************************************************************************/
327 /* Printable names of object descriptor types */
329 static const char *acpi_gbl_desc_type_names
[] = {
330 /* 00 */ "Not a Descriptor",
332 /* 02 */ "State-Generic",
333 /* 03 */ "State-Update",
334 /* 04 */ "State-Package",
335 /* 05 */ "State-Control",
336 /* 06 */ "State-RootParseScope",
337 /* 07 */ "State-ParseScope",
338 /* 08 */ "State-WalkScope",
339 /* 09 */ "State-Result",
340 /* 10 */ "State-Notify",
341 /* 11 */ "State-Thread",
348 char *acpi_ut_get_descriptor_name(void *object
)
352 return ("NULL OBJECT");
355 if (ACPI_GET_DESCRIPTOR_TYPE(object
) > ACPI_DESC_TYPE_MAX
) {
356 return ("Not a Descriptor");
359 return (ACPI_CAST_PTR(char,
360 acpi_gbl_desc_type_names
[ACPI_GET_DESCRIPTOR_TYPE
365 /*******************************************************************************
367 * FUNCTION: acpi_ut_get_reference_name
369 * PARAMETERS: object - An ACPI reference object
371 * RETURN: Decoded name of the type of reference
373 * DESCRIPTION: Decode a reference object sub-type to a string.
375 ******************************************************************************/
377 /* Printable names of reference object sub-types */
379 static const char *acpi_gbl_ref_class_names
[] = {
384 /* 04 */ "DdbHandle",
385 /* 05 */ "Named Object",
389 const char *acpi_ut_get_reference_name(union acpi_operand_object
*object
)
393 return ("NULL Object");
396 if (ACPI_GET_DESCRIPTOR_TYPE(object
) != ACPI_DESC_TYPE_OPERAND
) {
397 return ("Not an Operand object");
400 if (object
->common
.type
!= ACPI_TYPE_LOCAL_REFERENCE
) {
401 return ("Not a Reference object");
404 if (object
->reference
.class > ACPI_REFCLASS_MAX
) {
405 return ("Unknown Reference class");
408 return (acpi_gbl_ref_class_names
[object
->reference
.class]);
411 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
413 * Strings and procedures used for debug only
416 /*******************************************************************************
418 * FUNCTION: acpi_ut_get_mutex_name
420 * PARAMETERS: mutex_id - The predefined ID for this mutex.
422 * RETURN: Decoded name of the internal mutex
424 * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
426 ******************************************************************************/
428 /* Names for internal mutex objects, used for debug output */
430 static char *acpi_gbl_mutex_names
[ACPI_NUM_MUTEX
] = {
431 "ACPI_MTX_Interpreter",
432 "ACPI_MTX_Namespace",
437 "ACPI_MTX_CommandComplete",
438 "ACPI_MTX_CommandReady"
441 char *acpi_ut_get_mutex_name(u32 mutex_id
)
444 if (mutex_id
> ACPI_MAX_MUTEX
) {
445 return ("Invalid Mutex ID");
448 return (acpi_gbl_mutex_names
[mutex_id
]);
451 /*******************************************************************************
453 * FUNCTION: acpi_ut_get_notify_name
455 * PARAMETERS: notify_value - Value from the Notify() request
457 * RETURN: Decoded name for the notify value
459 * DESCRIPTION: Translate a Notify Value to a notify namestring.
461 ******************************************************************************/
463 /* Names for Notify() values, used for debug output */
465 static const char *acpi_gbl_notify_value_names
[ACPI_NOTIFY_MAX
+ 1] = {
466 /* 00 */ "Bus Check",
467 /* 01 */ "Device Check",
468 /* 02 */ "Device Wake",
469 /* 03 */ "Eject Request",
470 /* 04 */ "Device Check Light",
471 /* 05 */ "Frequency Mismatch",
472 /* 06 */ "Bus Mode Mismatch",
473 /* 07 */ "Power Fault",
474 /* 08 */ "Capabilities Check",
475 /* 09 */ "Device PLD Check",
477 /* 11 */ "System Locality Update",
478 /* 12 */ "Shutdown Request"
481 const char *acpi_ut_get_notify_name(u32 notify_value
)
484 if (notify_value
<= ACPI_NOTIFY_MAX
) {
485 return (acpi_gbl_notify_value_names
[notify_value
]);
486 } else if (notify_value
<= ACPI_MAX_SYS_NOTIFY
) {
488 } else if (notify_value
<= ACPI_MAX_DEVICE_SPECIFIC_NOTIFY
) {
489 return ("Device Specific");
491 return ("Hardware Specific");
496 /*******************************************************************************
498 * FUNCTION: acpi_ut_valid_object_type
500 * PARAMETERS: type - Object type to be validated
502 * RETURN: TRUE if valid object type, FALSE otherwise
504 * DESCRIPTION: Validate an object type
506 ******************************************************************************/
508 u8
acpi_ut_valid_object_type(acpi_object_type type
)
511 if (type
> ACPI_TYPE_LOCAL_MAX
) {
513 /* Note: Assumes all TYPEs are contiguous (external/local) */