[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 5/8] pci: Add pci_for_each_root_bus()
From: |
David Hildenbrand |
Subject: |
Re: [PATCH 5/8] pci: Add pci_for_each_root_bus() |
Date: |
Thu, 21 Oct 2021 13:00:19 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 |
On 21.10.21 12:42, Peter Xu wrote:
> Add a helper to loop over each root bus of the system, either the default root
> bus or extended buses like pxb-pcie.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> hw/pci/pci.c | 26 ++++++++++++++++++++++++++
> include/hw/pci/pci.h | 2 ++
> 2 files changed, 28 insertions(+)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 4a84e478ce..1623bc9099 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -2097,6 +2097,32 @@ void pci_for_each_bus_depth_first(PCIBus *bus,
> pci_bus_ret_fn begin,
> }
> }
>
> +typedef struct {
> + pci_bus_fn fn;
> + void *opaque;
> +} pci_root_bus_args;
> +
PCIRootBusArgs ?
Or maybe
PCIForEachRootBusInfo
... but it gets lengthy .. ;)
> +static int pci_find_root_bus(Object *obj, void *opaque)
> +{
> + pci_root_bus_args *args = opaque;
> +
> + if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
> + PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
> +
> + if (bus) {
> + args->fn(bus, args->opaque);
> + }
> + }
> +
> + return 0;
> +}
> +
> +void pci_for_each_root_bus(pci_bus_fn fn, void *opaque)
> +{
> + pci_root_bus_args args = { .fn = fn, .opaque = opaque };
> +
> + object_child_foreach_recursive(object_get_root(), pci_find_root_bus,
> &args);
> +}
>
> PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
> {
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index a7e81f04d3..9e490d8969 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -474,6 +474,8 @@ void pci_for_each_device_under_bus_reverse(PCIBus *bus,
> void *opaque);
> 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);
> PCIDevice *pci_get_function_0(PCIDevice *pci_dev);
>
> /* Use this wrapper when specific scan order is not required. */
>
Apart from that LGTM, but not a PCI expert.
--
Thanks,
David / dhildenb