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!
source
share