From a3c08076050ddd0bb14c3ad2e47b1312ef78a726 Mon Sep 17 00:00:00 2001 From: Liam Mark Date: Mon, 5 Nov 2018 14:33:06 -0800 Subject: [PATCH] ANDROID: GKI: dma-coherent: Expose device base address and size Allow clients to be able to determine the device base address and size of a dma coherent memory region. This is required for clients that want to explicitly manage that memory. Change-Id: I3e5b721d9d318526422ec26995cc1af7b7f04077 Signed-off-by: Liam Mark (cherry picked from commit 63585739d1881d987c0c0f06199cf749ad62c6d1) Bug: 155522481 Signed-off-by: Mark Salyzyn [saravanak conflict resolution due to file move and Change EXPORT_SYMBOL to EXPORT_SYMBOL_GPL] Signed-off-by: Saravana Kannan --- include/linux/dma-mapping.h | 15 +++++++++++++++ kernel/dma/coherent.c | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index c62fc4e78cdb..fe87f565768e 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -771,6 +771,10 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, void dma_release_declared_memory(struct device *dev); void *dma_mark_declared_memory_occupied(struct device *dev, dma_addr_t device_addr, size_t size); +dma_addr_t dma_get_device_base(struct device *dev, + struct dma_coherent_mem *mem); +unsigned long dma_get_size(struct dma_coherent_mem *mem); + #else static inline int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, @@ -790,6 +794,17 @@ dma_mark_declared_memory_occupied(struct device *dev, { return ERR_PTR(-EBUSY); } +static inline dma_addr_t +dma_get_device_base(struct device *dev, struct dma_coherent_mem *mem) +{ + return 0; +} + +static inline unsigned long dma_get_size(struct dma_coherent_mem *mem) +{ + return 0; +} + #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ #ifdef CONFIG_HAS_DMA diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index 597d40893862..83e48618b6ca 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -29,14 +29,21 @@ static inline struct dma_coherent_mem *dev_get_coherent_memory(struct device *de return NULL; } -static inline dma_addr_t dma_get_device_base(struct device *dev, - struct dma_coherent_mem * mem) +dma_addr_t dma_get_device_base(struct device *dev, + struct dma_coherent_mem *mem) { if (mem->use_dev_dma_pfn_offset) return (mem->pfn_base - dev->dma_pfn_offset) << PAGE_SHIFT; else return mem->device_base; } +EXPORT_SYMBOL_GPL(dma_get_device_base); + +unsigned long dma_get_size(struct dma_coherent_mem *mem) +{ + return mem->size << PAGE_SHIFT; +} +EXPORT_SYMBOL_GPL(dma_get_size); static int dma_init_coherent_memory( phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags,