utdecode.c 15 KB

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