lx_emul: provide alignment for DMA allocations

Ref #4268
This commit is contained in:
Stefan Kalkowski 2021-09-27 11:39:12 +02:00 committed by Norman Feske
parent 4c4ce2f899
commit 9bc7ecb605
3 changed files with 12 additions and 1 deletions

View File

@ -21,6 +21,7 @@ extern "C" {
void * lx_emul_mem_alloc(unsigned long size);
void * lx_emul_mem_alloc_uncached(unsigned long size);
void * lx_emul_mem_alloc_aligned(unsigned long size, unsigned long align);
void * lx_emul_mem_alloc_aligned_uncached(unsigned long size, unsigned long align);
unsigned long lx_emul_mem_dma_addr(void * addr);
void lx_emul_mem_free(const void * ptr);
unsigned long lx_emul_mem_size(const void * ptr);

View File

@ -43,6 +43,16 @@ extern "C" void * lx_emul_mem_alloc_uncached(unsigned long size)
};
extern "C" void * lx_emul_mem_alloc_aligned_uncached(unsigned long size,
unsigned long align)
{
/* always align memory objects to 32 bytes, like malloc, heap etc. */
void * const ptr = Lx_kit::env().uncached_memory.alloc(size, align);
lx_emul_forget_pages(ptr, size);
return ptr;
};
extern "C" unsigned long lx_emul_mem_dma_addr(void * addr)
{
unsigned long ret = Lx_kit::env().memory.dma_addr(addr);

View File

@ -29,7 +29,7 @@ void * dma_alloc_attrs(struct device * dev,
lx_emul_trace_and_stop(__func__);
}
addr = lx_emul_mem_alloc_uncached(size);
addr = lx_emul_mem_alloc_aligned_uncached(size, PAGE_SIZE);
*dma_handle = lx_emul_mem_dma_addr(addr);
return addr;
}