1 /* $Id: srmmu.c,v 1.233 2001/11/13 00:49:27 davem Exp $
2 * srmmu.c: SRMMU specific routines for memory management.
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Pete Zaitcev
6 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1999,2000 Anton Blanchard (anton@samba.org)
11 #include <linux/config.h>
12 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/vmalloc.h>
16 #include <linux/pagemap.h>
17 #include <linux/init.h>
18 #include <linux/blk.h>
19 #include <linux/spinlock.h>
20 #include <linux/bootmem.h>
22 #include <linux/seq_file.h>
25 #include <asm/pgalloc.h>
26 #include <asm/pgtable.h>
28 #include <asm/kdebug.h>
29 #include <asm/vaddrs.h>
30 #include <asm/traps.h>
33 #include <asm/cache.h>
34 #include <asm/oplib.h>
38 #include <asm/a.out.h>
39 #include <asm/mmu_context.h>
40 #include <asm/io-unit.h>
42 /* Now the cpu specific definitions. */
43 #include <asm/viking.h>
46 #include <asm/tsunami.h>
47 #include <asm/swift.h>
48 #include <asm/turbosparc.h>
50 #include <asm/btfixup.h>
52 enum mbus_module srmmu_modtype;
53 unsigned int hwbug_bitmask;
57 extern struct resource sparc_iomap;
59 extern unsigned long last_valid_pfn;
61 extern unsigned long page_kernel;
63 pgd_t *srmmu_swapper_pg_dir;
66 #define FLUSH_BEGIN(mm)
69 #define FLUSH_BEGIN(mm) if((mm)->context != NO_CONTEXT) {
73 BTFIXUPDEF_CALL(void, flush_page_for_dma, unsigned long)
74 #define flush_page_for_dma(page) BTFIXUP_CALL(flush_page_for_dma)(page)
76 int flush_page_for_dma_global = 1;
79 BTFIXUPDEF_CALL(void, local_flush_page_for_dma, unsigned long)
80 #define local_flush_page_for_dma(page) BTFIXUP_CALL(local_flush_page_for_dma)(page)
85 ctxd_t *srmmu_ctx_table_phys;
86 ctxd_t *srmmu_context_table;
88 int viking_mxcc_present;
89 static spinlock_t srmmu_context_spinlock = SPIN_LOCK_UNLOCKED;
94 * In general all page table modifications should use the V8 atomic
95 * swap instruction. This insures the mmu and the cpu are in sync
96 * with respect to ref/mod bits in the page tables.
98 static inline unsigned long srmmu_swap(unsigned long *addr, unsigned long value)
100 __asm__ __volatile__("swap [%2], %0" : "=&r" (value) : "0" (value), "r" (addr));
104 static inline void srmmu_set_pte(pte_t *ptep, pte_t pteval)
106 srmmu_swap((unsigned long *)ptep, pte_val(pteval));
109 /* The very generic SRMMU page table operations. */
110 static inline int srmmu_device_memory(unsigned long x)
112 return ((x & 0xF0000000) != 0);
115 int srmmu_cache_pagetables;
117 /* these will be initialized in srmmu_nocache_calcsize() */
118 int srmmu_nocache_npages;
119 unsigned long srmmu_nocache_size;
120 unsigned long srmmu_nocache_end;
121 unsigned long pkmap_base;
122 unsigned long pkmap_base_end;
123 unsigned long srmmu_nocache_bitmap_size;
124 extern unsigned long fix_kmap_begin;
125 extern unsigned long fix_kmap_end;
127 #define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4)
129 /* The context table is a nocache user with the biggest alignment needs. */
130 #define SRMMU_NOCACHE_ALIGN_MAX (sizeof(ctxd_t)*SRMMU_MAX_CONTEXTS)
132 void *srmmu_nocache_pool;
133 void *srmmu_nocache_bitmap;
134 int srmmu_nocache_low;
135 int srmmu_nocache_used;
136 static spinlock_t srmmu_nocache_spinlock = SPIN_LOCK_UNLOCKED;
138 /* This makes sense. Honest it does - Anton */
139 #define __nocache_pa(VADDR) (((unsigned long)VADDR) - SRMMU_NOCACHE_VADDR + __pa((unsigned long)srmmu_nocache_pool))
140 #define __nocache_va(PADDR) (__va((unsigned long)PADDR) - (unsigned long)srmmu_nocache_pool + SRMMU_NOCACHE_VADDR)
141 #define __nocache_fix(VADDR) __va(__nocache_pa(VADDR))
143 static inline unsigned long srmmu_pgd_page(pgd_t pgd)
144 { return srmmu_device_memory(pgd_val(pgd))?~0:(unsigned long)__nocache_va((pgd_val(pgd) & SRMMU_PTD_PMASK) << 4); }
146 static inline unsigned long srmmu_pmd_page(pmd_t pmd)
147 { return srmmu_device_memory(pmd_val(pmd))?~0:(unsigned long)__nocache_va((pmd_val(pmd) & SRMMU_PTD_PMASK) << 4); }
149 static inline struct page *srmmu_pte_page(pte_t pte)
150 { return (mem_map + (unsigned long)(srmmu_device_memory(pte_val(pte))?~0:(((pte_val(pte) & SRMMU_PTE_PMASK) << 4) >> PAGE_SHIFT))); }
152 static inline int srmmu_pte_none(pte_t pte)
153 { return !(pte_val(pte) & 0xFFFFFFF); }
155 static inline int srmmu_pte_present(pte_t pte)
156 { return ((pte_val(pte) & SRMMU_ET_MASK) == SRMMU_ET_PTE); }
158 static inline void srmmu_pte_clear(pte_t *ptep)
159 { srmmu_set_pte(ptep, __pte(0)); }
161 static inline int srmmu_pmd_none(pmd_t pmd)
162 { return !(pmd_val(pmd) & 0xFFFFFFF); }
164 static inline int srmmu_pmd_bad(pmd_t pmd)
165 { return (pmd_val(pmd) & SRMMU_ET_MASK) != SRMMU_ET_PTD; }
167 static inline int srmmu_pmd_present(pmd_t pmd)
168 { return ((pmd_val(pmd) & SRMMU_ET_MASK) == SRMMU_ET_PTD); }
170 static inline void srmmu_pmd_clear(pmd_t *pmdp)
171 { srmmu_set_pte((pte_t *)pmdp, __pte(0)); }
173 static inline int srmmu_pgd_none(pgd_t pgd)
174 { return !(pgd_val(pgd) & 0xFFFFFFF); }
176 static inline int srmmu_pgd_bad(pgd_t pgd)
177 { return (pgd_val(pgd) & SRMMU_ET_MASK) != SRMMU_ET_PTD; }
179 static inline int srmmu_pgd_present(pgd_t pgd)
180 { return ((pgd_val(pgd) & SRMMU_ET_MASK) == SRMMU_ET_PTD); }
182 static inline void srmmu_pgd_clear(pgd_t * pgdp)
183 { srmmu_set_pte((pte_t *)pgdp, __pte(0)); }
185 static inline int srmmu_pte_write(pte_t pte)
186 { return pte_val(pte) & SRMMU_WRITE; }
188 static inline int srmmu_pte_dirty(pte_t pte)
189 { return pte_val(pte) & SRMMU_DIRTY; }
191 static inline int srmmu_pte_young(pte_t pte)
192 { return pte_val(pte) & SRMMU_REF; }
194 static inline pte_t srmmu_pte_wrprotect(pte_t pte)
195 { return __pte(pte_val(pte) & ~SRMMU_WRITE);}
197 static inline pte_t srmmu_pte_mkclean(pte_t pte)
198 { return __pte(pte_val(pte) & ~SRMMU_DIRTY);}
200 static inline pte_t srmmu_pte_mkold(pte_t pte)
201 { return __pte(pte_val(pte) & ~SRMMU_REF);}
203 static inline pte_t srmmu_pte_mkwrite(pte_t pte)
204 { return __pte(pte_val(pte) | SRMMU_WRITE);}
206 static inline pte_t srmmu_pte_mkdirty(pte_t pte)
207 { return __pte(pte_val(pte) | SRMMU_DIRTY);}
209 static inline pte_t srmmu_pte_mkyoung(pte_t pte)
210 { return __pte(pte_val(pte) | SRMMU_REF);}
213 * Conversion functions: convert a page and protection to a page entry,
214 * and a page entry and page directory to the page they refer to.
216 static pte_t srmmu_mk_pte(struct page *page, pgprot_t pgprot)
217 { return __pte((((page - mem_map) << PAGE_SHIFT) >> 4) | pgprot_val(pgprot)); }
219 static pte_t srmmu_mk_pte_phys(unsigned long page, pgprot_t pgprot)
220 { return __pte(((page) >> 4) | pgprot_val(pgprot)); }
222 static pte_t srmmu_mk_pte_io(unsigned long page, pgprot_t pgprot, int space)
223 { return __pte(((page) >> 4) | (space << 28) | pgprot_val(pgprot)); }
225 /* XXX should we hyper_flush_whole_icache here - Anton */
226 static inline void srmmu_ctxd_set(ctxd_t *ctxp, pgd_t *pgdp)
227 { srmmu_set_pte((pte_t *)ctxp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) pgdp) >> 4))); }
229 static inline void srmmu_pgd_set(pgd_t * pgdp, pmd_t * pmdp)
230 { srmmu_set_pte((pte_t *)pgdp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) pmdp) >> 4))); }
232 static inline void srmmu_pmd_set(pmd_t * pmdp, pte_t * ptep)
233 { srmmu_set_pte((pte_t *)pmdp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) ptep) >> 4))); }
235 static inline pte_t srmmu_pte_modify(pte_t pte, pgprot_t newprot)
236 { return __pte((pte_val(pte) & SRMMU_CHG_MASK) | pgprot_val(newprot)); }
238 /* to find an entry in a top-level page table... */
239 extern inline pgd_t *srmmu_pgd_offset(struct mm_struct * mm, unsigned long address)
240 { return mm->pgd + (address >> SRMMU_PGDIR_SHIFT); }
242 /* Find an entry in the second-level page table.. */
243 static inline pmd_t *srmmu_pmd_offset(pgd_t * dir, unsigned long address)
244 { return (pmd_t *) srmmu_pgd_page(*dir) + ((address >> SRMMU_PMD_SHIFT) & (SRMMU_PTRS_PER_PMD - 1)); }
246 /* Find an entry in the third-level page table.. */
247 static inline pte_t *srmmu_pte_offset(pmd_t * dir, unsigned long address)
248 { return (pte_t *) srmmu_pmd_page(*dir) + ((address >> PAGE_SHIFT) & (SRMMU_PTRS_PER_PTE - 1)); }
250 unsigned long __srmmu_get_nocache(int size, int align)
252 int offset = srmmu_nocache_low;
254 unsigned long va_tmp, phys_tmp;
255 int lowest_failed = 0;
257 size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
259 spin_lock(&srmmu_nocache_spinlock);
262 offset = find_next_zero_bit(srmmu_nocache_bitmap, srmmu_nocache_bitmap_size, offset);
264 /* we align on physical address */
266 BUG_ON(align > SRMMU_NOCACHE_ALIGN_MAX);
267 va_tmp = (SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT));
268 phys_tmp = (__nocache_pa(va_tmp) + align - 1) & ~(align - 1);
269 va_tmp = (unsigned long)__nocache_va(phys_tmp);
270 offset = (va_tmp - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
273 if ((srmmu_nocache_bitmap_size - offset) < size) {
274 printk("Run out of nocached RAM!\n");
275 spin_unlock(&srmmu_nocache_spinlock);
281 if (test_bit(offset + i, srmmu_nocache_bitmap)) {
283 offset = offset + i + 1;
291 set_bit(offset + i, srmmu_nocache_bitmap);
293 srmmu_nocache_used++;
296 if (!lowest_failed && ((align >> SRMMU_NOCACHE_BITMAP_SHIFT) <= 1) && (offset > srmmu_nocache_low))
297 srmmu_nocache_low = offset;
299 spin_unlock(&srmmu_nocache_spinlock);
301 return (SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT));
304 unsigned inline long srmmu_get_nocache(int size, int align)
308 tmp = __srmmu_get_nocache(size, align);
311 memset((void *)tmp, 0, size);
316 void srmmu_free_nocache(unsigned long vaddr, int size)
318 int offset = (vaddr - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
320 size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
322 spin_lock(&srmmu_nocache_spinlock);
325 clear_bit(offset + size, srmmu_nocache_bitmap);
326 srmmu_nocache_used--;
329 if (offset < srmmu_nocache_low)
330 srmmu_nocache_low = offset;
332 spin_unlock(&srmmu_nocache_spinlock);
335 void srmmu_early_allocate_ptable_skeleton(unsigned long start, unsigned long end);
337 extern unsigned long probe_memory(void); /* in fault.c */
339 /* Reserve nocache dynamically proportionally to the amount of
340 * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
342 void srmmu_nocache_calcsize(void)
344 unsigned long sysmemavail = probe_memory() / 1024;
346 srmmu_nocache_npages =
347 sysmemavail / SRMMU_NOCACHE_ALCRATIO / 1024 * 256;
348 if (sysmemavail % (SRMMU_NOCACHE_ALCRATIO * 1024))
349 srmmu_nocache_npages += 256;
351 /* anything above 1280 blows up */
352 if (srmmu_nocache_npages > 1280) srmmu_nocache_npages = 1280;
354 srmmu_nocache_size = srmmu_nocache_npages * PAGE_SIZE;
355 srmmu_nocache_bitmap_size = srmmu_nocache_npages * 16;
356 srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
357 fix_kmap_begin = srmmu_nocache_end;
358 fix_kmap_end = fix_kmap_begin + (KM_TYPE_NR * NR_CPUS - 1) * PAGE_SIZE;
359 pkmap_base = SRMMU_NOCACHE_VADDR + srmmu_nocache_size + 0x40000;
360 pkmap_base_end = pkmap_base + LAST_PKMAP * PAGE_SIZE;
362 /* printk("system memory available = %luk\nnocache ram size = %luk\n",
363 sysmemavail, srmmu_nocache_size / 1024); */
366 void srmmu_nocache_init(void)
371 unsigned long paddr, vaddr;
372 unsigned long pteval;
374 srmmu_nocache_pool = __alloc_bootmem(srmmu_nocache_size,
375 SRMMU_NOCACHE_ALIGN_MAX, 0UL);
376 memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
378 srmmu_nocache_bitmap = __alloc_bootmem(srmmu_nocache_bitmap_size, SMP_CACHE_BYTES, 0UL);
379 memset(srmmu_nocache_bitmap, 0, srmmu_nocache_bitmap_size);
381 srmmu_swapper_pg_dir = (pgd_t *)__srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
382 memset(__nocache_fix(srmmu_swapper_pg_dir), 0, SRMMU_PGD_TABLE_SIZE);
383 init_mm.pgd = srmmu_swapper_pg_dir;
385 srmmu_early_allocate_ptable_skeleton(SRMMU_NOCACHE_VADDR, srmmu_nocache_end);
387 spin_lock_init(&srmmu_nocache_spinlock);
389 paddr = __pa((unsigned long)srmmu_nocache_pool);
390 vaddr = SRMMU_NOCACHE_VADDR;
392 while (vaddr < srmmu_nocache_end) {
393 pgd = pgd_offset_k(vaddr);
394 pmd = srmmu_pmd_offset(__nocache_fix(pgd), vaddr);
395 pte = srmmu_pte_offset(__nocache_fix(pmd), vaddr);
397 pteval = ((paddr >> 4) | SRMMU_ET_PTE | SRMMU_PRIV);
399 if (srmmu_cache_pagetables)
400 pteval |= SRMMU_CACHE;
402 srmmu_set_pte(__nocache_fix(pte), pteval);
412 static inline pgd_t *srmmu_get_pgd_fast(void)
416 pgd = (pgd_t *)__srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
418 pgd_t *init = pgd_offset_k(0);
419 memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
420 memcpy(pgd + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
421 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
427 static void srmmu_free_pgd_fast(pgd_t *pgd)
429 srmmu_free_nocache((unsigned long)pgd, SRMMU_PGD_TABLE_SIZE);
432 static pte_t *srmmu_pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
434 return (pte_t *)srmmu_get_nocache(SRMMU_PTE_TABLE_SIZE, SRMMU_PTE_TABLE_SIZE);
437 static pte_t *srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address)
442 static void srmmu_free_pte_fast(pte_t *pte)
444 srmmu_free_nocache((unsigned long)pte, SRMMU_PTE_TABLE_SIZE);
447 static pmd_t *srmmu_pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
449 return (pmd_t *)srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
452 static void srmmu_free_pmd_fast(pmd_t * pmd)
454 srmmu_free_nocache((unsigned long)pmd, SRMMU_PMD_TABLE_SIZE);
457 static inline void alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
459 struct ctx_list *ctxp;
461 ctxp = ctx_free.next;
462 if(ctxp != &ctx_free) {
463 remove_from_ctx_list(ctxp);
464 add_to_used_ctxlist(ctxp);
465 mm->context = ctxp->ctx_number;
469 ctxp = ctx_used.next;
470 if(ctxp->ctx_mm == old_mm)
472 if(ctxp == &ctx_used)
473 panic("out of mmu contexts");
474 flush_cache_mm(ctxp->ctx_mm);
475 flush_tlb_mm(ctxp->ctx_mm);
476 remove_from_ctx_list(ctxp);
477 add_to_used_ctxlist(ctxp);
478 ctxp->ctx_mm->context = NO_CONTEXT;
480 mm->context = ctxp->ctx_number;
483 static inline void free_context(int context)
485 struct ctx_list *ctx_old;
487 ctx_old = ctx_list_pool + context;
488 remove_from_ctx_list(ctx_old);
489 add_to_free_ctxlist(ctx_old);
493 static void srmmu_switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
494 struct task_struct *tsk, int cpu)
496 if(mm->context == NO_CONTEXT) {
497 spin_lock(&srmmu_context_spinlock);
498 alloc_context(old_mm, mm);
499 spin_unlock(&srmmu_context_spinlock);
500 srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
504 hyper_flush_whole_icache();
506 srmmu_set_context(mm->context);
509 /* Low level IO area allocation on the SRMMU. */
510 void srmmu_mapioaddr(unsigned long physaddr, unsigned long virt_addr, int bus_type, int rdonly)
517 physaddr &= PAGE_MASK;
518 pgdp = pgd_offset_k(virt_addr);
519 pmdp = srmmu_pmd_offset(pgdp, virt_addr);
520 ptep = srmmu_pte_offset(pmdp, virt_addr);
521 tmp = (physaddr >> 4) | SRMMU_ET_PTE;
524 * I need to test whether this is consistent over all
525 * sun4m's. The bus_type represents the upper 4 bits of
526 * 36-bit physical address on the I/O space lines...
528 tmp |= (bus_type << 28);
530 tmp |= SRMMU_PRIV_RDONLY;
533 __flush_page_to_ram(virt_addr);
534 srmmu_set_pte(ptep, __pte(tmp));
538 void srmmu_unmapioaddr(unsigned long virt_addr)
544 pgdp = pgd_offset_k(virt_addr);
545 pmdp = srmmu_pmd_offset(pgdp, virt_addr);
546 ptep = srmmu_pte_offset(pmdp, virt_addr);
548 /* No need to flush uncacheable page. */
549 srmmu_pte_clear(ptep);
554 * On the SRMMU we do not have the problems with limited tlb entries
555 * for mapping kernel pages, so we just take things from the free page
556 * pool. As a side effect we are putting a little too much pressure
557 * on the gfp() subsystem. This setup also makes the logic of the
558 * iommu mapping code a lot easier as we can transparently handle
559 * mappings on the kernel stack without any special code as we did
562 struct task_struct *srmmu_alloc_task_struct(void)
564 return (struct task_struct *) __get_free_pages(GFP_KERNEL, 1);
567 static void srmmu_free_task_struct(struct task_struct *tsk)
569 free_pages((unsigned long)tsk, 1);
572 static void srmmu_get_task_struct(struct task_struct *tsk)
574 atomic_inc(&virt_to_page(tsk)->count);
578 extern void tsunami_flush_cache_all(void);
579 extern void tsunami_flush_cache_mm(struct mm_struct *mm);
580 extern void tsunami_flush_cache_range(struct mm_struct *mm, unsigned long start, unsigned long end);
581 extern void tsunami_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
582 extern void tsunami_flush_page_to_ram(unsigned long page);
583 extern void tsunami_flush_page_for_dma(unsigned long page);
584 extern void tsunami_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
585 extern void tsunami_flush_tlb_all(void);
586 extern void tsunami_flush_tlb_mm(struct mm_struct *mm);
587 extern void tsunami_flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end);
588 extern void tsunami_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
589 extern void tsunami_setup_blockops(void);
592 * Workaround, until we find what's going on with Swift. When low on memory,
593 * it sometimes loops in fault/handle_mm_fault incl. flush_tlb_page to find
594 * out it is already in page tables/ fault again on the same instruction.
595 * I really don't understand it, have checked it and contexts
596 * are right, flush_tlb_all is done as well, and it faults again...
599 * The following code is a deadwood that may be necessary when
600 * we start to make precise page flushes again. --zaitcev
602 static void swift_update_mmu_cache(struct vm_area_struct * vma, unsigned long address, pte_t pte)
605 static unsigned long last;
607 /* unsigned int n; */
609 if (address == last) {
610 val = srmmu_hwprobe(address);
611 if (val != 0 && pte_val(pte) != val) {
612 printk("swift_update_mmu_cache: "
613 "addr %lx put %08x probed %08x from %p\n",
614 address, pte_val(pte), val,
615 __builtin_return_address(0));
616 srmmu_flush_whole_tlb();
624 extern void swift_flush_cache_all(void);
625 extern void swift_flush_cache_mm(struct mm_struct *mm);
626 extern void swift_flush_cache_range(struct mm_struct *mm,
627 unsigned long start, unsigned long end);
628 extern void swift_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
629 extern void swift_flush_page_to_ram(unsigned long page);
630 extern void swift_flush_page_for_dma(unsigned long page);
631 extern void swift_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
632 extern void swift_flush_tlb_all(void);
633 extern void swift_flush_tlb_mm(struct mm_struct *mm);
634 extern void swift_flush_tlb_range(struct mm_struct *mm,
635 unsigned long start, unsigned long end);
636 extern void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
638 #if 0 /* P3: deadwood to debug precise flushes on Swift. */
639 void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
644 if ((ctx1 = vma->vm_mm->context) != -1) {
645 cctx = srmmu_get_context();
646 /* Is context # ever different from current context? P3 */
648 printk("flush ctx %02x curr %02x\n", ctx1, cctx);
649 srmmu_set_context(ctx1);
650 swift_flush_page(page);
651 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
652 "r" (page), "i" (ASI_M_FLUSH_PROBE));
653 srmmu_set_context(cctx);
655 /* Rm. prot. bits from virt. c. */
656 /* swift_flush_cache_all(); */
657 /* swift_flush_cache_page(vma, page); */
658 swift_flush_page(page);
660 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
661 "r" (page), "i" (ASI_M_FLUSH_PROBE));
662 /* same as above: srmmu_flush_tlb_page() */
669 * The following are all MBUS based SRMMU modules, and therefore could
670 * be found in a multiprocessor configuration. On the whole, these
671 * chips seems to be much more touchy about DVMA and page tables
672 * with respect to cache coherency.
675 /* Cypress flushes. */
676 static void cypress_flush_cache_all(void)
678 volatile unsigned long cypress_sucks;
679 unsigned long faddr, tagval;
681 flush_user_windows();
682 for(faddr = 0; faddr < 0x10000; faddr += 0x20) {
683 __asm__ __volatile__("lda [%1 + %2] %3, %0\n\t" :
685 "r" (faddr), "r" (0x40000),
686 "i" (ASI_M_DATAC_TAG));
688 /* If modified and valid, kick it. */
689 if((tagval & 0x60) == 0x60)
690 cypress_sucks = *(unsigned long *)(0xf0020000 + faddr);
694 static void cypress_flush_cache_mm(struct mm_struct *mm)
696 register unsigned long a, b, c, d, e, f, g;
697 unsigned long flags, faddr;
701 flush_user_windows();
702 __save_and_cli(flags);
703 octx = srmmu_get_context();
704 srmmu_set_context(mm->context);
705 a = 0x20; b = 0x40; c = 0x60;
706 d = 0x80; e = 0xa0; f = 0xc0; g = 0xe0;
708 faddr = (0x10000 - 0x100);
713 __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
714 "sta %%g0, [%0 + %2] %1\n\t"
715 "sta %%g0, [%0 + %3] %1\n\t"
716 "sta %%g0, [%0 + %4] %1\n\t"
717 "sta %%g0, [%0 + %5] %1\n\t"
718 "sta %%g0, [%0 + %6] %1\n\t"
719 "sta %%g0, [%0 + %7] %1\n\t"
720 "sta %%g0, [%0 + %8] %1\n\t" : :
721 "r" (faddr), "i" (ASI_M_FLUSH_CTX),
722 "r" (a), "r" (b), "r" (c), "r" (d),
723 "r" (e), "r" (f), "r" (g));
725 srmmu_set_context(octx);
726 __restore_flags(flags);
730 static void cypress_flush_cache_range(struct mm_struct *mm, unsigned long start, unsigned long end)
732 register unsigned long a, b, c, d, e, f, g;
733 unsigned long flags, faddr;
737 flush_user_windows();
738 __save_and_cli(flags);
739 octx = srmmu_get_context();
740 srmmu_set_context(mm->context);
741 a = 0x20; b = 0x40; c = 0x60;
742 d = 0x80; e = 0xa0; f = 0xc0; g = 0xe0;
744 start &= SRMMU_PMD_MASK;
746 faddr = (start + (0x10000 - 0x100));
751 __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
752 "sta %%g0, [%0 + %2] %1\n\t"
753 "sta %%g0, [%0 + %3] %1\n\t"
754 "sta %%g0, [%0 + %4] %1\n\t"
755 "sta %%g0, [%0 + %5] %1\n\t"
756 "sta %%g0, [%0 + %6] %1\n\t"
757 "sta %%g0, [%0 + %7] %1\n\t"
758 "sta %%g0, [%0 + %8] %1\n\t" : :
760 "i" (ASI_M_FLUSH_SEG),
761 "r" (a), "r" (b), "r" (c), "r" (d),
762 "r" (e), "r" (f), "r" (g));
763 } while (faddr != start);
764 start += SRMMU_PMD_SIZE;
766 srmmu_set_context(octx);
767 __restore_flags(flags);
771 static void cypress_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
773 register unsigned long a, b, c, d, e, f, g;
774 struct mm_struct *mm = vma->vm_mm;
775 unsigned long flags, line;
779 flush_user_windows();
780 __save_and_cli(flags);
781 octx = srmmu_get_context();
782 srmmu_set_context(mm->context);
783 a = 0x20; b = 0x40; c = 0x60;
784 d = 0x80; e = 0xa0; f = 0xc0; g = 0xe0;
787 line = (page + PAGE_SIZE) - 0x100;
792 __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
793 "sta %%g0, [%0 + %2] %1\n\t"
794 "sta %%g0, [%0 + %3] %1\n\t"
795 "sta %%g0, [%0 + %4] %1\n\t"
796 "sta %%g0, [%0 + %5] %1\n\t"
797 "sta %%g0, [%0 + %6] %1\n\t"
798 "sta %%g0, [%0 + %7] %1\n\t"
799 "sta %%g0, [%0 + %8] %1\n\t" : :
801 "i" (ASI_M_FLUSH_PAGE),
802 "r" (a), "r" (b), "r" (c), "r" (d),
803 "r" (e), "r" (f), "r" (g));
804 } while(line != page);
805 srmmu_set_context(octx);
806 __restore_flags(flags);
810 /* Cypress is copy-back, at least that is how we configure it. */
811 static void cypress_flush_page_to_ram(unsigned long page)
813 register unsigned long a, b, c, d, e, f, g;
816 a = 0x20; b = 0x40; c = 0x60; d = 0x80; e = 0xa0; f = 0xc0; g = 0xe0;
818 line = (page + PAGE_SIZE) - 0x100;
823 __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
824 "sta %%g0, [%0 + %2] %1\n\t"
825 "sta %%g0, [%0 + %3] %1\n\t"
826 "sta %%g0, [%0 + %4] %1\n\t"
827 "sta %%g0, [%0 + %5] %1\n\t"
828 "sta %%g0, [%0 + %6] %1\n\t"
829 "sta %%g0, [%0 + %7] %1\n\t"
830 "sta %%g0, [%0 + %8] %1\n\t" : :
832 "i" (ASI_M_FLUSH_PAGE),
833 "r" (a), "r" (b), "r" (c), "r" (d),
834 "r" (e), "r" (f), "r" (g));
835 } while(line != page);
838 /* Cypress is also IO cache coherent. */
839 static void cypress_flush_page_for_dma(unsigned long page)
843 /* Cypress has unified L2 VIPT, from which both instructions and data
844 * are stored. It does not have an onboard icache of any sort, therefore
845 * no flush is necessary.
847 static void cypress_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
851 static void cypress_flush_tlb_all(void)
853 srmmu_flush_whole_tlb();
856 static void cypress_flush_tlb_mm(struct mm_struct *mm)
859 __asm__ __volatile__(
860 "lda [%0] %3, %%g5\n\t"
861 "sta %2, [%0] %3\n\t"
862 "sta %%g0, [%1] %4\n\t"
863 "sta %%g5, [%0] %3\n"
865 : "r" (SRMMU_CTX_REG), "r" (0x300), "r" (mm->context),
866 "i" (ASI_M_MMUREGS), "i" (ASI_M_FLUSH_PROBE)
871 static void cypress_flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end)
876 start &= SRMMU_PGDIR_MASK;
877 size = SRMMU_PGDIR_ALIGN(end) - start;
878 __asm__ __volatile__(
879 "lda [%0] %5, %%g5\n\t"
882 "subcc %3, %4, %3\n\t"
884 " sta %%g0, [%2 + %3] %6\n\t"
885 "sta %%g5, [%0] %5\n"
887 : "r" (SRMMU_CTX_REG), "r" (mm->context), "r" (start | 0x200),
888 "r" (size), "r" (SRMMU_PGDIR_SIZE), "i" (ASI_M_MMUREGS),
889 "i" (ASI_M_FLUSH_PROBE)
894 static void cypress_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
896 struct mm_struct *mm = vma->vm_mm;
899 __asm__ __volatile__(
900 "lda [%0] %3, %%g5\n\t"
901 "sta %1, [%0] %3\n\t"
902 "sta %%g0, [%2] %4\n\t"
903 "sta %%g5, [%0] %3\n"
905 : "r" (SRMMU_CTX_REG), "r" (mm->context), "r" (page & PAGE_MASK),
906 "i" (ASI_M_MMUREGS), "i" (ASI_M_FLUSH_PROBE)
912 extern void viking_flush_cache_all(void);
913 extern void viking_flush_cache_mm(struct mm_struct *mm);
914 extern void viking_flush_cache_range(struct mm_struct *mm, unsigned long start,
916 extern void viking_flush_cache_page(struct vm_area_struct *vma,
918 extern void viking_flush_page_to_ram(unsigned long page);
919 extern void viking_flush_page_for_dma(unsigned long page);
920 extern void viking_flush_sig_insns(struct mm_struct *mm, unsigned long addr);
921 extern void viking_flush_page(unsigned long page);
922 extern void viking_mxcc_flush_page(unsigned long page);
923 extern void viking_flush_tlb_all(void);
924 extern void viking_flush_tlb_mm(struct mm_struct *mm);
925 extern void viking_flush_tlb_range(struct mm_struct *mm, unsigned long start,
927 extern void viking_flush_tlb_page(struct vm_area_struct *vma,
929 extern void sun4dsmp_flush_tlb_all(void);
930 extern void sun4dsmp_flush_tlb_mm(struct mm_struct *mm);
931 extern void sun4dsmp_flush_tlb_range(struct mm_struct *mm, unsigned long start,
933 extern void sun4dsmp_flush_tlb_page(struct vm_area_struct *vma,
937 extern void hypersparc_flush_cache_all(void);
938 extern void hypersparc_flush_cache_mm(struct mm_struct *mm);
939 extern void hypersparc_flush_cache_range(struct mm_struct *mm, unsigned long start, unsigned long end);
940 extern void hypersparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
941 extern void hypersparc_flush_page_to_ram(unsigned long page);
942 extern void hypersparc_flush_page_for_dma(unsigned long page);
943 extern void hypersparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
944 extern void hypersparc_flush_tlb_all(void);
945 extern void hypersparc_flush_tlb_mm(struct mm_struct *mm);
946 extern void hypersparc_flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end);
947 extern void hypersparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
948 extern void hypersparc_setup_blockops(void);
951 * NOTE: All of this startup code assumes the low 16mb (approx.) of
952 * kernel mappings are done with one single contiguous chunk of
953 * ram. On small ram machines (classics mainly) we only get
954 * around 8mb mapped for us.
957 void __init early_pgtable_allocfail(char *type)
959 prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type);
963 void __init srmmu_early_allocate_ptable_skeleton(unsigned long start, unsigned long end)
970 pgdp = pgd_offset_k(start);
971 if(srmmu_pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
972 pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
974 early_pgtable_allocfail("pmd");
975 memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
976 srmmu_pgd_set(__nocache_fix(pgdp), pmdp);
978 pmdp = srmmu_pmd_offset(__nocache_fix(pgdp), start);
979 if(srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
980 ptep = (pte_t *)__srmmu_get_nocache(SRMMU_PTE_TABLE_SIZE, SRMMU_PTE_TABLE_SIZE);
982 early_pgtable_allocfail("pte");
983 memset(__nocache_fix(ptep), 0, SRMMU_PTE_TABLE_SIZE);
984 srmmu_pmd_set(__nocache_fix(pmdp), ptep);
986 start = (start + SRMMU_PMD_SIZE) & SRMMU_PMD_MASK;
990 void __init srmmu_allocate_ptable_skeleton(unsigned long start, unsigned long end)
997 pgdp = pgd_offset_k(start);
998 if(srmmu_pgd_none(*pgdp)) {
999 pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
1001 early_pgtable_allocfail("pmd");
1002 memset(pmdp, 0, SRMMU_PMD_TABLE_SIZE);
1003 srmmu_pgd_set(pgdp, pmdp);
1005 pmdp = srmmu_pmd_offset(pgdp, start);
1006 if(srmmu_pmd_none(*pmdp)) {
1007 ptep = (pte_t *)__srmmu_get_nocache(SRMMU_PTE_TABLE_SIZE, SRMMU_PTE_TABLE_SIZE);
1009 early_pgtable_allocfail("pte");
1010 memset(ptep, 0, SRMMU_PTE_TABLE_SIZE);
1011 srmmu_pmd_set(pmdp, ptep);
1013 start = (start + SRMMU_PMD_SIZE) & SRMMU_PMD_MASK;
1018 * This is much cleaner than poking around physical address space
1019 * looking at the prom's page table directly which is what most
1020 * other OS's do. Yuck... this is much better.
1022 void __init srmmu_inherit_prom_mappings(unsigned long start,unsigned long end)
1027 int what = 0; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
1028 unsigned long prompte;
1030 while(start <= end) {
1032 break; /* probably wrap around */
1033 if(start == 0xfef00000)
1034 start = KADB_DEBUGGER_BEGVM;
1035 if(!(prompte = srmmu_hwprobe(start))) {
1040 /* A red snapper, see what it really is. */
1043 if(!(start & ~(SRMMU_PMD_MASK))) {
1044 if(srmmu_hwprobe((start-PAGE_SIZE) + SRMMU_PMD_SIZE) == prompte)
1048 if(!(start & ~(SRMMU_PGDIR_MASK))) {
1049 if(srmmu_hwprobe((start-PAGE_SIZE) + SRMMU_PGDIR_SIZE) ==
1054 pgdp = pgd_offset_k(start);
1056 *(pgd_t *)__nocache_fix(pgdp) = __pgd(prompte);
1057 start += SRMMU_PGDIR_SIZE;
1060 if(srmmu_pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
1061 pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
1063 early_pgtable_allocfail("pmd");
1064 memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
1065 srmmu_pgd_set(__nocache_fix(pgdp), pmdp);
1067 pmdp = srmmu_pmd_offset(__nocache_fix(pgdp), start);
1069 *(pmd_t *)__nocache_fix(pmdp) = __pmd(prompte);
1070 start += SRMMU_PMD_SIZE;
1073 if(srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
1074 ptep = (pte_t *)__srmmu_get_nocache(SRMMU_PTE_TABLE_SIZE, SRMMU_PTE_TABLE_SIZE);
1076 early_pgtable_allocfail("pte");
1077 memset(__nocache_fix(ptep), 0, SRMMU_PTE_TABLE_SIZE);
1078 srmmu_pmd_set(__nocache_fix(pmdp), ptep);
1080 ptep = srmmu_pte_offset(__nocache_fix(pmdp), start);
1081 *(pte_t *)__nocache_fix(ptep) = __pte(prompte);
1086 #define KERNEL_PTE(page_shifted) ((page_shifted)|SRMMU_CACHE|SRMMU_PRIV|SRMMU_VALID)
1088 /* Create a third-level SRMMU 16MB page mapping. */
1089 static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_base)
1091 pgd_t *pgdp = pgd_offset_k(vaddr);
1092 unsigned long big_pte;
1094 big_pte = KERNEL_PTE(phys_base >> 4);
1095 *(pgd_t *)__nocache_fix(pgdp) = __pgd(big_pte);
1098 /* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
1099 static unsigned long __init map_spbank(unsigned long vbase, int sp_entry)
1101 unsigned long pstart = (sp_banks[sp_entry].base_addr & SRMMU_PGDIR_MASK);
1102 unsigned long vstart = (vbase & SRMMU_PGDIR_MASK);
1103 unsigned long vend = SRMMU_PGDIR_ALIGN(vbase + sp_banks[sp_entry].num_bytes);
1104 /* Map "low" memory only */
1105 const unsigned long min_vaddr = PAGE_OFFSET;
1106 const unsigned long max_vaddr = PAGE_OFFSET + SRMMU_MAXMEM;
1108 if (vstart < min_vaddr || vstart >= max_vaddr)
1111 if (vend > max_vaddr || vend < min_vaddr)
1114 while(vstart < vend) {
1115 do_large_mapping(vstart, pstart);
1116 vstart += SRMMU_PGDIR_SIZE; pstart += SRMMU_PGDIR_SIZE;
1121 static inline void memprobe_error(char *msg)
1124 prom_printf("Halting now...\n");
1128 static inline void map_kernel(void)
1132 if (phys_base > 0) {
1133 do_large_mapping(PAGE_OFFSET, phys_base);
1136 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
1137 map_spbank((unsigned long)__va(sp_banks[i].base_addr), i);
1140 BTFIXUPSET_SIMM13(user_ptrs_per_pgd, PAGE_OFFSET / SRMMU_PGDIR_SIZE);
1143 /* Paging initialization on the Sparc Reference MMU. */
1144 extern void sparc_context_init(int);
1146 extern int linux_num_cpus;
1147 extern unsigned long totalhigh_pages;
1149 void (*poke_srmmu)(void) __initdata = NULL;
1151 extern unsigned long bootmem_init(unsigned long *pages_avail);
1152 extern void sun_serial_setup(void);
1154 void __init srmmu_paging_init(void)
1161 unsigned long pages_avail;
1163 sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
1165 if (sparc_cpu_model == sun4d)
1166 num_contexts = 65536; /* We know it is Viking */
1168 /* Find the number of contexts on the srmmu. */
1169 cpunode = prom_getchild(prom_root_node);
1171 while(cpunode != 0) {
1172 prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
1173 if(!strcmp(node_str, "cpu")) {
1174 num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
1177 cpunode = prom_getsibling(cpunode);
1182 prom_printf("Something wrong, can't find cpu node in paging_init.\n");
1187 last_valid_pfn = bootmem_init(&pages_avail);
1189 srmmu_nocache_calcsize();
1190 srmmu_nocache_init();
1191 srmmu_inherit_prom_mappings(0xfe400000,(LINUX_OPPROM_ENDVM-PAGE_SIZE));
1194 /* ctx table has to be physically aligned to its size */
1195 srmmu_context_table = (ctxd_t *)__srmmu_get_nocache(num_contexts*sizeof(ctxd_t), num_contexts*sizeof(ctxd_t));
1196 srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa((unsigned long)srmmu_context_table);
1198 for(i = 0; i < num_contexts; i++)
1199 srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
1202 srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
1207 srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
1208 srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
1211 srmmu_allocate_ptable_skeleton(fix_kmap_begin, fix_kmap_end);
1212 srmmu_allocate_ptable_skeleton(pkmap_base, pkmap_base_end);
1214 pgd = pgd_offset_k(pkmap_base);
1215 pmd = pmd_offset(pgd, pkmap_base);
1216 pte = pte_offset(pmd, pkmap_base);
1217 pkmap_page_table = pte;
1223 * This does not logically belong here, but we need to
1224 * call it at the moment we are able to use the bootmem
1229 sparc_context_init(num_contexts);
1234 unsigned long zones_size[MAX_NR_ZONES];
1235 unsigned long zholes_size[MAX_NR_ZONES];
1236 unsigned long npages;
1239 for (znum = 0; znum < MAX_NR_ZONES; znum++)
1240 zones_size[znum] = zholes_size[znum] = 0;
1242 npages = max_low_pfn - (phys_base >> PAGE_SHIFT);
1244 zones_size[ZONE_DMA] = npages;
1245 zholes_size[ZONE_DMA] = npages - pages_avail;
1247 npages = highend_pfn - max_low_pfn;
1248 zones_size[ZONE_HIGHMEM] = npages;
1249 zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
1251 free_area_init_node(0, NULL, NULL, zones_size,
1252 phys_base, zholes_size);
1256 static void srmmu_mmu_info(struct seq_file *m)
1261 "nocache total\t: %ld\n"
1262 "nocache used\t: %d\n",
1266 (srmmu_nocache_used << SRMMU_NOCACHE_BITMAP_SHIFT));
1269 static void srmmu_update_mmu_cache(struct vm_area_struct * vma, unsigned long address, pte_t pte)
1273 static void srmmu_destroy_context(struct mm_struct *mm)
1276 if(mm->context != NO_CONTEXT) {
1278 srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
1280 spin_lock(&srmmu_context_spinlock);
1281 free_context(mm->context);
1282 spin_unlock(&srmmu_context_spinlock);
1283 mm->context = NO_CONTEXT;
1287 /* Init various srmmu chip types. */
1288 static void __init srmmu_is_bad(void)
1290 prom_printf("Could not determine SRMMU chip type.\n");
1294 static void __init init_vac_layout(void)
1296 int nd, cache_lines;
1300 unsigned long max_size = 0;
1301 unsigned long min_line_size = 0x10000000;
1304 nd = prom_getchild(prom_root_node);
1305 while((nd = prom_getsibling(nd)) != 0) {
1306 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
1307 if(!strcmp(node_str, "cpu")) {
1308 vac_line_size = prom_getint(nd, "cache-line-size");
1309 if (vac_line_size == -1) {
1310 prom_printf("can't determine cache-line-size, "
1314 cache_lines = prom_getint(nd, "cache-nlines");
1315 if (cache_lines == -1) {
1316 prom_printf("can't determine cache-nlines, halting.\n");
1320 vac_cache_size = cache_lines * vac_line_size;
1322 if(vac_cache_size > max_size)
1323 max_size = vac_cache_size;
1324 if(vac_line_size < min_line_size)
1325 min_line_size = vac_line_size;
1327 if(cpu == smp_num_cpus)
1335 prom_printf("No CPU nodes found, halting.\n");
1339 vac_cache_size = max_size;
1340 vac_line_size = min_line_size;
1342 printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
1343 (int)vac_cache_size, (int)vac_line_size);
1346 static void __init poke_hypersparc(void)
1348 volatile unsigned long clear;
1349 unsigned long mreg = srmmu_get_mmureg();
1351 hyper_flush_unconditional_combined();
1353 mreg &= ~(HYPERSPARC_CWENABLE);
1354 mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
1355 mreg |= (HYPERSPARC_CMODE);
1357 srmmu_set_mmureg(mreg);
1359 #if 0 /* XXX I think this is bad news... -DaveM */
1360 hyper_clear_all_tags();
1363 put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
1364 hyper_flush_whole_icache();
1365 clear = srmmu_get_faddr();
1366 clear = srmmu_get_fstatus();
1369 static void __init init_hypersparc(void)
1371 srmmu_name = "ROSS HyperSparc";
1377 BTFIXUPSET_CALL(pte_clear, srmmu_pte_clear, BTFIXUPCALL_NORM);
1378 BTFIXUPSET_CALL(pmd_clear, srmmu_pmd_clear, BTFIXUPCALL_NORM);
1379 BTFIXUPSET_CALL(pgd_clear, srmmu_pgd_clear, BTFIXUPCALL_NORM);
1380 BTFIXUPSET_CALL(flush_cache_all, hypersparc_flush_cache_all, BTFIXUPCALL_NORM);
1381 BTFIXUPSET_CALL(flush_cache_mm, hypersparc_flush_cache_mm, BTFIXUPCALL_NORM);
1382 BTFIXUPSET_CALL(flush_cache_range, hypersparc_flush_cache_range, BTFIXUPCALL_NORM);
1383 BTFIXUPSET_CALL(flush_cache_page, hypersparc_flush_cache_page, BTFIXUPCALL_NORM);
1385 BTFIXUPSET_CALL(flush_tlb_all, hypersparc_flush_tlb_all, BTFIXUPCALL_NORM);
1386 BTFIXUPSET_CALL(flush_tlb_mm, hypersparc_flush_tlb_mm, BTFIXUPCALL_NORM);
1387 BTFIXUPSET_CALL(flush_tlb_range, hypersparc_flush_tlb_range, BTFIXUPCALL_NORM);
1388 BTFIXUPSET_CALL(flush_tlb_page, hypersparc_flush_tlb_page, BTFIXUPCALL_NORM);
1390 BTFIXUPSET_CALL(__flush_page_to_ram, hypersparc_flush_page_to_ram, BTFIXUPCALL_NORM);
1391 BTFIXUPSET_CALL(flush_sig_insns, hypersparc_flush_sig_insns, BTFIXUPCALL_NORM);
1392 BTFIXUPSET_CALL(flush_page_for_dma, hypersparc_flush_page_for_dma, BTFIXUPCALL_NOP);
1395 poke_srmmu = poke_hypersparc;
1397 hypersparc_setup_blockops();
1400 static void __init poke_cypress(void)
1402 unsigned long mreg = srmmu_get_mmureg();
1403 unsigned long faddr, tagval;
1404 volatile unsigned long cypress_sucks;
1405 volatile unsigned long clear;
1407 clear = srmmu_get_faddr();
1408 clear = srmmu_get_fstatus();
1410 if (!(mreg & CYPRESS_CENABLE)) {
1411 for(faddr = 0x0; faddr < 0x10000; faddr += 20) {
1412 __asm__ __volatile__("sta %%g0, [%0 + %1] %2\n\t"
1413 "sta %%g0, [%0] %2\n\t" : :
1414 "r" (faddr), "r" (0x40000),
1415 "i" (ASI_M_DATAC_TAG));
1418 for(faddr = 0; faddr < 0x10000; faddr += 0x20) {
1419 __asm__ __volatile__("lda [%1 + %2] %3, %0\n\t" :
1421 "r" (faddr), "r" (0x40000),
1422 "i" (ASI_M_DATAC_TAG));
1424 /* If modified and valid, kick it. */
1425 if((tagval & 0x60) == 0x60)
1426 cypress_sucks = *(unsigned long *)
1427 (0xf0020000 + faddr);
1431 /* And one more, for our good neighbor, Mr. Broken Cypress. */
1432 clear = srmmu_get_faddr();
1433 clear = srmmu_get_fstatus();
1435 mreg |= (CYPRESS_CENABLE | CYPRESS_CMODE);
1436 srmmu_set_mmureg(mreg);
1439 static void __init init_cypress_common(void)
1443 BTFIXUPSET_CALL(pte_clear, srmmu_pte_clear, BTFIXUPCALL_NORM);
1444 BTFIXUPSET_CALL(pmd_clear, srmmu_pmd_clear, BTFIXUPCALL_NORM);
1445 BTFIXUPSET_CALL(pgd_clear, srmmu_pgd_clear, BTFIXUPCALL_NORM);
1446 BTFIXUPSET_CALL(flush_cache_all, cypress_flush_cache_all, BTFIXUPCALL_NORM);
1447 BTFIXUPSET_CALL(flush_cache_mm, cypress_flush_cache_mm, BTFIXUPCALL_NORM);
1448 BTFIXUPSET_CALL(flush_cache_range, cypress_flush_cache_range, BTFIXUPCALL_NORM);
1449 BTFIXUPSET_CALL(flush_cache_page, cypress_flush_cache_page, BTFIXUPCALL_NORM);
1451 BTFIXUPSET_CALL(flush_tlb_all, cypress_flush_tlb_all, BTFIXUPCALL_NORM);
1452 BTFIXUPSET_CALL(flush_tlb_mm, cypress_flush_tlb_mm, BTFIXUPCALL_NORM);
1453 BTFIXUPSET_CALL(flush_tlb_page, cypress_flush_tlb_page, BTFIXUPCALL_NORM);
1454 BTFIXUPSET_CALL(flush_tlb_range, cypress_flush_tlb_range, BTFIXUPCALL_NORM);
1457 BTFIXUPSET_CALL(__flush_page_to_ram, cypress_flush_page_to_ram, BTFIXUPCALL_NORM);
1458 BTFIXUPSET_CALL(flush_sig_insns, cypress_flush_sig_insns, BTFIXUPCALL_NOP);
1459 BTFIXUPSET_CALL(flush_page_for_dma, cypress_flush_page_for_dma, BTFIXUPCALL_NOP);
1461 poke_srmmu = poke_cypress;
1464 static void __init init_cypress_604(void)
1466 srmmu_name = "ROSS Cypress-604(UP)";
1467 srmmu_modtype = Cypress;
1468 init_cypress_common();
1471 static void __init init_cypress_605(unsigned long mrev)
1473 srmmu_name = "ROSS Cypress-605(MP)";
1475 srmmu_modtype = Cypress_vE;
1476 hwbug_bitmask |= HWBUG_COPYBACK_BROKEN;
1479 srmmu_modtype = Cypress_vD;
1480 hwbug_bitmask |= HWBUG_ASIFLUSH_BROKEN;
1482 srmmu_modtype = Cypress;
1485 init_cypress_common();
1488 static void __init poke_swift(void)
1492 /* Clear any crap from the cache or else... */
1493 swift_flush_cache_all();
1495 /* Enable I & D caches */
1496 mreg = srmmu_get_mmureg();
1497 mreg |= (SWIFT_IE | SWIFT_DE);
1499 * The Swift branch folding logic is completely broken. At
1500 * trap time, if things are just right, if can mistakenly
1501 * think that a trap is coming from kernel mode when in fact
1502 * it is coming from user mode (it mis-executes the branch in
1503 * the trap code). So you see things like crashme completely
1504 * hosing your machine which is completely unacceptable. Turn
1505 * this shit off... nice job Fujitsu.
1507 mreg &= ~(SWIFT_BF);
1508 srmmu_set_mmureg(mreg);
1511 #define SWIFT_MASKID_ADDR 0x10003018
1512 static void __init init_swift(void)
1514 unsigned long swift_rev;
1516 __asm__ __volatile__("lda [%1] %2, %0\n\t"
1517 "srl %0, 0x18, %0\n\t" :
1519 "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
1520 srmmu_name = "Fujitsu Swift";
1526 srmmu_modtype = Swift_lots_o_bugs;
1527 hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
1529 * Gee george, I wonder why Sun is so hush hush about
1530 * this hardware bug... really braindamage stuff going
1531 * on here. However I think we can find a way to avoid
1532 * all of the workaround overhead under Linux. Basically,
1533 * any page fault can cause kernel pages to become user
1534 * accessible (the mmu gets confused and clears some of
1535 * the ACC bits in kernel ptes). Aha, sounds pretty
1536 * horrible eh? But wait, after extensive testing it appears
1537 * that if you use pgd_t level large kernel pte's (like the
1538 * 4MB pages on the Pentium) the bug does not get tripped
1539 * at all. This avoids almost all of the major overhead.
1540 * Welcome to a world where your vendor tells you to,
1541 * "apply this kernel patch" instead of "sorry for the
1542 * broken hardware, send it back and we'll give you
1543 * properly functioning parts"
1548 srmmu_modtype = Swift_bad_c;
1549 hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
1551 * You see Sun allude to this hardware bug but never
1552 * admit things directly, they'll say things like,
1553 * "the Swift chip cache problems" or similar.
1557 srmmu_modtype = Swift_ok;
1561 BTFIXUPSET_CALL(flush_cache_all, swift_flush_cache_all, BTFIXUPCALL_NORM);
1562 BTFIXUPSET_CALL(flush_cache_mm, swift_flush_cache_mm, BTFIXUPCALL_NORM);
1563 BTFIXUPSET_CALL(flush_cache_page, swift_flush_cache_page, BTFIXUPCALL_NORM);
1564 BTFIXUPSET_CALL(flush_cache_range, swift_flush_cache_range, BTFIXUPCALL_NORM);
1567 BTFIXUPSET_CALL(flush_tlb_all, swift_flush_tlb_all, BTFIXUPCALL_NORM);
1568 BTFIXUPSET_CALL(flush_tlb_mm, swift_flush_tlb_mm, BTFIXUPCALL_NORM);
1569 BTFIXUPSET_CALL(flush_tlb_page, swift_flush_tlb_page, BTFIXUPCALL_NORM);
1570 BTFIXUPSET_CALL(flush_tlb_range, swift_flush_tlb_range, BTFIXUPCALL_NORM);
1572 BTFIXUPSET_CALL(__flush_page_to_ram, swift_flush_page_to_ram, BTFIXUPCALL_NORM);
1573 BTFIXUPSET_CALL(flush_sig_insns, swift_flush_sig_insns, BTFIXUPCALL_NORM);
1574 BTFIXUPSET_CALL(flush_page_for_dma, swift_flush_page_for_dma, BTFIXUPCALL_NORM);
1576 BTFIXUPSET_CALL(update_mmu_cache, swift_update_mmu_cache, BTFIXUPCALL_NORM);
1578 flush_page_for_dma_global = 0;
1581 * Are you now convinced that the Swift is one of the
1582 * biggest VLSI abortions of all time? Bravo Fujitsu!
1583 * Fujitsu, the !#?!%$'d up processor people. I bet if
1584 * you examined the microcode of the Swift you'd find
1585 * XXX's all over the place.
1587 poke_srmmu = poke_swift;
1590 static void turbosparc_flush_cache_all(void)
1592 flush_user_windows();
1593 turbosparc_idflash_clear();
1596 static void turbosparc_flush_cache_mm(struct mm_struct *mm)
1599 flush_user_windows();
1600 turbosparc_idflash_clear();
1604 static void turbosparc_flush_cache_range(struct mm_struct *mm, unsigned long start, unsigned long end)
1607 flush_user_windows();
1608 turbosparc_idflash_clear();
1612 static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
1614 FLUSH_BEGIN(vma->vm_mm)
1615 flush_user_windows();
1616 if (vma->vm_flags & VM_EXEC)
1617 turbosparc_flush_icache();
1618 turbosparc_flush_dcache();
1622 /* TurboSparc is copy-back, if we turn it on, but this does not work. */
1623 static void turbosparc_flush_page_to_ram(unsigned long page)
1625 #ifdef TURBOSPARC_WRITEBACK
1626 volatile unsigned long clear;
1628 if (srmmu_hwprobe(page))
1629 turbosparc_flush_page_cache(page);
1630 clear = srmmu_get_fstatus();
1634 static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
1638 static void turbosparc_flush_page_for_dma(unsigned long page)
1640 turbosparc_flush_dcache();
1643 static void turbosparc_flush_tlb_all(void)
1645 srmmu_flush_whole_tlb();
1648 static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
1651 srmmu_flush_whole_tlb();
1655 static void turbosparc_flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end)
1658 srmmu_flush_whole_tlb();
1662 static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
1664 FLUSH_BEGIN(vma->vm_mm)
1665 srmmu_flush_whole_tlb();
1670 static void __init poke_turbosparc(void)
1672 unsigned long mreg = srmmu_get_mmureg();
1673 unsigned long ccreg;
1675 /* Clear any crap from the cache or else... */
1676 turbosparc_flush_cache_all();
1677 mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* Temporarily disable I & D caches */
1678 mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
1679 srmmu_set_mmureg(mreg);
1681 ccreg = turbosparc_get_ccreg();
1683 #ifdef TURBOSPARC_WRITEBACK
1684 ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
1685 ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
1686 /* Write-back D-cache, emulate VLSI
1687 * abortion number three, not number one */
1689 /* For now let's play safe, optimize later */
1690 ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
1691 /* Do DVMA snooping in Dcache, Write-thru D-cache */
1692 ccreg &= ~(TURBOSPARC_uS2);
1693 /* Emulate VLSI abortion number three, not number one */
1696 switch (ccreg & 7) {
1697 case 0: /* No SE cache */
1698 case 7: /* Test mode */
1701 ccreg |= (TURBOSPARC_SCENABLE);
1703 turbosparc_set_ccreg (ccreg);
1705 mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
1706 mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
1707 srmmu_set_mmureg(mreg);
1710 static void __init init_turbosparc(void)
1712 srmmu_name = "Fujitsu TurboSparc";
1713 srmmu_modtype = TurboSparc;
1715 BTFIXUPSET_CALL(flush_cache_all, turbosparc_flush_cache_all, BTFIXUPCALL_NORM);
1716 BTFIXUPSET_CALL(flush_cache_mm, turbosparc_flush_cache_mm, BTFIXUPCALL_NORM);
1717 BTFIXUPSET_CALL(flush_cache_page, turbosparc_flush_cache_page, BTFIXUPCALL_NORM);
1718 BTFIXUPSET_CALL(flush_cache_range, turbosparc_flush_cache_range, BTFIXUPCALL_NORM);
1720 BTFIXUPSET_CALL(flush_tlb_all, turbosparc_flush_tlb_all, BTFIXUPCALL_NORM);
1721 BTFIXUPSET_CALL(flush_tlb_mm, turbosparc_flush_tlb_mm, BTFIXUPCALL_NORM);
1722 BTFIXUPSET_CALL(flush_tlb_page, turbosparc_flush_tlb_page, BTFIXUPCALL_NORM);
1723 BTFIXUPSET_CALL(flush_tlb_range, turbosparc_flush_tlb_range, BTFIXUPCALL_NORM);
1725 BTFIXUPSET_CALL(__flush_page_to_ram, turbosparc_flush_page_to_ram, BTFIXUPCALL_NORM);
1727 BTFIXUPSET_CALL(flush_sig_insns, turbosparc_flush_sig_insns, BTFIXUPCALL_NOP);
1728 BTFIXUPSET_CALL(flush_page_for_dma, turbosparc_flush_page_for_dma, BTFIXUPCALL_NORM);
1730 poke_srmmu = poke_turbosparc;
1733 static void __init poke_tsunami(void)
1735 unsigned long mreg = srmmu_get_mmureg();
1737 tsunami_flush_icache();
1738 tsunami_flush_dcache();
1739 mreg &= ~TSUNAMI_ITD;
1740 mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
1741 srmmu_set_mmureg(mreg);
1744 static void __init init_tsunami(void)
1747 * Tsunami's pretty sane, Sun and TI actually got it
1748 * somewhat right this time. Fujitsu should have
1749 * taken some lessons from them.
1752 srmmu_name = "TI Tsunami";
1753 srmmu_modtype = Tsunami;
1755 BTFIXUPSET_CALL(flush_cache_all, tsunami_flush_cache_all, BTFIXUPCALL_NORM);
1756 BTFIXUPSET_CALL(flush_cache_mm, tsunami_flush_cache_mm, BTFIXUPCALL_NORM);
1757 BTFIXUPSET_CALL(flush_cache_page, tsunami_flush_cache_page, BTFIXUPCALL_NORM);
1758 BTFIXUPSET_CALL(flush_cache_range, tsunami_flush_cache_range, BTFIXUPCALL_NORM);
1761 BTFIXUPSET_CALL(flush_tlb_all, tsunami_flush_tlb_all, BTFIXUPCALL_NORM);
1762 BTFIXUPSET_CALL(flush_tlb_mm, tsunami_flush_tlb_mm, BTFIXUPCALL_NORM);
1763 BTFIXUPSET_CALL(flush_tlb_page, tsunami_flush_tlb_page, BTFIXUPCALL_NORM);
1764 BTFIXUPSET_CALL(flush_tlb_range, tsunami_flush_tlb_range, BTFIXUPCALL_NORM);
1766 BTFIXUPSET_CALL(__flush_page_to_ram, tsunami_flush_page_to_ram, BTFIXUPCALL_NOP);
1767 BTFIXUPSET_CALL(flush_sig_insns, tsunami_flush_sig_insns, BTFIXUPCALL_NORM);
1768 BTFIXUPSET_CALL(flush_page_for_dma, tsunami_flush_page_for_dma, BTFIXUPCALL_NORM);
1770 poke_srmmu = poke_tsunami;
1772 tsunami_setup_blockops();
1775 static void __init poke_viking(void)
1777 unsigned long mreg = srmmu_get_mmureg();
1778 static int smp_catch;
1780 if(viking_mxcc_present) {
1781 unsigned long mxcc_control = mxcc_get_creg();
1783 mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
1784 mxcc_control &= ~(MXCC_CTL_RRC);
1785 mxcc_set_creg(mxcc_control);
1788 * We don't need memory parity checks.
1789 * XXX This is a mess, have to dig out later. ecd.
1790 viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
1793 /* We do cache ptables on MXCC. */
1794 mreg |= VIKING_TCENABLE;
1796 unsigned long bpreg;
1798 mreg &= ~(VIKING_TCENABLE);
1800 /* Must disable mixed-cmd mode here for other cpu's. */
1801 bpreg = viking_get_bpreg();
1802 bpreg &= ~(VIKING_ACTION_MIX);
1803 viking_set_bpreg(bpreg);
1805 /* Just in case PROM does something funny. */
1810 mreg |= VIKING_SPENABLE;
1811 mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
1812 mreg |= VIKING_SBENABLE;
1813 mreg &= ~(VIKING_ACENABLE);
1814 srmmu_set_mmureg(mreg);
1817 /* Avoid unnecessary cross calls. */
1818 BTFIXUPCOPY_CALL(flush_cache_all, local_flush_cache_all);
1819 BTFIXUPCOPY_CALL(flush_cache_mm, local_flush_cache_mm);
1820 BTFIXUPCOPY_CALL(flush_cache_range, local_flush_cache_range);
1821 BTFIXUPCOPY_CALL(flush_cache_page, local_flush_cache_page);
1822 BTFIXUPCOPY_CALL(__flush_page_to_ram, local_flush_page_to_ram);
1823 BTFIXUPCOPY_CALL(flush_sig_insns, local_flush_sig_insns);
1824 BTFIXUPCOPY_CALL(flush_page_for_dma, local_flush_page_for_dma);
1829 static void __init init_viking(void)
1831 unsigned long mreg = srmmu_get_mmureg();
1833 /* Ahhh, the viking. SRMMU VLSI abortion number two... */
1834 if(mreg & VIKING_MMODE) {
1835 srmmu_name = "TI Viking";
1836 viking_mxcc_present = 0;
1839 BTFIXUPSET_CALL(pte_clear, srmmu_pte_clear, BTFIXUPCALL_NORM);
1840 BTFIXUPSET_CALL(pmd_clear, srmmu_pmd_clear, BTFIXUPCALL_NORM);
1841 BTFIXUPSET_CALL(pgd_clear, srmmu_pgd_clear, BTFIXUPCALL_NORM);
1844 * We need this to make sure old viking takes no hits
1845 * on it's cache for dma snoops to workaround the
1846 * "load from non-cacheable memory" interrupt bug.
1847 * This is only necessary because of the new way in
1848 * which we use the IOMMU.
1850 BTFIXUPSET_CALL(flush_page_for_dma, viking_flush_page, BTFIXUPCALL_NORM);
1852 flush_page_for_dma_global = 0;
1854 srmmu_name = "TI Viking/MXCC";
1855 viking_mxcc_present = 1;
1857 srmmu_cache_pagetables = 1;
1859 /* MXCC vikings lack the DMA snooping bug. */
1860 BTFIXUPSET_CALL(flush_page_for_dma, viking_flush_page_for_dma, BTFIXUPCALL_NOP);
1863 BTFIXUPSET_CALL(flush_cache_all, viking_flush_cache_all, BTFIXUPCALL_NORM);
1864 BTFIXUPSET_CALL(flush_cache_mm, viking_flush_cache_mm, BTFIXUPCALL_NORM);
1865 BTFIXUPSET_CALL(flush_cache_page, viking_flush_cache_page, BTFIXUPCALL_NORM);
1866 BTFIXUPSET_CALL(flush_cache_range, viking_flush_cache_range, BTFIXUPCALL_NORM);
1869 if (sparc_cpu_model == sun4d) {
1870 BTFIXUPSET_CALL(flush_tlb_all, sun4dsmp_flush_tlb_all, BTFIXUPCALL_NORM);
1871 BTFIXUPSET_CALL(flush_tlb_mm, sun4dsmp_flush_tlb_mm, BTFIXUPCALL_NORM);
1872 BTFIXUPSET_CALL(flush_tlb_page, sun4dsmp_flush_tlb_page, BTFIXUPCALL_NORM);
1873 BTFIXUPSET_CALL(flush_tlb_range, sun4dsmp_flush_tlb_range, BTFIXUPCALL_NORM);
1877 BTFIXUPSET_CALL(flush_tlb_all, viking_flush_tlb_all, BTFIXUPCALL_NORM);
1878 BTFIXUPSET_CALL(flush_tlb_mm, viking_flush_tlb_mm, BTFIXUPCALL_NORM);
1879 BTFIXUPSET_CALL(flush_tlb_page, viking_flush_tlb_page, BTFIXUPCALL_NORM);
1880 BTFIXUPSET_CALL(flush_tlb_range, viking_flush_tlb_range, BTFIXUPCALL_NORM);
1883 BTFIXUPSET_CALL(__flush_page_to_ram, viking_flush_page_to_ram, BTFIXUPCALL_NOP);
1884 BTFIXUPSET_CALL(flush_sig_insns, viking_flush_sig_insns, BTFIXUPCALL_NOP);
1886 poke_srmmu = poke_viking;
1889 /* Probe for the srmmu chip version. */
1890 static void __init get_srmmu_type(void)
1892 unsigned long mreg, psr;
1893 unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
1895 srmmu_modtype = SRMMU_INVAL_MOD;
1898 mreg = srmmu_get_mmureg(); psr = get_psr();
1899 mod_typ = (mreg & 0xf0000000) >> 28;
1900 mod_rev = (mreg & 0x0f000000) >> 24;
1901 psr_typ = (psr >> 28) & 0xf;
1902 psr_vers = (psr >> 24) & 0xf;
1904 /* First, check for HyperSparc or Cypress. */
1908 /* UP or MP Hypersparc */
1913 /* Uniprocessor Cypress */
1919 /* _REALLY OLD_ Cypress MP chips... */
1923 /* MP Cypress mmu/cache-controller */
1924 init_cypress_605(mod_rev);
1927 /* Some other Cypress revision, assume a 605. */
1928 init_cypress_605(mod_rev);
1935 * Now Fujitsu TurboSparc. It might happen that it is
1936 * in Swift emulation mode, so we will check later...
1938 if (psr_typ == 0 && psr_vers == 5) {
1943 /* Next check for Fujitsu Swift. */
1944 if(psr_typ == 0 && psr_vers == 4) {
1948 /* Look if it is not a TurboSparc emulating Swift... */
1949 cpunode = prom_getchild(prom_root_node);
1950 while((cpunode = prom_getsibling(cpunode)) != 0) {
1951 prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
1952 if(!strcmp(node_str, "cpu")) {
1953 if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
1954 prom_getintdefault(cpunode, "psr-version", 1) == 5) {
1966 /* Now the Viking family of srmmu. */
1969 ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
1974 /* Finally the Tsunami. */
1975 if(psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
1984 /* dont laugh, static pagetables */
1985 static int srmmu_check_pgt_cache(int low, int high)
1990 extern unsigned long spwin_mmu_patchme, fwin_mmu_patchme,
1991 tsetup_mmu_patchme, rtrap_mmu_patchme;
1993 extern unsigned long spwin_srmmu_stackchk, srmmu_fwin_stackchk,
1994 tsetup_srmmu_stackchk, srmmu_rett_stackchk;
1996 extern unsigned long srmmu_fault;
1998 #define PATCH_BRANCH(insn, dest) do { \
2001 *iaddr = SPARC_BRANCH((unsigned long) daddr, (unsigned long) iaddr); \
2004 static void __init patch_window_trap_handlers(void)
2006 unsigned long *iaddr, *daddr;
2008 PATCH_BRANCH(spwin_mmu_patchme, spwin_srmmu_stackchk);
2009 PATCH_BRANCH(fwin_mmu_patchme, srmmu_fwin_stackchk);
2010 PATCH_BRANCH(tsetup_mmu_patchme, tsetup_srmmu_stackchk);
2011 PATCH_BRANCH(rtrap_mmu_patchme, srmmu_rett_stackchk);
2012 PATCH_BRANCH(sparc_ttable[SP_TRAP_TFLT].inst_three, srmmu_fault);
2013 PATCH_BRANCH(sparc_ttable[SP_TRAP_DFLT].inst_three, srmmu_fault);
2014 PATCH_BRANCH(sparc_ttable[SP_TRAP_DACC].inst_three, srmmu_fault);
2018 /* Local cross-calls. */
2019 static void smp_flush_page_for_dma(unsigned long page)
2021 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_for_dma), page);
2022 local_flush_page_for_dma(page);
2027 /* Load up routines and constants for sun4m and sun4d mmu */
2028 void __init ld_mmu_srmmu(void)
2030 extern void ld_mmu_iommu(void);
2031 extern void ld_mmu_iounit(void);
2032 extern void ___xchg32_sun4md(void);
2034 /* First the constants */
2035 BTFIXUPSET_SIMM13(pmd_shift, SRMMU_PMD_SHIFT);
2036 BTFIXUPSET_SETHI(pmd_size, SRMMU_PMD_SIZE);
2037 BTFIXUPSET_SETHI(pmd_mask, SRMMU_PMD_MASK);
2038 BTFIXUPSET_SIMM13(pgdir_shift, SRMMU_PGDIR_SHIFT);
2039 BTFIXUPSET_SETHI(pgdir_size, SRMMU_PGDIR_SIZE);
2040 BTFIXUPSET_SETHI(pgdir_mask, SRMMU_PGDIR_MASK);
2042 BTFIXUPSET_SIMM13(ptrs_per_pte, SRMMU_PTRS_PER_PTE);
2043 BTFIXUPSET_SIMM13(ptrs_per_pmd, SRMMU_PTRS_PER_PMD);
2044 BTFIXUPSET_SIMM13(ptrs_per_pgd, SRMMU_PTRS_PER_PGD);
2046 BTFIXUPSET_INT(page_none, pgprot_val(SRMMU_PAGE_NONE));
2047 BTFIXUPSET_INT(page_shared, pgprot_val(SRMMU_PAGE_SHARED));
2048 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2049 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2050 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2051 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2052 pg_iobits = SRMMU_VALID | SRMMU_WRITE | SRMMU_REF;
2056 BTFIXUPSET_CALL(___xchg32, ___xchg32_sun4md, BTFIXUPCALL_SWAPG1G2);
2058 BTFIXUPSET_CALL(do_check_pgt_cache, srmmu_check_pgt_cache, BTFIXUPCALL_NORM);
2060 BTFIXUPSET_CALL(set_pte, srmmu_set_pte, BTFIXUPCALL_SWAPO0O1);
2061 BTFIXUPSET_CALL(switch_mm, srmmu_switch_mm, BTFIXUPCALL_NORM);
2063 BTFIXUPSET_CALL(pte_page, srmmu_pte_page, BTFIXUPCALL_NORM);
2064 BTFIXUPSET_CALL(pmd_page, srmmu_pmd_page, BTFIXUPCALL_NORM);
2065 BTFIXUPSET_CALL(pgd_page, srmmu_pgd_page, BTFIXUPCALL_NORM);
2067 BTFIXUPSET_SETHI(none_mask, 0xF0000000); /* XXX P3: is it used? */
2069 BTFIXUPSET_CALL(pte_present, srmmu_pte_present, BTFIXUPCALL_NORM);
2070 BTFIXUPSET_CALL(pte_clear, srmmu_pte_clear, BTFIXUPCALL_SWAPO0G0);
2072 BTFIXUPSET_CALL(pmd_bad, srmmu_pmd_bad, BTFIXUPCALL_NORM);
2073 BTFIXUPSET_CALL(pmd_present, srmmu_pmd_present, BTFIXUPCALL_NORM);
2074 BTFIXUPSET_CALL(pmd_clear, srmmu_pmd_clear, BTFIXUPCALL_SWAPO0G0);
2076 BTFIXUPSET_CALL(pgd_none, srmmu_pgd_none, BTFIXUPCALL_NORM);
2077 BTFIXUPSET_CALL(pgd_bad, srmmu_pgd_bad, BTFIXUPCALL_NORM);
2078 BTFIXUPSET_CALL(pgd_present, srmmu_pgd_present, BTFIXUPCALL_NORM);
2079 BTFIXUPSET_CALL(pgd_clear, srmmu_pgd_clear, BTFIXUPCALL_SWAPO0G0);
2081 BTFIXUPSET_CALL(mk_pte, srmmu_mk_pte, BTFIXUPCALL_NORM);
2082 BTFIXUPSET_CALL(mk_pte_phys, srmmu_mk_pte_phys, BTFIXUPCALL_NORM);
2083 BTFIXUPSET_CALL(mk_pte_io, srmmu_mk_pte_io, BTFIXUPCALL_NORM);
2084 BTFIXUPSET_CALL(pgd_set, srmmu_pgd_set, BTFIXUPCALL_NORM);
2085 BTFIXUPSET_CALL(pmd_set, srmmu_pmd_set, BTFIXUPCALL_NORM);
2087 BTFIXUPSET_INT(pte_modify_mask, SRMMU_CHG_MASK);
2088 BTFIXUPSET_CALL(pmd_offset, srmmu_pmd_offset, BTFIXUPCALL_NORM);
2089 BTFIXUPSET_CALL(pte_offset, srmmu_pte_offset, BTFIXUPCALL_NORM);
2090 BTFIXUPSET_CALL(free_pte_fast, srmmu_free_pte_fast, BTFIXUPCALL_NORM);
2091 BTFIXUPSET_CALL(pte_alloc_one_fast, srmmu_pte_alloc_one_fast, BTFIXUPCALL_NORM);
2092 BTFIXUPSET_CALL(pte_alloc_one, srmmu_pte_alloc_one, BTFIXUPCALL_NORM);
2093 BTFIXUPSET_CALL(free_pmd_fast, srmmu_free_pmd_fast, BTFIXUPCALL_NORM);
2094 BTFIXUPSET_CALL(pmd_alloc_one_fast, srmmu_pmd_alloc_one_fast, BTFIXUPCALL_NORM);
2095 BTFIXUPSET_CALL(free_pgd_fast, srmmu_free_pgd_fast, BTFIXUPCALL_NORM);
2096 BTFIXUPSET_CALL(get_pgd_fast, srmmu_get_pgd_fast, BTFIXUPCALL_NORM);
2098 BTFIXUPSET_HALF(pte_writei, SRMMU_WRITE);
2099 BTFIXUPSET_HALF(pte_dirtyi, SRMMU_DIRTY);
2100 BTFIXUPSET_HALF(pte_youngi, SRMMU_REF);
2101 BTFIXUPSET_HALF(pte_wrprotecti, SRMMU_WRITE);
2102 BTFIXUPSET_HALF(pte_mkcleani, SRMMU_DIRTY);
2103 BTFIXUPSET_HALF(pte_mkoldi, SRMMU_REF);
2104 BTFIXUPSET_CALL(pte_mkwrite, srmmu_pte_mkwrite, BTFIXUPCALL_ORINT(SRMMU_WRITE));
2105 BTFIXUPSET_CALL(pte_mkdirty, srmmu_pte_mkdirty, BTFIXUPCALL_ORINT(SRMMU_DIRTY));
2106 BTFIXUPSET_CALL(pte_mkyoung, srmmu_pte_mkyoung, BTFIXUPCALL_ORINT(SRMMU_REF));
2107 BTFIXUPSET_CALL(update_mmu_cache, srmmu_update_mmu_cache, BTFIXUPCALL_NOP);
2108 BTFIXUPSET_CALL(destroy_context, srmmu_destroy_context, BTFIXUPCALL_NORM);
2110 BTFIXUPSET_CALL(mmu_info, srmmu_mmu_info, BTFIXUPCALL_NORM);
2112 /* Task struct and kernel stack allocating/freeing. */
2113 BTFIXUPSET_CALL(alloc_task_struct, srmmu_alloc_task_struct, BTFIXUPCALL_NORM);
2114 BTFIXUPSET_CALL(free_task_struct, srmmu_free_task_struct, BTFIXUPCALL_NORM);
2115 BTFIXUPSET_CALL(get_task_struct, srmmu_get_task_struct, BTFIXUPCALL_NORM);
2118 patch_window_trap_handlers();
2121 /* El switcheroo... */
2123 BTFIXUPCOPY_CALL(local_flush_cache_all, flush_cache_all);
2124 BTFIXUPCOPY_CALL(local_flush_cache_mm, flush_cache_mm);
2125 BTFIXUPCOPY_CALL(local_flush_cache_range, flush_cache_range);
2126 BTFIXUPCOPY_CALL(local_flush_cache_page, flush_cache_page);
2127 BTFIXUPCOPY_CALL(local_flush_tlb_all, flush_tlb_all);
2128 BTFIXUPCOPY_CALL(local_flush_tlb_mm, flush_tlb_mm);
2129 BTFIXUPCOPY_CALL(local_flush_tlb_range, flush_tlb_range);
2130 BTFIXUPCOPY_CALL(local_flush_tlb_page, flush_tlb_page);
2131 BTFIXUPCOPY_CALL(local_flush_page_to_ram, __flush_page_to_ram);
2132 BTFIXUPCOPY_CALL(local_flush_sig_insns, flush_sig_insns);
2133 BTFIXUPCOPY_CALL(local_flush_page_for_dma, flush_page_for_dma);
2135 BTFIXUPSET_CALL(flush_cache_all, smp_flush_cache_all, BTFIXUPCALL_NORM);
2136 BTFIXUPSET_CALL(flush_cache_mm, smp_flush_cache_mm, BTFIXUPCALL_NORM);
2137 BTFIXUPSET_CALL(flush_cache_range, smp_flush_cache_range, BTFIXUPCALL_NORM);
2138 BTFIXUPSET_CALL(flush_cache_page, smp_flush_cache_page, BTFIXUPCALL_NORM);
2139 if (sparc_cpu_model != sun4d) {
2140 BTFIXUPSET_CALL(flush_tlb_all, smp_flush_tlb_all, BTFIXUPCALL_NORM);
2141 BTFIXUPSET_CALL(flush_tlb_mm, smp_flush_tlb_mm, BTFIXUPCALL_NORM);
2142 BTFIXUPSET_CALL(flush_tlb_range, smp_flush_tlb_range, BTFIXUPCALL_NORM);
2143 BTFIXUPSET_CALL(flush_tlb_page, smp_flush_tlb_page, BTFIXUPCALL_NORM);
2145 BTFIXUPSET_CALL(__flush_page_to_ram, smp_flush_page_to_ram, BTFIXUPCALL_NORM);
2146 BTFIXUPSET_CALL(flush_sig_insns, smp_flush_sig_insns, BTFIXUPCALL_NORM);
2147 BTFIXUPSET_CALL(flush_page_for_dma, smp_flush_page_for_dma, BTFIXUPCALL_NORM);
2150 if (sparc_cpu_model == sun4d)
2155 if (sparc_cpu_model == sun4d)