How to implement mmap for bar0

401 views Asked by At

I'm trying to write my own Linux PCIe driver. I would like to write my mmap function so that it maps bar0, I realize I can do this without writing a driver but I'm doing this mostly for learning purposes.

My first question is why would you need to implement mmap if you can mmap bar0 without any driver development?

My second question is why is my mmap not working?

Here is my mmap code and the userspace app I use to access it

static int dma_proxy_mmap(struct file *filp, struct vm_area_struct *vma)
{

if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,vma->vm_end - vma->vm_start,vma->vm_page_prot))
{
return -EAGAIN;
}
printk(KERN_ALERT "mmap done\n");
return 0;
}

and here is my user space code

int main()
{

 int proxy_fd;
 int *MyMmap;
 proxy_fd = open("/dev/scull", O_RDWR);
 MyMmap = (int*)mmap(0,32, PROT_READ | PROT_WRITE, MAP_SHARED, proxy_fd, 0);
if (MyMmap == MAP_FAILED) {
printf("mmap failed");
}
  MyMmap[0] = 10;
  printf ("Decimals: %d\n", MyMmap[0]);

}

I know it's not working correctly because my pcie card is designed to write a different value regardless of what I send to it to write which I've verified is working by mmaping to resource0 of that board.

0

There are 0 answers