* [RFC] ARM: bcm2835: register dmabounce on devices hooked to main interconnect
@ 2019-07-23 16:19 Nicolas Saenz Julienne
2019-07-23 16:34 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Saenz Julienne @ 2019-07-23 16:19 UTC (permalink / raw)
To: Florian Fainelli, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, Eric Anholt, Stefan Wahren
Cc: mbrugger, hch, Nicolas Saenz Julienne, Russell King,
linux-arm-kernel, linux-kernel, linux-rpi-kernel
NOTE: This patch builds upon Stefan's series providing basic support for
RPi4[1]. I'm mostly interested in verifying if this is the correct approach
to the issue stated below. If so I assume this will be added to Stefan's
v2 series.
The new Raspberry Pi 4 happens to have weird DMA constraints. Even
though it might contain up to 4 GB of ram, most devices can only access
the first lower GB of memory.
This breaks the overall assumption DMA API makes whereas 32-bit DMA
masks are always supported[2], and potentially breaks DMA addressing for
all streaming DMA users. This has already been observed with
'sdhci-iproc' but might as well happen elsewhere. Note that contiguous
allocations are safe as 'dma_zone_size' is set accordingly.
To get around that limitation we register arm's dmabounce dma-ops on all
devices hooked to the SoC's main interconnect.
[1] https://www.spinics.net/lists/arm-kernel/msg742120.html
[2] https://www.spinics.net/lists/arm-kernel/msg742736.html
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
arch/arm/mach-bcm/Kconfig | 1 +
arch/arm/mach-bcm/board_bcm2835.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
index 5e5f1fabc3d4..588326f7e269 100644
--- a/arch/arm/mach-bcm/Kconfig
+++ b/arch/arm/mach-bcm/Kconfig
@@ -168,6 +168,7 @@ config ARCH_BCM2835
select PINCTRL
select PINCTRL_BCM2835
select MFD_CORE
+ select DMABOUNCE if ARCH_MULTI_V7
help
This enables support for the Broadcom BCM2835 and BCM2836 SoCs.
This SoC is used in the Raspberry Pi and Roku 2 devices.
diff --git a/arch/arm/mach-bcm/board_bcm2835.c b/arch/arm/mach-bcm/board_bcm2835.c
index c09cf25596af..7aff29f77ca7 100644
--- a/arch/arm/mach-bcm/board_bcm2835.c
+++ b/arch/arm/mach-bcm/board_bcm2835.c
@@ -3,6 +3,8 @@
* Copyright (C) 2010 Broadcom
*/
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
#include <linux/init.h>
#include <linux/irqchip.h>
#include <linux/of_address.h>
@@ -24,8 +26,35 @@ static const char * const bcm2835_compat[] = {
NULL
};
+static int bcm2835_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
+{
+ /*
+ * The accepted dma addresses are [0xc0000000, 0xffffffff] which map to
+ * ram's [0x00000000, 0x3fffffff].
+ */
+ return dma_addr < 3ULL * SZ_1G;
+}
+
+static int bcm2835_platform_notify(struct device *dev)
+{
+ if (dev->parent && !strcmp("soc", dev_name(dev->parent))) {
+ dev->dma_mask = &dev->coherent_dma_mask;
+ dev->coherent_dma_mask = DMA_BIT_MASK(30);
+ dmabounce_register_dev(dev, 2048, 4096, bcm2835_needs_bounce);
+ }
+
+ return 0;
+}
+
+void __init bcm2835_init_early(void)
+{
+ if(of_machine_is_compatible("brcm,bcm2711"))
+ platform_notify = bcm2835_platform_notify;
+}
+
DT_MACHINE_START(BCM2835, "BCM2835")
.dma_zone_size = SZ_1G,
.dt_compat = bcm2835_compat,
.smp = smp_ops(bcm2836_smp_ops),
+ .init_early = bcm2835_init_early,
MACHINE_END
--
2.22.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC] ARM: bcm2835: register dmabounce on devices hooked to main interconnect
2019-07-23 16:19 [RFC] ARM: bcm2835: register dmabounce on devices hooked to main interconnect Nicolas Saenz Julienne
@ 2019-07-23 16:34 ` Christoph Hellwig
2019-07-27 8:36 ` Florian Fainelli
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2019-07-23 16:34 UTC (permalink / raw)
To: Nicolas Saenz Julienne
Cc: Florian Fainelli, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, Eric Anholt, Stefan Wahren, mbrugger,
hch, Russell King, linux-arm-kernel, linux-kernel,
linux-rpi-kernel
> +static int bcm2835_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
Too long line..
> +void __init bcm2835_init_early(void)
> +{
> + if(of_machine_is_compatible("brcm,bcm2711"))
Odd formatting.
Otherwise this looks good to me.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] ARM: bcm2835: register dmabounce on devices hooked to main interconnect
2019-07-23 16:34 ` Christoph Hellwig
@ 2019-07-27 8:36 ` Florian Fainelli
0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2019-07-27 8:36 UTC (permalink / raw)
To: Christoph Hellwig, Nicolas Saenz Julienne
Cc: Ray Jui, Scott Branden, bcm-kernel-feedback-list, Eric Anholt,
Stefan Wahren, mbrugger, Russell King, linux-arm-kernel,
linux-kernel, linux-rpi-kernel
On 7/23/2019 6:34 PM, Christoph Hellwig wrote:
>> +static int bcm2835_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
>
> Too long line..
>
>> +void __init bcm2835_init_early(void)
>> +{
>> + if(of_machine_is_compatible("brcm,bcm2711"))
>
> Odd formatting.
>
> Otherwise this looks good to me.
Is this really the right way to solve this problem? First this is ARM
32-bit specific, and second, should not we have a way to indicate via
device tree that all peripherals behind the "soc" simple-bus parent node
are limited to 32-bit of DMA masks, but the specific memory map of the
BCM283x/BCM2711 makes it that only the last 1GB (0xC000_0000 -
0xffff_ffff) (which dma-ranges conveys already) is suitable for DMA into
the VPU uncached alias?
--
Florian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-27 8:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 16:19 [RFC] ARM: bcm2835: register dmabounce on devices hooked to main interconnect Nicolas Saenz Julienne
2019-07-23 16:34 ` Christoph Hellwig
2019-07-27 8:36 ` Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).