dump.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. static void show_devices(struct udevice *dev, int depth, int last_flag)
  11. {
  12. int i, is_last;
  13. struct udevice *child;
  14. /* print the first 11 characters to not break the tree-format. */
  15. printf(" %-10.10s [ %c ] %-10.10s ", dev->uclass->uc_drv->name,
  16. dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
  17. for (i = depth; i >= 0; i--) {
  18. is_last = (last_flag >> i) & 1;
  19. if (i) {
  20. if (is_last)
  21. printf(" ");
  22. else
  23. printf("| ");
  24. } else {
  25. if (is_last)
  26. printf("`-- ");
  27. else
  28. printf("|-- ");
  29. }
  30. }
  31. printf("%s\n", dev->name);
  32. list_for_each_entry(child, &dev->child_head, sibling_node) {
  33. is_last = list_is_last(&child->sibling_node, &dev->child_head);
  34. show_devices(child, depth + 1, (last_flag << 1) | is_last);
  35. }
  36. }
  37. void dm_dump_all(void)
  38. {
  39. struct udevice *root;
  40. root = dm_root();
  41. if (root) {
  42. printf(" Class Probed Driver Name\n");
  43. printf("----------------------------------------\n");
  44. show_devices(root, -1, 0);
  45. }
  46. }
  47. /**
  48. * dm_display_line() - Display information about a single device
  49. *
  50. * Displays a single line of information with an option prefix
  51. *
  52. * @dev: Device to display
  53. */
  54. static void dm_display_line(struct udevice *dev)
  55. {
  56. printf("- %c %s @ %08lx",
  57. dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
  58. dev->name, (ulong)map_to_sysmem(dev));
  59. if (dev->seq != -1 || dev->req_seq != -1)
  60. printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
  61. puts("\n");
  62. }
  63. void dm_dump_uclass(void)
  64. {
  65. struct uclass *uc;
  66. int ret;
  67. int id;
  68. for (id = 0; id < UCLASS_COUNT; id++) {
  69. struct udevice *dev;
  70. ret = uclass_get(id, &uc);
  71. if (ret)
  72. continue;
  73. printf("uclass %d: %s\n", id, uc->uc_drv->name);
  74. if (list_empty(&uc->dev_head))
  75. continue;
  76. list_for_each_entry(dev, &uc->dev_head, uclass_node) {
  77. dm_display_line(dev);
  78. }
  79. puts("\n");
  80. }
  81. }