2 * linux/arch/sparc/mm/leon_m.c
4 * Copyright (C) 2004 Konrad Eisele (eiselekd@web.de, konrad@gaisler.com) Gaisler Research
5 * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
6 * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
8 * do srmmu probe in software
12 #include <linux/kernel.h>
16 #include <asm/tlbflush.h>
18 int leon_flush_during_switch
= 1;
19 int srmmu_swprobe_trace
;
21 unsigned long srmmu_swprobe(unsigned long vaddr
, unsigned long *paddr
)
25 unsigned int pgd
, pmd
, ped
;
27 unsigned int lvl
, pte
, paddrbase
;
29 unsigned int paddr_calc
;
33 if (srmmu_swprobe_trace
)
34 printk(KERN_INFO
"swprobe: trace on\n");
36 ctxtbl
= srmmu_get_ctable_ptr();
38 if (srmmu_swprobe_trace
)
39 printk(KERN_INFO
"swprobe: srmmu_get_ctable_ptr returned 0=>0\n");
42 if (!_pfn_valid(PFN(ctxtbl
))) {
43 if (srmmu_swprobe_trace
)
45 "swprobe: !_pfn_valid(%x)=>0\n",
50 ctx
= srmmu_get_context();
51 if (srmmu_swprobe_trace
)
52 printk(KERN_INFO
"swprobe: --- ctx (%x) ---\n", ctx
);
54 pgd
= LEON_BYPASS_LOAD_PA(ctxtbl
+ (ctx
* 4));
56 if (((pgd
& SRMMU_ET_MASK
) == SRMMU_ET_PTE
)) {
57 if (srmmu_swprobe_trace
)
58 printk(KERN_INFO
"swprobe: pgd is entry level 3\n");
61 paddrbase
= pgd
& _SRMMU_PTE_PMASK_LEON
;
64 if (((pgd
& SRMMU_ET_MASK
) != SRMMU_ET_PTD
)) {
65 if (srmmu_swprobe_trace
)
66 printk(KERN_INFO
"swprobe: pgd is invalid => 0\n");
70 if (srmmu_swprobe_trace
)
71 printk(KERN_INFO
"swprobe: --- pgd (%x) ---\n", pgd
);
73 ptr
= (pgd
& SRMMU_PTD_PMASK
) << 4;
74 ptr
+= ((((vaddr
) >> LEON_PGD_SH
) & LEON_PGD_M
) * 4);
75 if (!_pfn_valid(PFN(ptr
)))
78 pmd
= LEON_BYPASS_LOAD_PA(ptr
);
79 if (((pmd
& SRMMU_ET_MASK
) == SRMMU_ET_PTE
)) {
80 if (srmmu_swprobe_trace
)
81 printk(KERN_INFO
"swprobe: pmd is entry level 2\n");
84 paddrbase
= pmd
& _SRMMU_PTE_PMASK_LEON
;
87 if (((pmd
& SRMMU_ET_MASK
) != SRMMU_ET_PTD
)) {
88 if (srmmu_swprobe_trace
)
89 printk(KERN_INFO
"swprobe: pmd is invalid => 0\n");
93 if (srmmu_swprobe_trace
)
94 printk(KERN_INFO
"swprobe: --- pmd (%x) ---\n", pmd
);
96 ptr
= (pmd
& SRMMU_PTD_PMASK
) << 4;
97 ptr
+= (((vaddr
>> LEON_PMD_SH
) & LEON_PMD_M
) * 4);
98 if (!_pfn_valid(PFN(ptr
))) {
99 if (srmmu_swprobe_trace
)
100 printk(KERN_INFO
"swprobe: !_pfn_valid(%x)=>0\n",
105 ped
= LEON_BYPASS_LOAD_PA(ptr
);
107 if (((ped
& SRMMU_ET_MASK
) == SRMMU_ET_PTE
)) {
108 if (srmmu_swprobe_trace
)
109 printk(KERN_INFO
"swprobe: ped is entry level 1\n");
112 paddrbase
= ped
& _SRMMU_PTE_PMASK_LEON
;
115 if (((ped
& SRMMU_ET_MASK
) != SRMMU_ET_PTD
)) {
116 if (srmmu_swprobe_trace
)
117 printk(KERN_INFO
"swprobe: ped is invalid => 0\n");
121 if (srmmu_swprobe_trace
)
122 printk(KERN_INFO
"swprobe: --- ped (%x) ---\n", ped
);
124 ptr
= (ped
& SRMMU_PTD_PMASK
) << 4;
125 ptr
+= (((vaddr
>> LEON_PTE_SH
) & LEON_PTE_M
) * 4);
126 if (!_pfn_valid(PFN(ptr
)))
129 ptr
= LEON_BYPASS_LOAD_PA(ptr
);
130 if (((ptr
& SRMMU_ET_MASK
) == SRMMU_ET_PTE
)) {
131 if (srmmu_swprobe_trace
)
132 printk(KERN_INFO
"swprobe: ptr is entry level 0\n");
135 paddrbase
= ptr
& _SRMMU_PTE_PMASK_LEON
;
138 if (srmmu_swprobe_trace
)
139 printk(KERN_INFO
"swprobe: ptr is invalid => 0\n");
146 (vaddr
& ~(-1 << LEON_PTE_SH
)) | ((pte
& ~0xff) << 4);
150 (vaddr
& ~(-1 << LEON_PMD_SH
)) | ((pte
& ~0xff) << 4);
154 (vaddr
& ~(-1 << LEON_PGD_SH
)) | ((pte
& ~0xff) << 4);
161 if (srmmu_swprobe_trace
)
162 printk(KERN_INFO
"swprobe: padde %x\n", paddr_calc
);
168 void leon_flush_icache_all(void)
170 __asm__
__volatile__(" flush "); /*iflush*/
173 void leon_flush_dcache_all(void)
175 __asm__
__volatile__("sta %%g0, [%%g0] %0\n\t" : :
176 "i"(ASI_LEON_DFLUSH
) : "memory");
179 void leon_flush_pcache_all(struct vm_area_struct
*vma
, unsigned long page
)
181 if (vma
->vm_flags
& VM_EXEC
)
182 leon_flush_icache_all();
183 leon_flush_dcache_all();
186 void leon_flush_cache_all(void)
188 __asm__
__volatile__(" flush "); /*iflush*/
189 __asm__
__volatile__("sta %%g0, [%%g0] %0\n\t" : :
190 "i"(ASI_LEON_DFLUSH
) : "memory");
193 void leon_flush_tlb_all(void)
195 leon_flush_cache_all();
196 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : : "r"(0x400),
197 "i"(ASI_LEON_MMUFLUSH
) : "memory");
200 /* get all cache regs */
201 void leon3_getCacheRegs(struct leon3_cacheregs
*regs
)
203 unsigned long ccr
, iccr
, dccr
;
207 /* Get Cache regs from "Cache ASI" address 0x0, 0x8 and 0xC */
208 __asm__
__volatile__("lda [%%g0] %3, %0\n\t"
210 "lda [%%g1] %3, %1\n\t"
212 "lda [%%g1] %3, %2\n\t"
213 : "=r"(ccr
), "=r"(iccr
), "=r"(dccr
)
215 : "i"(ASI_LEON_CACHEREGS
) /* input */
216 : "g1" /* clobber list */
223 /* Due to virtual cache we need to check cache configuration if
224 * it is possible to skip flushing in some cases.
226 * Leon2 and Leon3 differ in their way of telling cache information
229 int __init
leon_flush_needed(void)
231 int flush_needed
= -1;
232 unsigned int ssize
, sets
;
234 { "direct mapped", "2-way associative", "3-way associative",
238 struct leon3_cacheregs cregs
;
239 leon3_getCacheRegs(&cregs
);
240 sets
= (cregs
.dccr
& LEON3_XCCR_SETS_MASK
) >> 24;
241 /* (ssize=>realsize) 0=>1k, 1=>2k, 2=>4k, 3=>8k ... */
242 ssize
= 1 << ((cregs
.dccr
& LEON3_XCCR_SSIZE_MASK
) >> 20);
244 printk(KERN_INFO
"CACHE: %s cache, set size %dk\n",
245 sets
> 3 ? "unknown" : setStr
[sets
], ssize
);
246 if ((ssize
<= (PAGE_SIZE
/ 1024)) && (sets
== 0)) {
247 /* Set Size <= Page size ==>
248 flush on every context switch not needed. */
250 printk(KERN_INFO
"CACHE: not flushing on every context switch\n");
255 void leon_switch_mm(void)
257 flush_tlb_mm((void *)0);
258 if (leon_flush_during_switch
)
259 leon_flush_cache_all();