1 /****************************************************************************** 2 * 3 * Module Name: utdecode - Utility decoding routines (value-to-string) 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, 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 * Properties of the ACPI Object Types, both internal and external. 53 * The table is indexed by values of acpi_object_type 54 */ 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 */ 87 }; 88 89 /******************************************************************************* 90 * 91 * FUNCTION: acpi_ut_hex_to_ascii_char 92 * 93 * PARAMETERS: integer - Contains the hex digit 94 * position - bit position of the digit within the 95 * 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 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' 108 }; 109 110 char 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 130 const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = { 131 "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 */ 142 }; 143 144 char *acpi_ut_get_region_name(u8 space_id) 145 { 146 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"); 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 174 static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = { 175 "PM_Timer", 176 "GlobalLock", 177 "PowerButton", 178 "SleepButton", 179 "RealTimeClock", 180 }; 181 182 char *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 * 196 * PARAMETERS: type - An ACPI object type 197 * 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 */ 212 static const char acpi_gbl_bad_type[] = "UNDEFINED"; 213 214 /* Printable names of the ACPI object types */ 215 216 static 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 250 char *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 260 char *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 * 274 * PARAMETERS: object - A namespace node 275 * 276 * RETURN: ASCII name of the node 277 * 278 * DESCRIPTION: Validate the node and return the node's ACPI name. 279 * 280 ******************************************************************************/ 281 282 char *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 * 319 * PARAMETERS: object - An ACPI object 320 * 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 329 static 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 348 char *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 * 369 * PARAMETERS: object - An ACPI reference object 370 * 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 379 static 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 389 const 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 430 static 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 441 char *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 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", 476 /* 10 */ "Reserved", 477 /* 11 */ "System Locality Update", 478 /* 12 */ "Shutdown Request" 479 }; 480 481 const char *acpi_ut_get_notify_name(u32 notify_value) 482 { 483 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) { 487 return ("Reserved"); 488 } else if (notify_value <= ACPI_MAX_DEVICE_SPECIFIC_NOTIFY) { 489 return ("Device Specific"); 490 } else { 491 return ("Hardware Specific"); 492 } 493 } 494 #endif 495 496 /******************************************************************************* 497 * 498 * FUNCTION: acpi_ut_valid_object_type 499 * 500 * PARAMETERS: type - Object type to be validated 501 * 502 * RETURN: TRUE if valid object type, FALSE otherwise 503 * 504 * DESCRIPTION: Validate an object type 505 * 506 ******************************************************************************/ 507 508 u8 acpi_ut_valid_object_type(acpi_object_type type) 509 { 510 511 if (type > ACPI_TYPE_LOCAL_MAX) { 512 513 /* Note: Assumes all TYPEs are contiguous (external/local) */ 514 515 return (FALSE); 516 } 517 518 return (TRUE); 519 } 520