util.c 726 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. int list_count_items(struct list_head *head)
  13. {
  14. struct list_head *node;
  15. int count = 0;
  16. list_for_each(node, head)
  17. count++;
  18. return count;
  19. }
  20. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  21. int pci_get_devfn(struct udevice *dev)
  22. {
  23. struct fdt_pci_addr addr;
  24. int ret;
  25. /* Extract the devfn from fdt_pci_addr */
  26. ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
  27. "reg", &addr);
  28. if (ret) {
  29. if (ret != -ENOENT)
  30. return -EINVAL;
  31. }
  32. return addr.phys_hi & 0xff00;
  33. }
  34. #endif