Skip to content

Commit 356da6d

Browse files
author
Christoph Hellwig
committed
dma-mapping: bypass indirect calls for dma-direct
Avoid expensive indirect calls in the fast path DMA mapping operations by directly calling the dma_direct_* ops if we are using the directly mapped DMA operations. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Jesper Dangaard Brouer <brouer@redhat.com> Tested-by: Jesper Dangaard Brouer <brouer@redhat.com> Tested-by: Tony Luck <tony.luck@intel.com>
1 parent 190d4e5 commit 356da6d

File tree

20 files changed

+150
-119
lines changed

20 files changed

+150
-119
lines changed

arch/alpha/include/asm/dma-mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern const struct dma_map_ops alpha_pci_ops;
77
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
88
{
99
#ifdef CONFIG_ALPHA_JENSEN
10-
return &dma_direct_ops;
10+
return NULL;
1111
#else
1212
return &alpha_pci_ops;
1313
#endif

arch/arc/mm/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ void __init arc_cache_init_master(void)
12801280
/*
12811281
* In case of IOC (say IOC+SLC case), pointers above could still be set
12821282
* but end up not being relevant as the first function in chain is not
1283-
* called at all for @dma_direct_ops
1283+
* called at all for devices using coherent DMA.
12841284
* arch_sync_dma_for_cpu() -> dma_cache_*() -> __dma_cache_*()
12851285
*/
12861286
}

arch/arm/include/asm/dma-mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern const struct dma_map_ops arm_coherent_dma_ops;
1818

1919
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
2020
{
21-
return IS_ENABLED(CONFIG_MMU) ? &arm_dma_ops : &dma_direct_ops;
21+
return IS_ENABLED(CONFIG_MMU) ? &arm_dma_ops : NULL;
2222
}
2323

2424
#ifdef __arch_page_to_dma

arch/arm/mm/dma-mapping-nommu.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "dma.h"
2323

2424
/*
25-
* dma_direct_ops is used if
25+
* The generic direct mapping code is used if
2626
* - MMU/MPU is off
2727
* - cpu is v7m w/o cache support
2828
* - device is coherent
@@ -209,16 +209,9 @@ const struct dma_map_ops arm_nommu_dma_ops = {
209209
};
210210
EXPORT_SYMBOL(arm_nommu_dma_ops);
211211

212-
static const struct dma_map_ops *arm_nommu_get_dma_map_ops(bool coherent)
213-
{
214-
return coherent ? &dma_direct_ops : &arm_nommu_dma_ops;
215-
}
216-
217212
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
218213
const struct iommu_ops *iommu, bool coherent)
219214
{
220-
const struct dma_map_ops *dma_ops;
221-
222215
if (IS_ENABLED(CONFIG_CPU_V7M)) {
223216
/*
224217
* Cache support for v7m is optional, so can be treated as
@@ -234,7 +227,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
234227
dev->archdata.dma_coherent = (get_cr() & CR_M) ? coherent : true;
235228
}
236229

237-
dma_ops = arm_nommu_get_dma_map_ops(dev->archdata.dma_coherent);
238-
239-
set_dma_ops(dev, dma_ops);
230+
if (!dev->archdata.dma_coherent)
231+
set_dma_ops(dev, &arm_nommu_dma_ops);
240232
}

arch/arm64/mm/dma-mapping.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,6 @@ static void __iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
462462
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
463463
const struct iommu_ops *iommu, bool coherent)
464464
{
465-
if (!dev->dma_ops)
466-
dev->dma_ops = &dma_direct_ops;
467-
468465
dev->dma_coherent = coherent;
469466
__iommu_setup_dma_ops(dev, dma_base, size, iommu);
470467

arch/ia64/hp/common/hwsw_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static inline int use_swiotlb(struct device *dev)
3838
const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
3939
{
4040
if (use_swiotlb(dev))
41-
return &dma_direct_ops;
41+
return NULL;
4242
return &sba_dma_ops;
4343
}
4444
EXPORT_SYMBOL(hwsw_dma_get_ops);

arch/ia64/hp/common/sba_iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ sba_init(void)
20782078
* a successful kdump kernel boot is to use the swiotlb.
20792079
*/
20802080
if (is_kdump_kernel()) {
2081-
dma_ops = &dma_direct_ops;
2081+
dma_ops = NULL;
20822082
if (swiotlb_late_init_with_default_size(64 * (1<<20)) != 0)
20832083
panic("Unable to initialize software I/O TLB:"
20842084
" Try machvec=dig boot option");
@@ -2100,7 +2100,7 @@ sba_init(void)
21002100
* If we didn't find something sba_iommu can claim, we
21012101
* need to setup the swiotlb and switch to the dig machvec.
21022102
*/
2103-
dma_ops = &dma_direct_ops;
2103+
dma_ops = NULL;
21042104
if (swiotlb_late_init_with_default_size(64 * (1<<20)) != 0)
21052105
panic("Unable to find SBA IOMMU or initialize "
21062106
"software I/O TLB: Try machvec=dig boot option");

arch/ia64/kernel/dma-mapping.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
3636

3737
void __init swiotlb_dma_init(void)
3838
{
39-
dma_ops = &dma_direct_ops;
4039
swiotlb_init(1);
4140
}
4241
#endif

arch/mips/include/asm/dma-mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
1111
#if defined(CONFIG_MACH_JAZZ)
1212
return &jazz_dma_ops;
1313
#else
14-
return &dma_direct_ops;
14+
return NULL;
1515
#endif
1616
}
1717

arch/parisc/kernel/setup.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ void __init dma_ops_init(void)
9999

100100
case pcxl2:
101101
pa7300lc_init();
102-
case pcxl: /* falls through */
103-
case pcxs:
104-
case pcxt:
105-
hppa_dma_ops = &dma_direct_ops;
106102
break;
107103
default:
108104
break;

arch/sparc/include/asm/dma-mapping.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
1212
{
1313
#ifdef CONFIG_SPARC_LEON
1414
if (sparc_cpu_model == sparc_leon)
15-
return &dma_direct_ops;
15+
return NULL;
1616
#endif
1717
#if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
1818
if (bus == &pci_bus_type)
19-
return &dma_direct_ops;
19+
return NULL;
2020
#endif
2121
return dma_ops;
2222
}

arch/x86/kernel/pci-dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
static bool disable_dac_quirk __read_mostly;
1919

20-
const struct dma_map_ops *dma_ops = &dma_direct_ops;
20+
const struct dma_map_ops *dma_ops;
2121
EXPORT_SYMBOL(dma_ops);
2222

2323
#ifdef CONFIG_IOMMU_DEBUG

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
581581

582582
dev_priv->map_mode = vmw_dma_map_populate;
583583

584-
if (dma_ops->sync_single_for_cpu)
584+
if (dma_ops && dma_ops->sync_single_for_cpu)
585585
dev_priv->map_mode = vmw_dma_alloc_coherent;
586586
#ifdef CONFIG_SWIOTLB
587587
if (swiotlb_nr_tbl() == 0)

drivers/iommu/amd_iommu.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ static int amd_iommu_add_device(struct device *dev)
21842184
dev_name(dev));
21852185

21862186
iommu_ignore_device(dev);
2187-
dev->dma_ops = &dma_direct_ops;
2187+
dev->dma_ops = NULL;
21882188
goto out;
21892189
}
21902190
init_iommu_group(dev);
@@ -2770,17 +2770,6 @@ int __init amd_iommu_init_dma_ops(void)
27702770
swiotlb = (iommu_pass_through || sme_me_mask) ? 1 : 0;
27712771
iommu_detected = 1;
27722772

2773-
/*
2774-
* In case we don't initialize SWIOTLB (actually the common case
2775-
* when AMD IOMMU is enabled and SME is not active), make sure there
2776-
* are global dma_ops set as a fall-back for devices not handled by
2777-
* this driver (for example non-PCI devices). When SME is active,
2778-
* make sure that swiotlb variable remains set so the global dma_ops
2779-
* continue to be SWIOTLB.
2780-
*/
2781-
if (!swiotlb)
2782-
dma_ops = &dma_direct_ops;
2783-
27842773
if (amd_iommu_unmap_flush)
27852774
pr_info("AMD-Vi: IO/TLB flush on unmap enabled\n");
27862775
else

include/asm-generic/dma-mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
66
{
7-
return &dma_direct_ops;
7+
return NULL;
88
}
99

1010
#endif /* _ASM_GENERIC_DMA_MAPPING_H */

include/linux/dma-direct.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,5 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
6060
struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
6161
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs);
6262
void __dma_direct_free_pages(struct device *dev, size_t size, struct page *page);
63-
dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
64-
unsigned long offset, size_t size, enum dma_data_direction dir,
65-
unsigned long attrs);
66-
void dma_direct_unmap_page(struct device *dev, dma_addr_t addr,
67-
size_t size, enum dma_data_direction dir, unsigned long attrs);
68-
int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
69-
enum dma_data_direction dir, unsigned long attrs);
70-
void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sgl,
71-
int nents, enum dma_data_direction dir, unsigned long attrs);
72-
void dma_direct_sync_single_for_device(struct device *dev,
73-
dma_addr_t addr, size_t size, enum dma_data_direction dir);
74-
void dma_direct_sync_sg_for_device(struct device *dev,
75-
struct scatterlist *sgl, int nents, enum dma_data_direction dir);
76-
void dma_direct_sync_single_for_cpu(struct device *dev,
77-
dma_addr_t addr, size_t size, enum dma_data_direction dir);
78-
void dma_direct_sync_sg_for_cpu(struct device *dev,
79-
struct scatterlist *sgl, int nents, enum dma_data_direction dir);
8063
int dma_direct_supported(struct device *dev, u64 mask);
8164
#endif /* _LINUX_DMA_DIRECT_H */

0 commit comments

Comments
 (0)