[PATCH 10/15] dma-direct: Invoke dma offset func if needed
From: Jim Quinlan
Date: Tue May 19 2020 - 16:35:08 EST
Just like dma_pfn_offset, another offset is added to
the dma/phys translation if there happen to be multiple
regions that have different mapping offsets.
Signed-off-by: Jim Quinlan <james.quinlan@xxxxxxxxxxxx>
---
include/linux/dma-direct.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 24b8684aa21d..825a773dbbc3 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -15,6 +15,14 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
{
dma_addr_t dev_addr = (dma_addr_t)paddr;
+#ifdef CONFIG_DMA_PFN_OFFSET_MAP
+ if (unlikely(dev->dma_offset_map)) {
+ unsigned long dma_pfn_offset = dma_pfn_offset_frm_phys_addr(
+ dev->dma_offset_map, paddr);
+
+ return dev_addr - ((dma_addr_t)dma_pfn_offset << PAGE_SHIFT);
+ }
+#endif
return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
}
@@ -22,6 +30,14 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
{
phys_addr_t paddr = (phys_addr_t)dev_addr;
+#ifdef CONFIG_DMA_PFN_OFFSET_MAP
+ if (unlikely(dev->dma_offset_map)) {
+ unsigned long dma_pfn_offset = dma_pfn_offset_frm_dma_addr(
+ dev->dma_offset_map, dev_addr);
+
+ return paddr + ((phys_addr_t)dma_pfn_offset << PAGE_SHIFT);
+ }
+#endif
return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
}
#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
--
2.17.1