Skip to content

Commit abdaf11

Browse files
author
Christoph Hellwig
committed
dma-mapping: add (back) arch_dma_mark_clean for ia64
Add back a hook to optimize dcache flushing after reading executable code using DMA. This gets ia64 out of the business of pretending to be dma incoherent just for this optimization. Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent ef1a85b commit abdaf11

7 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎arch/ia64/Kconfig‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ menu "Processor type and features"
88

99
config IA64
1010
bool
11+
select ARCH_HAS_DMA_MARK_CLEAN
1112
select ARCH_MIGHT_HAVE_PC_PARPORT
1213
select ARCH_MIGHT_HAVE_PC_SERIO
1314
select ACPI
@@ -32,8 +33,6 @@ config IA64
3233
select TTY
3334
select HAVE_ARCH_TRACEHOOK
3435
select HAVE_VIRT_CPU_ACCOUNTING
35-
select DMA_NONCOHERENT_MMAP
36-
select ARCH_HAS_SYNC_DMA_FOR_CPU
3736
select VIRT_TO_BUS
3837
select GENERIC_IRQ_PROBE
3938
select GENERIC_PENDING_IRQ if SMP

‎arch/ia64/kernel/dma-mapping.c‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#include <linux/dma-direct.h>
2+
#include <linux/dma-mapping.h>
33
#include <linux/export.h>
44

55
/* Set this to 1 if there is a HW IOMMU in the system */
66
int iommu_detected __read_mostly;
77

88
const struct dma_map_ops *dma_ops;
99
EXPORT_SYMBOL(dma_ops);
10-
11-
void *arch_dma_alloc(struct device *dev, size_t size,
12-
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
13-
{
14-
return dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs);
15-
}
16-
17-
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
18-
dma_addr_t dma_addr, unsigned long attrs)
19-
{
20-
dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs);
21-
}

‎arch/ia64/mm/init.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ __ia64_sync_icache_dcache (pte_t pte)
7373
* DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to
7474
* flush them when they get mapped into an executable vm-area.
7575
*/
76-
void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
77-
enum dma_data_direction dir)
76+
void arch_dma_mark_clean(phys_addr_t paddr, size_t size)
7877
{
7978
unsigned long pfn = PHYS_PFN(paddr);
8079

‎include/linux/dma-direct.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static inline void dma_direct_sync_single_for_cpu(struct device *dev,
150150

151151
if (unlikely(is_swiotlb_buffer(paddr)))
152152
swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU);
153+
154+
if (dir == DMA_FROM_DEVICE)
155+
arch_dma_mark_clean(paddr, size);
153156
}
154157

155158
static inline dma_addr_t dma_direct_map_page(struct device *dev,

‎include/linux/dma-noncoherent.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ static inline void arch_dma_prep_coherent(struct page *page, size_t size)
108108
}
109109
#endif /* CONFIG_ARCH_HAS_DMA_PREP_COHERENT */
110110

111+
#ifdef CONFIG_ARCH_HAS_DMA_MARK_CLEAN
112+
void arch_dma_mark_clean(phys_addr_t paddr, size_t size);
113+
#else
114+
static inline void arch_dma_mark_clean(phys_addr_t paddr, size_t size)
115+
{
116+
}
117+
#endif /* ARCH_HAS_DMA_MARK_CLEAN */
118+
111119
void *arch_dma_set_uncached(void *addr, size_t size);
112120
void arch_dma_clear_uncached(void *addr, size_t size);
113121

‎kernel/dma/Kconfig‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ config ARCH_HAS_DMA_SET_MASK
4444
config ARCH_HAS_DMA_WRITE_COMBINE
4545
bool
4646

47+
#
48+
# Select if the architectures provides the arch_dma_mark_clean hook
49+
#
50+
config ARCH_HAS_DMA_MARK_CLEAN
51+
bool
52+
4753
config DMA_DECLARE_COHERENT
4854
bool
4955

‎kernel/dma/direct.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ void dma_direct_sync_sg_for_cpu(struct device *dev,
345345
if (unlikely(is_swiotlb_buffer(paddr)))
346346
swiotlb_tbl_sync_single(dev, paddr, sg->length, dir,
347347
SYNC_FOR_CPU);
348+
349+
if (dir == DMA_FROM_DEVICE)
350+
arch_dma_mark_clean(paddr, sg->length);
348351
}
349352

350353
if (!dev_is_dma_coherent(dev))

0 commit comments

Comments
 (0)