utdecode.c 17 KB

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