Re: Memory mapping PCI memory region to user space
From: Phil Nitschke <hidden>
Date: 2006-03-29 02:26:22
On Mon, 2006-03-27 at 10:18 -0600, Kumar Gala wrote:
On Mar 27, 2006, at 2:02 AM, Phil Nitschke wrote:quoted
On Thu, 2006-03-23 at 09:44 -0600, Kumar Gala wrote:quoted
On Mar 23, 2006, at 8:21 AM, Wyse, Chris wrote:quoted
Hi, I'm trying to map a PCI memory region 1 into user space from my driver (PPC440GX, Linux 2.6.10). Here's the mmap routine of the driver that I'm using:Why don't use the mmap file exposed by sysfs so you dont have to write your own code? See Documentation/filesystems/sysfs-pci.txt. But effectively down under /sys/bus/pci/devices/[domain:bus:dev:func]/ you will get resource[0..N-1] that corresponds to each BAR on the device. This is a mmap file to access that region.I have some custom hardware that appears on the PCI bus as follows: bash-3.00# lspci -vv 00:01.0 Class 0680: 1172:0004 (rev 01) Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- Status: Cap- 66Mhz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort+ <TAbort- <MAbort- >SERR- <PERR- Latency: 128, Cache Line Size 08 Interrupt: pin A routed to IRQ 71 Region 0: Memory at 000000009ffff000 (32-bit, non-prefetchable) [size=4K] Region 1: Memory at 000000009fc00000 (32-bit, non-prefetchable) [size=2M] But when I try to access resource0 or resource1, I get a read error. What characteristic of the device or driver determines whether it will allow mmap-ing? (I've written the driver for this device myself.)Nothing special beyond normal unix perms on the resource[0..n] files to my knowledge. When you say you get a read error what exactly does that mean?
It means I had a bug in my program which read (mmap()ed) the resouce :-( It is fixed now (see below). Thanks for the tip. -- Phil Nitschke [off-list ref] Avalon Systems Pty Ltd