0

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.

mx0
  • 6,445
  • 12
  • 49
  • 54
Matthew
  • 21
  • 3
  • No mmap succeeds but the values I read from MyMmap are not what was written to it by my fpga pcie card – Matthew Sep 15 '17 at 03:47
  • You perhaps need to call `memremap()` instead of your approach. To say more you may provide an output of `lspci -n -vv -s ` – 0andriy Sep 22 '17 at 18:46

0 Answers0