Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to access pci memory from driver?

319 views
Skip to first unread message

mch...@gmail.com

unread,
Jun 21, 2006, 12:55:28 PM6/21/06
to
i am working on a powerpc system running linux 2.6.
i have a simple driver that tries to access pci memory.
in the config space, bar0 is initialized to 0x6004_0000
where our pci device sits.

in my driver, i implemented
virt_pci_addr = ioremap(0x60040000, 0x40000);
for (i=0; i< 0x20; i+=4)
printk("offset %d = %#x\n", i, *((volatile int
*)virt_pci_addr));

the code above doesn't map to the correct pci memory space. i know that
i am

not mapping correctly because the values that are printed
out are NOT the reset value of the device registers.

(i have also tried mmap to the user space and that did not work).


below is the dump of /proc/iomem:

60000000-67ffffff : PCI1 host bridge
...
...
...

>From the above output, it seems that i am attempting to map valid pci
memory.

thank you in advance for suggestions.

Message has been deleted

steve_s...@hotmail.com

unread,
Jun 21, 2006, 1:56:03 PM6/21/06
to
mch...@gmail.com wrote:
> i am working on a powerpc system running linux 2.6.
> i have a simple driver that tries to access pci memory.
> in the config space, bar0 is initialized to 0x6004_0000
> where our pci device sits.
>
> in my driver, i implemented
> virt_pci_addr = ioremap(0x60040000, 0x40000);
> for (i=0; i< 0x20; i+=4)
> printk("offset %d = %#x\n", i, *((volatile int
> *)virt_pci_addr));
>
> the code above doesn't map to the correct pci memory space. i know that
> i am
>
> not mapping correctly because the values that are printed
> out are NOT the reset value of the device registers.

It is quite common for bar0 to be the memory/IO space
equivalent of the PCI configuration space registers and
bar1 to be the real device registers. Make sure you are
comparing against the correct ones.

Also, you might want to check that the device is mapped
into memory and not I/O space (least significant bit of
the bar is zero). ioremap() is used to map memory
mapped devices, not I/O space addresses.

Failing that, posting your output of "lspci -v" might help.

Oh, and you might want to consider using
ioremap_nocache() -- unrelated to this problem, but
might save you pain in the future.

Regards,
Steve
------------------------------------------------------------------------
Steve Schefter phone: +1 705 725 9999 x26
The Software Group Limited fax: +1 705 725 9666
642 Welham Road,
Barrie, Ontario CANADA L4N 9A1 Web: www.wanware.com

ma...@yahoo.com

unread,
Jun 21, 2006, 2:32:10 PM6/21/06
to
You can do cat /proc/pci to verify if you map the right address. Also
quite a few devices use the very first portion for PCI configuration
space.
Message has been deleted

mch...@gmail.com

unread,
Jun 21, 2006, 7:03:15 PM6/21/06
to
hi steve,
that's another thing i forgot to mention. lspci doesn't show anything.
so it seems that there's no pci device. but the fact that cat
/proc/iomem shows
0x60000000-0x67ffffff : PCI1 host bridge, does this mean that the my
device which is supposed to be at 0x60040000 is mapped to I/O space??
the lease significant bit of bar0 is indeed 0.

the linux is running on ppc platform. we had to modify the u-boot in
order to load linux on our system. so i am not sure if we have
performed the necessary steps to be able to map our pci device.

for one thing, we are not registering any of our pci devices when uboot
loads
linux. we are going to use our driver to read and write to the pci
device.
can we still map to the device eventhough it is not registered?

thank you in advance.

steve_s...@hotmail.com

unread,
Jun 22, 2006, 12:53:17 PM6/22/06
to
mch...@gmail.com wrote:
> hi steve,
> that's another thing i forgot to mention. lspci doesn't show anything.
> so it seems that there's no pci device. but the fact that cat
> /proc/iomem shows
> 0x60000000-0x67ffffff : PCI1 host bridge, does this mean that the my
> device which is supposed to be at 0x60040000 is mapped to I/O space??
> the lease significant bit of bar0 is indeed 0.
> the linux is running on ppc platform. we had to modify the u-boot in
> order to load linux on our system. so i am not sure if we have
> performed the necessary steps to be able to map our pci device.

Unfortunately, I've done PPC and PCI, but not PCI on PPC.
And on x86, the PCI subsystem worked fine before my
drivers attempted to use it.

However, the fact that you see nothing from lspci is worrysome.
It should contain what the Linux PCI subsystem found, not
what has a driver using it.

How did you find out that it was mapped to 0x60040000?
If lspci shows nothing, then I would have assumed that
pci_get_device() -- the normal way of finding out where
you device is -- would also fail.

I think you'll have to put some debugging in the kernel's
drivers/pci code, especially probe.c

> for one thing, we are not registering any of our pci devices when uboot
> loads
> linux. we are going to use our driver to read and write to the pci
> device.
> can we still map to the device eventhough it is not registered?

There's no registering of you driver for PCI (other than perhaps
requesting an interrupt assignment or a virtual address, which
are not specific to PCI). There is querying of PCI though, to
find out about your PCI devices and the physical addresses
assigned to them.

Robert Hancock

unread,
Jun 22, 2006, 9:21:23 PM6/22/06
to mch...@gmail.com, linux-kernel
mch...@gmail.com wrote:
> hi steve,
> that's another thing i forgot to mention. lspci doesn't show anything.
> so it seems that there's no pci device. but the fact that cat
> /proc/iomem shows
> 0x60000000-0x67ffffff : PCI1 host bridge, does this mean that the my
> device which is supposed to be at 0x60040000 is mapped to I/O space??
> the lease significant bit of bar0 is indeed 0.
>
> the linux is running on ppc platform. we had to modify the u-boot in
> order to load linux on our system. so i am not sure if we have
> performed the necessary steps to be able to map our pci device.
>
> for one thing, we are not registering any of our pci devices when uboot
> loads
> linux. we are going to use our driver to read and write to the pci
> device.
> can we still map to the device eventhough it is not registered?

I don't know PPC, but if your device doesn't even show up in lspci then
you have bigger problems than your driver, either with the device, the
machine hardware or the kernel's PCI detection.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hanc...@nospamshaw.ca
Home Page: http://www.roberthancock.com/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

0 new messages