Skip to content

Commit

Permalink
Prevent use of bounce buffer in targets with 4GB of memory
Browse files Browse the repository at this point in the history
This fixes the following error while mapping the DMA buffer:
panda a0000000.panda_pcap: swiotlb buffer is full (sz: 2097152 bytes),
    total 32768 (slots), used 0 (slots)

Linux has a memory zone for the first 2GB and will allocate from it when
passing the flag GFP_DMA32 to the allocating function.

There is still the question of why linux assumes a bounce buffer is needed
when the buffer is allocated in the highest 2GB.
  • Loading branch information
EmilioPeJu committed Jan 12, 2024
1 parent 54227ee commit a2aeed1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions driver/panda_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ static int create_block(
open->block.block_length < pcap->length - 4,
rc = -EINVAL, bad_request, "Invalid register argument for block");

/* Ok, all in order. Allocate the requested block and map it for DMA. */
open->block_addr = (void *) __get_free_pages(GFP_KERNEL, open->block.order);
/* Ok, all in order. Allocate the requested block and map it for DMA.
* Flag GFP_DMA32 is set to avoid using bounce buffer. */
open->block_addr = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA32, open->block.order);
TEST_OK(open->block_addr, rc = -ENOMEM, bad_request,
"Unable to allocate block");
open->dma = dma_map_single(
Expand Down
3 changes: 2 additions & 1 deletion driver/panda_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ static int allocate_blocks(struct stream_open *open)
for (; blk < block_count; blk ++)
{
block = &open->blocks[blk];
block->block = (void *) __get_free_pages(GFP_KERNEL, block_shift);
/* Flag GFP_DMA32 is set to avoid using bounce buffer */
block->block = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA32, block_shift);
TEST_OK(block->block,
rc = -ENOMEM, no_block, "Unable to allocate buffer");
block->dma =
Expand Down

0 comments on commit a2aeed1

Please sign in to comment.