blob: d20703739fad24824c6299c4f8c505b565e56ac5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stelian Popfa506a92008-01-31 21:15:53 +00002/*
3 * (C) Copyright 2007
Stelian Popc9e798d2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Stelian Popfa506a92008-01-31 21:15:53 +00005 * Lead Tech Design <www.leadtechdesign.com>
Stelian Popfa506a92008-01-31 21:15:53 +00006 */
7#ifndef __ASM_ARM_DMA_MAPPING_H
8#define __ASM_ARM_DMA_MAPPING_H
9
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053010#include <common.h>
11#include <asm/cache.h>
12#include <cpu_func.h>
Masahiro Yamadab27af392017-08-26 00:50:17 +090013#include <linux/dma-direction.h>
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053014#include <malloc.h>
Kishon Vijay Abraham I2f066932015-02-23 18:39:56 +053015
Masahiro Yamadab27af392017-08-26 00:50:17 +090016#define dma_mapping_error(x, y) 0
Stelian Popfa506a92008-01-31 21:15:53 +000017
Kishon Vijay Abraham Iaecbf872015-02-23 18:39:49 +053018static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
Stelian Popfa506a92008-01-31 21:15:53 +000019{
Ye Li9d47d132019-01-04 09:24:14 +000020 *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, ROUND(len, ARCH_DMA_MINALIGN));
Stelian Popfa506a92008-01-31 21:15:53 +000021 return (void *)*handle;
22}
23
Kishon Vijay Abraham I2f066932015-02-23 18:39:56 +053024static inline void dma_free_coherent(void *addr)
25{
26 free(addr);
27}
28
Stelian Popfa506a92008-01-31 21:15:53 +000029static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
30 enum dma_data_direction dir)
31{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053032 unsigned long addr = (unsigned long)vaddr;
33
34 len = ALIGN(len, ARCH_DMA_MINALIGN);
35
36 if (dir == DMA_FROM_DEVICE)
37 invalidate_dcache_range(addr, addr + len);
38 else
39 flush_dcache_range(addr, addr + len);
40
41 return addr;
Stelian Popfa506a92008-01-31 21:15:53 +000042}
43
44static inline void dma_unmap_single(volatile void *vaddr, size_t len,
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053045 enum dma_data_direction dir)
Stelian Popfa506a92008-01-31 21:15:53 +000046{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053047 unsigned long addr = (unsigned long)vaddr;
48
49 len = ALIGN(len, ARCH_DMA_MINALIGN);
50
51 if (dir != DMA_TO_DEVICE)
52 invalidate_dcache_range(addr, addr + len);
Stelian Popfa506a92008-01-31 21:15:53 +000053}
54
55#endif /* __ASM_ARM_DMA_MAPPING_H */