Commit Graph

23 Commits

Author SHA1 Message Date
Marek Szyprowski
ddad1465f6 PCI: brcmstb: Fix build on 32bit ARM platforms with older compilers
commit 73a7a271b3 upstream.

Some older compilers have no implementation for the helper for 64-bit
unsigned division/modulo, so linking pcie-brcmstb driver causes the
"undefined reference to `__aeabi_uldivmod'" error.

*rc_bar2_size is always a power of two, because it is calculated as:
"1ULL << fls64(entry->res->end - entry->res->start)", so the modulo
operation in the subsequent check can be replaced by a simple logical
AND with a proper mask.

Link: https://lore.kernel.org/r/20200227115146.24515-1-m.szyprowski@samsung.com
Fixes: c045213703 ("PCI: brcmstb: Add Broadcom STB PCIe host controller driver")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2020-05-20 13:49:39 +01:00
Jim Quinlan
d66893571f PCI: brcmstb: Add MSI support
commit 40ca1bf580 upstream.

This adds MSI support to the Broadcom STB PCIe host controller. The MSI
controller is physically located within the PCIe block, however, there
is no reason why the MSI controller could not be moved elsewhere in the
future. MSIX is not supported by the HW.

Since the internal Brcmstb MSI controller is intertwined with the PCIe
controller, it is not its own platform device but rather part of the
PCIe platform device.

Signed-off-by: Jim Quinlan <james.quinlan@broadcom.com>
Co-developed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
2020-05-20 13:49:39 +01:00
Jim Quinlan
b2ebf84cfe PCI: brcmstb: Add Broadcom STB PCIe host controller driver
commit c045213703 upstream.

This adds a basic driver for Broadcom's STB PCIe controller, for now
aimed at Raspberry Pi 4's SoC, bcm2711.

Signed-off-by: Jim Quinlan <james.quinlan@broadcom.com>
Co-developed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
[lorenzo.pieralisi@arm.com: updated brcm_pcie_get_rc_bar2_size_and_offset()according to https://lore.kernel.org/linux-pci/be8ddb33a7360af1815cf686f77f3f0913d02be3.camel@suse.de]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>
2020-05-20 13:49:39 +01:00
Phil Elwell
82287214ea Revert "PCI: brcmstb: Add Broadcom STB PCIe host controller driver"
This reverts commit 384cf27ff6a44e225fed06158ded5a7d408d3f73.
2020-05-20 13:49:38 +01:00
Phil Elwell
9ee5995893 Revert "PCI: brcmstb: Add dma-range mapping for inbound traffic"
This reverts commit 063c473df854f6634bd78f941119136e3ff63c8b.
2020-05-20 13:49:38 +01:00
Phil Elwell
ec8c475e51 Revert "PCI: brcmstb: Add MSI capability"
This reverts commit 835bc8fb5bfad613c2befd483c43c6d4b4f9aec7.
2020-05-20 13:49:38 +01:00
Phil Elwell
6ccd01d500 Revert "pcie-brcmstb: Changes for BCM2711"
This reverts commit f0acf98fed6a62a72c2218fc3debbf0e2b0ba929.
2020-05-20 13:49:38 +01:00
Phil Elwell
a089841653 Revert "bcm2835-dma: Add proper 40-bit DMA support"
This reverts commit 9408d6c0bc88fa8acbb0e12340802a653cc6c532.
2020-05-20 13:49:38 +01:00
Phil Elwell
b6aa95d780 Revert "pcie-brcmstb: Don't set DMA ops for root complex"
This reverts commit deed864a763ab0b7c45e4bc60f76470480ba625f.
2020-05-20 13:49:38 +01:00
Phil Elwell
93091b550f Revert "Ported pcie-brcmstb bounce buffer implementation to ARM64. (#3144)"
This reverts commit 86be3b54bfd138a6fd1842d0eaf337cfc91679bc.
2020-05-20 13:49:38 +01:00
Phil Elwell
346454cab2 Revert "pcie-brcmstb: Remove brcm_to_*, add pcie_to_dma40"
This reverts commit 4f8cad8c3b59f924d7a6773533f8592e4bf97af0.
2020-05-20 13:49:37 +01:00
Phil Elwell
b13d1662c9 Revert "pcie-brcmstb: Eliminate arch_dma_ops error message"
This reverts commit f8710daa77a98f99348f34fbd68fcb8fb8298ace.
2020-05-20 13:49:37 +01:00
Phil Elwell
04cc412b82 Revert "pcie-brcmstb: Bounce buffer support is for BCM2711B0"
This reverts commit 7f907b4f4e89ac30f7bb63df3202e96d184a3aa8.
2020-05-20 13:49:37 +01:00
Phil Elwell
18d67af4a1 pcie-brcmstb: Bounce buffer support is for BCM2711B0
Add a new compatible string to identify BCM2711B0, as later revisions
don't require the bounce buffer support.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:32 +01:00
Phil Elwell
3eabc13505 pcie-brcmstb: Eliminate arch_dma_ops error message
The driver attempts to set the dma_ops for the root complex, but doing
so causes an error message and only the end points need it. Fix the
error by making the code specific to the end point case.

Also copy some cosmetic tidy-ups from 5.5.y.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:28 +01:00
Phil Elwell
2cc84fe369 pcie-brcmstb: Remove brcm_to_*, add pcie_to_dma40
The DMA framework performs the necessary address conversions for the
common cases based on the dma-ranges DT property. brcm_to_pci and
brcm_to_cpu were probably designed for non-DT use cases, something
which isn't an issue for 2711. This second level of mapping causes
breakage with a non-identity PCIe<->system address mapping, so remove
it completely.

The non-identity mapping also broke the DMA40 support, so add back a
simple translation from PCIe to sys addresses.

arm64 builds also require a wider coherent_dma_mask, otherwise the
bounce buffer allocation is rejected.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:27 +01:00
yaroslavros
0c5396c48c Ported pcie-brcmstb bounce buffer implementation to ARM64. (#3144)
Ported pcie-brcmstb bounce buffer implementation to ARM64.
This enables full 4G RAM usage on Raspberry Pi in 64-bit mode.

Signed-off-by: Yaroslav Rosomakho <yaroslavros@gmail.com>
2020-05-20 13:49:17 +01:00
Phil Elwell
777f0240db pcie-brcmstb: Don't set DMA ops for root complex
A change to arm_get_dma_map_ops has stopped get_dma_ops from working
on the root complex, causing an error to be logged. However, there is
no need to override the DMA ops in that case, so skip it and
eliminate the error message.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:16 +01:00
Phil Elwell
c4453214a4 bcm2835-dma: Add proper 40-bit DMA support
The 40-bit additions are not fully tested, but it should be
capable of supporting both 40-bit memcpy on BCM2711 and regular
Lite channels on BCM2835.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:16 +01:00
Phil Elwell
e22d596cf1 pcie-brcmstb: Changes for BCM2711
The initial brcmstb PCIe driver - originally taken from the V3(?)
patch set - has been modified significantly for the BCM2711.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2020-05-20 13:49:07 +01:00
Phil Elwell
bd0b64f9c6 PCI: brcmstb: Add MSI capability
This commit adds MSI to the Broadcom STB PCIe host controller. It does
not add MSIX since that functionality is not in the HW.  The MSI
controller is physically located within the PCIe block, however, there
is no reason why the MSI controller could not be moved elsewhere in
the future.

Since the internal Brcmstb MSI controller is intertwined with the PCIe
controller, it is not its own platform device but rather part of the
PCIe platform device.

Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
2020-05-20 13:49:07 +01:00
Phil Elwell
cab401eace PCI: brcmstb: Add dma-range mapping for inbound traffic
The Broadcom STB PCIe host controller is intimately related to the
memory subsystem.  This close relationship adds complexity to how cpu
system memory is mapped to PCIe memory.  Ideally, this mapping is an
identity mapping, or an identity mapping off by a constant.  Not so in
this case.

Consider the Broadcom reference board BCM97445LCC_4X8 which has 6 GB
of system memory.  Here is how the PCIe controller maps the
system memory to PCIe memory:

  memc0-a@[        0....3fffffff] <=> pci@[        0....3fffffff]
  memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff]
  memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff]
  memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff]
  memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff]
  memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]

Although there are some "gaps" that can be added between the
individual mappings by software, the permutation of memory regions for
the most part is fixed by HW.  The solution of having something close
to an identity mapping is not possible.

The idea behind this HW design is that the same PCIe module can
act as an RC or EP, and if it acts as an EP it concatenates all
of system memory into a BAR so anything can be accessed.  Unfortunately,
when the PCIe block is in the role of an RC it also presents this
"BAR" to downstream PCIe devices, rather than offering an identity map
between its system memory and PCIe space.

Suppose that an endpoint driver allocs some DMA memory.  Suppose this
memory is located at 0x6000_0000, which is in the middle of memc1-a.
The driver wants a dma_addr_t value that it can pass on to the EP to
use.  Without doing any custom mapping, the EP will use this value for
DMA: the driver will get a dma_addr_t equal to 0x6000_0000.  But this
won't work; the device needs a dma_addr_t that reflects the PCIe space
address, namely 0xa000_0000.

So, essentially the solution to this problem must modify the
dma_addr_t returned by the DMA routines routines.  There are two
ways (I know of) of doing this:

(a) overriding/redefining the dma_to_phys() and phys_to_dma() calls
that are used by the dma_ops routines.  This is the approach of

	arch/mips/cavium-octeon/dma-octeon.c

In ARM and ARM64 these two routines are defiend in asm/dma-mapping.h
as static inline functions.

(b) Subscribe to a notifier that notifies when a device is added to a
bus.  When this happens, set_dma_ops() can be called for the device.
This method is mentioned in:

    http://lxr.free-electrons.com/source/drivers/of/platform.c?v=3.16#L152

where it says as a comment

    "In case if platform code need to use own special DMA
    configuration, it can use Platform bus notifier and
    handle BUS_NOTIFY_ADD_DEVICE event to fix up DMA
    configuration."

Solution (b) is what this commit does.  It uses its own set of
dma_ops which are wrappers around the arch_dma_ops.  The
wrappers translate the dma addresses before/after invoking
the arch_dma_ops, as appropriate.

Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
2020-05-20 13:49:07 +01:00
Phil Elwell
22de48bbb8 PCI: brcmstb: Add Broadcom STB PCIe host controller driver
This commit adds the basic Broadcom STB PCIe controller.  Missing is
the ability to process MSI and also handle dma-ranges for inbound
memory accesses.  These two functionalities are added in subsequent
commits.

The PCIe block contains an MDIO interface.  This is a local interface
only accessible by the PCIe controller.  It cannot be used or shared
by any other HW.  As such, the small amount of code for this
controller is included in this driver as there is little upside to put
it elsewhere.

Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
2020-05-20 13:49:07 +01:00