Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9257548d authored by Liam Mark's avatar Liam Mark Committed by Saravana Kannan
Browse files

ANDROID: GKI: dma-mapping: Add dma_remap functions



After getting an allocation from dma_alloc_coherent, there
may be cases where it is necessary to remap the handle
into the CPU's address space (e.g. no CPU side mapping was
requested at allocation time but now one is needed). Add
APIs to bring a handle into the CPU address space again.

Change-Id: Ieb9231c5f24d45aeb7436f643c9b87b93871f85d
Signed-off-by: default avatarLaura Abbott <lauraa@codeaurora.org>
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
[lmark@codeaurora.org: fix additional call to dma_common_free_remap]
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
Bug: 155522481
(cherry picked from commit 36e68e773c134cffe047cb1d95ebebeb91f6fbfb)
Signed-off-by: default avatarMark Salyzyn <salyzyn@google.com>
[saravanak minor conflict fixes]
Signed-off-by: default avatarSaravana Kannan <saravanak@google.com>
parent 0a85ff1b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot,
static void __dma_free_remap(void *cpu_addr, size_t size)
{
	dma_common_free_remap(cpu_addr, size,
			VM_ARM_DMA_CONSISTENT | VM_USERMAP);
			VM_ARM_DMA_CONSISTENT | VM_USERMAP, false);
}

#define DEFAULT_DMA_COHERENT_POOL_SIZE	SZ_256K
@@ -1648,7 +1648,7 @@ void __arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,

	if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) {
		dma_common_free_remap(cpu_addr, size,
			VM_ARM_DMA_CONSISTENT | VM_USERMAP);
			VM_ARM_DMA_CONSISTENT | VM_USERMAP, false);
	}

	__iommu_remove_mapping(dev, handle, size);
+3 −3
Original line number Diff line number Diff line
@@ -452,7 +452,7 @@ static int __init atomic_pool_init(void)
	goto out;

remove_mapping:
	dma_common_free_remap(addr, atomic_pool_size, VM_USERMAP);
	dma_common_free_remap(addr, atomic_pool_size, VM_USERMAP, false);
destroy_genpool:
	gen_pool_destroy(atomic_pool);
	atomic_pool = NULL;
@@ -696,14 +696,14 @@ static void __iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,

		iommu_dma_unmap_page(dev, handle, iosize, 0, attrs);
		dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT);
		dma_common_free_remap(cpu_addr, size, VM_USERMAP);
		dma_common_free_remap(cpu_addr, size, VM_USERMAP, false);
	} else if (is_vmalloc_addr(cpu_addr)){
		struct vm_struct *area = find_vm_area(cpu_addr);

		if (WARN_ON(!area || !area->pages))
			return;
		iommu_dma_free(dev, area->pages, iosize, &handle);
		dma_common_free_remap(cpu_addr, size, VM_USERMAP);
		dma_common_free_remap(cpu_addr, size, VM_USERMAP, false);
	} else {
		iommu_dma_unmap_page(dev, handle, iosize, 0, 0);
		__free_pages(virt_to_page(cpu_addr), get_order(size));
+2 −1
Original line number Diff line number Diff line
@@ -464,7 +464,8 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
void *dma_common_pages_remap(struct page **pages, size_t size,
			unsigned long vm_flags, pgprot_t prot,
			const void *caller);
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags);
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags,
			   bool nowarn);

/**
 * dma_mmap_attrs - map a coherent DMA allocation into user space
+4 −2
Original line number Diff line number Diff line
@@ -314,12 +314,14 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
/*
 * unmaps a range previously mapped by dma_common_*_remap
 */
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags)
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags,
			   bool no_warn)
{
	struct vm_struct *area = find_vm_area(cpu_addr);

	if (!area || (area->flags & vm_flags) != vm_flags) {
		WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr);
		WARN(!no_warn, "trying to free invalid coherent area: %p\n",
			cpu_addr);
		return;
	}