blob: 6cc39469590a047f121e0b481816f4f4e319d86e [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>
13#include <asm/cache.h>
14#include <cpu_func.h>
Anup Patel70b85622019-02-25 08:14:17 +000015#include <linux/dma-direction.h>
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053016#include <malloc.h>
Anup Patel70b85622019-02-25 08:14:17 +000017
18#define dma_mapping_error(x, y) 0
19
20static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
21{
22 *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
23 return (void *)*handle;
24}
25
26static inline void dma_free_coherent(void *addr)
27{
28 free(addr);
29}
30
31static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
32 enum dma_data_direction dir)
33{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053034 unsigned long addr = (unsigned long)vaddr;
35
36 len = ALIGN(len, ARCH_DMA_MINALIGN);
37
38 if (dir == DMA_FROM_DEVICE)
39 invalidate_dcache_range(addr, addr + len);
40 else
41 flush_dcache_range(addr, addr + len);
42
43 return addr;
Anup Patel70b85622019-02-25 08:14:17 +000044}
45
46static inline void dma_unmap_single(volatile void *vaddr, size_t len,
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053047 enum dma_data_direction dir)
Anup Patel70b85622019-02-25 08:14:17 +000048{
Vignesh Raghavendrac0a5a812020-01-16 14:23:45 +053049 unsigned long addr = (unsigned long)vaddr;
50
51 len = ALIGN(len, ARCH_DMA_MINALIGN);
52
53 if (dir != DMA_TO_DEVICE)
54 invalidate_dcache_range(addr, addr + len);
Anup Patel70b85622019-02-25 08:14:17 +000055}
56
57#endif /* __ASM_RISCV_DMA_MAPPING_H */