+static uint16_t
+make_pci_device_path(void *dest, uint8_t bus, uint8_t device, uint8_t function)
+{
+ struct device *dev;
+ struct pci_access *pacc;
+ struct list_head *pos, *n;
+ LIST_HEAD(pci_parent_list);
+ char *p = dest;
+
+ pacc = pci_alloc();
+ if (!pacc)
+ return 0;
+
+ pci_init(pacc);
+ pci_scan_bus(pacc);
+
+ do {
+ dev = find_parent(pacc, bus);
+ if (dev) {
+ list_add(&pci_parent_list, &dev->node);
+ bus = dev->pci_dev->bus;
+ }
+ } while (dev && bus);
+
+
+ list_for_each_safe(pos, n, &pci_parent_list) {
+ dev = list_entry(pos, struct device, node);
+ p += make_one_pci_device_path(p,
+ dev->pci_dev->dev,
+ dev->pci_dev->func);
+ list_del(&dev->node);
+ free(dev);
+ }
+
+ p += make_one_pci_device_path(p, device, function);
+
+ pci_cleanup(pacc);
+
+ return ((void *)p - dest);
+}
+