* [PATCH 0/8] Raspberry Pi 4 DMA addressing support
@ 2019-07-31 15:47 Nicolas Saenz Julienne
2019-07-31 15:47 ` [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable Nicolas Saenz Julienne
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-07-31 15:47 UTC (permalink / raw)
To: catalin.marinas, hch, wahrenst, marc.zyngier, Robin Murphy,
linux-arm-kernel, devicetree, iommu, linux-mm
Cc: phill, linux-s390, f.fainelli, mbrugger, frowand.list,
linuxppc-dev, linux-kernel, eric, robh+dt, linux-rpi-kernel, akpm,
will, nsaenzjulienne, m.szyprowski
Hi all,
this series attempts to address some issues we found while bringing up
the new Raspberry Pi 4 in arm64 and it's intended to serve as a follow
up of this discussion:
https://lkml.org/lkml/2019/7/17/476
The new Raspberry Pi 4 has up to 4GB of memory but most peripherals can
only address the first GB: their DMA address range is
0xc0000000-0xfc000000 which is aliased to the first GB of physical
memory 0x00000000-0x3c000000. Note that only some peripherals have these
limitations: the ARM cores, PCIe, V3D, GENET, and 40-bit DMA channels
have a wider view of the address space.
Part of this is solved in arm32 by setting up the machine specific
'.dma_zone_size = SZ_1G', which takes care of the allocating the
coherent memory area at the right spot. Yet no buffer bouncing (needed
for dma streaming) is available at the moment, but that's a story for
another series.
Unfortunately there is no such thing as '.dma_zone_size' in arm64 also
only ZONE_DMA32 is created which is interpreted by dma-direct and the
arm64 code as if all peripherals where be able to address the first 4GB
of memory.
In the light of this, the series implements the following changes:
- Add code that parses the device-tree in oder to find the SoC's common
DMA area.
- Create a ZONE_DMA whenever that area is needed and add the rest of the
lower 4 GB of memory to ZONE_DMA32*.
- Create the CMA area in a place suitable for all peripherals.
- Inform dma-direct of the new runtime calculated min_mask*.
That's all.
Regards,
Nicolas
* These solutions where already discussed on the previous RFC (see link
above).
---
Nicolas Saenz Julienne (8):
arm64: mm: use arm64_dma_phys_limit instead of calling
max_zone_dma_phys()
arm64: rename variables used to calculate ZONE_DMA32's size
of/fdt: add function to get the SoC wide DMA addressable memory size
arm64: re-introduce max_zone_dma_phys()
arm64: use ZONE_DMA on DMA addressing limited devices
dma-direct: turn ARCH_ZONE_DMA_BITS into a variable
arm64: update arch_zone_dma_bits to fine tune dma-direct min mask
mm: comment arm64's usage of 'enum zone_type'
arch/arm64/Kconfig | 4 ++
arch/arm64/mm/init.c | 78 ++++++++++++++++++++++++++-------
arch/powerpc/include/asm/page.h | 9 ----
arch/powerpc/mm/mem.c | 14 +++++-
arch/s390/include/asm/page.h | 2 -
arch/s390/mm/init.c | 1 +
drivers/of/fdt.c | 72 ++++++++++++++++++++++++++++++
include/linux/dma-direct.h | 2 +
include/linux/mmzone.h | 21 ++++-----
include/linux/of_fdt.h | 2 +
kernel/dma/direct.c | 8 ++--
11 files changed, 168 insertions(+), 45 deletions(-)
--
2.22.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable 2019-07-31 15:47 [PATCH 0/8] Raspberry Pi 4 DMA addressing support Nicolas Saenz Julienne @ 2019-07-31 15:47 ` Nicolas Saenz Julienne 2019-08-01 14:04 ` Christoph Hellwig 0 siblings, 1 reply; 4+ messages in thread From: Nicolas Saenz Julienne @ 2019-07-31 15:47 UTC (permalink / raw) To: catalin.marinas, hch, wahrenst, marc.zyngier, Robin Murphy, linux-arm-kernel, devicetree, iommu, linux-mm, Marek Szyprowski Cc: phill, linux-s390, f.fainelli, Vasily Gorbik, mbrugger, frowand.list, linuxppc-dev, Heiko Carstens, linux-kernel, eric, robh+dt, Paul Mackerras, linux-rpi-kernel, akpm, will, Christian Borntraeger, nsaenzjulienne Some architectures, notably arm64, are interested in tweaking this depending on their runtime dma addressing limitations. Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> --- arch/powerpc/include/asm/page.h | 9 --------- arch/powerpc/mm/mem.c | 14 ++++++++++++-- arch/s390/include/asm/page.h | 2 -- arch/s390/mm/init.c | 1 + include/linux/dma-direct.h | 2 ++ kernel/dma/direct.c | 8 +++----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 0d52f57fca04..73668a21ae78 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -319,13 +319,4 @@ struct vm_area_struct; #endif /* __ASSEMBLY__ */ #include <asm/slice.h> -/* - * Allow 30-bit DMA for very limited Broadcom wifi chips on many powerbooks. - */ -#ifdef CONFIG_PPC32 -#define ARCH_ZONE_DMA_BITS 30 -#else -#define ARCH_ZONE_DMA_BITS 31 -#endif - #endif /* _ASM_POWERPC_PAGE_H */ diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 9191a66b3bc5..3792a998ca02 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -31,6 +31,7 @@ #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/memremap.h> +#include <linux/dma-direct.h> #include <asm/pgalloc.h> #include <asm/prom.h> @@ -201,7 +202,7 @@ static int __init mark_nonram_nosave(void) * everything else. GFP_DMA32 page allocations automatically fall back to * ZONE_DMA. * - * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to + * By using 31-bit unconditionally, we can exploit arch_zone_dma_bits to * inform the generic DMA mapping code. 32-bit only devices (if not handled * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get * otherwise served by ZONE_DMA. @@ -237,9 +238,18 @@ void __init paging_init(void) printk(KERN_DEBUG "Memory hole size: %ldMB\n", (long int)((top_of_ram - total_ram) >> 20)); + /* + * Allow 30-bit DMA for very limited Broadcom wifi chips on many + * powerbooks. + */ + if (IS_ENABLED(CONFIG_PPC32)) + arch_zone_dma_bits = 30; + else + arch_zone_dma_bits = 31; + #ifdef CONFIG_ZONE_DMA max_zone_pfns[ZONE_DMA] = min(max_low_pfn, - 1UL << (ARCH_ZONE_DMA_BITS - PAGE_SHIFT)); + 1UL << (arch_zone_dma_bits - PAGE_SHIFT)); #endif max_zone_pfns[ZONE_NORMAL] = max_low_pfn; #ifdef CONFIG_HIGHMEM diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 823578c6b9e2..a4d38092530a 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -177,8 +177,6 @@ static inline int devmem_is_allowed(unsigned long pfn) #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) -#define ARCH_ZONE_DMA_BITS 31 - #include <asm-generic/memory_model.h> #include <asm-generic/getorder.h> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 20340a03ad90..07d93955d3e4 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -118,6 +118,7 @@ void __init paging_init(void) sparse_memory_present_with_active_regions(MAX_NUMNODES); sparse_init(); + arch_zone_dma_bits = 31; memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS); max_zone_pfns[ZONE_NORMAL] = max_low_pfn; diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index adf993a3bd58..a1b353b77858 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -5,6 +5,8 @@ #include <linux/dma-mapping.h> #include <linux/mem_encrypt.h> +extern unsigned int arch_zone_dma_bits; + #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA #include <asm/dma-direct.h> #else diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 59bdceea3737..40dfc9b4ee4c 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -19,9 +19,7 @@ * Most architectures use ZONE_DMA for the first 16 Megabytes, but * some use it for entirely different regions: */ -#ifndef ARCH_ZONE_DMA_BITS -#define ARCH_ZONE_DMA_BITS 24 -#endif +unsigned int arch_zone_dma_bits __ro_after_init = 24; static void report_addr(struct device *dev, dma_addr_t dma_addr, size_t size) { @@ -72,7 +70,7 @@ static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask, * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding * zones. */ - if (*phys_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)) + if (*phys_mask <= DMA_BIT_MASK(arch_zone_dma_bits)) return GFP_DMA; if (*phys_mask <= DMA_BIT_MASK(32)) return GFP_DMA32; @@ -387,7 +385,7 @@ int dma_direct_supported(struct device *dev, u64 mask) u64 min_mask; if (IS_ENABLED(CONFIG_ZONE_DMA)) - min_mask = DMA_BIT_MASK(ARCH_ZONE_DMA_BITS); + min_mask = DMA_BIT_MASK(arch_zone_dma_bits); else min_mask = DMA_BIT_MASK(32); -- 2.22.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable 2019-07-31 15:47 ` [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable Nicolas Saenz Julienne @ 2019-08-01 14:04 ` Christoph Hellwig 2019-08-01 15:59 ` Nicolas Saenz Julienne 0 siblings, 1 reply; 4+ messages in thread From: Christoph Hellwig @ 2019-08-01 14:04 UTC (permalink / raw) To: Nicolas Saenz Julienne Cc: Heiko Carstens, eric, Paul Mackerras, will, hch, Marek Szyprowski, phill, linux-s390, f.fainelli, frowand.list, Christian Borntraeger, catalin.marinas, devicetree, Vasily Gorbik, marc.zyngier, robh+dt, linux-rpi-kernel, linux-arm-kernel, mbrugger, linux-mm, linuxppc-dev, linux-kernel, iommu, wahrenst, akpm, Robin Murphy A few nitpicks, otherwise this looks great: > @@ -201,7 +202,7 @@ static int __init mark_nonram_nosave(void) > * everything else. GFP_DMA32 page allocations automatically fall back to > * ZONE_DMA. > * > - * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to > + * By using 31-bit unconditionally, we can exploit arch_zone_dma_bits to > * inform the generic DMA mapping code. 32-bit only devices (if not handled > * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get > * otherwise served by ZONE_DMA. > @@ -237,9 +238,18 @@ void __init paging_init(void) > printk(KERN_DEBUG "Memory hole size: %ldMB\n", > (long int)((top_of_ram - total_ram) >> 20)); > > + /* > + * Allow 30-bit DMA for very limited Broadcom wifi chips on many > + * powerbooks. > + */ > + if (IS_ENABLED(CONFIG_PPC32)) > + arch_zone_dma_bits = 30; > + else > + arch_zone_dma_bits = 31; > + So the above unconditionally comment obviously isn't true any more, and Ben also said for the recent ppc32 hack he'd prefer dynamic detection. Maybe Ben and or other ppc folks can chime in an add a patch to the series to sort this out now that we have a dynamic ZONE_DMA threshold? > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index 59bdceea3737..40dfc9b4ee4c 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -19,9 +19,7 @@ > * Most architectures use ZONE_DMA for the first 16 Megabytes, but > * some use it for entirely different regions: > */ > -#ifndef ARCH_ZONE_DMA_BITS > -#define ARCH_ZONE_DMA_BITS 24 > -#endif > +unsigned int arch_zone_dma_bits __ro_after_init = 24; I'd prefer to drop the arch_ prefix and just calls this zone_dma_bits. In the long run we really need to find a way to just automatically set this from the meminit code, but that is out of scope for this series. For now can you please just update the comment above to say something like: /* * Most architectures use ZONE_DMA for the first 16 Megabytes, but some use it * it for entirely different regions. In that case the arch code needs to * override the variable below for dma-direct to work properly. */ ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable 2019-08-01 14:04 ` Christoph Hellwig @ 2019-08-01 15:59 ` Nicolas Saenz Julienne 0 siblings, 0 replies; 4+ messages in thread From: Nicolas Saenz Julienne @ 2019-08-01 15:59 UTC (permalink / raw) To: Christoph Hellwig Cc: Heiko Carstens, eric, Paul Mackerras, will, Marek Szyprowski, phill, linux-s390, f.fainelli, frowand.list, Christian Borntraeger, catalin.marinas, devicetree, Vasily Gorbik, marc.zyngier, robh+dt, linux-rpi-kernel, linux-arm-kernel, mbrugger, linux-mm, linuxppc-dev, linux-kernel, iommu, wahrenst, akpm, Robin Murphy [-- Attachment #1: Type: text/plain, Size: 2485 bytes --] Hi Christoph, thanks for the review. On Thu, 2019-08-01 at 16:04 +0200, Christoph Hellwig wrote: > A few nitpicks, otherwise this looks great: > > > @@ -201,7 +202,7 @@ static int __init mark_nonram_nosave(void) > > * everything else. GFP_DMA32 page allocations automatically fall back to > > * ZONE_DMA. > > * > > - * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to > > + * By using 31-bit unconditionally, we can exploit arch_zone_dma_bits to > > * inform the generic DMA mapping code. 32-bit only devices (if not > > handled > > * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get > > * otherwise served by ZONE_DMA. > > @@ -237,9 +238,18 @@ void __init paging_init(void) > > printk(KERN_DEBUG "Memory hole size: %ldMB\n", > > (long int)((top_of_ram - total_ram) >> 20)); > > > > + /* > > + * Allow 30-bit DMA for very limited Broadcom wifi chips on many > > + * powerbooks. > > + */ > > + if (IS_ENABLED(CONFIG_PPC32)) > > + arch_zone_dma_bits = 30; > > + else > > + arch_zone_dma_bits = 31; > > + > > So the above unconditionally comment obviously isn't true any more, and > Ben also said for the recent ppc32 hack he'd prefer dynamic detection. > > Maybe Ben and or other ppc folks can chime in an add a patch to the series > to sort this out now that we have a dynamic ZONE_DMA threshold? Noted, for now I'll remove the comment. > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > > index 59bdceea3737..40dfc9b4ee4c 100644 > > --- a/kernel/dma/direct.c > > +++ b/kernel/dma/direct.c > > @@ -19,9 +19,7 @@ > > * Most architectures use ZONE_DMA for the first 16 Megabytes, but > > * some use it for entirely different regions: > > */ > > -#ifndef ARCH_ZONE_DMA_BITS > > -#define ARCH_ZONE_DMA_BITS 24 > > -#endif > > +unsigned int arch_zone_dma_bits __ro_after_init = 24; > > I'd prefer to drop the arch_ prefix and just calls this zone_dma_bits. > In the long run we really need to find a way to just automatically set > this from the meminit code, but that is out of scope for this series. > For now can you please just update the comment above to say something > like: > > /* > * Most architectures use ZONE_DMA for the first 16 Megabytes, but some use it > * it for entirely different regions. In that case the arch code needs to > * override the variable below for dma-direct to work properly. > */ Ok perfect. [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-01 16:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-07-31 15:47 [PATCH 0/8] Raspberry Pi 4 DMA addressing support Nicolas Saenz Julienne 2019-07-31 15:47 ` [PATCH 6/8] dma-direct: turn ARCH_ZONE_DMA_BITS into a variable Nicolas Saenz Julienne 2019-08-01 14:04 ` Christoph Hellwig 2019-08-01 15:59 ` Nicolas Saenz Julienne
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).