Skip to contentSkip to conversation

Add support for R-Car Gen4 PCI host controller

PATCH Superseded Mykyta Poturai 3 participants 12 messages Feb 24, 2025 – Mar 7, 2025

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Add support for R-Car Gen4 PCI host controller

This series adds support for R-Car Gen4 PCI host controller.

To fully support the controller, the following changes were made:
- Generic mechanism to support PCI child buses is added.
- Private data for PCI host bridge and means to access it are added.

The series also includes a workaround for proper ATU propramming and optimizations to lessen the performance impact of that workaround.

The series was tested both as a part of the pci-passthrough patches[1] and standalone on S4 and V4H boards.

[1] https://github.com/Deedone/xen/tree/pci_passthrough_wip

Oleksandr Andrushchenko (4):
xen/arm: allow PCI host bridge to have private data xen/arm: make pci_host_common_probe return the bridge xen/arm: add support for PCI child bus xen/arm: add support for R-Car Gen4 PCI host controller

Volodymyr Babchuk (3):
xen/arm: rcar4: add delay after programming ATU xen/arm: rcar4: add simple optimization to avoid ATU reprogramming xen/arm: rcar4: program ATU to accesses to all functions

 xen/arch/arm/include/asm/pci.h      |  16 +-
 xen/arch/arm/pci/Makefile           |   1 +
 xen/arch/arm/pci/ecam.c             |  17 +-
 xen/arch/arm/pci/pci-access.c       |  37 +-
 xen/arch/arm/pci/pci-host-common.c  | 106 +++++-
 xen/arch/arm/pci/pci-host-generic.c |   2 +-
 xen/arch/arm/pci/pci-host-rcar4.c   | 542 ++++++++++++++++++++++++++++
 xen/arch/arm/pci/pci-host-zynqmp.c  |   2 +-
 xen/arch/arm/vpci.c                 |  91 ++++-
 9 files changed, 764 insertions(+), 50 deletions(-)
 create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/7 xen/arm: allow PCI host bridge to have private data

From: Oleksandr Andrushchenko <[email protected]>

Some of the PCI host bridges require private data. Create a generic approach for that, so such bridges may request the private data to be allocated during initialization.

---
 xen/arch/arm/include/asm/pci.h      |  4 +++-
 xen/arch/arm/pci/pci-host-common.c  | 18 +++++++++++++++++-
 xen/arch/arm/pci/pci-host-generic.c |  2 +-
 xen/arch/arm/pci/pci-host-zynqmp.c  |  2 +-
 4 files changed, 22 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/pci.h +3 -1
index 7f77226c9b..44344ac8c1 100644
@@ -66,6 +66,7 @@ struct pci_host_bridge {
     uint16_t segment;                /* Segment number */
     struct pci_config_window* cfg;   /* Pointer to the bridge config window */
     const struct pci_ops *ops;
+    void *priv;                      /* Private data of the bridge. */
 };
 
 struct pci_ops {
@@ -95,7 +96,8 @@ struct pci_ecam_ops {
 extern const struct pci_ecam_ops pci_generic_ecam_ops;
 
 int pci_host_common_probe(struct dt_device_node *dev,
-                          const struct pci_ecam_ops *ops);
+                          const struct pci_ecam_ops *ops,
+                          size_t priv_sz);
 int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                             uint32_t reg, uint32_t len, uint32_t *value);
 int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
xen/arch/arm/pci/pci-host-common.c +17 -1
index c0faf0f436..be7e6c3510 100644
@@ -209,7 +209,8 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev)
 }
 
 int pci_host_common_probe(struct dt_device_node *dev,
-                          const struct pci_ecam_ops *ops)
+                          const struct pci_ecam_ops *ops,
+                          size_t priv_sz)
 {
     struct pci_host_bridge *bridge;
     struct pci_config_window *cfg;
@@ -241,11 +242,26 @@ int pci_host_common_probe(struct dt_device_node *dev,
         printk(XENLOG_ERR "Inconsistent \"linux,pci-domain\" property in DT\n");
         BUG();
     }
+
     bridge->segment = domain;
+
+    if ( priv_sz )
+    {
+        bridge->priv = xzalloc_bytes(priv_sz);
+        if ( !bridge->priv )
+        {
+            err = -ENOMEM;
+            goto err_priv;
+        }
+    }
+
     pci_add_host_bridge(bridge);
 
     return 0;
 
+err_priv:
+    xfree(bridge->priv);
+
 err_exit:
     xfree(bridge);
 
xen/arch/arm/pci/pci-host-generic.c +1 -1
index 46de6e43cc..cc4bc70684 100644
@@ -29,7 +29,7 @@ static const struct dt_device_match __initconstrel gen_pci_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return pci_host_common_probe(dev, &pci_generic_ecam_ops);
+    return pci_host_common_probe(dev, &pci_generic_ecam_ops, 0);
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI_HOSTBRIDGE)
xen/arch/arm/pci/pci-host-zynqmp.c +1 -1
index 101edb8593..985a43c516 100644
@@ -47,7 +47,7 @@ static const struct dt_device_match __initconstrel nwl_pcie_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return pci_host_common_probe(dev, &nwl_pcie_ops);
+    return pci_host_common_probe(dev, &nwl_pcie_ops, 0);
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI_HOSTBRIDGE)
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/7 xen/arm: make pci_host_common_probe return the bridge

In reply to Mykyta Poturai

From: Oleksandr Andrushchenko <[email protected]>

Some of the PCI host bridges require additional processing during the probe phase. For that they need to access struct bridge of the probed host, so return pointer to the new bridge from pci_host_common_probe.

---
 xen/arch/arm/include/asm/pci.h      |  8 +++++---
 xen/arch/arm/pci/pci-host-common.c  | 12 ++++++------
 xen/arch/arm/pci/pci-host-generic.c |  2 +-
 xen/arch/arm/pci/pci-host-zynqmp.c  |  2 +-
 4 files changed, 13 insertions(+), 11 deletions(-)
xen/arch/arm/include/asm/pci.h +5 -3
index 44344ac8c1..e1f63d75e3 100644
@@ -17,6 +17,8 @@
 
 #ifdef CONFIG_HAS_PCI
 
+#include <xen/err.h>
+
 #include <asm/p2m.h>
 
 #define pci_to_dev(pcidev) (&(pcidev)->arch.dev)
@@ -95,9 +97,9 @@ struct pci_ecam_ops {
 /* Default ECAM ops */
 extern const struct pci_ecam_ops pci_generic_ecam_ops;
 
-int pci_host_common_probe(struct dt_device_node *dev,
-                          const struct pci_ecam_ops *ops,
-                          size_t priv_sz);
+struct pci_host_bridge *pci_host_common_probe(struct dt_device_node *dev,
+                                              const struct pci_ecam_ops *ops,
+                                              size_t priv_sz);
 int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                             uint32_t reg, uint32_t len, uint32_t *value);
 int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
xen/arch/arm/pci/pci-host-common.c +6 -6
index be7e6c3510..e4e05d1176 100644
@@ -208,9 +208,9 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev)
     return domain;
 }
 
-int pci_host_common_probe(struct dt_device_node *dev,
-                          const struct pci_ecam_ops *ops,
-                          size_t priv_sz)
+struct pci_host_bridge *pci_host_common_probe(struct dt_device_node *dev,
+                                              const struct pci_ecam_ops *ops,
+                                              size_t priv_sz)
 {
     struct pci_host_bridge *bridge;
     struct pci_config_window *cfg;
@@ -222,7 +222,7 @@ int pci_host_common_probe(struct dt_device_node *dev,
 
     bridge = pci_alloc_host_bridge();
     if ( !bridge )
-        return -ENOMEM;
+        return ERR_PTR(-ENOMEM);
 
     /* Parse and map our Configuration Space windows */
     cfg = gen_pci_init(dev, ops);
@@ -257,7 +257,7 @@ int pci_host_common_probe(struct dt_device_node *dev,
 
     pci_add_host_bridge(bridge);
 
-    return 0;
+    return bridge;
 
 err_priv:
     xfree(bridge->priv);
@@ -265,7 +265,7 @@ err_priv:
 err_exit:
     xfree(bridge);
 
-    return err;
+    return ERR_PTR(err);
 }
 
 /*
xen/arch/arm/pci/pci-host-generic.c +1 -1
index cc4bc70684..dde6a79a8e 100644
@@ -29,7 +29,7 @@ static const struct dt_device_match __initconstrel gen_pci_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return pci_host_common_probe(dev, &pci_generic_ecam_ops, 0);
+    return PTR_RET(pci_host_common_probe(dev, &pci_generic_ecam_ops, 0));
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI_HOSTBRIDGE)
xen/arch/arm/pci/pci-host-zynqmp.c +1 -1
index 985a43c516..c796447ac4 100644
@@ -47,7 +47,7 @@ static const struct dt_device_match __initconstrel nwl_pcie_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return pci_host_common_probe(dev, &nwl_pcie_ops, 0);
+    return PTR_RET(pci_host_common_probe(dev, &nwl_pcie_ops, 0));
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI_HOSTBRIDGE)
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/7 xen/arm: add support for PCI child bus

In reply to Mykyta Poturai

From: Oleksandr Andrushchenko <[email protected]>

PCI host bridges often have different ways to access the root and child bus configuration spaces. One of the examples is Designware's host bridge and its multiple clones [1].

Linux kernel implements this by instantiating a child bus when device drivers provide not only the usual pci_ops to access ECAM space (this is the case for the generic host bridge), but also means to access the child bus which has a dedicated configuration space and own implementation for accessing the bus, e.g. child_ops.

For Xen it is not feasible to fully implement PCI bus infrastructure as Linux kernel does, but still child bus can be supported.

Add support for the PCI child bus which includes the following changes:
- introduce bus mapping functions depending on SBDF
- assign bus start and end for the child bus and re-configure the same for the parent (root) bus
- make pci_find_host_bridge be aware of multiple busses behind the same bridge
- update pci_host_bridge_mappings, so it also doesn't map to guest the memory spaces belonging to the child bus
- make pci_host_common_probe accept one more pci_ops structure for the child bus
- install MMIO handlers for the child bus
- re-work vpci_mmio_{write|read} with parent and child approach in mind

[1] https://elixir.bootlin.com/linux/v5.15/source/drivers/pci/controller/dwc

---
 xen/arch/arm/include/asm/pci.h      | 14 ++++-
 xen/arch/arm/pci/ecam.c             | 17 ++++--
 xen/arch/arm/pci/pci-access.c       | 37 ++++++++++--
 xen/arch/arm/pci/pci-host-common.c  | 86 +++++++++++++++++++++------
 xen/arch/arm/pci/pci-host-generic.c |  2 +-
 xen/arch/arm/pci/pci-host-zynqmp.c  |  2 +-
 xen/arch/arm/vpci.c                 | 91 ++++++++++++++++++++++++-----
 7 files changed, 200 insertions(+), 49 deletions(-)
xen/arch/arm/include/asm/pci.h +11 -3
index e1f63d75e3..0012c2ae9e 100644
@@ -69,6 +69,9 @@ struct pci_host_bridge {
     struct pci_config_window* cfg;   /* Pointer to the bridge config window */
     const struct pci_ops *ops;
     void *priv;                      /* Private data of the bridge. */
+    /* Child bus */
+    struct pci_config_window* child_cfg;
+    const struct pci_ops *child_ops;
 };
 
 struct pci_ops {
@@ -97,15 +100,20 @@ struct pci_ecam_ops {
 /* Default ECAM ops */
 extern const struct pci_ecam_ops pci_generic_ecam_ops;
 
-struct pci_host_bridge *pci_host_common_probe(struct dt_device_node *dev,
-                                              const struct pci_ecam_ops *ops,
-                                              size_t priv_sz);
+struct pci_host_bridge *
+pci_host_common_probe(struct dt_device_node *dev,
+                      const struct pci_ecam_ops *ops,
+                      const struct pci_ecam_ops *child_ops,
+                      size_t priv_sz);
 int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                             uint32_t reg, uint32_t len, uint32_t *value);
 int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                              uint32_t reg, uint32_t len, uint32_t value);
 void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
                                pci_sbdf_t sbdf, uint32_t where);
+void __iomem *pci_ecam_map_bus_generic(const struct pci_config_window *cfg,
+                                       const struct pci_ecam_ops *ops,
+                                       pci_sbdf_t sbdf, uint32_t where);
 bool pci_ecam_need_p2m_hwdom_mapping(struct domain *d,
                                      struct pci_host_bridge *bridge,
                                      uint64_t addr);
xen/arch/arm/pci/ecam.c +12 -5
index 3987f96b01..5486881c5c 100644
@@ -20,12 +20,10 @@
 /*
  * Function to implement the pci_ops->map_bus method.
  */
-void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
-                               pci_sbdf_t sbdf, uint32_t where)
+void __iomem *pci_ecam_map_bus_generic(const struct pci_config_window *cfg,
+                                       const struct pci_ecam_ops *ops,
+                                       pci_sbdf_t sbdf, uint32_t where)
 {
-    const struct pci_config_window *cfg = bridge->cfg;
-    const struct pci_ecam_ops *ops =
-        container_of(bridge->ops, const struct pci_ecam_ops, pci_ops);
     unsigned int devfn_shift = ops->bus_shift - 8;
     void __iomem *base;
     unsigned int busn = sbdf.bus;
@@ -39,6 +37,15 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
     return base + (sbdf.devfn << devfn_shift) + where;
 }
 
+void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
+                               pci_sbdf_t sbdf, uint32_t where)
+{
+    const struct pci_ecam_ops *ops =
+        container_of(bridge->ops, const struct pci_ecam_ops, pci_ops);
+
+    return pci_ecam_map_bus_generic(bridge->cfg, ops, sbdf, where);
+}
+
 bool __init pci_ecam_need_p2m_hwdom_mapping(struct domain *d,
                                             struct pci_host_bridge *bridge,
                                             uint64_t addr)
xen/arch/arm/pci/pci-access.c +31 -6
index 9f9aac43d7..4da607ac3f 100644
@@ -18,10 +18,31 @@
 #define INVALID_VALUE (~0U)
 #define PCI_ERR_VALUE(len) GENMASK(0, len * 8)
 
+static const struct pci_ops *get_ops(struct pci_host_bridge *bridge,
+                                     pci_sbdf_t sbdf)
+{
+    if ( bridge->child_ops )
+    {
+        struct pci_config_window* cfg = bridge->child_cfg;
+
+        if ( (sbdf.bus >= cfg->busn_start) && (sbdf.bus <= cfg->busn_end) )
+            return bridge->child_ops;
+    }
+    return bridge->ops;
+}
+
+static void __iomem *map_bus(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
+                            uint32_t reg)
+{
+    const struct pci_ops *ops = get_ops(bridge, sbdf);
+
+    return ops->map_bus(bridge, sbdf, reg);
+}
+
 int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                             uint32_t reg, uint32_t len, uint32_t *value)
 {
-    void __iomem *addr = bridge->ops->map_bus(bridge, sbdf, reg);
+    void __iomem *addr = map_bus(bridge, sbdf, reg);
 
     if ( !addr )
     {
@@ -50,7 +71,7 @@ int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
 int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
                              uint32_t reg, uint32_t len, uint32_t value)
 {
-    void __iomem *addr = bridge->ops->map_bus(bridge, sbdf, reg);
+    void __iomem *addr = map_bus(bridge, sbdf, reg);
 
     if ( !addr )
         return -ENODEV;
@@ -78,14 +99,16 @@ static uint32_t pci_config_read(pci_sbdf_t sbdf, unsigned int reg,
 {
     uint32_t val = PCI_ERR_VALUE(len);
     struct pci_host_bridge *bridge = pci_find_host_bridge(sbdf.seg, sbdf.bus);
+    const struct pci_ops *ops;
 
     if ( unlikely(!bridge) )
         return val;
 
-    if ( unlikely(!bridge->ops->read) )
+    ops = get_ops(bridge, sbdf);
+    if ( unlikely(!ops->read) )
         return val;
 
-    bridge->ops->read(bridge, sbdf, reg, len, &val);
+    ops->read(bridge, sbdf, reg, len, &val);
 
     return val;
 }
@@ -94,14 +117,16 @@ static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg,
                              unsigned int len, uint32_t val)
 {
     struct pci_host_bridge *bridge = pci_find_host_bridge(sbdf.seg, sbdf.bus);
+    const struct pci_ops *ops;
 
     if ( unlikely(!bridge) )
         return;
 
-    if ( unlikely(!bridge->ops->write) )
+    ops = get_ops(bridge, sbdf);
+    if ( unlikely(!ops->write) )
         return;
 
-    bridge->ops->write(bridge, sbdf, reg, len, val);
+    ops->write(bridge, sbdf, reg, len, val);
 }
 
 /*
xen/arch/arm/pci/pci-host-common.c +69 -17

142 lines not on this page · raw message

xen/arch/arm/pci/pci-host-generic.c +1 -1
index dde6a79a8e..08d94879b7 100644
@@ -29,7 +29,7 @@ static const struct dt_device_match __initconstrel gen_pci_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return PTR_RET(pci_host_common_probe(dev, &pci_generic_ecam_ops, 0));
+    return PTR_RET(pci_host_common_probe(dev, &pci_generic_ecam_ops, NULL, 0));
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI_HOSTBRIDGE)
xen/arch/arm/pci/pci-host-zynqmp.c +1 -1
index c796447ac4..0b51ff6bd9 100644
@@ -47,7 +47,7 @@ static const struct dt_device_match __initconstrel nwl_pcie_dt_match[] =
 static int __init pci_host_generic_probe(struct dt_device_node *dev,
                                          const void *data)
 {
-    return PTR_RET(pci_host_common_probe(dev, &nwl_pcie_ops, 0));
+    return PTR_RET(pci_host_common_probe(dev, &nwl_pcie_ops, NULL, 0));
 }
 
 DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI_HOSTBRIDGE)
xen/arch/arm/vpci.c +75 -16

140 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/7 xen/arm: add support for R-Car Gen4 PCI host controller

In reply to Mykyta Poturai

From: Oleksandr Andrushchenko <[email protected]>

Add support for Renesas R-Car Gen4 PCI host controller.
S4 and V4H SoCs are supported.
Implement config read/write operations for both root and child buses. For accessing the child bus, iATU is used for address translation.

---
 xen/arch/arm/pci/Makefile         |   1 +
 xen/arch/arm/pci/pci-host-rcar4.c | 529 ++++++++++++++++++++++++++++++
 2 files changed, 530 insertions(+)
 create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c
xen/arch/arm/pci/Makefile +1 -0
index 1d045ade01..63ea86d9fa 100644
@@ -4,3 +4,4 @@ obj-y += pci-host-generic.o
 obj-y += pci-host-common.o
 obj-y += ecam.o
 obj-y += pci-host-zynqmp.o
+obj-y += pci-host-rcar4.o
xen/arch/arm/pci/pci-host-rcar4.c new file +529 -0

529 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 4/7] xen/arm: add support for R-Car Gen4 PCI host controller

Quoted 7 lines · Mykyta Poturai

From: Oleksandr Andrushchenko <[email protected]>

Add support for Renesas R-Car Gen4 PCI host controller.
S4 and V4H SoCs are supported.
Implement config read/write operations for both root and child buses. For accessing the child bus, iATU is used for address translation.

Quoted 7 lines
---
 xen/arch/arm/pci/Makefile         |   1 +
 xen/arch/arm/pci/pci-host-rcar4.c | 529 ++++++++++++++++++++++++++++++
 2 files changed, 530 insertions(+)
 create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c

Can any parts of this potentially be reused for other designware-based PCIe controllers? If so, could those parts be moved to a separate file?

#6 lore raw

Re: [PATCH 4/7] xen/arm: add support for R-Car Gen4 PCI host controller

Quoted 16 lines · Stewart Hildebrand
Quoted 7 lines · Mykyta Poturai

From: Oleksandr Andrushchenko <[email protected]>

Add support for Renesas R-Car Gen4 PCI host controller.
S4 and V4H SoCs are supported.
Implement config read/write operations for both root and child buses. For accessing the child bus, iATU is used for address translation.

Quoted 7 lines
---
  xen/arch/arm/pci/Makefile         |   1 +
  xen/arch/arm/pci/pci-host-rcar4.c | 529 ++++++++++++++++++++++++++++++
  2 files changed, 530 insertions(+)

create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c

Quoted 2 lines

Can any parts of this potentially be reused for other designware-based PCIe controllers? If so, could those parts be moved to a separate file?

Great idea! I will try to do a separation similar to how it's done in Linux.

Signature · 1 line
Mykyta
#7 lore raw

PATCH 5/7 xen/arm: rcar4: add delay after programming ATU

In reply to Mykyta Poturai

From: Volodymyr Babchuk <[email protected]>

For some reason, we need a delay before accessing ATU region after we programmed it. Otherwise, we'll get erroneous TLP.

There is a code below, which should do this in proper way, by polling CTRL2 register, but according to documentation, hardware does not change this ATU_ENABLE bit at all.

---
 xen/arch/arm/pci/pci-host-rcar4.c | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/pci/pci-host-rcar4.c +5 -0
index df337e3159..3b97bf138a 100644
@@ -289,6 +289,11 @@ static void dw_pcie_prog_outbound_atu_unroll(struct pci_host_bridge *pci,
     dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
                              PCIE_ATU_ENABLE);
 
+    /*
+     * HACK: We need to delay there, because the next code does not
+     * work as expected on S4
+     */
+    mdelay(1);
     /*
      * Make sure ATU enable takes effect before any subsequent config
      * and I/O accesses.
Signature · 1 line
2.34.1
#8 lore raw

PATCH 6/7 xen/arm: rcar4: add simple optimization to avoid ATU reprogramming

In reply to Mykyta Poturai

From: Volodymyr Babchuk <[email protected]>

There are high chances that there will be a number of a consecutive accesses to configuration space of one device. To speed things up, we can program ATU only during first access.

This is mostly beneficial taking into account the previous patch that adds 1ms delay after ATU reprogramming.

---
 xen/arch/arm/pci/pci-host-rcar4.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/arch/arm/pci/pci-host-rcar4.c +8 -0
index 3b97bf138a..3e3e073b09 100644
@@ -367,6 +367,14 @@ static void dw_pcie_prog_outbound_atu(struct pci_host_bridge *pci, int index,
                                       int type, uint64_t cpu_addr,
                                       uint64_t pci_addr, uint64_t size)
 {
+    static uint64_t prev_addr = ~0;
+
+    /* Simple optimization to not-program ATU for every transaction */
+    if (prev_addr == pci_addr)
+        return;
+
+    prev_addr = pci_addr;
+
     __dw_pcie_prog_outbound_atu(pci, 0, index, type,
                                 cpu_addr, pci_addr, size);
 }
Signature · 1 line
2.34.1
#9 lore raw

PATCH 7/7 xen/arm: rcar4: program ATU to accesses to all functions

In reply to Mykyta Poturai

From: Volodymyr Babchuk <[email protected]>

According to ATU documentation, bits [18:16] of accessed memory address correspond to a function number. This is somewhat similar to ECAM, but with huge holes between regions.

We can use this to minimize number of ATU re-programmings: configure ATU to access BDF with F=0 and adjust memory address with function number.

Taking into account the previous patch, that optimizes ATU reprogramming by skipping call to __dw_pcie_prog_outbound_atu() if we already configured pci_address, we can be sure that accesses to all functions of one device will not trigger ATU reprogramming at all.

---
 xen/arch/arm/pci/pci-host-rcar4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/pci/pci-host-rcar4.c +2 -2
index 3e3e073b09..5d006e4897 100644
@@ -385,7 +385,7 @@ static void __iomem *rcar4_child_map_bus(struct pci_host_bridge *bridge,
     uint32_t busdev;
 
     busdev = PCIE_ATU_BUS(sbdf.bus) | PCIE_ATU_DEV(PCI_SLOT(sbdf.devfn)) |
-        PCIE_ATU_FUNC(PCI_FUNC(sbdf.devfn));
+        PCIE_ATU_FUNC(0);
 
     /* FIXME: Parent is the root bus, so use PCIE_ATU_TYPE_CFG0. */
     dw_pcie_prog_outbound_atu(bridge, PCIE_ATU_REGION_INDEX1,
@@ -393,7 +393,7 @@ static void __iomem *rcar4_child_map_bus(struct pci_host_bridge *bridge,
                               bridge->child_cfg->phys_addr,
                               busdev, bridge->child_cfg->size);
 
-    return bridge->child_cfg->win + where;
+    return bridge->child_cfg->win + ((uint32_t)sbdf.fn << 16) + where;
 }
 
 static int rcar4_child_config_read(struct pci_host_bridge *bridge,
Signature · 1 line
2.34.1
#10 lore raw
In reply to Mykyta Poturai
Quoted 6 lines · Mykyta Poturai

This series adds support for R-Car Gen4 PCI host controller.

To fully support the controller, the following changes were made:
- Generic mechanism to support PCI child buses is added.
- Private data for PCI host bridge and means to access it are added.

Quoted 7 lines

The series also includes a workaround for proper ATU propramming and optimizations to lessen the performance impact of that workaround.

The series was tested both as a part of the pci-passthrough patches[1] and standalone on S4 and V4H boards.

[1] https://github.com/Deedone/xen/tree/pci_passthrough_wip

Hi Mykyta,

I understand the need for this patch series in the context of vPCI and PCI Passthrough.

You also mentioned that you tested it as a standalone, meaning without the PCI Passthrough patches. What is the purpose of this patch series without PCI Passthrough?

Cheers,

Stefano

Quoted 26 lines

Oleksandr Andrushchenko (4):
xen/arm: allow PCI host bridge to have private data xen/arm: make pci_host_common_probe return the bridge xen/arm: add support for PCI child bus xen/arm: add support for R-Car Gen4 PCI host controller

Volodymyr Babchuk (3):
xen/arm: rcar4: add delay after programming ATU xen/arm: rcar4: add simple optimization to avoid ATU reprogramming xen/arm: rcar4: program ATU to accesses to all functions

 xen/arch/arm/include/asm/pci.h      |  16 +-
 xen/arch/arm/pci/Makefile           |   1 +
 xen/arch/arm/pci/ecam.c             |  17 +-
 xen/arch/arm/pci/pci-access.c       |  37 +-
 xen/arch/arm/pci/pci-host-common.c  | 106 +++++-
 xen/arch/arm/pci/pci-host-generic.c |   2 +-
 xen/arch/arm/pci/pci-host-rcar4.c   | 542 ++++++++++++++++++++++++++++
 xen/arch/arm/pci/pci-host-zynqmp.c  |   2 +-
 xen/arch/arm/vpci.c                 |  91 ++++-
 9 files changed, 764 insertions(+), 50 deletions(-)
 create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c
Signature · 1 line
2.34.1
#11 lore raw
Quoted 19 lines · Stefano Stabellini
Quoted 6 lines · Mykyta Poturai

This series adds support for R-Car Gen4 PCI host controller.

To fully support the controller, the following changes were made:
- Generic mechanism to support PCI child buses is added.
- Private data for PCI host bridge and means to access it are added.

Quoted 6 lines

The series also includes a workaround for proper ATU propramming and optimizations to lessen the performance impact of that workaround.

The series was tested both as a part of the pci-passthrough patches[1] and standalone on S4 and V4H boards.

Hi Mykyta,

I understand the need for this patch series in the context of vPCI and PCI Passthrough.

Quoted 7 lines

You also mentioned that you tested it as a standalone, meaning without the PCI Passthrough patches. What is the purpose of this patch series without PCI Passthrough?

Cheers,

Stefano

Hi Stefano

I just checked that it doesn't break anything if I force enable HAS_VPCI on the current master, without additional pci-passthrough patches.

However, while trying to confirm this, I have discovered that I somehow missed some fixups during patch preparations so this claim is sadly not true for this version of the series. And I have also found another issue with this while working on other series.

So please wait for V2 before looking further at this series, I will send it soon.

Signature · 1 line
Mykyta
Quoted 29 lines
Quoted 29 lines

Oleksandr Andrushchenko (4):
xen/arm: allow PCI host bridge to have private data xen/arm: make pci_host_common_probe return the bridge xen/arm: add support for PCI child bus xen/arm: add support for R-Car Gen4 PCI host controller

Volodymyr Babchuk (3):
xen/arm: rcar4: add delay after programming ATU xen/arm: rcar4: add simple optimization to avoid ATU reprogramming xen/arm: rcar4: program ATU to accesses to all functions

  xen/arch/arm/include/asm/pci.h      |  16 +-
  xen/arch/arm/pci/Makefile           |   1 +
  xen/arch/arm/pci/ecam.c             |  17 +-
  xen/arch/arm/pci/pci-access.c       |  37 +-
  xen/arch/arm/pci/pci-host-common.c  | 106 +++++-
  xen/arch/arm/pci/pci-host-generic.c |   2 +-
  xen/arch/arm/pci/pci-host-rcar4.c   | 542 ++++++++++++++++++++++++++++
  xen/arch/arm/pci/pci-host-zynqmp.c  |   2 +-
  xen/arch/arm/vpci.c                 |  91 ++++-
  9 files changed, 764 insertions(+), 50 deletions(-)

create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c

Signature · 1 line
2.34.1