rsdump.c 14 KB

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