utdecode.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /******************************************************************************
  2. *
  3. * Module Name: utdecode - Utility decoding routines (value-to-string)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acnamesp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utdecode")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_format_exception
  50. *
  51. * PARAMETERS: Status - The acpi_status code to be formatted
  52. *
  53. * RETURN: A string containing the exception text. A valid pointer is
  54. * always returned.
  55. *
  56. * DESCRIPTION: This function translates an ACPI exception into an ASCII string
  57. * It is here instead of utxface.c so it is always present.
  58. *
  59. ******************************************************************************/
  60. const char *acpi_format_exception(acpi_status status)
  61. {
  62. const char *exception = NULL;
  63. ACPI_FUNCTION_ENTRY();
  64. exception = acpi_ut_validate_exception(status);
  65. if (!exception) {
  66. /* Exception code was not recognized */
  67. ACPI_ERROR((AE_INFO,
  68. "Unknown exception code: 0x%8.8X", status));
  69. exception = "UNKNOWN_STATUS_CODE";
  70. }
  71. return (ACPI_CAST_PTR(const char, exception));
  72. }
  73. ACPI_EXPORT_SYMBOL(acpi_format_exception)
  74. /*
  75. * Properties of the ACPI Object Types, both internal and external.
  76. * The table is indexed by values of acpi_object_type
  77. */
  78. const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES] = {
  79. ACPI_NS_NORMAL, /* 00 Any */
  80. ACPI_NS_NORMAL, /* 01 Number */
  81. ACPI_NS_NORMAL, /* 02 String */
  82. ACPI_NS_NORMAL, /* 03 Buffer */
  83. ACPI_NS_NORMAL, /* 04 Package */
  84. ACPI_NS_NORMAL, /* 05 field_unit */
  85. ACPI_NS_NEWSCOPE, /* 06 Device */
  86. ACPI_NS_NORMAL, /* 07 Event */
  87. ACPI_NS_NEWSCOPE, /* 08 Method */
  88. ACPI_NS_NORMAL, /* 09 Mutex */
  89. ACPI_NS_NORMAL, /* 10 Region */
  90. ACPI_NS_NEWSCOPE, /* 11 Power */
  91. ACPI_NS_NEWSCOPE, /* 12 Processor */
  92. ACPI_NS_NEWSCOPE, /* 13 Thermal */
  93. ACPI_NS_NORMAL, /* 14 buffer_field */
  94. ACPI_NS_NORMAL, /* 15 ddb_handle */
  95. ACPI_NS_NORMAL, /* 16 Debug Object */
  96. ACPI_NS_NORMAL, /* 17 def_field */
  97. ACPI_NS_NORMAL, /* 18 bank_field */
  98. ACPI_NS_NORMAL, /* 19 index_field */
  99. ACPI_NS_NORMAL, /* 20 Reference */
  100. ACPI_NS_NORMAL, /* 21 Alias */
  101. ACPI_NS_NORMAL, /* 22 method_alias */
  102. ACPI_NS_NORMAL, /* 23 Notify */
  103. ACPI_NS_NORMAL, /* 24 Address Handler */
  104. ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL, /* 25 Resource Desc */
  105. ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL, /* 26 Resource Field */
  106. ACPI_NS_NEWSCOPE, /* 27 Scope */
  107. ACPI_NS_NORMAL, /* 28 Extra */
  108. ACPI_NS_NORMAL, /* 29 Data */
  109. ACPI_NS_NORMAL /* 30 Invalid */
  110. };
  111. /*******************************************************************************
  112. *
  113. * FUNCTION: acpi_ut_hex_to_ascii_char
  114. *
  115. * PARAMETERS: Integer - Contains the hex digit
  116. * Position - bit position of the digit within the
  117. * integer (multiple of 4)
  118. *
  119. * RETURN: The converted Ascii character
  120. *
  121. * DESCRIPTION: Convert a hex digit to an Ascii character
  122. *
  123. ******************************************************************************/
  124. /* Hex to ASCII conversion table */
  125. static const char acpi_gbl_hex_to_ascii[] = {
  126. '0', '1', '2', '3', '4', '5', '6', '7',
  127. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  128. };
  129. char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
  130. {
  131. return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
  132. }
  133. /*******************************************************************************
  134. *
  135. * FUNCTION: acpi_ut_get_region_name
  136. *
  137. * PARAMETERS: Space ID - ID for the region
  138. *
  139. * RETURN: Decoded region space_id name
  140. *
  141. * DESCRIPTION: Translate a Space ID into a name string (Debug only)
  142. *
  143. ******************************************************************************/
  144. /* Region type decoding */
  145. const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = {
  146. "SystemMemory",
  147. "SystemIO",
  148. "PCI_Config",
  149. "EmbeddedControl",
  150. "SMBus",
  151. "SystemCMOS",
  152. "PCIBARTarget",
  153. "IPMI"
  154. };
  155. char *acpi_ut_get_region_name(u8 space_id)
  156. {
  157. if (space_id >= ACPI_USER_REGION_BEGIN) {
  158. return ("UserDefinedRegion");
  159. } else if (space_id == ACPI_ADR_SPACE_DATA_TABLE) {
  160. return ("DataTable");
  161. } else if (space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
  162. return ("FunctionalFixedHW");
  163. } else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) {
  164. return ("InvalidSpaceId");
  165. }
  166. return (ACPI_CAST_PTR(char, acpi_gbl_region_types[space_id]));
  167. }
  168. /*******************************************************************************
  169. *
  170. * FUNCTION: acpi_ut_get_event_name
  171. *
  172. * PARAMETERS: event_id - Fixed event ID
  173. *
  174. * RETURN: Decoded event ID name
  175. *
  176. * DESCRIPTION: Translate a Event ID into a name string (Debug only)
  177. *
  178. ******************************************************************************/
  179. /* Event type decoding */
  180. static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = {
  181. "PM_Timer",
  182. "GlobalLock",
  183. "PowerButton",
  184. "SleepButton",
  185. "RealTimeClock",
  186. };
  187. char *acpi_ut_get_event_name(u32 event_id)
  188. {
  189. if (event_id > ACPI_EVENT_MAX) {
  190. return ("InvalidEventID");
  191. }
  192. return (ACPI_CAST_PTR(char, acpi_gbl_event_types[event_id]));
  193. }
  194. /*******************************************************************************
  195. *
  196. * FUNCTION: acpi_ut_get_type_name
  197. *
  198. * PARAMETERS: Type - An ACPI object type
  199. *
  200. * RETURN: Decoded ACPI object type name
  201. *
  202. * DESCRIPTION: Translate a Type ID into a name string (Debug only)
  203. *
  204. ******************************************************************************/
  205. /*
  206. * Elements of acpi_gbl_ns_type_names below must match
  207. * one-to-one with values of acpi_object_type
  208. *
  209. * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
  210. * when stored in a table it really means that we have thus far seen no
  211. * evidence to indicate what type is actually going to be stored for this entry.
  212. */
  213. static const char acpi_gbl_bad_type[] = "UNDEFINED";
  214. /* Printable names of the ACPI object types */
  215. static const char *acpi_gbl_ns_type_names[] = {
  216. /* 00 */ "Untyped",
  217. /* 01 */ "Integer",
  218. /* 02 */ "String",
  219. /* 03 */ "Buffer",
  220. /* 04 */ "Package",
  221. /* 05 */ "FieldUnit",
  222. /* 06 */ "Device",
  223. /* 07 */ "Event",
  224. /* 08 */ "Method",
  225. /* 09 */ "Mutex",
  226. /* 10 */ "Region",
  227. /* 11 */ "Power",
  228. /* 12 */ "Processor",
  229. /* 13 */ "Thermal",
  230. /* 14 */ "BufferField",
  231. /* 15 */ "DdbHandle",
  232. /* 16 */ "DebugObject",
  233. /* 17 */ "RegionField",
  234. /* 18 */ "BankField",
  235. /* 19 */ "IndexField",
  236. /* 20 */ "Reference",
  237. /* 21 */ "Alias",
  238. /* 22 */ "MethodAlias",
  239. /* 23 */ "Notify",
  240. /* 24 */ "AddrHandler",
  241. /* 25 */ "ResourceDesc",
  242. /* 26 */ "ResourceFld",
  243. /* 27 */ "Scope",
  244. /* 28 */ "Extra",
  245. /* 29 */ "Data",
  246. /* 30 */ "Invalid"
  247. };
  248. char *acpi_ut_get_type_name(acpi_object_type type)
  249. {
  250. if (type > ACPI_TYPE_INVALID) {
  251. return (ACPI_CAST_PTR(char, acpi_gbl_bad_type));
  252. }
  253. return (ACPI_CAST_PTR(char, acpi_gbl_ns_type_names[type]));
  254. }
  255. char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc)
  256. {
  257. if (!obj_desc) {
  258. return ("[NULL Object Descriptor]");
  259. }
  260. return (acpi_ut_get_type_name(obj_desc->common.type));
  261. }
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_ut_get_node_name
  265. *
  266. * PARAMETERS: Object - A namespace node
  267. *
  268. * RETURN: ASCII name of the node
  269. *
  270. * DESCRIPTION: Validate the node and return the node's ACPI name.
  271. *
  272. ******************************************************************************/
  273. char *acpi_ut_get_node_name(void *object)
  274. {
  275. struct acpi_namespace_node *node = (struct acpi_namespace_node *)object;
  276. /* Must return a string of exactly 4 characters == ACPI_NAME_SIZE */
  277. if (!object) {
  278. return ("NULL");
  279. }
  280. /* Check for Root node */
  281. if ((object == ACPI_ROOT_OBJECT) || (object == acpi_gbl_root_node)) {
  282. return ("\"\\\" ");
  283. }
  284. /* Descriptor must be a namespace node */
  285. if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
  286. return ("####");
  287. }
  288. /*
  289. * Ensure name is valid. The name was validated/repaired when the node
  290. * was created, but make sure it has not been corrupted.
  291. */
  292. acpi_ut_repair_name(node->name.ascii);
  293. /* Return the name */
  294. return (node->name.ascii);
  295. }
  296. /*******************************************************************************
  297. *
  298. * FUNCTION: acpi_ut_get_descriptor_name
  299. *
  300. * PARAMETERS: Object - An ACPI object
  301. *
  302. * RETURN: Decoded name of the descriptor type
  303. *
  304. * DESCRIPTION: Validate object and return the descriptor type
  305. *
  306. ******************************************************************************/
  307. /* Printable names of object descriptor types */
  308. static const char *acpi_gbl_desc_type_names[] = {
  309. /* 00 */ "Not a Descriptor",
  310. /* 01 */ "Cached",
  311. /* 02 */ "State-Generic",
  312. /* 03 */ "State-Update",
  313. /* 04 */ "State-Package",
  314. /* 05 */ "State-Control",
  315. /* 06 */ "State-RootParseScope",
  316. /* 07 */ "State-ParseScope",
  317. /* 08 */ "State-WalkScope",
  318. /* 09 */ "State-Result",
  319. /* 10 */ "State-Notify",
  320. /* 11 */ "State-Thread",
  321. /* 12 */ "Walk",
  322. /* 13 */ "Parser",
  323. /* 14 */ "Operand",
  324. /* 15 */ "Node"
  325. };
  326. char *acpi_ut_get_descriptor_name(void *object)
  327. {
  328. if (!object) {
  329. return ("NULL OBJECT");
  330. }
  331. if (ACPI_GET_DESCRIPTOR_TYPE(object) > ACPI_DESC_TYPE_MAX) {
  332. return ("Not a Descriptor");
  333. }
  334. return (ACPI_CAST_PTR(char,
  335. acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE
  336. (object)]));
  337. }
  338. /*******************************************************************************
  339. *
  340. * FUNCTION: acpi_ut_get_reference_name
  341. *
  342. * PARAMETERS: Object - An ACPI reference object
  343. *
  344. * RETURN: Decoded name of the type of reference
  345. *
  346. * DESCRIPTION: Decode a reference object sub-type to a string.
  347. *
  348. ******************************************************************************/
  349. /* Printable names of reference object sub-types */
  350. static const char *acpi_gbl_ref_class_names[] = {
  351. /* 00 */ "Local",
  352. /* 01 */ "Argument",
  353. /* 02 */ "RefOf",
  354. /* 03 */ "Index",
  355. /* 04 */ "DdbHandle",
  356. /* 05 */ "Named Object",
  357. /* 06 */ "Debug"
  358. };
  359. const char *acpi_ut_get_reference_name(union acpi_operand_object *object)
  360. {
  361. if (!object) {
  362. return ("NULL Object");
  363. }
  364. if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
  365. return ("Not an Operand object");
  366. }
  367. if (object->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
  368. return ("Not a Reference object");
  369. }
  370. if (object->reference.class > ACPI_REFCLASS_MAX) {
  371. return ("Unknown Reference class");
  372. }
  373. return (acpi_gbl_ref_class_names[object->reference.class]);
  374. }
  375. #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
  376. /*
  377. * Strings and procedures used for debug only
  378. */
  379. /*******************************************************************************
  380. *
  381. * FUNCTION: acpi_ut_get_mutex_name
  382. *
  383. * PARAMETERS: mutex_id - The predefined ID for this mutex.
  384. *
  385. * RETURN: Decoded name of the internal mutex
  386. *
  387. * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
  388. *
  389. ******************************************************************************/
  390. /* Names for internal mutex objects, used for debug output */
  391. static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
  392. "ACPI_MTX_Interpreter",
  393. "ACPI_MTX_Namespace",
  394. "ACPI_MTX_Tables",
  395. "ACPI_MTX_Events",
  396. "ACPI_MTX_Caches",
  397. "ACPI_MTX_Memory",
  398. "ACPI_MTX_CommandComplete",
  399. "ACPI_MTX_CommandReady"
  400. };
  401. char *acpi_ut_get_mutex_name(u32 mutex_id)
  402. {
  403. if (mutex_id > ACPI_MAX_MUTEX) {
  404. return ("Invalid Mutex ID");
  405. }
  406. return (acpi_gbl_mutex_names[mutex_id]);
  407. }
  408. /*******************************************************************************
  409. *
  410. * FUNCTION: acpi_ut_get_notify_name
  411. *
  412. * PARAMETERS: notify_value - Value from the Notify() request
  413. *
  414. * RETURN: Decoded name for the notify value
  415. *
  416. * DESCRIPTION: Translate a Notify Value to a notify namestring.
  417. *
  418. ******************************************************************************/
  419. /* Names for Notify() values, used for debug output */
  420. static const char *acpi_gbl_notify_value_names[] = {
  421. "Bus Check",
  422. "Device Check",
  423. "Device Wake",
  424. "Eject Request",
  425. "Device Check Light",
  426. "Frequency Mismatch",
  427. "Bus Mode Mismatch",
  428. "Power Fault",
  429. "Capabilities Check",
  430. "Device PLD Check",
  431. "Reserved",
  432. "System Locality Update"
  433. };
  434. const char *acpi_ut_get_notify_name(u32 notify_value)
  435. {
  436. if (notify_value <= ACPI_NOTIFY_MAX) {
  437. return (acpi_gbl_notify_value_names[notify_value]);
  438. } else if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
  439. return ("Reserved");
  440. } else { /* Greater or equal to 0x80 */
  441. return ("**Device Specific**");
  442. }
  443. }
  444. #endif
  445. /*******************************************************************************
  446. *
  447. * FUNCTION: acpi_ut_valid_object_type
  448. *
  449. * PARAMETERS: Type - Object type to be validated
  450. *
  451. * RETURN: TRUE if valid object type, FALSE otherwise
  452. *
  453. * DESCRIPTION: Validate an object type
  454. *
  455. ******************************************************************************/
  456. u8 acpi_ut_valid_object_type(acpi_object_type type)
  457. {
  458. if (type > ACPI_TYPE_LOCAL_MAX) {
  459. /* Note: Assumes all TYPEs are contiguous (external/local) */
  460. return (FALSE);
  461. }
  462. return (TRUE);
  463. }