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

[PATCH 2/3] pci: introduce a function to get PCIDevice


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, "Edgar E . Iglesias" <edgar.iglesias@xxxxxxxxx>, "Michael S . Tsirkin" <mst@xxxxxxxxxx>, Marcel Apfelbaum <marcel.apfelbaum@xxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Julia Zhang <julia.zhang@xxxxxxx>
  • Date: Sat, 7 Dec 2024 18:55:38 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=YaHGUZgM04HQD0VdrKLIvWNrpeh66J4OqCg0Rby1C6g=; b=md9oZJFpqB0rYp5yKsqmkRnaXGuEwySykTGCesIzeQBVQ8BiZaukS3N56vzpV2Zq+9+Blq7ENHw0zLy+/NwqeHtEbOr8TmQY+0HMtAPU39Krs2uA9iPIbuuXbNNHKKN9Gvi8gIukKF2BnYrihZ2WJqxBVWV2zUAz0jLqD8J4zTvaJFJL9VW1YuOtNs//DIs5Hh1gVgg28jByfxfoWq5F2daxOHfs2bitzGkYVFx94rkuNyXA7uXaOfYa2nB4kY0rm3Xude90E8h5xRFBZ16/VztsVj4s7UFu2Qs5XZw36OcGUuKQsslRaqUVfJvo7Dvgf0vfZMKu3DjatNfhwoXXDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FDSTIwzP2hCfkSDlD3jasev3OQMVtkVjWW9QvByL0AmhQjlT0EEfCPACwktnvZGYbST34jlXYK+o5SSIrmMOOpokXF1u6+IPZlwp1A2XFw3z8B4HzuMggj1kaOTH69DbTEV1kgghlxgqSmsU5dzEww3xof1xefhDX0GFz91tibC7ENLeqElrRtKsFed/VF9di6Tnean6b2M4o9PWyFay/uEkHXhti/TCp8O/mrtoU4LtaQf3zzeeDG5+8KDrgJVZP93E1ESRsJY9g6WWGWJjERmHb3hlysEEbZkkomFRM/xFxZnCPnDe3oN9H+Ugl9gh6cNYIgZqkGNMKLWi86YPoQ==
  • Cc: Alex Deucher <alexander.deucher@xxxxxxx>, Christian König <christian.koenig@xxxxxxx>, "Xenia Ragiadakou" <burzalodowa@xxxxxxxxx>, Julia Zhang <julia.zhang@xxxxxxx>, "Chen Jiqian" <Jiqian.Chen@xxxxxxx>, Huang Rui <ray.huang@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Zhu Lingshan <Lingshan.Zhu@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, <qemu-devel@xxxxxxxxxx>
  • Delivery-date: Sat, 07 Dec 2024 10:57:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Introduce a helper function to get PCIDevice from qdev pci notation.

Signed-off-by: Julia Zhang <julia.zhang@xxxxxxx>
---
 hw/pci/pci.c         | 22 ++++++++++++++++++++++
 include/hw/pci/pci.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 1416ae202c..95806ead4f 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2617,6 +2617,28 @@ static int pci_qdev_find_recursive(PCIBus *bus,
     return -EINVAL;
 }
 
+int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot, uint32_t 
virt_func,
+                       PCIDevice **pci_dev)
+{
+    PCIHostState *host_bridge;
+    PCIDevice *d;
+    int devfn;
+    int rc = -ENODEV;
+
+    QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
+        for(devfn = 0; devfn < ARRAY_SIZE(host_bridge->bus->devices); devfn++) 
{
+           d = host_bridge->bus->devices[devfn];
+           if (d && d->devfn == PCI_DEVFN(virt_slot, virt_func) &&
+               pci_bus_num(pci_get_bus(d)) == virt_bus) {
+               *pci_dev = d;
+               rc = 0;
+               break;
+           }
+       }
+    }
+    return rc;
+}
+
 int pci_qdev_find_device(const char *id, PCIDevice **pdev)
 {
     PCIHostState *host_bridge;
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 463d9984b3..1b493ab95e 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -366,6 +366,8 @@ const char *pci_root_bus_path(PCIDevice *dev);
 bool pci_bus_bypass_iommu(PCIBus *bus);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
+int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot,
+                       uint32_t virt_func, PCIDevice **pci_dev);
 void pci_bus_get_w64_range(PCIBus *bus, Range *range);
 
 void pci_device_deassert_intx(PCIDevice *dev);
-- 
2.34.1




 


Rackspace

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