pci: Export pci_for_each_device_under_bus*()

They're actually more commonly used than the helper without _under_bus, because
most callers do have the pci bus on hand.  After exporting we can switch a lot
of the call sites to use these two helpers.

Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20211028043129.38871-3-peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Peter Xu 2021-10-28 12:31:26 +08:00 committed by Michael S. Tsirkin
parent b3dcf94f77
commit 2914fc61d5
9 changed files with 27 additions and 29 deletions

View File

@ -2134,8 +2134,7 @@ dmar_host_bridges(Object *obj, void *opaque)
PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
if (bus && !pci_bus_bypass_iommu(bus)) { if (bus && !pci_bus_bypass_iommu(bus)) {
pci_for_each_device(bus, pci_bus_num(bus), insert_scope, pci_for_each_device_under_bus(bus, insert_scope, scope_blob);
scope_blob);
} }
} }
@ -2341,7 +2340,7 @@ ivrs_host_bridges(Object *obj, void *opaque)
PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
if (bus && !pci_bus_bypass_iommu(bus)) { if (bus && !pci_bus_bypass_iommu(bus)) {
pci_for_each_device(bus, pci_bus_num(bus), insert_ivhd, ivhd_blob); pci_for_each_device_under_bus(bus, insert_ivhd, ivhd_blob);
} }
} }

View File

@ -1654,9 +1654,9 @@ static const pci_class_desc pci_class_descriptions[] =
{ 0, NULL} { 0, NULL}
}; };
static void pci_for_each_device_under_bus_reverse(PCIBus *bus, void pci_for_each_device_under_bus_reverse(PCIBus *bus,
pci_bus_dev_fn fn, pci_bus_dev_fn fn,
void *opaque) void *opaque)
{ {
PCIDevice *d; PCIDevice *d;
int devfn; int devfn;
@ -1679,8 +1679,8 @@ void pci_for_each_device_reverse(PCIBus *bus, int bus_num,
} }
} }
static void pci_for_each_device_under_bus(PCIBus *bus, void pci_for_each_device_under_bus(PCIBus *bus,
pci_bus_dev_fn fn, void *opaque) pci_bus_dev_fn fn, void *opaque)
{ {
PCIDevice *d; PCIDevice *d;
int devfn; int devfn;

View File

@ -694,9 +694,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
(!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) ||
(old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) != PCI_EXP_SLTCTL_PIC_OFF)) { (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) != PCI_EXP_SLTCTL_PIC_OFF)) {
PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev));
pci_for_each_device(sec_bus, pci_bus_num(sec_bus), pci_for_each_device_under_bus(sec_bus, pcie_unplug_device, NULL);
pcie_unplug_device, NULL);
pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
PCI_EXP_SLTSTA_PDS); PCI_EXP_SLTSTA_PDS);
if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA ||

View File

@ -1317,8 +1317,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
RESOURCE_CELLS_SIZE)); RESOURCE_CELLS_SIZE));
assert(bus); assert(bus);
pci_for_each_device_reverse(bus, pci_bus_num(bus), pci_for_each_device_under_bus_reverse(bus, spapr_dt_pci_device_cb, &cbinfo);
spapr_dt_pci_device_cb, &cbinfo);
if (cbinfo.err) { if (cbinfo.err) {
return cbinfo.err; return cbinfo.err;
} }
@ -2306,8 +2305,8 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
return; return;
} }
pci_for_each_device(sec_bus, pci_bus_num(sec_bus), pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_enumerate_bridge,
spapr_phb_pci_enumerate_bridge, bus_no); bus_no);
pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1); pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
} }
@ -2316,9 +2315,8 @@ static void spapr_phb_pci_enumerate(SpaprPhbState *phb)
PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus; PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus;
unsigned int bus_no = 0; unsigned int bus_no = 0;
pci_for_each_device(bus, pci_bus_num(bus), pci_for_each_device_under_bus(bus, spapr_phb_pci_enumerate_bridge,
spapr_phb_pci_enumerate_bridge, &bus_no);
&bus_no);
} }

View File

@ -164,8 +164,7 @@ static void spapr_phb_pci_collect_nvgpu(PCIBus *bus, PCIDevice *pdev,
return; return;
} }
pci_for_each_device(sec_bus, pci_bus_num(sec_bus), pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_collect_nvgpu, opaque);
spapr_phb_pci_collect_nvgpu, opaque);
} }
void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp)
@ -183,8 +182,8 @@ void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp)
sphb->nvgpus->nv2_atsd_current = sphb->nv2_atsd_win_addr; sphb->nvgpus->nv2_atsd_current = sphb->nv2_atsd_win_addr;
bus = PCI_HOST_BRIDGE(sphb)->bus; bus = PCI_HOST_BRIDGE(sphb)->bus;
pci_for_each_device(bus, pci_bus_num(bus), pci_for_each_device_under_bus(bus, spapr_phb_pci_collect_nvgpu,
spapr_phb_pci_collect_nvgpu, sphb->nvgpus); sphb->nvgpus);
if (sphb->nvgpus->err) { if (sphb->nvgpus->err) {
error_propagate(errp, sphb->nvgpus->err); error_propagate(errp, sphb->nvgpus->err);

View File

@ -164,8 +164,8 @@ static void spapr_phb_vfio_eeh_clear_dev_msix(PCIBus *bus,
static void spapr_phb_vfio_eeh_clear_bus_msix(PCIBus *bus, void *opaque) static void spapr_phb_vfio_eeh_clear_bus_msix(PCIBus *bus, void *opaque)
{ {
pci_for_each_device(bus, pci_bus_num(bus), pci_for_each_device_under_bus(bus, spapr_phb_vfio_eeh_clear_dev_msix,
spapr_phb_vfio_eeh_clear_dev_msix, NULL); NULL);
} }
static void spapr_phb_vfio_eeh_pre_reset(SpaprPhbState *sphb) static void spapr_phb_vfio_eeh_pre_reset(SpaprPhbState *sphb)

View File

@ -1163,8 +1163,7 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
} }
/* Assign numbers to all child bridges. The last is the highest number. */ /* Assign numbers to all child bridges. The last is the highest number. */
pci_for_each_device(sec_bus, pci_bus_num(sec_bus), pci_for_each_device_under_bus(sec_bus, s390_pci_enumerate_bridge, s);
s390_pci_enumerate_bridge, s);
pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1); pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1);
} }
@ -1193,7 +1192,7 @@ static void s390_pcihost_reset(DeviceState *dev)
* on every system reset, we also have to reassign numbers. * on every system reset, we also have to reassign numbers.
*/ */
s->bus_no = 0; s->bus_no = 0;
pci_for_each_device(bus, pci_bus_num(bus), s390_pci_enumerate_bridge, s); pci_for_each_device_under_bus(bus, s390_pci_enumerate_bridge, s);
} }
static void s390_pcihost_class_init(ObjectClass *klass, void *data) static void s390_pcihost_class_init(ObjectClass *klass, void *data)

View File

@ -615,8 +615,8 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
} }
args.type = d->io_regions[bar].type; args.type = d->io_regions[bar].type;
pci_for_each_device(pci_get_bus(d), pci_dev_bus_num(d), pci_for_each_device_under_bus(pci_get_bus(d),
xen_pt_check_bar_overlap, &args); xen_pt_check_bar_overlap, &args);
if (args.rc) { if (args.rc) {
XEN_PT_WARN(d, "Region: %d (addr: 0x%"FMT_PCIBUS XEN_PT_WARN(d, "Region: %d (addr: 0x%"FMT_PCIBUS
", len: 0x%"FMT_PCIBUS") is overlapped.\n", ", len: 0x%"FMT_PCIBUS") is overlapped.\n",

View File

@ -467,6 +467,11 @@ void pci_for_each_device(PCIBus *bus, int bus_num,
void pci_for_each_device_reverse(PCIBus *bus, int bus_num, void pci_for_each_device_reverse(PCIBus *bus, int bus_num,
pci_bus_dev_fn fn, pci_bus_dev_fn fn,
void *opaque); void *opaque);
void pci_for_each_device_under_bus(PCIBus *bus,
pci_bus_dev_fn fn, void *opaque);
void pci_for_each_device_under_bus_reverse(PCIBus *bus,
pci_bus_dev_fn fn,
void *opaque);
void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin,
pci_bus_fn end, void *parent_state); pci_bus_fn end, void *parent_state);
PCIDevice *pci_get_function_0(PCIDevice *pci_dev); PCIDevice *pci_get_function_0(PCIDevice *pci_dev);