Anup Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 1 | /* 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 Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 12 | #include <common.h> |
Masahiro Yamada | c22c0db | 2020-02-14 16:40:17 +0900 | [diff] [blame^] | 13 | #include <linux/types.h> |
Vignesh Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 14 | #include <asm/cache.h> |
| 15 | #include <cpu_func.h> |
Anup Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 16 | #include <linux/dma-direction.h> |
Vignesh Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 17 | #include <malloc.h> |
Anup Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 18 | |
| 19 | #define dma_mapping_error(x, y) 0 |
| 20 | |
| 21 | static 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 | |
| 27 | static inline void dma_free_coherent(void *addr) |
| 28 | { |
| 29 | free(addr); |
| 30 | } |
| 31 | |
Masahiro Yamada | c22c0db | 2020-02-14 16:40:17 +0900 | [diff] [blame^] | 32 | static inline dma_addr_t dma_map_single(void *vaddr, size_t len, |
| 33 | enum dma_data_direction dir) |
Anup Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 34 | { |
Vignesh Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 35 | 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 Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static inline void dma_unmap_single(volatile void *vaddr, size_t len, |
Vignesh Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 48 | enum dma_data_direction dir) |
Anup Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 49 | { |
Vignesh Raghavendra | c0a5a81 | 2020-01-16 14:23:45 +0530 | [diff] [blame] | 50 | 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 Patel | 70b8562 | 2019-02-25 08:14:17 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #endif /* __ASM_RISCV_DMA_MAPPING_H */ |