util.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm/device.h>
  7. #include <dm/ofnode.h>
  8. #include <dm/read.h>
  9. #include <dm/util.h>
  10. #include <linux/libfdt.h>
  11. #include <vsprintf.h>
  12. #ifdef CONFIG_DM_WARN
  13. void dm_warn(const char *fmt, ...)
  14. {
  15. va_list args;
  16. va_start(args, fmt);
  17. vprintf(fmt, args);
  18. va_end(args);
  19. }
  20. #endif
  21. int list_count_items(struct list_head *head)
  22. {
  23. struct list_head *node;
  24. int count = 0;
  25. list_for_each(node, head)
  26. count++;
  27. return count;
  28. }
  29. #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
  30. bool dm_ofnode_pre_reloc(ofnode node)
  31. {
  32. #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD)
  33. /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass
  34. * had property dm-pre-reloc or u-boot,dm-spl/tpl.
  35. * They are removed in final dtb (fdtgrep 2nd pass)
  36. */
  37. return true;
  38. #else
  39. if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
  40. return true;
  41. if (ofnode_read_bool(node, "u-boot,dm-pre-proper"))
  42. return true;
  43. /*
  44. * In regular builds individual spl and tpl handling both
  45. * count as handled pre-relocation for later second init.
  46. */
  47. if (ofnode_read_bool(node, "u-boot,dm-spl") ||
  48. ofnode_read_bool(node, "u-boot,dm-tpl"))
  49. return true;
  50. return false;
  51. #endif
  52. }
  53. #endif
  54. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  55. int pci_get_devfn(struct udevice *dev)
  56. {
  57. struct fdt_pci_addr addr;
  58. int ret;
  59. /* Extract the devfn from fdt_pci_addr */
  60. ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
  61. "reg", &addr);
  62. if (ret) {
  63. if (ret != -ENOENT)
  64. return -EINVAL;
  65. }
  66. return addr.phys_hi & 0xff00;
  67. }
  68. #endif