Re: DMA memory mapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Usman S. Ansari wrote:

>I have a driver (this is continuation of preserving memory accross reboot) whic has some memory
>allocated and my application wants to write to it. Therefore in the application I (after open
>call) do
>
> if ((ptr = (char *) mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == NULL)
>    {
>     perror("error ...");
>    }
>
>Now I have access to memory starting at virtual location ptr for next 4096 bytes. In my driver
>static int ocr_mmap(struct file *file, struct vm_area_struct *vma)
>{
> unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
> int minor = MINOR(file->f_dentry->d_inode->i_rdev);
>
> vma->vm_flags |= VM_RESERVED;
>
> if (offset >= __pa(high_memory) || (file->f_flags & O_SYNC))
>    vma->vm_flags |= VM_IO;                    /* since this driver maps different kind of segs */
>
>if (remap_page_range(vma->vm_start, __pa(dT[minor].addr), vma->vm_end - vma->vm_start,
>                     vma->vm_page_prot) < 0)
>     return -EAGAIN;
> 
> return(0);
>}
>
>Following 3 are filled by kernel
>vma->vm_start
>vma->vm_end
>vma->vm_start
>
>__pa(dT[minor].addr) ---> I have a kernel virtual address and __pa() gives me physical address.
>
>I hope this is helpfull.
>
Indeed it has been, thanks...I am to this point.  I have vmalloced 
memory in the kernel, called mmap using the virt_to_phys call on the 
address returned by vmalloc and get a zero return value from 
remap_page_range.  At that point, I would assume that I should be able 
to access the memory using the address that was returned from the mmap 
call.  Using gdb, I am told that it cannot access the memory at the 
address that was returned. (x /256xb address is the dgb command that I 
am using).  I have used the PROT_READ|PROT_WRITE as well as the 
MAP_SHARED.  What am I missing?

TIA

-- 
Best regards,
David Stroupe
Keyed-Up Software
5307 Faireast Court
Arlington, Texas 76018-1683
817/557-4903 voice
817/472-0408 fax



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux