drm/ssd130x: Set SPI .id_table to prevent an SPI core warning
[drm/drm-misc.git] / arch / csky / mm / dma-mapping.c
blob82447029feb485aef3554121e8d58b2840d12391
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>
8 #include <linux/io.h>
9 #include <linux/mm.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);
20 size_t left = size;
22 do {
23 size_t len = left;
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);
34 kunmap_atomic(start);
35 } else {
36 fn((unsigned long)start + offset,
37 (unsigned long)start + offset + len);
39 offset = 0;
41 page++;
42 start += PAGE_SIZE;
43 left -= len;
44 } while (left);
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)
61 switch (dir) {
62 case DMA_TO_DEVICE:
63 cache_op(paddr, size, dma_wb_range);
64 break;
65 case DMA_FROM_DEVICE:
66 case DMA_BIDIRECTIONAL:
67 cache_op(paddr, size, dma_wbinv_range);
68 break;
69 default:
70 BUG();
74 void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
75 enum dma_data_direction dir)
77 switch (dir) {
78 case DMA_TO_DEVICE:
79 return;
80 case DMA_FROM_DEVICE:
81 case DMA_BIDIRECTIONAL:
82 cache_op(paddr, size, dma_inv_range);
83 break;
84 default:
85 BUG();