dma_declare_coherent spring cleaning
Subsystems (20)
Hi all,
this series removes various bits of dead code and refactors the remaining functionality around dma_declare_coherent to be a somewhat more coherent code base.
PATCH 1/12 mfd/sm501: depend on HAS_DMA
Currently the sm501 mfd driver can be compiled without any dependencies, but through the use of dma_declare_coherent it really depends on having DMA and iomem support. Normally we don't explicitly require DMA support as we have stubs for it if on UML, but in this case the driver selects support for dma_declare_coherent and thus also requires memmap support. Guard this by an explicit dependency.
--- drivers/mfd/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/Kconfig +1 -0
@@ -1066,6 +1066,7 @@ config MFD_SI476X_CORE config MFD_SM501 tristate "Silicon Motion SM501" + depends on HAS_DMA ---help--- This is the core driver for the Silicon Motion SM501 multimedia companion chip. This device is a multifunction device which may
Signature · 1 line
2.20.1
Re: [PATCH 01/12] mfd/sm501: depend on HAS_DMA
Quoted 17 lines · Christoph Hellwig
Currently the sm501 mfd driver can be compiled without any dependencies, but through the use of
dma_declare_coherentit really depends on having DMA and iomem support. Normally we don't explicitly require DMA support as we have stubs for it if on UML, but in this case the driver selects support fordma_declare_coherentand thus also requires memmap support. Guard this by an explicit dependency.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/mfd/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/mfd/Kconfig +0
-0
drivers/mfd/Kconfig config MFD_SI476X_CORE · line 1072
Quoted 7 lines
drivers/mfd/Kconfig +1
-0@@ -1066,6 +1066,7 @@ config MFD_SI476X_CORE config MFD_SM501 tristate "Silicon Motion SM501" + depends on HAS_DMA ---help--- This is the core driver for the Silicon Motion SM501 multimedia companion chip. This device is a multifunction device which may
I would normally have taken this, but I fear it will conflict with [PATCH 06/12]. For that reason, just take my:
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH 01/12] mfd/sm501: depend on HAS_DMA
Quoted 4 lines · Lee Jones
I would normally have taken this, but I fear it will conflict with [PATCH 06/12]. For that reason, just take my:
Acked-by Lee Jones <[email protected]>
Yes, I'll need it for the later patches in the series.
Thanks for the review.
PATCH 2/12 device.h: dma_mem is only needed for HAVE_GENERIC_DMA_COHERENT
In reply to Christoph HellwigNo need to carry an unused field around.
--- include/linux/device.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/device.h +2 -0
@@ -1017,8 +1017,10 @@ struct device {struct list_head dma_pools;/* dma pools (if dma'ble) */ +#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT struct dma_coherent_mem *dma_mem;/* internal for coherent mem override */ +#endif #ifdef CONFIG_DMA_CMA struct cma *cma_area;/* contiguous memory area for dma allocations */
Signature · 1 line
2.20.1
Re: [PATCH 02/12] device.h: dma_mem is only needed for HAVE_GENERIC_DMA_COHERENT
Quoted 6 lines · Christoph Hellwig
No need to carry an unused field around.
Signed-off-by Christoph Hellwig <[email protected]>--- include/linux/device.h | 2 ++ 1 file changed, 2 insertions(+)
PATCH 3/12 of: mark early_init_dt_alloc_reserved_memory_arch static
In reply to Christoph HellwigThis function is only used in of_reserved_mem.c, and never overridden despite the __weak marker.
--- drivers/of/of_reserved_mem.c | 2 +- include/linux/of_reserved_mem.h | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/of/of_reserved_mem.c +1 -1
@@ -26,7 +26,7 @@static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS ];static int reserved_mem_count; -int __init __weak early_init_dt_alloc_reserved_memory_arch (phys_addr_t size, +static int __init early_init_dt_alloc_reserved_memory_arch (phys_addr_t size,phys_addr_t align,phys_addr_t start,phys_addr_t end,bool nomap,phys_addr_t *res_base) {
include/linux/of_reserved_mem.h +0 -7
@@ -35,13 +35,6 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx);void of_reserved_mem_device_release (struct device *dev); -int early_init_dt_alloc_reserved_memory_arch (phys_addr_t size, -phys_addr_t align, -phys_addr_t start, -phys_addr_t end, -bool nomap, -phys_addr_t *res_base); -void fdt_init_reserved_mem (void );void fdt_reserved_mem_save_node (unsigned long node,const char *uname,phys_addr_t base,phys_addr_t size);
Signature · 1 line
2.20.1
Re: [PATCH 03/12] of: mark early_init_dt_alloc_reserved_memory_arch static
Quoted 9 lines · Christoph Hellwig
This function is only used in
of_reserved_mem.c, and never overridden despite the__weakmarker.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/of/of_reserved_mem.c | 2 +- include/linux/of_reserved_mem.h | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-)
Looks like this one isn't a dependency, so I can take it if you want.
Rob
Re: [PATCH 03/12] of: mark early_init_dt_alloc_reserved_memory_arch static
Quoted 1 line · Rob Herring
Looks like this one isn't a dependency, so I can take it if you want.
Sure, please go ahead.
PATCH 4/12 of: select OF_RESERVED_MEM automatically
In reply to Christoph HellwigThe OF_RESERVED_MEM can be used if we have either CMA or the generic declare coherent code built and we support the early flattened DT.
So don't bother making it a user visible options that is selected by most configs that fit the above category, but just select it when the requirements are met.
--- arch/arc/Kconfig | 1 - arch/arm/Kconfig | 1 - arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/powerpc/Kconfig | 1 - arch/xtensa/Kconfig | 1 - drivers/of/Kconfig | 5 ++--- 7 files changed, 2 insertions(+), 9 deletions(-)
arch/arc/Kconfig +0 -1
@@ -44,7 +44,6 @@ config ARC select MODULES_USE_ELF_RELA select OF select OF_EARLY_FLATTREE - select OF_RESERVED_MEM select PCI_SYSCALL if PCI select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING
arch/arm/Kconfig +0 -1
@@ -101,7 +101,6 @@ config ARM select MODULES_USE_ELF_REL select NEED_DMA_MAP_STATE select OF_EARLY_FLATTREE if OF - select OF_RESERVED_MEM if OF select OLD_SIGACTION select OLD_SIGSUSPEND3 select PCI_SYSCALL if PCI
arch/arm64/Kconfig +0 -1
@@ -163,7 +163,6 @@ config ARM64 select NEED_SG_DMA_LENGTH select OF select OF_EARLY_FLATTREE - select OF_RESERVED_MEM select PCI_DOMAINS_GENERIC if PCI select PCI_ECAM if (ACPI && PCI) select PCI_SYSCALL if PCI
arch/csky/Kconfig +0 -1
@@ -42,7 +42,6 @@ config CSKY select MODULES_USE_ELF_RELA if MODULES select OF select OF_EARLY_FLATTREE - select OF_RESERVED_MEM select PERF_USE_VMALLOC if CPU_CK610 select RTC_LIB select TIMER_OF
arch/powerpc/Kconfig +0 -1
@@ -233,7 +233,6 @@ config PPC select NEED_SG_DMA_LENGTH select OF select OF_EARLY_FLATTREE - select OF_RESERVED_MEM select OLD_SIGACTION if PPC32 select OLD_SIGSUSPEND select PCI_DOMAINS if PCI
arch/xtensa/Kconfig +0 -1
@@ -447,7 +447,6 @@ config USE_OF bool "Flattened Device Tree support" select OF select OF_EARLY_FLATTREE - select OF_RESERVED_MEM help Include support for flattened device tree machine descriptions.
drivers/of/Kconfig +2 -3
@@ -81,10 +81,9 @@ config OF_MDIO OpenFirmware MDIO bus (Ethernet PHY) accessors config OF_RESERVED_MEM - depends on OF_EARLY_FLATTREE bool - help - Helpers to allow for reservation of memory regions + depends on OF_EARLY_FLATTREE + default y if HAVE_GENERIC_DMA_COHERENT || DMA_CMA config OF_RESOLVE bool
Signature · 1 line
2.20.1
Re: [PATCH 04/12] of: select OF_RESERVED_MEM automatically
Quoted 9 lines · Christoph Hellwig
The
OF_RESERVED_MEMcan be used if we have either CMA or the generic declare coherent code built and we support the early flattened DT.So don't bother making it a user visible options that is selected by most configs that fit the above category, but just select it when the requirements are met.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 9 lines
--- arch/arc/Kconfig | 1 - arch/arm/Kconfig | 1 - arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/powerpc/Kconfig | 1 - arch/xtensa/Kconfig | 1 - drivers/of/Kconfig | 5 ++--- 7 files changed, 2 insertions(+), 9 deletions(-)
PATCH 5/12 dma-mapping: remove an incorrect __iommem annotation
In reply to Christoph Hellwigmemmap return a regular void pointer, not and __iomem one.
--- kernel/dma/coherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/dma/coherent.c +1 -1
@@ -43,7 +43,7 @@ static int dma_init_coherent_memory( struct dma_coherent_mem **mem) {struct dma_coherent_mem *dma_mem =NULL ; -void __iomem *mem_base =NULL ; +void *mem_base =NULL ;int pages = size >>PAGE_SHIFT ;int bitmap_size =BITS_TO_LONGS (pages) *sizeof (long );int ret;
Signature · 1 line
2.20.1
PATCH 6/12 dma-mapping: improve selection of dma_declare_coherent availability
In reply to Christoph HellwigThis API is primarily used through DT entries, but two architectures and two drivers call it directly. So instead of selecting the config symbol for random architectures pull it in implicitly for the actual users. Also rename the Kconfig option to describe the feature better.
--- arch/arc/Kconfig | 1 - arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/mips/Kconfig | 1 - arch/riscv/Kconfig | 1 - arch/sh/Kconfig | 2 +- arch/unicore32/Kconfig | 1 - arch/x86/Kconfig | 1 - drivers/mfd/Kconfig | 2 ++ drivers/of/Kconfig | 3 ++- include/linux/device.h | 2 +- include/linux/dma-mapping.h | 8 ++++---- kernel/dma/Kconfig | 2 +- kernel/dma/Makefile | 2 +- 15 files changed, 13 insertions(+), 17 deletions(-)
arch/arc/Kconfig +0 -1
@@ -30,7 +30,6 @@ config ARC select HAVE_ARCH_TRACEHOOK select HAVE_DEBUG_STACKOVERFLOW select HAVE_FUTEX_CMPXCHG if FUTEX - select HAVE_GENERIC_DMA_COHERENT select HAVE_IOREMAP_PROT select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZMA
arch/arm/Kconfig +1 -1
@@ -30,6 +30,7 @@ config ARM select CLONE_BACKWARDS select CPU_PM if SUSPEND || CPU_IDLE select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS + select DMA_DECLARE_COHERENT select DMA_REMAP if MMU select EDAC_SUPPORT select EDAC_ATOMIC_SCRUB
@@ -72,7 +73,6 @@ config ARM select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL select HAVE_FUNCTION_TRACER if !XIP_KERNEL select HAVE_GCC_PLUGINS - select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7) select HAVE_IDE if PCI || ISA || PCMCIA select HAVE_IRQ_TIME_ACCOUNTING
arch/arm64/Kconfig +0 -1
@@ -137,7 +137,6 @@ config ARM64 select HAVE_FUNCTION_TRACER select HAVE_FUNCTION_GRAPH_TRACER select HAVE_GCC_PLUGINS - select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IRQ_TIME_ACCOUNTING select HAVE_MEMBLOCK_NODE_MAP if NUMA
arch/csky/Kconfig +0 -1
@@ -30,7 +30,6 @@ config CSKY select HAVE_ARCH_TRACEHOOK select HAVE_FUNCTION_TRACER select HAVE_FUNCTION_GRAPH_TRACER - select HAVE_GENERIC_DMA_COHERENT select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZO select HAVE_KERNEL_LZMA
arch/mips/Kconfig +0 -1
@@ -56,7 +56,6 @@ config MIPS select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER - select HAVE_GENERIC_DMA_COHERENT select HAVE_IDE select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK
arch/riscv/Kconfig +0 -1
@@ -32,7 +32,6 @@ config RISCV select HAVE_MEMBLOCK_NODE_MAP select HAVE_DMA_CONTIGUOUS select HAVE_FUTEX_CMPXCHG if FUTEX - select HAVE_GENERIC_DMA_COHERENT select HAVE_PERF_EVENTS select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN
arch/sh/Kconfig +1 -1
@@ -7,11 +7,11 @@ config SUPERH select ARCH_NO_COHERENT_DMA_MMAP if !MMU select HAVE_PATA_PLATFORM select CLKDEV_LOOKUP + select DMA_DECLARE_COHERENT select HAVE_IDE if HAS_IOPORT_MAP select HAVE_MEMBLOCK_NODE_MAP select ARCH_DISCARD_MEMBLOCK select HAVE_OPROFILE - select HAVE_GENERIC_DMA_COHERENT select HAVE_ARCH_TRACEHOOK select HAVE_PERF_EVENTS select HAVE_DEBUG_BUGVERBOSE
arch/unicore32/Kconfig +0 -1
@@ -4,7 +4,6 @@ config UNICORE32 select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO - select HAVE_GENERIC_DMA_COHERENT select HAVE_KERNEL_GZIP select HAVE_KERNEL_BZIP2 select GENERIC_ATOMIC64
arch/x86/Kconfig +0 -1
@@ -15,7 +15,6 @@ config X86_32 select CLKSRC_I8253 select CLONE_BACKWARDS select HAVE_AOUT - select HAVE_GENERIC_DMA_COHERENT select MODULES_USE_ELF_REL select OLD_SIGACTION
drivers/mfd/Kconfig +2 -0
@@ -1067,6 +1067,7 @@ config MFD_SI476X_CORE config MFD_SM501 tristate "Silicon Motion SM501" depends on HAS_DMA + select DMA_DECLARE_COHERENT ---help--- This is the core driver for the Silicon Motion SM501 multimedia companion chip. This device is a multifunction device which may
@@ -1675,6 +1676,7 @@ config MFD_TC6393XB select GPIOLIB select MFD_CORE select MFD_TMIO + select DMA_DECLARE_COHERENT help Support for Toshiba Mobile IO Controller TC6393XB
drivers/of/Kconfig +2 -1
@@ -43,6 +43,7 @@ config OF_FLATTREE config OF_EARLY_FLATTREE bool + select DMA_DECLARE_COHERENT select OF_FLATTREE config OF_PROMTREE
@@ -83,7 +84,7 @@ config OF_MDIO config OF_RESERVED_MEM bool depends on OF_EARLY_FLATTREE - default y if HAVE_GENERIC_DMA_COHERENT || DMA_CMA + default y if DMA_DECLARE_COHERENT || DMA_CMA config OF_RESOLVE bool
include/linux/device.h +1 -1
@@ -1017,7 +1017,7 @@ struct device {struct list_head dma_pools;/* dma pools (if dma'ble) */ -#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT +#ifdef CONFIG_DMA_DECLARE_COHERENT struct dma_coherent_mem *dma_mem;/* internal for coherent mem override */ #endif
include/linux/dma-mapping.h +4 -4
@@ -153,7 +153,7 @@ static inline int is_device_dma_capable(struct device *dev)return dev->dma_mask !=NULL && *dev->dma_mask !=DMA_MASK_NONE ; } -#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT +#ifdef CONFIG_DMA_DECLARE_COHERENT /* * These three functions are only for dma allocator. * Don't use them in device drivers.
@@ -192,7 +192,7 @@ static inline int dma_mmap_from_global_coherent(struct vm_area_struct *vma, {return 0 ; } -#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ +#endif /* CONFIG_DMA_DECLARE_COHERENT */ static inline bool dma_is_direct (const struct dma_map_ops *ops) {
@@ -731,7 +731,7 @@ static inline int dma_get_cache_alignment(void)/* flags for the coherent memory api */ #define DMA_MEMORY_EXCLUSIVE 0x01 -#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT +#ifdef CONFIG_DMA_DECLARE_COHERENT int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr,dma_addr_t device_addr,size_t size,int flags);void dma_release_declared_memory (struct device *dev);
@@ -756,7 +756,7 @@ dma_mark_declared_memory_occupied(struct device *dev, {return ERR_PTR (-EBUSY ); } -#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ +#endif /* CONFIG_DMA_DECLARE_COHERENT */ static inline void *dmam_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp)
kernel/dma/Kconfig +1 -1
@@ -16,7 +16,7 @@ config ARCH_DMA_ADDR_T_64BIT config ARCH_HAS_DMA_COHERENCE_H bool -config HAVE_GENERIC_DMA_COHERENT +config DMA_DECLARE_COHERENT bool config ARCH_HAS_SYNC_DMA_FOR_DEVICE
kernel/dma/Makefile +1 -1
@@ -2,7 +2,7 @@ obj-$(CONFIG_HAS_DMA) += mapping.o direct.o dummy.o obj-$(CONFIG_DMA_CMA) += contiguous.o -obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += coherent.o +obj-$(CONFIG_DMA_DECLARE_COHERENT) += coherent.o obj-$(CONFIG_DMA_VIRT_OPS) += virt.o obj-$(CONFIG_DMA_API_DEBUG) += debug.o obj-$(CONFIG_SWIOTLB) += swiotlb.o
Signature · 1 line
2.20.1
Re: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
Hi Christoph,
Quoted 6 lines · Christoph Hellwig
This API is primarily used through DT entries, but two architectures and two drivers call it directly. So instead of selecting the config symbol for random architectures pull it in implicitly for the actual users. Also rename the
Kconfigoption to describe the feature better.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Paul
Re: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
This API is primarily used through DT entries, but two architectures and two drivers call it directly. So instead of selecting the config symbol for random architectures pull it in implicitly for the actual users. Also rename the
Kconfigoption to describe the feature better.Signed-off-by Christoph Hellwig <[email protected]>
Rob Herring
maintainerRe: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
In reply to Christoph HellwigQuoted 30 lines · Christoph Hellwig
This API is primarily used through DT entries, but two architectures and two drivers call it directly. So instead of selecting the config symbol for random architectures pull it in implicitly for the actual users. Also rename the
Kconfigoption to describe the feature better.Signed-off-by Christoph Hellwig <[email protected]>--- arch/arc/Kconfig | 1 - arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/mips/Kconfig | 1 - arch/riscv/Kconfig | 1 - arch/sh/Kconfig | 2 +- arch/unicore32/Kconfig | 1 - arch/x86/Kconfig | 1 - drivers/mfd/Kconfig | 2 ++ drivers/of/Kconfig | 3 ++- include/linux/device.h | 2 +- include/linux/dma-mapping.h | 8 ++++---- kernel/dma/Kconfig | 2 +- kernel/dma/Makefile | 2 +- 15 files changed, 13 insertions(+), 17 deletions(-)drivers/of/Kconfig +0
-0
drivers/of/Kconfig config OF_FLATTREE · line 46
Quoted 4 lines
drivers/of/Kconfig +1
-0@@ -43,6 +43,7 @@ config OF_FLATTREE config OF_EARLY_FLATTREE bool + select DMA_DECLARE_COHERENT
Is selecting DMA_DECLARE_COHERENT okay on UML? We run the unittests with UML.
Maybe we should just get rid of OF_RESERVED_MEM. If we support booting from DT, then it should always be enabled anyways.
Quoted 12 lines
drivers/of/Kconfig +1
-1select OF_FLATTREE config OF_PROMTREE@@ -83,7 +84,7 @@ config OF_MDIO config OF_RESERVED_MEM bool depends on OF_EARLY_FLATTREE - default y if HAVE_GENERIC_DMA_COHERENT || DMA_CMA + default y if DMA_DECLARE_COHERENT || DMA_CMA config OF_RESOLVE bool
Re: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
Quoted 11 lines · Rob Herring
drivers/of/Kconfig config OF_FLATTREE · line 46
Quoted 9 lines
drivers/of/Kconfig +1
-0@@ -43,6 +43,7 @@ config OF_FLATTREE config OF_EARLY_FLATTREE bool + select DMA_DECLARE_COHERENTIs selecting
DMA_DECLARE_COHERENTokay on UML? We run the unittests with UML.
No, that will fail with undefined references to memunmap.
I gues this needs to be
select DMA_DECLARE_COHERENT if HAS_DMA
Quoted 2 lines
Maybe we should just get rid of
OF_RESERVED_MEM. If we support booting from DT, then it should always be enabled anyways.
Fine with me. Do you want me to respin the series to just remove it?
Rob Herring
maintainerRe: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
Quoted 18 lines · Christoph Hellwig
Quoted 11 lines · Rob Herring
drivers/of/Kconfig config OF_FLATTREE · line 46
Quoted 9 lines
drivers/of/Kconfig +1
-0@@ -43,6 +43,7 @@ config OF_FLATTREE config OF_EARLY_FLATTREE bool + select DMA_DECLARE_COHERENTIs selecting
DMA_DECLARE_COHERENTokay on UML? We run the unittests with UML.No, that will fail with undefined references to memunmap.
I gues this needs to be
Quoted 7 lines
select
DMA_DECLARE_COHERENTifHAS_DMAQuoted 2 lines
Maybe we should just get rid of
OF_RESERVED_MEM. If we support booting from DT, then it should always be enabled anyways.Fine with me. Do you want me to respin the series to just remove it?
Either now or it can wait. I don't want to hold this up any.
Rob
Re: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability
In reply to Christoph HellwigQuoted 17 lines · Christoph Hellwig
This API is primarily used through DT entries, but two architectures and two drivers call it directly. So instead of selecting the config symbol for random architectures pull it in implicitly for the actual users. Also rename the
Kconfigoption to describe the feature better.Signed-off-by Christoph Hellwig <[email protected]>--- arch/arc/Kconfig | 1 - arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/mips/Kconfig | 1 - arch/riscv/Kconfig | 1 - arch/sh/Kconfig | 2 +- arch/unicore32/Kconfig | 1 - arch/x86/Kconfig | 1 -
Quoted 1 line
drivers/mfd/Kconfig | 2 ++
If everyone else is happy with these changes, then so am I.
Quoted 6 lines
drivers/of/Kconfig | 3 ++- include/linux/device.h | 2 +- include/linux/dma-mapping.h | 8 ++++---- kernel/dma/Kconfig | 2 +- kernel/dma/Makefile | 2 +- 15 files changed, 13 insertions(+), 17 deletions(-)
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 7/12 dma-mapping: move CONFIG_DMA_CMA to kernel/dma/Kconfig
In reply to Christoph HellwigThis is where all the related code already lives.
--- drivers/base/Kconfig | 77 -------------------------------------------- kernel/dma/Kconfig | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 77 deletions(-)
drivers/base/Kconfig +0 -77
@@ -191,83 +191,6 @@ config DMA_FENCE_TRACE lockup related problems for dma-buffers shared across multiple devices. -config DMA_CMA - bool "DMA Contiguous Memory Allocator" - depends on HAVE_DMA_CONTIGUOUS && CMA - help - This enables the Contiguous Memory Allocator which allows drivers - to allocate big physically-contiguous blocks of memory for use with - hardware components that do not support I/O map nor scatter-gather. - - You can disable CMA by specifying "cma=0" on the kernel's command - line. - - For more information see <include/linux/dma-contiguous.h>. - If unsure, say "n". - -if DMA_CMA -comment "Default contiguous memory area size:" - -config CMA_SIZE_MBYTES - int "Size in Mega Bytes" - depends on !CMA_SIZE_SEL_PERCENTAGE - default 0 if X86 - default 16 - help - Defines the size (in MiB) of the default memory area for Contiguous - Memory Allocator. If the size of 0 is selected, CMA is disabled by - default, but it can be enabled by passing cma=size[MG] to the kernel. - - -config CMA_SIZE_PERCENTAGE - int "Percentage of total memory" - depends on !CMA_SIZE_SEL_MBYTES - default 0 if X86 - default 10 - help - Defines the size of the default memory area for Contiguous Memory - Allocator as a percentage of the total memory in the system. - If 0 percent is selected, CMA is disabled by default, but it can be - enabled by passing cma=size[MG] to the kernel. - -choice - prompt "Selected region size" - default CMA_SIZE_SEL_MBYTES - -config CMA_SIZE_SEL_MBYTES - bool "Use mega bytes value only" - -config CMA_SIZE_SEL_PERCENTAGE - bool "Use percentage value only" - -config CMA_SIZE_SEL_MIN - bool "Use lower value (minimum)" - -config CMA_SIZE_SEL_MAX - bool "Use higher value (maximum)" - -endchoice - -config CMA_ALIGNMENT - int "Maximum PAGE_SIZE order of alignment for contiguous buffers" - range 4 12 - default 8 - help - DMA mapping framework by default aligns all buffers to the smallest - PAGE_SIZE order which is greater than or equal to the requested buffer - size. This works well for buffers up to a few hundreds kilobytes, but - for larger buffers it just a memory waste. With this parameter you can - specify the maximum PAGE_SIZE order for contiguous buffers. Larger - buffers will be aligned only to this specified order. The order is - expressed as a power of two multiplied by the PAGE_SIZE. - - For example, if your system defaults to 4KiB pages, the order value - of 8 means that the buffers will be aligned up to 1MiB only. - - If unsure, leave the default value "8". - -endif - config GENERIC_ARCH_TOPOLOGY bool help
kernel/dma/Kconfig +77 -0
80 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 07/12] dma-mapping: move CONFIG_DMA_CMA to kernel/dma/Kconfig
Quoted 7 lines · Christoph Hellwig
This is where all the related code already lives.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/base/Kconfig | 77 -------------------------------------------- kernel/dma/Kconfig | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 77 deletions(-)
Much nicer, thanks!
PATCH 8/12 dma-mapping: remove dma_mark_declared_memory_occupied
In reply to Christoph HellwigThis API is not used anywhere, so remove it.
--- Documentation/DMA-API.txt | 17 ----------------- include/linux/dma-mapping.h | 9 --------- kernel/dma/coherent.c | 23 ----------------------- 3 files changed, 49 deletions(-)
Documentation/DMA-API.txt +0 -17
@@ -605,23 +605,6 @@ unconditionally having removed all the required structures. It is the driver's job to ensure that no parts of this memory region are currently in use. -:: - - void * - dma_mark_declared_memory_occupied(struct device *dev, - dma_addr_t device_addr, size_t size) - -This is used to occupy specific regions of the declared space -(dma_alloc_coherent() will hand out the first free region it finds). - -device_addr is the *device* address of the region requested. - -size is the size (and should be a page-sized multiple). - -The return value will be either a pointer to the processor virtual -address of the memory, or an error (via PTR_ERR()) if any part of the -region is occupied. - Part III - Debug drivers use of the DMA-API -------------------------------------------
include/linux/dma-mapping.h +0 -9
@@ -735,8 +735,6 @@ static inline int dma_get_cache_alignment(void)int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr,dma_addr_t device_addr,size_t size,int flags);void dma_release_declared_memory (struct device *dev); -void *dma_mark_declared_memory_occupied (struct device *dev, -dma_addr_t device_addr,size_t size);#else static inline int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
@@ -749,13 +747,6 @@ static inline void dma_release_declared_memory(struct device *dev) { } - -static inline void * -dma_mark_declared_memory_occupied (struct device *dev, -dma_addr_t device_addr,size_t size) -{ -return ERR_PTR (-EBUSY ); -}#endif /* CONFIG_DMA_DECLARE_COHERENT */ static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
kernel/dma/coherent.c +0 -23
@@ -137,29 +137,6 @@ void dma_release_declared_memory(struct device *dev) }EXPORT_SYMBOL (dma_release_declared_memory); -void *dma_mark_declared_memory_occupied (struct device *dev, -dma_addr_t device_addr,size_t size) -{ -struct dma_coherent_mem *mem = dev->dma_mem; -unsigned long flags; -int pos, err; - - size += device_addr & ~PAGE_MASK ; - -if (!mem) -return ERR_PTR (-EINVAL ); - -spin_lock_irqsave (&mem->spinlock, flags); - pos =PFN_DOWN (device_addr -dma_get_device_base (dev, mem)); - err =bitmap_allocate_region (mem->bitmap, pos,get_order (size)); -spin_unlock_irqrestore (&mem->spinlock, flags); - -if (err !=0 ) -return ERR_PTR (err); -return mem->virt_base + (pos <<PAGE_SHIFT ); -} -EXPORT_SYMBOL (dma_mark_declared_memory_occupied); -static void *__dma_alloc_from_coherent (struct dma_coherent_mem *mem,ssize_t size,dma_addr_t *dma_handle) {
Signature · 1 line
2.20.1
PATCH 9/12 dma-mapping: remove the DMA_MEMORY_EXCLUSIVE flag
In reply to Christoph HellwigAll users of dma_declare_coherent want their allocations to be exclusive, so default to exclusive allocations.
--- Documentation/DMA-API.txt | 9 +------ arch/arm/mach-imx/mach-imx27_visstrim_m10.c | 12 +++------ arch/arm/mach-imx/mach-mx31moboard.c | 3 +-- arch/sh/boards/mach-ap325rxa/setup.c | 5 ++-- arch/sh/boards/mach-ecovec24/setup.c | 6 ++--- arch/sh/boards/mach-kfr2r09/setup.c | 5 ++-- arch/sh/boards/mach-migor/setup.c | 5 ++-- arch/sh/boards/mach-se/7724/setup.c | 6 ++--- arch/sh/drivers/pci/fixups-dreamcast.c | 3 +-- .../soc_camera/sh_mobile_ceu_camera.c | 3 +-- drivers/usb/host/ohci-sm501.c | 3 +-- drivers/usb/host/ohci-tmio.c | 2 +- include/linux/dma-mapping.h | 7 ++---- kernel/dma/coherent.c | 25 ++++++------------- 14 files changed, 29 insertions(+), 65 deletions(-)
Documentation/DMA-API.txt +1 -8
@@ -566,8 +566,7 @@ boundaries when doing this. int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, - dma_addr_t device_addr, size_t size, int - flags) + dma_addr_t device_addr, size_t size); Declare region of memory to be handed out by dma_alloc_coherent() when it's asked for coherent memory for this device.
@@ -581,12 +580,6 @@ dma_addr_t in dma_alloc_coherent()). size is the size of the area (must be multiples of PAGE_SIZE). -flags can be ORed together and are: - -- DMA_MEMORY_EXCLUSIVE - only allocate memory from the declared regions. - Do not allow dma_alloc_coherent() to fall back to system memory when - it's out of memory in the declared region. - As a simplification for the platforms, only *one* such region of memory may be declared per device.
arch/arm/mach-imx/mach-imx27_visstrim_m10.c +4 -8
@@ -258,8 +258,7 @@ static void __init visstrim_analog_camera_init(void)return ;dma_declare_coherent_memory (&pdev->dev, mx2_camera_base, - mx2_camera_base,MX2_CAMERA_BUF_SIZE , -DMA_MEMORY_EXCLUSIVE ); + mx2_camera_base,MX2_CAMERA_BUF_SIZE ); }static void __init visstrim_reserve (void )
@@ -445,8 +444,7 @@ static void __init visstrim_coda_init(void)dma_declare_coherent_memory (&pdev->dev, mx2_camera_base +MX2_CAMERA_BUF_SIZE , mx2_camera_base +MX2_CAMERA_BUF_SIZE , -MX2_CAMERA_BUF_SIZE , -DMA_MEMORY_EXCLUSIVE ); +MX2_CAMERA_BUF_SIZE ); }/* DMA deinterlace */
@@ -465,8 +463,7 @@ static void __init visstrim_deinterlace_init(void)dma_declare_coherent_memory (&pdev->dev, mx2_camera_base +2 *MX2_CAMERA_BUF_SIZE , mx2_camera_base +2 *MX2_CAMERA_BUF_SIZE , -MX2_CAMERA_BUF_SIZE , -DMA_MEMORY_EXCLUSIVE ); +MX2_CAMERA_BUF_SIZE ); }/* Emma-PrP for format conversion */
@@ -485,8 +482,7 @@ static void __init visstrim_emmaprp_init(void)*/ ret =dma_declare_coherent_memory (&pdev->dev, mx2_camera_base, mx2_camera_base, -MX2_CAMERA_BUF_SIZE , -DMA_MEMORY_EXCLUSIVE ); +MX2_CAMERA_BUF_SIZE );if (ret)pr_err ("Failed to declare memory for emmaprp\n" ); }
arch/arm/mach-imx/mach-mx31moboard.c +1 -2
@@ -475,8 +475,7 @@ static int __init mx31moboard_init_cam(void) ret =dma_declare_coherent_memory (&pdev->dev, mx3_camera_base, mx3_camera_base, -MX3_CAMERA_BUF_SIZE , -DMA_MEMORY_EXCLUSIVE ); +MX3_CAMERA_BUF_SIZE );if (ret) goto err;
arch/sh/boards/mach-ap325rxa/setup.c +2 -3
@@ -529,9 +529,8 @@ static int __init ap325rxa_devices_setup(void)device_initialize (&ap325rxa_ceu_device.dev);arch_setup_pdev_archdata (&ap325rxa_ceu_device);dma_declare_coherent_memory (&ap325rxa_ceu_device.dev, - ceu_dma_membase, ceu_dma_membase, - ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); + ceu_dma_membase, ceu_dma_membase, + ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (&ap325rxa_ceu_device);
arch/sh/boards/mach-ecovec24/setup.c +2 -4
@@ -1440,8 +1440,7 @@ static int __init arch_setup(void)dma_declare_coherent_memory (&ecovec_ceu_devices[0 ]->dev, ceu0_dma_membase, ceu0_dma_membase, ceu0_dma_membase + -CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (ecovec_ceu_devices[0 ]);device_initialize (&ecovec_ceu_devices[1 ]->dev);
@@ -1449,8 +1448,7 @@ static int __init arch_setup(void)dma_declare_coherent_memory (&ecovec_ceu_devices[1 ]->dev, ceu1_dma_membase, ceu1_dma_membase, ceu1_dma_membase + -CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (ecovec_ceu_devices[1 ]);gpiod_add_lookup_table (&cn12_power_gpiod_table);
arch/sh/boards/mach-kfr2r09/setup.c +2 -3
@@ -603,9 +603,8 @@ static int __init kfr2r09_devices_setup(void)device_initialize (&kfr2r09_ceu_device.dev);arch_setup_pdev_archdata (&kfr2r09_ceu_device);dma_declare_coherent_memory (&kfr2r09_ceu_device.dev, - ceu_dma_membase, ceu_dma_membase, - ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); + ceu_dma_membase, ceu_dma_membase, + ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (&kfr2r09_ceu_device);
arch/sh/boards/mach-migor/setup.c +2 -3
@@ -603,9 +603,8 @@ static int __init migor_devices_setup(void)device_initialize (&migor_ceu_device.dev);arch_setup_pdev_archdata (&migor_ceu_device);dma_declare_coherent_memory (&migor_ceu_device.dev, - ceu_dma_membase, ceu_dma_membase, - ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); + ceu_dma_membase, ceu_dma_membase, + ceu_dma_membase +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (&migor_ceu_device);
arch/sh/boards/mach-se/7724/setup.c +2 -4
@@ -941,8 +941,7 @@ static int __init devices_setup(void)dma_declare_coherent_memory (&ms7724se_ceu_devices[0 ]->dev, ceu0_dma_membase, ceu0_dma_membase, ceu0_dma_membase + -CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (ms7724se_ceu_devices[0 ]);device_initialize (&ms7724se_ceu_devices[1 ]->dev);
@@ -950,8 +949,7 @@ static int __init devices_setup(void)dma_declare_coherent_memory (&ms7724se_ceu_devices[1 ]->dev, ceu1_dma_membase, ceu1_dma_membase, ceu1_dma_membase + -CEU_BUFFER_MEMORY_SIZE -1 , -DMA_MEMORY_EXCLUSIVE ); +CEU_BUFFER_MEMORY_SIZE -1 );platform_device_add (ms7724se_ceu_devices[1 ]); return platform_add_devices(ms7724se_devices,
arch/sh/drivers/pci/fixups-dreamcast.c +1 -2
@@ -63,8 +63,7 @@ static void gapspci_fixup_resources(struct pci_dev *dev)BUG_ON (dma_declare_coherent_memory (&dev->dev, res.start, region.start, -resource_size (&res), -DMA_MEMORY_EXCLUSIVE )); +resource_size (&res)));break ;default :printk ("PCI: Failed resource fixup\n" );
drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c +1 -2
@@ -1708,8 +1708,7 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)if (res) { err =dma_declare_coherent_memory (&pdev->dev, res->start, res->start, -resource_size (res), -DMA_MEMORY_EXCLUSIVE ); +resource_size (res));if (err) {dev_err (&pdev->dev,"Unable to declare CEU memory.\n" );return err;
drivers/usb/host/ohci-sm501.c +1 -2
@@ -126,8 +126,7 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev) retval =dma_declare_coherent_memory (dev, mem->start, mem->start - mem->parent->start, -resource_size (mem), -DMA_MEMORY_EXCLUSIVE ); +resource_size (mem));if (retval) {dev_err (dev,"cannot declare coherent memory\n" ); goto err1;
drivers/usb/host/ohci-tmio.c +1 -1
@@ -225,7 +225,7 @@ static int ohci_hcd_tmio_drv_probe(struct platform_device *dev) } ret =dma_declare_coherent_memory (&dev->dev, sram->start, sram->start, -resource_size (sram),DMA_MEMORY_EXCLUSIVE ); +resource_size (sram));if (ret) goto err_dma_declare;
include/linux/dma-mapping.h +2 -5
@@ -728,17 +728,14 @@ static inline int dma_get_cache_alignment(void)return 1 ; } -/* flags for the coherent memory api */ -#define DMA_MEMORY_EXCLUSIVE 0x01 -#ifdef CONFIG_DMA_DECLARE_COHERENT int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr, -dma_addr_t device_addr,size_t size,int flags); +dma_addr_t device_addr,size_t size);void dma_release_declared_memory (struct device *dev);#else static inline int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr, -dma_addr_t device_addr,size_t size,int flags) +dma_addr_t device_addr,size_t size) {return -ENOSYS ; }
kernel/dma/coherent.c +7 -18
@@ -14,7 +14,6 @@ struct dma_coherent_mem {dma_addr_t device_base;unsigned long pfn_base;int size; -int flags;unsigned long *bitmap;spinlock_t spinlock;bool use_dev_dma_pfn_offset;
@@ -38,9 +37,9 @@ static inline dma_addr_t dma_get_device_base(struct device *dev,return mem->device_base; } -static int dma_init_coherent_memory ( -phys_addr_t phys_addr,dma_addr_t device_addr,size_t size,int flags, -struct dma_coherent_mem **mem) +static int dma_init_coherent_memory (phys_addr_t phys_addr, +dma_addr_t device_addr,size_t size, +struct dma_coherent_mem **mem) {struct dma_coherent_mem *dma_mem =NULL ;void *mem_base =NULL ;
@@ -73,7 +72,6 @@ static int dma_init_coherent_memory( dma_mem->device_base = device_addr; dma_mem->pfn_base =PFN_DOWN (phys_addr); dma_mem->size = pages; - dma_mem->flags = flags;spin_lock_init (&dma_mem->spinlock); *mem = dma_mem;
@@ -110,12 +108,12 @@ static int dma_assign_coherent_memory(struct device *dev, }int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr, -dma_addr_t device_addr,size_t size,int flags) +dma_addr_t device_addr,size_t size) {struct dma_coherent_mem *mem;int ret; - ret =dma_init_coherent_memory (phys_addr, device_addr, size, flags, &mem); + ret =dma_init_coherent_memory (phys_addr, device_addr, size, &mem);if (ret)return ret;
@@ -190,15 +188,7 @@ int dma_alloc_from_dev_coherent(struct device *dev, ssize_t size,return 0 ; *ret =__dma_alloc_from_coherent (mem, size, dma_handle); -if (*ret) -return 1 ; - -/* -* In the case where the allocation can not be satisfied from the -* per-device area, try to fall back to generic memory if the -* constraints allow it. -*/ -return mem->flags &DMA_MEMORY_EXCLUSIVE ; +return 1 ; }void *dma_alloc_from_global_coherent (ssize_t size,dma_addr_t *dma_handle)
@@ -327,8 +317,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)if (!mem) { ret =dma_init_coherent_memory (rmem->base, rmem->base, - rmem->size, -DMA_MEMORY_EXCLUSIVE , &mem); + rmem->size, &mem);if (ret) {pr_err ("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n" , &rmem->base, (unsigned long )rmem->size /SZ_1M );
Signature · 1 line
2.20.1
Re: [PATCH 09/12] dma-mapping: remove the DMA_MEMORY_EXCLUSIVE flag
Quoted 4 lines · Christoph Hellwig
All users of
dma_declare_coherentwant their allocations to be exclusive, so default to exclusive allocations.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 16 lines
--- Documentation/DMA-API.txt | 9 +------ arch/arm/mach-imx/mach-imx27_visstrim_m10.c | 12 +++------ arch/arm/mach-imx/mach-mx31moboard.c | 3 +-- arch/sh/boards/mach-ap325rxa/setup.c | 5 ++-- arch/sh/boards/mach-ecovec24/setup.c | 6 ++--- arch/sh/boards/mach-kfr2r09/setup.c | 5 ++-- arch/sh/boards/mach-migor/setup.c | 5 ++-- arch/sh/boards/mach-se/7724/setup.c | 6 ++--- arch/sh/drivers/pci/fixups-dreamcast.c | 3 +-- .../soc_camera/sh_mobile_ceu_camera.c | 3 +-- drivers/usb/host/ohci-sm501.c | 3 +-- drivers/usb/host/ohci-tmio.c | 2 +- include/linux/dma-mapping.h | 7 ++---- kernel/dma/coherent.c | 25 ++++++------------- 14 files changed, 29 insertions(+), 65 deletions(-)
PATCH 10/12 dma-mapping: simplify allocations from per-device coherent memory
In reply to Christoph HellwigAll users of per-device coherent memory are exclusive, that is if we can't allocate from the per-device pool we can't use the system memory either. Unfold the current dma_{alloc,free}_from_dev_coherent implementation and always use the per-device pool if it exists.
--- arch/arm/mm/dma-mapping-nommu.c | 12 ++--- include/linux/dma-mapping.h | 14 ++---- kernel/dma/coherent.c | 89 ++++++++------------------------- kernel/dma/internal.h | 19 +++++++ kernel/dma/mapping.c | 12 +++-- 5 files changed, 55 insertions(+), 91 deletions(-) create mode 100644 kernel/dma/internal.h
arch/arm/mm/dma-mapping-nommu.c +3 -9
@@ -70,16 +70,10 @@ static void arm_nommu_dma_free(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_addr, unsigned long attrs) { - if (attrs & DMA_ATTR_NON_CONSISTENT) { + if (attrs & DMA_ATTR_NON_CONSISTENT) dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs); - } else { -int ret =dma_release_from_global_coherent (get_order (size), - cpu_addr); - -WARN_ON_ONCE (ret ==0 ); - } - -return ; + else +dma_release_from_global_coherent (size ,cpu_addr ); } static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
include/linux/dma-mapping.h +4 -10
@@ -158,30 +158,24 @@ static inline int is_device_dma_capable(struct device *dev)* These three functions are only for dma allocator. * Don't use them in device drivers. */ -int dma_alloc_from_dev_coherent (struct device *dev,ssize_t size, -dma_addr_t *dma_handle,void **ret); -int dma_release_from_dev_coherent (struct device *dev,int order,void *vaddr); -int dma_mmap_from_dev_coherent (struct device *dev,struct vm_area_struct *vma,void *cpu_addr,size_t size,int *ret); -void *dma_alloc_from_global_coherent (ssize_t size,dma_addr_t *dma_handle); -int dma_release_from_global_coherent (int order,void *vaddr); +void *dma_alloc_from_global_coherent (size_t size,dma_addr_t *dma_handle); +void dma_release_from_global_coherent (size_t size,void *vaddr);int dma_mmap_from_global_coherent (struct vm_area_struct *vma,void *cpu_addr,size_t size,int *ret);#else -#define dma_alloc_from_dev_coherent (dev, size, handle, ret) (0) -#define dma_release_from_dev_coherent (dev, order, vaddr) (0)#define dma_mmap_from_dev_coherent (dev, vma, vaddr, order, ret) (0) -static inline void *dma_alloc_from_global_coherent (ssize_t size, +static inline void *dma_alloc_from_global_coherent (size_t size,dma_addr_t *dma_handle) {return NULL ; } -static inline int dma_release_from_global_coherent (int order,void *vaddr) +static inline void dma_release_from_global_coherent (size_t size,void *vaddr) {return 0 ; }
kernel/dma/coherent.c +21 -68
129 lines not on this page · raw message
kernel/dma/internal.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _DMA_INTERNAL_H +#define _DMA_INTERNAL_H + +static inline struct dma_coherent_mem *dev_get_coherent_memory (struct device *dev) +{ +#ifdef DMA_DECLARE_COHERENT +if (dev && dev->dma_mem) +return dev->dma_mem; +#endif +return NULL ; +} + +void *__dma_alloc_from_coherent (struct dma_coherent_mem *mem,size_t size, +dma_addr_t *dma_handle); +void __dma_release_from_coherent (struct dma_coherent_mem *mem,size_t size, +void *vaddr); + +#endif /* _DMA_INTERNAL_H */
kernel/dma/mapping.c +8 -4
@@ -14,6 +14,7 @@#include <linux/of_device.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include "internal.h" /* * Managed DMA API
@@ -248,12 +249,13 @@ void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) {const struct dma_map_ops *ops =get_dma_ops (dev); +struct dma_coherent_mem *mem =dev_get_coherent_memory (dev);void *cpu_addr;WARN_ON_ONCE (dev && !dev->coherent_dma_mask); -if (dma_alloc_from_dev_coherent (dev, size, dma_handle, &cpu_addr)) -return cpu_addr; +if (mem) +return __dma_alloc_from_coherent (mem, size, dma_handle);/* let the implementation decide on the zone to allocate from: */ flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);
@@ -277,9 +279,11 @@ void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs) {const struct dma_map_ops *ops =get_dma_ops (dev); +struct dma_coherent_mem *mem =dev_get_coherent_memory (dev); + +if (mem) +return __dma_release_from_coherent (mem, size, cpu_addr); -if (dma_release_from_dev_coherent (dev,get_order (size), cpu_addr)) -return ;/* * On non-coherent platforms which implement DMA-coherent buffers via * non-cacheable remaps, ops->free() may call vunmap(). Thus getting
Signature · 1 line
2.20.1
PATCH 11/12 dma-mapping: handle per-device coherent memory mmap in common code
In reply to Christoph HellwigWe handle allocation and freeing in common code, so we should handle mmap the same way. Also all users of per-device coherent memory are exclusive, that is if we can't allocate from the per-device pool we can't use the system memory either. Unfold the current dma_mmap_from_dev_coherent implementation and always use the per-device pool if it exists.
--- arch/arm/mm/dma-mapping-nommu.c | 7 ++-- arch/arm/mm/dma-mapping.c | 3 -- arch/arm64/mm/dma-mapping.c | 3 -- include/linux/dma-mapping.h | 11 ++----- kernel/dma/coherent.c | 58 ++++++++------------------------- kernel/dma/internal.h | 2 ++ kernel/dma/mapping.c | 8 ++--- 7 files changed, 24 insertions(+), 68 deletions(-)
arch/arm/mm/dma-mapping-nommu.c +2 -5
@@ -80,11 +80,8 @@ static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { - int ret; - -if (dma_mmap_from_global_coherent (vma, cpu_addr, size, &ret)) -return ret; - + if (!(attrs & DMA_ATTR_NON_CONSISTENT)) + return dma_mmap_from_global_coherent(vma, cpu_addr, size);return dma_common_mmap (dev, vma, cpu_addr, dma_addr, size, attrs); }
arch/arm/mm/dma-mapping.c +0 -3
@@ -830,9 +830,6 @@ static int __arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,unsigned long pfn =dma_to_pfn (dev, dma_addr);unsigned long off = vma->vm_pgoff; -if (dma_mmap_from_dev_coherent (dev, vma, cpu_addr, size, &ret)) -return ret; -if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) { ret = remap_pfn_range(vma, vma->vm_start, pfn + off,
arch/arm64/mm/dma-mapping.c +0 -3
@@ -246,9 +246,6 @@ static int __iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, vma->vm_page_prot =arch_dma_mmap_pgprot (dev, vma->vm_page_prot, attrs); -if (dma_mmap_from_dev_coherent (dev, vma, cpu_addr, size, &ret)) -return ret; -if (attrs &DMA_ATTR_FORCE_CONTIGUOUS ) {/* * DMA_ATTR_FORCE_CONTIGUOUS allocations are always remapped,
include/linux/dma-mapping.h +2 -9
@@ -158,17 +158,12 @@ static inline int is_device_dma_capable(struct device *dev)* These three functions are only for dma allocator. * Don't use them in device drivers. */ -int dma_mmap_from_dev_coherent (struct device *dev,struct vm_area_struct *vma, -void *cpu_addr,size_t size,int *ret); -void *dma_alloc_from_global_coherent (size_t size,dma_addr_t *dma_handle);void dma_release_from_global_coherent (size_t size,void *vaddr);int dma_mmap_from_global_coherent (struct vm_area_struct *vma,void *cpu_addr, -size_t size,int *ret); +size_t size);#else -#define dma_mmap_from_dev_coherent (dev, vma, vaddr, order, ret) (0) -static inline void *dma_alloc_from_global_coherent (size_t size,dma_addr_t *dma_handle) {
@@ -177,12 +172,10 @@ static inline void *dma_alloc_from_global_coherent(size_t size,static inline void dma_release_from_global_coherent (size_t size,void *vaddr) { -return 0 ; }static inline int dma_mmap_from_global_coherent (struct vm_area_struct *vma, -void *cpu_addr,size_t size, -int *ret) +void *cpu_addr,size_t size) {return 0 ; }
kernel/dma/coherent.c +14 -44
74 lines not on this page · raw message
kernel/dma/internal.h +2 -0
@@ -15,5 +15,7 @@ void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem, size_t size, dma_addr_t *dma_handle);void __dma_release_from_coherent (struct dma_coherent_mem *mem,size_t size,void *vaddr); +int __dma_mmap_from_coherent (struct dma_coherent_mem *mem, +struct vm_area_struct *vma,void *vaddr,size_t size);#endif /* _DMA_INTERNAL_H */
kernel/dma/mapping.c +4 -4
@@ -158,13 +158,9 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,unsigned long count =PAGE_ALIGN (size) >>PAGE_SHIFT ;unsigned long off = vma->vm_pgoff;unsigned long pfn; -int ret = -ENXIO ; vma->vm_page_prot =arch_dma_mmap_pgprot (dev, vma->vm_page_prot, attrs); -if (dma_mmap_from_dev_coherent (dev, vma, cpu_addr, size, &ret)) -return ret; -if (off >= count || user_count > count - off)return -ENXIO ;
@@ -201,6 +197,10 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, unsigned long attrs) {const struct dma_map_ops *ops =get_dma_ops (dev); +struct dma_coherent_mem *mem =dev_get_coherent_memory (dev); + +if (mem) +return __dma_mmap_from_coherent (mem, vma, cpu_addr, size);if (!dma_is_direct (ops) && ops->mmap)return ops->mmap (dev, vma, cpu_addr, dma_addr, size, attrs);
Signature · 1 line
2.20.1
PATCH 12/12 dma-mapping: remove dma_assign_coherent_memory
In reply to Christoph HellwigThe only useful bit in this function was the already assigned check. Once that is moved to dma_init_coherent_memory thee rest can easily be handled in the two callers.
--- kernel/dma/coherent.c | 47 +++++++++++++------------------------------ 1 file changed, 14 insertions(+), 33 deletions(-)
kernel/dma/coherent.c +14 -33
@@ -41,6 +41,9 @@ static int dma_init_coherent_memory(phys_addr_t phys_addr,int bitmap_size =BITS_TO_LONGS (pages) *sizeof (long );int ret; +if (*mem) +return -EBUSY ; +if (!size) { ret = -EINVAL ; goto out;
@@ -88,33 +91,11 @@ static void dma_release_coherent_memory(struct dma_coherent_mem *mem)kfree (mem); } -static int dma_assign_coherent_memory (struct device *dev, -struct dma_coherent_mem *mem) -{ -if (!dev) -return -ENODEV ; - -if (dev->dma_mem) -return -EBUSY ; - - dev->dma_mem = mem; -return 0 ; -} -int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr,dma_addr_t device_addr,size_t size) { -struct dma_coherent_mem *mem; -int ret; - - ret =dma_init_coherent_memory (phys_addr, device_addr, size, &mem); -if (ret) -return ret; - - ret =dma_assign_coherent_memory (dev, mem); -if (ret) -dma_release_coherent_memory (mem); -return ret; +return dma_init_coherent_memory (phys_addr, device_addr, size, + &dev->dma_mem); }EXPORT_SYMBOL (dma_declare_coherent_memory);
@@ -238,18 +219,18 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)struct dma_coherent_mem *mem = rmem->priv;int ret; -if (!mem) { - ret =dma_init_coherent_memory (rmem->base, rmem->base, - rmem->size, &mem); -if (ret) { -pr_err ("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n" , - &rmem->base, (unsigned long )rmem->size /SZ_1M ); -return ret; - } + ret =dma_init_coherent_memory (rmem->base, rmem->base, rmem->size, + &mem); +if (ret && ret != -EBUSY ) { +pr_err ("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n" , + &rmem->base, (unsigned long )rmem->size /SZ_1M ); +return ret; } + mem->use_dev_dma_pfn_offset = true; +if (dev) + dev->dma_mem = mem; rmem->priv = mem; -dma_assign_coherent_memory (dev, mem);return 0 ; }
Signature · 1 line
2.20.1