Groups | Search | Server Info | Login | Register
Groups > comp.os.linux.development.system > #206
| From | Pavel Borzenkov <pavel@devio.us> |
|---|---|
| Newsgroups | comp.os.linux.development.system |
| Subject | Re: mmap dma buffer |
| Date | 2011-07-07 09:59 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <slrnj1b0sk.6ff.pavel@wolfman.devio.us> (permalink) |
| References | <b1c8cc05-4b93-4b07-a041-c8a597965aa7@b39g2000prd.googlegroups.com> |
Hello,
On 2011-07-06, new <luvraghu@gmail.com> wrote:
> Hello Experts,
>
> From the application using ioctl i get the size of the write dma
> buffer and then i do the mmap() operation. can you pls review the code
> below:
>
> *************************************************
> /* driver mmap routine*/
> static int pcie_mmap(struct file *filp, struct vm_area_struct *vma)
> {
> unsigned long pfn;
> unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
> unsigned long len = vma->vm_end - vma->vm_start;
>
> printk(KERN_ALERT "\nRAGHU: pcie-axi: Inside pcie_MMAP");
>
> if (offset >= PAGE_SIZE)
> return -EINVAL;
>
> if (len > (PAGE_SIZE - offset))
> return -EINVAL;
>
> vma->vm_flags |= VM_RESERVED;
> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>
> printk(KERN_ALERT "\nRAGHU: pcie-axi: %s: mapping %ld bytes of mem at
> offset %ld\n",
> __stringify(KBUILD_BASENAME), len, offset);
>
> /* need to get the pfn for remap_pfn_range --
> ds->wr_buf_ptr is the virtual pointer returned from
> pci_alloc_consistent*/
>
> pfn = virt_to_phys(ds->wr_buf_ptr + offset) >> PAGE_SHIFT;
You can't convert address returned by pci_alloc_consistent() using
virt_to_phys() macro. This macro correctly works only for the kernel virtual
addresses. And this is not needed, actually, because pci_alloc_consistent()
function returns physical address of the allocated memory in its third
argument.
--
Pavel
Back to comp.os.linux.development.system | Previous | Next — Previous in thread | Next in thread | Find similar
mmap dma buffer new <luvraghu@gmail.com> - 2011-07-06 08:12 -0700
Re: mmap dma buffer Pavel Borzenkov <pavel@devio.us> - 2011-07-07 09:59 +0000
Re: mmap dma buffer Pavel Borzenkov <pavel@devio.us> - 2011-07-07 10:02 +0000
Re: mmap dma buffer new <luvraghu@gmail.com> - 2011-07-07 05:42 -0700
Re: mmap dma buffer Pavel Borzenkov <pavel@devio.us> - 2011-07-07 13:27 +0000
Re: mmap dma buffer new <luvraghu@gmail.com> - 2011-07-07 07:46 -0700
Re: mmap dma buffer Pavel Borzenkov <pavel@devio.us> - 2011-07-08 07:01 +0000
Re: mmap dma buffer new <luvraghu@gmail.com> - 2011-07-08 03:31 -0700
csiph-web