Skip to content

Commit fec777c

Browse files
Christoph HellwigIngo Molnar
authored andcommitted
x86/dma: Use DMA-direct (CONFIG_DMA_DIRECT_OPS=y)
The generic DMA-direct (CONFIG_DMA_DIRECT_OPS=y) implementation is now functionally equivalent to the x86 nommu dma_map implementation, so switch over to using it. That includes switching from using x86_dma_supported in various IOMMU drivers to use dma_direct_supported instead, which provides the same functionality. Tested-by: Tom Lendacky <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jon Mason <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Muli Ben-Yehuda <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 038d07a commit fec777c

File tree

11 files changed

+17
-90
lines changed

11 files changed

+17
-90
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ config X86
8383
select CLOCKSOURCE_VALIDATE_LAST_CYCLE
8484
select CLOCKSOURCE_WATCHDOG
8585
select DCACHE_WORD_ACCESS
86+
select DMA_DIRECT_OPS
8687
select EDAC_ATOMIC_SCRUB
8788
select EDAC_SUPPORT
8889
select GENERIC_CLOCKEVENTS

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ int arch_dma_supported(struct device *dev, u64 mask);
3636
bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
3737
#define arch_dma_alloc_attrs arch_dma_alloc_attrs
3838

39-
extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
40-
dma_addr_t *dma_addr, gfp_t flag,
41-
unsigned long attrs);
42-
43-
extern void dma_generic_free_coherent(struct device *dev, size_t size,
44-
void *vaddr, dma_addr_t dma_addr,
45-
unsigned long attrs);
46-
4739
static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp)
4840
{
4941
if (dev->coherent_dma_mask <= DMA_BIT_MASK(24))

arch/x86/include/asm/iommu.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
#ifndef _ASM_X86_IOMMU_H
33
#define _ASM_X86_IOMMU_H
44

5-
extern const struct dma_map_ops nommu_dma_ops;
65
extern int force_iommu, no_iommu;
76
extern int iommu_detected;
87
extern int iommu_pass_through;
98

10-
int x86_dma_supported(struct device *dev, u64 mask);
11-
129
/* 10 seconds */
1310
#define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
1411

arch/x86/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o
5757
obj-$(CONFIG_SYSFS) += ksysfs.o
5858
obj-y += bootflag.o e820.o
5959
obj-y += pci-dma.o quirks.o topology.o kdebugfs.o
60-
obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o
60+
obj-y += alternative.o i8253.o hw_breakpoint.o
6161
obj-y += tsc.o tsc_msr.o io_delay.o rtc.o
6262
obj-y += pci-iommu_table.o
6363
obj-y += resource.o

arch/x86/kernel/amd_gart_64.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
501501
}
502502
__free_pages(page, get_order(size));
503503
} else
504-
return dma_generic_alloc_coherent(dev, size, dma_addr, flag,
505-
attrs);
504+
return dma_direct_alloc(dev, size, dma_addr, flag, attrs);
506505

507506
return NULL;
508507
}
@@ -513,7 +512,7 @@ gart_free_coherent(struct device *dev, size_t size, void *vaddr,
513512
dma_addr_t dma_addr, unsigned long attrs)
514513
{
515514
gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, 0);
516-
dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
515+
dma_direct_free(dev, size, vaddr, dma_addr, attrs);
517516
}
518517

519518
static int gart_mapping_error(struct device *dev, dma_addr_t dma_addr)
@@ -705,7 +704,7 @@ static const struct dma_map_ops gart_dma_ops = {
705704
.alloc = gart_alloc_coherent,
706705
.free = gart_free_coherent,
707706
.mapping_error = gart_mapping_error,
708-
.dma_supported = x86_dma_supported,
707+
.dma_supported = dma_direct_supported,
709708
};
710709

711710
static void gart_iommu_shutdown(void)

arch/x86/kernel/pci-calgary_64.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/string.h>
3434
#include <linux/crash_dump.h>
3535
#include <linux/dma-mapping.h>
36+
#include <linux/dma-direct.h>
3637
#include <linux/bitmap.h>
3738
#include <linux/pci_ids.h>
3839
#include <linux/pci.h>
@@ -493,7 +494,7 @@ static const struct dma_map_ops calgary_dma_ops = {
493494
.map_page = calgary_map_page,
494495
.unmap_page = calgary_unmap_page,
495496
.mapping_error = calgary_mapping_error,
496-
.dma_supported = x86_dma_supported,
497+
.dma_supported = dma_direct_supported,
497498
};
498499

499500
static inline void __iomem * busno_to_bbar(unsigned char num)

arch/x86/kernel/pci-dma.c

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
static int forbid_dac __read_mostly;
2020

21-
const struct dma_map_ops *dma_ops = &nommu_dma_ops;
21+
const struct dma_map_ops *dma_ops = &dma_direct_ops;
2222
EXPORT_SYMBOL(dma_ops);
2323

2424
static int iommu_sac_force __read_mostly;
@@ -76,60 +76,6 @@ void __init pci_iommu_alloc(void)
7676
}
7777
}
7878
}
79-
void *dma_generic_alloc_coherent(struct device *dev, size_t size,
80-
dma_addr_t *dma_addr, gfp_t flag,
81-
unsigned long attrs)
82-
{
83-
struct page *page;
84-
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
85-
dma_addr_t addr;
86-
87-
again:
88-
page = NULL;
89-
/* CMA can be used only in the context which permits sleeping */
90-
if (gfpflags_allow_blocking(flag)) {
91-
page = dma_alloc_from_contiguous(dev, count, get_order(size),
92-
flag);
93-
if (page) {
94-
addr = phys_to_dma(dev, page_to_phys(page));
95-
if (addr + size > dev->coherent_dma_mask) {
96-
dma_release_from_contiguous(dev, page, count);
97-
page = NULL;
98-
}
99-
}
100-
}
101-
/* fallback */
102-
if (!page)
103-
page = alloc_pages_node(dev_to_node(dev), flag, get_order(size));
104-
if (!page)
105-
return NULL;
106-
107-
addr = phys_to_dma(dev, page_to_phys(page));
108-
if (addr + size > dev->coherent_dma_mask) {
109-
__free_pages(page, get_order(size));
110-
111-
if (dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
112-
!(flag & GFP_DMA)) {
113-
flag = (flag & ~GFP_DMA32) | GFP_DMA;
114-
goto again;
115-
}
116-
117-
return NULL;
118-
}
119-
memset(page_address(page), 0, size);
120-
*dma_addr = addr;
121-
return page_address(page);
122-
}
123-
124-
void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr,
125-
dma_addr_t dma_addr, unsigned long attrs)
126-
{
127-
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
128-
struct page *page = virt_to_page(vaddr);
129-
130-
if (!dma_release_from_contiguous(dev, page, count))
131-
free_pages((unsigned long)vaddr, get_order(size));
132-
}
13379

13480
bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp)
13581
{
@@ -243,16 +189,6 @@ int arch_dma_supported(struct device *dev, u64 mask)
243189
}
244190
EXPORT_SYMBOL(arch_dma_supported);
245191

246-
int x86_dma_supported(struct device *dev, u64 mask)
247-
{
248-
/* Copied from i386. Doesn't make much sense, because it will
249-
only work for pci_alloc_coherent.
250-
The caller just has to use GFP_DMA in this case. */
251-
if (mask < DMA_BIT_MASK(24))
252-
return 0;
253-
return 1;
254-
}
255-
256192
static int __init pci_iommu_init(void)
257193
{
258194
struct iommu_table_entry *p;

arch/x86/kernel/pci-swiotlb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
3030
*/
3131
flags |= __GFP_NOWARN;
3232

33-
vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags,
34-
attrs);
33+
vaddr = dma_direct_alloc(hwdev, size, dma_handle, flags, attrs);
3534
if (vaddr)
3635
return vaddr;
3736

@@ -45,7 +44,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
4544
if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
4645
swiotlb_free_coherent(dev, size, vaddr, dma_addr);
4746
else
48-
dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
47+
dma_direct_free(dev, size, vaddr, dma_addr, attrs);
4948
}
5049

5150
static const struct dma_map_ops x86_swiotlb_dma_ops = {

arch/x86/pci/sta2x11-fixup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static const struct dma_map_ops sta2x11_dma_ops = {
193193
.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
194194
.sync_sg_for_device = swiotlb_sync_sg_for_device,
195195
.mapping_error = swiotlb_dma_mapping_error,
196-
.dma_supported = x86_dma_supported,
196+
.dma_supported = dma_direct_supported,
197197
};
198198

199199
/* At setup time, we use our own ops if the device is a ConneXt one */

drivers/iommu/amd_iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/debugfs.h>
2929
#include <linux/scatterlist.h>
3030
#include <linux/dma-mapping.h>
31+
#include <linux/dma-direct.h>
3132
#include <linux/iommu-helper.h>
3233
#include <linux/iommu.h>
3334
#include <linux/delay.h>
@@ -2193,7 +2194,7 @@ static int amd_iommu_add_device(struct device *dev)
21932194
dev_name(dev));
21942195

21952196
iommu_ignore_device(dev);
2196-
dev->dma_ops = &nommu_dma_ops;
2197+
dev->dma_ops = &dma_direct_ops;
21972198
goto out;
21982199
}
21992200
init_iommu_group(dev);
@@ -2680,7 +2681,7 @@ static void free_coherent(struct device *dev, size_t size,
26802681
*/
26812682
static int amd_iommu_dma_supported(struct device *dev, u64 mask)
26822683
{
2683-
if (!x86_dma_supported(dev, mask))
2684+
if (!dma_direct_supported(dev, mask))
26842685
return 0;
26852686
return check_device(dev);
26862687
}
@@ -2794,7 +2795,7 @@ int __init amd_iommu_init_dma_ops(void)
27942795
* continue to be SWIOTLB.
27952796
*/
27962797
if (!swiotlb)
2797-
dma_ops = &nommu_dma_ops;
2798+
dma_ops = &dma_direct_ops;
27982799

27992800
if (amd_iommu_unmap_flush)
28002801
pr_info("AMD-Vi: IO/TLB flush on unmap enabled\n");

drivers/iommu/intel-iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <linux/pci-ats.h>
4646
#include <linux/memblock.h>
4747
#include <linux/dma-contiguous.h>
48+
#include <linux/dma-direct.h>
4849
#include <linux/crash_dump.h>
4950
#include <asm/irq_remapping.h>
5051
#include <asm/cacheflush.h>
@@ -3871,7 +3872,7 @@ const struct dma_map_ops intel_dma_ops = {
38713872
.unmap_page = intel_unmap_page,
38723873
.mapping_error = intel_mapping_error,
38733874
#ifdef CONFIG_X86
3874-
.dma_supported = x86_dma_supported,
3875+
.dma_supported = dma_direct_supported,
38753876
#endif
38763877
};
38773878

0 commit comments

Comments
 (0)