Skip to contentSkip to conversation

Driver access ito PCI card memory space question.

DISCUSSION Alan Kilian 4 participants 4 messages Oct 6, 2004 – Oct 8, 2004

lore
Share & tools
lore
#0 lore raw

Folks,

I'm not sure how to access the memory spaces on my PCI card.

I do

From /var/log/messages:

SSE: Start of card attachment.
SSE: Found a DeCypher card, interrupting on line 3
SSE: Bar0 From 0xfeaff000 to 0xfeafffff F=0x200 MEMORY space
SSE: Bar1 From 0xfeafc000 to 0xfeafdfff F=0x200 MEMORY space
SSE: Bar2 From 0xfe000000 to 0xfe7fffff F=0x200 MEMORY space

My driver detects the card, and asks about the memory areas.

Then I do request_mem_area(0xfeaff000,4095, "SSE");

Then I do a readl(0xfeaff100); and get this:

Unable to handle kernel paging request at virtual address feaff100

Any hints? Maybe these are byte-addresses, and I need to do:
readl(0xfeaff100>>2);

I'm just beginning this adventure, so please excuse the basic questions.

-Alan

Signature · 2 lines
- Alan Kilian <kilian(at)timelogic.com> 
Director of Bioinformatics, TimeLogic Corporation 763-449-7622
#1 lore raw
    Alan>      Then I do request_mem_area(0xfeaff000,4095, "SSE");

    Alan>      Then I do a readl(0xfeaff100); and get this:

    Alan>         Unable to handle kernel paging request at virtual address feaff100

You can't blindly access an address from your device's BARs; on many architectures PCI access needs setting up and/or addresses need munging before use. The API you need is ioremap().

You need to do something like:

	void __iomem *mybase = ioremap(pci_resource_start(my_pdev, 0), 4095);
	u32 value = readl(mybase + 0x100);

(Delete the __iomem annotation for kernels before 2.6.9).

The "Linux Device Drivers" online book, available at
<http://www.xml.com/ldd/chapter/book/> will probably be pretty helpful. In fact if you're serious about writing drivers, you should buy a dead-tree copy.

- Roland

#2 lore raw
Quoted 4 lines · Roland Dreier

The "Linux Device Drivers" online book, available at
<http://www.xml.com/ldd/chapter/book/> will probably be pretty helpful. In fact if you're serious about writing drivers, you should buy a dead-tree copy.

Note that LDD is focused on 2.4, but LWN has a nice series of articles that describes how to port 2.4 drivers to 2.6:

http://lwn.net/Articles/driver-porting/

LDD should give you the basics, the articles on lwn.net should tell you what's different.

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#3 lore raw
In reply to Alan Kilian
Quoted 10 lines · Alan Kilian

Folks,

I'm not sure how to access the memory spaces on my PCI card.

I do

From /var/log/messages:

Quoted 8 lines

SSE: Start of card attachment.
SSE: Found a DeCypher card, interrupting on line 3
SSE: Bar0 From 0xfeaff000 to 0xfeafffff F=0x200 MEMORY space
SSE: Bar1 From 0xfeafc000 to 0xfeafdfff F=0x200 MEMORY space
SSE: Bar2 From 0xfe000000 to 0xfe7fffff F=0x200 MEMORY space

My driver detects the card, and asks about the memory areas.

Please look at a driver module that uses PCI. There are plenty in the kernel.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.5-1.358-noreg on an i686 machine (5537.79 BogoMips).
Note 96.31% of all statistics are fiction.