2004-10-06 22:06:40

by Alan Kilian

[permalink] [raw]
Subject: Driver access ito PCI card memory space question.



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

--
- Alan Kilian <kilian(at)timelogic.com>
Director of Bioinformatics, TimeLogic Corporation 763-449-7622


2004-10-06 22:58:06

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Driver access ito PCI card memory space question.

On Wed, 6 Oct 2004, Alan Kilian wrote:

>
>
> 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.
>

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.

2004-10-06 22:50:13

by Roland Dreier

[permalink] [raw]
Subject: Re: Driver access ito PCI card memory space question.

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

2004-10-08 17:00:15

by Erik Mouw

[permalink] [raw]
Subject: Re: Driver access ito PCI card memory space question.

On Wed, Oct 06, 2004 at 03:43:13PM -0700, Roland Dreier wrote:
> 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

--
+-- Erik Mouw -- http://www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands

2004-10-14 20:55:57

by Alan Kilian

[permalink] [raw]
Subject: Re: Driver access ito PCI card memory space question.



I want to thank everyone for helping me get my Solaris driver
running under Linux.

It's taken three days, but it appears to be working, it passes all
my hardware diagnostics and I'm ready to hook it up to the
application layer. I think going from knowing NOTHING about the
Linux kernel to a working PCI bus driver in three days is not too
shabby.

The Rubini and Corbet book helped a LOT, but it helped more after
I knew what I was doing a bit.

I suspect I'll be back when I start implementing the DMA part.

Hey! what RPM do I install so I can get man pages for kernel
functions? A man page for readl() sure would have been useful.

Thanks a million folks!!!

-Alan

--
- Alan Kilian <kilian(at)timelogic.com>
Director of Bioinformatics, TimeLogic Corporation 763-449-7622

2004-10-14 21:22:48

by Jesper Juhl

[permalink] [raw]
Subject: Re: Driver access ito PCI card memory space question.

On Thu, 14 Oct 2004 [email protected] wrote:

>
> Hey! what RPM do I install so I can get man pages for kernel
> functions? A man page for readl() sure would have been useful.
>
I don't know about any RPM for that (using a non-rpm based distribution),
but what I do personally is use "make mandocs" and "make installmandocs".

If you run "make help" in the kernel source tree you'll see this bit:

[...]
Documentation targets:
Linux kernel internal documentation in different formats:
sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF)
htmldocs (HTML), mandocs (man pages, use installmandocs to install)
[...]

As you see you can get docs in various forms.

Hope that helps.

--
Jesper Juhl