blob: 900b99b8a69a194f5b3f1203829a65f62222b302 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Andy Shevchenkof2b047f2017-07-06 14:41:51 +03002/*
3 * (C) Copyright 2007
4 * Stelian Pop <stelian@popies.net>
5 * Lead Tech Design <www.leadtechdesign.com>
Andy Shevchenkof2b047f2017-07-06 14:41:51 +03006 */
7#ifndef __ASM_X86_DMA_MAPPING_H
8#define __ASM_X86_DMA_MAPPING_H
9
Vignesh Raghavendra4a81a212020-01-16 14:23:45 +053010#include <common.h>
11#include <asm/cache.h>
12#include <cpu_func.h>
Masahiro Yamadaef205ea2017-08-26 00:50:17 +090013#include <linux/dma-direction.h>
Vignesh Raghavendra4a81a212020-01-16 14:23:45 +053014#include <malloc.h>
Andy Shevchenkof2b047f2017-07-06 14:41:51 +030015
Masahiro Yamadaef205ea2017-08-26 00:50:17 +090016#define dma_mapping_error(x, y) 0
Andy Shevchenkof2b047f2017-07-06 14:41:51 +030017
18static 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
24static inline void dma_free_coherent(void *addr)
25{
26 free(addr);
27}
28
29static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
30 enum dma_data_direction dir)
31{
Vignesh Raghavendra4a81a212020-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;
Andy Shevchenkof2b047f2017-07-06 14:41:51 +030042}
43
44static inline void dma_unmap_single(volatile void *vaddr, size_t len,
Vignesh Raghavendra4a81a212020-01-16 14:23:45 +053045 enum dma_data_direction dir)
Andy Shevchenkof2b047f2017-07-06 14:41:51 +030046{
Vignesh Raghavendra4a81a212020-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);
Andy Shevchenkof2b047f2017-07-06 14:41:51 +030053}
54
55#endif /* __ASM_X86_DMA_MAPPING_H */