Read/Write memory from PCIe Device
Hello,
first of all let me say I am new to the forum and I am not pretty sure if this is the right sections for this question, but I couldn't find a more suitable one.
This may sound a little dumb but here it goes.
I have an FPGA development board with PCIe Gen2 x4 and I am trying to develop both a linux driver and FPGA design to be able to read/write memory located in the board from the PC.
After many tries I think I have it. I have made a simple FPGA design with two PCIe BARs and a driver which detects the device and claims the memory regions and enables de device. As comfirmation of that I can see the mapping in /prop/iomem is correct and also the output of lspci -vvv -d:XXXX says "Driver in use: mydriver".
However, now that I have done all this I am stuck at what I suspect is probably the easier part. How do I actually read/write that memory I have just claimed???
I only know a little bit about drivers and I remember a char driver was accessed with file operations and ioctl such as read/write/lseek etc. However I don't think PCI devices are accessed that way right? I mean they are directly mapped to memory...
Anyway I would like to make an app which I can call with some arguments and have it access those memory regions. Until now I have been using devmem2 but it offers very little flexibility and I really want to make my own because I really want to learn how this is done.
Thanks a lot!
EDIT: i have been investigating and I understand mmap() system call can access that space from userland. However I am not sure if this is the way to go... I would like to do this the "proper" way. By that I mean I wan't to make it optimal, robust and coherent. Should my driver module export functions which read/write to pci? should my user apps then import those functions to perform operations?
Last edited by viterbi; 11-04-2015 at 09:03 AM.
Reason: more info
|