rsdump.c 14 KB

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