Hi,

kernel mapping is implicit with dma_alloc_coherent, in consequence ion_cma_map_kernel only have to return the address of mapped memory (info->cpu_addr). unmap_kernel is useless in this context.

When DMA_ATTR_NO_KERNEL_MAPPING will be available in Android kernel, we could set it when calling dma_alloc_coherent and the mapping will become explicit with a map_kernel and unmap_kernel to do the map/unmap operations.

Regards,
Benjamin 


2012/12/6 Laura Abbott <lauraa@codeaurora.org>
Hi,


On 12/6/2012 4:50 AM, benjamin.gaignard@linaro.org wrote:
From: Benjamin Gaignard <benjamin.gaignard@linaro.org>

<snip>


+
+/* return physical address in addr */
+static int ion_cma_phys(struct ion_heap *heap, struct ion_buffer *buffer,
+                       ion_phys_addr_t *addr, size_t *len)
+{
+       struct device *dev = heap->priv;
+       struct ion_cma_buffer_info *info = buffer->priv_virt;
+
+       dev_dbg(dev, "Return buffer %p physical address 0x%x\n", buffer,
+               virt_to_phys(info->cpu_addr));
+
+       *addr = virt_to_phys(info->cpu_addr);
+       *len = buffer->size;
+
+       return 0;
+}
+
info->handle should give back the physical address so we should be able to use that directly instead of calling virt_to_phys


+struct sg_table *ion_cma_heap_map_dma(struct ion_heap *heap,
+                                        struct ion_buffer *buffer)
+{
+       struct ion_cma_buffer_info *info = buffer->priv_virt;
+
+       return info->table;
+}
+
+void ion_cma_heap_unmap_dma(struct ion_heap *heap,
+                              struct ion_buffer *buffer)
+{
+       return;
+}
+
+static int ion_cma_mmap(struct ion_heap *mapper, struct ion_buffer *buffer,
+                       struct vm_area_struct *vma)
+{
+       struct device *dev = buffer->heap->priv;
+       struct ion_cma_buffer_info *info = buffer->priv_virt;
+
+       return dma_mmap_coherent(dev, vma, info->cpu_addr, info->handle,
+                                buffer->size);
+}
+
+void *ion_cma_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer)
+{
+       struct ion_cma_buffer_info *info = buffer->priv_virt;
+       /* kernel memory mapping has been done at allocation time */
+       return info->cpu_addr;
+}
+
+static struct ion_heap_ops ion_cma_ops = {
+       .allocate = ion_cma_allocate,
+       .free = ion_cma_free,
+       .map_dma = ion_cma_heap_map_dma,
+       .unmap_dma = ion_cma_heap_unmap_dma,
+       .phys = ion_cma_phys,
+       .map_user = ion_cma_mmap,
+       .map_kernel = ion_cma_map_kernel,
+};
+

Missing the unmap_kernel?


Thanks,
Laura

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation



--

Benjamin Gaignard 

Graphic Working Group

Linaro.org │ Open source software for ARM SoCs

Follow Linaro: Facebook | Twitter | Blog