Skip to content

Commit af6f23b

Browse files
author
Christoph Hellwig
committed
ARM/dma-mapping: use the generic versions of dma_to_phys/phys_to_dma by default
Only 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. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Tested-by: Marc Zyngier <[email protected]>
1 parent f9774cf commit af6f23b

File tree

7 files changed

+21
-55
lines changed

7 files changed

+21
-55
lines changed

arch/arm/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ config ARM
1515
select ARCH_HAS_MEMBARRIER_SYNC_CORE
1616
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
1717
select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
18-
select ARCH_HAS_PHYS_TO_DMA
1918
select ARCH_HAS_SETUP_DMA_OPS
2019
select ARCH_HAS_SET_MEMORY
2120
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL

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

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1 @@
1-
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef ASM_ARM_DMA_DIRECT_H
3-
#define ASM_ARM_DMA_DIRECT_H 1
4-
5-
#include <asm/memory.h>
6-
7-
/*
8-
* dma_to_pfn/pfn_to_dma are architecture private
9-
* functions used internally by the DMA-mapping API to provide DMA
10-
* addresses. They must not be used by drivers.
11-
*/
12-
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
13-
{
14-
if (dev && dev->dma_range_map)
15-
pfn = PFN_DOWN(translate_phys_to_dma(dev, PFN_PHYS(pfn)));
16-
return (dma_addr_t)__pfn_to_bus(pfn);
17-
}
18-
19-
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
20-
{
21-
unsigned long pfn = __bus_to_pfn(addr);
22-
23-
if (dev && dev->dma_range_map)
24-
pfn = PFN_DOWN(translate_dma_to_phys(dev, PFN_PHYS(pfn)));
25-
return pfn;
26-
}
27-
28-
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
29-
{
30-
unsigned int offset = paddr & ~PAGE_MASK;
31-
return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
32-
}
33-
34-
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
35-
{
36-
unsigned int offset = dev_addr & ~PAGE_MASK;
37-
return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
38-
}
39-
40-
#endif /* ASM_ARM_DMA_DIRECT_H */
1+
#include <mach/dma-direct.h>

arch/arm/include/asm/memory.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ static inline unsigned long __virt_to_idmap(unsigned long x)
378378
#ifndef __virt_to_bus
379379
#define __virt_to_bus __virt_to_phys
380380
#define __bus_to_virt __phys_to_virt
381-
#define __pfn_to_bus(x) __pfn_to_phys(x)
382-
#define __bus_to_pfn(x) __phys_to_pfn(x)
383381
#endif
384382

385383
/*

arch/arm/mach-footbridge/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ endmenu
6060

6161
# Footbridge support
6262
config FOOTBRIDGE
63+
select ARCH_HAS_PHYS_TO_DMA
6364
bool
6465

6566
# Footbridge in host mode

arch/arm/mach-footbridge/common.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/io.h>
1414
#include <linux/spinlock.h>
15+
#include <linux/dma-direct.h>
1516
#include <video/vga.h>
1617

1718
#include <asm/page.h>
@@ -335,17 +336,19 @@ unsigned long __bus_to_virt(unsigned long res)
335336
return res;
336337
}
337338
EXPORT_SYMBOL(__bus_to_virt);
338-
339-
unsigned long __pfn_to_bus(unsigned long pfn)
339+
#else
340+
static inline unsigned long fb_bus_sdram_offset(void)
340341
{
341-
return __pfn_to_phys(pfn) + (fb_bus_sdram_offset() - PHYS_OFFSET);
342+
return BUS_OFFSET;
342343
}
343-
EXPORT_SYMBOL(__pfn_to_bus);
344+
#endif /* CONFIG_FOOTBRIDGE_ADDIN */
344345

345-
unsigned long __bus_to_pfn(unsigned long bus)
346+
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
346347
{
347-
return __phys_to_pfn(bus - (fb_bus_sdram_offset() - PHYS_OFFSET));
348+
return paddr + (fb_bus_sdram_offset() - PHYS_OFFSET);
348349
}
349-
EXPORT_SYMBOL(__bus_to_pfn);
350350

351-
#endif
351+
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
352+
{
353+
return dev_addr - (fb_bus_sdram_offset() - PHYS_OFFSET);
354+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef MACH_FOOTBRIDGE_DMA_DIRECT_H
3+
#define MACH_FOOTBRIDGE_DMA_DIRECT_H 1
4+
5+
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
6+
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr);
7+
8+
#endif /* MACH_FOOTBRIDGE_DMA_DIRECT_H */

arch/arm/mach-footbridge/include/mach/memory.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#ifndef __ASSEMBLY__
2727
extern unsigned long __virt_to_bus(unsigned long);
2828
extern unsigned long __bus_to_virt(unsigned long);
29-
extern unsigned long __pfn_to_bus(unsigned long);
30-
extern unsigned long __bus_to_pfn(unsigned long);
3129
#endif
3230
#define __virt_to_bus __virt_to_bus
3331
#define __bus_to_virt __bus_to_virt
@@ -42,8 +40,6 @@ extern unsigned long __bus_to_pfn(unsigned long);
4240
#define BUS_OFFSET 0xe0000000
4341
#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
4442
#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
45-
#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PHYS_OFFSET))
46-
#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PHYS_OFFSET))
4743

4844
#else
4945

0 commit comments

Comments
 (0)