Skip to content

Commit 038d07a

Browse files
Christoph HellwigIngo Molnar
authored andcommitted
x86/dma: Remove dma_alloc_coherent_mask()
These days all devices (including the ISA fallback device) have a coherent DMA mask set, so remove the workaround. Tested-by: Tom Lendacky <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jon Mason <[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 3eb93ea commit 038d07a

File tree

4 files changed

+8
-40
lines changed

4 files changed

+8
-40
lines changed

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,12 @@ extern void dma_generic_free_coherent(struct device *dev, size_t size,
4444
void *vaddr, dma_addr_t dma_addr,
4545
unsigned long attrs);
4646

47-
static inline unsigned long dma_alloc_coherent_mask(struct device *dev,
48-
gfp_t gfp)
49-
{
50-
unsigned long dma_mask = 0;
51-
52-
dma_mask = dev->coherent_dma_mask;
53-
if (!dma_mask)
54-
dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32);
55-
56-
return dma_mask;
57-
}
58-
5947
static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp)
6048
{
61-
unsigned long dma_mask = dma_alloc_coherent_mask(dev, gfp);
62-
63-
if (dma_mask <= DMA_BIT_MASK(24))
49+
if (dev->coherent_dma_mask <= DMA_BIT_MASK(24))
6450
gfp |= GFP_DMA;
6551
#ifdef CONFIG_X86_64
66-
if (dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA))
52+
if (dev->coherent_dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA))
6753
gfp |= GFP_DMA32;
6854
#endif
6955
return gfp;

arch/x86/kernel/pci-dma.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,10 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
8080
dma_addr_t *dma_addr, gfp_t flag,
8181
unsigned long attrs)
8282
{
83-
unsigned long dma_mask;
8483
struct page *page;
8584
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
8685
dma_addr_t addr;
8786

88-
dma_mask = dma_alloc_coherent_mask(dev, flag);
89-
9087
again:
9188
page = NULL;
9289
/* CMA can be used only in the context which permits sleeping */
@@ -95,7 +92,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
9592
flag);
9693
if (page) {
9794
addr = phys_to_dma(dev, page_to_phys(page));
98-
if (addr + size > dma_mask) {
95+
if (addr + size > dev->coherent_dma_mask) {
9996
dma_release_from_contiguous(dev, page, count);
10097
page = NULL;
10198
}
@@ -108,10 +105,11 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
108105
return NULL;
109106

110107
addr = phys_to_dma(dev, page_to_phys(page));
111-
if (addr + size > dma_mask) {
108+
if (addr + size > dev->coherent_dma_mask) {
112109
__free_pages(page, get_order(size));
113110

114-
if (dma_mask < DMA_BIT_MASK(32) && !(flag & GFP_DMA)) {
111+
if (dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
112+
!(flag & GFP_DMA)) {
115113
flag = (flag & ~GFP_DMA32) | GFP_DMA;
116114
goto again;
117115
}

arch/x86/mm/mem_encrypt.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,10 @@ void __init sme_early_init(void)
198198
static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
199199
gfp_t gfp, unsigned long attrs)
200200
{
201-
unsigned long dma_mask;
202201
unsigned int order;
203202
struct page *page;
204203
void *vaddr = NULL;
205204

206-
dma_mask = dma_alloc_coherent_mask(dev, gfp);
207205
order = get_order(size);
208206

209207
/*
@@ -221,7 +219,7 @@ static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
221219
* mask with it already cleared.
222220
*/
223221
addr = __sme_clr(phys_to_dma(dev, page_to_phys(page)));
224-
if ((addr + size) > dma_mask) {
222+
if ((addr + size) > dev->coherent_dma_mask) {
225223
__free_pages(page, get_order(size));
226224
} else {
227225
vaddr = page_address(page);

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@
5353
* API.
5454
*/
5555

56-
#ifndef CONFIG_X86
57-
static unsigned long dma_alloc_coherent_mask(struct device *dev,
58-
gfp_t gfp)
59-
{
60-
unsigned long dma_mask = 0;
61-
62-
dma_mask = dev->coherent_dma_mask;
63-
if (!dma_mask)
64-
dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32);
65-
66-
return dma_mask;
67-
}
68-
#endif
69-
7056
#define XEN_SWIOTLB_ERROR_CODE (~(dma_addr_t)0x0)
7157

7258
static char *xen_io_tlb_start, *xen_io_tlb_end;
@@ -328,7 +314,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
328314
return ret;
329315

330316
if (hwdev && hwdev->coherent_dma_mask)
331-
dma_mask = dma_alloc_coherent_mask(hwdev, flags);
317+
dma_mask = hwdev->coherent_dma_mask;
332318

333319
/* At this point dma_handle is the physical address, next we are
334320
* going to set it to the machine address.

0 commit comments

Comments
 (0)