blob: 1562d35f0dc424376f025ee78e9344248a8407df [file] [log] [blame]
Thomas Chou015e0072010-04-17 23:34:40 +08001#ifndef __ASM_NIOS2_DMA_MAPPING_H
2#define __ASM_NIOS2_DMA_MAPPING_H
3
Thomas Chou8e1e96d2015-10-18 20:03:53 +08004#include <memalign.h>
5#include <asm/io.h>
6
7/*
8 * dma_alloc_coherent() return cache-line aligned allocation which is mapped
Thomas Chou015e0072010-04-17 23:34:40 +08009 * to uncached io region.
Thomas Chou015e0072010-04-17 23:34:40 +080010 */
Thomas Chou015e0072010-04-17 23:34:40 +080011static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
12{
Thomas Chou8e1e96d2015-10-18 20:03:53 +080013 unsigned long addr = (unsigned long)malloc_cache_aligned(len);
14
Thomas Chou015e0072010-04-17 23:34:40 +080015 if (!addr)
Thomas Chou8e1e96d2015-10-18 20:03:53 +080016 return NULL;
Thomas Chou015e0072010-04-17 23:34:40 +080017
Thomas Chou8e1e96d2015-10-18 20:03:53 +080018 invalidate_dcache_range(addr, addr + len);
19 if (handle)
20 *handle = addr;
21
22 return ioremap(addr, len);
23}
Thomas Chou015e0072010-04-17 23:34:40 +080024#endif /* __ASM_NIOS2_DMA_MAPPING_H */