utdecode.c 15 KB

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