rsdump.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: rsdump - AML debugger support for resource structures.
  5. *
  6. ******************************************************************************/
  7. #include <acpi/acpi.h>
  8. #include "accommon.h"
  9. #include "acresrc.h"
  10. #define _COMPONENT ACPI_RESOURCES
  11. ACPI_MODULE_NAME("rsdump")
  12. /*
  13. * All functions in this module are used by the AML Debugger only
  14. */
  15. /* Local prototypes */
  16. static void acpi_rs_out_string(const char *title, const char *value);
  17. static void acpi_rs_out_integer8(const char *title, u8 value);
  18. static void acpi_rs_out_integer16(const char *title, u16 value);
  19. static void acpi_rs_out_integer32(const char *title, u32 value);
  20. static void acpi_rs_out_integer64(const char *title, u64 value);
  21. static void acpi_rs_out_title(const char *title);
  22. static void acpi_rs_dump_byte_list(u16 length, u8 *data);
  23. static void acpi_rs_dump_word_list(u16 length, u16 *data);
  24. static void acpi_rs_dump_dword_list(u8 length, u32 *data);
  25. static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
  26. static void
  27. acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
  28. static void
  29. acpi_rs_dump_resource_label(char *title,
  30. struct acpi_resource_label *resource_label);
  31. static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
  32. static void
  33. acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
  34. /*******************************************************************************
  35. *
  36. * FUNCTION: acpi_rs_dump_resource_list
  37. *
  38. * PARAMETERS: resource_list - Pointer to a resource descriptor list
  39. *
  40. * RETURN: None
  41. *
  42. * DESCRIPTION: Dispatches the structure to the correct dump routine.
  43. *
  44. ******************************************************************************/
  45. void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
  46. {
  47. u32 count = 0;
  48. u32 type;
  49. ACPI_FUNCTION_ENTRY();
  50. /* Check if debug output enabled */
  51. if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
  52. return;
  53. }
  54. /* Walk list and dump all resource descriptors (END_TAG terminates) */
  55. do {
  56. acpi_os_printf("\n[%02X] ", count);
  57. count++;
  58. /* Validate Type before dispatch */
  59. type = resource_list->type;
  60. if (type > ACPI_RESOURCE_TYPE_MAX) {
  61. acpi_os_printf
  62. ("Invalid descriptor type (%X) in resource list\n",
  63. resource_list->type);
  64. return;
  65. }
  66. /* Sanity check the length. It must not be zero, or we loop forever */
  67. if (!resource_list->length) {
  68. acpi_os_printf
  69. ("Invalid zero length descriptor in resource list\n");
  70. return;
  71. }
  72. /* Dump the resource descriptor */
  73. if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
  74. acpi_rs_dump_descriptor(&resource_list->data,
  75. acpi_gbl_dump_serial_bus_dispatch
  76. [resource_list->data.
  77. common_serial_bus.type]);
  78. } else {
  79. acpi_rs_dump_descriptor(&resource_list->data,
  80. acpi_gbl_dump_resource_dispatch
  81. [type]);
  82. }
  83. /* Point to the next resource structure */
  84. resource_list = ACPI_NEXT_RESOURCE(resource_list);
  85. /* Exit when END_TAG descriptor is reached */
  86. } while (type != ACPI_RESOURCE_TYPE_END_TAG);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_rs_dump_irq_list
  91. *
  92. * PARAMETERS: route_table - Pointer to the routing table to dump.
  93. *
  94. * RETURN: None
  95. *
  96. * DESCRIPTION: Print IRQ routing table
  97. *
  98. ******************************************************************************/
  99. void acpi_rs_dump_irq_list(u8 *route_table)
  100. {
  101. struct acpi_pci_routing_table *prt_element;
  102. u8 count;
  103. ACPI_FUNCTION_ENTRY();
  104. /* Check if debug output enabled */
  105. if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
  106. return;
  107. }
  108. prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
  109. /* Dump all table elements, Exit on zero length element */
  110. for (count = 0; prt_element->length; count++) {
  111. acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
  112. count);
  113. acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
  114. prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
  115. prt_element, prt_element->length);
  116. }
  117. }
  118. /*******************************************************************************
  119. *
  120. * FUNCTION: acpi_rs_dump_descriptor
  121. *
  122. * PARAMETERS: resource - Buffer containing the resource
  123. * table - Table entry to decode the resource
  124. *
  125. * RETURN: None
  126. *
  127. * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
  128. *
  129. ******************************************************************************/
  130. static void
  131. acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
  132. {
  133. u8 *target = NULL;
  134. u8 *previous_target;
  135. const char *name;
  136. u8 count;
  137. /* First table entry must contain the table length (# of table entries) */
  138. count = table->offset;
  139. while (count) {
  140. previous_target = target;
  141. target = ACPI_ADD_PTR(u8, resource, table->offset);
  142. name = table->name;
  143. switch (table->opcode) {
  144. case ACPI_RSD_TITLE:
  145. /*
  146. * Optional resource title
  147. */
  148. if (table->name) {
  149. acpi_os_printf("%s Resource\n", name);
  150. }
  151. break;
  152. /* Strings */
  153. case ACPI_RSD_LITERAL:
  154. acpi_rs_out_string(name,
  155. ACPI_CAST_PTR(char, table->pointer));
  156. break;
  157. case ACPI_RSD_STRING:
  158. acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
  159. break;
  160. /* Data items, 8/16/32/64 bit */
  161. case ACPI_RSD_UINT8:
  162. if (table->pointer) {
  163. acpi_rs_out_string(name,
  164. table->pointer[*target]);
  165. } else {
  166. acpi_rs_out_integer8(name, ACPI_GET8(target));
  167. }
  168. break;
  169. case ACPI_RSD_UINT16:
  170. acpi_rs_out_integer16(name, ACPI_GET16(target));
  171. break;
  172. case ACPI_RSD_UINT32:
  173. acpi_rs_out_integer32(name, ACPI_GET32(target));
  174. break;
  175. case ACPI_RSD_UINT64:
  176. acpi_rs_out_integer64(name, ACPI_GET64(target));
  177. break;
  178. /* Flags: 1-bit and 2-bit flags supported */
  179. case ACPI_RSD_1BITFLAG:
  180. acpi_rs_out_string(name,
  181. table->pointer[*target & 0x01]);
  182. break;
  183. case ACPI_RSD_2BITFLAG:
  184. acpi_rs_out_string(name,
  185. table->pointer[*target & 0x03]);
  186. break;
  187. case ACPI_RSD_3BITFLAG:
  188. acpi_rs_out_string(name,
  189. table->pointer[*target & 0x07]);
  190. break;
  191. case ACPI_RSD_SHORTLIST:
  192. /*
  193. * Short byte list (single line output) for DMA and IRQ resources
  194. * Note: The list length is obtained from the previous table entry
  195. */
  196. if (previous_target) {
  197. acpi_rs_out_title(name);
  198. acpi_rs_dump_short_byte_list(*previous_target,
  199. target);
  200. }
  201. break;
  202. case ACPI_RSD_SHORTLISTX:
  203. /*
  204. * Short byte list (single line output) for GPIO vendor data
  205. * Note: The list length is obtained from the previous table entry
  206. */
  207. if (previous_target) {
  208. acpi_rs_out_title(name);
  209. acpi_rs_dump_short_byte_list(*previous_target,
  210. *
  211. (ACPI_CAST_INDIRECT_PTR
  212. (u8, target)));
  213. }
  214. break;
  215. case ACPI_RSD_LONGLIST:
  216. /*
  217. * Long byte list for Vendor resource data
  218. * Note: The list length is obtained from the previous table entry
  219. */
  220. if (previous_target) {
  221. acpi_rs_dump_byte_list(ACPI_GET16
  222. (previous_target),
  223. target);
  224. }
  225. break;
  226. case ACPI_RSD_DWORDLIST:
  227. /*
  228. * Dword list for Extended Interrupt resources
  229. * Note: The list length is obtained from the previous table entry
  230. */
  231. if (previous_target) {
  232. acpi_rs_dump_dword_list(*previous_target,
  233. ACPI_CAST_PTR(u32,
  234. target));
  235. }
  236. break;
  237. case ACPI_RSD_WORDLIST:
  238. /*
  239. * Word list for GPIO Pin Table
  240. * Note: The list length is obtained from the previous table entry
  241. */
  242. if (previous_target) {
  243. acpi_rs_dump_word_list(*previous_target,
  244. *(ACPI_CAST_INDIRECT_PTR
  245. (u16, target)));
  246. }
  247. break;
  248. case ACPI_RSD_ADDRESS:
  249. /*
  250. * Common flags for all Address resources
  251. */
  252. acpi_rs_dump_address_common(ACPI_CAST_PTR
  253. (union acpi_resource_data,
  254. target));
  255. break;
  256. case ACPI_RSD_SOURCE:
  257. /*
  258. * Optional resource_source for Address resources
  259. */
  260. acpi_rs_dump_resource_source(ACPI_CAST_PTR
  261. (struct
  262. acpi_resource_source,
  263. target));
  264. break;
  265. case ACPI_RSD_LABEL:
  266. /*
  267. * resource_label
  268. */
  269. acpi_rs_dump_resource_label("Resource Label",
  270. ACPI_CAST_PTR(struct
  271. acpi_resource_label,
  272. target));
  273. break;
  274. case ACPI_RSD_SOURCE_LABEL:
  275. /*
  276. * resource_source_label
  277. */
  278. acpi_rs_dump_resource_label("Resource Source Label",
  279. ACPI_CAST_PTR(struct
  280. acpi_resource_label,
  281. target));
  282. break;
  283. default:
  284. acpi_os_printf("**** Invalid table opcode [%X] ****\n",
  285. table->opcode);
  286. return;
  287. }
  288. table++;
  289. count--;
  290. }
  291. }
  292. /*******************************************************************************
  293. *
  294. * FUNCTION: acpi_rs_dump_resource_source
  295. *
  296. * PARAMETERS: resource_source - Pointer to a Resource Source struct
  297. *
  298. * RETURN: None
  299. *
  300. * DESCRIPTION: Common routine for dumping the optional resource_source and the
  301. * corresponding resource_source_index.
  302. *
  303. ******************************************************************************/
  304. static void
  305. acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
  306. {
  307. ACPI_FUNCTION_ENTRY();
  308. if (resource_source->index == 0xFF) {
  309. return;
  310. }
  311. acpi_rs_out_integer8("Resource Source Index", resource_source->index);
  312. acpi_rs_out_string("Resource Source",
  313. resource_source->string_ptr ?
  314. resource_source->string_ptr : "[Not Specified]");
  315. }
  316. /*******************************************************************************
  317. *
  318. * FUNCTION: acpi_rs_dump_resource_label
  319. *
  320. * PARAMETERS: title - Title of the dumped resource field
  321. * resource_label - Pointer to a Resource Label struct
  322. *
  323. * RETURN: None
  324. *
  325. * DESCRIPTION: Common routine for dumping the resource_label
  326. *
  327. ******************************************************************************/
  328. static void
  329. acpi_rs_dump_resource_label(char *title,
  330. struct acpi_resource_label *resource_label)
  331. {
  332. ACPI_FUNCTION_ENTRY();
  333. acpi_rs_out_string(title,
  334. resource_label->string_ptr ?
  335. resource_label->string_ptr : "[Not Specified]");
  336. }
  337. /*******************************************************************************
  338. *
  339. * FUNCTION: acpi_rs_dump_address_common
  340. *
  341. * PARAMETERS: resource - Pointer to an internal resource descriptor
  342. *
  343. * RETURN: None
  344. *
  345. * DESCRIPTION: Dump the fields that are common to all Address resource
  346. * descriptors
  347. *
  348. ******************************************************************************/
  349. static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
  350. {
  351. ACPI_FUNCTION_ENTRY();
  352. /* Decode the type-specific flags */
  353. switch (resource->address.resource_type) {
  354. case ACPI_MEMORY_RANGE:
  355. acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
  356. break;
  357. case ACPI_IO_RANGE:
  358. acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
  359. break;
  360. case ACPI_BUS_NUMBER_RANGE:
  361. acpi_rs_out_string("Resource Type", "Bus Number Range");
  362. break;
  363. default:
  364. acpi_rs_out_integer8("Resource Type",
  365. (u8) resource->address.resource_type);
  366. break;
  367. }
  368. /* Decode the general flags */
  369. acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
  370. }
  371. /*******************************************************************************
  372. *
  373. * FUNCTION: acpi_rs_out*
  374. *
  375. * PARAMETERS: title - Name of the resource field
  376. * value - Value of the resource field
  377. *
  378. * RETURN: None
  379. *
  380. * DESCRIPTION: Miscellaneous helper functions to consistently format the
  381. * output of the resource dump routines
  382. *
  383. ******************************************************************************/
  384. static void acpi_rs_out_string(const char *title, const char *value)
  385. {
  386. acpi_os_printf("%27s : %s", title, value);
  387. if (!*value) {
  388. acpi_os_printf("[NULL NAMESTRING]");
  389. }
  390. acpi_os_printf("\n");
  391. }
  392. static void acpi_rs_out_integer8(const char *title, u8 value)
  393. {
  394. acpi_os_printf("%27s : %2.2X\n", title, value);
  395. }
  396. static void acpi_rs_out_integer16(const char *title, u16 value)
  397. {
  398. acpi_os_printf("%27s : %4.4X\n", title, value);
  399. }
  400. static void acpi_rs_out_integer32(const char *title, u32 value)
  401. {
  402. acpi_os_printf("%27s : %8.8X\n", title, value);
  403. }
  404. static void acpi_rs_out_integer64(const char *title, u64 value)
  405. {
  406. acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
  407. }
  408. static void acpi_rs_out_title(const char *title)
  409. {
  410. acpi_os_printf("%27s : ", title);
  411. }
  412. /*******************************************************************************
  413. *
  414. * FUNCTION: acpi_rs_dump*List
  415. *
  416. * PARAMETERS: length - Number of elements in the list
  417. * data - Start of the list
  418. *
  419. * RETURN: None
  420. *
  421. * DESCRIPTION: Miscellaneous functions to dump lists of raw data
  422. *
  423. ******************************************************************************/
  424. static void acpi_rs_dump_byte_list(u16 length, u8 * data)
  425. {
  426. u16 i;
  427. for (i = 0; i < length; i++) {
  428. acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
  429. }
  430. }
  431. static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
  432. {
  433. u8 i;
  434. for (i = 0; i < length; i++) {
  435. acpi_os_printf("%X ", data[i]);
  436. }
  437. acpi_os_printf("\n");
  438. }
  439. static void acpi_rs_dump_dword_list(u8 length, u32 * data)
  440. {
  441. u8 i;
  442. for (i = 0; i < length; i++) {
  443. acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
  444. }
  445. }
  446. static void acpi_rs_dump_word_list(u16 length, u16 *data)
  447. {
  448. u16 i;
  449. for (i = 0; i < length; i++) {
  450. acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
  451. }
  452. }