[PATCH v3 03/11] xen/arm: Introduce pci_find_host_bridge_node helper

Oleksandr Andrushchenko posted 11 patches 3 years, 2 months ago
There is a newer version of this series
[PATCH v3 03/11] xen/arm: Introduce pci_find_host_bridge_node helper
Posted by Oleksandr Andrushchenko 3 years, 2 months ago
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Get host bridge node given a PCI device attached to it.

This helper will be re-used for adding PCI devices by the subsequent
patches.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

---
Since v2:
 - !! dropped Stefano's r-b because of the changes
 - s/PRI_pci/%pp after rebase onto Arm series
---
 xen/arch/arm/pci/pci-host-common.c | 16 ++++++++++++++++
 xen/include/asm-arm/pci.h          |  1 +
 2 files changed, 17 insertions(+)

diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
index 593beeb48ce4..592c01aae5bb 100644
--- a/xen/arch/arm/pci/pci-host-common.c
+++ b/xen/arch/arm/pci/pci-host-common.c
@@ -276,6 +276,22 @@ int pci_get_host_bridge_segment(const struct dt_device_node *node,
     return -EINVAL;
 }
 
+/*
+ * Get host bridge node given a device attached to it.
+ */
+struct dt_device_node *pci_find_host_bridge_node(struct device *dev)
+{
+    struct pci_host_bridge *bridge;
+    struct pci_dev *pdev = dev_to_pci(dev);
+
+    bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
+    if ( unlikely(!bridge) )
+    {
+        printk(XENLOG_ERR "Unable to find PCI bridge for %pp\n", &pdev->sbdf);
+        return NULL;
+    }
+    return bridge->dt_node;
+}
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h
index 603a1fc072d1..e6d4000e2ac8 100644
--- a/xen/include/asm-arm/pci.h
+++ b/xen/include/asm-arm/pci.h
@@ -99,6 +99,7 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
 struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus);
 int pci_get_host_bridge_segment(const struct dt_device_node *node,
                                 uint16_t *segment);
+struct dt_device_node *pci_find_host_bridge_node(struct device *dev);
 
 static always_inline bool is_pci_passthrough_enabled(void)
 {
-- 
2.25.1


Re: [PATCH v3 03/11] xen/arm: Introduce pci_find_host_bridge_node helper
Posted by Stefano Stabellini 3 years, 2 months ago
On Thu, 30 Sep 2021, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> 
> Get host bridge node given a PCI device attached to it.
> 
> This helper will be re-used for adding PCI devices by the subsequent
> patches.
> 
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> 
> ---
> Since v2:
>  - !! dropped Stefano's r-b because of the changes
>  - s/PRI_pci/%pp after rebase onto Arm series
> ---
>  xen/arch/arm/pci/pci-host-common.c | 16 ++++++++++++++++
>  xen/include/asm-arm/pci.h          |  1 +
>  2 files changed, 17 insertions(+)
> 
> diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
> index 593beeb48ce4..592c01aae5bb 100644
> --- a/xen/arch/arm/pci/pci-host-common.c
> +++ b/xen/arch/arm/pci/pci-host-common.c
> @@ -276,6 +276,22 @@ int pci_get_host_bridge_segment(const struct dt_device_node *node,
>      return -EINVAL;
>  }
>  
> +/*
> + * Get host bridge node given a device attached to it.
> + */
> +struct dt_device_node *pci_find_host_bridge_node(struct device *dev)
> +{
> +    struct pci_host_bridge *bridge;
> +    struct pci_dev *pdev = dev_to_pci(dev);
> +
> +    bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
> +    if ( unlikely(!bridge) )
> +    {
> +        printk(XENLOG_ERR "Unable to find PCI bridge for %pp\n", &pdev->sbdf);
> +        return NULL;
> +    }
> +    return bridge->dt_node;
> +}
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h
> index 603a1fc072d1..e6d4000e2ac8 100644
> --- a/xen/include/asm-arm/pci.h
> +++ b/xen/include/asm-arm/pci.h
> @@ -99,6 +99,7 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
>  struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus);
>  int pci_get_host_bridge_segment(const struct dt_device_node *node,
>                                  uint16_t *segment);
> +struct dt_device_node *pci_find_host_bridge_node(struct device *dev);
>  
>  static always_inline bool is_pci_passthrough_enabled(void)
>  {
> -- 
> 2.25.1
> 

Re: [PATCH v3 03/11] xen/arm: Introduce pci_find_host_bridge_node helper
Posted by Stefano Stabellini 3 years, 2 months ago
On Thu, 30 Sep 2021, Stefano Stabellini wrote:
> On Thu, 30 Sep 2021, Oleksandr Andrushchenko wrote:
> > From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > 
> > Get host bridge node given a PCI device attached to it.
> > 
> > This helper will be re-used for adding PCI devices by the subsequent
> > patches.
> > 
> > Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

I meant to say:

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> > ---
> > Since v2:
> >  - !! dropped Stefano's r-b because of the changes
> >  - s/PRI_pci/%pp after rebase onto Arm series
> > ---
> >  xen/arch/arm/pci/pci-host-common.c | 16 ++++++++++++++++
> >  xen/include/asm-arm/pci.h          |  1 +
> >  2 files changed, 17 insertions(+)
> > 
> > diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
> > index 593beeb48ce4..592c01aae5bb 100644
> > --- a/xen/arch/arm/pci/pci-host-common.c
> > +++ b/xen/arch/arm/pci/pci-host-common.c
> > @@ -276,6 +276,22 @@ int pci_get_host_bridge_segment(const struct dt_device_node *node,
> >      return -EINVAL;
> >  }
> >  
> > +/*
> > + * Get host bridge node given a device attached to it.
> > + */
> > +struct dt_device_node *pci_find_host_bridge_node(struct device *dev)
> > +{
> > +    struct pci_host_bridge *bridge;
> > +    struct pci_dev *pdev = dev_to_pci(dev);
> > +
> > +    bridge = pci_find_host_bridge(pdev->seg, pdev->bus);
> > +    if ( unlikely(!bridge) )
> > +    {
> > +        printk(XENLOG_ERR "Unable to find PCI bridge for %pp\n", &pdev->sbdf);
> > +        return NULL;
> > +    }
> > +    return bridge->dt_node;
> > +}
> >  /*
> >   * Local variables:
> >   * mode: C
> > diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h
> > index 603a1fc072d1..e6d4000e2ac8 100644
> > --- a/xen/include/asm-arm/pci.h
> > +++ b/xen/include/asm-arm/pci.h
> > @@ -99,6 +99,7 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
> >  struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus);
> >  int pci_get_host_bridge_segment(const struct dt_device_node *node,
> >                                  uint16_t *segment);
> > +struct dt_device_node *pci_find_host_bridge_node(struct device *dev);
> >  
> >  static always_inline bool is_pci_passthrough_enabled(void)
> >  {
> > -- 
> > 2.25.1
> > 
>