[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/8] pci: Add pci_for_each_device_all()
From: |
Peter Xu |
Subject: |
[PATCH 7/8] pci: Add pci_for_each_device_all() |
Date: |
Thu, 21 Oct 2021 18:42:58 +0800 |
With all the prepared infrastructures, we can easily add one helper now to loop
over all the existing PCI devices across the whole system.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
hw/pci/pci.c | 25 +++++++++++++++++++++++++
include/hw/pci/pci.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 1623bc9099..5c970f0727 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2124,6 +2124,31 @@ void pci_for_each_root_bus(pci_bus_fn fn, void *opaque)
object_child_foreach_recursive(object_get_root(), pci_find_root_bus,
&args);
}
+typedef struct {
+ pci_bus_dev_fn fn;
+ void *opaque;
+} pci_bus_dev_args;
+
+static void pci_single_bus_hook(PCIBus *bus, void *opaque)
+{
+ pci_bus_dev_args *args = opaque;
+
+ pci_for_each_device_under_bus(bus, args->fn, args->opaque);
+}
+
+static void pci_root_bus_hook(PCIBus *bus, void *opaque)
+{
+ assert(pci_bus_is_root(bus));
+ pci_for_each_bus(bus, pci_single_bus_hook, opaque);
+}
+
+void pci_for_each_device_all(pci_bus_dev_fn fn, void *opaque)
+{
+ pci_bus_dev_args args = { .fn = fn, .opaque = opaque };
+
+ pci_for_each_root_bus(pci_root_bus_hook, &args);
+}
+
PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
{
bus = pci_find_bus_nr(bus, bus_num);
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 9e490d8969..1a862d1903 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -476,6 +476,8 @@ void pci_for_each_bus_depth_first(PCIBus *bus,
pci_bus_ret_fn begin,
pci_bus_fn end, void *parent_state);
/* Call `fn' for each pci root bus on the system */
void pci_for_each_root_bus(pci_bus_fn fn, void *opaque);
+/* Call 'fn' for each pci device on the system */
+void pci_for_each_device_all(pci_bus_dev_fn fn, void *opaque);
PCIDevice *pci_get_function_0(PCIDevice *pci_dev);
/* Use this wrapper when specific scan order is not required. */
--
2.32.0
- Re: [PATCH 4/8] pci: Define pci_bus_fn/pci_bus_ret_fn type, (continued)
[PATCH 5/8] pci: Add pci_for_each_root_bus(), Peter Xu, 2021/10/21
[PATCH 6/8] pci: Use pci_for_each_root_bus() in current code, Peter Xu, 2021/10/21
[PATCH 7/8] pci: Add pci_for_each_device_all(),
Peter Xu <=
[PATCH 8/8] x86-iommu: Fail early if vIOMMU specified after vfio-pci, Peter Xu, 2021/10/21