Skip to contentSkip to conversation

PCI: emulated PCI bridge config space

PATCH New Thomas Petazzoni 2 participants 6 messages Oct 18, 2018

Subsystems (4)
lore
Share & tools
lore

Thomas Petazzoni

author maintainer
#0 lore raw

v3 cover PCI: emulated PCI bridge config space

Hello,

The pci-mvebu driver already contains some logic to emulate a root port PCI bridge configuration space. It turns out that we have a similar need for the pci-aardvark driver. Instead of duplicating the same logic in two drivers, this patch series starts by adding a small common infrastructure that helps emulate a root port PCI bridge config space, converts pci-mvebu to use it, and finally extends pci-aardvark to use it as well.

Thanks to this, Marvell Armada 3720 based systems, which use the Aarkvark PCI controller, will have better PCI support, by having a root port PCI bridge exposed.

The emulated PCI bridge common logic is a proposal, I very much welcome comments and suggestions. Also, if you feel that adding a common logic for only two drivers is too early, I'm fine with duplicating a bit of code betwen pci-mvebu and pci-aardvark.

Changes v2 -> v3:

- Address the FIXME comment that was pointed out by Russell. In fact the |= pcie_devctl was not needed, because pcie_devctl is always zero. To fix this, an additional commit was added to the series to drop the use of unneeded fields in the PCI Express capability block emulation in pci-mvebu.

- Drop some more code from pci-mvebu that was used to prevent messing up with W1C bits, because this is now already taken care of by the common bridge emulation logic.

- Fixed the commit log of "PCI: mvebu: Convert to PCI emulated bridge config space" according to Lorenzo comments.

- Use PCI_STD_HEADER_SIZEOF when defining PCI_BRIDGE_CONTROL, as suggested by Bjorn.

- Added Bjorn Acked-by and Russell Reviewed-by on the patch adding the common logic.

Changes v1 -> v2:

- Rebased to 4.19-rc1

- The functions implementing the config space read/write emulation now have the knowledge of which registers/bits are read-only, read-write, reserved and write-1-to-clear, and behave according to this information.

- I have renamed the function to use conf_read() and conf_write() suffixes, as suggested by Bjorn.

- The whole thing is now named pci-bridge-emul instead of pci-sw-bridge (and of course all functions, types and macros were changed accordingly), as Bjorn wasn't happy about pci-sw-bridge.

- The header file was moved into drivers/pci (instead of being in include/linux).

Thanks a lot in advance for your review and feedback.

Best regards,

Thomas Petazzoni

Thomas Petazzoni (3):
PCI: Introduce PCI bridge emulated config space common logic
PCI: mvebu: Drop unused PCI express capability code
PCI: mvebu: Convert to PCI emulated bridge config space

Zachary Zhang (1):
PCI: aardvark: Implement emulated root PCI bridge config space

 drivers/pci/Kconfig                   |   3 +
 drivers/pci/Makefile                  |   1 +
 drivers/pci/controller/Kconfig        |   2 +
 drivers/pci/controller/pci-aardvark.c | 129 ++++++++++-
 drivers/pci/controller/pci-mvebu.c    | 384 +++++++++-----------------------
 drivers/pci/pci-bridge-emul.c         | 408 ++++++++++++++++++++++++++++++++++
 drivers/pci/pci-bridge-emul.h         | 124 +++++++++++
 7 files changed, 764 insertions(+), 287 deletions(-)
 create mode 100644 drivers/pci/pci-bridge-emul.c
 create mode 100644 drivers/pci/pci-bridge-emul.h
Signature · 1 line
2.14.4
author maintainer
#1 lore raw

PATCH v3 1/4 PCI: Introduce PCI bridge emulated config space common logic

Some PCI host controllers do not expose a configuration space for the root port PCI bridge. Due to this, the Marvell Armada 370/38x/XP PCI controller driver (pci-mvebu) emulates a root port PCI bridge configuration space, and uses that to (among other things) dynamically create the memory windows that correspond to the PCI MEM and I/O regions.

Since we now need to add a very similar logic for the Marvell Armada 37xx PCI controller driver (pci-aardvark), instead of duplicating the code, we create in this commit a common logic called pci-bridge-emul.

The idea of this logic is to emulate a root port PCI bridge configuration space by providing configuration space read/write operations, and faking behind the scenes the configuration space of a PCI bridge. A PCI host controller driver simply has to call pci_bridge_emul_conf_read() and pci_bridge_emul_conf_write() to read/write the configuration space of the bridge.

By default, the PCI bridge configuration space is simply emulated by a chunk of memory, but the PCI host controller can override the behavior of the read and write operations on a per-register basis to do additional actions if needed. We take care of complying with the behavior of the PCI configuration space registers in terms of bits that are read-write, read-only, reserved and write-1-to-clear.

---
 drivers/pci/Kconfig           |   3 +
 drivers/pci/Makefile          |   1 +
 drivers/pci/pci-bridge-emul.c | 408 ++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/pci-bridge-emul.h | 124 +++++++++++++
 4 files changed, 536 insertions(+)
 create mode 100644 drivers/pci/pci-bridge-emul.c
 create mode 100644 drivers/pci/pci-bridge-emul.h
drivers/pci/Kconfig +3 -0
index 56ff8f6d31fc..4a28e07d4c0e 100644
@@ -98,6 +98,9 @@ config PCI_ECAM
 config PCI_LOCKLESS_CONFIG
 	bool
 
+config PCI_BRIDGE_EMUL
+	bool
+
 config PCI_IOV
 	bool "PCI IOV support"
 	depends on PCI
drivers/pci/Makefile +1 -0
index 1b2cfe51e8d7..3e5caf7347e9 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_HOTPLUG_PCI)	+= hotplug/
 obj-$(CONFIG_PCI_MSI)		+= msi.o
 obj-$(CONFIG_PCI_ATS)		+= ats.o
 obj-$(CONFIG_PCI_IOV)		+= iov.o
+obj-$(CONFIG_PCI_BRIDGE_EMUL)	+= pci-bridge-emul.o
 obj-$(CONFIG_ACPI)		+= pci-acpi.o
 obj-$(CONFIG_PCI_LABEL)		+= pci-label.o
 obj-$(CONFIG_X86_INTEL_MID)	+= pci-mid.o
drivers/pci/pci-bridge-emul.c new file +408 -0

408 lines not on this page · raw message

drivers/pci/pci-bridge-emul.h new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.14.4
author maintainer
#2 lore raw

PATCH v3 2/4 PCI: mvebu: Drop unused PCI express capability code

In reply to Thomas Petazzoni

Commit dc0352ab0b2a0 ("PCI: mvebu: Add PCI Express root complex capability block") added support for emulating the PCI Express capability block. As part of this, the pcie_sltcap, pcie_devctl and pcie_rtctl fields were added to the mvebu_sw_pci_bridge structure, and used when reading the corresponding PCI Express capability block registers.

However, those structure members are never set to any value other than zero. This makes them unneeded because:

- pcie_devctl is used to OR *value, so with pcie_devctl always zero, it has no effect.

- for pcie_sltcap and pcie_rtstl, the mvebu_sw_pci_bridge_read() function always returns 0 for registers that are not explicitly handled.

In preparation for reworking the PCI bridge emulation logic in pci-mvebu, let's simplify the code by dropping those structure members.

---
 drivers/pci/controller/pci-mvebu.c | 14 --------------
 1 file changed, 14 deletions(-)
drivers/pci/controller/pci-mvebu.c +0 -14
index 50eb0729385b..beaff9325a09 100644
@@ -111,11 +111,6 @@ struct mvebu_sw_pci_bridge {
 	u8 intline;
 	u8 intpin;
 	u16 bridgectrl;
-
-	/* PCI express capability */
-	u32 pcie_sltcap;
-	u16 pcie_devctl;
-	u16 pcie_rtctl;
 };
 
 struct mvebu_pcie_port;
@@ -588,7 +583,6 @@ static int mvebu_sw_pci_bridge_read(struct mvebu_pcie_port *port,
 		*value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL) &
 				 ~(PCI_EXP_DEVCTL_URRE | PCI_EXP_DEVCTL_FERE |
 				   PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_CERE);
-		*value |= bridge->pcie_devctl;
 		break;
 
 	case PCISWCAP_EXP_LNKCAP:
@@ -604,18 +598,10 @@ static int mvebu_sw_pci_bridge_read(struct mvebu_pcie_port *port,
 		*value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL);
 		break;
 
-	case PCISWCAP_EXP_SLTCAP:
-		*value = bridge->pcie_sltcap;
-		break;
-
 	case PCISWCAP_EXP_SLTCTL:
 		*value = PCI_EXP_SLTSTA_PDS << 16;
 		break;
 
-	case PCISWCAP_EXP_RTCTL:
-		*value = bridge->pcie_rtctl;
-		break;
-
 	case PCISWCAP_EXP_RTSTA:
 		*value = mvebu_readl(port, PCIE_RC_RTSTA);
 		break;
Signature · 1 line
2.14.4
author maintainer
#3 lore raw

PATCH v3 3/4 PCI: mvebu: Convert to PCI emulated bridge config space

In reply to Thomas Petazzoni

Convert the pci-mvebu driver to use the pci-bridge-emul logic, that helps emulating a root port PCI bridge configuration space.

It has been tested on Armada GP XP, with a E1000E NIC.

---
 drivers/pci/controller/Kconfig     |   1 +
 drivers/pci/controller/pci-mvebu.c | 370 ++++++++++---------------------------
 2 files changed, 101 insertions(+), 270 deletions(-)
drivers/pci/controller/Kconfig +1 -0
index 028b287466fb..6d0f9930be7f 100644
@@ -9,6 +9,7 @@ config PCI_MVEBU
 	depends on MVEBU_MBUS
 	depends on ARM
 	depends on OF
+	select PCI_BRIDGE_EMUL
 
 config PCI_AARDVARK
 	bool "Aardvark PCIe controller"
drivers/pci/controller/pci-mvebu.c +100 -270

527 lines not on this page · raw message

Signature · 1 line
2.14.4
author maintainer
#4 lore raw

PATCH v3 4/4 PCI: aardvark: Implement emulated root PCI bridge config space

In reply to Thomas Petazzoni

From: Zachary Zhang <[email protected]>

The PCI controller in the Marvell Armada 3720 does not implement a software-accessible root port PCI bridge configuration space. This causes a number of problems when using PCIe switches or when the Max Payload size needs to be aligned between the root complex and the endpoint.

Implementing an emulated root PCI bridge, like is already done in the pci-mvebu driver for older Marvell platforms allows to solve those issues, and also to support features such as ASR, PME, VC, HP.

[Thomas: convert to the common emulated PCI bridge logic.]
---
 drivers/pci/controller/Kconfig        |   1 +
 drivers/pci/controller/pci-aardvark.c | 129 +++++++++++++++++++++++++++++++++-
 2 files changed, 127 insertions(+), 3 deletions(-)
drivers/pci/controller/Kconfig +1 -0
index 6d0f9930be7f..5d76ef51532d 100644
@@ -16,6 +16,7 @@ config PCI_AARDVARK
 	depends on (ARCH_MVEBU && ARM64) || COMPILE_TEST
 	depends on OF
 	depends on PCI_MSI_IRQ_DOMAIN
+	select PCI_BRIDGE_EMUL
 	help
 	 Add support for Aardvark 64bit PCIe Host Controller. This
 	 controller is part of the South Bridge of the Marvel Armada
drivers/pci/controller/pci-aardvark.c +126 -3

196 lines not on this page · raw message

Signature · 1 line
2.14.4
#5 lore raw

v3 cover PCI: emulated PCI bridge config space

In reply to Thomas Petazzoni
Quoted 73 lines · Thomas Petazzoni

Hello,

The pci-mvebu driver already contains some logic to emulate a root port PCI bridge configuration space. It turns out that we have a similar need for the pci-aardvark driver. Instead of duplicating the same logic in two drivers, this patch series starts by adding a small common infrastructure that helps emulate a root port PCI bridge config space, converts pci-mvebu to use it, and finally extends pci-aardvark to use it as well.

Thanks to this, Marvell Armada 3720 based systems, which use the Aarkvark PCI controller, will have better PCI support, by having a root port PCI bridge exposed.

The emulated PCI bridge common logic is a proposal, I very much welcome comments and suggestions. Also, if you feel that adding a common logic for only two drivers is too early, I'm fine with duplicating a bit of code betwen pci-mvebu and pci-aardvark.

Changes v2 -> v3:

- Address the FIXME comment that was pointed out by Russell. In fact the |= pcie_devctl was not needed, because pcie_devctl is always zero. To fix this, an additional commit was added to the series to drop the use of unneeded fields in the PCI Express capability block emulation in pci-mvebu.

- Drop some more code from pci-mvebu that was used to prevent messing up with W1C bits, because this is now already taken care of by the common bridge emulation logic.

- Fixed the commit log of "PCI: mvebu: Convert to PCI emulated bridge config space" according to Lorenzo comments.

- Use PCI_STD_HEADER_SIZEOF when defining PCI_BRIDGE_CONTROL, as suggested by Bjorn.

- Added Bjorn Acked-by and Russell Reviewed-by on the patch adding the common logic.

Changes v1 -> v2:

- Rebased to 4.19-rc1

- The functions implementing the config space read/write emulation now have the knowledge of which registers/bits are read-only, read-write, reserved and write-1-to-clear, and behave according to this information.

- I have renamed the function to use conf_read() and conf_write() suffixes, as suggested by Bjorn.

- The whole thing is now named pci-bridge-emul instead of pci-sw-bridge (and of course all functions, types and macros were changed accordingly), as Bjorn wasn't happy about pci-sw-bridge.

- The header file was moved into drivers/pci (instead of being in include/linux).

Thanks a lot in advance for your review and feedback.

Best regards,

Thomas Petazzoni

Thomas Petazzoni (3):
PCI: Introduce PCI bridge emulated config space common logic
PCI: mvebu: Drop unused PCI express capability code
PCI: mvebu: Convert to PCI emulated bridge config space

Zachary Zhang (1):
PCI: aardvark: Implement emulated root PCI bridge config space

Quoted 10 lines
 drivers/pci/Kconfig                   |   3 +
 drivers/pci/Makefile                  |   1 +
 drivers/pci/controller/Kconfig        |   2 +
 drivers/pci/controller/pci-aardvark.c | 129 ++++++++++-
 drivers/pci/controller/pci-mvebu.c    | 384 +++++++++-----------------------
 drivers/pci/pci-bridge-emul.c         | 408 ++++++++++++++++++++++++++++++++++
 drivers/pci/pci-bridge-emul.h         | 124 +++++++++++
 7 files changed, 764 insertions(+), 287 deletions(-)
 create mode 100644 drivers/pci/pci-bridge-emul.c
 create mode 100644 drivers/pci/pci-bridge-emul.h

I have applied the series with Bjorn and Russell ACKs to pci/controller-misc, tentatively for v4.20.

Thanks !
Lorenzo