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 <asm/cache.h>
14 static inline void cache_op(phys_addr_t paddr
, size_t size
,
15 void (*fn
)(unsigned long start
, unsigned long end
))
17 struct page
*page
= phys_to_page(paddr
);
18 void *start
= __va(page_to_phys(page
));
19 unsigned long offset
= offset_in_page(paddr
);
25 if (offset
+ len
> PAGE_SIZE
)
26 len
= PAGE_SIZE
- offset
;
28 if (PageHighMem(page
)) {
29 start
= kmap_atomic(page
);
31 fn((unsigned long)start
+ offset
,
32 (unsigned long)start
+ offset
+ len
);
36 fn((unsigned long)start
+ offset
,
37 (unsigned long)start
+ offset
+ len
);
47 static void dma_wbinv_set_zero_range(unsigned long start
, unsigned long end
)
49 memset((void *)start
, 0, end
- start
);
50 dma_wbinv_range(start
, end
);
53 void arch_dma_prep_coherent(struct page
*page
, size_t size
)
55 cache_op(page_to_phys(page
), size
, dma_wbinv_set_zero_range
);
58 void arch_sync_dma_for_device(phys_addr_t paddr
, size_t size
,
59 enum dma_data_direction dir
)
63 cache_op(paddr
, size
, dma_wb_range
);
66 case DMA_BIDIRECTIONAL
:
67 cache_op(paddr
, size
, dma_wbinv_range
);
74 void arch_sync_dma_for_cpu(phys_addr_t paddr
, size_t size
,
75 enum dma_data_direction dir
)
81 case DMA_BIDIRECTIONAL
:
82 cache_op(paddr
, size
, dma_inv_range
);