blob: 65f67bc1f442041dba9d747600b7857ab06a59dc [file] [log] [blame]
Thomas Chou7e812f22010-04-17 23:34:40 +08001#ifndef __ASM_NIOS2_DMA_MAPPING_H
2#define __ASM_NIOS2_DMA_MAPPING_H
3
Thomas Chou7cacb642015-10-18 20:03:53 +08004#include <memalign.h>
5#include <asm/io.h>
Thomas Chou7e812f22010-04-17 23:34:40 +08006
Thomas Chou7cacb642015-10-18 20:03:53 +08007/*
8 * dma_alloc_coherent() return cache-line aligned allocation which is mapped
9 * to uncached io region.
10 */
Thomas Chou7e812f22010-04-17 23:34:40 +080011static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
12{
Thomas Chou7cacb642015-10-18 20:03:53 +080013 unsigned long addr = (unsigned long)malloc_cache_aligned(len);
Thomas Chou7e812f22010-04-17 23:34:40 +080014
Thomas Chou7cacb642015-10-18 20:03:53 +080015 if (!addr)
16 return NULL;
17
18 invalidate_dcache_range(addr, addr + len);
19 if (handle)
20 *handle = addr;
21
Thomas Chou7be35dd2015-11-14 11:34:09 +080022 return map_physmem(addr, len, MAP_NOCACHE);
Thomas Chou7cacb642015-10-18 20:03:53 +080023}
Thomas Chou7e812f22010-04-17 23:34:40 +080024#endif /* __ASM_NIOS2_DMA_MAPPING_H */