Re: ioremap(), bus_to_virt() and PCI devices on different Linux archi

Pete Zaitcev (zaitcev@metabyte.com)
Thu, 28 Oct 1999 12:38:15 -0700 (PDT)


> I don't know the correct and universal way on all linux architecture to map
> PCI memory. Some drivers
> in the kernel use ioremap, other use bus_to_virt() ...

I smell a poor wording or understanding here.
Typically "PCI memory" means a memory located in a PCI board.
Memory located on the other side of a north bridge is a
"normal" or "CPU" memory.

ioremap() makes PCI memory visible to CPU.

bus_to_virt() reverses a bus address, obtained by some other
way, of a normal memory. It is not applicable to PCI memory.
Yet people continue to do this because it works for some architectures...
For example Russell King's cyber2000fb.c contains this code:

int __init cyber2000fb_init(void)
{

CyberRegs = bus_to_virt(dev->base_address[0]) + 0x00800000;/*FIXME*/
}

This is wrong. ioremap() must be used instead (and the
driver must be updated to use dev->resource[0].start).
Perhaps ioremap() does not work properly on arm.

The freehand sprinkling of bus_to_virt and such around drivers
is promoted by 64-bits architectures. With vast address spaces
they just map whole PCIs attached to a system somewhere into
the CPU physical space, or even into the kernel virtual space.
I fixed an abuse of this in drivers/net/sunhme.c a couple of
weeks ago.

> I've made some test in linux Intel and PPC. The only way to have a defined
> virtual memory ptr is to use
> ioremap on an Intel box. On Linux PPC ioremap returns 0 sometimes, or
> otherwise returns a pointer
> without doing any PCI memory to physical memory conversion (is this correct

I take it "doing any PCI memory to physical memory conversion"
was a typo. Surely you realize that ioremap() converts into
virtual, not physical, don't you?

I think only Cort can explain why his ioremap() returns 0.
It is a legitimate return code from ioremap(), it means that
mapping cannot be established. For example you may be asking
for too much (like 256MB), system may be running out of mappings,
or it may be a ppc bug. Sparc lived with broken ioremap() since
2.1 times, we will have it fixed in 2.4. Why not ppc :)

--Pete

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