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

Roland Dreier
2002-06-10T19:03:27Z

>>>>> "Tom" == Tom Rini <trini@kernel.crashing.org> 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
<linux/usb.h>):

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

#ifdef CONFIG_NOT_CACHE_COHERENT

#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)))

#else /* CONFIG_NOT_CACHE_COHERENT */

#define __dma_buffer

#endif /* CONFIG_NOT_CACHE_COHERENT */

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.

Comments?

Thanks,
Roland