1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (c) 2013 Google, Inc 4 */ 5 6 #include <common.h> 7 #include <dm/device.h> 8 #include <dm/ofnode.h> 9 #include <dm/read.h> 10 #include <dm/util.h> 11 #include <linux/libfdt.h> 12 #include <vsprintf.h> 13 list_count_items(struct list_head * head)14int list_count_items(struct list_head *head) 15 { 16 struct list_head *node; 17 int count = 0; 18 19 list_for_each(node, head) 20 count++; 21 22 return count; 23 } 24 25 #if CONFIG_IS_ENABLED(OF_REAL) pci_get_devfn(struct udevice * dev)26int pci_get_devfn(struct udevice *dev) 27 { 28 struct fdt_pci_addr addr; 29 int ret; 30 31 /* Extract the devfn from fdt_pci_addr */ 32 ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, 33 "reg", &addr); 34 if (ret) { 35 if (ret != -ENOENT) 36 return -EINVAL; 37 } 38 39 return addr.phys_hi & 0xff00; 40 } 41 #endif 42