Issue
I want to use DMA_ATTR_NO_KERNEL_MAPPING
for memory allocation. According to the kernel documentation, I have to use dma_mmap_attrs()
, but it requires struct vm_area_struct
as one of its argument. How can I use it?
dma_addr_t phys;
void *virt;
void *tmp_virt;
struct vm_area_struct *vma;
pr_debug("pmap: cma: request to alloc %s for size 0x%08x\n",
info->name, info->size);
if(strcmp(info->name,"video") == 0)
{
pr_debug("video allocation.....\n");
tmp_virt = dma_alloc_attrs(pmap_device, info->size, &phys, GFP_KERNEL,
DMA_ATTR_NO_KERNEL_MAPPING | DMA_ATTR_FORCE_CONTIGUOUS);
virt = dma_mmap_attrs(pmap_device, vma, tmp_virt, &phys, info->size,
DMA_ATTR_NO_KERNEL_MAPPING | DMA_ATTR_FORCE_CONTIGUOUS);
}
I am requesting memory allocation using the ioctl call from user space, and then a kernel panic occurs with a system reboot.
How do I use DMA_ATTR_NO_KERNEL_MAPPING
for user space allocation using ioctl?
In my sample driver code I am declaring struct vm_area_struct *vma
. Is that correct?
Solution
if you used DMA_ATTR_NO_KERNEL_MAPPING in dma_alloc_attr(), it means that you dont want virtual mapping for the allocated area. DMA_ATTR_NO_KERNEL_MAPPING only used again to mapped with user space memory, no direct api to mapped it with kernel space memory.
if user space want to mapped it virtually, below are the options.
- Use dma_mmap_attr() in driver you have to used .map = map_user_space_function() and then use dma_mmap_attr() in that function, it will mapped to user space virtual memory.
- Use get_vm_area() in driver and use dma_mmap_attr() in which used the vm_area return by get_vm_area().
Answered By - Pankaj Suryawanshi Answer Checked By - Marie Seifert (WPSolving Admin)