Add support for R-Car Gen4 PCI host controller
Subsystems (2)
v6 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 was tested as a part of the pci-passthrough patches[1] and build-tested standalone with enabled HAS_PCI and HAS_VPCI. CI pipeline results: [2]
[1]: https://github.com/Deedone/xen/tree/pci_passthrough_wip
[2]: https://gitlab.com/xen-project/people/mpoturai/xen/-/pipelines/1828720661
v5->v6:
* see individual patches
v4->v5:
* see individual patches
v3->v4:
* rebase
* see individual patches
v2->v3:
* dropped patches related to ATU programming delay
* improved formatting
v1->v2:
* see individual patches
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
MAINTAINERS | 5 + xen/arch/arm/include/asm/pci.h | 22 +- xen/arch/arm/pci/Makefile | 2 + xen/arch/arm/pci/ecam.c | 1 + xen/arch/arm/pci/pci-access.c | 37 ++- xen/arch/arm/pci/pci-designware.c | 405 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-designware.h | 90 +++++++ xen/arch/arm/pci/pci-host-common.c | 92 +++++-- xen/arch/arm/pci/pci-host-generic.c | 2 +- xen/arch/arm/pci/pci-host-rcar4.c | 94 +++++++ xen/arch/arm/pci/pci-host-zynqmp.c | 3 +- xen/arch/arm/vpci.c | 91 +++++-- 12 files changed, 796 insertions(+), 48 deletions(-) create mode 100644 xen/arch/arm/pci/pci-designware.c create mode 100644 xen/arch/arm/pci/pci-designware.h create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c
Signature · 1 line
2.34.1
PATCH v6 1/4 xen/arm: allow PCI host bridge to have private data
From: Oleksandr Andrushchenko <[email protected]>
Some of the PCI host bridges require private data. Add priv field to struct pci_host_bridge, so such bridges may populate it with their private data.
---v5->v6:
* no change
v4->v5:
* no change
v3->v4:
* Added Stefano's RB
v2->v3:
* removed priv allocation from common code
v1->v2:
* no change
--- xen/arch/arm/include/asm/pci.h | 1 + 1 file changed, 1 insertion(+)
xen/arch/arm/include/asm/pci.h +1 -0
@@ -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 {
Signature · 1 line
2.34.1
PATCH v6 2/4 xen/arm: make pci_host_common_probe return the bridge
In reply to Mykyta PoturaiFrom: 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.
---v5->v6:
* no change
v4->v5:
* added Stefano's RB
v3->v4:
* change return 0 to return NULL
v2->v3:
* no change
v1->v2:
* no change
--- xen/arch/arm/include/asm/pci.h | 5 +++-- 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, 11 insertions(+), 10 deletions(-)
xen/arch/arm/include/asm/pci.h +3 -2
@@ -18,6 +18,7 @@#ifdef CONFIG_HAS_PCI #include <asm/p2m.h> +#include <xen/err.h> #define pci_to_dev (pcidev) (&(pcidev)->arch.dev)
@@ -95,8 +96,8 @@ 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); +struct pci_host_bridge *pci_host_common_probe (struct dt_device_node *dev, +const struct pci_ecam_ops *ops);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
@@ -208,8 +208,8 @@ 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) +struct pci_host_bridge *pci_host_common_probe (struct dt_device_node *dev, +const struct pci_ecam_ops *ops) {struct pci_host_bridge *bridge;struct pci_config_window *cfg;
@@ -217,11 +217,11 @@ int pci_host_common_probe(struct dt_device_node *dev,int domain;if (dt_device_for_passthrough (dev) ) -return 0 ; +return NULL ; 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);
@@ -244,12 +244,12 @@ int pci_host_common_probe(struct dt_device_node *dev, bridge->segment = domain;pci_add_host_bridge (bridge); -return 0 ; +return bridge; err_exit:xfree (bridge); -return err; +return ERR_PTR (err); }/*
xen/arch/arm/pci/pci-host-generic.c +1 -1
@@ -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 PTR_RET (pci_host_common_probe (dev, &pci_generic_ecam_ops)); }DT_DEVICE_START (pci_gen,"PCI HOST GENERIC" ,DEVICE_PCI_HOSTBRIDGE )
xen/arch/arm/pci/pci-host-zynqmp.c +1 -1
@@ -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 PTR_RET (pci_host_common_probe (dev, &nwl_pcie_ops)); }DT_DEVICE_START (pci_gen,"PCI HOST ZYNQMP" ,DEVICE_PCI_HOSTBRIDGE )
Signature · 1 line
2.34.1
PATCH v6 3/4 xen/arm: add support for PCI child bus
In reply to Mykyta PoturaiFrom: 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 for hardware domain
- 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
---v5->v6:
* no change
v4->v5:
* fix formatting
* move init_bus_range inside pci_ops
* fix logic error in pci_host_bridge_mappings again
v3->v4:
* remove changes to pci_ecam_map_bus
* make map_bus inline
* fix logic error in pci_host_bridge_mappings
v2->v3:
* no change
v1->v2:
* fixed compilation issues
--- xen/arch/arm/include/asm/pci.h | 20 ++++++- xen/arch/arm/pci/ecam.c | 1 + xen/arch/arm/pci/pci-access.c | 37 ++++++++++-- xen/arch/arm/pci/pci-host-common.c | 84 +++++++++++++++++++++----- xen/arch/arm/pci/pci-host-generic.c | 2 +- xen/arch/arm/pci/pci-host-zynqmp.c | 3 +- xen/arch/arm/vpci.c | 91 +++++++++++++++++++++++------ 7 files changed, 194 insertions(+), 44 deletions(-)
xen/arch/arm/include/asm/pci.h +18 -2
@@ -67,6 +67,9 @@ 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; +/* Child bus */ +struct pci_config_window *child_cfg; +const struct pci_ops *child_ops;void *priv;/* Private data of the bridge. */ };
@@ -80,6 +83,9 @@ struct pci_ops {bool (*need_p2m_hwdom_mapping)(struct domain *d,struct pci_host_bridge *bridge,uint64_t addr); +void (*init_bus_range)(struct dt_device_node *dev, +struct pci_host_bridge *bridge, +struct pci_config_window *cfg); };/*
@@ -96,8 +102,10 @@ 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); +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);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,
@@ -133,6 +141,14 @@ bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end);static inline int pci_sanitize_bar_memory (struct rangeset *r) {return 0 ; } +void pci_generic_init_bus_range (struct dt_device_node *dev, +struct pci_host_bridge *bridge, +struct pci_config_window *cfg); + +void pci_generic_init_bus_range_child (struct dt_device_node *dev, +struct pci_host_bridge *bridge, +struct pci_config_window *cfg); +#else /*!CONFIG_HAS_PCI*/ struct pci_dev ;
xen/arch/arm/pci/ecam.c +1 -0
@@ -60,6 +60,7 @@ const struct pci_ecam_ops pci_generic_ecam_ops = { .read = pci_generic_config_read, .write = pci_generic_config_write, .need_p2m_hwdom_mapping = pci_ecam_need_p2m_hwdom_mapping, + .init_bus_range = pci_generic_init_bus_range, } };
xen/arch/arm/pci/pci-access.c +31 -6
@@ -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 inline 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 +68 -16
138 lines not on this page · raw message
xen/arch/arm/pci/pci-host-generic.c +1 -1
@@ -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)); +return PTR_RET (pci_host_common_probe (dev, &pci_generic_ecam_ops,NULL )); }DT_DEVICE_START (pci_gen,"PCI HOST GENERIC" ,DEVICE_PCI_HOSTBRIDGE )
xen/arch/arm/pci/pci-host-zynqmp.c +2 -1
@@ -35,6 +35,7 @@ const struct pci_ecam_ops nwl_pcie_ops = { .read = pci_generic_config_read, .write = pci_generic_config_write, .need_p2m_hwdom_mapping = pci_ecam_need_p2m_hwdom_mapping, + .init_bus_range = pci_generic_init_bus_range, } };
@@ -47,7 +48,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)); +return PTR_RET (pci_host_common_probe (dev, &nwl_pcie_ops,NULL )); }DT_DEVICE_START (pci_gen,"PCI HOST ZYNQMP" ,DEVICE_PCI_HOSTBRIDGE )
xen/arch/arm/vpci.c +73 -18
147 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v6 3/4] xen/arm: add support for PCI child bus
Quoted 30 lines · 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_opsto 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
- makepci_find_host_bridgebe aware of multiple busses behind the same bridge
- updatepci_host_bridge_mappings, so it also doesn't map to guest the memory spaces belonging to the child bus
- makepci_host_common_probeaccept one morepci_opsstructure for the child bus
- install MMIO handlers for the child bus for hardware domain
- 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
Signed-off-by Oleksandr Andrushchenko <[email protected]>Signed-off-by Mykyta Poturai <[email protected]>
[...]
Quoted 29 lines
xen/arch/arm/pci/pci-host-common.c +4
-9@@ -57,17 +57,12 @@ static void pci_ecam_free(struct pci_config_window *cfg)xfree (cfg); } -static struct pci_config_window *__init -gen_pci_init (struct dt_device_node *dev,const struct pci_ecam_ops *ops) +void __init pci_generic_init_bus_range (struct dt_device_node *dev, +struct pci_host_bridge *bridge, +struct pci_config_window *cfg) { -int err, cfg_reg_idx;u32 bus_range[2 ]; -paddr_t addr, size; -struct pci_config_window *cfg; - - cfg = xzalloc(struct pci_config_window); -if ( !cfg ) -return NULL ; +int err; err =dt_property_read_u32_array (dev,"bus-range" , bus_range,ARRAY_SIZE (bus_range));@@ -82,6 +77,35 @@ gen_pci_init(struct dt_device_node *dev, const struct pci_ecam_ops *ops)if ( cfg->busn_end > cfg->busn_start +0xff ) cfg->busn_end = cfg->busn_start +0xff ;
xen/arch/arm/pci/pci-host-common.c gen_pci_init(struct dt_device_node *dev, const struct pci_ecam_ops *ops) · line 88
Quoted 10 lines
xen/arch/arm/pci/pci-host-common.c +9
-0} +} + +void __init pci_generic_init_bus_range_child (struct dt_device_node *dev, +struct pci_host_bridge *bridge, +struct pci_config_window *cfg) +{ + cfg->busn_start = bridge->cfg->busn_start +1 ; + cfg->busn_end = bridge->cfg->busn_end; + bridge->cfg->busn_end = bridge->cfg->busn_start;
I think Stewart meant that pci_generic_init_bus_range_child should be renamed pci_designware_init_bus_range_child and moved to pci-designware.c.
However, given that we don't have a second user of this and I am not certain how generic (or not) this bus_range_child function is, also considering the other comments have been addressed:
It can be moved later as appropriate if this turns out not to be generic once we have a second user.
Quoted 3 lines
xen/arch/arm/pci/pci-host-common.c +3
-0+printk (XENLOG_INFO "Root bus end updated: [bus %x-%x]\n" , + bridge->cfg->busn_start, bridge->cfg->busn_end); +}
PATCH v6 4/4 xen/arm: add support for R-Car Gen4 PCI host controller
In reply to Mykyta PoturaiFrom: Oleksandr Andrushchenko <[email protected]>
Add support for Renesas R-Car Gen4 PCI host controller, specifically targeting the S4 and V4H SoCs. The implementation includes configuration read/write operations for both root and child buses. For accessing the child bus, iATU is used for address translation.
The host controller needs to be initialized by Dom0 first to be properly handled by Xen. Xen itself only handles the runtime configuration of the iATU for accessing different child devices.
iATU programming is done similarly to Linux, where only window 0 is used for dynamic configuration, and it is reconfigured for every config space read/write.
Code common to all DesignWare PCI host controllers is located in a separate file to allow for easy reuse in other DesignWare-based PCI host controllers.
---v5->v6:
* add Stefano's AB
* rename LINK_WAIT_IATU to LINK_WAIT_IATU_DELAY_MS
* remove unimplemented dw_pcie_enable_ecrc
* improve error messages
* use unsigned types for len
* Remove xen/arch/arm/pci/pci-designware* maintainer entry to leave it to ARM section
v4->v5:
* update license identifiers
* improve error checking
* use XENLOG_G_* where needed
* make macro defs more robust and minor style fixes
* add MAINTANERS entry
v3->v4:
* no changes
v2->v3:
* move priv allocation to dw_pcie_host_probe
v1->v2:
* move designware code in a separate file
--- MAINTAINERS | 5 + xen/arch/arm/pci/Makefile | 2 + xen/arch/arm/pci/pci-designware.c | 405 ++++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-designware.h | 90 +++++++ xen/arch/arm/pci/pci-host-rcar4.c | 94 +++++++ 5 files changed, 596 insertions(+) create mode 100644 xen/arch/arm/pci/pci-designware.c create mode 100644 xen/arch/arm/pci/pci-designware.h create mode 100644 xen/arch/arm/pci/pci-host-rcar4.c
MAINTAINERS +5 -0
@@ -473,6 +473,11 @@ M: Anthony Perard <[email protected]> S: Supported T: git https://xenbits.xenproject.org/git-http/qemu-xen.git +RCAR PCI +M: Mykyta Poturai <[email protected]> +S: Supported +F: xen/arch/arm/pci/pci-host-rcar4.c + REMUS S: Orphan F: docs/README.remus
xen/arch/arm/pci/Makefile +2 -0
@@ -4,3 +4,5 @@ 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-designware.o +obj-y += pci-host-rcar4.o
xen/arch/arm/pci/pci-designware.c new file +405 -0
405 lines not on this page · raw message
xen/arch/arm/pci/pci-designware.h new file +90 -0
90 lines not on this page · raw message
xen/arch/arm/pci/pci-host-rcar4.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.34.1