Groups | Search | Server Info | Login | Register


Groups > comp.os.linux.development.system > #203

mmap dma buffer

From new <luvraghu@gmail.com>
Newsgroups comp.os.linux.development.system
Subject mmap dma buffer
Date 2011-07-06 08:12 -0700
Organization http://groups.google.com
Message-ID <b1c8cc05-4b93-4b07-a041-c8a597965aa7@b39g2000prd.googlegroups.com> (permalink)

Show all headers | View raw


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;

if (remap_pfn_range(vma, vma->vm_start, pfn, len, vma->vm_page_prot))
{
return -EAGAIN;
}

printk(KERN_ALERT "\nRAGHU: pcie-axi: Exit pcie_MMAP");
return 0;
}

/* application routine */

int DmaWrite()
{

unsigned char *mmap_buf;

/*deviceHandle is the fd got from open */

if(ioctl(deviceHandle, PCIE_AXI_REGDMA_WR, &regdma))
return -pio.status;

/* got the size using ioctl */

mmap_buf = mmap(NULL, regdma.dmabuffsize, PROT_READ | PROT_WRITE,
MAP_SHARED, deviceHandle, 0);

if (mmap_buf == (unsigned char *)MAP_FAILED) {
printf("MMAP FAILED\n");
return 0;
}
/* call the write function*/
write(deviceHandle,mmap_buf,regdma.dmabuffsize);

return 0;
}
*************************************************
In driver write routine I setup the descriptor chain and initiate the
DMA.

Questions:
``````````
1) Is my code correct? Am I missing anything?
2) In the mmap() for write operation what should be the flag?
PROT_WRITE or PROT_WRITE|PROT_READ.
3) Do I need to follow the same thing for the read part also? i.e get
the size and mmap and pass the read buffer pointer(got from
pci_alloc_consistent) as pfn arg to remap_pfn_range().

Please ignore the any sanity checks as of now.

Appreciate your help.

Thanks a ton.

Back to comp.os.linux.development.system | Previous | NextNext in thread | Find similar


Thread

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