Re: virt_to_bus and >1G of memory (was MAX_DMA_ADDRESS ...)

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Fri, 13 Nov 1998 18:44:09 +0000


On Fri, Nov 13, 1998 at 10:02:52AM -0800, Linus Torvalds wrote:
> On Fri, 13 Nov 1998, Jamie Lokier wrote:
> > One thing I've seen in some drivers is that virt_to_bus doesn't work on
> > a user-space address, _or_ an address in a module.
>
> It will never work. It's not supposed to. Anybody trying to do that is
> buggy.
>
> The "virt_to_phys()" and "virt_to_bus()" things are _only_ supposed to
> work on normal kernel mappings, the kind of mappings you get from
> "get_free_pages()" etc. Assuming anything else is just stupid, because it
> assumes a level of complexity that I never want to see.

You're right. The module address thing was only theoretical and I've
never seen it.

The user-space thing is actually cropping up in a few experimental
drivers. Perhaps the most visible (pun intended) being bttv.c. And as
Jeff Millar's project is finding (bttv frame capture into video card via
mmapped video card memory), it doesn't always work.

virt_to_bus() is done in a few places that seem quite sensible, until
you realise the address they're passing is from ioremap(). Linus, you
and I know that's wrong but it's not obvious to the people who actually
write device drivers.

A documentation glitch is that x86 ioremap()'s argument claims to be a
physical address, when it's supposed to be a bus address. But that
explains why it works, because if it did
virt_to_phys(bus_to_virt(busaddr)) on the passed address ready to fill
the page tables, the address would get clobbered.

Fortunately, I have about finished a generic user-space DMA device
driver (which can also be called from other drivers). This supports DMA
to/from user-space, that can be used for drivers running in user-space
or by other kernel drivers that want to do user-space DMA. It can
provide kmalloc()ed memory with whatever granularity is required and use
that, and also supports DMA to existing mlock()ed mappings. Including
mappings of other devices (x86 at least, who knows about the others).

So at least all the necessary translation hacks can be gathered in one
place.

-- Jamie

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