blob: 90ec37c473c617f24af5beae34b1e2b6931eb4b4 [file] [log] [blame]
Bob Moorea257e072011-02-14 16:00:21 +08001/******************************************************************************
2 *
3 * Module Name: utdecode - Utility decoding routines (value-to-string)
4 *
5 *****************************************************************************/
6
7/*
Bob Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, Intel Corp.
Bob Moorea257e072011-02-14 16:00:21 +08009 * 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
49ACPI_MODULE_NAME("utdecode")
50
Bob Moorea257e072011-02-14 16:00:21 +080051/*
52 * Properties of the ACPI Object Types, both internal and external.
53 * The table is indexed by values of acpi_object_type
54 */
55const 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 */
87};
88
89/*******************************************************************************
90 *
91 * FUNCTION: acpi_ut_hex_to_ascii_char
92 *
Bob Mooreba494be2012-07-12 09:40:10 +080093 * PARAMETERS: integer - Contains the hex digit
94 * position - bit position of the digit within the
Bob Moorea257e072011-02-14 16:00:21 +080095 * integer (multiple of 4)
96 *
97 * RETURN: The converted Ascii character
98 *
99 * DESCRIPTION: Convert a hex digit to an Ascii character
100 *
101 ******************************************************************************/
102
103/* Hex to ASCII conversion table */
104
105static 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'
108};
109
110char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
111{
112
113 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
114}
115
116/*******************************************************************************
117 *
118 * FUNCTION: acpi_ut_get_region_name
119 *
120 * PARAMETERS: Space ID - ID for the region
121 *
122 * RETURN: Decoded region space_id name
123 *
124 * DESCRIPTION: Translate a Space ID into a name string (Debug only)
125 *
126 ******************************************************************************/
127
128/* Region type decoding */
129
130const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = {
Bob Moore540b85a2012-07-16 10:01:36 +0800131 "SystemMemory", /* 0x00 */
132 "SystemIO", /* 0x01 */
133 "PCI_Config", /* 0x02 */
134 "EmbeddedControl", /* 0x03 */
135 "SMBus", /* 0x04 */
136 "SystemCMOS", /* 0x05 */
137 "PCIBARTarget", /* 0x06 */
138 "IPMI", /* 0x07 */
139 "GeneralPurposeIo", /* 0x08 */
140 "GenericSerialBus", /* 0x09 */
141 "PCC" /* 0x0A */
Bob Moorea257e072011-02-14 16:00:21 +0800142};
143
144char *acpi_ut_get_region_name(u8 space_id)
145{
146
147 if (space_id >= ACPI_USER_REGION_BEGIN) {
148 return ("UserDefinedRegion");
Bob Moore82a1b7c2011-04-13 13:19:35 +0800149 } else if (space_id == ACPI_ADR_SPACE_DATA_TABLE) {
150 return ("DataTable");
Bob Moore47863b92011-02-14 16:11:43 +0800151 } else if (space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
152 return ("FunctionalFixedHW");
Bob Moorea257e072011-02-14 16:00:21 +0800153 } else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) {
154 return ("InvalidSpaceId");
155 }
156
157 return (ACPI_CAST_PTR(char, acpi_gbl_region_types[space_id]));
158}
159
160/*******************************************************************************
161 *
162 * FUNCTION: acpi_ut_get_event_name
163 *
164 * PARAMETERS: event_id - Fixed event ID
165 *
166 * RETURN: Decoded event ID name
167 *
168 * DESCRIPTION: Translate a Event ID into a name string (Debug only)
169 *
170 ******************************************************************************/
171
172/* Event type decoding */
173
174static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = {
175 "PM_Timer",
176 "GlobalLock",
177 "PowerButton",
178 "SleepButton",
179 "RealTimeClock",
180};
181
182char *acpi_ut_get_event_name(u32 event_id)
183{
184
185 if (event_id > ACPI_EVENT_MAX) {
186 return ("InvalidEventID");
187 }
188
189 return (ACPI_CAST_PTR(char, acpi_gbl_event_types[event_id]));
190}
191
192/*******************************************************************************
193 *
194 * FUNCTION: acpi_ut_get_type_name
195 *
Bob Mooreba494be2012-07-12 09:40:10 +0800196 * PARAMETERS: type - An ACPI object type
Bob Moorea257e072011-02-14 16:00:21 +0800197 *
198 * RETURN: Decoded ACPI object type name
199 *
200 * DESCRIPTION: Translate a Type ID into a name string (Debug only)
201 *
202 ******************************************************************************/
203
204/*
205 * Elements of acpi_gbl_ns_type_names below must match
206 * one-to-one with values of acpi_object_type
207 *
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.
211 */
212static const char acpi_gbl_bad_type[] = "UNDEFINED";
213
214/* Printable names of the ACPI object types */
215
216static const char *acpi_gbl_ns_type_names[] = {
217 /* 00 */ "Untyped",
218 /* 01 */ "Integer",
219 /* 02 */ "String",
220 /* 03 */ "Buffer",
221 /* 04 */ "Package",
222 /* 05 */ "FieldUnit",
223 /* 06 */ "Device",
224 /* 07 */ "Event",
225 /* 08 */ "Method",
226 /* 09 */ "Mutex",
227 /* 10 */ "Region",
228 /* 11 */ "Power",
229 /* 12 */ "Processor",
230 /* 13 */ "Thermal",
231 /* 14 */ "BufferField",
232 /* 15 */ "DdbHandle",
233 /* 16 */ "DebugObject",
234 /* 17 */ "RegionField",
235 /* 18 */ "BankField",
236 /* 19 */ "IndexField",
237 /* 20 */ "Reference",
238 /* 21 */ "Alias",
239 /* 22 */ "MethodAlias",
240 /* 23 */ "Notify",
241 /* 24 */ "AddrHandler",
242 /* 25 */ "ResourceDesc",
243 /* 26 */ "ResourceFld",
244 /* 27 */ "Scope",
245 /* 28 */ "Extra",
246 /* 29 */ "Data",
247 /* 30 */ "Invalid"
248};
249
250char *acpi_ut_get_type_name(acpi_object_type type)
251{
252
253 if (type > ACPI_TYPE_INVALID) {
254 return (ACPI_CAST_PTR(char, acpi_gbl_bad_type));
255 }
256
257 return (ACPI_CAST_PTR(char, acpi_gbl_ns_type_names[type]));
258}
259
260char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc)
261{
262
263 if (!obj_desc) {
264 return ("[NULL Object Descriptor]");
265 }
266
267 return (acpi_ut_get_type_name(obj_desc->common.type));
268}
269
270/*******************************************************************************
271 *
272 * FUNCTION: acpi_ut_get_node_name
273 *
Bob Mooreba494be2012-07-12 09:40:10 +0800274 * PARAMETERS: object - A namespace node
Bob Moorea257e072011-02-14 16:00:21 +0800275 *
276 * RETURN: ASCII name of the node
277 *
278 * DESCRIPTION: Validate the node and return the node's ACPI name.
279 *
280 ******************************************************************************/
281
282char *acpi_ut_get_node_name(void *object)
283{
284 struct acpi_namespace_node *node = (struct acpi_namespace_node *)object;
285
286 /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
287
288 if (!object) {
289 return ("NULL");
290 }
291
292 /* Check for Root node */
293
294 if ((object == ACPI_ROOT_OBJECT) || (object == acpi_gbl_root_node)) {
295 return ("\"\\\" ");
296 }
297
298 /* Descriptor must be a namespace node */
299
300 if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
301 return ("####");
302 }
303
304 /*
305 * Ensure name is valid. The name was validated/repaired when the node
306 * was created, but make sure it has not been corrupted.
307 */
308 acpi_ut_repair_name(node->name.ascii);
309
310 /* Return the name */
311
312 return (node->name.ascii);
313}
314
315/*******************************************************************************
316 *
317 * FUNCTION: acpi_ut_get_descriptor_name
318 *
Bob Mooreba494be2012-07-12 09:40:10 +0800319 * PARAMETERS: object - An ACPI object
Bob Moorea257e072011-02-14 16:00:21 +0800320 *
321 * RETURN: Decoded name of the descriptor type
322 *
323 * DESCRIPTION: Validate object and return the descriptor type
324 *
325 ******************************************************************************/
326
327/* Printable names of object descriptor types */
328
329static const char *acpi_gbl_desc_type_names[] = {
330 /* 00 */ "Not a Descriptor",
331 /* 01 */ "Cached",
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",
342 /* 12 */ "Walk",
343 /* 13 */ "Parser",
344 /* 14 */ "Operand",
345 /* 15 */ "Node"
346};
347
348char *acpi_ut_get_descriptor_name(void *object)
349{
350
351 if (!object) {
352 return ("NULL OBJECT");
353 }
354
355 if (ACPI_GET_DESCRIPTOR_TYPE(object) > ACPI_DESC_TYPE_MAX) {
356 return ("Not a Descriptor");
357 }
358
359 return (ACPI_CAST_PTR(char,
360 acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE
361 (object)]));
362
363}
364
365/*******************************************************************************
366 *
367 * FUNCTION: acpi_ut_get_reference_name
368 *
Bob Mooreba494be2012-07-12 09:40:10 +0800369 * PARAMETERS: object - An ACPI reference object
Bob Moorea257e072011-02-14 16:00:21 +0800370 *
371 * RETURN: Decoded name of the type of reference
372 *
373 * DESCRIPTION: Decode a reference object sub-type to a string.
374 *
375 ******************************************************************************/
376
377/* Printable names of reference object sub-types */
378
379static const char *acpi_gbl_ref_class_names[] = {
380 /* 00 */ "Local",
381 /* 01 */ "Argument",
382 /* 02 */ "RefOf",
383 /* 03 */ "Index",
384 /* 04 */ "DdbHandle",
385 /* 05 */ "Named Object",
386 /* 06 */ "Debug"
387};
388
389const char *acpi_ut_get_reference_name(union acpi_operand_object *object)
390{
391
392 if (!object) {
393 return ("NULL Object");
394 }
395
396 if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
397 return ("Not an Operand object");
398 }
399
400 if (object->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
401 return ("Not a Reference object");
402 }
403
404 if (object->reference.class > ACPI_REFCLASS_MAX) {
405 return ("Unknown Reference class");
406 }
407
408 return (acpi_gbl_ref_class_names[object->reference.class]);
409}
410
411#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
412/*
413 * Strings and procedures used for debug only
414 */
415
416/*******************************************************************************
417 *
418 * FUNCTION: acpi_ut_get_mutex_name
419 *
420 * PARAMETERS: mutex_id - The predefined ID for this mutex.
421 *
422 * RETURN: Decoded name of the internal mutex
423 *
424 * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
425 *
426 ******************************************************************************/
427
428/* Names for internal mutex objects, used for debug output */
429
430static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
431 "ACPI_MTX_Interpreter",
432 "ACPI_MTX_Namespace",
433 "ACPI_MTX_Tables",
434 "ACPI_MTX_Events",
435 "ACPI_MTX_Caches",
436 "ACPI_MTX_Memory",
437 "ACPI_MTX_CommandComplete",
438 "ACPI_MTX_CommandReady"
439};
440
441char *acpi_ut_get_mutex_name(u32 mutex_id)
442{
443
444 if (mutex_id > ACPI_MAX_MUTEX) {
445 return ("Invalid Mutex ID");
446 }
447
448 return (acpi_gbl_mutex_names[mutex_id]);
449}
450
451/*******************************************************************************
452 *
453 * FUNCTION: acpi_ut_get_notify_name
454 *
455 * PARAMETERS: notify_value - Value from the Notify() request
456 *
457 * RETURN: Decoded name for the notify value
458 *
459 * DESCRIPTION: Translate a Notify Value to a notify namestring.
460 *
461 ******************************************************************************/
462
463/* Names for Notify() values, used for debug output */
464
Bob Moore06a63e32014-04-04 12:37:44 +0800465static const char *acpi_gbl_generic_notify[ACPI_NOTIFY_MAX + 1] = {
Bob Mooreea143602012-02-14 18:23:39 +0800466 /* 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",
Bob Moore06a63e32014-04-04 12:37:44 +0800476 /* 0A */ "Reserved",
477 /* 0B */ "System Locality Update",
478 /* 0C */ "Shutdown Request"
Bob Moorea257e072011-02-14 16:00:21 +0800479};
480
Bob Moore06a63e32014-04-04 12:37:44 +0800481static const char *acpi_gbl_device_notify[4] = {
482 /* 80 */ "Status Change",
483 /* 81 */ "Information Change",
484 /* 82 */ "Device-Specific Change",
485 /* 83 */ "Device-Specific Change"
486};
487
488static const char *acpi_gbl_processor_notify[4] = {
489 /* 80 */ "Performance Capability Change",
490 /* 81 */ "C-State Change",
491 /* 82 */ "Throttling Capability Change",
492 /* 83 */ "Device-Specific Change"
493};
494
495static const char *acpi_gbl_thermal_notify[4] = {
496 /* 80 */ "Thermal Status Change",
497 /* 81 */ "Thermal Trip Point Change",
498 /* 82 */ "Thermal Device List Change",
499 /* 83 */ "Thermal Relationship Change"
500};
501
502const char *acpi_ut_get_notify_name(u32 notify_value, acpi_object_type type)
Bob Moorea257e072011-02-14 16:00:21 +0800503{
504
Bob Moore06a63e32014-04-04 12:37:44 +0800505 /* 00 - 0C are common to all object types */
506
Bob Moorea257e072011-02-14 16:00:21 +0800507 if (notify_value <= ACPI_NOTIFY_MAX) {
Bob Moore06a63e32014-04-04 12:37:44 +0800508 return (acpi_gbl_generic_notify[notify_value]);
Bob Moorea257e072011-02-14 16:00:21 +0800509 }
Bob Moore06a63e32014-04-04 12:37:44 +0800510
511 /* 0D - 7F are reserved */
512
513 if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
514 return ("Reserved");
515 }
516
517 /* 80 - 83 are per-object-type */
518
519 if (notify_value <= 0x83) {
520 switch (type) {
521 case ACPI_TYPE_ANY:
522 case ACPI_TYPE_DEVICE:
523 return (acpi_gbl_device_notify[notify_value - 0x80]);
524
525 case ACPI_TYPE_PROCESSOR:
526 return (acpi_gbl_processor_notify[notify_value - 0x80]);
527
528 case ACPI_TYPE_THERMAL:
529 return (acpi_gbl_thermal_notify[notify_value - 0x80]);
530
531 default:
532 return ("Target object type does not support notifies");
533 }
534 }
535
536 /* 84 - BF are device-specific */
537
538 if (notify_value <= ACPI_MAX_DEVICE_SPECIFIC_NOTIFY) {
539 return ("Device-Specific");
540 }
541
542 /* C0 and above are hardware-specific */
543
544 return ("Hardware-Specific");
Bob Moorea257e072011-02-14 16:00:21 +0800545}
546#endif
547
548/*******************************************************************************
549 *
550 * FUNCTION: acpi_ut_valid_object_type
551 *
Bob Mooreba494be2012-07-12 09:40:10 +0800552 * PARAMETERS: type - Object type to be validated
Bob Moorea257e072011-02-14 16:00:21 +0800553 *
554 * RETURN: TRUE if valid object type, FALSE otherwise
555 *
556 * DESCRIPTION: Validate an object type
557 *
558 ******************************************************************************/
559
560u8 acpi_ut_valid_object_type(acpi_object_type type)
561{
562
563 if (type > ACPI_TYPE_LOCAL_MAX) {
564
565 /* Note: Assumes all TYPEs are contiguous (external/local) */
566
567 return (FALSE);
568 }
569
570 return (TRUE);
571}