[Qemu-devel] [for-2.12 5/7] pci: Add pci_dev_bus_num() helper

David Gibson posted 7 patches 8 years, 2 months ago
[Qemu-devel] [for-2.12 5/7] pci: Add pci_dev_bus_num() helper
Posted by David Gibson 8 years, 2 months ago
A fair proportion of the users of pci_bus_num() want to get the bus
number on a specific device, so first have to look up the bus from the
device then call it.  This adds a helper to do that (since we're going
to make looking up the bus slightly more verbose).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/pci/pcie_aer.c           | 2 +-
 hw/s390x/s390-pci-bus.c     | 2 +-
 hw/scsi/megasas.c           | 2 +-
 hw/scsi/mptsas.c            | 2 +-
 hw/xen/xen_pt.c             | 6 +++---
 include/hw/pci/pci.h        | 5 +++++
 include/hw/xen/xen_common.h | 8 ++++----
 7 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index 171955195f..7688293edc 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -1024,7 +1024,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
     }
     details->id = id;
     details->root_bus = pci_root_bus_path(dev);
-    details->bus = pci_bus_num(dev->bus);
+    details->bus = pci_dev_bus_num(dev);
     details->devfn = dev->devfn;
 
     return 0;
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 3a8894a36c..1aecada271 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -691,7 +691,7 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
             /* In the case the PCI device does not define an id */
             /* we generate one based on the PCI address         */
             dev->id = g_strdup_printf("auto_%02x:%02x.%01x",
-                                      pci_bus_num(pdev->bus),
+                                      pci_dev_bus_num(pdev),
                                       PCI_SLOT(pdev->devfn),
                                       PCI_FUNC(pdev->devfn));
         }
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index d5eae6239a..3e38e9e8aa 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2372,7 +2372,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
     if (!s->sas_addr) {
         s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
                        IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
-        s->sas_addr |= (pci_bus_num(dev->bus) << 16);
+        s->sas_addr |= (pci_dev_bus_num(dev) << 16);
         s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
         s->sas_addr |= PCI_FUNC(dev->devfn);
     }
diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
index f6db1b0103..3f061f3f68 100644
--- a/hw/scsi/mptsas.c
+++ b/hw/scsi/mptsas.c
@@ -1312,7 +1312,7 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
     if (!s->sas_addr) {
         s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
                        IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
-        s->sas_addr |= (pci_bus_num(dev->bus) << 16);
+        s->sas_addr |= (pci_dev_bus_num(dev) << 16);
         s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
         s->sas_addr |= PCI_FUNC(dev->devfn);
     }
diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index 9bba717708..6236f0c391 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -73,7 +73,7 @@ void xen_pt_log(const PCIDevice *d, const char *f, ...)
 
     va_start(ap, f);
     if (d) {
-        fprintf(stderr, "[%02x:%02x.%d] ", pci_bus_num(d->bus),
+        fprintf(stderr, "[%02x:%02x.%d] ", pci_dev_bus_num(d),
                 PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
     }
     vfprintf(stderr, f, ap);
@@ -711,7 +711,7 @@ static void xen_pt_destroy(PCIDevice *d) {
         intx = xen_pt_pci_intx(s);
         rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq,
                                      PT_IRQ_TYPE_PCI,
-                                     pci_bus_num(d->bus),
+                                     pci_dev_bus_num(d),
                                      PCI_SLOT(s->dev.devfn),
                                      intx,
                                      0 /* isa_irq */);
@@ -867,7 +867,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
         uint8_t e_intx = xen_pt_pci_intx(s);
 
         rc = xc_domain_bind_pt_pci_irq(xen_xc, xen_domid, machine_irq,
-                                       pci_bus_num(d->bus),
+                                       pci_dev_bus_num(d),
                                        PCI_SLOT(d->devfn),
                                        e_intx);
         if (rc < 0) {
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index cbb3386207..a490a2c7d4 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -488,6 +488,11 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
 PCIDevice *pci_vga_init(PCIBus *bus);
 
 int pci_bus_num(PCIBus *s);
+static inline int pci_dev_bus_num(const PCIDevice *dev)
+{
+    return pci_bus_num(dev->bus);
+}
+
 int pci_bus_numa_node(PCIBus *bus);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h
index 86c7f26106..64a978e4e0 100644
--- a/include/hw/xen/xen_common.h
+++ b/include/hw/xen/xen_common.h
@@ -542,10 +542,10 @@ static inline void xen_map_pcidev(domid_t dom,
         return;
     }
 
-    trace_xen_map_pcidev(ioservid, pci_bus_num(pci_dev->bus),
+    trace_xen_map_pcidev(ioservid, pci_dev_bus_num(pci_dev),
                          PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
     xendevicemodel_map_pcidev_to_ioreq_server(xen_dmod, dom, ioservid, 0,
-                                              pci_bus_num(pci_dev->bus),
+                                              pci_dev_bus_num(pci_dev),
                                               PCI_SLOT(pci_dev->devfn),
                                               PCI_FUNC(pci_dev->devfn));
 }
@@ -558,10 +558,10 @@ static inline void xen_unmap_pcidev(domid_t dom,
         return;
     }
 
-    trace_xen_unmap_pcidev(ioservid, pci_bus_num(pci_dev->bus),
+    trace_xen_unmap_pcidev(ioservid, pci_dev_bus_num(pci_dev),
                            PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
     xendevicemodel_unmap_pcidev_from_ioreq_server(xen_dmod, dom, ioservid, 0,
-                                                  pci_bus_num(pci_dev->bus),
+                                                  pci_dev_bus_num(pci_dev),
                                                   PCI_SLOT(pci_dev->devfn),
                                                   PCI_FUNC(pci_dev->devfn));
 }
-- 
2.14.3


Re: [Qemu-devel] [for-2.12 5/7] pci: Add pci_dev_bus_num() helper
Posted by Marcel Apfelbaum 8 years, 2 months ago
On 29/11/2017 10:46, David Gibson wrote:
> A fair proportion of the users of pci_bus_num() want to get the bus
> number on a specific device, so first have to look up the bus from the
> device then call it.  This adds a helper to do that (since we're going
> to make looking up the bus slightly more verbose).
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>   hw/pci/pcie_aer.c           | 2 +-
>   hw/s390x/s390-pci-bus.c     | 2 +-
>   hw/scsi/megasas.c           | 2 +-
>   hw/scsi/mptsas.c            | 2 +-
>   hw/xen/xen_pt.c             | 6 +++---
>   include/hw/pci/pci.h        | 5 +++++
>   include/hw/xen/xen_common.h | 8 ++++----
>   7 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
> index 171955195f..7688293edc 100644
> --- a/hw/pci/pcie_aer.c
> +++ b/hw/pci/pcie_aer.c
> @@ -1024,7 +1024,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
>       }
>       details->id = id;
>       details->root_bus = pci_root_bus_path(dev);
> -    details->bus = pci_bus_num(dev->bus);
> +    details->bus = pci_dev_bus_num(dev);
>       details->devfn = dev->devfn;
>   
>       return 0;
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index 3a8894a36c..1aecada271 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -691,7 +691,7 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
>               /* In the case the PCI device does not define an id */
>               /* we generate one based on the PCI address         */
>               dev->id = g_strdup_printf("auto_%02x:%02x.%01x",
> -                                      pci_bus_num(pdev->bus),
> +                                      pci_dev_bus_num(pdev),
>                                         PCI_SLOT(pdev->devfn),
>                                         PCI_FUNC(pdev->devfn));
>           }
> diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
> index d5eae6239a..3e38e9e8aa 100644
> --- a/hw/scsi/megasas.c
> +++ b/hw/scsi/megasas.c
> @@ -2372,7 +2372,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
>       if (!s->sas_addr) {
>           s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
>                          IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
> -        s->sas_addr |= (pci_bus_num(dev->bus) << 16);
> +        s->sas_addr |= (pci_dev_bus_num(dev) << 16);
>           s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
>           s->sas_addr |= PCI_FUNC(dev->devfn);
>       }
> diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
> index f6db1b0103..3f061f3f68 100644
> --- a/hw/scsi/mptsas.c
> +++ b/hw/scsi/mptsas.c
> @@ -1312,7 +1312,7 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
>       if (!s->sas_addr) {
>           s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
>                          IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
> -        s->sas_addr |= (pci_bus_num(dev->bus) << 16);
> +        s->sas_addr |= (pci_dev_bus_num(dev) << 16);
>           s->sas_addr |= (PCI_SLOT(dev->devfn) << 8);
>           s->sas_addr |= PCI_FUNC(dev->devfn);
>       }
> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
> index 9bba717708..6236f0c391 100644
> --- a/hw/xen/xen_pt.c
> +++ b/hw/xen/xen_pt.c
> @@ -73,7 +73,7 @@ void xen_pt_log(const PCIDevice *d, const char *f, ...)
>   
>       va_start(ap, f);
>       if (d) {
> -        fprintf(stderr, "[%02x:%02x.%d] ", pci_bus_num(d->bus),
> +        fprintf(stderr, "[%02x:%02x.%d] ", pci_dev_bus_num(d),
>                   PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
>       }
>       vfprintf(stderr, f, ap);
> @@ -711,7 +711,7 @@ static void xen_pt_destroy(PCIDevice *d) {
>           intx = xen_pt_pci_intx(s);
>           rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq,
>                                        PT_IRQ_TYPE_PCI,
> -                                     pci_bus_num(d->bus),
> +                                     pci_dev_bus_num(d),
>                                        PCI_SLOT(s->dev.devfn),
>                                        intx,
>                                        0 /* isa_irq */);
> @@ -867,7 +867,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
>           uint8_t e_intx = xen_pt_pci_intx(s);
>   
>           rc = xc_domain_bind_pt_pci_irq(xen_xc, xen_domid, machine_irq,
> -                                       pci_bus_num(d->bus),
> +                                       pci_dev_bus_num(d),
>                                          PCI_SLOT(d->devfn),
>                                          e_intx);
>           if (rc < 0) {
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index cbb3386207..a490a2c7d4 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -488,6 +488,11 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
>   PCIDevice *pci_vga_init(PCIBus *bus);
>   
>   int pci_bus_num(PCIBus *s);
> +static inline int pci_dev_bus_num(const PCIDevice *dev)
> +{
> +    return pci_bus_num(dev->bus);
> +}
> +
>   int pci_bus_numa_node(PCIBus *bus);
>   void pci_for_each_device(PCIBus *bus, int bus_num,
>                            void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
> diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h
> index 86c7f26106..64a978e4e0 100644
> --- a/include/hw/xen/xen_common.h
> +++ b/include/hw/xen/xen_common.h
> @@ -542,10 +542,10 @@ static inline void xen_map_pcidev(domid_t dom,
>           return;
>       }
>   
> -    trace_xen_map_pcidev(ioservid, pci_bus_num(pci_dev->bus),
> +    trace_xen_map_pcidev(ioservid, pci_dev_bus_num(pci_dev),
>                            PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
>       xendevicemodel_map_pcidev_to_ioreq_server(xen_dmod, dom, ioservid, 0,
> -                                              pci_bus_num(pci_dev->bus),
> +                                              pci_dev_bus_num(pci_dev),
>                                                 PCI_SLOT(pci_dev->devfn),
>                                                 PCI_FUNC(pci_dev->devfn));
>   }
> @@ -558,10 +558,10 @@ static inline void xen_unmap_pcidev(domid_t dom,
>           return;
>       }
>   
> -    trace_xen_unmap_pcidev(ioservid, pci_bus_num(pci_dev->bus),
> +    trace_xen_unmap_pcidev(ioservid, pci_dev_bus_num(pci_dev),
>                              PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
>       xendevicemodel_unmap_pcidev_from_ioreq_server(xen_dmod, dom, ioservid, 0,
> -                                                  pci_bus_num(pci_dev->bus),
> +                                                  pci_dev_bus_num(pci_dev),
>                                                     PCI_SLOT(pci_dev->devfn),
>                                                     PCI_FUNC(pci_dev->devfn));
>   }
> 


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel




Re: [Qemu-devel] [for-2.12 5/7] pci: Add pci_dev_bus_num() helper
Posted by Peter Xu 8 years, 2 months ago
On Wed, Nov 29, 2017 at 07:46:26PM +1100, David Gibson wrote:
> A fair proportion of the users of pci_bus_num() want to get the bus
> number on a specific device, so first have to look up the bus from the
> device then call it.  This adds a helper to do that (since we're going
> to make looking up the bus slightly more verbose).
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu