dump.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <mapmem.h>
  8. #include <dm/root.h>
  9. #include <dm/util.h>
  10. #include <dm/uclass-internal.h>
  11. static void show_devices(struct udevice *dev, int depth, int last_flag)
  12. {
  13. int i, is_last;
  14. struct udevice *child;
  15. /* print the first 20 characters to not break the tree-format. */
  16. printf(" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
  17. dev_get_uclass_index(dev, NULL),
  18. dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
  19. for (i = depth; i >= 0; i--) {
  20. is_last = (last_flag >> i) & 1;
  21. if (i) {
  22. if (is_last)
  23. printf(" ");
  24. else
  25. printf("| ");
  26. } else {
  27. if (is_last)
  28. printf("`-- ");
  29. else
  30. printf("|-- ");
  31. }
  32. }
  33. printf("%s\n", dev->name);
  34. list_for_each_entry(child, &dev->child_head, sibling_node) {
  35. is_last = list_is_last(&child->sibling_node, &dev->child_head);
  36. show_devices(child, depth + 1, (last_flag << 1) | is_last);
  37. }
  38. }
  39. void dm_dump_all(void)
  40. {
  41. struct udevice *root;
  42. root = dm_root();
  43. if (root) {
  44. printf(" Class Index Probed Driver Name\n");
  45. printf("-----------------------------------------------------------\n");
  46. show_devices(root, -1, 0);
  47. }
  48. }
  49. /**
  50. * dm_display_line() - Display information about a single device
  51. *
  52. * Displays a single line of information with an option prefix
  53. *
  54. * @dev: Device to display
  55. */
  56. static void dm_display_line(struct udevice *dev, int index)
  57. {
  58. printf("%-3i %c %s @ %08lx", index,
  59. dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
  60. dev->name, (ulong)map_to_sysmem(dev));
  61. if (dev_seq(dev) != -1 || dev->req_seq != -1)
  62. printf(", seq %d, (req %d)", dev_seq(dev), dev->req_seq);
  63. puts("\n");
  64. }
  65. void dm_dump_uclass(void)
  66. {
  67. struct uclass *uc;
  68. int ret;
  69. int id;
  70. for (id = 0; id < UCLASS_COUNT; id++) {
  71. struct udevice *dev;
  72. int i = 0;
  73. ret = uclass_get(id, &uc);
  74. if (ret)
  75. continue;
  76. printf("uclass %d: %s\n", id, uc->uc_drv->name);
  77. if (list_empty(&uc->dev_head))
  78. continue;
  79. uclass_foreach_dev(dev, uc) {
  80. dm_display_line(dev, i);
  81. i++;
  82. }
  83. puts("\n");
  84. }
  85. }
  86. void dm_dump_driver_compat(void)
  87. {
  88. struct driver *d = ll_entry_start(struct driver, driver);
  89. const int n_ents = ll_entry_count(struct driver, driver);
  90. struct driver *entry;
  91. const struct udevice_id *match;
  92. puts("Driver Compatible\n");
  93. puts("--------------------------------\n");
  94. for (entry = d; entry < d + n_ents; entry++) {
  95. match = entry->of_match;
  96. printf("%-20.20s", entry->name);
  97. if (match) {
  98. printf(" %s", match->compatible);
  99. match++;
  100. }
  101. printf("\n");
  102. for (; match && match->compatible; match++)
  103. printf("%-20.20s %s\n", "", match->compatible);
  104. }
  105. }
  106. void dm_dump_drivers(void)
  107. {
  108. struct driver *d = ll_entry_start(struct driver, driver);
  109. const int n_ents = ll_entry_count(struct driver, driver);
  110. struct driver *entry;
  111. struct udevice *udev;
  112. struct uclass *uc;
  113. int i;
  114. puts("Driver uid uclass Devices\n");
  115. puts("----------------------------------------------------------\n");
  116. for (entry = d; entry < d + n_ents; entry++) {
  117. uclass_get(entry->id, &uc);
  118. printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
  119. uc ? uc->uc_drv->name : "<no uclass>");
  120. if (!uc) {
  121. puts("\n");
  122. continue;
  123. }
  124. i = 0;
  125. uclass_foreach_dev(udev, uc) {
  126. if (udev->driver != entry)
  127. continue;
  128. if (i)
  129. printf("%-51.51s", "");
  130. printf("%-25.25s\n", udev->name);
  131. i++;
  132. }
  133. if (!i)
  134. puts("<none>\n");
  135. }
  136. }
  137. void dm_dump_static_driver_info(void)
  138. {
  139. struct driver_info *drv = ll_entry_start(struct driver_info,
  140. driver_info);
  141. const int n_ents = ll_entry_count(struct driver_info, driver_info);
  142. struct driver_info *entry;
  143. puts("Driver Address\n");
  144. puts("---------------------------------\n");
  145. for (entry = drv; entry != drv + n_ents; entry++) {
  146. printf("%-25.25s @%08lx\n", entry->name,
  147. (ulong)map_to_sysmem(entry->plat));
  148. }
  149. }