utdecode.c 15 KB

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