blob: eac56f8fbdfaa3e884675f071cad4009d54039af [file] [log] [blame]
Anup Patel70b85622019-02-25 08:14:17 +00001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2018 Western Digital Corporation or its affiliates.
4 *
5 * Authors:
6 * Anup Patel <anup.patel@wdc.com>
7 */
8
9#ifndef __ASM_RISCV_DMA_MAPPING_H
10#define __ASM_RISCV_DMA_MAPPING_H
11
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053012#include <common.h>
Masahiro Yamadac22c0db2020-02-14 16:40:17 +090013#include <linux/types.h>
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053014#include <asm/cache.h>
15#include <cpu_func.h>
Anup Patel70b85622019-02-25 08:14:17 +000016#include <linux/dma-direction.h>
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053017#include <malloc.h>
Anup Patel70b85622019-02-25 08:14:17 +000018
19#define dma_mapping_error(x, y) 0
20
21static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
22{
23 *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
24 return (void *)*handle;
25}
26
27static inline void dma_free_coherent(void *addr)
28{
29 free(addr);
30}
31
Masahiro Yamadac22c0db2020-02-14 16:40:17 +090032static inline dma_addr_t dma_map_single(void *vaddr, size_t len,
33 enum dma_data_direction dir)
Anup Patel70b85622019-02-25 08:14:17 +000034{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053035 unsigned long addr = (unsigned long)vaddr;
36
37 len = ALIGN(len, ARCH_DMA_MINALIGN);
38
39 if (dir == DMA_FROM_DEVICE)
40 invalidate_dcache_range(addr, addr + len);
41 else
42 flush_dcache_range(addr, addr + len);
43
44 return addr;
Anup Patel70b85622019-02-25 08:14:17 +000045}
46
47static inline void dma_unmap_single(volatile void *vaddr, size_t len,
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053048 enum dma_data_direction dir)
Anup Patel70b85622019-02-25 08:14:17 +000049{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053050 unsigned long addr = (unsigned long)vaddr;
51
52 len = ALIGN(len, ARCH_DMA_MINALIGN);
53
54 if (dir != DMA_TO_DEVICE)
55 invalidate_dcache_range(addr, addr + len);
Anup Patel70b85622019-02-25 08:14:17 +000056}
57
58#endif /* __ASM_RISCV_DMA_MAPPING_H */