I have build an character driver in which i am allocating two PAGESIZE buffer using
dma_alloc_coherent()
Now i am passing the PHYSICAL address of these BUFFER [src_ptr & dest_ptr] to user space using
ioctl()
assource_offset
anddest_offset
.In user space this offeset is used as an offset for mmap call. So on same /dev file say /dev/250 i am making TWO MMAP call
usr_src_ptr= mmap(0,page_size, PROT_READ|PROT_WRITE, MAP_SHARED,dev_FD, src_offset ); if (usr_src_ptr == MAP_FAILED){ printf("USR[UPP]:SOURCE MMAP FAiled \n\n"); close(dev_FD); exit(-1); }else{ printf("USR[UPP]:SOURCE MMAP is %X..\n",usr_src_ptr); } usr_dest_ptr= mmap(0,page_size, PROT_READ|PROT_WRITE,MAP_SHARED, dev_FD,dest_offset ); if (usr_dest_ptr == MAP_FAILED){ printf("USR[UPP]:DEST MMAP FAiled \n\n"); close(dev_FD); exit(-1); }else{ printf("USR[UPP]:DEST MMAP is %X..\n",usr_dest_ptr); }
I am writing
0x77
inuser_src_ptr
in user space & printinguser_src_ptr
in user space anddest_src_ptr
in KERNEL space . I get correct data for both user and kernel spaceI am writng
0x55
indest_ptr
in kernel space & printingdest_ptr
in kernel space andusr_dest_ptr
in user space. Now for this case I get the correct data e.g.0X55
in kernel bufferdest_ptr
, but the user space buffer of destination always return0x77
. i.e the data which I have written intousr_src_ptr
.
Can any one please let me know if we can do two mmap()
operations on same file at different OFFSET?
Instead of:
if ((ret = remap_pfn_range(vma,vma->vm_start,
(virt_to_phys((void *)src_ptr) >> PAGE_SHIFT),
size,vma->vm_page_prot)) < 0) return ret;
The correct one is:
if ((ret = remap_pfn_range(vma,vma->vm_start,
vma->vm_pgoff,
size,vma->vm_page_prot)) < 0)
Thanks BЈовић for your input ....