Skip to contentSkip to conversation

mmap pci

newb Neal Becker 2 participants 3 messages Apr 16, 2008 – Apr 17, 2008

lore
Share & tools
lore
#0 lore raw

We have a device - an FPGA board on PCI bus. It has a range of internal memory mapped to PCI. I want to expose this to user via mmap. Is there some example code someone could point me to?

If this is not the best forum for such questions, what would be a better choice?

#1 lore raw
Quoted 6 lines · On Wed, 16 Apr 2008 07:23:29 -0400 Neal Becker <[email protected]> wrote:

We have a device - an FPGA board on PCI bus. It has a range of internal memory mapped to PCI. I want to expose this to user via mmap. Is there some example code someone could point me to?

If this is not the best forum for such questions, what would be a better choice?

Hi,

if it's just a PCI bar, you can already memory map it without even writing a driver! You can just use the sysfs files for this, for example /sys/devices/pci0000:00/0000:00:02.0/resource1

There's also a way to do this via the /proc representation of the PCI device..

Greetings,
Arjan van de Ven

Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#2 lore raw
Quoted 16 lines · Arjan van de Ven
Quoted 6 lines · On Wed, 16 Apr 2008 07:23:29 -0400 Neal Becker <[email protected]> wrote:

We have a device - an FPGA board on PCI bus. It has a range of internal memory mapped to PCI. I want to expose this to user via mmap. Is there some example code someone could point me to?

If this is not the best forum for such questions, what would be a better choice?

Hi,

if it's just a PCI bar, you can already memory map it without even writing a driver! You can just use the sysfs files for this, for example /sys/devices/pci0000:00/0000:00:02.0/resource1

Quoted 7 lines

There's also a way to do this via the /proc representation of the PCI device..

Greetings,
Arjan van de Ven

Thanks! Only problem: seems the mapping is read-only? This python test code works if prot=mmap.PROT_READ, but I get permission denied if PROT_READ|PROT_WRITE.

import mmap
import struct

f = open ('/sys/bus/pci/devices/0000:05:0f.0/resource0','rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ)