Is the buffer within kmalloc also a safe DMA buffer?

I am in the middle of writing a framebuffer driver for an LCD connected to SPI. I use kmalloc to allocate a buffer that is quite large - 150 KB. Given that kmalloc allocates a buffer, ksize reports that more memory is being used - 256 KB or so.

The SPI spi_transfer structure accepts pointers to tx and rx buffers, both of which must be safe DMA. Since I want the tx buffer to be around 16 KB, can I allocate this buffer in the kilometer video buffer and still be DMA safe?

This can be considered a premature optimization, but there is so much free space in the video buffer that it’s bad for him not to use it! Essentially, there is no difference in distributed memory between:

kmalloc(videosize)

and

kmalloc(PAGE_ALIGN(videosize) + txbufsize)

to return kptr and do:

txbuf = (u8 *)kptr + PAGE_ALIGN(videosize);

I know that part of the “DMA safe” requirement corresponds to the correct alignment - the size of the processor cache, which I think ... - but should the page alignment be ok for that?

As an aside, I'm not sure if tx and rx can point to the same place. The spi.h header is also obscure (clearly obscure). Given that the rx buffer will never be more than a few bytes, it would be foolish to create problems trying to figure it out!

+4
source share
1 answer

The answer is yes with reservations. (In particular, that "it's harder than that")

__get_free_page *() (kmalloc), DMA / , , . , kmalloc, , DMA, , .

, (, ISA). , dma_mask .

. . , dma . , , ( DMA API) , ( , ).

DMA dma_alloc_coherent() DMA , , DMA . , - - . dma_map_single() .

tx rx- spi_sync dma_map_single - spi . dma_map_single unmap dma_sync_single_for_cpu(), . , - - .

. :

+2

All Articles