dump.c 4.0 KB

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