Skip to content

Commit 6ce0d20

Browse files
grygoriySSantosh Shilimkar
authored and
Santosh Shilimkar
committed
ARM: dma: Use dma_pfn_offset for dma address translation
In most of cases DMA addresses can be performed using offset value of Bus address space relatively to physical address space as following: PFN->DMA: __pfn_to_phys(pfn + [-]dma_pfn_offset) DMA->PFN: __phys_to_pfn(dma_addr) + [-]dma_pfn_offset Thanks to Russell King for suggesting the optimised macro's for conversion. Cc: Greg Kroah-Hartman <[email protected]> Cc: Russell King <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Olof Johansson <[email protected]> Cc: Grant Likely <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Linus Walleij <[email protected]> Reviewed-by: Rob Herring <[email protected]> Signed-off-by: Grygorii Strashko <[email protected]> Signed-off-by: Santosh Shilimkar <[email protected]>
1 parent 591c1ee commit 6ce0d20

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,37 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
5858
#ifndef __arch_pfn_to_dma
5959
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
6060
{
61+
if (dev)
62+
pfn -= dev->dma_pfn_offset;
6163
return (dma_addr_t)__pfn_to_bus(pfn);
6264
}
6365

6466
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
6567
{
66-
return __bus_to_pfn(addr);
68+
unsigned long pfn = __bus_to_pfn(addr);
69+
70+
if (dev)
71+
pfn += dev->dma_pfn_offset;
72+
73+
return pfn;
6774
}
6875

6976
static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
7077
{
78+
if (dev) {
79+
unsigned long pfn = dma_to_pfn(dev, addr);
80+
81+
return phys_to_virt(__pfn_to_phys(pfn));
82+
}
83+
7184
return (void *)__bus_to_virt((unsigned long)addr);
7285
}
7386

7487
static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
7588
{
89+
if (dev)
90+
return pfn_to_dma(dev, virt_to_pfn(addr));
91+
7692
return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
7793
}
7894

0 commit comments

Comments
 (0)