util.c 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #if CONFIG_IS_ENABLED(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_PLATDATA)
  30. int pci_get_devfn(struct udevice *dev)
  31. {
  32. struct fdt_pci_addr addr;
  33. int ret;
  34. /* Extract the devfn from fdt_pci_addr */
  35. ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
  36. "reg", &addr);
  37. if (ret) {
  38. if (ret != -ENOENT)
  39. return -EINVAL;
  40. }
  41. return addr.phys_hi & 0xff00;
  42. }
  43. #endif