[lkml]   [2017]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Proper way to allocate DMA buffer within a single 4GB block?
On Wed, 20 Sep 2017 17:18:09 -0500
Timur Tabi <> wrote:

> I have a device that requires I allocated a few buffers for DMA. The
> problem is that this device has only one register for the upper 32
> bits of all of the buffers. That is, all of buffers must reside
> within the same 4GB block of memory. In order words,
> end = start + size - 1;
> if (upper_32_bits(start) != upper_32_bits(end))
> // Oh no, the buffer spans across a 4GB boundary!
> The buffer is typically less than 16KB in size, so we've never seen
> it actually span across a 4GB boundary. However, I want to ensure
> that it's impossible. I wrote this function that re-tries the
> allocation if the first one is invalid, but I suspect that it's too
> hackish. Is there a better way?

Allocate a buffer twice as big as what you really need. If the first
half doesn't work, the second half will.

 \ /
  Last update: 2017-09-24 16:21    [W:0.302 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site