fully convert arm to use dma-direct v3
Subsystems (7)
Hi all,
arm is the last platform not using the dma-direct code for directly mapped DMA. With the dmaboune removal from Arnd we can easily switch arm to always use dma-direct now (it already does for LPAE configs and nommu). I'd love to merge this series through the dma-mapping tree as it gives us the opportunity for additional core dma-mapping improvements.
Changes since v2:
- rebased to Linux 5.19-rc2
Changes since v1:
- remove another unused function
- improve a few commit logs
- add three more patches from Robin
Diffstat:
arch/arm/common/dmabounce.c | 582 ----------------- arch/arm/include/asm/dma-mapping.h | 128 --- b/arch/arm/Kconfig | 5 b/arch/arm/common/Kconfig | 6 b/arch/arm/common/Makefile | 1 b/arch/arm/common/sa1111.c | 64 - b/arch/arm/include/asm/device.h | 3 b/arch/arm/include/asm/dma-direct.h | 49 - b/arch/arm/include/asm/memory.h | 2 b/arch/arm/mach-footbridge/Kconfig | 1 b/arch/arm/mach-footbridge/common.c | 19 b/arch/arm/mach-footbridge/include/mach/dma-direct.h | 8 b/arch/arm/mach-footbridge/include/mach/memory.h | 4 b/arch/arm/mach-highbank/highbank.c | 2 b/arch/arm/mach-mvebu/coherency.c | 2 b/arch/arm/mm/dma-mapping.c | 649 ++----------------- b/drivers/usb/core/hcd.c | 17 b/drivers/usb/host/ohci-sa1111.c | 25 18 files changed, 137 insertions(+), 1430 deletions(-)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 1/10 ARM: sa1100/assabet: move dmabounce hack to ohci driver
From: Arnd Bergmann <[email protected]>
The sa1111 platform is one of the two remaining users of the old Arm specific "dmabounce" code, which is an earlier implementation of the generic swiotlb.
Linus Walleij submitted a patch that removes dmabounce support from the ixp4xx, and I had a look at the other user, which is the sa1111 companion chip.
Looking at how dmabounce is used, I could narrow it down to one driver one three machines:
- dmabounce is only initialized on assabet/neponset, jornada720 and badge4, which are the platforms that have an sa1111 and support DMA on it.
- All three of these suffer from "erratum #7" that requires only doing DMA to half the memory sections based on one of the address lines, in addition, the neponset also can't DMA to the RAM that is connected to sa1111 itself.
- the pxa lubbock machine also has sa1111, but does not support DMA on it and does not set dmabounce.
- only the OHCI and audio devices on sa1111 support DMA, but as there is no audio driver for this hardware, only OHCI remains.
In the OHCI code, I noticed that two other platforms already have a local bounce buffer support in the form of the "local_mem" allocator. Specifically, TMIO and SM501 use this on a few other ARM boards with 16KB or 128KB of local SRAM that can be accessed from the OHCI and from the CPU.
While this is not the same problem as on sa1111, I could not find a reason why we can't re-use the existing implementation but replace the physical SRAM address mapping with a locally allocated DMA buffer.
There are two main downsides:
- rather than using a dynamically sized pool, this buffer needs to be allocated at probe time using a fixed size. Without having any idea of what it should be, I picked a size of 64KB, which is between what the other two OHCI front-ends use in their SRAM. If anyone has a better idea what that size is reasonable, this can be trivially changed.
- Previously, only USB transfers to unaddressable memory needed to go through the bounce buffer, now all of them do, which may impact runtime performance for USB endpoints that do a lot of transfers.
On the upside, the local_mem support uses write-combining buffers, which should be a bit faster for transfers to the device compared to normal uncached coherent memory as used in dmabounce.
--- arch/arm/common/Kconfig | 2 +- arch/arm/common/sa1111.c | 64 ---------------------------------- drivers/usb/core/hcd.c | 17 +++++++-- drivers/usb/host/ohci-sa1111.c | 25 +++++++++++++ 4 files changed, 40 insertions(+), 68 deletions(-)
arch/arm/common/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 config SA1111 bool - select DMABOUNCE if !ARCH_PXA + select ZONE_DMA if ARCH_SA1100 config DMABOUNCE bool
arch/arm/common/sa1111.c +0 -64
79 lines not on this page · raw message
drivers/usb/core/hcd.c +14 -3
@@ -1251,7 +1251,8 @@ void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb)EXPORT_SYMBOL_GPL (usb_hcd_unlink_urb_from_ep);/* -* Some usb host controllers can only perform dma using a small SRAM area. +* Some usb host controllers can only perform dma using a small SRAM area, +* or have restrictions on addressable DRAM. * The usb core itself is however optimized for host controllers that can dma * using regular system memory - like pci devices doing bus mastering. *
@@ -3117,8 +3118,18 @@ int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr,if (IS_ERR (hcd->localmem_pool))return PTR_ERR (hcd->localmem_pool); - local_mem =devm_memremap (hcd->self.sysdev, phys_addr, - size,MEMREMAP_WC ); +/* +* if a physical SRAM address was passed, map it, otherwise +* allocate system memory as a buffer. +*/ +if (phys_addr) + local_mem =devm_memremap (hcd->self.sysdev, phys_addr, + size,MEMREMAP_WC ); +else + local_mem =dmam_alloc_attrs (hcd->self.sysdev, size, &dma, +GFP_KERNEL , +DMA_ATTR_WRITE_COMBINE ); +if (IS_ERR (local_mem))return PTR_ERR (local_mem);
drivers/usb/host/ohci-sa1111.c +25 -0
@@ -203,6 +203,31 @@ static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev) goto err1; } +/* +* According to the "Intel StrongARM SA-1111 Microprocessor Companion +* Chip Specification Update" (June 2000), erratum #7, there is a +* significant bug in the SA1111 SDRAM shared memory controller. If +* an access to a region of memory above 1MB relative to the bank base, +* it is important that address bit 10 _NOT_ be asserted. Depending +* on the configuration of the RAM, bit 10 may correspond to one +* of several different (processor-relative) address bits. +* +* Section 4.6 of the "Intel StrongARM SA-1111 Development Module +* User's Guide" mentions that jumpers R51 and R52 control the +* target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or +* SDRAM bank 1 on Neponset). The default configuration selects +* Assabet, so any address in bank 1 is necessarily invalid. +* +* As a workaround, use a bounce buffer in addressable memory +* as local_mem, relying on ZONE_DMA to provide an area that +* fits within the above constraints. +* +* SZ_64K is an estimate for what size this might need. +*/ + ret =usb_hcd_setup_local_mem (hcd,0 ,0 ,SZ_64K ); +if (ret) + goto err1; +if (!request_mem_region (hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {dev_dbg (&dev->dev,"request_mem_region failed\n" ); ret = -EBUSY ;
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/10 ARM/dma-mapping: remove dmabounce
In reply to Christoph HellwigRemove the now unused dmabounce code.
--- arch/arm/common/Kconfig | 4 - arch/arm/common/Makefile | 1 - arch/arm/common/dmabounce.c | 582 ----------------------------- arch/arm/include/asm/device.h | 3 - arch/arm/include/asm/dma-mapping.h | 29 -- 5 files changed, 619 deletions(-) delete mode 100644 arch/arm/common/dmabounce.c
arch/arm/common/Kconfig +0 -4
@@ -3,10 +3,6 @@ config SA1111 bool select ZONE_DMA if ARCH_SA1100 -config DMABOUNCE - bool - select ZONE_DMA - config KRAIT_L2_ACCESSORS bool
arch/arm/common/Makefile +0 -1
@@ -6,7 +6,6 @@ obj-y += firmware.o obj-$(CONFIG_SA1111) += sa1111.o -obj-$(CONFIG_DMABOUNCE) += dmabounce.o obj-$(CONFIG_KRAIT_L2_ACCESSORS) += krait-l2-accessors.o obj-$(CONFIG_SHARP_LOCOMO) += locomo.o obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o
arch/arm/common/dmabounce.c deleted +0 -582
582 lines not on this page · raw message
arch/arm/include/asm/device.h +0 -3
@@ -6,9 +6,6 @@#define ASMARM_DEVICE_H struct dev_archdata { -#ifdef CONFIG_DMABOUNCE -struct dmabounce_device_info *dmabounce; -#endif #ifdef CONFIG_ARM_DMA_USE_IOMMU struct dma_iommu_mapping *mapping;#endif
arch/arm/include/asm/dma-mapping.h +0 -29
@@ -80,35 +80,6 @@ extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,* */ -/** -* dmabounce_register_dev -* -* @dev: valid struct device pointer -* @small_buf_size: size of buffers to use with small buffer pool -* @large_buf_size: size of buffers to use with large buffer pool (can be 0) -* @needs_bounce_fn: called to determine whether buffer needs bouncing -* -* This function should be called by low-level platform code to register -* a device as requireing DMA buffer bouncing. The function will allocate -* appropriate DMA pools for the device. -*/ -extern int dmabounce_register_dev (struct device *,unsigned long , -unsigned long ,int (*)(struct device *,dma_addr_t ,size_t )); - -/** -* dmabounce_unregister_dev -* -* @dev: valid struct device pointer -* -* This function should be called by low-level platform code when device -* that was previously registered with dmabounce_register_dev is removed -* from the system. -* -*/ -extern void dmabounce_unregister_dev (struct device *); - - -/* * The scatter list versions of the above methods. */
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 3/10 ARM/dma-mapping: mark various dma-mapping routines static in dma-mapping.c
In reply to Christoph HellwigWith the dmabounce removal these aren't used outside of dma-mapping.c, so mark them static. Move the dma_map_ops declarations down a bit to avoid lots of forward declarations.
--- arch/arm/include/asm/dma-mapping.h | 75 ---------------------- arch/arm/mm/dma-mapping.c | 100 +++++++++++++---------------- 2 files changed, 46 insertions(+), 129 deletions(-)
arch/arm/include/asm/dma-mapping.h +0 -75
@@ -20,80 +20,5 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)return NULL ; } -/** -* arm_dma_alloc - allocate consistent memory for DMA -* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices -* @size: required memory size -* @handle: bus-specific DMA address -* @attrs: optinal attributes that specific mapping properties -* -* Allocate some memory for a device for performing DMA. This function -* allocates pages, and will return the CPU-viewed address, and sets @handle -* to be the device-viewed address. -*/ -extern void *arm_dma_alloc (struct device *dev,size_t size,dma_addr_t *handle, -gfp_t gfp,unsigned long attrs); - -/** -* arm_dma_free - free memory allocated by arm_dma_alloc -* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices -* @size: size of memory originally requested in dma_alloc_coherent -* @cpu_addr: CPU-view address returned from dma_alloc_coherent -* @handle: device-view address returned from dma_alloc_coherent -* @attrs: optinal attributes that specific mapping properties -* -* Free (and unmap) a DMA buffer previously allocated by -* arm_dma_alloc(). -* -* References to memory and mappings associated with cpu_addr/handle -* during and after this call executing are illegal. -*/ -extern void arm_dma_free (struct device *dev,size_t size,void *cpu_addr, -dma_addr_t handle,unsigned long attrs); - -/** -* arm_dma_mmap - map a coherent DMA allocation into user space -* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices -* @vma: vm_area_struct describing requested user mapping -* @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent -* @handle: device-view address returned from dma_alloc_coherent -* @size: size of memory originally requested in dma_alloc_coherent -* @attrs: optinal attributes that specific mapping properties -* -* Map a coherent DMA buffer previously allocated by dma_alloc_coherent -* into user space. The coherent DMA buffer must not be freed by the -* driver until the user space mapping has been released. -*/ -extern int arm_dma_mmap (struct device *dev,struct vm_area_struct *vma, -void *cpu_addr,dma_addr_t dma_addr,size_t size, -unsigned long attrs); - -/* -* For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic" -* and utilize bounce buffers as needed to work around limited DMA windows. -* -* On the SA-1111, a bug limits DMA to only certain regions of RAM. -* On the IXP425, the PCI inbound window is 64MB (256MB total RAM) -* On some ADI engineering systems, PCI inbound window is 32MB (12MB total RAM) -* -* The following are helper functions used by the dmabounce subystem -* -*/ - -/* -* The scatter list versions of the above methods. -*/ -extern int arm_dma_map_sg (struct device *,struct scatterlist *,int , -enum dma_data_direction ,unsigned long attrs); -extern void arm_dma_unmap_sg (struct device *,struct scatterlist *,int , -enum dma_data_direction ,unsigned long attrs); -extern void arm_dma_sync_sg_for_cpu (struct device *,struct scatterlist *,int , -enum dma_data_direction ); -extern void arm_dma_sync_sg_for_device (struct device *,struct scatterlist *,int , -enum dma_data_direction ); -extern int arm_dma_get_sgtable (struct device *dev,struct sg_table *sgt, -void *cpu_addr,dma_addr_t dma_addr,size_t size, -unsigned long attrs); -#endif /* __KERNEL__ */ #endif
arch/arm/mm/dma-mapping.c +46 -54
160 lines not on this page · raw message
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 4/10 ARM/dma-mapping: remove the unused virt_to_dma helper
In reply to Christoph Hellwigvirt_to_dma was only used by the now removed dmabounce code.
--- arch/arm/include/asm/dma-direct.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
arch/arm/include/asm/dma-direct.h +1 -9
@@ -5,7 +5,7 @@#include <asm/memory.h> /* -* dma_to_pfn/pfn_to_dma/virt_to_dma are architecture private +* dma_to_pfn/pfn_to_dma are architecture private * functions used internally by the DMA-mapping API to provide DMA * addresses. They must not be used by drivers. */
@@ -25,14 +25,6 @@ static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)return pfn; } -static inline dma_addr_t virt_to_dma (struct device *dev,void *addr) -{ -if (dev) -return pfn_to_dma (dev,virt_to_pfn (addr)); - -return (dma_addr_t )__virt_to_bus ((unsigned long )(addr)); -} -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) {unsigned int offset = paddr & ~PAGE_MASK ;
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 5/10 ARM/dma-mapping: use dma_to_phys/phys_to_dma in the dma-mapping code
In reply to Christoph HellwigUse the helpers as expected by the dma-direct code in the old arm dma-mapping code to ease a gradual switch to the common DMA code.
--- arch/arm/mm/dma-mapping.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
arch/arm/mm/dma-mapping.c +12 -12
@@ -128,14 +128,14 @@ static dma_addr_t arm_dma_map_page(struct device *dev, struct page *page, {if ((attrs &DMA_ATTR_SKIP_CPU_SYNC ) ==0 )__dma_page_cpu_to_dev (page, offset, size, dir); -return pfn_to_dma (dev,page_to_pfn (page)) + offset; +return phys_to_dma (dev,page_to_phys (page) + offset); }static dma_addr_t arm_coherent_dma_map_page (struct device *dev,struct page *page,unsigned long offset,size_t size,enum dma_data_direction dir,unsigned long attrs) { -return pfn_to_dma (dev,page_to_pfn (page)) + offset; +return phys_to_dma (dev,page_to_phys (page) + offset); }/**
@@ -156,7 +156,7 @@ static void arm_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir, unsigned long attrs) { if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0) - __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)), + __dma_page_dev_to_cpu(phys_to_page(dma_to_phys(dev, handle)), handle & ~PAGE_MASK, size, dir); }
@@ -164,7 +164,7 @@ static void arm_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { unsigned int offset = handle & (PAGE_SIZE - 1); -struct page *page =pfn_to_page (dma_to_pfn (dev, handle-offset)); +struct page *page =phys_to_page (dma_to_phys (dev, handle-offset));__dma_page_dev_to_cpu (page, offset, size, dir); }
@@ -172,7 +172,7 @@ static void arm_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { unsigned int offset = handle & (PAGE_SIZE - 1); -struct page *page =pfn_to_page (dma_to_pfn (dev, handle-offset)); +struct page *page =phys_to_page (dma_to_phys (dev, handle-offset));__dma_page_cpu_to_dev (page, offset, size, dir); }
@@ -190,7 +190,7 @@ static int arm_dma_supported(struct device *dev, u64 mask)* Translate the device's DMA mask to a PFN limit. This * PFN number includes the page which we can DMA to. */ -return dma_to_pfn (dev, mask) >= max_dma_pfn; +return PHYS_PFN (dma_to_phys (dev, mask)) >= max_dma_pfn; }static void __dma_clear_buffer (struct page *page,size_t size,int coherent_flag)
@@ -681,7 +681,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,if (page) {unsigned long flags; - *handle =pfn_to_dma (dev,page_to_pfn (page)); + *handle =phys_to_dma (dev,page_to_phys (page)); buf->virt = args.want_vaddr ? addr : page;spin_lock_irqsave (&arm_dma_bufs_lock, flags);
@@ -721,7 +721,7 @@ static int __arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,int ret = -ENXIO ;unsigned long nr_vma_pages =vma_pages (vma);unsigned long nr_pages =PAGE_ALIGN (size) >>PAGE_SHIFT ; -unsigned long pfn =dma_to_pfn (dev, dma_addr); +unsigned long pfn =PHYS_PFN (dma_to_phys (dev, dma_addr));unsigned long off = vma->vm_pgoff;if (dma_mmap_from_dev_coherent (dev, vma, cpu_addr, size, &ret))
@@ -762,7 +762,7 @@ static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle, unsigned long attrs, bool is_coherent) { - struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); + struct page *page = phys_to_page(dma_to_phys(dev, handle));struct arm_dma_buffer *buf; struct arm_dma_free_args args = { .dev = dev,
@@ -796,15 +796,15 @@ static int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t handle, size_t size, unsigned long attrs) { - unsigned long pfn = dma_to_pfn(dev, handle); + phys_addr_t paddr = dma_to_phys(dev, handle);struct page *page;int ret;/* If the PFN is not valid, we do not have a struct page */ -if (!pfn_valid (pfn)) +if (!pfn_valid (PHYS_PFN (paddr)))return -ENXIO ; - page =pfn_to_page (pfn); + page =phys_to_page (paddr); ret =sg_alloc_table (sgt,1 ,GFP_KERNEL );if (unlikely (ret))
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 6/10 ARM/dma-mapping: use the generic versions of dma_to_phys/phys_to_dma by default
In reply to Christoph HellwigOnly the footbridge platforms provide their own DMA address translation helpers, so switch to the generic version for all other platforms, and consolidate the footbridge implementation to remove two levels of indirection.
--- arch/arm/Kconfig | 1 - arch/arm/include/asm/dma-direct.h | 41 +------------------ arch/arm/include/asm/memory.h | 2 - arch/arm/mach-footbridge/Kconfig | 1 + arch/arm/mach-footbridge/common.c | 19 +++++---- .../mach-footbridge/include/mach/dma-direct.h | 8 ++++ .../arm/mach-footbridge/include/mach/memory.h | 4 -- 7 files changed, 21 insertions(+), 55 deletions(-) create mode 100644 arch/arm/mach-footbridge/include/mach/dma-direct.h
arch/arm/Kconfig +0 -1
@@ -15,7 +15,6 @@ config ARM select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PTE_SPECIAL if ARM_LPAE - select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
arch/arm/include/asm/dma-direct.h +1 -40
41 lines not on this page · raw message
arch/arm/include/asm/memory.h +0 -2
@@ -378,8 +378,6 @@ static inline unsigned long __virt_to_idmap(unsigned long x)#ifndef __virt_to_bus#define __virt_to_bus __virt_to_phys#define __bus_to_virt __phys_to_virt -#define __pfn_to_bus (x) __pfn_to_phys(x) -#define __bus_to_pfn (x) __phys_to_pfn(x)#endif /*
arch/arm/mach-footbridge/Kconfig +1 -0
@@ -60,6 +60,7 @@ endmenu # Footbridge support config FOOTBRIDGE + select ARCH_HAS_PHYS_TO_DMA bool # Footbridge in host mode
arch/arm/mach-footbridge/common.c +11 -8
@@ -12,6 +12,7 @@#include <linux/init.h> #include <linux/io.h> #include <linux/spinlock.h> +#include <linux/dma-direct.h> #include <video/vga.h> #include <asm/page.h>
@@ -335,17 +336,19 @@ unsigned long __bus_to_virt(unsigned long res) return res; }EXPORT_SYMBOL (__bus_to_virt); - -unsigned long __pfn_to_bus (unsigned long pfn) +#else +static inline unsigned long fb_bus_sdram_offset (void ) { -return __pfn_to_phys (pfn) + (fb_bus_sdram_offset () -PHYS_OFFSET ); +return BUS_OFFSET ; } -EXPORT_SYMBOL (__pfn_to_bus); +#endif /* CONFIG_FOOTBRIDGE_ADDIN */ -unsigned long __bus_to_pfn (unsigned long bus) +dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) { -return __phys_to_pfn (bus - (fb_bus_sdram_offset () -PHYS_OFFSET )); +return paddr + (fb_bus_sdram_offset () -PHYS_OFFSET ); } -EXPORT_SYMBOL (__bus_to_pfn); -#endif +phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +{ +return dev_addr - (fb_bus_sdram_offset () -PHYS_OFFSET ); +}
arch/arm/mach-footbridge/include/mach/dma-direct.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef MACH_FOOTBRIDGE_DMA_DIRECT_H +#define MACH_FOOTBRIDGE_DMA_DIRECT_H 1 + +dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); +phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr); + +#endif /* MACH_FOOTBRIDGE_DMA_DIRECT_H */
arch/arm/mach-footbridge/include/mach/memory.h +0 -4
@@ -26,8 +26,6 @@#ifndef __ASSEMBLY__extern unsigned long __virt_to_bus (unsigned long );extern unsigned long __bus_to_virt (unsigned long ); -extern unsigned long __pfn_to_bus (unsigned long ); -extern unsigned long __bus_to_pfn (unsigned long );#endif #define __virt_to_bus __virt_to_bus#define __bus_to_virt __bus_to_virt
@@ -42,8 +40,6 @@ extern unsigned long __bus_to_pfn(unsigned long);#define BUS_OFFSET 0xe0000000#define __virt_to_bus (x) ((x) + (BUS_OFFSET - PAGE_OFFSET))#define __bus_to_virt (x) ((x) - (BUS_OFFSET - PAGE_OFFSET)) -#define __pfn_to_bus (x) (__pfn_to_phys(x) + (BUS_OFFSET - PHYS_OFFSET)) -#define __bus_to_pfn (x) __phys_to_pfn((x) - (BUS_OFFSET - PHYS_OFFSET))#else
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 7/10 ARM/dma-mapping: use dma-direct unconditionally
In reply to Christoph HellwigUse dma-direct unconditionally on arm. It has already been used for some time for LPAE and nommu configurations.
This mostly changes the streaming mapping implementation and the (simple) coherent allocator for device that are DMA coherent. The existing complex allocator for uncached mappings for non-coherent devices is still used as is using the arch_dma_alloc/arch_dma_free hooks.
--- arch/arm/Kconfig | 4 +- arch/arm/include/asm/dma-mapping.h | 24 -- arch/arm/mach-highbank/highbank.c | 2 +- arch/arm/mach-mvebu/coherency.c | 2 +- arch/arm/mm/dma-mapping.c | 365 ++--------------------------- 5 files changed, 19 insertions(+), 378 deletions(-) delete mode 100644 arch/arm/include/asm/dma-mapping.h
arch/arm/Kconfig +2 -2
@@ -19,8 +19,8 @@ config ARM select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL select ARCH_HAS_STRICT_MODULE_RWX if MMU - select ARCH_HAS_SYNC_DMA_FOR_DEVICE if SWIOTLB || !MMU - select ARCH_HAS_SYNC_DMA_FOR_CPU if SWIOTLB || !MMU + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_TEARDOWN_DMA_OPS if MMU select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_CUSTOM_GPIO_H
arch/arm/include/asm/dma-mapping.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef ASMARM_DMA_MAPPING_H -#define ASMARM_DMA_MAPPING_H - -#ifdef __KERNEL__ - -#include <linux/mm_types.h> -#include <linux/scatterlist.h> - -#include <xen/xen.h> -#include <asm/xen/hypervisor.h> - -extern const struct dma_map_ops arm_dma_ops; -extern const struct dma_map_ops arm_coherent_dma_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) -{ -if (IS_ENABLED (CONFIG_MMU ) && !IS_ENABLED (CONFIG_ARM_LPAE )) -return &arm_dma_ops; -return NULL ; -} - -#endif /* __KERNEL__ */ -#endif
arch/arm/mach-highbank/highbank.c +1 -1
@@ -98,7 +98,7 @@ static int highbank_platform_notifier(struct notifier_block *nb,if (of_property_read_bool (dev->of_node,"dma-coherent" )) { val =readl (sregs_base + reg);writel (val |0xff01 , sregs_base + reg); -set_dma_ops (dev, &arm_coherent_dma_ops); + dev->dma_coherent = true; }return NOTIFY_OK ;
arch/arm/mach-mvebu/coherency.c +1 -1
@@ -98,7 +98,7 @@ static int mvebu_hwcc_notifier(struct notifier_block *nb,if (event !=BUS_NOTIFY_ADD_DEVICE )return NOTIFY_DONE ; -set_dma_ops (dev, &arm_coherent_dma_ops); + dev->dma_coherent = true;return NOTIFY_OK ; }
arch/arm/mm/dma-mapping.c +15 -350
455 lines not on this page · raw message
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 8/10 ARM/dma-mapping: drop .dma_supported for IOMMU ops
In reply to Christoph HellwigFrom: Robin Murphy <[email protected]>
When an IOMMU is present, we trust that it should be capable of remapping any physical memory, and since the device masks represent the input (virtual) addresses to the IOMMU it makes no sense to validate them against physical PFNs anyway.
--- arch/arm/mm/dma-mapping.c | 23 ----------------------- 1 file changed, 23 deletions(-)
arch/arm/mm/dma-mapping.c +0 -23
@@ -104,25 +104,6 @@ static struct arm_dma_buffer *arm_dma_buffer_find(void *virt)* */ -#ifdef CONFIG_ARM_DMA_USE_IOMMU -/* -* Return whether the given device DMA address mask can be supported -* properly. For example, if your device can only drive the low 24-bits -* during bus mastering, then you would pass 0x00ffffff as the mask -* to this function. -*/ -static int arm_dma_supported (struct device *dev,u64 mask) -{ -unsigned long max_dma_pfn =min (max_pfn -1 , arm_dma_pfn_limit); - -/* -* Translate the device's DMA mask to a PFN limit. This -* PFN number includes the page which we can DMA to. -*/ -return PHYS_PFN (dma_to_phys (dev, mask)) >= max_dma_pfn; -} -#endif -static void __dma_clear_buffer (struct page *page,size_t size,int coherent_flag) {/*
@@ -1681,8 +1662,6 @@ static const struct dma_map_ops iommu_ops = { .map_resource = arm_iommu_map_resource, .unmap_resource = arm_iommu_unmap_resource, - - .dma_supported = arm_dma_supported, };static const struct dma_map_ops iommu_coherent_ops = {
@@ -1699,8 +1678,6 @@ static const struct dma_map_ops iommu_coherent_ops = { .map_resource = arm_iommu_map_resource, .unmap_resource = arm_iommu_unmap_resource, - - .dma_supported = arm_dma_supported, };/**
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 9/10 ARM/dma-mapping: consolidate IOMMU ops callbacks
In reply to Christoph HellwigFrom: Robin Murphy <[email protected]>
Merge the coherent and non-coherent callbacks down to a single implementation each, relying on the generic dev->dma_coherent flag at the points where the difference matters.
--- arch/arm/mm/dma-mapping.c | 238 +++++++++----------------------------- 1 file changed, 55 insertions(+), 183 deletions(-)
arch/arm/mm/dma-mapping.c +55 -183
@@ -1079,13 +1079,13 @@ static void __iommu_free_atomic(struct device *dev, void *cpu_addr,__free_from_pool (cpu_addr, size); } -static void *__arm_iommu_alloc_attrs (struct device *dev,size_t size, -dma_addr_t *handle,gfp_t gfp,unsigned long attrs, -int coherent_flag) +static void *arm_iommu_alloc_attrs (struct device *dev,size_t size, +dma_addr_t *handle,gfp_t gfp,unsigned long attrs) {pgprot_t prot =__get_dma_pgprot (attrs,PAGE_KERNEL );struct page **pages;void *addr =NULL ; +int coherent_flag = dev->dma_coherent ?COHERENT :NORMAL ; *handle =DMA_MAPPING_ERROR ; size =PAGE_ALIGN (size);
@@ -1128,19 +1128,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,return NULL ; } -static void *arm_iommu_alloc_attrs (struct device *dev,size_t size, -dma_addr_t *handle,gfp_t gfp,unsigned long attrs) -{ -return __arm_iommu_alloc_attrs (dev, size, handle, gfp, attrs,NORMAL ); -} - -static void *arm_coherent_iommu_alloc_attrs (struct device *dev,size_t size, -dma_addr_t *handle,gfp_t gfp,unsigned long attrs) -{ -return __arm_iommu_alloc_attrs (dev, size, handle, gfp, attrs,COHERENT ); -} - -static int __arm_iommu_mmap_attrs (struct device *dev,struct vm_area_struct *vma, +static int arm_iommu_mmap_attrs (struct device *dev,struct vm_area_struct *vma,void *cpu_addr,dma_addr_t dma_addr,size_t size,unsigned long attrs) {
@@ -1154,35 +1142,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vmaif (vma->vm_pgoff >= nr_pages)return -ENXIO ; +if (!dev->dma_coherent) + vma->vm_page_prot =__get_dma_pgprot (attrs, vma->vm_page_prot); + err =vm_map_pages (vma, pages, nr_pages);if (err)pr_err ("Remapping memory failed: %d\n" , err);return err; } -static int arm_iommu_mmap_attrs (struct device *dev, -struct vm_area_struct *vma,void *cpu_addr, -dma_addr_t dma_addr,size_t size,unsigned long attrs) -{ - vma->vm_page_prot =__get_dma_pgprot (attrs, vma->vm_page_prot); - -return __arm_iommu_mmap_attrs (dev, vma, cpu_addr, dma_addr, size, attrs); -} - -static int arm_coherent_iommu_mmap_attrs (struct device *dev, -struct vm_area_struct *vma,void *cpu_addr, -dma_addr_t dma_addr,size_t size,unsigned long attrs) -{ -return __arm_iommu_mmap_attrs (dev, vma, cpu_addr, dma_addr, size, attrs); -}/* * free a page as defined by the above mapping. * Must not be called with IRQs disabled. */ -static void __arm_iommu_free_attrs (struct device *dev,size_t size,void *cpu_addr, -dma_addr_t handle,unsigned long attrs,int coherent_flag) +static void arm_iommu_free_attrs (struct device *dev,size_t size,void *cpu_addr, +dma_addr_t handle,unsigned long attrs) { +int coherent_flag = dev->dma_coherent ?COHERENT :NORMAL ;struct page **pages; size =PAGE_ALIGN (size);
@@ -1204,19 +1181,6 @@ static void __arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_ad__iommu_free_buffer (dev, pages, size, attrs); } -static void arm_iommu_free_attrs (struct device *dev,size_t size, -void *cpu_addr,dma_addr_t handle, -unsigned long attrs) -{ -__arm_iommu_free_attrs (dev, size, cpu_addr, handle, attrs,NORMAL ); -} - -static void arm_coherent_iommu_free_attrs (struct device *dev,size_t size, -void *cpu_addr,dma_addr_t handle,unsigned long attrs) -{ -__arm_iommu_free_attrs (dev, size, cpu_addr, handle, attrs,COHERENT ); -} -static int arm_iommu_get_sgtable (struct device *dev,struct sg_table *sgt,void *cpu_addr,dma_addr_t dma_addr,size_t size,unsigned long attrs)
@@ -1236,8 +1200,7 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,*/ static int __map_sg_chunk (struct device *dev,struct scatterlist *sg,size_t size,dma_addr_t *handle, -enum dma_data_direction dir,unsigned long attrs, -bool is_coherent) +enum dma_data_direction dir,unsigned long attrs) {struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova, iova_base;
@@ -1257,7 +1220,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,phys_addr_t phys =page_to_phys (sg_page (s));unsigned int len =PAGE_ALIGN (s->offset + s->length); -if (!is_coherent && (attrs &DMA_ATTR_SKIP_CPU_SYNC ) ==0 ) +if (!dev->dma_coherent && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))__dma_page_cpu_to_dev (sg_page (s), s->offset, s->length, dir); prot =__dma_info_to_prot (dir, attrs);
@@ -1277,9 +1240,20 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,return ret; } -static int __iommu_map_sg (struct device *dev,struct scatterlist *sg,int nents, -enum dma_data_direction dir,unsigned long attrs, -bool is_coherent) +/** +* arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA +* @dev: valid struct device pointer +* @sg: list of buffers +* @nents: number of buffers to map +* @dir: DMA transfer direction +* +* Map a set of buffers described by scatterlist in streaming mode for DMA. +* The scatter gather list elements are merged together (if possible) and +* tagged with the appropriate dma address and length. They are obtained via +* sg_dma_{address,length}. +*/ +static int arm_iommu_map_sg (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) {struct scatterlist *s = sg, *dma = sg, *start = sg;int i, count =0 , ret;
@@ -1294,8 +1268,7 @@ static int __iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,if (s->offset || (size & ~PAGE_MASK ) || size + s->length > max) { ret =__map_sg_chunk (dev, start, size, - &dma->dma_address, dir, attrs, - is_coherent); + &dma->dma_address, dir, attrs);if (ret <0 ) goto bad_mapping;
@@ -1309,8 +1282,7 @@ static int __iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents, } size += s->length; } - ret =__map_sg_chunk (dev, start, size, &dma->dma_address, dir, attrs, - is_coherent); + ret =__map_sg_chunk (dev, start, size, &dma->dma_address, dir, attrs);if (ret <0 ) goto bad_mapping;
@@ -1328,44 +1300,19 @@ static int __iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents, }/** -* arm_coherent_iommu_map_sg - map a set of SG buffers for streaming mode DMA -* @dev: valid struct device pointer -* @sg: list of buffers -* @nents: number of buffers to map -* @dir: DMA transfer direction -* -* Map a set of i/o coherent buffers described by scatterlist in streaming -* mode for DMA. The scatter gather list elements are merged together (if -* possible) and tagged with the appropriate dma address and length. They are -* obtained via sg_dma_{address,length}. -*/ -static int arm_coherent_iommu_map_sg (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir,unsigned long attrs) -{ -return __iommu_map_sg (dev, sg, nents, dir, attrs, true); -} - -/** -* arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA +* arm_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg * @dev: valid struct device pointer * @sg: list of buffers -* @nents: number of buffers to map -* @dir: DMA transfer direction +* @nents: number of buffers to unmap (same as was passed to dma_map_sg) +* @dir: DMA transfer direction (same as was passed to dma_map_sg) * -* Map a set of buffers described by scatterlist in streaming mode for DMA. -* The scatter gather list elements are merged together (if possible) and -* tagged with the appropriate dma address and length. They are obtained via -* sg_dma_{address,length}. +* Unmap a set of streaming mode DMA translations. Again, CPU access +* rules concerning calls here are the same as for dma_unmap_single(). */ -static int arm_iommu_map_sg (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir,unsigned long attrs) -{ -return __iommu_map_sg (dev, sg, nents, dir, attrs, false); -} - -static void __iommu_unmap_sg (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir, -unsigned long attrs,bool is_coherent) +static void arm_iommu_unmap_sg (struct device *dev, +struct scatterlist *sg,int nents, +enum dma_data_direction dir, +unsigned long attrs) {struct scatterlist *s;int i;
@@ -1374,47 +1321,12 @@ static void __iommu_unmap_sg(struct device *dev, struct scatterlist *sg,if (sg_dma_len (s))__iommu_remove_mapping (dev,sg_dma_address (s),sg_dma_len (s)); -if (!is_coherent && (attrs &DMA_ATTR_SKIP_CPU_SYNC ) ==0 ) +if (!dev->dma_coherent && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))__dma_page_dev_to_cpu (sg_page (s), s->offset, s->length, dir); } } -/** -* arm_coherent_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg -* @dev: valid struct device pointer -* @sg: list of buffers -* @nents: number of buffers to unmap (same as was passed to dma_map_sg) -* @dir: DMA transfer direction (same as was passed to dma_map_sg) -* -* Unmap a set of streaming mode DMA translations. Again, CPU access -* rules concerning calls here are the same as for dma_unmap_single(). -*/ -static void arm_coherent_iommu_unmap_sg (struct device *dev, -struct scatterlist *sg,int nents,enum dma_data_direction dir, -unsigned long attrs) -{ -__iommu_unmap_sg (dev, sg, nents, dir, attrs, true); -} - -/** -* arm_iommu_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg -* @dev: valid struct device pointer -* @sg: list of buffers -* @nents: number of buffers to unmap (same as was passed to dma_map_sg) -* @dir: DMA transfer direction (same as was passed to dma_map_sg) -* -* Unmap a set of streaming mode DMA translations. Again, CPU access -* rules concerning calls here are the same as for dma_unmap_single(). -*/ -static void arm_iommu_unmap_sg (struct device *dev, -struct scatterlist *sg,int nents, -enum dma_data_direction dir, -unsigned long attrs) -{ -__iommu_unmap_sg (dev, sg, nents, dir, attrs, false); -} -/** * arm_iommu_sync_sg_for_cpu * @dev: valid struct device pointer
@@ -1452,18 +1364,17 @@ static void arm_iommu_sync_sg_for_device(struct device *dev,__dma_page_cpu_to_dev (sg_page (s), s->offset, s->length, dir); } -/** -* arm_coherent_iommu_map_page +* arm_iommu_map_page * @dev: valid struct device pointer * @page: page that buffer resides in * @offset: offset into page for start of buffer * @size: size of buffer to map * @dir: DMA transfer direction * -* Coherent IOMMU aware version of arm_dma_map_page() +* IOMMU aware version of arm_dma_map_page() */ -static dma_addr_t arm_coherent_iommu_map_page (struct device *dev,struct page *page, +static dma_addr_t arm_iommu_map_page (struct device *dev,struct page *page,unsigned long offset,size_t size,enum dma_data_direction dir,unsigned long attrs) {
@@ -1471,6 +1382,9 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *pdma_addr_t dma_addr;int ret, prot, len =PAGE_ALIGN (size + offset); +if (!dev->dma_coherent && !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_page_cpu_to_dev (page, offset, size, dir); + dma_addr =__alloc_iova (mapping, len);if (dma_addr ==DMA_MAPPING_ERROR )return dma_addr;
@@ -1487,50 +1401,6 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *preturn DMA_MAPPING_ERROR ; } -/** -* arm_iommu_map_page -* @dev: valid struct device pointer -* @page: page that buffer resides in -* @offset: offset into page for start of buffer -* @size: size of buffer to map -* @dir: DMA transfer direction -* -* IOMMU aware version of arm_dma_map_page() -*/ -static dma_addr_t arm_iommu_map_page (struct device *dev,struct page *page, -unsigned long offset,size_t size,enum dma_data_direction dir, -unsigned long attrs) -{ -if ((attrs &DMA_ATTR_SKIP_CPU_SYNC ) ==0 ) -__dma_page_cpu_to_dev (page, offset, size, dir); - -return arm_coherent_iommu_map_page (dev, page, offset, size, dir, attrs); -} - -/** -* arm_coherent_iommu_unmap_page -* @dev: valid struct device pointer -* @handle: DMA address of buffer -* @size: size of buffer (same as passed to dma_map_page) -* @dir: DMA transfer direction (same as passed to dma_map_page) -* -* Coherent IOMMU aware version of arm_dma_unmap_page() -*/ -static void arm_coherent_iommu_unmap_page (struct device *dev,dma_addr_t handle, -size_t size,enum dma_data_direction dir,unsigned long attrs) -{ -struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev); -dma_addr_t iova = handle &PAGE_MASK ; -int offset = handle & ~PAGE_MASK ; -int len =PAGE_ALIGN (size + offset); - -if (!iova) -return ; - -iommu_unmap (mapping->domain, iova, len); -__free_iova (mapping, iova, len); -} -/** * arm_iommu_unmap_page * @dev: valid struct device pointer
@@ -1545,15 +1415,17 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle, {struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova = handle &PAGE_MASK ; -struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova)); +struct page *page;int offset = handle & ~PAGE_MASK ;int len =PAGE_ALIGN (size + offset);if (!iova)return ; -if ((attrs &DMA_ATTR_SKIP_CPU_SYNC ) ==0 ) +if (!dev->dma_coherent && !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) { + page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));__dma_page_dev_to_cpu (page, offset, size, dir); + }iommu_unmap (mapping->domain, iova, len);__free_iova (mapping, iova, len);
@@ -1665,16 +1537,16 @@ static const struct dma_map_ops iommu_ops = { };static const struct dma_map_ops iommu_coherent_ops = { - .alloc = arm_coherent_iommu_alloc_attrs, - .free = arm_coherent_iommu_free_attrs, - .mmap = arm_coherent_iommu_mmap_attrs, + .alloc = arm_iommu_alloc_attrs, + .free = arm_iommu_free_attrs, + .mmap = arm_iommu_mmap_attrs, .get_sgtable = arm_iommu_get_sgtable, - .map_page = arm_coherent_iommu_map_page, - .unmap_page = arm_coherent_iommu_unmap_page, + .map_page = arm_iommu_map_page, + .unmap_page = arm_iommu_unmap_page, - .map_sg = arm_coherent_iommu_map_sg, - .unmap_sg = arm_coherent_iommu_unmap_sg, + .map_sg = arm_iommu_map_sg, + .unmap_sg = arm_iommu_unmap_sg, .map_resource = arm_iommu_map_resource, .unmap_resource = arm_iommu_unmap_resource,
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 10/10 ARM/dma-mapping: merge IOMMU ops
In reply to Christoph HellwigFrom: Robin Murphy <[email protected]>
The dma_sync_* operations are now the only difference between the coherent and non-coherent IOMMU ops. Some minor tweaks to make those safe for coherent devices with minimal overhead, and we can condense down to a single set of DMA ops.
--- arch/arm/mm/dma-mapping.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-)
arch/arm/mm/dma-mapping.c +13 -24
@@ -1341,6 +1341,9 @@ static void arm_iommu_sync_sg_for_cpu(struct device *dev,struct scatterlist *s;int i; +if (dev->dma_coherent) +return ; +for_each_sg (sg, s, nents, i)__dma_page_dev_to_cpu (sg_page (s), s->offset, s->length, dir);
@@ -1360,6 +1363,9 @@ static void arm_iommu_sync_sg_for_device(struct device *dev,struct scatterlist *s;int i; +if (dev->dma_coherent) +return ; +for_each_sg (sg, s, nents, i)__dma_page_cpu_to_dev (sg_page (s), s->offset, s->length, dir); }
@@ -1493,12 +1499,13 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev, {struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova = handle &PAGE_MASK ; -struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova)); +struct page *page;unsigned int offset = handle & ~PAGE_MASK ; -if (!iova) +if (dev->dma_coherent || !iova)return ; + page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));__dma_page_dev_to_cpu (page, offset, size, dir); }
@@ -1507,12 +1514,13 @@ static void arm_iommu_sync_single_for_device(struct device *dev, {struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev);dma_addr_t iova = handle &PAGE_MASK ; -struct page *page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova)); +struct page *page;unsigned int offset = handle & ~PAGE_MASK ; -if (!iova) +if (dev->dma_coherent || !iova)return ; + page =phys_to_page (iommu_iova_to_phys (mapping->domain, iova));__dma_page_cpu_to_dev (page, offset, size, dir); }
@@ -1536,22 +1544,6 @@ static const struct dma_map_ops iommu_ops = { .unmap_resource = arm_iommu_unmap_resource, }; -static const struct dma_map_ops iommu_coherent_ops = { - .alloc = arm_iommu_alloc_attrs, - .free = arm_iommu_free_attrs, - .mmap = arm_iommu_mmap_attrs, - .get_sgtable = arm_iommu_get_sgtable, - - .map_page = arm_iommu_map_page, - .unmap_page = arm_iommu_unmap_page, - - .map_sg = arm_iommu_map_sg, - .unmap_sg = arm_iommu_unmap_sg, - - .map_resource = arm_iommu_map_resource, - .unmap_resource = arm_iommu_unmap_resource, -}; -/** * arm_iommu_create_mapping * @bus: pointer to the bus holding the client device (for IOMMU calls)
@@ -1750,10 +1742,7 @@ static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,return ; } -if (coherent) -set_dma_ops (dev, &iommu_coherent_ops); -else -set_dma_ops (dev, &iommu_ops); +set_dma_ops (dev, &iommu_ops); }static void arm_teardown_iommu_dma_ops (struct device *dev)
Signature · 6 lines
2.30.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Any comments or additional testing? It would be really great to get this off the table.
Quoted 38 lines · Christoph Hellwig
Hi all,
arm is the last platform not using the dma-direct code for directly mapped DMA. With the dmaboune removal from Arnd we can easily switch arm to always use dma-direct now (it already does for LPAE configs and nommu). I'd love to merge this series through the dma-mapping tree as it gives us the opportunity for additional core dma-mapping improvements.
Changes since v2:
- rebased to Linux 5.19-rc2Changes since v1:
- remove another unused function
- improve a few commit logs
- add three more patches from RobinDiffstat:
arch/arm/common/dmabounce.c | 582 ----------------- arch/arm/include/asm/dma-mapping.h | 128 --- b/arch/arm/Kconfig | 5 b/arch/arm/common/Kconfig | 6 b/arch/arm/common/Makefile | 1 b/arch/arm/common/sa1111.c | 64 - b/arch/arm/include/asm/device.h | 3 b/arch/arm/include/asm/dma-direct.h | 49 - b/arch/arm/include/asm/memory.h | 2 b/arch/arm/mach-footbridge/Kconfig | 1 b/arch/arm/mach-footbridge/common.c | 19 b/arch/arm/mach-footbridge/include/mach/dma-direct.h | 8 b/arch/arm/mach-footbridge/include/mach/memory.h | 4 b/arch/arm/mach-highbank/highbank.c | 2 b/arch/arm/mach-mvebu/coherency.c | 2 b/arch/arm/mm/dma-mapping.c | 649 ++----------------- b/drivers/usb/core/hcd.c | 17 b/drivers/usb/host/ohci-sa1111.c | 25 18 files changed, 137 insertions(+), 1430 deletions(-)
Quoted 4 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
---end quoted text---
Quoted 2 lines · Christoph Hellwig
Any comments or additional testing? It would be really great to get this off the table.
For the USB bits:
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · Christoph Hellwig
Any comments or additional testing? It would be really great to get this off the table.
For the USB bits:
So given that we're not making any progress on getting anyone interested on the series, I'm tempted to just pull it into the dma-mapping tree this weekend so that we'll finally have all architectures using the common code.
Anyone who has real concerns, please scream now.
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Greg Kroah-Hartman
Quoted 2 lines · Christoph Hellwig
Any comments or additional testing? It would be really great to get this off the table.
Quoted 8 lines
Quoted 3 lines
For the USB bits:
So given that we're not making any progress on getting anyone interested on the series, I'm tempted to just pull it into the dma-mapping tree this weekend so that we'll finally have all architectures using the common code.
Yes, please do!
Getting it into linux-next now should give plenty of time to test it with the automated kernelci and lkft systems, as well as Russell's Assabet. I'm sure we can fix up any regressions before this actually hits the 5.20 release.
Arnd
Greg Kroah-Hartman
maintainerQuoted 7 lines · Christoph Hellwig
Quoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Christoph Hellwig
Any comments or additional testing? It would be really great to get this off the table.
For the USB bits:
Quoted 8 lines
Quoted 1 line
So given that we're not making any progress on getting anyone interested on the series, I'm tempted to just pull it into the dma-mapping tree this weekend so that we'll finally have all architectures using the common code.
Anyone who has real concerns, please scream now.
Sounds like a good plan to me, pull it in and let's see if anyone even notices.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line
Anyone who has real concerns, please scream now.
Sounds like a good plan to me, pull it in and let's see if anyone even notices.
Ok, I've added the series to the dma-mapping tree now.