]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/commitdiff
dma-coherent: pass dma_handle to dma_release_coherent_attr()
authorSri Krishna chowdary <schowdary@nvidia.com>
Mon, 23 May 2016 09:38:34 +0000 (15:08 +0530)
committerSachin Nikam <snikam@nvidia.com>
Wed, 8 Jun 2016 08:05:44 +0000 (01:05 -0700)
dma_release_coherent_dev() and dma_release_coherent_heap_dev() decide
whether to treat vaddr as physical address or virtual address on the
basis of DMA_MEMORY_NOMAP flag passed during the coherent device init.

This should be transparent to client which just calls dma_free_attrs()
and does not know the implementation. However, on TOT, it is not.
The client needs to pass dma_handle as the vaddr in dma_free_attrs()
in order to release the memory properly.

Adding a dma_handle argument to dma_release_coherent_attr() should
allow us to achieve the required transparency and at the same time
since in the current implementation, the only valid case where
vaddr is NULL and dma_handle is not DMA_ERROR_CODE is when the
coherent device was initialized with DMA_MEMORY_NOMEM, it can pass
dma_handle as vaddr from within.

JIRA TMM-40

Change-Id: Ib69f650607fade636e223c588158bed61d0e3079
Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Reviewed-on: http://git-master/r/1151791
(cherry picked from commit c3788074303e411fcfc0f6994792fd856e17bfe3)
Reviewed-on: http://git-master/r/1159926
GVS: Gerrit_Virtual_Submit
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
arch/arm64/mm/dma-mapping.c
drivers/base/dma-coherent.c
include/asm-generic/dma-coherent.h

index f9510ca5fba40e0b0300b2265e4563bd45c7eaa9..b4e5e8d698fe248dd3dd8153962b3ec7ae52946e 100644 (file)
@@ -1086,7 +1086,8 @@ static void __arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
 {
        struct page *page = pfn_to_page(dma_to_pfn(dev, handle));
 
-       if (dma_release_from_coherent_attr(dev, size, cpu_addr, attrs))
+       if (dma_release_from_coherent_attr(dev, size, cpu_addr,
+               attrs, handle))
                return;
 
        if (dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs)) {
index ed5249fc0ab59b1f3370f922506436dcf9f66d3d..9cfd7318d245090b33a2cd965c6f927261d60891 100644 (file)
@@ -983,11 +983,19 @@ EXPORT_SYMBOL(dma_alloc_from_coherent_attr);
  * generic pools.
  */
 int dma_release_from_coherent_attr(struct device *dev, size_t size, void *vaddr,
-                               struct dma_attrs *attrs)
+                       struct dma_attrs *attrs, dma_addr_t dma_handle)
 {
        if (!dev)
                return 0;
 
+       if (!vaddr)
+               /*
+                * The only possible valid case where vaddr is NULL is when
+                * dma_alloc_attrs() is called on coherent dev which was
+                * initialized with DMA_MEMORY_NOMAP.
+                */
+               vaddr = (void *)dma_handle;
+
        if (dev->dma_mem)
                return dma_release_from_coherent_dev(dev, size, vaddr, attrs);
        else
index 143b3cf397236f94b4266036532d9a274137c485..c9cd754322d42dfdde49bed31aeca1b78f2a751b 100644 (file)
@@ -10,11 +10,12 @@ int dma_alloc_from_coherent_attr(struct device *dev, ssize_t size,
                                       dma_addr_t *dma_handle, void **ret,
                                       struct dma_attrs *attrs);
 int dma_release_from_coherent_attr(struct device *dev, size_t size, void *vaddr,
-                                      struct dma_attrs *attrs);
+                                      struct dma_attrs *attrs,
+                                      dma_addr_t dma_handle);
 #define dma_alloc_from_coherent(d, s, h, r) \
         dma_alloc_from_coherent_attr(d, s, h, r, NULL)
 #define dma_release_from_coherent(d, s, v) \
-        dma_release_from_coherent_attr(d, s, v, NULL)
+        dma_release_from_coherent_attr(d, s, v, NULL, 0)
 
 int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
                            void *cpu_addr, size_t size, int *ret);