1 /* $Id: sun4c.c,v 1.210 2001/11/13 03:27:47 davem Exp $
2 * sun4c.c: Doing in software what should be done in hardware.
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1996 Andrew Tridgell (Andrew.Tridgell@anu.edu.au)
7 * Copyright (C) 1997-2000 Anton Blanchard (anton@samba.org)
8 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 */
10
11 #define NR_TASK_BUCKETS 512
12
13 #include <linux/config.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/init.h>
17 #include <linux/bootmem.h>
18 #include <linux/highmem.h>
19 #include <linux/fs.h>
20 #include <linux/seq_file.h>
21
22 #include <asm/scatterlist.h>
23 #include <asm/page.h>
24 #include <asm/pgalloc.h>
25 #include <asm/pgtable.h>
26 #include <asm/vaddrs.h>
27 #include <asm/idprom.h>
28 #include <asm/machines.h>
29 #include <asm/memreg.h>
30 #include <asm/processor.h>
31 #include <asm/auxio.h>
32 #include <asm/io.h>
33 #include <asm/oplib.h>
34 #include <asm/openprom.h>
35 #include <asm/mmu_context.h>
36 #include <asm/sun4paddr.h>
37 #include <asm/highmem.h>
38 #include <asm/btfixup.h>
39
40 /* Because of our dynamic kernel TLB miss strategy, and how
41 * our DVMA mapping allocation works, you _MUST_:
42 *
43 * 1) Disable interrupts _and_ not touch any dynamic kernel
44 * memory while messing with kernel MMU state. By
45 * dynamic memory I mean any object which is not in
46 * the kernel image itself or a task_struct (both of
47 * which are locked into the MMU).
48 * 2) Disable interrupts while messing with user MMU state.
49 */
50
51 extern int num_segmaps, num_contexts;
52
53 extern unsigned long page_kernel;
54
55 #ifdef CONFIG_SUN4
56 #define SUN4C_VAC_SIZE sun4c_vacinfo.num_bytes
57 #else
58 /* That's it, we prom_halt() on sun4c if the cache size is something other than 65536.
59 * So let's save some cycles and just use that everywhere except for that bootup
60 * sanity check.
61 */
62 #define SUN4C_VAC_SIZE 65536
63 #endif
64
65 #define SUN4C_KERNEL_BUCKETS 32
66
67 /* Flushing the cache. */
68 struct sun4c_vac_props sun4c_vacinfo;
69 unsigned long sun4c_kernel_faults;
70
71 /* Invalidate every sun4c cache line tag. */
sun4c_flush_all(void)72 static void __init sun4c_flush_all(void)
73 {
74 unsigned long begin, end;
75
76 if (sun4c_vacinfo.on)
77 panic("SUN4C: AIEEE, trying to invalidate vac while it is on.");
78
79 /* Clear 'valid' bit in all cache line tags */
80 begin = AC_CACHETAGS;
81 end = (AC_CACHETAGS + SUN4C_VAC_SIZE);
82 while (begin < end) {
83 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
84 "r" (begin), "i" (ASI_CONTROL));
85 begin += sun4c_vacinfo.linesize;
86 }
87 }
88
sun4c_flush_context_hw(void)89 static void sun4c_flush_context_hw(void)
90 {
91 unsigned long end = SUN4C_VAC_SIZE;
92
93 __asm__ __volatile__(
94 "1: addcc %0, -4096, %0\n\t"
95 " bne 1b\n\t"
96 " sta %%g0, [%0] %2"
97 : "=&r" (end)
98 : "0" (end), "i" (ASI_HWFLUSHCONTEXT)
99 : "cc");
100 }
101
102 /* Must be called minimally with IRQs disabled. */
sun4c_flush_segment_hw(unsigned long addr)103 static void sun4c_flush_segment_hw(unsigned long addr)
104 {
105 if (sun4c_get_segmap(addr) != invalid_segment) {
106 unsigned long vac_size = SUN4C_VAC_SIZE;
107
108 __asm__ __volatile__(
109 "1: addcc %0, -4096, %0\n\t"
110 " bne 1b\n\t"
111 " sta %%g0, [%2 + %0] %3"
112 : "=&r" (vac_size)
113 : "0" (vac_size), "r" (addr), "i" (ASI_HWFLUSHSEG)
114 : "cc");
115 }
116 }
117
118 /* File local boot time fixups. */
BTFIXUPDEF_CALL(void,sun4c_flush_page,unsigned long)119 BTFIXUPDEF_CALL(void, sun4c_flush_page, unsigned long)
120 BTFIXUPDEF_CALL(void, sun4c_flush_segment, unsigned long)
121 BTFIXUPDEF_CALL(void, sun4c_flush_context, void)
122
123 #define sun4c_flush_page(addr) BTFIXUP_CALL(sun4c_flush_page)(addr)
124 #define sun4c_flush_segment(addr) BTFIXUP_CALL(sun4c_flush_segment)(addr)
125 #define sun4c_flush_context() BTFIXUP_CALL(sun4c_flush_context)()
126
127 /* Must be called minimally with interrupts disabled. */
128 static void sun4c_flush_page_hw(unsigned long addr)
129 {
130 addr &= PAGE_MASK;
131 if ((int)sun4c_get_pte(addr) < 0)
132 __asm__ __volatile__("sta %%g0, [%0] %1"
133 : : "r" (addr), "i" (ASI_HWFLUSHPAGE));
134 }
135
136 /* Don't inline the software version as it eats too many cache lines if expanded. */
sun4c_flush_context_sw(void)137 static void sun4c_flush_context_sw(void)
138 {
139 unsigned long nbytes = SUN4C_VAC_SIZE;
140 unsigned long lsize = sun4c_vacinfo.linesize;
141
142 __asm__ __volatile__(
143 "add %2, %2, %%g1\n\t"
144 "add %2, %%g1, %%g2\n\t"
145 "add %2, %%g2, %%g3\n\t"
146 "add %2, %%g3, %%g4\n\t"
147 "add %2, %%g4, %%g5\n\t"
148 "add %2, %%g5, %%o4\n\t"
149 "add %2, %%o4, %%o5\n"
150 "1:\n\t"
151 "subcc %0, %%o5, %0\n\t"
152 "sta %%g0, [%0] %3\n\t"
153 "sta %%g0, [%0 + %2] %3\n\t"
154 "sta %%g0, [%0 + %%g1] %3\n\t"
155 "sta %%g0, [%0 + %%g2] %3\n\t"
156 "sta %%g0, [%0 + %%g3] %3\n\t"
157 "sta %%g0, [%0 + %%g4] %3\n\t"
158 "sta %%g0, [%0 + %%g5] %3\n\t"
159 "bg 1b\n\t"
160 " sta %%g0, [%1 + %%o4] %3\n"
161 : "=&r" (nbytes)
162 : "0" (nbytes), "r" (lsize), "i" (ASI_FLUSHCTX)
163 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
164 }
165
166 /* Don't inline the software version as it eats too many cache lines if expanded. */
sun4c_flush_segment_sw(unsigned long addr)167 static void sun4c_flush_segment_sw(unsigned long addr)
168 {
169 if (sun4c_get_segmap(addr) != invalid_segment) {
170 unsigned long nbytes = SUN4C_VAC_SIZE;
171 unsigned long lsize = sun4c_vacinfo.linesize;
172
173 __asm__ __volatile__(
174 "add %2, %2, %%g1\n\t"
175 "add %2, %%g1, %%g2\n\t"
176 "add %2, %%g2, %%g3\n\t"
177 "add %2, %%g3, %%g4\n\t"
178 "add %2, %%g4, %%g5\n\t"
179 "add %2, %%g5, %%o4\n\t"
180 "add %2, %%o4, %%o5\n"
181 "1:\n\t"
182 "subcc %1, %%o5, %1\n\t"
183 "sta %%g0, [%0] %6\n\t"
184 "sta %%g0, [%0 + %2] %6\n\t"
185 "sta %%g0, [%0 + %%g1] %6\n\t"
186 "sta %%g0, [%0 + %%g2] %6\n\t"
187 "sta %%g0, [%0 + %%g3] %6\n\t"
188 "sta %%g0, [%0 + %%g4] %6\n\t"
189 "sta %%g0, [%0 + %%g5] %6\n\t"
190 "sta %%g0, [%0 + %%o4] %6\n\t"
191 "bg 1b\n\t"
192 " add %0, %%o5, %0\n"
193 : "=&r" (addr), "=&r" (nbytes), "=&r" (lsize)
194 : "0" (addr), "1" (nbytes), "2" (lsize),
195 "i" (ASI_FLUSHSEG)
196 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
197 }
198 }
199
200 /* Don't inline the software version as it eats too many cache lines if expanded. */
sun4c_flush_page_sw(unsigned long addr)201 static void sun4c_flush_page_sw(unsigned long addr)
202 {
203 addr &= PAGE_MASK;
204 if ((sun4c_get_pte(addr) & (_SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_VALID)) ==
205 _SUN4C_PAGE_VALID) {
206 unsigned long left = PAGE_SIZE;
207 unsigned long lsize = sun4c_vacinfo.linesize;
208
209 __asm__ __volatile__(
210 "add %2, %2, %%g1\n\t"
211 "add %2, %%g1, %%g2\n\t"
212 "add %2, %%g2, %%g3\n\t"
213 "add %2, %%g3, %%g4\n\t"
214 "add %2, %%g4, %%g5\n\t"
215 "add %2, %%g5, %%o4\n\t"
216 "add %2, %%o4, %%o5\n"
217 "1:\n\t"
218 "subcc %1, %%o5, %1\n\t"
219 "sta %%g0, [%0] %6\n\t"
220 "sta %%g0, [%0 + %2] %6\n\t"
221 "sta %%g0, [%0 + %%g1] %6\n\t"
222 "sta %%g0, [%0 + %%g2] %6\n\t"
223 "sta %%g0, [%0 + %%g3] %6\n\t"
224 "sta %%g0, [%0 + %%g4] %6\n\t"
225 "sta %%g0, [%0 + %%g5] %6\n\t"
226 "sta %%g0, [%0 + %%o4] %6\n\t"
227 "bg 1b\n\t"
228 " add %0, %%o5, %0\n"
229 : "=&r" (addr), "=&r" (left), "=&r" (lsize)
230 : "0" (addr), "1" (left), "2" (lsize),
231 "i" (ASI_FLUSHPG)
232 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
233 }
234 }
235
236 /* The sun4c's do have an on chip store buffer. And the way you
237 * clear them out isn't so obvious. The only way I can think of
238 * to accomplish this is to read the current context register,
239 * store the same value there, then read an external hardware
240 * register.
241 */
sun4c_complete_all_stores(void)242 void sun4c_complete_all_stores(void)
243 {
244 volatile int _unused;
245
246 _unused = sun4c_get_context();
247 sun4c_set_context(_unused);
248 #ifdef CONFIG_SUN_AUXIO
249 _unused = get_auxio();
250 #endif
251 }
252
253 /* Bootup utility functions. */
sun4c_init_clean_segmap(unsigned char pseg)254 static inline void sun4c_init_clean_segmap(unsigned char pseg)
255 {
256 unsigned long vaddr;
257
258 sun4c_put_segmap(0, pseg);
259 for (vaddr = 0; vaddr < SUN4C_REAL_PGDIR_SIZE; vaddr += PAGE_SIZE)
260 sun4c_put_pte(vaddr, 0);
261 sun4c_put_segmap(0, invalid_segment);
262 }
263
sun4c_init_clean_mmu(unsigned long kernel_end)264 static inline void sun4c_init_clean_mmu(unsigned long kernel_end)
265 {
266 unsigned long vaddr;
267 unsigned char savectx, ctx;
268
269 savectx = sun4c_get_context();
270 kernel_end = SUN4C_REAL_PGDIR_ALIGN(kernel_end);
271 for (ctx = 0; ctx < num_contexts; ctx++) {
272 sun4c_set_context(ctx);
273 for (vaddr = 0; vaddr < 0x20000000; vaddr += SUN4C_REAL_PGDIR_SIZE)
274 sun4c_put_segmap(vaddr, invalid_segment);
275 for (vaddr = 0xe0000000; vaddr < KERNBASE; vaddr += SUN4C_REAL_PGDIR_SIZE)
276 sun4c_put_segmap(vaddr, invalid_segment);
277 for (vaddr = kernel_end; vaddr < KADB_DEBUGGER_BEGVM; vaddr += SUN4C_REAL_PGDIR_SIZE)
278 sun4c_put_segmap(vaddr, invalid_segment);
279 for (vaddr = LINUX_OPPROM_ENDVM; vaddr; vaddr += SUN4C_REAL_PGDIR_SIZE)
280 sun4c_put_segmap(vaddr, invalid_segment);
281 }
282 sun4c_set_context(savectx);
283 }
284
sun4c_probe_vac(void)285 void __init sun4c_probe_vac(void)
286 {
287 sun4c_disable_vac();
288
289 if (ARCH_SUN4) {
290 switch (idprom->id_machtype) {
291
292 case (SM_SUN4|SM_4_110):
293 sun4c_vacinfo.type = VAC_NONE;
294 sun4c_vacinfo.num_bytes = 0;
295 sun4c_vacinfo.linesize = 0;
296 sun4c_vacinfo.do_hwflushes = 0;
297 prom_printf("No VAC. Get some bucks and buy a real computer.");
298 prom_halt();
299 break;
300
301 case (SM_SUN4|SM_4_260):
302 sun4c_vacinfo.type = VAC_WRITE_BACK;
303 sun4c_vacinfo.num_bytes = 128 * 1024;
304 sun4c_vacinfo.linesize = 16;
305 sun4c_vacinfo.do_hwflushes = 0;
306 break;
307
308 case (SM_SUN4|SM_4_330):
309 sun4c_vacinfo.type = VAC_WRITE_THROUGH;
310 sun4c_vacinfo.num_bytes = 128 * 1024;
311 sun4c_vacinfo.linesize = 16;
312 sun4c_vacinfo.do_hwflushes = 0;
313 break;
314
315 case (SM_SUN4|SM_4_470):
316 sun4c_vacinfo.type = VAC_WRITE_BACK;
317 sun4c_vacinfo.num_bytes = 128 * 1024;
318 sun4c_vacinfo.linesize = 32;
319 sun4c_vacinfo.do_hwflushes = 0;
320 break;
321
322 default:
323 prom_printf("Cannot initialize VAC - weird sun4 model idprom->id_machtype = %d", idprom->id_machtype);
324 prom_halt();
325 };
326 } else {
327 sun4c_vacinfo.type = VAC_WRITE_THROUGH;
328
329 if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
330 (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
331 /* PROM on SS1 lacks this info, to be super safe we
332 * hard code it here since this arch is cast in stone.
333 */
334 sun4c_vacinfo.num_bytes = 65536;
335 sun4c_vacinfo.linesize = 16;
336 } else {
337 sun4c_vacinfo.num_bytes =
338 prom_getintdefault(prom_root_node, "vac-size", 65536);
339 sun4c_vacinfo.linesize =
340 prom_getintdefault(prom_root_node, "vac-linesize", 16);
341 }
342 sun4c_vacinfo.do_hwflushes =
343 prom_getintdefault(prom_root_node, "vac-hwflush", 0);
344
345 if (sun4c_vacinfo.do_hwflushes == 0)
346 sun4c_vacinfo.do_hwflushes =
347 prom_getintdefault(prom_root_node, "vac_hwflush", 0);
348
349 if (sun4c_vacinfo.num_bytes != 65536) {
350 prom_printf("WEIRD Sun4C VAC cache size, "
351 "tell sparclinux@vger.kernel.org");
352 prom_halt();
353 }
354 }
355
356 sun4c_vacinfo.num_lines =
357 (sun4c_vacinfo.num_bytes / sun4c_vacinfo.linesize);
358 switch (sun4c_vacinfo.linesize) {
359 case 16:
360 sun4c_vacinfo.log2lsize = 4;
361 break;
362 case 32:
363 sun4c_vacinfo.log2lsize = 5;
364 break;
365 default:
366 prom_printf("probe_vac: Didn't expect vac-linesize of %d, halting\n",
367 sun4c_vacinfo.linesize);
368 prom_halt();
369 };
370
371 sun4c_flush_all();
372 sun4c_enable_vac();
373 }
374
375 /* Patch instructions for the low level kernel fault handler. */
376 extern unsigned long invalid_segment_patch1, invalid_segment_patch1_ff;
377 extern unsigned long invalid_segment_patch2, invalid_segment_patch2_ff;
378 extern unsigned long invalid_segment_patch1_1ff, invalid_segment_patch2_1ff;
379 extern unsigned long num_context_patch1, num_context_patch1_16;
380 extern unsigned long num_context_patch2, num_context_patch2_16;
381 extern unsigned long vac_linesize_patch, vac_linesize_patch_32;
382 extern unsigned long vac_hwflush_patch1, vac_hwflush_patch1_on;
383 extern unsigned long vac_hwflush_patch2, vac_hwflush_patch2_on;
384
385 #define PATCH_INSN(src, dst) do { \
386 daddr = &(dst); \
387 iaddr = &(src); \
388 *daddr = *iaddr; \
389 } while (0)
390
patch_kernel_fault_handler(void)391 static void __init patch_kernel_fault_handler(void)
392 {
393 unsigned long *iaddr, *daddr;
394
395 switch (num_segmaps) {
396 case 128:
397 /* Default, nothing to do. */
398 break;
399 case 256:
400 PATCH_INSN(invalid_segment_patch1_ff,
401 invalid_segment_patch1);
402 PATCH_INSN(invalid_segment_patch2_ff,
403 invalid_segment_patch2);
404 break;
405 case 512:
406 PATCH_INSN(invalid_segment_patch1_1ff,
407 invalid_segment_patch1);
408 PATCH_INSN(invalid_segment_patch2_1ff,
409 invalid_segment_patch2);
410 break;
411 default:
412 prom_printf("Unhandled number of segmaps: %d\n",
413 num_segmaps);
414 prom_halt();
415 };
416 switch (num_contexts) {
417 case 8:
418 /* Default, nothing to do. */
419 break;
420 case 16:
421 PATCH_INSN(num_context_patch1_16,
422 num_context_patch1);
423 break;
424 default:
425 prom_printf("Unhandled number of contexts: %d\n",
426 num_contexts);
427 prom_halt();
428 };
429
430 if (sun4c_vacinfo.do_hwflushes != 0) {
431 PATCH_INSN(vac_hwflush_patch1_on, vac_hwflush_patch1);
432 PATCH_INSN(vac_hwflush_patch2_on, vac_hwflush_patch2);
433 } else {
434 switch (sun4c_vacinfo.linesize) {
435 case 16:
436 /* Default, nothing to do. */
437 break;
438 case 32:
439 PATCH_INSN(vac_linesize_patch_32, vac_linesize_patch);
440 break;
441 default:
442 prom_printf("Impossible VAC linesize %d, halting...\n",
443 sun4c_vacinfo.linesize);
444 prom_halt();
445 };
446 }
447 }
448
sun4c_probe_mmu(void)449 static void __init sun4c_probe_mmu(void)
450 {
451 if (ARCH_SUN4) {
452 switch (idprom->id_machtype) {
453 case (SM_SUN4|SM_4_110):
454 prom_printf("No support for 4100 yet\n");
455 prom_halt();
456 num_segmaps = 256;
457 num_contexts = 8;
458 break;
459
460 case (SM_SUN4|SM_4_260):
461 /* should be 512 segmaps. when it get fixed */
462 num_segmaps = 256;
463 num_contexts = 16;
464 break;
465
466 case (SM_SUN4|SM_4_330):
467 num_segmaps = 256;
468 num_contexts = 16;
469 break;
470
471 case (SM_SUN4|SM_4_470):
472 /* should be 1024 segmaps. when it get fixed */
473 num_segmaps = 256;
474 num_contexts = 64;
475 break;
476 default:
477 prom_printf("Invalid SUN4 model\n");
478 prom_halt();
479 };
480 } else {
481 if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
482 (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
483 /* Hardcode these just to be safe, PROM on SS1 does
484 * not have this info available in the root node.
485 */
486 num_segmaps = 128;
487 num_contexts = 8;
488 } else {
489 num_segmaps =
490 prom_getintdefault(prom_root_node, "mmu-npmg", 128);
491 num_contexts =
492 prom_getintdefault(prom_root_node, "mmu-nctx", 0x8);
493 }
494 }
495 patch_kernel_fault_handler();
496 }
497
498 volatile unsigned long *sun4c_memerr_reg = 0;
499
sun4c_probe_memerr_reg(void)500 void __init sun4c_probe_memerr_reg(void)
501 {
502 int node;
503 struct linux_prom_registers regs[1];
504
505 if (ARCH_SUN4) {
506 sun4c_memerr_reg = ioremap(sun4_memreg_physaddr, PAGE_SIZE);
507 } else {
508 node = prom_getchild(prom_root_node);
509 node = prom_searchsiblings(prom_root_node, "memory-error");
510 if (!node)
511 return;
512 prom_getproperty(node, "reg", (char *)regs, sizeof(regs));
513 /* hmm I think regs[0].which_io is zero here anyways */
514 sun4c_memerr_reg = ioremap(regs[0].phys_addr, regs[0].reg_size);
515 }
516 }
517
sun4c_init_ss2_cache_bug(void)518 static inline void sun4c_init_ss2_cache_bug(void)
519 {
520 extern unsigned long start;
521
522 if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS2)) ||
523 (idprom->id_machtype == (SM_SUN4C | SM_4C_IPX)) ||
524 (idprom->id_machtype == (SM_SUN4 | SM_4_330)) ||
525 (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC))) {
526 /* Whee.. */
527 printk("SS2 cache bug detected, uncaching trap table page\n");
528 sun4c_flush_page((unsigned int) &start);
529 sun4c_put_pte(((unsigned long) &start),
530 (sun4c_get_pte((unsigned long) &start) | _SUN4C_PAGE_NOCACHE));
531 }
532 }
533
534 /* Addr is always aligned on a page boundry for us already. */
sun4c_map_dma_area(unsigned long va,u32 addr,int len)535 static void sun4c_map_dma_area(unsigned long va, u32 addr, int len)
536 {
537 unsigned long page, end;
538
539 end = PAGE_ALIGN((addr + len));
540 while (addr < end) {
541 page = va;
542 sun4c_flush_page(page);
543 page -= PAGE_OFFSET;
544 page >>= PAGE_SHIFT;
545 page |= (_SUN4C_PAGE_VALID | _SUN4C_PAGE_DIRTY |
546 _SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_PRIV);
547 sun4c_put_pte(addr, page);
548 addr += PAGE_SIZE;
549 va += PAGE_SIZE;
550 }
551 }
552
sun4c_translate_dvma(unsigned long busa)553 static unsigned long sun4c_translate_dvma(unsigned long busa)
554 {
555 /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
556 unsigned long pte = sun4c_get_pte(busa);
557 return (pte << PAGE_SHIFT) + PAGE_OFFSET;
558 }
559
sun4c_unmap_dma_area(unsigned long busa,int len)560 static void sun4c_unmap_dma_area(unsigned long busa, int len)
561 {
562 /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
563 /* XXX Implement this */
564 }
565
566 /* TLB management. */
567
568 /* Don't change this struct without changing entry.S. This is used
569 * in the in-window kernel fault handler, and you don't want to mess
570 * with that. (See sun4c_fault in entry.S).
571 */
572 struct sun4c_mmu_entry {
573 struct sun4c_mmu_entry *next;
574 struct sun4c_mmu_entry *prev;
575 unsigned long vaddr;
576 unsigned char pseg;
577 unsigned char locked;
578
579 /* For user mappings only, and completely hidden from kernel
580 * TLB miss code.
581 */
582 unsigned char ctx;
583 struct sun4c_mmu_entry *lru_next;
584 struct sun4c_mmu_entry *lru_prev;
585 };
586
587 static struct sun4c_mmu_entry mmu_entry_pool[SUN4C_MAX_SEGMAPS];
588
sun4c_init_mmu_entry_pool(void)589 static void __init sun4c_init_mmu_entry_pool(void)
590 {
591 int i;
592
593 for (i=0; i < SUN4C_MAX_SEGMAPS; i++) {
594 mmu_entry_pool[i].pseg = i;
595 mmu_entry_pool[i].next = 0;
596 mmu_entry_pool[i].prev = 0;
597 mmu_entry_pool[i].vaddr = 0;
598 mmu_entry_pool[i].locked = 0;
599 mmu_entry_pool[i].ctx = 0;
600 mmu_entry_pool[i].lru_next = 0;
601 mmu_entry_pool[i].lru_prev = 0;
602 }
603 mmu_entry_pool[invalid_segment].locked = 1;
604 }
605
fix_permissions(unsigned long vaddr,unsigned long bits_on,unsigned long bits_off)606 static inline void fix_permissions(unsigned long vaddr, unsigned long bits_on,
607 unsigned long bits_off)
608 {
609 unsigned long start, end;
610
611 end = vaddr + SUN4C_REAL_PGDIR_SIZE;
612 for (start = vaddr; start < end; start += PAGE_SIZE)
613 if (sun4c_get_pte(start) & _SUN4C_PAGE_VALID)
614 sun4c_put_pte(start, (sun4c_get_pte(start) | bits_on) &
615 ~bits_off);
616 }
617
sun4c_init_map_kernelprom(unsigned long kernel_end)618 static inline void sun4c_init_map_kernelprom(unsigned long kernel_end)
619 {
620 unsigned long vaddr;
621 unsigned char pseg, ctx;
622 #ifdef CONFIG_SUN4
623 /* sun4/110 and 260 have no kadb. */
624 if ((idprom->id_machtype != (SM_SUN4 | SM_4_260)) &&
625 (idprom->id_machtype != (SM_SUN4 | SM_4_110))) {
626 #endif
627 for (vaddr = KADB_DEBUGGER_BEGVM;
628 vaddr < LINUX_OPPROM_ENDVM;
629 vaddr += SUN4C_REAL_PGDIR_SIZE) {
630 pseg = sun4c_get_segmap(vaddr);
631 if (pseg != invalid_segment) {
632 mmu_entry_pool[pseg].locked = 1;
633 for (ctx = 0; ctx < num_contexts; ctx++)
634 prom_putsegment(ctx, vaddr, pseg);
635 fix_permissions(vaddr, _SUN4C_PAGE_PRIV, 0);
636 }
637 }
638 #ifdef CONFIG_SUN4
639 }
640 #endif
641 for (vaddr = KERNBASE; vaddr < kernel_end; vaddr += SUN4C_REAL_PGDIR_SIZE) {
642 pseg = sun4c_get_segmap(vaddr);
643 mmu_entry_pool[pseg].locked = 1;
644 for (ctx = 0; ctx < num_contexts; ctx++)
645 prom_putsegment(ctx, vaddr, pseg);
646 fix_permissions(vaddr, _SUN4C_PAGE_PRIV, _SUN4C_PAGE_NOCACHE);
647 }
648 }
649
sun4c_init_lock_area(unsigned long start,unsigned long end)650 static void __init sun4c_init_lock_area(unsigned long start, unsigned long end)
651 {
652 int i, ctx;
653
654 while (start < end) {
655 for (i = 0; i < invalid_segment; i++)
656 if (!mmu_entry_pool[i].locked)
657 break;
658 mmu_entry_pool[i].locked = 1;
659 sun4c_init_clean_segmap(i);
660 for (ctx = 0; ctx < num_contexts; ctx++)
661 prom_putsegment(ctx, start, mmu_entry_pool[i].pseg);
662 start += SUN4C_REAL_PGDIR_SIZE;
663 }
664 }
665
666 /* Don't change this struct without changing entry.S. This is used
667 * in the in-window kernel fault handler, and you don't want to mess
668 * with that. (See sun4c_fault in entry.S).
669 */
670 struct sun4c_mmu_ring {
671 struct sun4c_mmu_entry ringhd;
672 int num_entries;
673 };
674
675 static struct sun4c_mmu_ring sun4c_context_ring[SUN4C_MAX_CONTEXTS]; /* used user entries */
676 static struct sun4c_mmu_ring sun4c_ufree_ring; /* free user entries */
677 static struct sun4c_mmu_ring sun4c_ulru_ring; /* LRU user entries */
678 struct sun4c_mmu_ring sun4c_kernel_ring; /* used kernel entries */
679 struct sun4c_mmu_ring sun4c_kfree_ring; /* free kernel entries */
680
sun4c_init_rings(void)681 static inline void sun4c_init_rings(void)
682 {
683 int i;
684
685 for (i = 0; i < SUN4C_MAX_CONTEXTS; i++) {
686 sun4c_context_ring[i].ringhd.next =
687 sun4c_context_ring[i].ringhd.prev =
688 &sun4c_context_ring[i].ringhd;
689 sun4c_context_ring[i].num_entries = 0;
690 }
691 sun4c_ufree_ring.ringhd.next = sun4c_ufree_ring.ringhd.prev =
692 &sun4c_ufree_ring.ringhd;
693 sun4c_ufree_ring.num_entries = 0;
694 sun4c_ulru_ring.ringhd.lru_next = sun4c_ulru_ring.ringhd.lru_prev =
695 &sun4c_ulru_ring.ringhd;
696 sun4c_ulru_ring.num_entries = 0;
697 sun4c_kernel_ring.ringhd.next = sun4c_kernel_ring.ringhd.prev =
698 &sun4c_kernel_ring.ringhd;
699 sun4c_kernel_ring.num_entries = 0;
700 sun4c_kfree_ring.ringhd.next = sun4c_kfree_ring.ringhd.prev =
701 &sun4c_kfree_ring.ringhd;
702 sun4c_kfree_ring.num_entries = 0;
703 }
704
add_ring(struct sun4c_mmu_ring * ring,struct sun4c_mmu_entry * entry)705 static void add_ring(struct sun4c_mmu_ring *ring,
706 struct sun4c_mmu_entry *entry)
707 {
708 struct sun4c_mmu_entry *head = &ring->ringhd;
709
710 entry->prev = head;
711 (entry->next = head->next)->prev = entry;
712 head->next = entry;
713 ring->num_entries++;
714 }
715
add_lru(struct sun4c_mmu_entry * entry)716 static __inline__ void add_lru(struct sun4c_mmu_entry *entry)
717 {
718 struct sun4c_mmu_ring *ring = &sun4c_ulru_ring;
719 struct sun4c_mmu_entry *head = &ring->ringhd;
720
721 entry->lru_next = head;
722 (entry->lru_prev = head->lru_prev)->lru_next = entry;
723 head->lru_prev = entry;
724 }
725
add_ring_ordered(struct sun4c_mmu_ring * ring,struct sun4c_mmu_entry * entry)726 static void add_ring_ordered(struct sun4c_mmu_ring *ring,
727 struct sun4c_mmu_entry *entry)
728 {
729 struct sun4c_mmu_entry *head = &ring->ringhd;
730 unsigned long addr = entry->vaddr;
731
732 while ((head->next != &ring->ringhd) && (head->next->vaddr < addr))
733 head = head->next;
734
735 entry->prev = head;
736 (entry->next = head->next)->prev = entry;
737 head->next = entry;
738 ring->num_entries++;
739
740 add_lru(entry);
741 }
742
remove_ring(struct sun4c_mmu_ring * ring,struct sun4c_mmu_entry * entry)743 static __inline__ void remove_ring(struct sun4c_mmu_ring *ring,
744 struct sun4c_mmu_entry *entry)
745 {
746 struct sun4c_mmu_entry *next = entry->next;
747
748 (next->prev = entry->prev)->next = next;
749 ring->num_entries--;
750 }
751
remove_lru(struct sun4c_mmu_entry * entry)752 static void remove_lru(struct sun4c_mmu_entry *entry)
753 {
754 struct sun4c_mmu_entry *next = entry->lru_next;
755
756 (next->lru_prev = entry->lru_prev)->lru_next = next;
757 }
758
free_user_entry(int ctx,struct sun4c_mmu_entry * entry)759 static void free_user_entry(int ctx, struct sun4c_mmu_entry *entry)
760 {
761 remove_ring(sun4c_context_ring+ctx, entry);
762 remove_lru(entry);
763 add_ring(&sun4c_ufree_ring, entry);
764 }
765
free_kernel_entry(struct sun4c_mmu_entry * entry,struct sun4c_mmu_ring * ring)766 static void free_kernel_entry(struct sun4c_mmu_entry *entry,
767 struct sun4c_mmu_ring *ring)
768 {
769 remove_ring(ring, entry);
770 add_ring(&sun4c_kfree_ring, entry);
771 }
772
sun4c_init_fill_kernel_ring(int howmany)773 static void __init sun4c_init_fill_kernel_ring(int howmany)
774 {
775 int i;
776
777 while (howmany) {
778 for (i = 0; i < invalid_segment; i++)
779 if (!mmu_entry_pool[i].locked)
780 break;
781 mmu_entry_pool[i].locked = 1;
782 sun4c_init_clean_segmap(i);
783 add_ring(&sun4c_kfree_ring, &mmu_entry_pool[i]);
784 howmany--;
785 }
786 }
787
sun4c_init_fill_user_ring(void)788 static void __init sun4c_init_fill_user_ring(void)
789 {
790 int i;
791
792 for (i = 0; i < invalid_segment; i++) {
793 if (mmu_entry_pool[i].locked)
794 continue;
795 sun4c_init_clean_segmap(i);
796 add_ring(&sun4c_ufree_ring, &mmu_entry_pool[i]);
797 }
798 }
799
sun4c_kernel_unmap(struct sun4c_mmu_entry * kentry)800 static void sun4c_kernel_unmap(struct sun4c_mmu_entry *kentry)
801 {
802 int savectx, ctx;
803
804 savectx = sun4c_get_context();
805 for (ctx = 0; ctx < num_contexts; ctx++) {
806 sun4c_set_context(ctx);
807 sun4c_put_segmap(kentry->vaddr, invalid_segment);
808 }
809 sun4c_set_context(savectx);
810 }
811
sun4c_kernel_map(struct sun4c_mmu_entry * kentry)812 static void sun4c_kernel_map(struct sun4c_mmu_entry *kentry)
813 {
814 int savectx, ctx;
815
816 savectx = sun4c_get_context();
817 for (ctx = 0; ctx < num_contexts; ctx++) {
818 sun4c_set_context(ctx);
819 sun4c_put_segmap(kentry->vaddr, kentry->pseg);
820 }
821 sun4c_set_context(savectx);
822 }
823
824 #define sun4c_user_unmap(__entry) \
825 sun4c_put_segmap((__entry)->vaddr, invalid_segment)
826
sun4c_demap_context(struct sun4c_mmu_ring * crp,unsigned char ctx)827 static void sun4c_demap_context(struct sun4c_mmu_ring *crp, unsigned char ctx)
828 {
829 struct sun4c_mmu_entry *head = &crp->ringhd;
830 unsigned long flags;
831
832 save_and_cli(flags);
833 if (head->next != head) {
834 struct sun4c_mmu_entry *entry = head->next;
835 int savectx = sun4c_get_context();
836
837 flush_user_windows();
838 sun4c_set_context(ctx);
839 sun4c_flush_context();
840 do {
841 struct sun4c_mmu_entry *next = entry->next;
842
843 sun4c_user_unmap(entry);
844 free_user_entry(ctx, entry);
845
846 entry = next;
847 } while (entry != head);
848 sun4c_set_context(savectx);
849 }
850 restore_flags(flags);
851 }
852
853 static int sun4c_user_taken_entries; /* This is how much we have. */
854 static int max_user_taken_entries; /* This limits us and prevents deadlock. */
855
sun4c_kernel_strategy(void)856 static struct sun4c_mmu_entry *sun4c_kernel_strategy(void)
857 {
858 struct sun4c_mmu_entry *this_entry;
859
860 /* If some are free, return first one. */
861 if (sun4c_kfree_ring.num_entries) {
862 this_entry = sun4c_kfree_ring.ringhd.next;
863 return this_entry;
864 }
865
866 /* Else free one up. */
867 this_entry = sun4c_kernel_ring.ringhd.prev;
868 sun4c_flush_segment(this_entry->vaddr);
869 sun4c_kernel_unmap(this_entry);
870 free_kernel_entry(this_entry, &sun4c_kernel_ring);
871 this_entry = sun4c_kfree_ring.ringhd.next;
872
873 return this_entry;
874 }
875
876 /* Using this method to free up mmu entries eliminates a lot of
877 * potential races since we have a kernel that incurs tlb
878 * replacement faults. There may be performance penalties.
879 *
880 * NOTE: Must be called with interrupts disabled.
881 */
sun4c_user_strategy(void)882 static struct sun4c_mmu_entry *sun4c_user_strategy(void)
883 {
884 struct sun4c_mmu_entry *entry;
885 unsigned char ctx;
886 int savectx;
887
888 /* If some are free, return first one. */
889 if (sun4c_ufree_ring.num_entries) {
890 entry = sun4c_ufree_ring.ringhd.next;
891 goto unlink_out;
892 }
893
894 if (sun4c_user_taken_entries) {
895 entry = sun4c_kernel_strategy();
896 sun4c_user_taken_entries--;
897 goto kunlink_out;
898 }
899
900 /* Grab from the beginning of the LRU list. */
901 entry = sun4c_ulru_ring.ringhd.lru_next;
902 ctx = entry->ctx;
903
904 savectx = sun4c_get_context();
905 flush_user_windows();
906 sun4c_set_context(ctx);
907 sun4c_flush_segment(entry->vaddr);
908 sun4c_user_unmap(entry);
909 remove_ring(sun4c_context_ring + ctx, entry);
910 remove_lru(entry);
911 sun4c_set_context(savectx);
912
913 return entry;
914
915 unlink_out:
916 remove_ring(&sun4c_ufree_ring, entry);
917 return entry;
918 kunlink_out:
919 remove_ring(&sun4c_kfree_ring, entry);
920 return entry;
921 }
922
923 /* NOTE: Must be called with interrupts disabled. */
sun4c_grow_kernel_ring(void)924 void sun4c_grow_kernel_ring(void)
925 {
926 struct sun4c_mmu_entry *entry;
927
928 /* Prevent deadlock condition. */
929 if (sun4c_user_taken_entries >= max_user_taken_entries)
930 return;
931
932 if (sun4c_ufree_ring.num_entries) {
933 entry = sun4c_ufree_ring.ringhd.next;
934 remove_ring(&sun4c_ufree_ring, entry);
935 add_ring(&sun4c_kfree_ring, entry);
936 sun4c_user_taken_entries++;
937 }
938 }
939
940 /* 2 page buckets for task struct and kernel stack allocation.
941 *
942 * TASK_STACK_BEGIN
943 * bucket[0]
944 * bucket[1]
945 * [ ... ]
946 * bucket[NR_TASK_BUCKETS-1]
947 * TASK_STACK_BEGIN + (sizeof(struct task_bucket) * NR_TASK_BUCKETS)
948 *
949 * Each slot looks like:
950 *
951 * page 1 -- task struct + beginning of kernel stack
952 * page 2 -- rest of kernel stack
953 */
954
955 union task_union *sun4c_bucket[NR_TASK_BUCKETS];
956
957 static int sun4c_lowbucket_avail;
958
959 #define BUCKET_EMPTY ((union task_union *) 0)
960 #define BUCKET_SHIFT (PAGE_SHIFT + 1) /* log2(sizeof(struct task_bucket)) */
961 #define BUCKET_SIZE (1 << BUCKET_SHIFT)
962 #define BUCKET_NUM(addr) ((((addr) - SUN4C_LOCK_VADDR) >> BUCKET_SHIFT))
963 #define BUCKET_ADDR(num) (((num) << BUCKET_SHIFT) + SUN4C_LOCK_VADDR)
964 #define BUCKET_PTE(page) \
965 ((((page) - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(SUN4C_PAGE_KERNEL))
966 #define BUCKET_PTE_PAGE(pte) \
967 (PAGE_OFFSET + (((pte) & SUN4C_PFN_MASK) << PAGE_SHIFT))
968
get_locked_segment(unsigned long addr)969 static void get_locked_segment(unsigned long addr)
970 {
971 struct sun4c_mmu_entry *stolen;
972 unsigned long flags;
973
974 save_and_cli(flags);
975 addr &= SUN4C_REAL_PGDIR_MASK;
976 stolen = sun4c_user_strategy();
977 max_user_taken_entries--;
978 stolen->vaddr = addr;
979 flush_user_windows();
980 sun4c_kernel_map(stolen);
981 restore_flags(flags);
982 }
983
free_locked_segment(unsigned long addr)984 static void free_locked_segment(unsigned long addr)
985 {
986 struct sun4c_mmu_entry *entry;
987 unsigned long flags;
988 unsigned char pseg;
989
990 save_and_cli(flags);
991 addr &= SUN4C_REAL_PGDIR_MASK;
992 pseg = sun4c_get_segmap(addr);
993 entry = &mmu_entry_pool[pseg];
994
995 flush_user_windows();
996 sun4c_flush_segment(addr);
997 sun4c_kernel_unmap(entry);
998 add_ring(&sun4c_ufree_ring, entry);
999 max_user_taken_entries++;
1000 restore_flags(flags);
1001 }
1002
garbage_collect(int entry)1003 static inline void garbage_collect(int entry)
1004 {
1005 int start, end;
1006
1007 /* 32 buckets per segment... */
1008 entry &= ~31;
1009 start = entry;
1010 for (end = (start + 32); start < end; start++)
1011 if (sun4c_bucket[start] != BUCKET_EMPTY)
1012 return;
1013
1014 /* Entire segment empty, release it. */
1015 free_locked_segment(BUCKET_ADDR(entry));
1016 }
1017
1018 #ifdef CONFIG_SUN4
1019 #define TASK_STRUCT_ORDER 0
1020 #else
1021 #define TASK_STRUCT_ORDER 1
1022 #endif
1023
sun4c_alloc_task_struct(void)1024 static struct task_struct *sun4c_alloc_task_struct(void)
1025 {
1026 unsigned long addr, pages;
1027 int entry;
1028
1029 pages = __get_free_pages(GFP_KERNEL, TASK_STRUCT_ORDER);
1030 if (!pages)
1031 return (struct task_struct *) 0;
1032
1033 for (entry = sun4c_lowbucket_avail; entry < NR_TASK_BUCKETS; entry++)
1034 if (sun4c_bucket[entry] == BUCKET_EMPTY)
1035 break;
1036 if (entry == NR_TASK_BUCKETS) {
1037 free_pages(pages, TASK_STRUCT_ORDER);
1038 return (struct task_struct *) 0;
1039 }
1040 if (entry >= sun4c_lowbucket_avail)
1041 sun4c_lowbucket_avail = entry + 1;
1042
1043 addr = BUCKET_ADDR(entry);
1044 sun4c_bucket[entry] = (union task_union *) addr;
1045 if(sun4c_get_segmap(addr) == invalid_segment)
1046 get_locked_segment(addr);
1047
1048 /* We are changing the virtual color of the page(s)
1049 * so we must flush the cache to guarentee consistancy.
1050 */
1051 sun4c_flush_page(pages);
1052 #ifndef CONFIG_SUN4
1053 sun4c_flush_page(pages + PAGE_SIZE);
1054 #endif
1055
1056 sun4c_put_pte(addr, BUCKET_PTE(pages));
1057 #ifndef CONFIG_SUN4
1058 sun4c_put_pte(addr + PAGE_SIZE, BUCKET_PTE(pages + PAGE_SIZE));
1059 #endif
1060 return (struct task_struct *) addr;
1061 }
1062
sun4c_free_task_struct(struct task_struct * tsk)1063 static void sun4c_free_task_struct(struct task_struct *tsk)
1064 {
1065 unsigned long tsaddr = (unsigned long) tsk;
1066 unsigned long pages = BUCKET_PTE_PAGE(sun4c_get_pte(tsaddr));
1067 int entry = BUCKET_NUM(tsaddr);
1068
1069 if (atomic_dec_and_test(&(tsk)->thread.refcount)) {
1070 /* We are deleting a mapping, so the flush here is mandatory. */
1071 sun4c_flush_page(tsaddr);
1072 #ifndef CONFIG_SUN4
1073 sun4c_flush_page(tsaddr + PAGE_SIZE);
1074 #endif
1075 sun4c_put_pte(tsaddr, 0);
1076 #ifndef CONFIG_SUN4
1077 sun4c_put_pte(tsaddr + PAGE_SIZE, 0);
1078 #endif
1079 sun4c_bucket[entry] = BUCKET_EMPTY;
1080 if (entry < sun4c_lowbucket_avail)
1081 sun4c_lowbucket_avail = entry;
1082
1083 free_pages(pages, TASK_STRUCT_ORDER);
1084 garbage_collect(entry);
1085 }
1086 }
1087
sun4c_get_task_struct(struct task_struct * tsk)1088 static void sun4c_get_task_struct(struct task_struct *tsk)
1089 {
1090 atomic_inc(&(tsk)->thread.refcount);
1091 }
1092
sun4c_init_buckets(void)1093 static void __init sun4c_init_buckets(void)
1094 {
1095 int entry;
1096
1097 if (sizeof(union task_union) != (PAGE_SIZE << TASK_STRUCT_ORDER)) {
1098 prom_printf("task union not %d page(s)!\n", 1 << TASK_STRUCT_ORDER);
1099 }
1100 for (entry = 0; entry < NR_TASK_BUCKETS; entry++)
1101 sun4c_bucket[entry] = BUCKET_EMPTY;
1102 sun4c_lowbucket_avail = 0;
1103 }
1104
1105 static unsigned long sun4c_iobuffer_start;
1106 static unsigned long sun4c_iobuffer_end;
1107 static unsigned long sun4c_iobuffer_high;
1108 static unsigned long *sun4c_iobuffer_map;
1109 static int iobuffer_map_size;
1110
1111 /*
1112 * Alias our pages so they do not cause a trap.
1113 * Also one page may be aliased into several I/O areas and we may
1114 * finish these I/O separately.
1115 */
sun4c_lockarea(char * vaddr,unsigned long size)1116 static char *sun4c_lockarea(char *vaddr, unsigned long size)
1117 {
1118 unsigned long base, scan;
1119 unsigned long npages;
1120 unsigned long vpage;
1121 unsigned long pte;
1122 unsigned long apage;
1123 unsigned long high;
1124 unsigned long flags;
1125
1126 npages = (((unsigned long)vaddr & ~PAGE_MASK) +
1127 size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
1128
1129 scan = 0;
1130 save_and_cli(flags);
1131 for (;;) {
1132 scan = find_next_zero_bit(sun4c_iobuffer_map,
1133 iobuffer_map_size, scan);
1134 if ((base = scan) + npages > iobuffer_map_size) goto abend;
1135 for (;;) {
1136 if (scan >= base + npages) goto found;
1137 if (test_bit(scan, sun4c_iobuffer_map)) break;
1138 scan++;
1139 }
1140 }
1141
1142 found:
1143 high = ((base + npages) << PAGE_SHIFT) + sun4c_iobuffer_start;
1144 high = SUN4C_REAL_PGDIR_ALIGN(high);
1145 while (high > sun4c_iobuffer_high) {
1146 get_locked_segment(sun4c_iobuffer_high);
1147 sun4c_iobuffer_high += SUN4C_REAL_PGDIR_SIZE;
1148 }
1149
1150 vpage = ((unsigned long) vaddr) & PAGE_MASK;
1151 for (scan = base; scan < base+npages; scan++) {
1152 pte = ((vpage-PAGE_OFFSET) >> PAGE_SHIFT);
1153 pte |= pgprot_val(SUN4C_PAGE_KERNEL);
1154 pte |= _SUN4C_PAGE_NOCACHE;
1155 set_bit(scan, sun4c_iobuffer_map);
1156 apage = (scan << PAGE_SHIFT) + sun4c_iobuffer_start;
1157
1158 /* Flush original mapping so we see the right things later. */
1159 sun4c_flush_page(vpage);
1160
1161 sun4c_put_pte(apage, pte);
1162 vpage += PAGE_SIZE;
1163 }
1164 restore_flags(flags);
1165 return (char *) ((base << PAGE_SHIFT) + sun4c_iobuffer_start +
1166 (((unsigned long) vaddr) & ~PAGE_MASK));
1167
1168 abend:
1169 restore_flags(flags);
1170 printk("DMA vaddr=0x%p size=%08lx\n", vaddr, size);
1171 panic("Out of iobuffer table");
1172 return 0;
1173 }
1174
sun4c_unlockarea(char * vaddr,unsigned long size)1175 static void sun4c_unlockarea(char *vaddr, unsigned long size)
1176 {
1177 unsigned long vpage, npages;
1178 unsigned long flags;
1179 int scan, high;
1180
1181 vpage = (unsigned long)vaddr & PAGE_MASK;
1182 npages = (((unsigned long)vaddr & ~PAGE_MASK) +
1183 size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
1184
1185 save_and_cli(flags);
1186 while (npages != 0) {
1187 --npages;
1188
1189 /* This mapping is marked non-cachable, no flush necessary. */
1190 sun4c_put_pte(vpage, 0);
1191 clear_bit((vpage - sun4c_iobuffer_start) >> PAGE_SHIFT,
1192 sun4c_iobuffer_map);
1193 vpage += PAGE_SIZE;
1194 }
1195
1196 /* garbage collect */
1197 scan = (sun4c_iobuffer_high - sun4c_iobuffer_start) >> PAGE_SHIFT;
1198 while (scan >= 0 && !sun4c_iobuffer_map[scan >> 5])
1199 scan -= 32;
1200 scan += 32;
1201 high = sun4c_iobuffer_start + (scan << PAGE_SHIFT);
1202 high = SUN4C_REAL_PGDIR_ALIGN(high) + SUN4C_REAL_PGDIR_SIZE;
1203 while (high < sun4c_iobuffer_high) {
1204 sun4c_iobuffer_high -= SUN4C_REAL_PGDIR_SIZE;
1205 free_locked_segment(sun4c_iobuffer_high);
1206 }
1207 restore_flags(flags);
1208 }
1209
1210 /* Note the scsi code at init time passes to here buffers
1211 * which sit on the kernel stack, those are already locked
1212 * by implication and fool the page locking code above
1213 * if passed to by mistake.
1214 */
sun4c_get_scsi_one(char * bufptr,unsigned long len,struct sbus_bus * sbus)1215 static __u32 sun4c_get_scsi_one(char *bufptr, unsigned long len, struct sbus_bus *sbus)
1216 {
1217 unsigned long page;
1218
1219 page = ((unsigned long)bufptr) & PAGE_MASK;
1220 if (!VALID_PAGE(virt_to_page(page))) {
1221 sun4c_flush_page(page);
1222 return (__u32)bufptr; /* already locked */
1223 }
1224 return (__u32)sun4c_lockarea(bufptr, len);
1225 }
1226
sun4c_get_scsi_sgl(struct scatterlist * sg,int sz,struct sbus_bus * sbus)1227 static void sun4c_get_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
1228 {
1229 while (sz != 0) {
1230 sz--;
1231 sg[sz].dvma_address = (__u32)sun4c_lockarea(sg[sz].address, sg[sz].length);
1232 sg[sz].dvma_length = sg[sz].length;
1233 }
1234 }
1235
sun4c_release_scsi_one(__u32 bufptr,unsigned long len,struct sbus_bus * sbus)1236 static void sun4c_release_scsi_one(__u32 bufptr, unsigned long len, struct sbus_bus *sbus)
1237 {
1238 if (bufptr < sun4c_iobuffer_start)
1239 return; /* On kernel stack or similar, see above */
1240 sun4c_unlockarea((char *)bufptr, len);
1241 }
1242
sun4c_release_scsi_sgl(struct scatterlist * sg,int sz,struct sbus_bus * sbus)1243 static void sun4c_release_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
1244 {
1245 while (sz != 0) {
1246 --sz;
1247 sun4c_unlockarea((char *)sg[sz].dvma_address, sg[sz].length);
1248 }
1249 }
1250
1251 #define TASK_ENTRY_SIZE BUCKET_SIZE /* see above */
1252 #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
1253
1254 struct vm_area_struct sun4c_kstack_vma;
1255
sun4c_init_lock_areas(void)1256 static void __init sun4c_init_lock_areas(void)
1257 {
1258 unsigned long sun4c_taskstack_start;
1259 unsigned long sun4c_taskstack_end;
1260 int bitmap_size;
1261
1262 sun4c_init_buckets();
1263 sun4c_taskstack_start = SUN4C_LOCK_VADDR;
1264 sun4c_taskstack_end = (sun4c_taskstack_start +
1265 (TASK_ENTRY_SIZE * NR_TASK_BUCKETS));
1266 if (sun4c_taskstack_end >= SUN4C_LOCK_END) {
1267 prom_printf("Too many tasks, decrease NR_TASK_BUCKETS please.\n");
1268 prom_halt();
1269 }
1270
1271 sun4c_iobuffer_start = sun4c_iobuffer_high =
1272 SUN4C_REAL_PGDIR_ALIGN(sun4c_taskstack_end);
1273 sun4c_iobuffer_end = SUN4C_LOCK_END;
1274 bitmap_size = (sun4c_iobuffer_end - sun4c_iobuffer_start) >> PAGE_SHIFT;
1275 bitmap_size = (bitmap_size + 7) >> 3;
1276 bitmap_size = LONG_ALIGN(bitmap_size);
1277 iobuffer_map_size = bitmap_size << 3;
1278 sun4c_iobuffer_map = __alloc_bootmem(bitmap_size, SMP_CACHE_BYTES, 0UL);
1279 memset((void *) sun4c_iobuffer_map, 0, bitmap_size);
1280
1281 sun4c_kstack_vma.vm_mm = &init_mm;
1282 sun4c_kstack_vma.vm_start = sun4c_taskstack_start;
1283 sun4c_kstack_vma.vm_end = sun4c_taskstack_end;
1284 sun4c_kstack_vma.vm_page_prot = PAGE_SHARED;
1285 sun4c_kstack_vma.vm_flags = VM_READ | VM_WRITE | VM_EXEC;
1286 insert_vm_struct(&init_mm, &sun4c_kstack_vma);
1287 }
1288
1289 /* Cache flushing on the sun4c. */
sun4c_flush_cache_all(void)1290 static void sun4c_flush_cache_all(void)
1291 {
1292 unsigned long begin, end;
1293
1294 flush_user_windows();
1295 begin = (KERNBASE + SUN4C_REAL_PGDIR_SIZE);
1296 end = (begin + SUN4C_VAC_SIZE);
1297
1298 if (sun4c_vacinfo.linesize == 32) {
1299 while (begin < end) {
1300 __asm__ __volatile__(
1301 "ld [%0 + 0x00], %%g0\n\t"
1302 "ld [%0 + 0x20], %%g0\n\t"
1303 "ld [%0 + 0x40], %%g0\n\t"
1304 "ld [%0 + 0x60], %%g0\n\t"
1305 "ld [%0 + 0x80], %%g0\n\t"
1306 "ld [%0 + 0xa0], %%g0\n\t"
1307 "ld [%0 + 0xc0], %%g0\n\t"
1308 "ld [%0 + 0xe0], %%g0\n\t"
1309 "ld [%0 + 0x100], %%g0\n\t"
1310 "ld [%0 + 0x120], %%g0\n\t"
1311 "ld [%0 + 0x140], %%g0\n\t"
1312 "ld [%0 + 0x160], %%g0\n\t"
1313 "ld [%0 + 0x180], %%g0\n\t"
1314 "ld [%0 + 0x1a0], %%g0\n\t"
1315 "ld [%0 + 0x1c0], %%g0\n\t"
1316 "ld [%0 + 0x1e0], %%g0\n"
1317 : : "r" (begin));
1318 begin += 512;
1319 }
1320 } else {
1321 while (begin < end) {
1322 __asm__ __volatile__(
1323 "ld [%0 + 0x00], %%g0\n\t"
1324 "ld [%0 + 0x10], %%g0\n\t"
1325 "ld [%0 + 0x20], %%g0\n\t"
1326 "ld [%0 + 0x30], %%g0\n\t"
1327 "ld [%0 + 0x40], %%g0\n\t"
1328 "ld [%0 + 0x50], %%g0\n\t"
1329 "ld [%0 + 0x60], %%g0\n\t"
1330 "ld [%0 + 0x70], %%g0\n\t"
1331 "ld [%0 + 0x80], %%g0\n\t"
1332 "ld [%0 + 0x90], %%g0\n\t"
1333 "ld [%0 + 0xa0], %%g0\n\t"
1334 "ld [%0 + 0xb0], %%g0\n\t"
1335 "ld [%0 + 0xc0], %%g0\n\t"
1336 "ld [%0 + 0xd0], %%g0\n\t"
1337 "ld [%0 + 0xe0], %%g0\n\t"
1338 "ld [%0 + 0xf0], %%g0\n"
1339 : : "r" (begin));
1340 begin += 256;
1341 }
1342 }
1343 }
1344
sun4c_flush_cache_mm(struct mm_struct * mm)1345 static void sun4c_flush_cache_mm(struct mm_struct *mm)
1346 {
1347 int new_ctx = mm->context;
1348
1349 if (new_ctx != NO_CONTEXT) {
1350 flush_user_windows();
1351
1352 if (sun4c_context_ring[new_ctx].num_entries) {
1353 struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
1354 unsigned long flags;
1355
1356 save_and_cli(flags);
1357 if (head->next != head) {
1358 struct sun4c_mmu_entry *entry = head->next;
1359 int savectx = sun4c_get_context();
1360
1361 sun4c_set_context(new_ctx);
1362 sun4c_flush_context();
1363 do {
1364 struct sun4c_mmu_entry *next = entry->next;
1365
1366 sun4c_user_unmap(entry);
1367 free_user_entry(new_ctx, entry);
1368
1369 entry = next;
1370 } while (entry != head);
1371 sun4c_set_context(savectx);
1372 }
1373 restore_flags(flags);
1374 }
1375 }
1376 }
1377
sun4c_flush_cache_range(struct mm_struct * mm,unsigned long start,unsigned long end)1378 static void sun4c_flush_cache_range(struct mm_struct *mm, unsigned long start, unsigned long end)
1379 {
1380 int new_ctx = mm->context;
1381
1382 if (new_ctx != NO_CONTEXT) {
1383 struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
1384 struct sun4c_mmu_entry *entry;
1385 unsigned long flags;
1386
1387 flush_user_windows();
1388
1389 save_and_cli(flags);
1390 /* All user segmap chains are ordered on entry->vaddr. */
1391 for (entry = head->next;
1392 (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
1393 entry = entry->next)
1394 ;
1395
1396 /* Tracing various job mixtures showed that this conditional
1397 * only passes ~35% of the time for most worse case situations,
1398 * therefore we avoid all of this gross overhead ~65% of the time.
1399 */
1400 if ((entry != head) && (entry->vaddr < end)) {
1401 int octx = sun4c_get_context();
1402 sun4c_set_context(new_ctx);
1403
1404 /* At this point, always, (start >= entry->vaddr) and
1405 * (entry->vaddr < end), once the latter condition
1406 * ceases to hold, or we hit the end of the list, we
1407 * exit the loop. The ordering of all user allocated
1408 * segmaps makes this all work out so beautifully.
1409 */
1410 do {
1411 struct sun4c_mmu_entry *next = entry->next;
1412 unsigned long realend;
1413
1414 /* "realstart" is always >= entry->vaddr */
1415 realend = entry->vaddr + SUN4C_REAL_PGDIR_SIZE;
1416 if (end < realend)
1417 realend = end;
1418 if ((realend - entry->vaddr) <= (PAGE_SIZE << 3)) {
1419 unsigned long page = entry->vaddr;
1420 while (page < realend) {
1421 sun4c_flush_page(page);
1422 page += PAGE_SIZE;
1423 }
1424 } else {
1425 sun4c_flush_segment(entry->vaddr);
1426 sun4c_user_unmap(entry);
1427 free_user_entry(new_ctx, entry);
1428 }
1429 entry = next;
1430 } while ((entry != head) && (entry->vaddr < end));
1431 sun4c_set_context(octx);
1432 }
1433 restore_flags(flags);
1434 }
1435 }
1436
sun4c_flush_cache_page(struct vm_area_struct * vma,unsigned long page)1437 static void sun4c_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
1438 {
1439 struct mm_struct *mm = vma->vm_mm;
1440 int new_ctx = mm->context;
1441
1442 /* Sun4c has no separate I/D caches so cannot optimize for non
1443 * text page flushes.
1444 */
1445 if (new_ctx != NO_CONTEXT) {
1446 int octx = sun4c_get_context();
1447 unsigned long flags;
1448
1449 flush_user_windows();
1450 save_and_cli(flags);
1451 sun4c_set_context(new_ctx);
1452 sun4c_flush_page(page);
1453 sun4c_set_context(octx);
1454 restore_flags(flags);
1455 }
1456 }
1457
sun4c_flush_page_to_ram(unsigned long page)1458 static void sun4c_flush_page_to_ram(unsigned long page)
1459 {
1460 unsigned long flags;
1461
1462 save_and_cli(flags);
1463 sun4c_flush_page(page);
1464 restore_flags(flags);
1465 }
1466
1467 /* Sun4c cache is unified, both instructions and data live there, so
1468 * no need to flush the on-stack instructions for new signal handlers.
1469 */
sun4c_flush_sig_insns(struct mm_struct * mm,unsigned long insn_addr)1470 static void sun4c_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
1471 {
1472 }
1473
1474 /* TLB flushing on the sun4c. These routines count on the cache
1475 * flushing code to flush the user register windows so that we need
1476 * not do so when we get here.
1477 */
1478
sun4c_flush_tlb_all(void)1479 static void sun4c_flush_tlb_all(void)
1480 {
1481 struct sun4c_mmu_entry *this_entry, *next_entry;
1482 unsigned long flags;
1483 int savectx, ctx;
1484
1485 save_and_cli(flags);
1486 this_entry = sun4c_kernel_ring.ringhd.next;
1487 savectx = sun4c_get_context();
1488 flush_user_windows();
1489 while (sun4c_kernel_ring.num_entries) {
1490 next_entry = this_entry->next;
1491 sun4c_flush_segment(this_entry->vaddr);
1492 for (ctx = 0; ctx < num_contexts; ctx++) {
1493 sun4c_set_context(ctx);
1494 sun4c_put_segmap(this_entry->vaddr, invalid_segment);
1495 }
1496 free_kernel_entry(this_entry, &sun4c_kernel_ring);
1497 this_entry = next_entry;
1498 }
1499 sun4c_set_context(savectx);
1500 restore_flags(flags);
1501 }
1502
sun4c_flush_tlb_mm(struct mm_struct * mm)1503 static void sun4c_flush_tlb_mm(struct mm_struct *mm)
1504 {
1505 int new_ctx = mm->context;
1506
1507 if (new_ctx != NO_CONTEXT) {
1508 struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
1509 unsigned long flags;
1510
1511 save_and_cli(flags);
1512 if (head->next != head) {
1513 struct sun4c_mmu_entry *entry = head->next;
1514 int savectx = sun4c_get_context();
1515
1516 sun4c_set_context(new_ctx);
1517 sun4c_flush_context();
1518 do {
1519 struct sun4c_mmu_entry *next = entry->next;
1520
1521 sun4c_user_unmap(entry);
1522 free_user_entry(new_ctx, entry);
1523
1524 entry = next;
1525 } while (entry != head);
1526 sun4c_set_context(savectx);
1527 }
1528 restore_flags(flags);
1529 }
1530 }
1531
sun4c_flush_tlb_range(struct mm_struct * mm,unsigned long start,unsigned long end)1532 static void sun4c_flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end)
1533 {
1534 int new_ctx = mm->context;
1535
1536 if (new_ctx != NO_CONTEXT) {
1537 struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
1538 struct sun4c_mmu_entry *entry;
1539 unsigned long flags;
1540
1541 save_and_cli(flags);
1542 /* See commentary in sun4c_flush_cache_range(). */
1543 for (entry = head->next;
1544 (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
1545 entry = entry->next)
1546 ;
1547
1548 if ((entry != head) && (entry->vaddr < end)) {
1549 int octx = sun4c_get_context();
1550
1551 sun4c_set_context(new_ctx);
1552 do {
1553 struct sun4c_mmu_entry *next = entry->next;
1554
1555 sun4c_flush_segment(entry->vaddr);
1556 sun4c_user_unmap(entry);
1557 free_user_entry(new_ctx, entry);
1558
1559 entry = next;
1560 } while ((entry != head) && (entry->vaddr < end));
1561 sun4c_set_context(octx);
1562 }
1563 restore_flags(flags);
1564 }
1565 }
1566
sun4c_flush_tlb_page(struct vm_area_struct * vma,unsigned long page)1567 static void sun4c_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
1568 {
1569 struct mm_struct *mm = vma->vm_mm;
1570 int new_ctx = mm->context;
1571
1572 if (new_ctx != NO_CONTEXT) {
1573 int savectx = sun4c_get_context();
1574 unsigned long flags;
1575
1576 save_and_cli(flags);
1577 sun4c_set_context(new_ctx);
1578 page &= PAGE_MASK;
1579 sun4c_flush_page(page);
1580 sun4c_put_pte(page, 0);
1581 sun4c_set_context(savectx);
1582 restore_flags(flags);
1583 }
1584 }
1585
sun4c_mapioaddr(unsigned long physaddr,unsigned long virt_addr,int bus_type,int rdonly)1586 void sun4c_mapioaddr(unsigned long physaddr, unsigned long virt_addr,
1587 int bus_type, int rdonly)
1588 {
1589 unsigned long page_entry;
1590
1591 page_entry = ((physaddr >> PAGE_SHIFT) & SUN4C_PFN_MASK);
1592 page_entry |= ((pg_iobits | _SUN4C_PAGE_PRIV) & ~(_SUN4C_PAGE_PRESENT));
1593 if (rdonly)
1594 page_entry &= ~_SUN4C_WRITEABLE;
1595 sun4c_put_pte(virt_addr, page_entry);
1596 }
1597
sun4c_unmapioaddr(unsigned long virt_addr)1598 void sun4c_unmapioaddr(unsigned long virt_addr)
1599 {
1600 sun4c_put_pte(virt_addr, 0);
1601 }
1602
sun4c_alloc_context(struct mm_struct * old_mm,struct mm_struct * mm)1603 static void sun4c_alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
1604 {
1605 struct ctx_list *ctxp;
1606
1607 ctxp = ctx_free.next;
1608 if (ctxp != &ctx_free) {
1609 remove_from_ctx_list(ctxp);
1610 add_to_used_ctxlist(ctxp);
1611 mm->context = ctxp->ctx_number;
1612 ctxp->ctx_mm = mm;
1613 return;
1614 }
1615 ctxp = ctx_used.next;
1616 if (ctxp->ctx_mm == old_mm)
1617 ctxp = ctxp->next;
1618 remove_from_ctx_list(ctxp);
1619 add_to_used_ctxlist(ctxp);
1620 ctxp->ctx_mm->context = NO_CONTEXT;
1621 ctxp->ctx_mm = mm;
1622 mm->context = ctxp->ctx_number;
1623 sun4c_demap_context(&sun4c_context_ring[ctxp->ctx_number],
1624 ctxp->ctx_number);
1625 }
1626
1627 /* Switch the current MM context. */
sun4c_switch_mm(struct mm_struct * old_mm,struct mm_struct * mm,struct task_struct * tsk,int cpu)1628 static void sun4c_switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk, int cpu)
1629 {
1630 struct ctx_list *ctx;
1631 int dirty = 0;
1632
1633 if (mm->context == NO_CONTEXT) {
1634 dirty = 1;
1635 sun4c_alloc_context(old_mm, mm);
1636 } else {
1637 /* Update the LRU ring of contexts. */
1638 ctx = ctx_list_pool + mm->context;
1639 remove_from_ctx_list(ctx);
1640 add_to_used_ctxlist(ctx);
1641 }
1642 if (dirty || old_mm != mm)
1643 sun4c_set_context(mm->context);
1644 }
1645
sun4c_destroy_context(struct mm_struct * mm)1646 static void sun4c_destroy_context(struct mm_struct *mm)
1647 {
1648 struct ctx_list *ctx_old;
1649
1650 if (mm->context != NO_CONTEXT) {
1651 sun4c_demap_context(&sun4c_context_ring[mm->context], mm->context);
1652 ctx_old = ctx_list_pool + mm->context;
1653 remove_from_ctx_list(ctx_old);
1654 add_to_free_ctxlist(ctx_old);
1655 mm->context = NO_CONTEXT;
1656 }
1657 }
1658
sun4c_mmu_info(struct seq_file * m)1659 static void sun4c_mmu_info(struct seq_file *m)
1660 {
1661 int used_user_entries, i;
1662
1663 used_user_entries = 0;
1664 for (i = 0; i < num_contexts; i++)
1665 used_user_entries += sun4c_context_ring[i].num_entries;
1666
1667 seq_printf(m,
1668 "vacsize\t\t: %d bytes\n"
1669 "vachwflush\t: %s\n"
1670 "vaclinesize\t: %d bytes\n"
1671 "mmuctxs\t\t: %d\n"
1672 "mmupsegs\t: %d\n"
1673 "kernelpsegs\t: %d\n"
1674 "kfreepsegs\t: %d\n"
1675 "usedpsegs\t: %d\n"
1676 "ufreepsegs\t: %d\n"
1677 "user_taken\t: %d\n"
1678 "max_taken\t: %d\n",
1679 sun4c_vacinfo.num_bytes,
1680 (sun4c_vacinfo.do_hwflushes ? "yes" : "no"),
1681 sun4c_vacinfo.linesize,
1682 num_contexts,
1683 (invalid_segment + 1),
1684 sun4c_kernel_ring.num_entries,
1685 sun4c_kfree_ring.num_entries,
1686 used_user_entries,
1687 sun4c_ufree_ring.num_entries,
1688 sun4c_user_taken_entries,
1689 max_user_taken_entries);
1690 }
1691
1692 /* Nothing below here should touch the mmu hardware nor the mmu_entry
1693 * data structures.
1694 */
1695
1696 /* First the functions which the mid-level code uses to directly
1697 * manipulate the software page tables. Some defines since we are
1698 * emulating the i386 page directory layout.
1699 */
1700 #define PGD_PRESENT 0x001
1701 #define PGD_RW 0x002
1702 #define PGD_USER 0x004
1703 #define PGD_ACCESSED 0x020
1704 #define PGD_DIRTY 0x040
1705 #define PGD_TABLE (PGD_PRESENT | PGD_RW | PGD_USER | PGD_ACCESSED | PGD_DIRTY)
1706
sun4c_set_pte(pte_t * ptep,pte_t pte)1707 static void sun4c_set_pte(pte_t *ptep, pte_t pte)
1708 {
1709 *ptep = pte;
1710 }
1711
sun4c_pgd_set(pgd_t * pgdp,pmd_t * pmdp)1712 static void sun4c_pgd_set(pgd_t * pgdp, pmd_t * pmdp)
1713 {
1714 }
1715
sun4c_pmd_set(pmd_t * pmdp,pte_t * ptep)1716 static void sun4c_pmd_set(pmd_t * pmdp, pte_t * ptep)
1717 {
1718 *pmdp = __pmd(PGD_TABLE | (unsigned long) ptep);
1719 }
1720
sun4c_pte_present(pte_t pte)1721 static int sun4c_pte_present(pte_t pte)
1722 {
1723 return ((pte_val(pte) & (_SUN4C_PAGE_PRESENT | _SUN4C_PAGE_PRIV)) != 0);
1724 }
sun4c_pte_clear(pte_t * ptep)1725 static void sun4c_pte_clear(pte_t *ptep) { *ptep = __pte(0); }
1726
sun4c_pmd_bad(pmd_t pmd)1727 static int sun4c_pmd_bad(pmd_t pmd)
1728 {
1729 return (((pmd_val(pmd) & ~PAGE_MASK) != PGD_TABLE) ||
1730 (!VALID_PAGE(virt_to_page(pmd_val(pmd)))));
1731 }
1732
sun4c_pmd_present(pmd_t pmd)1733 static int sun4c_pmd_present(pmd_t pmd)
1734 {
1735 return ((pmd_val(pmd) & PGD_PRESENT) != 0);
1736 }
sun4c_pmd_clear(pmd_t * pmdp)1737 static void sun4c_pmd_clear(pmd_t *pmdp) { *pmdp = __pmd(0); }
1738
sun4c_pgd_none(pgd_t pgd)1739 static int sun4c_pgd_none(pgd_t pgd) { return 0; }
sun4c_pgd_bad(pgd_t pgd)1740 static int sun4c_pgd_bad(pgd_t pgd) { return 0; }
sun4c_pgd_present(pgd_t pgd)1741 static int sun4c_pgd_present(pgd_t pgd) { return 1; }
sun4c_pgd_clear(pgd_t * pgdp)1742 static void sun4c_pgd_clear(pgd_t * pgdp) { }
1743
1744 /*
1745 * The following only work if pte_present() is true.
1746 * Undefined behaviour if not..
1747 */
sun4c_pte_mkwrite(pte_t pte)1748 static pte_t sun4c_pte_mkwrite(pte_t pte)
1749 {
1750 pte = __pte(pte_val(pte) | _SUN4C_PAGE_WRITE);
1751 if (pte_val(pte) & _SUN4C_PAGE_MODIFIED)
1752 pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
1753 return pte;
1754 }
1755
sun4c_pte_mkdirty(pte_t pte)1756 static pte_t sun4c_pte_mkdirty(pte_t pte)
1757 {
1758 pte = __pte(pte_val(pte) | _SUN4C_PAGE_MODIFIED);
1759 if (pte_val(pte) & _SUN4C_PAGE_WRITE)
1760 pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
1761 return pte;
1762 }
1763
sun4c_pte_mkyoung(pte_t pte)1764 static pte_t sun4c_pte_mkyoung(pte_t pte)
1765 {
1766 pte = __pte(pte_val(pte) | _SUN4C_PAGE_ACCESSED);
1767 if (pte_val(pte) & _SUN4C_PAGE_READ)
1768 pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_READ);
1769 return pte;
1770 }
1771
1772 /*
1773 * Conversion functions: convert a page and protection to a page entry,
1774 * and a page entry and page directory to the page they refer to.
1775 */
sun4c_mk_pte(struct page * page,pgprot_t pgprot)1776 static pte_t sun4c_mk_pte(struct page *page, pgprot_t pgprot)
1777 {
1778 return __pte((page - mem_map) | pgprot_val(pgprot));
1779 }
1780
sun4c_mk_pte_phys(unsigned long phys_page,pgprot_t pgprot)1781 static pte_t sun4c_mk_pte_phys(unsigned long phys_page, pgprot_t pgprot)
1782 {
1783 return __pte((phys_page >> PAGE_SHIFT) | pgprot_val(pgprot));
1784 }
1785
sun4c_mk_pte_io(unsigned long page,pgprot_t pgprot,int space)1786 static pte_t sun4c_mk_pte_io(unsigned long page, pgprot_t pgprot, int space)
1787 {
1788 return __pte(((page - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(pgprot));
1789 }
1790
sun4c_pte_page(pte_t pte)1791 static struct page *sun4c_pte_page(pte_t pte)
1792 {
1793 return (mem_map + (unsigned long)(pte_val(pte) & SUN4C_PFN_MASK));
1794 }
1795
sun4c_pmd_page(pmd_t pmd)1796 static inline unsigned long sun4c_pmd_page(pmd_t pmd)
1797 {
1798 return (pmd_val(pmd) & PAGE_MASK);
1799 }
1800
sun4c_pgd_page(pgd_t pgd)1801 static unsigned long sun4c_pgd_page(pgd_t pgd) { return 0; }
1802
1803 /* to find an entry in a page-table-directory */
sun4c_pgd_offset(struct mm_struct * mm,unsigned long address)1804 static inline pgd_t *sun4c_pgd_offset(struct mm_struct * mm, unsigned long address)
1805 {
1806 return mm->pgd + (address >> SUN4C_PGDIR_SHIFT);
1807 }
1808
1809 /* Find an entry in the second-level page table.. */
sun4c_pmd_offset(pgd_t * dir,unsigned long address)1810 static pmd_t *sun4c_pmd_offset(pgd_t * dir, unsigned long address)
1811 {
1812 return (pmd_t *) dir;
1813 }
1814
1815 /* Find an entry in the third-level page table.. */
sun4c_pte_offset(pmd_t * dir,unsigned long address)1816 pte_t *sun4c_pte_offset(pmd_t * dir, unsigned long address)
1817 {
1818 return (pte_t *) sun4c_pmd_page(*dir) + ((address >> PAGE_SHIFT) & (SUN4C_PTRS_PER_PTE - 1));
1819 }
1820
sun4c_free_pte_slow(pte_t * pte)1821 static void sun4c_free_pte_slow(pte_t *pte)
1822 {
1823 free_page((unsigned long)pte);
1824 }
1825
sun4c_free_pgd_slow(pgd_t * pgd)1826 static void sun4c_free_pgd_slow(pgd_t *pgd)
1827 {
1828 free_page((unsigned long)pgd);
1829 }
1830
sun4c_get_pgd_fast(void)1831 static pgd_t *sun4c_get_pgd_fast(void)
1832 {
1833 unsigned long *ret;
1834
1835 if ((ret = pgd_quicklist) != NULL) {
1836 pgd_quicklist = (unsigned long *)(*ret);
1837 ret[0] = ret[1];
1838 pgtable_cache_size--;
1839 } else {
1840 pgd_t *init;
1841
1842 ret = (unsigned long *)__get_free_page(GFP_KERNEL);
1843 memset (ret, 0, (KERNBASE / SUN4C_PGDIR_SIZE) * sizeof(pgd_t));
1844 init = sun4c_pgd_offset(&init_mm, 0);
1845 memcpy (((pgd_t *)ret) + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
1846 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
1847 }
1848 return (pgd_t *)ret;
1849 }
1850
sun4c_free_pgd_fast(pgd_t * pgd)1851 static void sun4c_free_pgd_fast(pgd_t *pgd)
1852 {
1853 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
1854 pgd_quicklist = (unsigned long *) pgd;
1855 pgtable_cache_size++;
1856 }
1857
sun4c_pte_alloc_one(struct mm_struct * mm,unsigned long address)1858 static pte_t *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
1859 {
1860 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL);
1861 if (pte)
1862 memset(pte, 0, PAGE_SIZE);
1863 return pte;
1864 }
1865
sun4c_pte_alloc_one_fast(struct mm_struct * mm,unsigned long address)1866 pte_t *sun4c_pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
1867 {
1868 unsigned long *ret;
1869
1870 if ((ret = (unsigned long *)pte_quicklist) != NULL) {
1871 pte_quicklist = (unsigned long *)(*ret);
1872 ret[0] = ret[1];
1873 pgtable_cache_size--;
1874 }
1875 return (pte_t *)ret;
1876 }
1877
sun4c_free_pte_fast(pte_t * pte)1878 static __inline__ void sun4c_free_pte_fast(pte_t *pte)
1879 {
1880 *(unsigned long *)pte = (unsigned long) pte_quicklist;
1881 pte_quicklist = (unsigned long *) pte;
1882 pgtable_cache_size++;
1883 }
1884
1885 /*
1886 * allocating and freeing a pmd is trivial: the 1-entry pmd is
1887 * inside the pgd, so has no extra memory associated with it.
1888 */
sun4c_pmd_alloc_one_fast(struct mm_struct * mm,unsigned long address)1889 static pmd_t *sun4c_pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
1890 {
1891 BUG();
1892 return NULL;
1893 }
1894
sun4c_free_pmd_fast(pmd_t * pmd)1895 static void sun4c_free_pmd_fast(pmd_t * pmd) { }
1896
sun4c_check_pgt_cache(int low,int high)1897 static int sun4c_check_pgt_cache(int low, int high)
1898 {
1899 int freed = 0;
1900 if (pgtable_cache_size > high) {
1901 do {
1902 if (pgd_quicklist)
1903 sun4c_free_pgd_slow(sun4c_get_pgd_fast()), freed++;
1904 if (pte_quicklist)
1905 sun4c_free_pte_slow(sun4c_pte_alloc_one_fast(NULL, 0)), freed++;
1906 } while (pgtable_cache_size > low);
1907 }
1908 return freed;
1909 }
1910
1911 /* An experiment, turn off by default for now... -DaveM */
1912 #define SUN4C_PRELOAD_PSEG
1913
sun4c_update_mmu_cache(struct vm_area_struct * vma,unsigned long address,pte_t pte)1914 void sun4c_update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
1915 {
1916 unsigned long flags;
1917 int pseg;
1918
1919 save_and_cli(flags);
1920 address &= PAGE_MASK;
1921 if ((pseg = sun4c_get_segmap(address)) == invalid_segment) {
1922 struct sun4c_mmu_entry *entry = sun4c_user_strategy();
1923 struct mm_struct *mm = vma->vm_mm;
1924 unsigned long start, end;
1925
1926 entry->vaddr = start = (address & SUN4C_REAL_PGDIR_MASK);
1927 entry->ctx = mm->context;
1928 add_ring_ordered(sun4c_context_ring + mm->context, entry);
1929 sun4c_put_segmap(entry->vaddr, entry->pseg);
1930 end = start + SUN4C_REAL_PGDIR_SIZE;
1931 while (start < end) {
1932 #ifdef SUN4C_PRELOAD_PSEG
1933 pgd_t *pgdp = sun4c_pgd_offset(mm, start);
1934 pte_t *ptep;
1935
1936 if (!pgdp)
1937 goto no_mapping;
1938 ptep = sun4c_pte_offset((pmd_t *) pgdp, start);
1939 if (!ptep || !(pte_val(*ptep) & _SUN4C_PAGE_PRESENT))
1940 goto no_mapping;
1941 sun4c_put_pte(start, pte_val(*ptep));
1942 goto next;
1943
1944 no_mapping:
1945 #endif
1946 sun4c_put_pte(start, 0);
1947 #ifdef SUN4C_PRELOAD_PSEG
1948 next:
1949 #endif
1950 start += PAGE_SIZE;
1951 }
1952 #ifndef SUN4C_PRELOAD_PSEG
1953 sun4c_put_pte(address, pte_val(pte));
1954 #endif
1955 restore_flags(flags);
1956 return;
1957 } else {
1958 struct sun4c_mmu_entry *entry = &mmu_entry_pool[pseg];
1959
1960 remove_lru(entry);
1961 add_lru(entry);
1962 }
1963
1964 sun4c_put_pte(address, pte_val(pte));
1965 restore_flags(flags);
1966 }
1967
1968 extern void sparc_context_init(int);
1969 extern unsigned long end;
1970 extern unsigned long bootmem_init(unsigned long *pages_avail);
1971 extern unsigned long last_valid_pfn;
1972 extern void sun_serial_setup(void);
1973
1974 extern unsigned long fix_kmap_begin;
1975 extern unsigned long fix_kmap_end;
1976
sun4c_paging_init(void)1977 void __init sun4c_paging_init(void)
1978 {
1979 int i, cnt;
1980 unsigned long kernel_end, vaddr;
1981 extern struct resource sparc_iomap;
1982 unsigned long end_pfn, pages_avail;
1983
1984 fix_kmap_begin = KERNBASE + SRMMU_MAXMEM; /* Why bother with SRMMU_MAXMEM? */
1985 fix_kmap_end = fix_kmap_begin + ((KM_TYPE_NR*NR_CPUS)-1)*PAGE_SIZE;
1986
1987 kernel_end = (unsigned long) &end;
1988 kernel_end += (SUN4C_REAL_PGDIR_SIZE * 4);
1989 kernel_end = SUN4C_REAL_PGDIR_ALIGN(kernel_end);
1990
1991 pages_avail = 0;
1992 last_valid_pfn = bootmem_init(&pages_avail);
1993 end_pfn = last_valid_pfn;
1994
1995 /* This does not logically belong here, but we need to
1996 * call it at the moment we are able to use the bootmem
1997 * allocator.
1998 */
1999 sun_serial_setup();
2000
2001 sun4c_probe_mmu();
2002 invalid_segment = (num_segmaps - 1);
2003 sun4c_init_mmu_entry_pool();
2004 sun4c_init_rings();
2005 sun4c_init_map_kernelprom(kernel_end);
2006 sun4c_init_clean_mmu(kernel_end);
2007 sun4c_init_fill_kernel_ring(SUN4C_KERNEL_BUCKETS);
2008 sun4c_init_lock_area(sparc_iomap.start, IOBASE_END);
2009 sun4c_init_lock_area(DVMA_VADDR, DVMA_END);
2010 sun4c_init_lock_areas();
2011 sun4c_init_fill_user_ring();
2012
2013 sun4c_set_context(0);
2014 memset(swapper_pg_dir, 0, PAGE_SIZE);
2015 memset(pg0, 0, PAGE_SIZE);
2016 memset(pg1, 0, PAGE_SIZE);
2017 memset(pg2, 0, PAGE_SIZE);
2018 memset(pg3, 0, PAGE_SIZE);
2019
2020 /* Save work later. */
2021 vaddr = VMALLOC_START;
2022 swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg0);
2023 vaddr += SUN4C_PGDIR_SIZE;
2024 swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg1);
2025 vaddr += SUN4C_PGDIR_SIZE;
2026 swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg2);
2027 vaddr += SUN4C_PGDIR_SIZE;
2028 swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg3);
2029 sun4c_init_ss2_cache_bug();
2030 sparc_context_init(num_contexts);
2031
2032 {
2033 unsigned long zones_size[MAX_NR_ZONES];
2034 unsigned long zholes_size[MAX_NR_ZONES];
2035 unsigned long npages;
2036 int znum;
2037
2038 for (znum = 0; znum < MAX_NR_ZONES; znum++)
2039 zones_size[znum] = zholes_size[znum] = 0;
2040
2041 npages = max_low_pfn - (phys_base >> PAGE_SHIFT);
2042
2043 zones_size[ZONE_DMA] = npages;
2044 zholes_size[ZONE_DMA] = npages - pages_avail;
2045
2046 npages = highend_pfn - max_low_pfn;
2047 zones_size[ZONE_HIGHMEM] = npages;
2048 zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
2049
2050 free_area_init_node(0, NULL, NULL, zones_size,
2051 phys_base, zholes_size);
2052 }
2053
2054 cnt = 0;
2055 for (i = 0; i < num_segmaps; i++)
2056 if (mmu_entry_pool[i].locked)
2057 cnt++;
2058
2059 max_user_taken_entries = num_segmaps - cnt - 40 - 1;
2060
2061 printk("SUN4C: %d mmu entries for the kernel\n", cnt);
2062 }
2063
2064 /* Load up routines and constants for sun4c mmu */
ld_mmu_sun4c(void)2065 void __init ld_mmu_sun4c(void)
2066 {
2067 extern void ___xchg32_sun4c(void);
2068
2069 printk("Loading sun4c MMU routines\n");
2070
2071 /* First the constants */
2072 BTFIXUPSET_SIMM13(pmd_shift, SUN4C_PMD_SHIFT);
2073 BTFIXUPSET_SETHI(pmd_size, SUN4C_PMD_SIZE);
2074 BTFIXUPSET_SETHI(pmd_mask, SUN4C_PMD_MASK);
2075 BTFIXUPSET_SIMM13(pgdir_shift, SUN4C_PGDIR_SHIFT);
2076 BTFIXUPSET_SETHI(pgdir_size, SUN4C_PGDIR_SIZE);
2077 BTFIXUPSET_SETHI(pgdir_mask, SUN4C_PGDIR_MASK);
2078
2079 BTFIXUPSET_SIMM13(ptrs_per_pte, SUN4C_PTRS_PER_PTE);
2080 BTFIXUPSET_SIMM13(ptrs_per_pmd, SUN4C_PTRS_PER_PMD);
2081 BTFIXUPSET_SIMM13(ptrs_per_pgd, SUN4C_PTRS_PER_PGD);
2082 BTFIXUPSET_SIMM13(user_ptrs_per_pgd, KERNBASE / SUN4C_PGDIR_SIZE);
2083
2084 BTFIXUPSET_INT(page_none, pgprot_val(SUN4C_PAGE_NONE));
2085 BTFIXUPSET_INT(page_shared, pgprot_val(SUN4C_PAGE_SHARED));
2086 BTFIXUPSET_INT(page_copy, pgprot_val(SUN4C_PAGE_COPY));
2087 BTFIXUPSET_INT(page_readonly, pgprot_val(SUN4C_PAGE_READONLY));
2088 BTFIXUPSET_INT(page_kernel, pgprot_val(SUN4C_PAGE_KERNEL));
2089 page_kernel = pgprot_val(SUN4C_PAGE_KERNEL);
2090 pg_iobits = _SUN4C_PAGE_PRESENT | _SUN4C_READABLE | _SUN4C_WRITEABLE |
2091 _SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE;
2092
2093 /* Functions */
2094 BTFIXUPSET_CALL(___xchg32, ___xchg32_sun4c, BTFIXUPCALL_NORM);
2095 BTFIXUPSET_CALL(do_check_pgt_cache, sun4c_check_pgt_cache, BTFIXUPCALL_NORM);
2096
2097 BTFIXUPSET_CALL(flush_cache_all, sun4c_flush_cache_all, BTFIXUPCALL_NORM);
2098
2099 if (sun4c_vacinfo.do_hwflushes) {
2100 BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_hw, BTFIXUPCALL_NORM);
2101 BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_hw, BTFIXUPCALL_NORM);
2102 BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_hw, BTFIXUPCALL_NORM);
2103 } else {
2104 BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_sw, BTFIXUPCALL_NORM);
2105 BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_sw, BTFIXUPCALL_NORM);
2106 BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_sw, BTFIXUPCALL_NORM);
2107 }
2108
2109 BTFIXUPSET_CALL(flush_tlb_mm, sun4c_flush_tlb_mm, BTFIXUPCALL_NORM);
2110 BTFIXUPSET_CALL(flush_cache_mm, sun4c_flush_cache_mm, BTFIXUPCALL_NORM);
2111 BTFIXUPSET_CALL(destroy_context, sun4c_destroy_context, BTFIXUPCALL_NORM);
2112 BTFIXUPSET_CALL(switch_mm, sun4c_switch_mm, BTFIXUPCALL_NORM);
2113 BTFIXUPSET_CALL(flush_cache_page, sun4c_flush_cache_page, BTFIXUPCALL_NORM);
2114 BTFIXUPSET_CALL(flush_tlb_page, sun4c_flush_tlb_page, BTFIXUPCALL_NORM);
2115 BTFIXUPSET_CALL(flush_tlb_range, sun4c_flush_tlb_range, BTFIXUPCALL_NORM);
2116 BTFIXUPSET_CALL(flush_cache_range, sun4c_flush_cache_range, BTFIXUPCALL_NORM);
2117 BTFIXUPSET_CALL(free_task_struct, sun4c_free_task_struct, BTFIXUPCALL_NORM);
2118 BTFIXUPSET_CALL(__flush_page_to_ram, sun4c_flush_page_to_ram, BTFIXUPCALL_NORM);
2119 BTFIXUPSET_CALL(flush_tlb_all, sun4c_flush_tlb_all, BTFIXUPCALL_NORM);
2120
2121 BTFIXUPSET_CALL(flush_sig_insns, sun4c_flush_sig_insns, BTFIXUPCALL_NOP);
2122
2123 BTFIXUPSET_CALL(set_pte, sun4c_set_pte, BTFIXUPCALL_STO1O0);
2124
2125 BTFIXUPSET_CALL(pte_page, sun4c_pte_page, BTFIXUPCALL_NORM);
2126 #if PAGE_SHIFT <= 12
2127 BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_ANDNINT(PAGE_SIZE - 1));
2128 #else
2129 BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_NORM);
2130 #endif
2131 BTFIXUPSET_CALL(pmd_set, sun4c_pmd_set, BTFIXUPCALL_NORM);
2132
2133 BTFIXUPSET_CALL(pte_present, sun4c_pte_present, BTFIXUPCALL_NORM);
2134 BTFIXUPSET_CALL(pte_clear, sun4c_pte_clear, BTFIXUPCALL_STG0O0);
2135
2136 BTFIXUPSET_CALL(pmd_bad, sun4c_pmd_bad, BTFIXUPCALL_NORM);
2137 BTFIXUPSET_CALL(pmd_present, sun4c_pmd_present, BTFIXUPCALL_NORM);
2138 BTFIXUPSET_CALL(pmd_clear, sun4c_pmd_clear, BTFIXUPCALL_STG0O0);
2139
2140 BTFIXUPSET_CALL(pgd_none, sun4c_pgd_none, BTFIXUPCALL_RETINT(0));
2141 BTFIXUPSET_CALL(pgd_bad, sun4c_pgd_bad, BTFIXUPCALL_RETINT(0));
2142 BTFIXUPSET_CALL(pgd_present, sun4c_pgd_present, BTFIXUPCALL_RETINT(1));
2143 BTFIXUPSET_CALL(pgd_clear, sun4c_pgd_clear, BTFIXUPCALL_NOP);
2144
2145 BTFIXUPSET_CALL(mk_pte, sun4c_mk_pte, BTFIXUPCALL_NORM);
2146 BTFIXUPSET_CALL(mk_pte_phys, sun4c_mk_pte_phys, BTFIXUPCALL_NORM);
2147 BTFIXUPSET_CALL(mk_pte_io, sun4c_mk_pte_io, BTFIXUPCALL_NORM);
2148
2149 BTFIXUPSET_INT(pte_modify_mask, _SUN4C_PAGE_CHG_MASK);
2150 BTFIXUPSET_CALL(pmd_offset, sun4c_pmd_offset, BTFIXUPCALL_NORM);
2151 BTFIXUPSET_CALL(pte_offset, sun4c_pte_offset, BTFIXUPCALL_NORM);
2152 BTFIXUPSET_CALL(free_pte_fast, sun4c_free_pte_fast, BTFIXUPCALL_NORM);
2153 BTFIXUPSET_CALL(pte_alloc_one, sun4c_pte_alloc_one, BTFIXUPCALL_NORM);
2154 BTFIXUPSET_CALL(pte_alloc_one_fast, sun4c_pte_alloc_one_fast, BTFIXUPCALL_NORM);
2155 BTFIXUPSET_CALL(free_pmd_fast, sun4c_free_pmd_fast, BTFIXUPCALL_NOP);
2156 BTFIXUPSET_CALL(pmd_alloc_one_fast, sun4c_pmd_alloc_one_fast, BTFIXUPCALL_RETO0);
2157 BTFIXUPSET_CALL(free_pgd_fast, sun4c_free_pgd_fast, BTFIXUPCALL_NORM);
2158 BTFIXUPSET_CALL(get_pgd_fast, sun4c_get_pgd_fast, BTFIXUPCALL_NORM);
2159
2160 BTFIXUPSET_HALF(pte_writei, _SUN4C_PAGE_WRITE);
2161 BTFIXUPSET_HALF(pte_dirtyi, _SUN4C_PAGE_MODIFIED);
2162 BTFIXUPSET_HALF(pte_youngi, _SUN4C_PAGE_ACCESSED);
2163 BTFIXUPSET_HALF(pte_wrprotecti, _SUN4C_PAGE_WRITE|_SUN4C_PAGE_SILENT_WRITE);
2164 BTFIXUPSET_HALF(pte_mkcleani, _SUN4C_PAGE_MODIFIED|_SUN4C_PAGE_SILENT_WRITE);
2165 BTFIXUPSET_HALF(pte_mkoldi, _SUN4C_PAGE_ACCESSED|_SUN4C_PAGE_SILENT_READ);
2166 BTFIXUPSET_CALL(pte_mkwrite, sun4c_pte_mkwrite, BTFIXUPCALL_NORM);
2167 BTFIXUPSET_CALL(pte_mkdirty, sun4c_pte_mkdirty, BTFIXUPCALL_NORM);
2168 BTFIXUPSET_CALL(pte_mkyoung, sun4c_pte_mkyoung, BTFIXUPCALL_NORM);
2169 BTFIXUPSET_CALL(update_mmu_cache, sun4c_update_mmu_cache, BTFIXUPCALL_NORM);
2170
2171 BTFIXUPSET_CALL(mmu_lockarea, sun4c_lockarea, BTFIXUPCALL_NORM);
2172 BTFIXUPSET_CALL(mmu_unlockarea, sun4c_unlockarea, BTFIXUPCALL_NORM);
2173
2174 BTFIXUPSET_CALL(mmu_get_scsi_one, sun4c_get_scsi_one, BTFIXUPCALL_NORM);
2175 BTFIXUPSET_CALL(mmu_get_scsi_sgl, sun4c_get_scsi_sgl, BTFIXUPCALL_NORM);
2176 BTFIXUPSET_CALL(mmu_release_scsi_one, sun4c_release_scsi_one, BTFIXUPCALL_NORM);
2177 BTFIXUPSET_CALL(mmu_release_scsi_sgl, sun4c_release_scsi_sgl, BTFIXUPCALL_NORM);
2178
2179 BTFIXUPSET_CALL(mmu_map_dma_area, sun4c_map_dma_area, BTFIXUPCALL_NORM);
2180 BTFIXUPSET_CALL(mmu_unmap_dma_area, sun4c_unmap_dma_area, BTFIXUPCALL_NORM);
2181 BTFIXUPSET_CALL(mmu_translate_dvma, sun4c_translate_dvma, BTFIXUPCALL_NORM);
2182
2183 /* Task struct and kernel stack allocating/freeing. */
2184 BTFIXUPSET_CALL(alloc_task_struct, sun4c_alloc_task_struct, BTFIXUPCALL_NORM);
2185 BTFIXUPSET_CALL(get_task_struct, sun4c_get_task_struct, BTFIXUPCALL_NORM);
2186
2187 BTFIXUPSET_CALL(mmu_info, sun4c_mmu_info, BTFIXUPCALL_NORM);
2188
2189 /* These should _never_ get called with two level tables. */
2190 BTFIXUPSET_CALL(pgd_set, sun4c_pgd_set, BTFIXUPCALL_NOP);
2191 BTFIXUPSET_CALL(pgd_page, sun4c_pgd_page, BTFIXUPCALL_RETO0);
2192 }
2193