From: Luca Fancellu <luca.fance...@arm.com>

Create add_discovered_pci_devices function that calls pci_device_add
on every PCI device discovered.
The devices will be added to dom_io so that they can be assigned
later to other domains.

Signed-off-by: Luca Fancellu <luca.fance...@arm.com>
Signed-off-by: Mykyta Poturai <mykyta_potu...@epam.com>
---
(cherry picked from commit eff51e50021b75f5a50533f7de681b2ce044f5bd from
 the downstream branch poc/pci-passthrough from
 https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git)
---
 xen/arch/arm/pci/pci.c        |  1 +
 xen/drivers/passthrough/pci.c | 28 ++++++++++++++++++++++++++++
 xen/include/xen/pci.h         |  1 +
 3 files changed, 30 insertions(+)

diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c
index eea264db0e..b2426878ee 100644
--- a/xen/arch/arm/pci/pci.c
+++ b/xen/arch/arm/pci/pci.c
@@ -123,6 +123,7 @@ static int __init pci_init(void)
         if ( ret < 0 )
             return ret;
 
+        add_discovered_pci_devices();
 #ifdef DEBUG
         dump_pci_devices('c');
 #endif
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 49a39d69db..d6f1c78701 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)
     return ret;
 }
 
+static int __init _add_discovered_pci_devices(struct pci_seg *pseg, void *arg)
+{
+    struct pci_dev *pdev;
+    int ret = 0;
+
+    list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
+    {
+        ret = pci_add_device(dom_io, pdev->seg, pdev->bus, pdev->devfn, NULL,
+                             NUMA_NO_NODE);
+        if ( ret < 0 )
+        {
+            printk(XENLOG_ERR
+                   "%pp: Failure adding the discovered pci device (Error 
%d)\n",
+                   &pdev->sbdf, ret);
+            break;
+        }
+    }
+
+    return ret;
+}
+
+void __init add_discovered_pci_devices(void)
+{
+    pcidevs_lock();
+    pci_segments_iterate(_add_discovered_pci_devices, NULL);
+    pcidevs_unlock();
+}
+
 struct setup_hwdom {
     struct domain *d;
     int (*handler)(uint8_t devfn, struct pci_dev *pdev);
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 77a44aea70..81c0c23604 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -217,6 +217,7 @@ static always_inline bool pcidevs_trylock(void)
 bool pci_known_segment(u16 seg);
 bool pci_device_detect(u16 seg, u8 bus, u8 dev, u8 func);
 int scan_pci_devices(void);
+void add_discovered_pci_devices(void);
 void dump_pci_devices(unsigned char ch);
 enum pdev_type pdev_type(u16 seg, u8 bus, u8 devfn);
 int find_upstream_bridge(u16 seg, u8 *bus, u8 *devfn, u8 *secbus);
-- 
2.34.1

Reply via email to