1 /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
3 * Copyright (C) 1995, 1997, 2005 David S. Miller <davem@davemloft.net>
4 * Copyright (C) 1996 Eddie C. Dost (ecd@brainaid.de)
5 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 #include <linux/config.h>
13 #include <asm/pgtable.h>
19 * On a second level vpte miss, check whether the original fault is to the OBP
20 * range (note that this is only possible for instruction miss, data misses to
21 * obp range do not use vpte). If so, go back directly to the faulting address.
22 * This is because we want to read the tpc, otherwise we have no way of knowing
23 * the 8k aligned faulting address if we are using >8k kernel pagesize. This
24 * also ensures no vpte range addresses are dropped into tlb while obp is
25 * executing (see inherit_locked_prom_mappings() rant).
28 /* Note that kvmap below has verified that the address is
29 * in the range MODULES_VADDR --> VMALLOC_END already. So
30 * here we need only check if it is an OBP address or not.
32 sethi %hi(LOW_OBP_ADDRESS), %g5
34 blu,pn %xcc, kern_vpte
38 blu,pn %xcc, vpte_insn_obp
41 /* These two instructions are patched by paginig_init(). */
43 sethi %hi(swapper_pgd_zero), %g5
44 lduw [%g5 + %lo(swapper_pgd_zero)], %g5
46 /* With kernel PGD in %g5, branch back into dtlb_backend. */
47 ba,pt %xcc, sparc64_kpte_continue
48 andn %g1, 0x3, %g1 /* Finish PMD offset adjustment. */
51 /* Restore previous TAG_ACCESS, %g5 is zero, and we will
52 * skip over the trap instruction so that the top level
53 * TLB miss handler will thing this %g5 value is just an
54 * invalid PTE, thus branching to full fault processing.
57 stxa %g4, [%g1 + %g1] ASI_DMMU
61 /* Behave as if we are at TL0. */
63 rdpr %tpc, %g4 /* Find original faulting iaddr */
64 srlx %g4, 13, %g4 /* Throw out context bits */
65 sllx %g4, 13, %g4 /* g4 has vpn + ctx0 now */
67 /* Restore previous TAG_ACCESS. */
69 stxa %g4, [%g1 + %g1] ASI_IMMU
71 sethi %hi(prom_trans), %g5
72 or %g5, %lo(prom_trans), %g5
74 1: ldx [%g5 + 0x00], %g6 ! base
75 brz,a,pn %g6, longpath ! no more entries, fail
76 mov TLB_SFSR, %g1 ! and restore %g1
77 ldx [%g5 + 0x08], %g1 ! len
78 add %g6, %g1, %g1 ! end
83 ldx [%g5 + 0x10], %g1 ! PTE
85 /* TLB load, restore %g1, and return from trap. */
89 stxa %g5, [%g0] ASI_ITLB_DATA_IN
93 add %g5, (3 * 8), %g5 ! next entry
96 sethi %hi(prom_trans), %g5
97 or %g5, %lo(prom_trans), %g5
101 1: ldx [%g5 + 0x00], %g6 ! base
102 brz,a,pn %g6, longpath ! no more entries, fail
103 mov TLB_SFSR, %g1 ! and restore %g1
104 ldx [%g5 + 0x08], %g1 ! len
105 add %g6, %g1, %g1 ! end
110 ldx [%g5 + 0x10], %g1 ! PTE
112 /* TLB load, restore %g1, and return from trap. */
116 stxa %g5, [%g0] ASI_DTLB_DATA_IN
120 add %g5, (3 * 8), %g5 ! next entry
123 * On a first level data miss, check whether this is to the OBP range (note
124 * that such accesses can be made by prom, as well as by kernel using
125 * prom_getproperty on "address"), and if so, do not use vpte access ...
126 * rather, use information saved during inherit_prom_mappings() using 8k
131 brgez,pn %g4, kvmap_nonlinear
134 #ifdef CONFIG_DEBUG_PAGEALLOC
135 .globl kvmap_linear_patch
138 ba,pt %xcc, kvmap_load
141 #ifdef CONFIG_DEBUG_PAGEALLOC
142 sethi %hi(swapper_pg_dir), %g5
143 or %g5, %lo(swapper_pg_dir), %g5
144 sllx %g4, 64 - (PGDIR_SHIFT + PGDIR_BITS), %g6
145 srlx %g6, 64 - PAGE_SHIFT, %g6
147 lduw [%g5 + %g6], %g5
149 sllx %g4, 64 - (PMD_SHIFT + PMD_BITS), %g6
150 srlx %g6, 64 - PAGE_SHIFT, %g6
153 lduwa [%g5 + %g6] ASI_PHYS_USE_EC, %g5
155 sllx %g4, 64 - PMD_SHIFT, %g6
156 srlx %g6, 64 - PAGE_SHIFT, %g6
159 ldxa [%g5 + %g6] ASI_PHYS_USE_EC, %g5
162 ba,a,pt %xcc, kvmap_load
166 sethi %hi(MODULES_VADDR), %g5
168 blu,pn %xcc, longpath
169 mov (VMALLOC_END >> 24), %g5
172 bgeu,pn %xcc, longpath
176 sethi %hi(LOW_OBP_ADDRESS), %g5
178 blu,pn %xcc, kvmap_vmalloc_addr
182 blu,pn %xcc, kvmap_do_obp
186 /* If we get here, a vmalloc addr was accessed, load kernel VPTE. */
187 ldxa [%g3 + %g6] ASI_N, %g5
188 brgez,pn %g5, longpath
192 /* PTE is valid, load into TLB and return from trap. */
193 stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB