1 /* sun4c.c: Doing in software what should be done in hardware.
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1996 Andrew Tridgell (Andrew.Tridgell@anu.edu.au)
6 * Copyright (C) 1997-2000 Anton Blanchard (anton@samba.org)
7 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10 #define NR_TASK_BUCKETS 512
12 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
16 #include <linux/highmem.h>
18 #include <linux/seq_file.h>
19 #include <linux/scatterlist.h>
22 #include <asm/pgalloc.h>
23 #include <asm/pgtable.h>
24 #include <asm/vaddrs.h>
25 #include <asm/idprom.h>
26 #include <asm/machines.h>
27 #include <asm/memreg.h>
28 #include <asm/processor.h>
29 #include <asm/auxio.h>
31 #include <asm/oplib.h>
32 #include <asm/openprom.h>
33 #include <asm/mmu_context.h>
34 #include <asm/highmem.h>
35 #include <asm/btfixup.h>
36 #include <asm/cacheflush.h>
37 #include <asm/tlbflush.h>
39 /* Because of our dynamic kernel TLB miss strategy, and how
40 * our DVMA mapping allocation works, you _MUST_:
42 * 1) Disable interrupts _and_ not touch any dynamic kernel
43 * memory while messing with kernel MMU state. By
44 * dynamic memory I mean any object which is not in
45 * the kernel image itself or a thread_union (both of
46 * which are locked into the MMU).
47 * 2) Disable interrupts while messing with user MMU state.
50 extern int num_segmaps
, num_contexts
;
52 extern unsigned long page_kernel
;
54 /* That's it, we prom_halt() on sun4c if the cache size is something other than 65536.
55 * So let's save some cycles and just use that everywhere except for that bootup
58 #define SUN4C_VAC_SIZE 65536
60 #define SUN4C_KERNEL_BUCKETS 32
62 /* Flushing the cache. */
63 struct sun4c_vac_props sun4c_vacinfo
;
64 unsigned long sun4c_kernel_faults
;
66 /* Invalidate every sun4c cache line tag. */
67 static void __init
sun4c_flush_all(void)
69 unsigned long begin
, end
;
72 panic("SUN4C: AIEEE, trying to invalidate vac while it is on.");
74 /* Clear 'valid' bit in all cache line tags */
76 end
= (AC_CACHETAGS
+ SUN4C_VAC_SIZE
);
78 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
79 "r" (begin
), "i" (ASI_CONTROL
));
80 begin
+= sun4c_vacinfo
.linesize
;
84 static void sun4c_flush_context_hw(void)
86 unsigned long end
= SUN4C_VAC_SIZE
;
89 "1: addcc %0, -4096, %0\n\t"
93 : "0" (end
), "i" (ASI_HWFLUSHCONTEXT
)
97 /* Must be called minimally with IRQs disabled. */
98 static void sun4c_flush_segment_hw(unsigned long addr
)
100 if (sun4c_get_segmap(addr
) != invalid_segment
) {
101 unsigned long vac_size
= SUN4C_VAC_SIZE
;
103 __asm__
__volatile__(
104 "1: addcc %0, -4096, %0\n\t"
106 " sta %%g0, [%2 + %0] %3"
108 : "0" (vac_size
), "r" (addr
), "i" (ASI_HWFLUSHSEG
)
113 /* File local boot time fixups. */
114 BTFIXUPDEF_CALL(void, sun4c_flush_page
, unsigned long)
115 BTFIXUPDEF_CALL(void, sun4c_flush_segment
, unsigned long)
116 BTFIXUPDEF_CALL(void, sun4c_flush_context
, void)
118 #define sun4c_flush_page(addr) BTFIXUP_CALL(sun4c_flush_page)(addr)
119 #define sun4c_flush_segment(addr) BTFIXUP_CALL(sun4c_flush_segment)(addr)
120 #define sun4c_flush_context() BTFIXUP_CALL(sun4c_flush_context)()
122 /* Must be called minimally with interrupts disabled. */
123 static void sun4c_flush_page_hw(unsigned long addr
)
126 if ((int)sun4c_get_pte(addr
) < 0)
127 __asm__
__volatile__("sta %%g0, [%0] %1"
128 : : "r" (addr
), "i" (ASI_HWFLUSHPAGE
));
131 /* Don't inline the software version as it eats too many cache lines if expanded. */
132 static void sun4c_flush_context_sw(void)
134 unsigned long nbytes
= SUN4C_VAC_SIZE
;
135 unsigned long lsize
= sun4c_vacinfo
.linesize
;
137 __asm__
__volatile__(
138 "add %2, %2, %%g1\n\t"
139 "add %2, %%g1, %%g2\n\t"
140 "add %2, %%g2, %%g3\n\t"
141 "add %2, %%g3, %%g4\n\t"
142 "add %2, %%g4, %%g5\n\t"
143 "add %2, %%g5, %%o4\n\t"
144 "add %2, %%o4, %%o5\n"
146 "subcc %0, %%o5, %0\n\t"
147 "sta %%g0, [%0] %3\n\t"
148 "sta %%g0, [%0 + %2] %3\n\t"
149 "sta %%g0, [%0 + %%g1] %3\n\t"
150 "sta %%g0, [%0 + %%g2] %3\n\t"
151 "sta %%g0, [%0 + %%g3] %3\n\t"
152 "sta %%g0, [%0 + %%g4] %3\n\t"
153 "sta %%g0, [%0 + %%g5] %3\n\t"
155 " sta %%g0, [%1 + %%o4] %3\n"
157 : "0" (nbytes
), "r" (lsize
), "i" (ASI_FLUSHCTX
)
158 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
161 /* Don't inline the software version as it eats too many cache lines if expanded. */
162 static void sun4c_flush_segment_sw(unsigned long addr
)
164 if (sun4c_get_segmap(addr
) != invalid_segment
) {
165 unsigned long nbytes
= SUN4C_VAC_SIZE
;
166 unsigned long lsize
= sun4c_vacinfo
.linesize
;
168 __asm__
__volatile__(
169 "add %2, %2, %%g1\n\t"
170 "add %2, %%g1, %%g2\n\t"
171 "add %2, %%g2, %%g3\n\t"
172 "add %2, %%g3, %%g4\n\t"
173 "add %2, %%g4, %%g5\n\t"
174 "add %2, %%g5, %%o4\n\t"
175 "add %2, %%o4, %%o5\n"
177 "subcc %1, %%o5, %1\n\t"
178 "sta %%g0, [%0] %6\n\t"
179 "sta %%g0, [%0 + %2] %6\n\t"
180 "sta %%g0, [%0 + %%g1] %6\n\t"
181 "sta %%g0, [%0 + %%g2] %6\n\t"
182 "sta %%g0, [%0 + %%g3] %6\n\t"
183 "sta %%g0, [%0 + %%g4] %6\n\t"
184 "sta %%g0, [%0 + %%g5] %6\n\t"
185 "sta %%g0, [%0 + %%o4] %6\n\t"
187 " add %0, %%o5, %0\n"
188 : "=&r" (addr
), "=&r" (nbytes
), "=&r" (lsize
)
189 : "0" (addr
), "1" (nbytes
), "2" (lsize
),
191 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
195 /* Don't inline the software version as it eats too many cache lines if expanded. */
196 static void sun4c_flush_page_sw(unsigned long addr
)
199 if ((sun4c_get_pte(addr
) & (_SUN4C_PAGE_NOCACHE
| _SUN4C_PAGE_VALID
)) ==
201 unsigned long left
= PAGE_SIZE
;
202 unsigned long lsize
= sun4c_vacinfo
.linesize
;
204 __asm__
__volatile__(
205 "add %2, %2, %%g1\n\t"
206 "add %2, %%g1, %%g2\n\t"
207 "add %2, %%g2, %%g3\n\t"
208 "add %2, %%g3, %%g4\n\t"
209 "add %2, %%g4, %%g5\n\t"
210 "add %2, %%g5, %%o4\n\t"
211 "add %2, %%o4, %%o5\n"
213 "subcc %1, %%o5, %1\n\t"
214 "sta %%g0, [%0] %6\n\t"
215 "sta %%g0, [%0 + %2] %6\n\t"
216 "sta %%g0, [%0 + %%g1] %6\n\t"
217 "sta %%g0, [%0 + %%g2] %6\n\t"
218 "sta %%g0, [%0 + %%g3] %6\n\t"
219 "sta %%g0, [%0 + %%g4] %6\n\t"
220 "sta %%g0, [%0 + %%g5] %6\n\t"
221 "sta %%g0, [%0 + %%o4] %6\n\t"
223 " add %0, %%o5, %0\n"
224 : "=&r" (addr
), "=&r" (left
), "=&r" (lsize
)
225 : "0" (addr
), "1" (left
), "2" (lsize
),
227 : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
231 /* The sun4c's do have an on chip store buffer. And the way you
232 * clear them out isn't so obvious. The only way I can think of
233 * to accomplish this is to read the current context register,
234 * store the same value there, then read an external hardware
237 void sun4c_complete_all_stores(void)
239 volatile int _unused
;
241 _unused
= sun4c_get_context();
242 sun4c_set_context(_unused
);
243 _unused
= get_auxio();
246 /* Bootup utility functions. */
247 static inline void sun4c_init_clean_segmap(unsigned char pseg
)
251 sun4c_put_segmap(0, pseg
);
252 for (vaddr
= 0; vaddr
< SUN4C_REAL_PGDIR_SIZE
; vaddr
+= PAGE_SIZE
)
253 sun4c_put_pte(vaddr
, 0);
254 sun4c_put_segmap(0, invalid_segment
);
257 static inline void sun4c_init_clean_mmu(unsigned long kernel_end
)
260 unsigned char savectx
, ctx
;
262 savectx
= sun4c_get_context();
263 for (ctx
= 0; ctx
< num_contexts
; ctx
++) {
264 sun4c_set_context(ctx
);
265 for (vaddr
= 0; vaddr
< 0x20000000; vaddr
+= SUN4C_REAL_PGDIR_SIZE
)
266 sun4c_put_segmap(vaddr
, invalid_segment
);
267 for (vaddr
= 0xe0000000; vaddr
< KERNBASE
; vaddr
+= SUN4C_REAL_PGDIR_SIZE
)
268 sun4c_put_segmap(vaddr
, invalid_segment
);
269 for (vaddr
= kernel_end
; vaddr
< KADB_DEBUGGER_BEGVM
; vaddr
+= SUN4C_REAL_PGDIR_SIZE
)
270 sun4c_put_segmap(vaddr
, invalid_segment
);
271 for (vaddr
= LINUX_OPPROM_ENDVM
; vaddr
; vaddr
+= SUN4C_REAL_PGDIR_SIZE
)
272 sun4c_put_segmap(vaddr
, invalid_segment
);
274 sun4c_set_context(savectx
);
277 void __init
sun4c_probe_vac(void)
281 if ((idprom
->id_machtype
== (SM_SUN4C
| SM_4C_SS1
)) ||
282 (idprom
->id_machtype
== (SM_SUN4C
| SM_4C_SS1PLUS
))) {
283 /* PROM on SS1 lacks this info, to be super safe we
284 * hard code it here since this arch is cast in stone.
286 sun4c_vacinfo
.num_bytes
= 65536;
287 sun4c_vacinfo
.linesize
= 16;
289 sun4c_vacinfo
.num_bytes
=
290 prom_getintdefault(prom_root_node
, "vac-size", 65536);
291 sun4c_vacinfo
.linesize
=
292 prom_getintdefault(prom_root_node
, "vac-linesize", 16);
294 sun4c_vacinfo
.do_hwflushes
=
295 prom_getintdefault(prom_root_node
, "vac-hwflush", 0);
297 if (sun4c_vacinfo
.do_hwflushes
== 0)
298 sun4c_vacinfo
.do_hwflushes
=
299 prom_getintdefault(prom_root_node
, "vac_hwflush", 0);
301 if (sun4c_vacinfo
.num_bytes
!= 65536) {
302 prom_printf("WEIRD Sun4C VAC cache size, "
303 "tell sparclinux@vger.kernel.org");
307 switch (sun4c_vacinfo
.linesize
) {
309 sun4c_vacinfo
.log2lsize
= 4;
312 sun4c_vacinfo
.log2lsize
= 5;
315 prom_printf("probe_vac: Didn't expect vac-linesize of %d, halting\n",
316 sun4c_vacinfo
.linesize
);
324 /* Patch instructions for the low level kernel fault handler. */
325 extern unsigned long invalid_segment_patch1
, invalid_segment_patch1_ff
;
326 extern unsigned long invalid_segment_patch2
, invalid_segment_patch2_ff
;
327 extern unsigned long invalid_segment_patch1_1ff
, invalid_segment_patch2_1ff
;
328 extern unsigned long num_context_patch1
, num_context_patch1_16
;
329 extern unsigned long num_context_patch2_16
;
330 extern unsigned long vac_linesize_patch
, vac_linesize_patch_32
;
331 extern unsigned long vac_hwflush_patch1
, vac_hwflush_patch1_on
;
332 extern unsigned long vac_hwflush_patch2
, vac_hwflush_patch2_on
;
334 #define PATCH_INSN(src, dst) do { \
340 static void __init
patch_kernel_fault_handler(void)
342 unsigned long *iaddr
, *daddr
;
344 switch (num_segmaps
) {
346 /* Default, nothing to do. */
349 PATCH_INSN(invalid_segment_patch1_ff
,
350 invalid_segment_patch1
);
351 PATCH_INSN(invalid_segment_patch2_ff
,
352 invalid_segment_patch2
);
355 PATCH_INSN(invalid_segment_patch1_1ff
,
356 invalid_segment_patch1
);
357 PATCH_INSN(invalid_segment_patch2_1ff
,
358 invalid_segment_patch2
);
361 prom_printf("Unhandled number of segmaps: %d\n",
365 switch (num_contexts
) {
367 /* Default, nothing to do. */
370 PATCH_INSN(num_context_patch1_16
,
374 prom_printf("Unhandled number of contexts: %d\n",
379 if (sun4c_vacinfo
.do_hwflushes
!= 0) {
380 PATCH_INSN(vac_hwflush_patch1_on
, vac_hwflush_patch1
);
381 PATCH_INSN(vac_hwflush_patch2_on
, vac_hwflush_patch2
);
383 switch (sun4c_vacinfo
.linesize
) {
385 /* Default, nothing to do. */
388 PATCH_INSN(vac_linesize_patch_32
, vac_linesize_patch
);
391 prom_printf("Impossible VAC linesize %d, halting...\n",
392 sun4c_vacinfo
.linesize
);
398 static void __init
sun4c_probe_mmu(void)
400 if ((idprom
->id_machtype
== (SM_SUN4C
| SM_4C_SS1
)) ||
401 (idprom
->id_machtype
== (SM_SUN4C
| SM_4C_SS1PLUS
))) {
402 /* Hardcode these just to be safe, PROM on SS1 does
403 * not have this info available in the root node.
409 prom_getintdefault(prom_root_node
, "mmu-npmg", 128);
411 prom_getintdefault(prom_root_node
, "mmu-nctx", 0x8);
413 patch_kernel_fault_handler();
416 volatile unsigned long __iomem
*sun4c_memerr_reg
= NULL
;
418 void __init
sun4c_probe_memerr_reg(void)
421 struct linux_prom_registers regs
[1];
423 node
= prom_getchild(prom_root_node
);
424 node
= prom_searchsiblings(prom_root_node
, "memory-error");
427 if (prom_getproperty(node
, "reg", (char *)regs
, sizeof(regs
)) <= 0)
429 /* hmm I think regs[0].which_io is zero here anyways */
430 sun4c_memerr_reg
= ioremap(regs
[0].phys_addr
, regs
[0].reg_size
);
433 static inline void sun4c_init_ss2_cache_bug(void)
435 extern unsigned long start
;
437 if ((idprom
->id_machtype
== (SM_SUN4C
| SM_4C_SS2
)) ||
438 (idprom
->id_machtype
== (SM_SUN4C
| SM_4C_IPX
)) ||
439 (idprom
->id_machtype
== (SM_SUN4C
| SM_4C_ELC
))) {
441 printk("SS2 cache bug detected, uncaching trap table page\n");
442 sun4c_flush_page((unsigned int) &start
);
443 sun4c_put_pte(((unsigned long) &start
),
444 (sun4c_get_pte((unsigned long) &start
) | _SUN4C_PAGE_NOCACHE
));
448 /* Addr is always aligned on a page boundary for us already. */
449 static int sun4c_map_dma_area(struct device
*dev
, dma_addr_t
*pba
, unsigned long va
,
450 unsigned long addr
, int len
)
452 unsigned long page
, end
;
456 end
= PAGE_ALIGN((addr
+ len
));
459 sun4c_flush_page(page
);
462 page
|= (_SUN4C_PAGE_VALID
| _SUN4C_PAGE_DIRTY
|
463 _SUN4C_PAGE_NOCACHE
| _SUN4C_PAGE_PRIV
);
464 sun4c_put_pte(addr
, page
);
472 static void sun4c_unmap_dma_area(struct device
*dev
, unsigned long busa
, int len
)
474 /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
475 /* XXX Implement this */
478 /* TLB management. */
480 /* Don't change this struct without changing entry.S. This is used
481 * in the in-window kernel fault handler, and you don't want to mess
482 * with that. (See sun4c_fault in entry.S).
484 struct sun4c_mmu_entry
{
485 struct sun4c_mmu_entry
*next
;
486 struct sun4c_mmu_entry
*prev
;
489 unsigned char locked
;
491 /* For user mappings only, and completely hidden from kernel
495 struct sun4c_mmu_entry
*lru_next
;
496 struct sun4c_mmu_entry
*lru_prev
;
499 static struct sun4c_mmu_entry mmu_entry_pool
[SUN4C_MAX_SEGMAPS
];
501 static void __init
sun4c_init_mmu_entry_pool(void)
505 for (i
=0; i
< SUN4C_MAX_SEGMAPS
; i
++) {
506 mmu_entry_pool
[i
].pseg
= i
;
507 mmu_entry_pool
[i
].next
= NULL
;
508 mmu_entry_pool
[i
].prev
= NULL
;
509 mmu_entry_pool
[i
].vaddr
= 0;
510 mmu_entry_pool
[i
].locked
= 0;
511 mmu_entry_pool
[i
].ctx
= 0;
512 mmu_entry_pool
[i
].lru_next
= NULL
;
513 mmu_entry_pool
[i
].lru_prev
= NULL
;
515 mmu_entry_pool
[invalid_segment
].locked
= 1;
518 static inline void fix_permissions(unsigned long vaddr
, unsigned long bits_on
,
519 unsigned long bits_off
)
521 unsigned long start
, end
;
523 end
= vaddr
+ SUN4C_REAL_PGDIR_SIZE
;
524 for (start
= vaddr
; start
< end
; start
+= PAGE_SIZE
)
525 if (sun4c_get_pte(start
) & _SUN4C_PAGE_VALID
)
526 sun4c_put_pte(start
, (sun4c_get_pte(start
) | bits_on
) &
530 static inline void sun4c_init_map_kernelprom(unsigned long kernel_end
)
533 unsigned char pseg
, ctx
;
535 for (vaddr
= KADB_DEBUGGER_BEGVM
;
536 vaddr
< LINUX_OPPROM_ENDVM
;
537 vaddr
+= SUN4C_REAL_PGDIR_SIZE
) {
538 pseg
= sun4c_get_segmap(vaddr
);
539 if (pseg
!= invalid_segment
) {
540 mmu_entry_pool
[pseg
].locked
= 1;
541 for (ctx
= 0; ctx
< num_contexts
; ctx
++)
542 prom_putsegment(ctx
, vaddr
, pseg
);
543 fix_permissions(vaddr
, _SUN4C_PAGE_PRIV
, 0);
547 for (vaddr
= KERNBASE
; vaddr
< kernel_end
; vaddr
+= SUN4C_REAL_PGDIR_SIZE
) {
548 pseg
= sun4c_get_segmap(vaddr
);
549 mmu_entry_pool
[pseg
].locked
= 1;
550 for (ctx
= 0; ctx
< num_contexts
; ctx
++)
551 prom_putsegment(ctx
, vaddr
, pseg
);
552 fix_permissions(vaddr
, _SUN4C_PAGE_PRIV
, _SUN4C_PAGE_NOCACHE
);
556 static void __init
sun4c_init_lock_area(unsigned long start
, unsigned long end
)
560 while (start
< end
) {
561 for (i
= 0; i
< invalid_segment
; i
++)
562 if (!mmu_entry_pool
[i
].locked
)
564 mmu_entry_pool
[i
].locked
= 1;
565 sun4c_init_clean_segmap(i
);
566 for (ctx
= 0; ctx
< num_contexts
; ctx
++)
567 prom_putsegment(ctx
, start
, mmu_entry_pool
[i
].pseg
);
568 start
+= SUN4C_REAL_PGDIR_SIZE
;
572 /* Don't change this struct without changing entry.S. This is used
573 * in the in-window kernel fault handler, and you don't want to mess
574 * with that. (See sun4c_fault in entry.S).
576 struct sun4c_mmu_ring
{
577 struct sun4c_mmu_entry ringhd
;
581 static struct sun4c_mmu_ring sun4c_context_ring
[SUN4C_MAX_CONTEXTS
]; /* used user entries */
582 static struct sun4c_mmu_ring sun4c_ufree_ring
; /* free user entries */
583 static struct sun4c_mmu_ring sun4c_ulru_ring
; /* LRU user entries */
584 struct sun4c_mmu_ring sun4c_kernel_ring
; /* used kernel entries */
585 struct sun4c_mmu_ring sun4c_kfree_ring
; /* free kernel entries */
587 static inline void sun4c_init_rings(void)
591 for (i
= 0; i
< SUN4C_MAX_CONTEXTS
; i
++) {
592 sun4c_context_ring
[i
].ringhd
.next
=
593 sun4c_context_ring
[i
].ringhd
.prev
=
594 &sun4c_context_ring
[i
].ringhd
;
595 sun4c_context_ring
[i
].num_entries
= 0;
597 sun4c_ufree_ring
.ringhd
.next
= sun4c_ufree_ring
.ringhd
.prev
=
598 &sun4c_ufree_ring
.ringhd
;
599 sun4c_ufree_ring
.num_entries
= 0;
600 sun4c_ulru_ring
.ringhd
.lru_next
= sun4c_ulru_ring
.ringhd
.lru_prev
=
601 &sun4c_ulru_ring
.ringhd
;
602 sun4c_ulru_ring
.num_entries
= 0;
603 sun4c_kernel_ring
.ringhd
.next
= sun4c_kernel_ring
.ringhd
.prev
=
604 &sun4c_kernel_ring
.ringhd
;
605 sun4c_kernel_ring
.num_entries
= 0;
606 sun4c_kfree_ring
.ringhd
.next
= sun4c_kfree_ring
.ringhd
.prev
=
607 &sun4c_kfree_ring
.ringhd
;
608 sun4c_kfree_ring
.num_entries
= 0;
611 static void add_ring(struct sun4c_mmu_ring
*ring
,
612 struct sun4c_mmu_entry
*entry
)
614 struct sun4c_mmu_entry
*head
= &ring
->ringhd
;
617 (entry
->next
= head
->next
)->prev
= entry
;
622 static inline void add_lru(struct sun4c_mmu_entry
*entry
)
624 struct sun4c_mmu_ring
*ring
= &sun4c_ulru_ring
;
625 struct sun4c_mmu_entry
*head
= &ring
->ringhd
;
627 entry
->lru_next
= head
;
628 (entry
->lru_prev
= head
->lru_prev
)->lru_next
= entry
;
629 head
->lru_prev
= entry
;
632 static void add_ring_ordered(struct sun4c_mmu_ring
*ring
,
633 struct sun4c_mmu_entry
*entry
)
635 struct sun4c_mmu_entry
*head
= &ring
->ringhd
;
636 unsigned long addr
= entry
->vaddr
;
638 while ((head
->next
!= &ring
->ringhd
) && (head
->next
->vaddr
< addr
))
642 (entry
->next
= head
->next
)->prev
= entry
;
649 static inline void remove_ring(struct sun4c_mmu_ring
*ring
,
650 struct sun4c_mmu_entry
*entry
)
652 struct sun4c_mmu_entry
*next
= entry
->next
;
654 (next
->prev
= entry
->prev
)->next
= next
;
658 static void remove_lru(struct sun4c_mmu_entry
*entry
)
660 struct sun4c_mmu_entry
*next
= entry
->lru_next
;
662 (next
->lru_prev
= entry
->lru_prev
)->lru_next
= next
;
665 static void free_user_entry(int ctx
, struct sun4c_mmu_entry
*entry
)
667 remove_ring(sun4c_context_ring
+ctx
, entry
);
669 add_ring(&sun4c_ufree_ring
, entry
);
672 static void free_kernel_entry(struct sun4c_mmu_entry
*entry
,
673 struct sun4c_mmu_ring
*ring
)
675 remove_ring(ring
, entry
);
676 add_ring(&sun4c_kfree_ring
, entry
);
679 static void __init
sun4c_init_fill_kernel_ring(int howmany
)
684 for (i
= 0; i
< invalid_segment
; i
++)
685 if (!mmu_entry_pool
[i
].locked
)
687 mmu_entry_pool
[i
].locked
= 1;
688 sun4c_init_clean_segmap(i
);
689 add_ring(&sun4c_kfree_ring
, &mmu_entry_pool
[i
]);
694 static void __init
sun4c_init_fill_user_ring(void)
698 for (i
= 0; i
< invalid_segment
; i
++) {
699 if (mmu_entry_pool
[i
].locked
)
701 sun4c_init_clean_segmap(i
);
702 add_ring(&sun4c_ufree_ring
, &mmu_entry_pool
[i
]);
706 static void sun4c_kernel_unmap(struct sun4c_mmu_entry
*kentry
)
710 savectx
= sun4c_get_context();
711 for (ctx
= 0; ctx
< num_contexts
; ctx
++) {
712 sun4c_set_context(ctx
);
713 sun4c_put_segmap(kentry
->vaddr
, invalid_segment
);
715 sun4c_set_context(savectx
);
718 static void sun4c_kernel_map(struct sun4c_mmu_entry
*kentry
)
722 savectx
= sun4c_get_context();
723 for (ctx
= 0; ctx
< num_contexts
; ctx
++) {
724 sun4c_set_context(ctx
);
725 sun4c_put_segmap(kentry
->vaddr
, kentry
->pseg
);
727 sun4c_set_context(savectx
);
730 #define sun4c_user_unmap(__entry) \
731 sun4c_put_segmap((__entry)->vaddr, invalid_segment)
733 static void sun4c_demap_context(struct sun4c_mmu_ring
*crp
, unsigned char ctx
)
735 struct sun4c_mmu_entry
*head
= &crp
->ringhd
;
738 local_irq_save(flags
);
739 if (head
->next
!= head
) {
740 struct sun4c_mmu_entry
*entry
= head
->next
;
741 int savectx
= sun4c_get_context();
743 flush_user_windows();
744 sun4c_set_context(ctx
);
745 sun4c_flush_context();
747 struct sun4c_mmu_entry
*next
= entry
->next
;
749 sun4c_user_unmap(entry
);
750 free_user_entry(ctx
, entry
);
753 } while (entry
!= head
);
754 sun4c_set_context(savectx
);
756 local_irq_restore(flags
);
759 static int sun4c_user_taken_entries
; /* This is how much we have. */
760 static int max_user_taken_entries
; /* This limits us and prevents deadlock. */
762 static struct sun4c_mmu_entry
*sun4c_kernel_strategy(void)
764 struct sun4c_mmu_entry
*this_entry
;
766 /* If some are free, return first one. */
767 if (sun4c_kfree_ring
.num_entries
) {
768 this_entry
= sun4c_kfree_ring
.ringhd
.next
;
772 /* Else free one up. */
773 this_entry
= sun4c_kernel_ring
.ringhd
.prev
;
774 sun4c_flush_segment(this_entry
->vaddr
);
775 sun4c_kernel_unmap(this_entry
);
776 free_kernel_entry(this_entry
, &sun4c_kernel_ring
);
777 this_entry
= sun4c_kfree_ring
.ringhd
.next
;
782 /* Using this method to free up mmu entries eliminates a lot of
783 * potential races since we have a kernel that incurs tlb
784 * replacement faults. There may be performance penalties.
786 * NOTE: Must be called with interrupts disabled.
788 static struct sun4c_mmu_entry
*sun4c_user_strategy(void)
790 struct sun4c_mmu_entry
*entry
;
794 /* If some are free, return first one. */
795 if (sun4c_ufree_ring
.num_entries
) {
796 entry
= sun4c_ufree_ring
.ringhd
.next
;
800 if (sun4c_user_taken_entries
) {
801 entry
= sun4c_kernel_strategy();
802 sun4c_user_taken_entries
--;
806 /* Grab from the beginning of the LRU list. */
807 entry
= sun4c_ulru_ring
.ringhd
.lru_next
;
810 savectx
= sun4c_get_context();
811 flush_user_windows();
812 sun4c_set_context(ctx
);
813 sun4c_flush_segment(entry
->vaddr
);
814 sun4c_user_unmap(entry
);
815 remove_ring(sun4c_context_ring
+ ctx
, entry
);
817 sun4c_set_context(savectx
);
822 remove_ring(&sun4c_ufree_ring
, entry
);
825 remove_ring(&sun4c_kfree_ring
, entry
);
829 /* NOTE: Must be called with interrupts disabled. */
830 void sun4c_grow_kernel_ring(void)
832 struct sun4c_mmu_entry
*entry
;
834 /* Prevent deadlock condition. */
835 if (sun4c_user_taken_entries
>= max_user_taken_entries
)
838 if (sun4c_ufree_ring
.num_entries
) {
839 entry
= sun4c_ufree_ring
.ringhd
.next
;
840 remove_ring(&sun4c_ufree_ring
, entry
);
841 add_ring(&sun4c_kfree_ring
, entry
);
842 sun4c_user_taken_entries
++;
846 /* 2 page buckets for task struct and kernel stack allocation.
852 * bucket[NR_TASK_BUCKETS-1]
853 * TASK_STACK_BEGIN + (sizeof(struct task_bucket) * NR_TASK_BUCKETS)
855 * Each slot looks like:
857 * page 1 -- task struct + beginning of kernel stack
858 * page 2 -- rest of kernel stack
861 union task_union
*sun4c_bucket
[NR_TASK_BUCKETS
];
863 static int sun4c_lowbucket_avail
;
865 #define BUCKET_EMPTY ((union task_union *) 0)
866 #define BUCKET_SHIFT (PAGE_SHIFT + 1) /* log2(sizeof(struct task_bucket)) */
867 #define BUCKET_SIZE (1 << BUCKET_SHIFT)
868 #define BUCKET_NUM(addr) ((((addr) - SUN4C_LOCK_VADDR) >> BUCKET_SHIFT))
869 #define BUCKET_ADDR(num) (((num) << BUCKET_SHIFT) + SUN4C_LOCK_VADDR)
870 #define BUCKET_PTE(page) \
871 ((((page) - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(SUN4C_PAGE_KERNEL))
872 #define BUCKET_PTE_PAGE(pte) \
873 (PAGE_OFFSET + (((pte) & SUN4C_PFN_MASK) << PAGE_SHIFT))
875 static void get_locked_segment(unsigned long addr
)
877 struct sun4c_mmu_entry
*stolen
;
880 local_irq_save(flags
);
881 addr
&= SUN4C_REAL_PGDIR_MASK
;
882 stolen
= sun4c_user_strategy();
883 max_user_taken_entries
--;
884 stolen
->vaddr
= addr
;
885 flush_user_windows();
886 sun4c_kernel_map(stolen
);
887 local_irq_restore(flags
);
890 static void free_locked_segment(unsigned long addr
)
892 struct sun4c_mmu_entry
*entry
;
896 local_irq_save(flags
);
897 addr
&= SUN4C_REAL_PGDIR_MASK
;
898 pseg
= sun4c_get_segmap(addr
);
899 entry
= &mmu_entry_pool
[pseg
];
901 flush_user_windows();
902 sun4c_flush_segment(addr
);
903 sun4c_kernel_unmap(entry
);
904 add_ring(&sun4c_ufree_ring
, entry
);
905 max_user_taken_entries
++;
906 local_irq_restore(flags
);
909 static inline void garbage_collect(int entry
)
913 /* 32 buckets per segment... */
916 for (end
= (start
+ 32); start
< end
; start
++)
917 if (sun4c_bucket
[start
] != BUCKET_EMPTY
)
920 /* Entire segment empty, release it. */
921 free_locked_segment(BUCKET_ADDR(entry
));
924 static struct thread_info
*sun4c_alloc_thread_info(void)
926 unsigned long addr
, pages
;
929 pages
= __get_free_pages(GFP_KERNEL
, THREAD_INFO_ORDER
);
933 for (entry
= sun4c_lowbucket_avail
; entry
< NR_TASK_BUCKETS
; entry
++)
934 if (sun4c_bucket
[entry
] == BUCKET_EMPTY
)
936 if (entry
== NR_TASK_BUCKETS
) {
937 free_pages(pages
, THREAD_INFO_ORDER
);
940 if (entry
>= sun4c_lowbucket_avail
)
941 sun4c_lowbucket_avail
= entry
+ 1;
943 addr
= BUCKET_ADDR(entry
);
944 sun4c_bucket
[entry
] = (union task_union
*) addr
;
945 if(sun4c_get_segmap(addr
) == invalid_segment
)
946 get_locked_segment(addr
);
948 /* We are changing the virtual color of the page(s)
949 * so we must flush the cache to guarantee consistency.
951 sun4c_flush_page(pages
);
952 sun4c_flush_page(pages
+ PAGE_SIZE
);
954 sun4c_put_pte(addr
, BUCKET_PTE(pages
));
955 sun4c_put_pte(addr
+ PAGE_SIZE
, BUCKET_PTE(pages
+ PAGE_SIZE
));
957 #ifdef CONFIG_DEBUG_STACK_USAGE
958 memset((void *)addr
, 0, PAGE_SIZE
<< THREAD_INFO_ORDER
);
959 #endif /* DEBUG_STACK_USAGE */
961 return (struct thread_info
*) addr
;
964 static void sun4c_free_thread_info(struct thread_info
*ti
)
966 unsigned long tiaddr
= (unsigned long) ti
;
967 unsigned long pages
= BUCKET_PTE_PAGE(sun4c_get_pte(tiaddr
));
968 int entry
= BUCKET_NUM(tiaddr
);
970 /* We are deleting a mapping, so the flush here is mandatory. */
971 sun4c_flush_page(tiaddr
);
972 sun4c_flush_page(tiaddr
+ PAGE_SIZE
);
974 sun4c_put_pte(tiaddr
, 0);
975 sun4c_put_pte(tiaddr
+ PAGE_SIZE
, 0);
977 sun4c_bucket
[entry
] = BUCKET_EMPTY
;
978 if (entry
< sun4c_lowbucket_avail
)
979 sun4c_lowbucket_avail
= entry
;
981 free_pages(pages
, THREAD_INFO_ORDER
);
982 garbage_collect(entry
);
985 static void __init
sun4c_init_buckets(void)
989 if (sizeof(union thread_union
) != (PAGE_SIZE
<< THREAD_INFO_ORDER
)) {
990 extern void thread_info_size_is_bolixed_pete(void);
991 thread_info_size_is_bolixed_pete();
994 for (entry
= 0; entry
< NR_TASK_BUCKETS
; entry
++)
995 sun4c_bucket
[entry
] = BUCKET_EMPTY
;
996 sun4c_lowbucket_avail
= 0;
999 static unsigned long sun4c_iobuffer_start
;
1000 static unsigned long sun4c_iobuffer_end
;
1001 static unsigned long sun4c_iobuffer_high
;
1002 static unsigned long *sun4c_iobuffer_map
;
1003 static int iobuffer_map_size
;
1006 * Alias our pages so they do not cause a trap.
1007 * Also one page may be aliased into several I/O areas and we may
1008 * finish these I/O separately.
1010 static char *sun4c_lockarea(char *vaddr
, unsigned long size
)
1012 unsigned long base
, scan
;
1013 unsigned long npages
;
1014 unsigned long vpage
;
1016 unsigned long apage
;
1018 unsigned long flags
;
1020 npages
= (((unsigned long)vaddr
& ~PAGE_MASK
) +
1021 size
+ (PAGE_SIZE
-1)) >> PAGE_SHIFT
;
1024 local_irq_save(flags
);
1026 scan
= find_next_zero_bit(sun4c_iobuffer_map
,
1027 iobuffer_map_size
, scan
);
1028 if ((base
= scan
) + npages
> iobuffer_map_size
) goto abend
;
1030 if (scan
>= base
+ npages
) goto found
;
1031 if (test_bit(scan
, sun4c_iobuffer_map
)) break;
1037 high
= ((base
+ npages
) << PAGE_SHIFT
) + sun4c_iobuffer_start
;
1038 high
= SUN4C_REAL_PGDIR_ALIGN(high
);
1039 while (high
> sun4c_iobuffer_high
) {
1040 get_locked_segment(sun4c_iobuffer_high
);
1041 sun4c_iobuffer_high
+= SUN4C_REAL_PGDIR_SIZE
;
1044 vpage
= ((unsigned long) vaddr
) & PAGE_MASK
;
1045 for (scan
= base
; scan
< base
+npages
; scan
++) {
1046 pte
= ((vpage
-PAGE_OFFSET
) >> PAGE_SHIFT
);
1047 pte
|= pgprot_val(SUN4C_PAGE_KERNEL
);
1048 pte
|= _SUN4C_PAGE_NOCACHE
;
1049 set_bit(scan
, sun4c_iobuffer_map
);
1050 apage
= (scan
<< PAGE_SHIFT
) + sun4c_iobuffer_start
;
1052 /* Flush original mapping so we see the right things later. */
1053 sun4c_flush_page(vpage
);
1055 sun4c_put_pte(apage
, pte
);
1058 local_irq_restore(flags
);
1059 return (char *) ((base
<< PAGE_SHIFT
) + sun4c_iobuffer_start
+
1060 (((unsigned long) vaddr
) & ~PAGE_MASK
));
1063 local_irq_restore(flags
);
1064 printk("DMA vaddr=0x%p size=%08lx\n", vaddr
, size
);
1065 panic("Out of iobuffer table");
1069 static void sun4c_unlockarea(char *vaddr
, unsigned long size
)
1071 unsigned long vpage
, npages
;
1072 unsigned long flags
;
1075 vpage
= (unsigned long)vaddr
& PAGE_MASK
;
1076 npages
= (((unsigned long)vaddr
& ~PAGE_MASK
) +
1077 size
+ (PAGE_SIZE
-1)) >> PAGE_SHIFT
;
1079 local_irq_save(flags
);
1080 while (npages
!= 0) {
1083 /* This mapping is marked non-cachable, no flush necessary. */
1084 sun4c_put_pte(vpage
, 0);
1085 clear_bit((vpage
- sun4c_iobuffer_start
) >> PAGE_SHIFT
,
1086 sun4c_iobuffer_map
);
1090 /* garbage collect */
1091 scan
= (sun4c_iobuffer_high
- sun4c_iobuffer_start
) >> PAGE_SHIFT
;
1092 while (scan
>= 0 && !sun4c_iobuffer_map
[scan
>> 5])
1095 high
= sun4c_iobuffer_start
+ (scan
<< PAGE_SHIFT
);
1096 high
= SUN4C_REAL_PGDIR_ALIGN(high
) + SUN4C_REAL_PGDIR_SIZE
;
1097 while (high
< sun4c_iobuffer_high
) {
1098 sun4c_iobuffer_high
-= SUN4C_REAL_PGDIR_SIZE
;
1099 free_locked_segment(sun4c_iobuffer_high
);
1101 local_irq_restore(flags
);
1104 /* Note the scsi code at init time passes to here buffers
1105 * which sit on the kernel stack, those are already locked
1106 * by implication and fool the page locking code above
1107 * if passed to by mistake.
1109 static __u32
sun4c_get_scsi_one(struct device
*dev
, char *bufptr
, unsigned long len
)
1113 page
= ((unsigned long)bufptr
) & PAGE_MASK
;
1114 if (!virt_addr_valid(page
)) {
1115 sun4c_flush_page(page
);
1116 return (__u32
)bufptr
; /* already locked */
1118 return (__u32
)sun4c_lockarea(bufptr
, len
);
1121 static void sun4c_get_scsi_sgl(struct device
*dev
, struct scatterlist
*sg
, int sz
)
1125 sg
->dvma_address
= (__u32
)sun4c_lockarea(sg_virt(sg
), sg
->length
);
1126 sg
->dvma_length
= sg
->length
;
1131 static void sun4c_release_scsi_one(struct device
*dev
, __u32 bufptr
, unsigned long len
)
1133 if (bufptr
< sun4c_iobuffer_start
)
1134 return; /* On kernel stack or similar, see above */
1135 sun4c_unlockarea((char *)bufptr
, len
);
1138 static void sun4c_release_scsi_sgl(struct device
*dev
, struct scatterlist
*sg
, int sz
)
1142 sun4c_unlockarea((char *)sg
->dvma_address
, sg
->length
);
1147 #define TASK_ENTRY_SIZE BUCKET_SIZE /* see above */
1148 #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
1150 struct vm_area_struct sun4c_kstack_vma
;
1152 static void __init
sun4c_init_lock_areas(void)
1154 unsigned long sun4c_taskstack_start
;
1155 unsigned long sun4c_taskstack_end
;
1158 sun4c_init_buckets();
1159 sun4c_taskstack_start
= SUN4C_LOCK_VADDR
;
1160 sun4c_taskstack_end
= (sun4c_taskstack_start
+
1161 (TASK_ENTRY_SIZE
* NR_TASK_BUCKETS
));
1162 if (sun4c_taskstack_end
>= SUN4C_LOCK_END
) {
1163 prom_printf("Too many tasks, decrease NR_TASK_BUCKETS please.\n");
1167 sun4c_iobuffer_start
= sun4c_iobuffer_high
=
1168 SUN4C_REAL_PGDIR_ALIGN(sun4c_taskstack_end
);
1169 sun4c_iobuffer_end
= SUN4C_LOCK_END
;
1170 bitmap_size
= (sun4c_iobuffer_end
- sun4c_iobuffer_start
) >> PAGE_SHIFT
;
1171 bitmap_size
= (bitmap_size
+ 7) >> 3;
1172 bitmap_size
= LONG_ALIGN(bitmap_size
);
1173 iobuffer_map_size
= bitmap_size
<< 3;
1174 sun4c_iobuffer_map
= __alloc_bootmem(bitmap_size
, SMP_CACHE_BYTES
, 0UL);
1175 memset((void *) sun4c_iobuffer_map
, 0, bitmap_size
);
1177 sun4c_kstack_vma
.vm_mm
= &init_mm
;
1178 sun4c_kstack_vma
.vm_start
= sun4c_taskstack_start
;
1179 sun4c_kstack_vma
.vm_end
= sun4c_taskstack_end
;
1180 sun4c_kstack_vma
.vm_page_prot
= PAGE_SHARED
;
1181 sun4c_kstack_vma
.vm_flags
= VM_READ
| VM_WRITE
| VM_EXEC
;
1182 insert_vm_struct(&init_mm
, &sun4c_kstack_vma
);
1185 /* Cache flushing on the sun4c. */
1186 static void sun4c_flush_cache_all(void)
1188 unsigned long begin
, end
;
1190 flush_user_windows();
1191 begin
= (KERNBASE
+ SUN4C_REAL_PGDIR_SIZE
);
1192 end
= (begin
+ SUN4C_VAC_SIZE
);
1194 if (sun4c_vacinfo
.linesize
== 32) {
1195 while (begin
< end
) {
1196 __asm__
__volatile__(
1197 "ld [%0 + 0x00], %%g0\n\t"
1198 "ld [%0 + 0x20], %%g0\n\t"
1199 "ld [%0 + 0x40], %%g0\n\t"
1200 "ld [%0 + 0x60], %%g0\n\t"
1201 "ld [%0 + 0x80], %%g0\n\t"
1202 "ld [%0 + 0xa0], %%g0\n\t"
1203 "ld [%0 + 0xc0], %%g0\n\t"
1204 "ld [%0 + 0xe0], %%g0\n\t"
1205 "ld [%0 + 0x100], %%g0\n\t"
1206 "ld [%0 + 0x120], %%g0\n\t"
1207 "ld [%0 + 0x140], %%g0\n\t"
1208 "ld [%0 + 0x160], %%g0\n\t"
1209 "ld [%0 + 0x180], %%g0\n\t"
1210 "ld [%0 + 0x1a0], %%g0\n\t"
1211 "ld [%0 + 0x1c0], %%g0\n\t"
1212 "ld [%0 + 0x1e0], %%g0\n"
1217 while (begin
< end
) {
1218 __asm__
__volatile__(
1219 "ld [%0 + 0x00], %%g0\n\t"
1220 "ld [%0 + 0x10], %%g0\n\t"
1221 "ld [%0 + 0x20], %%g0\n\t"
1222 "ld [%0 + 0x30], %%g0\n\t"
1223 "ld [%0 + 0x40], %%g0\n\t"
1224 "ld [%0 + 0x50], %%g0\n\t"
1225 "ld [%0 + 0x60], %%g0\n\t"
1226 "ld [%0 + 0x70], %%g0\n\t"
1227 "ld [%0 + 0x80], %%g0\n\t"
1228 "ld [%0 + 0x90], %%g0\n\t"
1229 "ld [%0 + 0xa0], %%g0\n\t"
1230 "ld [%0 + 0xb0], %%g0\n\t"
1231 "ld [%0 + 0xc0], %%g0\n\t"
1232 "ld [%0 + 0xd0], %%g0\n\t"
1233 "ld [%0 + 0xe0], %%g0\n\t"
1234 "ld [%0 + 0xf0], %%g0\n"
1241 static void sun4c_flush_cache_mm(struct mm_struct
*mm
)
1243 int new_ctx
= mm
->context
;
1245 if (new_ctx
!= NO_CONTEXT
) {
1246 flush_user_windows();
1248 if (sun4c_context_ring
[new_ctx
].num_entries
) {
1249 struct sun4c_mmu_entry
*head
= &sun4c_context_ring
[new_ctx
].ringhd
;
1250 unsigned long flags
;
1252 local_irq_save(flags
);
1253 if (head
->next
!= head
) {
1254 struct sun4c_mmu_entry
*entry
= head
->next
;
1255 int savectx
= sun4c_get_context();
1257 sun4c_set_context(new_ctx
);
1258 sun4c_flush_context();
1260 struct sun4c_mmu_entry
*next
= entry
->next
;
1262 sun4c_user_unmap(entry
);
1263 free_user_entry(new_ctx
, entry
);
1266 } while (entry
!= head
);
1267 sun4c_set_context(savectx
);
1269 local_irq_restore(flags
);
1274 static void sun4c_flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
)
1276 struct mm_struct
*mm
= vma
->vm_mm
;
1277 int new_ctx
= mm
->context
;
1279 if (new_ctx
!= NO_CONTEXT
) {
1280 struct sun4c_mmu_entry
*head
= &sun4c_context_ring
[new_ctx
].ringhd
;
1281 struct sun4c_mmu_entry
*entry
;
1282 unsigned long flags
;
1284 flush_user_windows();
1286 local_irq_save(flags
);
1287 /* All user segmap chains are ordered on entry->vaddr. */
1288 for (entry
= head
->next
;
1289 (entry
!= head
) && ((entry
->vaddr
+SUN4C_REAL_PGDIR_SIZE
) < start
);
1290 entry
= entry
->next
)
1293 /* Tracing various job mixtures showed that this conditional
1294 * only passes ~35% of the time for most worse case situations,
1295 * therefore we avoid all of this gross overhead ~65% of the time.
1297 if ((entry
!= head
) && (entry
->vaddr
< end
)) {
1298 int octx
= sun4c_get_context();
1299 sun4c_set_context(new_ctx
);
1301 /* At this point, always, (start >= entry->vaddr) and
1302 * (entry->vaddr < end), once the latter condition
1303 * ceases to hold, or we hit the end of the list, we
1304 * exit the loop. The ordering of all user allocated
1305 * segmaps makes this all work out so beautifully.
1308 struct sun4c_mmu_entry
*next
= entry
->next
;
1309 unsigned long realend
;
1311 /* "realstart" is always >= entry->vaddr */
1312 realend
= entry
->vaddr
+ SUN4C_REAL_PGDIR_SIZE
;
1315 if ((realend
- entry
->vaddr
) <= (PAGE_SIZE
<< 3)) {
1316 unsigned long page
= entry
->vaddr
;
1317 while (page
< realend
) {
1318 sun4c_flush_page(page
);
1322 sun4c_flush_segment(entry
->vaddr
);
1323 sun4c_user_unmap(entry
);
1324 free_user_entry(new_ctx
, entry
);
1327 } while ((entry
!= head
) && (entry
->vaddr
< end
));
1328 sun4c_set_context(octx
);
1330 local_irq_restore(flags
);
1334 static void sun4c_flush_cache_page(struct vm_area_struct
*vma
, unsigned long page
)
1336 struct mm_struct
*mm
= vma
->vm_mm
;
1337 int new_ctx
= mm
->context
;
1339 /* Sun4c has no separate I/D caches so cannot optimize for non
1340 * text page flushes.
1342 if (new_ctx
!= NO_CONTEXT
) {
1343 int octx
= sun4c_get_context();
1344 unsigned long flags
;
1346 flush_user_windows();
1347 local_irq_save(flags
);
1348 sun4c_set_context(new_ctx
);
1349 sun4c_flush_page(page
);
1350 sun4c_set_context(octx
);
1351 local_irq_restore(flags
);
1355 static void sun4c_flush_page_to_ram(unsigned long page
)
1357 unsigned long flags
;
1359 local_irq_save(flags
);
1360 sun4c_flush_page(page
);
1361 local_irq_restore(flags
);
1364 /* Sun4c cache is unified, both instructions and data live there, so
1365 * no need to flush the on-stack instructions for new signal handlers.
1367 static void sun4c_flush_sig_insns(struct mm_struct
*mm
, unsigned long insn_addr
)
1371 /* TLB flushing on the sun4c. These routines count on the cache
1372 * flushing code to flush the user register windows so that we need
1373 * not do so when we get here.
1376 static void sun4c_flush_tlb_all(void)
1378 struct sun4c_mmu_entry
*this_entry
, *next_entry
;
1379 unsigned long flags
;
1382 local_irq_save(flags
);
1383 this_entry
= sun4c_kernel_ring
.ringhd
.next
;
1384 savectx
= sun4c_get_context();
1385 flush_user_windows();
1386 while (sun4c_kernel_ring
.num_entries
) {
1387 next_entry
= this_entry
->next
;
1388 sun4c_flush_segment(this_entry
->vaddr
);
1389 for (ctx
= 0; ctx
< num_contexts
; ctx
++) {
1390 sun4c_set_context(ctx
);
1391 sun4c_put_segmap(this_entry
->vaddr
, invalid_segment
);
1393 free_kernel_entry(this_entry
, &sun4c_kernel_ring
);
1394 this_entry
= next_entry
;
1396 sun4c_set_context(savectx
);
1397 local_irq_restore(flags
);
1400 static void sun4c_flush_tlb_mm(struct mm_struct
*mm
)
1402 int new_ctx
= mm
->context
;
1404 if (new_ctx
!= NO_CONTEXT
) {
1405 struct sun4c_mmu_entry
*head
= &sun4c_context_ring
[new_ctx
].ringhd
;
1406 unsigned long flags
;
1408 local_irq_save(flags
);
1409 if (head
->next
!= head
) {
1410 struct sun4c_mmu_entry
*entry
= head
->next
;
1411 int savectx
= sun4c_get_context();
1413 sun4c_set_context(new_ctx
);
1414 sun4c_flush_context();
1416 struct sun4c_mmu_entry
*next
= entry
->next
;
1418 sun4c_user_unmap(entry
);
1419 free_user_entry(new_ctx
, entry
);
1422 } while (entry
!= head
);
1423 sun4c_set_context(savectx
);
1425 local_irq_restore(flags
);
1429 static void sun4c_flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
)
1431 struct mm_struct
*mm
= vma
->vm_mm
;
1432 int new_ctx
= mm
->context
;
1434 if (new_ctx
!= NO_CONTEXT
) {
1435 struct sun4c_mmu_entry
*head
= &sun4c_context_ring
[new_ctx
].ringhd
;
1436 struct sun4c_mmu_entry
*entry
;
1437 unsigned long flags
;
1439 local_irq_save(flags
);
1440 /* See commentary in sun4c_flush_cache_range(). */
1441 for (entry
= head
->next
;
1442 (entry
!= head
) && ((entry
->vaddr
+SUN4C_REAL_PGDIR_SIZE
) < start
);
1443 entry
= entry
->next
)
1446 if ((entry
!= head
) && (entry
->vaddr
< end
)) {
1447 int octx
= sun4c_get_context();
1449 sun4c_set_context(new_ctx
);
1451 struct sun4c_mmu_entry
*next
= entry
->next
;
1453 sun4c_flush_segment(entry
->vaddr
);
1454 sun4c_user_unmap(entry
);
1455 free_user_entry(new_ctx
, entry
);
1458 } while ((entry
!= head
) && (entry
->vaddr
< end
));
1459 sun4c_set_context(octx
);
1461 local_irq_restore(flags
);
1465 static void sun4c_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
1467 struct mm_struct
*mm
= vma
->vm_mm
;
1468 int new_ctx
= mm
->context
;
1470 if (new_ctx
!= NO_CONTEXT
) {
1471 int savectx
= sun4c_get_context();
1472 unsigned long flags
;
1474 local_irq_save(flags
);
1475 sun4c_set_context(new_ctx
);
1477 sun4c_flush_page(page
);
1478 sun4c_put_pte(page
, 0);
1479 sun4c_set_context(savectx
);
1480 local_irq_restore(flags
);
1484 static inline void sun4c_mapioaddr(unsigned long physaddr
, unsigned long virt_addr
)
1486 unsigned long page_entry
, pg_iobits
;
1488 pg_iobits
= _SUN4C_PAGE_PRESENT
| _SUN4C_READABLE
| _SUN4C_WRITEABLE
|
1489 _SUN4C_PAGE_IO
| _SUN4C_PAGE_NOCACHE
;
1491 page_entry
= ((physaddr
>> PAGE_SHIFT
) & SUN4C_PFN_MASK
);
1492 page_entry
|= ((pg_iobits
| _SUN4C_PAGE_PRIV
) & ~(_SUN4C_PAGE_PRESENT
));
1493 sun4c_put_pte(virt_addr
, page_entry
);
1496 static void sun4c_mapiorange(unsigned int bus
, unsigned long xpa
,
1497 unsigned long xva
, unsigned int len
)
1501 sun4c_mapioaddr(xpa
, xva
);
1507 static void sun4c_unmapiorange(unsigned long virt_addr
, unsigned int len
)
1511 sun4c_put_pte(virt_addr
, 0);
1512 virt_addr
+= PAGE_SIZE
;
1516 static void sun4c_alloc_context(struct mm_struct
*old_mm
, struct mm_struct
*mm
)
1518 struct ctx_list
*ctxp
;
1520 ctxp
= ctx_free
.next
;
1521 if (ctxp
!= &ctx_free
) {
1522 remove_from_ctx_list(ctxp
);
1523 add_to_used_ctxlist(ctxp
);
1524 mm
->context
= ctxp
->ctx_number
;
1528 ctxp
= ctx_used
.next
;
1529 if (ctxp
->ctx_mm
== old_mm
)
1531 remove_from_ctx_list(ctxp
);
1532 add_to_used_ctxlist(ctxp
);
1533 ctxp
->ctx_mm
->context
= NO_CONTEXT
;
1535 mm
->context
= ctxp
->ctx_number
;
1536 sun4c_demap_context(&sun4c_context_ring
[ctxp
->ctx_number
],
1540 /* Switch the current MM context. */
1541 static void sun4c_switch_mm(struct mm_struct
*old_mm
, struct mm_struct
*mm
, struct task_struct
*tsk
, int cpu
)
1543 struct ctx_list
*ctx
;
1546 if (mm
->context
== NO_CONTEXT
) {
1548 sun4c_alloc_context(old_mm
, mm
);
1550 /* Update the LRU ring of contexts. */
1551 ctx
= ctx_list_pool
+ mm
->context
;
1552 remove_from_ctx_list(ctx
);
1553 add_to_used_ctxlist(ctx
);
1555 if (dirty
|| old_mm
!= mm
)
1556 sun4c_set_context(mm
->context
);
1559 static void sun4c_destroy_context(struct mm_struct
*mm
)
1561 struct ctx_list
*ctx_old
;
1563 if (mm
->context
!= NO_CONTEXT
) {
1564 sun4c_demap_context(&sun4c_context_ring
[mm
->context
], mm
->context
);
1565 ctx_old
= ctx_list_pool
+ mm
->context
;
1566 remove_from_ctx_list(ctx_old
);
1567 add_to_free_ctxlist(ctx_old
);
1568 mm
->context
= NO_CONTEXT
;
1572 static void sun4c_mmu_info(struct seq_file
*m
)
1574 int used_user_entries
, i
;
1576 used_user_entries
= 0;
1577 for (i
= 0; i
< num_contexts
; i
++)
1578 used_user_entries
+= sun4c_context_ring
[i
].num_entries
;
1581 "vacsize\t\t: %d bytes\n"
1582 "vachwflush\t: %s\n"
1583 "vaclinesize\t: %d bytes\n"
1586 "kernelpsegs\t: %d\n"
1587 "kfreepsegs\t: %d\n"
1589 "ufreepsegs\t: %d\n"
1590 "user_taken\t: %d\n"
1591 "max_taken\t: %d\n",
1592 sun4c_vacinfo
.num_bytes
,
1593 (sun4c_vacinfo
.do_hwflushes
? "yes" : "no"),
1594 sun4c_vacinfo
.linesize
,
1596 (invalid_segment
+ 1),
1597 sun4c_kernel_ring
.num_entries
,
1598 sun4c_kfree_ring
.num_entries
,
1600 sun4c_ufree_ring
.num_entries
,
1601 sun4c_user_taken_entries
,
1602 max_user_taken_entries
);
1605 /* Nothing below here should touch the mmu hardware nor the mmu_entry
1609 /* First the functions which the mid-level code uses to directly
1610 * manipulate the software page tables. Some defines since we are
1611 * emulating the i386 page directory layout.
1613 #define PGD_PRESENT 0x001
1614 #define PGD_RW 0x002
1615 #define PGD_USER 0x004
1616 #define PGD_ACCESSED 0x020
1617 #define PGD_DIRTY 0x040
1618 #define PGD_TABLE (PGD_PRESENT | PGD_RW | PGD_USER | PGD_ACCESSED | PGD_DIRTY)
1620 static void sun4c_set_pte(pte_t
*ptep
, pte_t pte
)
1625 static void sun4c_pgd_set(pgd_t
* pgdp
, pmd_t
* pmdp
)
1629 static void sun4c_pmd_set(pmd_t
* pmdp
, pte_t
* ptep
)
1631 pmdp
->pmdv
[0] = PGD_TABLE
| (unsigned long) ptep
;
1634 static void sun4c_pmd_populate(pmd_t
* pmdp
, struct page
* ptep
)
1636 if (page_address(ptep
) == NULL
) BUG(); /* No highmem on sun4c */
1637 pmdp
->pmdv
[0] = PGD_TABLE
| (unsigned long) page_address(ptep
);
1640 static int sun4c_pte_present(pte_t pte
)
1642 return ((pte_val(pte
) & (_SUN4C_PAGE_PRESENT
| _SUN4C_PAGE_PRIV
)) != 0);
1644 static void sun4c_pte_clear(pte_t
*ptep
) { *ptep
= __pte(0); }
1646 static int sun4c_pmd_bad(pmd_t pmd
)
1648 return (((pmd_val(pmd
) & ~PAGE_MASK
) != PGD_TABLE
) ||
1649 (!virt_addr_valid(pmd_val(pmd
))));
1652 static int sun4c_pmd_present(pmd_t pmd
)
1654 return ((pmd_val(pmd
) & PGD_PRESENT
) != 0);
1657 #if 0 /* if PMD takes one word */
1658 static void sun4c_pmd_clear(pmd_t
*pmdp
) { *pmdp
= __pmd(0); }
1659 #else /* if pmd_t is a longish aggregate */
1660 static void sun4c_pmd_clear(pmd_t
*pmdp
) {
1661 memset((void *)pmdp
, 0, sizeof(pmd_t
));
1665 static int sun4c_pgd_none(pgd_t pgd
) { return 0; }
1666 static int sun4c_pgd_bad(pgd_t pgd
) { return 0; }
1667 static int sun4c_pgd_present(pgd_t pgd
) { return 1; }
1668 static void sun4c_pgd_clear(pgd_t
* pgdp
) { }
1671 * The following only work if pte_present() is true.
1672 * Undefined behaviour if not..
1674 static pte_t
sun4c_pte_mkwrite(pte_t pte
)
1676 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_WRITE
);
1677 if (pte_val(pte
) & _SUN4C_PAGE_MODIFIED
)
1678 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_SILENT_WRITE
);
1682 static pte_t
sun4c_pte_mkdirty(pte_t pte
)
1684 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_MODIFIED
);
1685 if (pte_val(pte
) & _SUN4C_PAGE_WRITE
)
1686 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_SILENT_WRITE
);
1690 static pte_t
sun4c_pte_mkyoung(pte_t pte
)
1692 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_ACCESSED
);
1693 if (pte_val(pte
) & _SUN4C_PAGE_READ
)
1694 pte
= __pte(pte_val(pte
) | _SUN4C_PAGE_SILENT_READ
);
1699 * Conversion functions: convert a page and protection to a page entry,
1700 * and a page entry and page directory to the page they refer to.
1702 static pte_t
sun4c_mk_pte(struct page
*page
, pgprot_t pgprot
)
1704 return __pte(page_to_pfn(page
) | pgprot_val(pgprot
));
1707 static pte_t
sun4c_mk_pte_phys(unsigned long phys_page
, pgprot_t pgprot
)
1709 return __pte((phys_page
>> PAGE_SHIFT
) | pgprot_val(pgprot
));
1712 static pte_t
sun4c_mk_pte_io(unsigned long page
, pgprot_t pgprot
, int space
)
1714 return __pte(((page
- PAGE_OFFSET
) >> PAGE_SHIFT
) | pgprot_val(pgprot
));
1717 static unsigned long sun4c_pte_pfn(pte_t pte
)
1719 return pte_val(pte
) & SUN4C_PFN_MASK
;
1722 static pte_t
sun4c_pgoff_to_pte(unsigned long pgoff
)
1724 return __pte(pgoff
| _SUN4C_PAGE_FILE
);
1727 static unsigned long sun4c_pte_to_pgoff(pte_t pte
)
1729 return pte_val(pte
) & ((1UL << PTE_FILE_MAX_BITS
) - 1);
1733 static inline unsigned long sun4c_pmd_page_v(pmd_t pmd
)
1735 return (pmd_val(pmd
) & PAGE_MASK
);
1738 static struct page
*sun4c_pmd_page(pmd_t pmd
)
1740 return virt_to_page(sun4c_pmd_page_v(pmd
));
1743 static unsigned long sun4c_pgd_page(pgd_t pgd
) { return 0; }
1745 /* to find an entry in a page-table-directory */
1746 static inline pgd_t
*sun4c_pgd_offset(struct mm_struct
* mm
, unsigned long address
)
1748 return mm
->pgd
+ (address
>> SUN4C_PGDIR_SHIFT
);
1751 /* Find an entry in the second-level page table.. */
1752 static pmd_t
*sun4c_pmd_offset(pgd_t
* dir
, unsigned long address
)
1754 return (pmd_t
*) dir
;
1757 /* Find an entry in the third-level page table.. */
1758 pte_t
*sun4c_pte_offset_kernel(pmd_t
* dir
, unsigned long address
)
1760 return (pte_t
*) sun4c_pmd_page_v(*dir
) +
1761 ((address
>> PAGE_SHIFT
) & (SUN4C_PTRS_PER_PTE
- 1));
1764 static unsigned long sun4c_swp_type(swp_entry_t entry
)
1766 return (entry
.val
& SUN4C_SWP_TYPE_MASK
);
1769 static unsigned long sun4c_swp_offset(swp_entry_t entry
)
1771 return (entry
.val
>> SUN4C_SWP_OFF_SHIFT
) & SUN4C_SWP_OFF_MASK
;
1774 static swp_entry_t
sun4c_swp_entry(unsigned long type
, unsigned long offset
)
1776 return (swp_entry_t
) {
1777 (offset
& SUN4C_SWP_OFF_MASK
) << SUN4C_SWP_OFF_SHIFT
1778 | (type
& SUN4C_SWP_TYPE_MASK
) };
1781 static void sun4c_free_pte_slow(pte_t
*pte
)
1783 free_page((unsigned long)pte
);
1786 static void sun4c_free_pgd_slow(pgd_t
*pgd
)
1788 free_page((unsigned long)pgd
);
1791 static pgd_t
*sun4c_get_pgd_fast(void)
1795 if ((ret
= pgd_quicklist
) != NULL
) {
1796 pgd_quicklist
= (unsigned long *)(*ret
);
1798 pgtable_cache_size
--;
1802 ret
= (unsigned long *)__get_free_page(GFP_KERNEL
);
1803 memset (ret
, 0, (KERNBASE
/ SUN4C_PGDIR_SIZE
) * sizeof(pgd_t
));
1804 init
= sun4c_pgd_offset(&init_mm
, 0);
1805 memcpy (((pgd_t
*)ret
) + USER_PTRS_PER_PGD
, init
+ USER_PTRS_PER_PGD
,
1806 (PTRS_PER_PGD
- USER_PTRS_PER_PGD
) * sizeof(pgd_t
));
1808 return (pgd_t
*)ret
;
1811 static void sun4c_free_pgd_fast(pgd_t
*pgd
)
1813 *(unsigned long *)pgd
= (unsigned long) pgd_quicklist
;
1814 pgd_quicklist
= (unsigned long *) pgd
;
1815 pgtable_cache_size
++;
1819 static inline pte_t
*
1820 sun4c_pte_alloc_one_fast(struct mm_struct
*mm
, unsigned long address
)
1824 if ((ret
= (unsigned long *)pte_quicklist
) != NULL
) {
1825 pte_quicklist
= (unsigned long *)(*ret
);
1827 pgtable_cache_size
--;
1829 return (pte_t
*)ret
;
1832 static pte_t
*sun4c_pte_alloc_one_kernel(struct mm_struct
*mm
, unsigned long address
)
1836 if ((pte
= sun4c_pte_alloc_one_fast(mm
, address
)) != NULL
)
1839 pte
= (pte_t
*)get_zeroed_page(GFP_KERNEL
|__GFP_REPEAT
);
1843 static pgtable_t
sun4c_pte_alloc_one(struct mm_struct
*mm
, unsigned long address
)
1848 pte
= sun4c_pte_alloc_one_kernel(mm
, address
);
1851 page
= virt_to_page(pte
);
1852 pgtable_page_ctor(page
);
1856 static inline void sun4c_free_pte_fast(pte_t
*pte
)
1858 *(unsigned long *)pte
= (unsigned long) pte_quicklist
;
1859 pte_quicklist
= (unsigned long *) pte
;
1860 pgtable_cache_size
++;
1863 static void sun4c_pte_free(pgtable_t pte
)
1865 pgtable_page_dtor(pte
);
1866 sun4c_free_pte_fast(page_address(pte
));
1870 * allocating and freeing a pmd is trivial: the 1-entry pmd is
1871 * inside the pgd, so has no extra memory associated with it.
1873 static pmd_t
*sun4c_pmd_alloc_one(struct mm_struct
*mm
, unsigned long address
)
1879 static void sun4c_free_pmd_fast(pmd_t
* pmd
) { }
1881 static void sun4c_check_pgt_cache(int low
, int high
)
1883 if (pgtable_cache_size
> high
) {
1886 sun4c_free_pgd_slow(sun4c_get_pgd_fast());
1888 sun4c_free_pte_slow(sun4c_pte_alloc_one_fast(NULL
, 0));
1889 } while (pgtable_cache_size
> low
);
1893 /* An experiment, turn off by default for now... -DaveM */
1894 #define SUN4C_PRELOAD_PSEG
1896 void sun4c_update_mmu_cache(struct vm_area_struct
*vma
, unsigned long address
, pte_t pte
)
1898 unsigned long flags
;
1901 if (vma
->vm_mm
->context
== NO_CONTEXT
)
1904 local_irq_save(flags
);
1905 address
&= PAGE_MASK
;
1906 if ((pseg
= sun4c_get_segmap(address
)) == invalid_segment
) {
1907 struct sun4c_mmu_entry
*entry
= sun4c_user_strategy();
1908 struct mm_struct
*mm
= vma
->vm_mm
;
1909 unsigned long start
, end
;
1911 entry
->vaddr
= start
= (address
& SUN4C_REAL_PGDIR_MASK
);
1912 entry
->ctx
= mm
->context
;
1913 add_ring_ordered(sun4c_context_ring
+ mm
->context
, entry
);
1914 sun4c_put_segmap(entry
->vaddr
, entry
->pseg
);
1915 end
= start
+ SUN4C_REAL_PGDIR_SIZE
;
1916 while (start
< end
) {
1917 #ifdef SUN4C_PRELOAD_PSEG
1918 pgd_t
*pgdp
= sun4c_pgd_offset(mm
, start
);
1923 ptep
= sun4c_pte_offset_kernel((pmd_t
*) pgdp
, start
);
1924 if (!ptep
|| !(pte_val(*ptep
) & _SUN4C_PAGE_PRESENT
))
1926 sun4c_put_pte(start
, pte_val(*ptep
));
1931 sun4c_put_pte(start
, 0);
1932 #ifdef SUN4C_PRELOAD_PSEG
1937 #ifndef SUN4C_PRELOAD_PSEG
1938 sun4c_put_pte(address
, pte_val(pte
));
1940 local_irq_restore(flags
);
1943 struct sun4c_mmu_entry
*entry
= &mmu_entry_pool
[pseg
];
1949 sun4c_put_pte(address
, pte_val(pte
));
1950 local_irq_restore(flags
);
1953 extern void sparc_context_init(int);
1954 extern unsigned long end
;
1955 extern unsigned long bootmem_init(unsigned long *pages_avail
);
1956 extern unsigned long last_valid_pfn
;
1958 void __init
sun4c_paging_init(void)
1961 unsigned long kernel_end
, vaddr
;
1962 extern struct resource sparc_iomap
;
1963 unsigned long end_pfn
, pages_avail
;
1965 kernel_end
= (unsigned long) &end
;
1966 kernel_end
= SUN4C_REAL_PGDIR_ALIGN(kernel_end
);
1969 last_valid_pfn
= bootmem_init(&pages_avail
);
1970 end_pfn
= last_valid_pfn
;
1973 invalid_segment
= (num_segmaps
- 1);
1974 sun4c_init_mmu_entry_pool();
1976 sun4c_init_map_kernelprom(kernel_end
);
1977 sun4c_init_clean_mmu(kernel_end
);
1978 sun4c_init_fill_kernel_ring(SUN4C_KERNEL_BUCKETS
);
1979 sun4c_init_lock_area(sparc_iomap
.start
, IOBASE_END
);
1980 sun4c_init_lock_area(DVMA_VADDR
, DVMA_END
);
1981 sun4c_init_lock_areas();
1982 sun4c_init_fill_user_ring();
1984 sun4c_set_context(0);
1985 memset(swapper_pg_dir
, 0, PAGE_SIZE
);
1986 memset(pg0
, 0, PAGE_SIZE
);
1987 memset(pg1
, 0, PAGE_SIZE
);
1988 memset(pg2
, 0, PAGE_SIZE
);
1989 memset(pg3
, 0, PAGE_SIZE
);
1991 /* Save work later. */
1992 vaddr
= VMALLOC_START
;
1993 swapper_pg_dir
[vaddr
>>SUN4C_PGDIR_SHIFT
] = __pgd(PGD_TABLE
| (unsigned long) pg0
);
1994 vaddr
+= SUN4C_PGDIR_SIZE
;
1995 swapper_pg_dir
[vaddr
>>SUN4C_PGDIR_SHIFT
] = __pgd(PGD_TABLE
| (unsigned long) pg1
);
1996 vaddr
+= SUN4C_PGDIR_SIZE
;
1997 swapper_pg_dir
[vaddr
>>SUN4C_PGDIR_SHIFT
] = __pgd(PGD_TABLE
| (unsigned long) pg2
);
1998 vaddr
+= SUN4C_PGDIR_SIZE
;
1999 swapper_pg_dir
[vaddr
>>SUN4C_PGDIR_SHIFT
] = __pgd(PGD_TABLE
| (unsigned long) pg3
);
2000 sun4c_init_ss2_cache_bug();
2001 sparc_context_init(num_contexts
);
2004 unsigned long zones_size
[MAX_NR_ZONES
];
2005 unsigned long zholes_size
[MAX_NR_ZONES
];
2006 unsigned long npages
;
2009 for (znum
= 0; znum
< MAX_NR_ZONES
; znum
++)
2010 zones_size
[znum
] = zholes_size
[znum
] = 0;
2012 npages
= max_low_pfn
- pfn_base
;
2014 zones_size
[ZONE_DMA
] = npages
;
2015 zholes_size
[ZONE_DMA
] = npages
- pages_avail
;
2017 npages
= highend_pfn
- max_low_pfn
;
2018 zones_size
[ZONE_HIGHMEM
] = npages
;
2019 zholes_size
[ZONE_HIGHMEM
] = npages
- calc_highpages();
2021 free_area_init_node(0, zones_size
, pfn_base
, zholes_size
);
2025 for (i
= 0; i
< num_segmaps
; i
++)
2026 if (mmu_entry_pool
[i
].locked
)
2029 max_user_taken_entries
= num_segmaps
- cnt
- 40 - 1;
2031 printk("SUN4C: %d mmu entries for the kernel\n", cnt
);
2034 static pgprot_t
sun4c_pgprot_noncached(pgprot_t prot
)
2036 prot
|= __pgprot(_SUN4C_PAGE_IO
| _SUN4C_PAGE_NOCACHE
);
2041 /* Load up routines and constants for sun4c mmu */
2042 void __init
ld_mmu_sun4c(void)
2044 extern void ___xchg32_sun4c(void);
2046 printk("Loading sun4c MMU routines\n");
2048 /* First the constants */
2049 BTFIXUPSET_SIMM13(pgdir_shift
, SUN4C_PGDIR_SHIFT
);
2050 BTFIXUPSET_SETHI(pgdir_size
, SUN4C_PGDIR_SIZE
);
2051 BTFIXUPSET_SETHI(pgdir_mask
, SUN4C_PGDIR_MASK
);
2053 BTFIXUPSET_SIMM13(ptrs_per_pmd
, SUN4C_PTRS_PER_PMD
);
2054 BTFIXUPSET_SIMM13(ptrs_per_pgd
, SUN4C_PTRS_PER_PGD
);
2055 BTFIXUPSET_SIMM13(user_ptrs_per_pgd
, KERNBASE
/ SUN4C_PGDIR_SIZE
);
2057 BTFIXUPSET_INT(page_none
, pgprot_val(SUN4C_PAGE_NONE
));
2058 PAGE_SHARED
= pgprot_val(SUN4C_PAGE_SHARED
);
2059 BTFIXUPSET_INT(page_copy
, pgprot_val(SUN4C_PAGE_COPY
));
2060 BTFIXUPSET_INT(page_readonly
, pgprot_val(SUN4C_PAGE_READONLY
));
2061 BTFIXUPSET_INT(page_kernel
, pgprot_val(SUN4C_PAGE_KERNEL
));
2062 page_kernel
= pgprot_val(SUN4C_PAGE_KERNEL
);
2065 BTFIXUPSET_CALL(pgprot_noncached
, sun4c_pgprot_noncached
, BTFIXUPCALL_NORM
);
2066 BTFIXUPSET_CALL(___xchg32
, ___xchg32_sun4c
, BTFIXUPCALL_NORM
);
2067 BTFIXUPSET_CALL(do_check_pgt_cache
, sun4c_check_pgt_cache
, BTFIXUPCALL_NORM
);
2069 BTFIXUPSET_CALL(flush_cache_all
, sun4c_flush_cache_all
, BTFIXUPCALL_NORM
);
2071 if (sun4c_vacinfo
.do_hwflushes
) {
2072 BTFIXUPSET_CALL(sun4c_flush_page
, sun4c_flush_page_hw
, BTFIXUPCALL_NORM
);
2073 BTFIXUPSET_CALL(sun4c_flush_segment
, sun4c_flush_segment_hw
, BTFIXUPCALL_NORM
);
2074 BTFIXUPSET_CALL(sun4c_flush_context
, sun4c_flush_context_hw
, BTFIXUPCALL_NORM
);
2076 BTFIXUPSET_CALL(sun4c_flush_page
, sun4c_flush_page_sw
, BTFIXUPCALL_NORM
);
2077 BTFIXUPSET_CALL(sun4c_flush_segment
, sun4c_flush_segment_sw
, BTFIXUPCALL_NORM
);
2078 BTFIXUPSET_CALL(sun4c_flush_context
, sun4c_flush_context_sw
, BTFIXUPCALL_NORM
);
2081 BTFIXUPSET_CALL(flush_tlb_mm
, sun4c_flush_tlb_mm
, BTFIXUPCALL_NORM
);
2082 BTFIXUPSET_CALL(flush_cache_mm
, sun4c_flush_cache_mm
, BTFIXUPCALL_NORM
);
2083 BTFIXUPSET_CALL(destroy_context
, sun4c_destroy_context
, BTFIXUPCALL_NORM
);
2084 BTFIXUPSET_CALL(switch_mm
, sun4c_switch_mm
, BTFIXUPCALL_NORM
);
2085 BTFIXUPSET_CALL(flush_cache_page
, sun4c_flush_cache_page
, BTFIXUPCALL_NORM
);
2086 BTFIXUPSET_CALL(flush_tlb_page
, sun4c_flush_tlb_page
, BTFIXUPCALL_NORM
);
2087 BTFIXUPSET_CALL(flush_tlb_range
, sun4c_flush_tlb_range
, BTFIXUPCALL_NORM
);
2088 BTFIXUPSET_CALL(flush_cache_range
, sun4c_flush_cache_range
, BTFIXUPCALL_NORM
);
2089 BTFIXUPSET_CALL(__flush_page_to_ram
, sun4c_flush_page_to_ram
, BTFIXUPCALL_NORM
);
2090 BTFIXUPSET_CALL(flush_tlb_all
, sun4c_flush_tlb_all
, BTFIXUPCALL_NORM
);
2092 BTFIXUPSET_CALL(flush_sig_insns
, sun4c_flush_sig_insns
, BTFIXUPCALL_NOP
);
2094 BTFIXUPSET_CALL(set_pte
, sun4c_set_pte
, BTFIXUPCALL_STO1O0
);
2096 /* The 2.4.18 code does not set this on sun4c, how does it work? XXX */
2097 /* BTFIXUPSET_SETHI(none_mask, 0x00000000); */ /* Defaults to zero? */
2099 BTFIXUPSET_CALL(pte_pfn
, sun4c_pte_pfn
, BTFIXUPCALL_NORM
);
2100 #if 0 /* PAGE_SHIFT <= 12 */ /* Eek. Investigate. XXX */
2101 BTFIXUPSET_CALL(pmd_page
, sun4c_pmd_page
, BTFIXUPCALL_ANDNINT(PAGE_SIZE
- 1));
2103 BTFIXUPSET_CALL(pmd_page
, sun4c_pmd_page
, BTFIXUPCALL_NORM
);
2105 BTFIXUPSET_CALL(pmd_set
, sun4c_pmd_set
, BTFIXUPCALL_NORM
);
2106 BTFIXUPSET_CALL(pmd_populate
, sun4c_pmd_populate
, BTFIXUPCALL_NORM
);
2108 BTFIXUPSET_CALL(pte_present
, sun4c_pte_present
, BTFIXUPCALL_NORM
);
2109 BTFIXUPSET_CALL(pte_clear
, sun4c_pte_clear
, BTFIXUPCALL_STG0O0
);
2111 BTFIXUPSET_CALL(pmd_bad
, sun4c_pmd_bad
, BTFIXUPCALL_NORM
);
2112 BTFIXUPSET_CALL(pmd_present
, sun4c_pmd_present
, BTFIXUPCALL_NORM
);
2113 BTFIXUPSET_CALL(pmd_clear
, sun4c_pmd_clear
, BTFIXUPCALL_STG0O0
);
2115 BTFIXUPSET_CALL(pgd_none
, sun4c_pgd_none
, BTFIXUPCALL_RETINT(0));
2116 BTFIXUPSET_CALL(pgd_bad
, sun4c_pgd_bad
, BTFIXUPCALL_RETINT(0));
2117 BTFIXUPSET_CALL(pgd_present
, sun4c_pgd_present
, BTFIXUPCALL_RETINT(1));
2118 BTFIXUPSET_CALL(pgd_clear
, sun4c_pgd_clear
, BTFIXUPCALL_NOP
);
2120 BTFIXUPSET_CALL(mk_pte
, sun4c_mk_pte
, BTFIXUPCALL_NORM
);
2121 BTFIXUPSET_CALL(mk_pte_phys
, sun4c_mk_pte_phys
, BTFIXUPCALL_NORM
);
2122 BTFIXUPSET_CALL(mk_pte_io
, sun4c_mk_pte_io
, BTFIXUPCALL_NORM
);
2124 BTFIXUPSET_INT(pte_modify_mask
, _SUN4C_PAGE_CHG_MASK
);
2125 BTFIXUPSET_CALL(pmd_offset
, sun4c_pmd_offset
, BTFIXUPCALL_NORM
);
2126 BTFIXUPSET_CALL(pte_offset_kernel
, sun4c_pte_offset_kernel
, BTFIXUPCALL_NORM
);
2127 BTFIXUPSET_CALL(free_pte_fast
, sun4c_free_pte_fast
, BTFIXUPCALL_NORM
);
2128 BTFIXUPSET_CALL(pte_free
, sun4c_pte_free
, BTFIXUPCALL_NORM
);
2129 BTFIXUPSET_CALL(pte_alloc_one_kernel
, sun4c_pte_alloc_one_kernel
, BTFIXUPCALL_NORM
);
2130 BTFIXUPSET_CALL(pte_alloc_one
, sun4c_pte_alloc_one
, BTFIXUPCALL_NORM
);
2131 BTFIXUPSET_CALL(free_pmd_fast
, sun4c_free_pmd_fast
, BTFIXUPCALL_NOP
);
2132 BTFIXUPSET_CALL(pmd_alloc_one
, sun4c_pmd_alloc_one
, BTFIXUPCALL_RETO0
);
2133 BTFIXUPSET_CALL(free_pgd_fast
, sun4c_free_pgd_fast
, BTFIXUPCALL_NORM
);
2134 BTFIXUPSET_CALL(get_pgd_fast
, sun4c_get_pgd_fast
, BTFIXUPCALL_NORM
);
2136 BTFIXUPSET_HALF(pte_writei
, _SUN4C_PAGE_WRITE
);
2137 BTFIXUPSET_HALF(pte_dirtyi
, _SUN4C_PAGE_MODIFIED
);
2138 BTFIXUPSET_HALF(pte_youngi
, _SUN4C_PAGE_ACCESSED
);
2139 BTFIXUPSET_HALF(pte_filei
, _SUN4C_PAGE_FILE
);
2140 BTFIXUPSET_HALF(pte_wrprotecti
, _SUN4C_PAGE_WRITE
|_SUN4C_PAGE_SILENT_WRITE
);
2141 BTFIXUPSET_HALF(pte_mkcleani
, _SUN4C_PAGE_MODIFIED
|_SUN4C_PAGE_SILENT_WRITE
);
2142 BTFIXUPSET_HALF(pte_mkoldi
, _SUN4C_PAGE_ACCESSED
|_SUN4C_PAGE_SILENT_READ
);
2143 BTFIXUPSET_CALL(pte_mkwrite
, sun4c_pte_mkwrite
, BTFIXUPCALL_NORM
);
2144 BTFIXUPSET_CALL(pte_mkdirty
, sun4c_pte_mkdirty
, BTFIXUPCALL_NORM
);
2145 BTFIXUPSET_CALL(pte_mkyoung
, sun4c_pte_mkyoung
, BTFIXUPCALL_NORM
);
2146 BTFIXUPSET_CALL(update_mmu_cache
, sun4c_update_mmu_cache
, BTFIXUPCALL_NORM
);
2148 BTFIXUPSET_CALL(pte_to_pgoff
, sun4c_pte_to_pgoff
, BTFIXUPCALL_NORM
);
2149 BTFIXUPSET_CALL(pgoff_to_pte
, sun4c_pgoff_to_pte
, BTFIXUPCALL_NORM
);
2151 BTFIXUPSET_CALL(mmu_lockarea
, sun4c_lockarea
, BTFIXUPCALL_NORM
);
2152 BTFIXUPSET_CALL(mmu_unlockarea
, sun4c_unlockarea
, BTFIXUPCALL_NORM
);
2154 BTFIXUPSET_CALL(mmu_get_scsi_one
, sun4c_get_scsi_one
, BTFIXUPCALL_NORM
);
2155 BTFIXUPSET_CALL(mmu_get_scsi_sgl
, sun4c_get_scsi_sgl
, BTFIXUPCALL_NORM
);
2156 BTFIXUPSET_CALL(mmu_release_scsi_one
, sun4c_release_scsi_one
, BTFIXUPCALL_NORM
);
2157 BTFIXUPSET_CALL(mmu_release_scsi_sgl
, sun4c_release_scsi_sgl
, BTFIXUPCALL_NORM
);
2159 BTFIXUPSET_CALL(mmu_map_dma_area
, sun4c_map_dma_area
, BTFIXUPCALL_NORM
);
2160 BTFIXUPSET_CALL(mmu_unmap_dma_area
, sun4c_unmap_dma_area
, BTFIXUPCALL_NORM
);
2162 BTFIXUPSET_CALL(sparc_mapiorange
, sun4c_mapiorange
, BTFIXUPCALL_NORM
);
2163 BTFIXUPSET_CALL(sparc_unmapiorange
, sun4c_unmapiorange
, BTFIXUPCALL_NORM
);
2165 BTFIXUPSET_CALL(__swp_type
, sun4c_swp_type
, BTFIXUPCALL_NORM
);
2166 BTFIXUPSET_CALL(__swp_offset
, sun4c_swp_offset
, BTFIXUPCALL_NORM
);
2167 BTFIXUPSET_CALL(__swp_entry
, sun4c_swp_entry
, BTFIXUPCALL_NORM
);
2169 BTFIXUPSET_CALL(alloc_thread_info
, sun4c_alloc_thread_info
, BTFIXUPCALL_NORM
);
2170 BTFIXUPSET_CALL(free_thread_info
, sun4c_free_thread_info
, BTFIXUPCALL_NORM
);
2172 BTFIXUPSET_CALL(mmu_info
, sun4c_mmu_info
, BTFIXUPCALL_NORM
);
2174 /* These should _never_ get called with two level tables. */
2175 BTFIXUPSET_CALL(pgd_set
, sun4c_pgd_set
, BTFIXUPCALL_NOP
);
2176 BTFIXUPSET_CALL(pgd_page_vaddr
, sun4c_pgd_page
, BTFIXUPCALL_RETO0
);