[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 3/3] xen/pci: add discovered PCI device at boot


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Date: Fri, 1 Aug 2025 09:22:43 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=e64OALVPA2DRTruFZiGWQJ7H25VJryTEDwAJlln/x14=; b=SiHWIbr+BAwMUY+XOfyhWOcCMw4SxuUtMtdFKG0JVe4BlayMAbRvfOHHVDAJU+cMapu6zkhOaWNZ4vrkQ+Ea6UyHR4q17+hyJyczvI/0bMnN9M8it4MdXyylOYgrdM6mnPsMTvM5+XzY2uAA/WTzthCpbjlSpGMWFuW+l4MASkzAuGYuXOH7UpJrka+g0oEwDUfujmX4wkASnLIoj1QNlQTWjwngPkWF1UZwqLblb/ihmxEy8VCd8f+xKxCy+ux1GkAIpQhnS+pgOZjQ5uVQTkROxpV6a72dkKaJIObCwxRzOuvZcA/7+t9+mug0lR7lRyD+th1oObUTb41pw+VgTQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nxt0oiV0uEVZqmxLq8xkIOpJF1b4v2sv9ABS1ORdNUX+P7VcC1485jEMYgY+QA1W/glyUIu4Vz7/0pKWO5j1vsKr9MHpMEQEP3UX6SGKqCXi97sDXX3tqw786v0+smqWw7hzY/pyViRmDW2R2R0V9DYwJbTaLRJwDDxLGR8LqqTa7hUFk9yVC0ZmxRIVBb62WdI/65phDzdgB51QRrvJLSsFXWHPGoHokLEKysVZtUWeY6pEcU2xS7V+UHTA0NdhvZr0fe1GYrlVoRmlMC036rWbGM89MSJu29fQuFQZSPiz5od0+XjBIFj8z4zND4pauGrRGcnXZwPhBcFpqtXgbg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Luca Fancellu <luca.fancellu@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Delivery-date: Fri, 01 Aug 2025 09:22:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcAsXVA3qngHqyPEewy8MzwqQRRg==
  • Thread-topic: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot

From: Luca Fancellu <luca.fancellu@xxxxxxx>

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.fancellu@xxxxxxx>
Signed-off-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>
---
(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



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.