Re: PCI DMA to small buffers on cache-incoherent arch

From: Roland Dreier (
Date: Mon Jun 10 2002 - 14:03:19 EST

>>>>> "Tom" == Tom Rini <> writes:

    Tom> No. We should just make it come out to a nop for arches that
    Tom> don't need it. Otherwise we'll end up with ugly things like:
    Tom> #ifdef CONFIG_NOT_CACHE_COHERENT ... #else ... #endif
    Tom> All over things like USB...

Good point. How about the following: add a file to each arch named
say, <asm/dma_buffer.h>, that defines a macro __dma_buffer. This
macro would be used as follows to mark DMA buffers (example taken from

struct usb_device {
        /* ... stuff deleted ... */

        struct usb_bus *bus; /* Bus we're part of */

        struct usb_device_descriptor descriptor __dma_buffer; /* Descriptor */
        struct usb_config_descriptor *config; /* All of the configs */

        /* ... more stuff deleted ... */

Then cache-coherent architectures like i386 can just do

#define __dma_buffer

while PPC can do


#define __dma_buffer __dma_buffer_line(__LINE__)
#define __dma_buffer_line(line) __dma_buffer_expand_line(line)
#define __dma_buffer_expand_line(line) \
        __attribute__ ((aligned(SMP_CACHE_BYTES))); \
        char __dma_pad_ ## line [0] __attribute__ ((aligned(SMP_CACHE_BYTES)))


#define __dma_buffer


C purists will point out that this is not guaranteed to work since the
compiler can reorder structure members. However I'm sure that there
are many, many other places in the kernel where we are counting on gcc
not to reorder structures.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sat Jun 15 2002 - 22:00:18 EST