blob: 65f67bc1f442041dba9d747600b7857ab06a59dc [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
Thomas Chou71d90312015-11-14 11:34:09 +080022 return map_physmem(addr, len, MAP_NOCACHE);
Thomas Chou8e1e96d2015-10-18 20:03:53 +080023}
Thomas Chou015e0072010-04-17 23:34:40 +080024#endif /* __ASM_NIOS2_DMA_MAPPING_H */