utdecode.c 15 KB

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