Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * Stelian Pop <stelian@popies.net> |
| 5 | * Lead Tech Design <www.leadtechdesign.com> |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 6 | */ |
| 7 | #ifndef __ASM_X86_DMA_MAPPING_H |
| 8 | #define __ASM_X86_DMA_MAPPING_H |
| 9 | |
Vignesh Raghavendra | 4a81a21 | 2020-01-16 14:23:45 +0530 | [diff] [blame^] | 10 | #include <common.h> |
| 11 | #include <asm/cache.h> |
| 12 | #include <cpu_func.h> |
Masahiro Yamada | ef205ea | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 13 | #include <linux/dma-direction.h> |
Vignesh Raghavendra | 4a81a21 | 2020-01-16 14:23:45 +0530 | [diff] [blame^] | 14 | #include <malloc.h> |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 15 | |
Masahiro Yamada | ef205ea | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 16 | #define dma_mapping_error(x, y) 0 |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 17 | |
| 18 | static inline void *dma_alloc_coherent(size_t len, unsigned long *handle) |
| 19 | { |
| 20 | *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len); |
| 21 | return (void *)*handle; |
| 22 | } |
| 23 | |
| 24 | static inline void dma_free_coherent(void *addr) |
| 25 | { |
| 26 | free(addr); |
| 27 | } |
| 28 | |
| 29 | static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, |
| 30 | enum dma_data_direction dir) |
| 31 | { |
Vignesh Raghavendra | 4a81a21 | 2020-01-16 14:23:45 +0530 | [diff] [blame^] | 32 | 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; |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static inline void dma_unmap_single(volatile void *vaddr, size_t len, |
Vignesh Raghavendra | 4a81a21 | 2020-01-16 14:23:45 +0530 | [diff] [blame^] | 45 | enum dma_data_direction dir) |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 46 | { |
Vignesh Raghavendra | 4a81a21 | 2020-01-16 14:23:45 +0530 | [diff] [blame^] | 47 | 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); |
Andy Shevchenko | f2b047f | 2017-07-06 14:41:51 +0300 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #endif /* __ASM_X86_DMA_MAPPING_H */ |