1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/dma-map-ops.h>
17#include <linux/pagewalk.h>
18
19#include <asm/cpuinfo.h>
20#include <asm/spr_defs.h>
21#include <asm/tlbflush.h>
22
23static int
24page_set_nocache(pte_t *pte, unsigned long addr,
25 unsigned long next, struct mm_walk *walk)
26{
27 unsigned long cl;
28 struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()];
29
30 pte_val(*pte) |= _PAGE_CI;
31
32
33
34
35
36 flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
37
38
39 for (cl = __pa(addr); cl < __pa(next); cl += cpuinfo->dcache_block_size)
40 mtspr(SPR_DCBFR, cl);
41
42 return 0;
43}
44
45static const struct mm_walk_ops set_nocache_walk_ops = {
46 .pte_entry = page_set_nocache,
47};
48
49static int
50page_clear_nocache(pte_t *pte, unsigned long addr,
51 unsigned long next, struct mm_walk *walk)
52{
53 pte_val(*pte) &= ~_PAGE_CI;
54
55
56
57
58
59 flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
60
61 return 0;
62}
63
64static const struct mm_walk_ops clear_nocache_walk_ops = {
65 .pte_entry = page_clear_nocache,
66};
67
68void *arch_dma_set_uncached(void *cpu_addr, size_t size)
69{
70 unsigned long va = (unsigned long)cpu_addr;
71 int error;
72
73
74
75
76
77 mmap_read_lock(&init_mm);
78 error = walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops,
79 NULL);
80 mmap_read_unlock(&init_mm);
81
82 if (error)
83 return ERR_PTR(error);
84 return cpu_addr;
85}
86
87void arch_dma_clear_uncached(void *cpu_addr, size_t size)
88{
89 unsigned long va = (unsigned long)cpu_addr;
90
91 mmap_read_lock(&init_mm);
92
93 WARN_ON(walk_page_range(&init_mm, va, va + size,
94 &clear_nocache_walk_ops, NULL));
95 mmap_read_unlock(&init_mm);
96}
97
98void arch_sync_dma_for_device(phys_addr_t addr, size_t size,
99 enum dma_data_direction dir)
100{
101 unsigned long cl;
102 struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()];
103
104 switch (dir) {
105 case DMA_TO_DEVICE:
106
107 for (cl = addr; cl < addr + size;
108 cl += cpuinfo->dcache_block_size)
109 mtspr(SPR_DCBFR, cl);
110 break;
111 case DMA_FROM_DEVICE:
112
113 for (cl = addr; cl < addr + size;
114 cl += cpuinfo->dcache_block_size)
115 mtspr(SPR_DCBIR, cl);
116 break;
117 default:
118
119
120
121
122
123 break;
124 }
125}
126