qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	peterx@redhat.com, Shannon Zhao <shannon.zhaosl@gmail.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Eric Auger <eric.auger@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 7/8] pci: Add pci_for_each_device_all()
Date: Thu, 21 Oct 2021 18:42:58 +0800	[thread overview]
Message-ID: <20211021104259.57754-8-peterx@redhat.com> (raw)
In-Reply-To: <20211021104259.57754-1-peterx@redhat.com>

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



  parent reply	other threads:[~2021-10-21 10:51 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 10:42 [PATCH 0/8] pci/iommu: Fail early if vfio-pci detected before vIOMMU Peter Xu
2021-10-21 10:42 ` [PATCH 1/8] pci: Define pci_bus_dev_fn type Peter Xu
2021-10-21 10:53   ` David Hildenbrand
2021-10-21 11:15   ` Eric Auger
2021-10-22  2:16     ` Peter Xu
2021-10-21 11:36   ` Philippe Mathieu-Daudé
2021-10-21 10:42 ` [PATCH 2/8] pci: Export pci_for_each_device_under_bus*() Peter Xu
2021-10-21 10:54   ` David Hildenbrand
2021-10-21 11:32   ` Eric Auger
2021-10-21 11:39   ` Philippe Mathieu-Daudé
2021-10-21 10:42 ` [PATCH 3/8] pci: Use pci_for_each_device_under_bus*() Peter Xu
2021-10-21 10:56   ` David Hildenbrand
2021-10-21 11:34   ` Eric Auger
2021-10-22  2:19     ` Peter Xu
2021-10-21 10:42 ` [PATCH 4/8] pci: Define pci_bus_fn/pci_bus_ret_fn type Peter Xu
2021-10-21 10:57   ` David Hildenbrand
2021-10-21 11:37   ` Eric Auger
2021-10-21 11:44   ` Philippe Mathieu-Daudé
2021-10-21 12:54     ` Philippe Mathieu-Daudé
2021-10-22  2:24       ` Peter Xu
2021-10-21 10:42 ` [PATCH 5/8] pci: Add pci_for_each_root_bus() Peter Xu
2021-10-21 11:00   ` David Hildenbrand
2021-10-21 12:22   ` Eric Auger
2021-10-25 13:16   ` Michael S. Tsirkin
2021-10-28  2:56     ` Peter Xu
2021-10-21 10:42 ` [PATCH 6/8] pci: Use pci_for_each_root_bus() in current code Peter Xu
2021-10-21 11:06   ` David Hildenbrand
2021-10-21 12:28   ` Eric Auger
2021-10-21 10:42 ` Peter Xu [this message]
2021-10-21 10:54   ` [PATCH 7/8] pci: Add pci_for_each_device_all() Michael S. Tsirkin
2021-10-22  2:33     ` Peter Xu
2021-10-22  8:43       ` Michael S. Tsirkin
2021-10-25 12:57         ` Peter Xu
2021-10-25 13:13           ` Michael S. Tsirkin
2021-10-21 10:42 ` [PATCH 8/8] x86-iommu: Fail early if vIOMMU specified after vfio-pci Peter Xu
2021-10-21 10:49   ` Michael S. Tsirkin
2021-10-21 12:38   ` Eric Auger
2021-10-22  2:37     ` Peter Xu
2021-10-21 22:30   ` Alex Williamson
2021-10-22  2:14     ` Peter Xu
2021-10-26 15:11       ` Igor Mammedov
2021-10-26 15:38         ` Alex Williamson
2021-10-27  8:30         ` Peter Xu
2021-10-28  2:30           ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211021104259.57754-8-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shannon.zhaosl@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).