LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-04-2015, 06:06 AM   #1
viterbi
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Rep: Reputation: Disabled
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
 
Old 11-04-2015, 10:17 AM   #2
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Rep: Reputation: 164Reputation: 164
I dont think you want to develop a "app".
You need to develop a driver for your board.
 
Old 11-04-2015, 10:33 AM   #3
viterbi
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
when I said app I meant a PC application, obviously not a smartphone so called "app".

The thing is that I want to develop both, the driver and the application, and I am not sure how my application should access memory, if it should do so through the driver, I am not sure how that is done.
 
Old 11-04-2015, 04:08 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,128

Rep: Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639
Most of these boards have some factory support I'd think. Be sure to see what they have on this. It may already be written.
 
Old 11-05-2015, 02:01 AM   #5
viterbi
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for the replies,

I am afraid I still don't know if my driver should export some functions which read/write memory by deferencing pointers directly or what...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Kernel fails to assign memory to PCIe device dbrazeau Linux - Kernel 5 03-27-2018 11:32 AM
PCIe read/write are not working as desired. Abdul Basit Linux - Kernel 0 04-22-2015 04:44 PM
Regarding accessing memory mapping of the pcie device tamilvanan Programming 6 03-21-2013 09:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration