Re: can device drivers return non-ram via vm_ops->nopage?

From: Russell King
Date: Sat Mar 20 2004 - 11:17:13 EST


On Sat, Mar 20, 2004 at 04:57:39PM +0100, Andrea Arcangeli wrote:
> > One of my current projects is fixing this crap in ALSA.
>
> Do you agree it should be fixed by returning a PFN from ->nopage?

No. How would you return the PFN from a remapped page? It's far
easier to provide an interface which returns the struct page* for
the underlying pages, thusly:

static struct page *
dma_coherent_to_page(struct device *dev, void *cpu_addr,
dma_addr_t handle, unsigned int offset)

And this is precisely what I would be working on if I weren't writing
this mail. 8)

Take a moment to think about the problem. We've allocated some memory
for coherent DMA via the dma_alloc_coherent() interface. At some point,
we've had to get a struct page* in this allocator. However, the
allocator has had to do some architecture defined operations to provide
coherent memory.

Only the architecture can translate the results from dma_alloc_coherent()
back to a struct page* - which it needs to be able to do if
dma_free_coherent() is going to work.

Therefore, what we need to do to solve the ALSA problem is require all
architectures to provide dma_coherent_to_page() and make ALSA use that.

(A related problem is that some architectures need pgprot_dmacoherent()
to modify the page protections so that the user space mapping is also
DMA-coherent. However, that discussion should be the subject of a
new thread.)

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/