1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/cache.h>
5 #include <linux/dma-map-ops.h>
6 #include <linux/genalloc.h>
7 #include <linux/highmem.h>
10 #include <linux/scatterlist.h>
11 #include <linux/types.h>
12 #include <linux/version.h>
13 #include <asm/cache.h>
15 static inline void cache_op(phys_addr_t paddr
, size_t size
,
16 void (*fn
)(unsigned long start
, unsigned long end
))
18 struct page
*page
= phys_to_page(paddr
);
19 void *start
= __va(page_to_phys(page
));
20 unsigned long offset
= offset_in_page(paddr
);
26 if (offset
+ len
> PAGE_SIZE
)
27 len
= PAGE_SIZE
- offset
;
29 if (PageHighMem(page
)) {
30 start
= kmap_atomic(page
);
32 fn((unsigned long)start
+ offset
,
33 (unsigned long)start
+ offset
+ len
);
37 fn((unsigned long)start
+ offset
,
38 (unsigned long)start
+ offset
+ len
);
48 static void dma_wbinv_set_zero_range(unsigned long start
, unsigned long end
)
50 memset((void *)start
, 0, end
- start
);
51 dma_wbinv_range(start
, end
);
54 void arch_dma_prep_coherent(struct page
*page
, size_t size
)
56 cache_op(page_to_phys(page
), size
, dma_wbinv_set_zero_range
);
59 void arch_sync_dma_for_device(phys_addr_t paddr
, size_t size
,
60 enum dma_data_direction dir
)
64 cache_op(paddr
, size
, dma_wb_range
);
67 case DMA_BIDIRECTIONAL
:
68 cache_op(paddr
, size
, dma_wbinv_range
);
75 void arch_sync_dma_for_cpu(phys_addr_t paddr
, size_t size
,
76 enum dma_data_direction dir
)
82 case DMA_BIDIRECTIONAL
:
83 cache_op(paddr
, size
, dma_inv_range
);