Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Synthesize TLB refill handlers at runtime. |
| 7 | * |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 8 | * Copyright (C) 2004, 2005, 2006, 2008 Thiemo Seufer |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 9 | * Copyright (C) 2005, 2007, 2008, 2009 Maciej W. Rozycki |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 10 | * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org) |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 11 | * Copyright (C) 2008, 2009 Cavium Networks, Inc. |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 12 | * |
| 13 | * ... and the days got worse and worse and now you see |
| 14 | * I've gone completly out of my mind. |
| 15 | * |
| 16 | * They're coming to take me a away haha |
| 17 | * they're coming to take me a away hoho hihi haha |
| 18 | * to the funny farm where code is beautiful all the time ... |
| 19 | * |
| 20 | * (Condolences to Napoleon XIV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 23 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/types.h> |
Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 26 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/string.h> |
| 28 | #include <linux/init.h> |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 29 | #include <linux/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 31 | #include <asm/cacheflush.h> |
| 32 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/war.h> |
Florian Fainelli | 3482d71 | 2010-01-28 15:21:24 +0100 | [diff] [blame] | 34 | #include <asm/uasm.h> |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 35 | |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 36 | /* |
| 37 | * TLB load/store/modify handlers. |
| 38 | * |
| 39 | * Only the fastpath gets synthesized at runtime, the slowpath for |
| 40 | * do_page_fault remains normal asm. |
| 41 | */ |
| 42 | extern void tlb_do_page_fault_0(void); |
| 43 | extern void tlb_do_page_fault_1(void); |
| 44 | |
| 45 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 46 | static inline int r45k_bvahwbug(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | /* XXX: We should probe for the presence of this bug, but we don't. */ |
| 49 | return 0; |
| 50 | } |
| 51 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 52 | static inline int r4k_250MHZhwbug(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | /* XXX: We should probe for the presence of this bug, but we don't. */ |
| 55 | return 0; |
| 56 | } |
| 57 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 58 | static inline int __maybe_unused bcm1250_m3_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | return BCM1250_M3_WAR; |
| 61 | } |
| 62 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 63 | static inline int __maybe_unused r10000_llsc_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | return R10000_LLSC_WAR; |
| 66 | } |
| 67 | |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 68 | static int use_bbit_insns(void) |
| 69 | { |
| 70 | switch (current_cpu_type()) { |
| 71 | case CPU_CAVIUM_OCTEON: |
| 72 | case CPU_CAVIUM_OCTEON_PLUS: |
| 73 | case CPU_CAVIUM_OCTEON2: |
| 74 | return 1; |
| 75 | default: |
| 76 | return 0; |
| 77 | } |
| 78 | } |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 81 | * Found by experiment: At least some revisions of the 4kc throw under |
| 82 | * some circumstances a machine check exception, triggered by invalid |
| 83 | * values in the index register. Delaying the tlbp instruction until |
| 84 | * after the next branch, plus adding an additional nop in front of |
| 85 | * tlbwi/tlbwr avoids the invalid index register values. Nobody knows |
| 86 | * why; it's not an issue caused by the core RTL. |
| 87 | * |
| 88 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 89 | static int __cpuinit m4kc_tlbp_war(void) |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 90 | { |
| 91 | return (current_cpu_data.processor_id & 0xffff00) == |
| 92 | (PRID_COMP_MIPS | PRID_IMP_4KC); |
| 93 | } |
| 94 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 95 | /* Handle labels (which must be positive integers). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | enum label_id { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 97 | label_second_part = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | label_leave, |
| 99 | label_vmalloc, |
| 100 | label_vmalloc_done, |
| 101 | label_tlbw_hazard, |
| 102 | label_split, |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 103 | label_tlbl_goaround1, |
| 104 | label_tlbl_goaround2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | label_nopage_tlbl, |
| 106 | label_nopage_tlbs, |
| 107 | label_nopage_tlbm, |
| 108 | label_smp_pgtable_change, |
| 109 | label_r3000_write_probe_fail, |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 110 | label_large_segbits_fault, |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 111 | #ifdef CONFIG_HUGETLB_PAGE |
| 112 | label_tlb_huge_update, |
| 113 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 116 | UASM_L_LA(_second_part) |
| 117 | UASM_L_LA(_leave) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 118 | UASM_L_LA(_vmalloc) |
| 119 | UASM_L_LA(_vmalloc_done) |
| 120 | UASM_L_LA(_tlbw_hazard) |
| 121 | UASM_L_LA(_split) |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 122 | UASM_L_LA(_tlbl_goaround1) |
| 123 | UASM_L_LA(_tlbl_goaround2) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 124 | UASM_L_LA(_nopage_tlbl) |
| 125 | UASM_L_LA(_nopage_tlbs) |
| 126 | UASM_L_LA(_nopage_tlbm) |
| 127 | UASM_L_LA(_smp_pgtable_change) |
| 128 | UASM_L_LA(_r3000_write_probe_fail) |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 129 | UASM_L_LA(_large_segbits_fault) |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 130 | #ifdef CONFIG_HUGETLB_PAGE |
| 131 | UASM_L_LA(_tlb_huge_update) |
| 132 | #endif |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 133 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 134 | /* |
| 135 | * For debug purposes. |
| 136 | */ |
| 137 | static inline void dump_handler(const u32 *handler, int count) |
| 138 | { |
| 139 | int i; |
| 140 | |
| 141 | pr_debug("\t.set push\n"); |
| 142 | pr_debug("\t.set noreorder\n"); |
| 143 | |
| 144 | for (i = 0; i < count; i++) |
| 145 | pr_debug("\t%p\t.word 0x%08x\n", &handler[i], handler[i]); |
| 146 | |
| 147 | pr_debug("\t.set pop\n"); |
| 148 | } |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* The only general purpose registers allowed in TLB handlers. */ |
| 151 | #define K0 26 |
| 152 | #define K1 27 |
| 153 | |
| 154 | /* Some CP0 registers */ |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 155 | #define C0_INDEX 0, 0 |
| 156 | #define C0_ENTRYLO0 2, 0 |
| 157 | #define C0_TCBIND 2, 2 |
| 158 | #define C0_ENTRYLO1 3, 0 |
| 159 | #define C0_CONTEXT 4, 0 |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 160 | #define C0_PAGEMASK 5, 0 |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 161 | #define C0_BADVADDR 8, 0 |
| 162 | #define C0_ENTRYHI 10, 0 |
| 163 | #define C0_EPC 14, 0 |
| 164 | #define C0_XCONTEXT 20, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 166 | #ifdef CONFIG_64BIT |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 167 | # define GET_CONTEXT(buf, reg) UASM_i_MFC0(buf, reg, C0_XCONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 169 | # define GET_CONTEXT(buf, reg) UASM_i_MFC0(buf, reg, C0_CONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #endif |
| 171 | |
| 172 | /* The worst case length of the handler is around 18 instructions for |
| 173 | * R3000-style TLBs and up to 63 instructions for R4000-style TLBs. |
| 174 | * Maximum space available is 32 instructions for R3000 and 64 |
| 175 | * instructions for R4000. |
| 176 | * |
| 177 | * We deliberately chose a buffer size of 128, so we won't scribble |
| 178 | * over anything important on overflow before we panic. |
| 179 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 180 | static u32 tlb_handler[128] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | /* simply assume worst case size for labels and relocs */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 183 | static struct uasm_label labels[128] __cpuinitdata; |
| 184 | static struct uasm_reloc relocs[128] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 186 | #ifdef CONFIG_64BIT |
| 187 | static int check_for_high_segbits __cpuinitdata; |
| 188 | #endif |
| 189 | |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 190 | #ifdef CONFIG_MIPS_PGD_C0_CONTEXT |
| 191 | |
| 192 | static unsigned int kscratch_used_mask __cpuinitdata; |
| 193 | |
| 194 | static int __cpuinit allocate_kscratch(void) |
| 195 | { |
| 196 | int r; |
| 197 | unsigned int a = cpu_data[0].kscratch_mask & ~kscratch_used_mask; |
| 198 | |
| 199 | r = ffs(a); |
| 200 | |
| 201 | if (r == 0) |
| 202 | return -1; |
| 203 | |
| 204 | r--; /* make it zero based */ |
| 205 | |
| 206 | kscratch_used_mask |= (1 << r); |
| 207 | |
| 208 | return r; |
| 209 | } |
| 210 | |
| 211 | static int pgd_reg __cpuinitdata; |
| 212 | |
| 213 | #else /* !CONFIG_MIPS_PGD_C0_CONTEXT*/ |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 214 | /* |
| 215 | * CONFIG_MIPS_PGD_C0_CONTEXT implies 64 bit and lack of pgd_current, |
| 216 | * we cannot do r3000 under these circumstances. |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 217 | * |
| 218 | * Declare pgd_current here instead of including mmu_context.h to avoid type |
| 219 | * conflicts for tlbmiss_handler_setup_pgd |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 220 | */ |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 221 | extern unsigned long pgd_current[]; |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* |
| 224 | * The R3000 TLB handler is simple. |
| 225 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 226 | static void __cpuinit build_r3000_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | long pgdc = (long)pgd_current; |
| 229 | u32 *p; |
| 230 | |
| 231 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 232 | p = tlb_handler; |
| 233 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 234 | uasm_i_mfc0(&p, K0, C0_BADVADDR); |
| 235 | uasm_i_lui(&p, K1, uasm_rel_hi(pgdc)); /* cp0 delay */ |
| 236 | uasm_i_lw(&p, K1, uasm_rel_lo(pgdc), K1); |
| 237 | uasm_i_srl(&p, K0, K0, 22); /* load delay */ |
| 238 | uasm_i_sll(&p, K0, K0, 2); |
| 239 | uasm_i_addu(&p, K1, K1, K0); |
| 240 | uasm_i_mfc0(&p, K0, C0_CONTEXT); |
| 241 | uasm_i_lw(&p, K1, 0, K1); /* cp0 delay */ |
| 242 | uasm_i_andi(&p, K0, K0, 0xffc); /* load delay */ |
| 243 | uasm_i_addu(&p, K1, K1, K0); |
| 244 | uasm_i_lw(&p, K0, 0, K1); |
| 245 | uasm_i_nop(&p); /* load delay */ |
| 246 | uasm_i_mtc0(&p, K0, C0_ENTRYLO0); |
| 247 | uasm_i_mfc0(&p, K1, C0_EPC); /* cp0 delay */ |
| 248 | uasm_i_tlbwr(&p); /* cp0 delay */ |
| 249 | uasm_i_jr(&p, K1); |
| 250 | uasm_i_rfe(&p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (p > tlb_handler + 32) |
| 253 | panic("TLB refill handler space exceeded"); |
| 254 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 255 | pr_debug("Wrote TLB refill handler (%u instructions).\n", |
| 256 | (unsigned int)(p - tlb_handler)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 258 | memcpy((void *)ebase, tlb_handler, 0x80); |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 259 | |
| 260 | dump_handler((u32 *)ebase, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 262 | #endif /* CONFIG_MIPS_PGD_C0_CONTEXT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * The R4000 TLB handler is much more complicated. We have two |
| 266 | * consecutive handler areas with 32 instructions space each. |
| 267 | * Since they aren't used at the same time, we can overflow in the |
| 268 | * other one.To keep things simple, we first assume linear space, |
| 269 | * then we relocate it to the final handler layout as needed. |
| 270 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 271 | static u32 final_handler[64] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | /* |
| 274 | * Hazards |
| 275 | * |
| 276 | * From the IDT errata for the QED RM5230 (Nevada), processor revision 1.0: |
| 277 | * 2. A timing hazard exists for the TLBP instruction. |
| 278 | * |
| 279 | * stalling_instruction |
| 280 | * TLBP |
| 281 | * |
| 282 | * The JTLB is being read for the TLBP throughout the stall generated by the |
| 283 | * previous instruction. This is not really correct as the stalling instruction |
| 284 | * can modify the address used to access the JTLB. The failure symptom is that |
| 285 | * the TLBP instruction will use an address created for the stalling instruction |
| 286 | * and not the address held in C0_ENHI and thus report the wrong results. |
| 287 | * |
| 288 | * The software work-around is to not allow the instruction preceding the TLBP |
| 289 | * to stall - make it an NOP or some other instruction guaranteed not to stall. |
| 290 | * |
| 291 | * Errata 2 will not be fixed. This errata is also on the R5000. |
| 292 | * |
| 293 | * As if we MIPS hackers wouldn't know how to nop pipelines happy ... |
| 294 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 295 | static void __cpuinit __maybe_unused build_tlb_probe_entry(u32 **p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 297 | switch (current_cpu_type()) { |
Thomas Bogendoerfer | 326e2e1 | 2008-05-12 13:55:42 +0200 | [diff] [blame] | 298 | /* Found by experiment: R4600 v2.0/R4700 needs this, too. */ |
Thiemo Seufer | f5b4d95 | 2005-09-09 17:11:50 +0000 | [diff] [blame] | 299 | case CPU_R4600: |
Thomas Bogendoerfer | 326e2e1 | 2008-05-12 13:55:42 +0200 | [diff] [blame] | 300 | case CPU_R4700: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | case CPU_R5000: |
| 302 | case CPU_R5000A: |
| 303 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 304 | uasm_i_nop(p); |
| 305 | uasm_i_tlbp(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | break; |
| 307 | |
| 308 | default: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 309 | uasm_i_tlbp(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | break; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * Write random or indexed TLB entry, and care about the hazards from |
| 316 | * the preceeding mtc0 and for the following eret. |
| 317 | */ |
| 318 | enum tlb_write_entry { tlb_random, tlb_indexed }; |
| 319 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 320 | static void __cpuinit build_tlb_write_entry(u32 **p, struct uasm_label **l, |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 321 | struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | enum tlb_write_entry wmode) |
| 323 | { |
| 324 | void(*tlbw)(u32 **) = NULL; |
| 325 | |
| 326 | switch (wmode) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 327 | case tlb_random: tlbw = uasm_i_tlbwr; break; |
| 328 | case tlb_indexed: tlbw = uasm_i_tlbwi; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Ralf Baechle | 161548b | 2008-01-29 10:14:54 +0000 | [diff] [blame] | 331 | if (cpu_has_mips_r2) { |
David Daney | 41f0e4d | 2009-05-12 12:41:53 -0700 | [diff] [blame] | 332 | if (cpu_has_mips_r2_exec_hazard) |
| 333 | uasm_i_ehb(p); |
Ralf Baechle | 161548b | 2008-01-29 10:14:54 +0000 | [diff] [blame] | 334 | tlbw(p); |
| 335 | return; |
| 336 | } |
| 337 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 338 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | case CPU_R4000PC: |
| 340 | case CPU_R4000SC: |
| 341 | case CPU_R4000MC: |
| 342 | case CPU_R4400PC: |
| 343 | case CPU_R4400SC: |
| 344 | case CPU_R4400MC: |
| 345 | /* |
| 346 | * This branch uses up a mtc0 hazard nop slot and saves |
| 347 | * two nops after the tlbw instruction. |
| 348 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 349 | uasm_il_bgezl(p, r, 0, label_tlbw_hazard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 351 | uasm_l_tlbw_hazard(l, *p); |
| 352 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | break; |
| 354 | |
| 355 | case CPU_R4600: |
| 356 | case CPU_R4700: |
| 357 | case CPU_R5000: |
| 358 | case CPU_R5000A: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 359 | uasm_i_nop(p); |
Maciej W. Rozycki | 2c93e12 | 2005-06-30 10:51:01 +0000 | [diff] [blame] | 360 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 361 | uasm_i_nop(p); |
Maciej W. Rozycki | 2c93e12 | 2005-06-30 10:51:01 +0000 | [diff] [blame] | 362 | break; |
| 363 | |
| 364 | case CPU_R4300: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | case CPU_5KC: |
| 366 | case CPU_TX49XX: |
Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 367 | case CPU_PR4450: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 368 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | tlbw(p); |
| 370 | break; |
| 371 | |
| 372 | case CPU_R10000: |
| 373 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 374 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | case CPU_4KC: |
Thomas Bogendoerfer | b1ec4c8 | 2008-03-26 16:42:54 +0100 | [diff] [blame] | 376 | case CPU_4KEC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | case CPU_SB1: |
Andrew Isaacson | 93ce2f52 | 2005-10-19 23:56:20 -0700 | [diff] [blame] | 378 | case CPU_SB1A: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | case CPU_4KSC: |
| 380 | case CPU_20KC: |
| 381 | case CPU_25KF: |
Kevin Cernekee | 602977b | 2010-10-16 14:22:30 -0700 | [diff] [blame] | 382 | case CPU_BMIPS32: |
| 383 | case CPU_BMIPS3300: |
| 384 | case CPU_BMIPS4350: |
| 385 | case CPU_BMIPS4380: |
| 386 | case CPU_BMIPS5000: |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 387 | case CPU_LOONGSON2: |
Shinya Kuribayashi | a644b27 | 2009-03-03 18:05:51 +0900 | [diff] [blame] | 388 | case CPU_R5500: |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 389 | if (m4kc_tlbp_war()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 390 | uasm_i_nop(p); |
Manuel Lauss | 2f794d0 | 2009-03-25 17:49:30 +0100 | [diff] [blame] | 391 | case CPU_ALCHEMY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | tlbw(p); |
| 393 | break; |
| 394 | |
| 395 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 396 | uasm_i_nop(p); /* QED specifies 2 nops hazard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* |
| 398 | * This branch uses up a mtc0 hazard nop slot and saves |
| 399 | * a nop after the tlbw instruction. |
| 400 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 401 | uasm_il_bgezl(p, r, 0, label_tlbw_hazard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 403 | uasm_l_tlbw_hazard(l, *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | break; |
| 405 | |
| 406 | case CPU_RM7000: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 407 | uasm_i_nop(p); |
| 408 | uasm_i_nop(p); |
| 409 | uasm_i_nop(p); |
| 410 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | tlbw(p); |
| 412 | break; |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | case CPU_RM9000: |
| 415 | /* |
| 416 | * When the JTLB is updated by tlbwi or tlbwr, a subsequent |
| 417 | * use of the JTLB for instructions should not occur for 4 |
| 418 | * cpu cycles and use for data translations should not occur |
| 419 | * for 3 cpu cycles. |
| 420 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 421 | uasm_i_ssnop(p); |
| 422 | uasm_i_ssnop(p); |
| 423 | uasm_i_ssnop(p); |
| 424 | uasm_i_ssnop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 426 | uasm_i_ssnop(p); |
| 427 | uasm_i_ssnop(p); |
| 428 | uasm_i_ssnop(p); |
| 429 | uasm_i_ssnop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | break; |
| 431 | |
| 432 | case CPU_VR4111: |
| 433 | case CPU_VR4121: |
| 434 | case CPU_VR4122: |
| 435 | case CPU_VR4181: |
| 436 | case CPU_VR4181A: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 437 | uasm_i_nop(p); |
| 438 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 440 | uasm_i_nop(p); |
| 441 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | break; |
| 443 | |
| 444 | case CPU_VR4131: |
| 445 | case CPU_VR4133: |
Ralf Baechle | 7623deb | 2005-08-29 16:49:55 +0000 | [diff] [blame] | 446 | case CPU_R5432: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 447 | uasm_i_nop(p); |
| 448 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | tlbw(p); |
| 450 | break; |
| 451 | |
Lars-Peter Clausen | 83ccf69 | 2010-07-17 11:07:51 +0000 | [diff] [blame] | 452 | case CPU_JZRISC: |
| 453 | tlbw(p); |
| 454 | uasm_i_nop(p); |
| 455 | break; |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | default: |
| 458 | panic("No TLB refill handler yet (CPU type: %d)", |
| 459 | current_cpu_data.cputype); |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 464 | static __cpuinit __maybe_unused void build_convert_pte_to_entrylo(u32 **p, |
| 465 | unsigned int reg) |
| 466 | { |
| 467 | if (kernel_uses_smartmips_rixi) { |
| 468 | UASM_i_SRL(p, reg, reg, ilog2(_PAGE_NO_EXEC)); |
| 469 | UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); |
| 470 | } else { |
| 471 | #ifdef CONFIG_64BIT_PHYS_ADDR |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 472 | uasm_i_dsrl_safe(p, reg, reg, ilog2(_PAGE_GLOBAL)); |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 473 | #else |
| 474 | UASM_i_SRL(p, reg, reg, ilog2(_PAGE_GLOBAL)); |
| 475 | #endif |
| 476 | } |
| 477 | } |
| 478 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 479 | #ifdef CONFIG_HUGETLB_PAGE |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 480 | |
| 481 | static __cpuinit void build_restore_pagemask(u32 **p, |
| 482 | struct uasm_reloc **r, |
| 483 | unsigned int tmp, |
| 484 | enum label_id lid) |
| 485 | { |
| 486 | /* Reset default page size */ |
| 487 | if (PM_DEFAULT_MASK >> 16) { |
| 488 | uasm_i_lui(p, tmp, PM_DEFAULT_MASK >> 16); |
| 489 | uasm_i_ori(p, tmp, tmp, PM_DEFAULT_MASK & 0xffff); |
| 490 | uasm_il_b(p, r, lid); |
| 491 | uasm_i_mtc0(p, tmp, C0_PAGEMASK); |
| 492 | } else if (PM_DEFAULT_MASK) { |
| 493 | uasm_i_ori(p, tmp, 0, PM_DEFAULT_MASK); |
| 494 | uasm_il_b(p, r, lid); |
| 495 | uasm_i_mtc0(p, tmp, C0_PAGEMASK); |
| 496 | } else { |
| 497 | uasm_il_b(p, r, lid); |
| 498 | uasm_i_mtc0(p, 0, C0_PAGEMASK); |
| 499 | } |
| 500 | } |
| 501 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 502 | static __cpuinit void build_huge_tlb_write_entry(u32 **p, |
| 503 | struct uasm_label **l, |
| 504 | struct uasm_reloc **r, |
| 505 | unsigned int tmp, |
| 506 | enum tlb_write_entry wmode) |
| 507 | { |
| 508 | /* Set huge page tlb entry size */ |
| 509 | uasm_i_lui(p, tmp, PM_HUGE_MASK >> 16); |
| 510 | uasm_i_ori(p, tmp, tmp, PM_HUGE_MASK & 0xffff); |
| 511 | uasm_i_mtc0(p, tmp, C0_PAGEMASK); |
| 512 | |
| 513 | build_tlb_write_entry(p, l, r, wmode); |
| 514 | |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 515 | build_restore_pagemask(p, r, tmp, label_leave); |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Check if Huge PTE is present, if so then jump to LABEL. |
| 520 | */ |
| 521 | static void __cpuinit |
| 522 | build_is_huge_pte(u32 **p, struct uasm_reloc **r, unsigned int tmp, |
| 523 | unsigned int pmd, int lid) |
| 524 | { |
| 525 | UASM_i_LW(p, tmp, 0, pmd); |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 526 | if (use_bbit_insns()) { |
| 527 | uasm_il_bbit1(p, r, tmp, ilog2(_PAGE_HUGE), lid); |
| 528 | } else { |
| 529 | uasm_i_andi(p, tmp, tmp, _PAGE_HUGE); |
| 530 | uasm_il_bnez(p, r, tmp, lid); |
| 531 | } |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static __cpuinit void build_huge_update_entries(u32 **p, |
| 535 | unsigned int pte, |
| 536 | unsigned int tmp) |
| 537 | { |
| 538 | int small_sequence; |
| 539 | |
| 540 | /* |
| 541 | * A huge PTE describes an area the size of the |
| 542 | * configured huge page size. This is twice the |
| 543 | * of the large TLB entry size we intend to use. |
| 544 | * A TLB entry half the size of the configured |
| 545 | * huge page size is configured into entrylo0 |
| 546 | * and entrylo1 to cover the contiguous huge PTE |
| 547 | * address space. |
| 548 | */ |
| 549 | small_sequence = (HPAGE_SIZE >> 7) < 0x10000; |
| 550 | |
| 551 | /* We can clobber tmp. It isn't used after this.*/ |
| 552 | if (!small_sequence) |
| 553 | uasm_i_lui(p, tmp, HPAGE_SIZE >> (7 + 16)); |
| 554 | |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 555 | build_convert_pte_to_entrylo(p, pte); |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 556 | UASM_i_MTC0(p, pte, C0_ENTRYLO0); /* load it */ |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 557 | /* convert to entrylo1 */ |
| 558 | if (small_sequence) |
| 559 | UASM_i_ADDIU(p, pte, pte, HPAGE_SIZE >> 7); |
| 560 | else |
| 561 | UASM_i_ADDU(p, pte, pte, tmp); |
| 562 | |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 563 | UASM_i_MTC0(p, pte, C0_ENTRYLO1); /* load it */ |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static __cpuinit void build_huge_handler_tail(u32 **p, |
| 567 | struct uasm_reloc **r, |
| 568 | struct uasm_label **l, |
| 569 | unsigned int pte, |
| 570 | unsigned int ptr) |
| 571 | { |
| 572 | #ifdef CONFIG_SMP |
| 573 | UASM_i_SC(p, pte, 0, ptr); |
| 574 | uasm_il_beqz(p, r, pte, label_tlb_huge_update); |
| 575 | UASM_i_LW(p, pte, 0, ptr); /* Needed because SC killed our PTE */ |
| 576 | #else |
| 577 | UASM_i_SW(p, pte, 0, ptr); |
| 578 | #endif |
| 579 | build_huge_update_entries(p, pte, ptr); |
| 580 | build_huge_tlb_write_entry(p, l, r, pte, tlb_indexed); |
| 581 | } |
| 582 | #endif /* CONFIG_HUGETLB_PAGE */ |
| 583 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 584 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* |
| 586 | * TMP and PTR are scratch. |
| 587 | * TMP will be clobbered, PTR will hold the pmd entry. |
| 588 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 589 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 590 | build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | unsigned int tmp, unsigned int ptr) |
| 592 | { |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 593 | #ifndef CONFIG_MIPS_PGD_C0_CONTEXT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | long pgdc = (long)pgd_current; |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 595 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | /* |
| 597 | * The vmalloc handling is not in the hotpath. |
| 598 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 599 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 600 | |
| 601 | if (check_for_high_segbits) { |
| 602 | /* |
| 603 | * The kernel currently implicitely assumes that the |
| 604 | * MIPS SEGBITS parameter for the processor is |
| 605 | * (PGDIR_SHIFT+PGDIR_BITS) or less, and will never |
| 606 | * allocate virtual addresses outside the maximum |
| 607 | * range for SEGBITS = (PGDIR_SHIFT+PGDIR_BITS). But |
| 608 | * that doesn't prevent user code from accessing the |
| 609 | * higher xuseg addresses. Here, we make sure that |
| 610 | * everything but the lower xuseg addresses goes down |
| 611 | * the module_alloc/vmalloc path. |
| 612 | */ |
| 613 | uasm_i_dsrl_safe(p, ptr, tmp, PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3); |
| 614 | uasm_il_bnez(p, r, ptr, label_vmalloc); |
| 615 | } else { |
| 616 | uasm_il_bltz(p, r, tmp, label_vmalloc); |
| 617 | } |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 618 | /* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 620 | #ifdef CONFIG_MIPS_PGD_C0_CONTEXT |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 621 | if (pgd_reg != -1) { |
| 622 | /* pgd is in pgd_reg */ |
| 623 | UASM_i_MFC0(p, ptr, 31, pgd_reg); |
| 624 | } else { |
| 625 | /* |
| 626 | * &pgd << 11 stored in CONTEXT [23..63]. |
| 627 | */ |
| 628 | UASM_i_MFC0(p, ptr, C0_CONTEXT); |
| 629 | |
| 630 | /* Clear lower 23 bits of context. */ |
| 631 | uasm_i_dins(p, ptr, 0, 0, 23); |
| 632 | |
| 633 | /* 1 0 1 0 1 << 6 xkphys cached */ |
| 634 | uasm_i_ori(p, ptr, ptr, 0x540); |
| 635 | uasm_i_drotr(p, ptr, ptr, 11); |
| 636 | } |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 637 | #elif defined(CONFIG_SMP) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 638 | # ifdef CONFIG_MIPS_MT_SMTC |
| 639 | /* |
| 640 | * SMTC uses TCBind value as "CPU" index |
| 641 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 642 | uasm_i_mfc0(p, ptr, C0_TCBIND); |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 643 | uasm_i_dsrl_safe(p, ptr, ptr, 19); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 644 | # else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | /* |
Thiemo Seufer | 1b3a6e9 | 2005-04-01 14:07:13 +0000 | [diff] [blame] | 646 | * 64 bit SMP running in XKPHYS has smp_processor_id() << 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | * stored in CONTEXT. |
| 648 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 649 | uasm_i_dmfc0(p, ptr, C0_CONTEXT); |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 650 | uasm_i_dsrl_safe(p, ptr, ptr, 23); |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 651 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 652 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 653 | uasm_i_daddu(p, ptr, ptr, tmp); |
| 654 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); |
| 655 | uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 657 | UASM_i_LA_mostly(p, ptr, pgdc); |
| 658 | uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | #endif |
| 660 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 661 | uasm_l_vmalloc_done(l, *p); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 662 | |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 663 | /* get pgd offset in bytes */ |
| 664 | uasm_i_dsrl_safe(p, tmp, tmp, PGDIR_SHIFT - 3); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 665 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 666 | uasm_i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3); |
| 667 | uasm_i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */ |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 668 | #ifndef __PAGETABLE_PMD_FOLDED |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 669 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 670 | uasm_i_ld(p, ptr, 0, ptr); /* get pmd pointer */ |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 671 | uasm_i_dsrl_safe(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 672 | uasm_i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3); |
| 673 | uasm_i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */ |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 674 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 677 | enum vmalloc64_mode {not_refill, refill}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* |
| 679 | * BVADDR is the faulting address, PTR is scratch. |
| 680 | * PTR will hold the pgd for vmalloc. |
| 681 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 682 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 683 | build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 684 | unsigned int bvaddr, unsigned int ptr, |
| 685 | enum vmalloc64_mode mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
| 687 | long swpd = (long)swapper_pg_dir; |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 688 | int single_insn_swpd; |
| 689 | int did_vmalloc_branch = 0; |
| 690 | |
| 691 | single_insn_swpd = uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 693 | uasm_l_vmalloc(l, *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 695 | if (mode == refill && check_for_high_segbits) { |
| 696 | if (single_insn_swpd) { |
| 697 | uasm_il_bltz(p, r, bvaddr, label_vmalloc_done); |
| 698 | uasm_i_lui(p, ptr, uasm_rel_hi(swpd)); |
| 699 | did_vmalloc_branch = 1; |
| 700 | /* fall through */ |
| 701 | } else { |
| 702 | uasm_il_bgez(p, r, bvaddr, label_large_segbits_fault); |
| 703 | } |
| 704 | } |
| 705 | if (!did_vmalloc_branch) { |
| 706 | if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) { |
| 707 | uasm_il_b(p, r, label_vmalloc_done); |
| 708 | uasm_i_lui(p, ptr, uasm_rel_hi(swpd)); |
| 709 | } else { |
| 710 | UASM_i_LA_mostly(p, ptr, swpd); |
| 711 | uasm_il_b(p, r, label_vmalloc_done); |
| 712 | if (uasm_in_compat_space_p(swpd)) |
| 713 | uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd)); |
| 714 | else |
| 715 | uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd)); |
| 716 | } |
| 717 | } |
| 718 | if (mode == refill && check_for_high_segbits) { |
| 719 | uasm_l_large_segbits_fault(l, *p); |
| 720 | /* |
| 721 | * We get here if we are an xsseg address, or if we are |
| 722 | * an xuseg address above (PGDIR_SHIFT+PGDIR_BITS) boundary. |
| 723 | * |
| 724 | * Ignoring xsseg (assume disabled so would generate |
| 725 | * (address errors?), the only remaining possibility |
| 726 | * is the upper xuseg addresses. On processors with |
| 727 | * TLB_SEGBITS <= PGDIR_SHIFT+PGDIR_BITS, these |
| 728 | * addresses would have taken an address error. We try |
| 729 | * to mimic that here by taking a load/istream page |
| 730 | * fault. |
| 731 | */ |
| 732 | UASM_i_LA(p, ptr, (unsigned long)tlb_do_page_fault_0); |
| 733 | uasm_i_jr(p, ptr); |
| 734 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 738 | #else /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
| 740 | /* |
| 741 | * TMP and PTR are scratch. |
| 742 | * TMP will be clobbered, PTR will hold the pgd entry. |
| 743 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 744 | static void __cpuinit __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr) |
| 746 | { |
| 747 | long pgdc = (long)pgd_current; |
| 748 | |
| 749 | /* 32 bit SMP has smp_processor_id() stored in CONTEXT. */ |
| 750 | #ifdef CONFIG_SMP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 751 | #ifdef CONFIG_MIPS_MT_SMTC |
| 752 | /* |
| 753 | * SMTC uses TCBind value as "CPU" index |
| 754 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 755 | uasm_i_mfc0(p, ptr, C0_TCBIND); |
| 756 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 757 | uasm_i_srl(p, ptr, ptr, 19); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 758 | #else |
| 759 | /* |
| 760 | * smp_processor_id() << 3 is stored in CONTEXT. |
| 761 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 762 | uasm_i_mfc0(p, ptr, C0_CONTEXT); |
| 763 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 764 | uasm_i_srl(p, ptr, ptr, 23); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 765 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 766 | uasm_i_addu(p, ptr, tmp, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 768 | UASM_i_LA_mostly(p, ptr, pgdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 770 | uasm_i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 771 | uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr); |
| 772 | uasm_i_srl(p, tmp, tmp, PGDIR_SHIFT); /* get pgd only bits */ |
| 773 | uasm_i_sll(p, tmp, tmp, PGD_T_LOG2); |
| 774 | uasm_i_addu(p, ptr, ptr, tmp); /* add in pgd offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 777 | #endif /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 779 | static void __cpuinit build_adjust_context(u32 **p, unsigned int ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 781 | unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1); |
| 783 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 784 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | case CPU_VR41XX: |
| 786 | case CPU_VR4111: |
| 787 | case CPU_VR4121: |
| 788 | case CPU_VR4122: |
| 789 | case CPU_VR4131: |
| 790 | case CPU_VR4181: |
| 791 | case CPU_VR4181A: |
| 792 | case CPU_VR4133: |
| 793 | shift += 2; |
| 794 | break; |
| 795 | |
| 796 | default: |
| 797 | break; |
| 798 | } |
| 799 | |
| 800 | if (shift) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 801 | UASM_i_SRL(p, ctx, ctx, shift); |
| 802 | uasm_i_andi(p, ctx, ctx, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 805 | static void __cpuinit build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
| 807 | /* |
| 808 | * Bug workaround for the Nevada. It seems as if under certain |
| 809 | * circumstances the move from cp0_context might produce a |
| 810 | * bogus result when the mfc0 instruction and its consumer are |
| 811 | * in a different cacheline or a load instruction, probably any |
| 812 | * memory reference, is between them. |
| 813 | */ |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 814 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 816 | UASM_i_LW(p, ptr, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | GET_CONTEXT(p, tmp); /* get context reg */ |
| 818 | break; |
| 819 | |
| 820 | default: |
| 821 | GET_CONTEXT(p, tmp); /* get context reg */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 822 | UASM_i_LW(p, ptr, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | break; |
| 824 | } |
| 825 | |
| 826 | build_adjust_context(p, tmp); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 827 | UASM_i_ADDU(p, ptr, ptr, tmp); /* add in offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 830 | static void __cpuinit build_update_entries(u32 **p, unsigned int tmp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | unsigned int ptep) |
| 832 | { |
| 833 | /* |
| 834 | * 64bit address support (36bit on a 32bit CPU) in a 32bit |
| 835 | * Kernel is a special case. Only a few CPUs use it. |
| 836 | */ |
| 837 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 838 | if (cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 839 | uasm_i_ld(p, tmp, 0, ptep); /* get even pte */ |
| 840 | uasm_i_ld(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 841 | if (kernel_uses_smartmips_rixi) { |
| 842 | UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_NO_EXEC)); |
| 843 | UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_NO_EXEC)); |
| 844 | UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); |
| 845 | UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 846 | UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); |
| 847 | } else { |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 848 | uasm_i_dsrl_safe(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */ |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 849 | UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 850 | uasm_i_dsrl_safe(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */ |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 851 | } |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 852 | UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } else { |
| 854 | int pte_off_even = sizeof(pte_t) / 2; |
| 855 | int pte_off_odd = pte_off_even + sizeof(pte_t); |
| 856 | |
| 857 | /* The pte entries are pre-shifted */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 858 | uasm_i_lw(p, tmp, pte_off_even, ptep); /* get even pte */ |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 859 | UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 860 | uasm_i_lw(p, ptep, pte_off_odd, ptep); /* get odd pte */ |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 861 | UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 864 | UASM_i_LW(p, tmp, 0, ptep); /* get even pte */ |
| 865 | UASM_i_LW(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | if (r45k_bvahwbug()) |
| 867 | build_tlb_probe_entry(p); |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 868 | if (kernel_uses_smartmips_rixi) { |
| 869 | UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_NO_EXEC)); |
| 870 | UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_NO_EXEC)); |
| 871 | UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); |
| 872 | if (r4k_250MHZhwbug()) |
| 873 | UASM_i_MTC0(p, 0, C0_ENTRYLO0); |
| 874 | UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 875 | UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); |
| 876 | } else { |
| 877 | UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */ |
| 878 | if (r4k_250MHZhwbug()) |
| 879 | UASM_i_MTC0(p, 0, C0_ENTRYLO0); |
| 880 | UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 881 | UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */ |
| 882 | if (r45k_bvahwbug()) |
| 883 | uasm_i_mfc0(p, tmp, C0_INDEX); |
| 884 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | if (r4k_250MHZhwbug()) |
David Daney | 9b8c389 | 2010-02-10 15:12:44 -0800 | [diff] [blame] | 886 | UASM_i_MTC0(p, 0, C0_ENTRYLO1); |
| 887 | UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | #endif |
| 889 | } |
| 890 | |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 891 | /* |
| 892 | * For a 64-bit kernel, we are using the 64-bit XTLB refill exception |
| 893 | * because EXL == 0. If we wrap, we can also use the 32 instruction |
| 894 | * slots before the XTLB refill exception handler which belong to the |
| 895 | * unused TLB refill exception. |
| 896 | */ |
| 897 | #define MIPS64_REFILL_INSNS 32 |
| 898 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 899 | static void __cpuinit build_r4000_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
| 901 | u32 *p = tlb_handler; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 902 | struct uasm_label *l = labels; |
| 903 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | u32 *f; |
| 905 | unsigned int final_len; |
| 906 | |
| 907 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 908 | memset(labels, 0, sizeof(labels)); |
| 909 | memset(relocs, 0, sizeof(relocs)); |
| 910 | memset(final_handler, 0, sizeof(final_handler)); |
| 911 | |
| 912 | /* |
| 913 | * create the plain linear handler |
| 914 | */ |
| 915 | if (bcm1250_m3_war()) { |
Ralf Baechle | 3d45285 | 2010-03-23 17:56:38 +0100 | [diff] [blame] | 916 | unsigned int segbits = 44; |
| 917 | |
| 918 | uasm_i_dmfc0(&p, K0, C0_BADVADDR); |
| 919 | uasm_i_dmfc0(&p, K1, C0_ENTRYHI); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 920 | uasm_i_xor(&p, K0, K0, K1); |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 921 | uasm_i_dsrl_safe(&p, K1, K0, 62); |
| 922 | uasm_i_dsrl_safe(&p, K0, K0, 12 + 1); |
| 923 | uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits); |
Ralf Baechle | 3d45285 | 2010-03-23 17:56:38 +0100 | [diff] [blame] | 924 | uasm_i_or(&p, K0, K0, K1); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 925 | uasm_il_bnez(&p, &r, K0, label_leave); |
| 926 | /* No need for uasm_i_nop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 929 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | build_get_pmde64(&p, &l, &r, K0, K1); /* get pmd in K1 */ |
| 931 | #else |
| 932 | build_get_pgde32(&p, K0, K1); /* get pgd in K1 */ |
| 933 | #endif |
| 934 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 935 | #ifdef CONFIG_HUGETLB_PAGE |
| 936 | build_is_huge_pte(&p, &r, K0, K1, label_tlb_huge_update); |
| 937 | #endif |
| 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | build_get_ptep(&p, K0, K1); |
| 940 | build_update_entries(&p, K0, K1); |
| 941 | build_tlb_write_entry(&p, &l, &r, tlb_random); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 942 | uasm_l_leave(&l, p); |
| 943 | uasm_i_eret(&p); /* return from trap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 945 | #ifdef CONFIG_HUGETLB_PAGE |
| 946 | uasm_l_tlb_huge_update(&l, p); |
| 947 | UASM_i_LW(&p, K0, 0, K1); |
| 948 | build_huge_update_entries(&p, K0, K1); |
| 949 | build_huge_tlb_write_entry(&p, &l, &r, K0, tlb_random); |
| 950 | #endif |
| 951 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 952 | #ifdef CONFIG_64BIT |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 953 | build_get_pgd_vmalloc64(&p, &l, &r, K0, K1, refill); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | #endif |
| 955 | |
| 956 | /* |
| 957 | * Overflow check: For the 64bit handler, we need at least one |
| 958 | * free instruction slot for the wrap-around branch. In worst |
| 959 | * case, if the intended insertion point is a delay slot, we |
Matt LaPlante | 4b3f686 | 2006-10-03 22:21:02 +0200 | [diff] [blame] | 960 | * need three, with the second nop'ed and the third being |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | * unused. |
| 962 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 963 | /* Loongson2 ebase is different than r4k, we have more space */ |
| 964 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | if ((p - tlb_handler) > 64) |
| 966 | panic("TLB refill handler space exceeded"); |
| 967 | #else |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 968 | if (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 1) |
| 969 | || (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 3) |
| 970 | && uasm_insn_has_bdelay(relocs, |
| 971 | tlb_handler + MIPS64_REFILL_INSNS - 3))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | panic("TLB refill handler space exceeded"); |
| 973 | #endif |
| 974 | |
| 975 | /* |
| 976 | * Now fold the handler in the TLB refill handler space. |
| 977 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 978 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | f = final_handler; |
| 980 | /* Simplest case, just copy the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 981 | uasm_copy_handler(relocs, labels, tlb_handler, p, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | final_len = p - tlb_handler; |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 983 | #else /* CONFIG_64BIT */ |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 984 | f = final_handler + MIPS64_REFILL_INSNS; |
| 985 | if ((p - tlb_handler) <= MIPS64_REFILL_INSNS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | /* Just copy the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 987 | uasm_copy_handler(relocs, labels, tlb_handler, p, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | final_len = p - tlb_handler; |
| 989 | } else { |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 990 | #if defined(CONFIG_HUGETLB_PAGE) |
| 991 | const enum label_id ls = label_tlb_huge_update; |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 992 | #else |
| 993 | const enum label_id ls = label_vmalloc; |
| 994 | #endif |
| 995 | u32 *split; |
| 996 | int ov = 0; |
| 997 | int i; |
| 998 | |
| 999 | for (i = 0; i < ARRAY_SIZE(labels) && labels[i].lab != ls; i++) |
| 1000 | ; |
| 1001 | BUG_ON(i == ARRAY_SIZE(labels)); |
| 1002 | split = labels[i].addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | /* |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 1005 | * See if we have overflown one way or the other. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | */ |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 1007 | if (split > tlb_handler + MIPS64_REFILL_INSNS || |
| 1008 | split < p - MIPS64_REFILL_INSNS) |
| 1009 | ov = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 1011 | if (ov) { |
| 1012 | /* |
| 1013 | * Split two instructions before the end. One |
| 1014 | * for the branch and one for the instruction |
| 1015 | * in the delay slot. |
| 1016 | */ |
| 1017 | split = tlb_handler + MIPS64_REFILL_INSNS - 2; |
| 1018 | |
| 1019 | /* |
| 1020 | * If the branch would fall in a delay slot, |
| 1021 | * we must back up an additional instruction |
| 1022 | * so that it is no longer in a delay slot. |
| 1023 | */ |
| 1024 | if (uasm_insn_has_bdelay(relocs, split - 1)) |
| 1025 | split--; |
| 1026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | /* Copy first part of the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1028 | uasm_copy_handler(relocs, labels, tlb_handler, split, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | f += split - tlb_handler; |
| 1030 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame] | 1031 | if (ov) { |
| 1032 | /* Insert branch. */ |
| 1033 | uasm_l_split(&l, final_handler); |
| 1034 | uasm_il_b(&f, &r, label_split); |
| 1035 | if (uasm_insn_has_bdelay(relocs, split)) |
| 1036 | uasm_i_nop(&f); |
| 1037 | else { |
| 1038 | uasm_copy_handler(relocs, labels, |
| 1039 | split, split + 1, f); |
| 1040 | uasm_move_labels(labels, f, f + 1, -1); |
| 1041 | f++; |
| 1042 | split++; |
| 1043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /* Copy the rest of the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1047 | uasm_copy_handler(relocs, labels, split, p, final_handler); |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 1048 | final_len = (f - (final_handler + MIPS64_REFILL_INSNS)) + |
| 1049 | (p - split); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1051 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1053 | uasm_resolve_relocs(relocs, labels); |
| 1054 | pr_debug("Wrote TLB refill handler (%u instructions).\n", |
| 1055 | final_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 1057 | memcpy((void *)ebase, final_handler, 0x100); |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1058 | |
| 1059 | dump_handler((u32 *)ebase, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | * 128 instructions for the fastpath handler is generous and should |
| 1064 | * never be exceeded. |
| 1065 | */ |
| 1066 | #define FASTPATH_SIZE 128 |
| 1067 | |
Franck Bui-Huu | cbdbe07 | 2007-10-18 09:11:16 +0200 | [diff] [blame] | 1068 | u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned; |
| 1069 | u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned; |
| 1070 | u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned; |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 1071 | #ifdef CONFIG_MIPS_PGD_C0_CONTEXT |
| 1072 | u32 tlbmiss_handler_setup_pgd[16] __cacheline_aligned; |
| 1073 | |
| 1074 | static void __cpuinit build_r4000_setup_pgd(void) |
| 1075 | { |
| 1076 | const int a0 = 4; |
| 1077 | const int a1 = 5; |
| 1078 | u32 *p = tlbmiss_handler_setup_pgd; |
| 1079 | struct uasm_label *l = labels; |
| 1080 | struct uasm_reloc *r = relocs; |
| 1081 | |
| 1082 | memset(tlbmiss_handler_setup_pgd, 0, sizeof(tlbmiss_handler_setup_pgd)); |
| 1083 | memset(labels, 0, sizeof(labels)); |
| 1084 | memset(relocs, 0, sizeof(relocs)); |
| 1085 | |
| 1086 | pgd_reg = allocate_kscratch(); |
| 1087 | |
| 1088 | if (pgd_reg == -1) { |
| 1089 | /* PGD << 11 in c0_Context */ |
| 1090 | /* |
| 1091 | * If it is a ckseg0 address, convert to a physical |
| 1092 | * address. Shifting right by 29 and adding 4 will |
| 1093 | * result in zero for these addresses. |
| 1094 | * |
| 1095 | */ |
| 1096 | UASM_i_SRA(&p, a1, a0, 29); |
| 1097 | UASM_i_ADDIU(&p, a1, a1, 4); |
| 1098 | uasm_il_bnez(&p, &r, a1, label_tlbl_goaround1); |
| 1099 | uasm_i_nop(&p); |
| 1100 | uasm_i_dinsm(&p, a0, 0, 29, 64 - 29); |
| 1101 | uasm_l_tlbl_goaround1(&l, p); |
| 1102 | UASM_i_SLL(&p, a0, a0, 11); |
| 1103 | uasm_i_jr(&p, 31); |
| 1104 | UASM_i_MTC0(&p, a0, C0_CONTEXT); |
| 1105 | } else { |
| 1106 | /* PGD in c0_KScratch */ |
| 1107 | uasm_i_jr(&p, 31); |
| 1108 | UASM_i_MTC0(&p, a0, 31, pgd_reg); |
| 1109 | } |
| 1110 | if (p - tlbmiss_handler_setup_pgd > ARRAY_SIZE(tlbmiss_handler_setup_pgd)) |
| 1111 | panic("tlbmiss_handler_setup_pgd space exceeded"); |
| 1112 | uasm_resolve_relocs(relocs, labels); |
| 1113 | pr_debug("Wrote tlbmiss_handler_setup_pgd (%u instructions).\n", |
| 1114 | (unsigned int)(p - tlbmiss_handler_setup_pgd)); |
| 1115 | |
| 1116 | dump_handler(tlbmiss_handler_setup_pgd, |
| 1117 | ARRAY_SIZE(tlbmiss_handler_setup_pgd)); |
| 1118 | } |
| 1119 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1121 | static void __cpuinit |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1122 | iPTE_LW(u32 **p, unsigned int pte, unsigned int ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
| 1124 | #ifdef CONFIG_SMP |
| 1125 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1126 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1127 | uasm_i_lld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | else |
| 1129 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1130 | UASM_i_LL(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | #else |
| 1132 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1133 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1134 | uasm_i_ld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | else |
| 1136 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1137 | UASM_i_LW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | #endif |
| 1139 | } |
| 1140 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1141 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1142 | iPTE_SW(u32 **p, struct uasm_reloc **r, unsigned int pte, unsigned int ptr, |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1143 | unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1145 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 1146 | unsigned int hwmode = mode & (_PAGE_VALID | _PAGE_DIRTY); |
| 1147 | #endif |
| 1148 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1149 | uasm_i_ori(p, pte, pte, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | #ifdef CONFIG_SMP |
| 1151 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1152 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1153 | uasm_i_scd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | else |
| 1155 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1156 | UASM_i_SC(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | if (r10000_llsc_war()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1159 | uasm_il_beqzl(p, r, pte, label_smp_pgtable_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1161 | uasm_il_beqz(p, r, pte, label_smp_pgtable_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1164 | if (!cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1165 | /* no uasm_i_nop needed */ |
| 1166 | uasm_i_ll(p, pte, sizeof(pte_t) / 2, ptr); |
| 1167 | uasm_i_ori(p, pte, pte, hwmode); |
| 1168 | uasm_i_sc(p, pte, sizeof(pte_t) / 2, ptr); |
| 1169 | uasm_il_beqz(p, r, pte, label_smp_pgtable_change); |
| 1170 | /* no uasm_i_nop needed */ |
| 1171 | uasm_i_lw(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1173 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | # else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1175 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | # endif |
| 1177 | #else |
| 1178 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1179 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1180 | uasm_i_sd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | else |
| 1182 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1183 | UASM_i_SW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
| 1185 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1186 | if (!cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1187 | uasm_i_lw(p, pte, sizeof(pte_t) / 2, ptr); |
| 1188 | uasm_i_ori(p, pte, pte, hwmode); |
| 1189 | uasm_i_sw(p, pte, sizeof(pte_t) / 2, ptr); |
| 1190 | uasm_i_lw(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | # endif |
| 1193 | #endif |
| 1194 | } |
| 1195 | |
| 1196 | /* |
| 1197 | * Check if PTE is present, if not then jump to LABEL. PTR points to |
| 1198 | * the page table where this PTE is located, PTE will be re-loaded |
| 1199 | * with it's original value. |
| 1200 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1201 | static void __cpuinit |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1202 | build_pte_present(u32 **p, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1204 | { |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1205 | if (kernel_uses_smartmips_rixi) { |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1206 | if (use_bbit_insns()) { |
| 1207 | uasm_il_bbit0(p, r, pte, ilog2(_PAGE_PRESENT), lid); |
| 1208 | uasm_i_nop(p); |
| 1209 | } else { |
| 1210 | uasm_i_andi(p, pte, pte, _PAGE_PRESENT); |
| 1211 | uasm_il_beqz(p, r, pte, lid); |
| 1212 | iPTE_LW(p, pte, ptr); |
| 1213 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1214 | } else { |
| 1215 | uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 1216 | uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 1217 | uasm_il_bnez(p, r, pte, lid); |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1218 | iPTE_LW(p, pte, ptr); |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /* Make PTE valid, store result in PTR. */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1223 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1224 | build_make_valid(u32 **p, struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | unsigned int ptr) |
| 1226 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1227 | unsigned int mode = _PAGE_VALID | _PAGE_ACCESSED; |
| 1228 | |
| 1229 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Check if PTE can be written to, if not branch to LABEL. Regardless |
| 1234 | * restore PTE with value from PTR when done. |
| 1235 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1236 | static void __cpuinit |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1237 | build_pte_writable(u32 **p, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1239 | { |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1240 | if (use_bbit_insns()) { |
| 1241 | uasm_il_bbit0(p, r, pte, ilog2(_PAGE_PRESENT), lid); |
| 1242 | uasm_i_nop(p); |
| 1243 | uasm_il_bbit0(p, r, pte, ilog2(_PAGE_WRITE), lid); |
| 1244 | uasm_i_nop(p); |
| 1245 | } else { |
| 1246 | uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 1247 | uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 1248 | uasm_il_bnez(p, r, pte, lid); |
| 1249 | iPTE_LW(p, pte, ptr); |
| 1250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /* Make PTE writable, update software status bits as well, then store |
| 1254 | * at PTR. |
| 1255 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1256 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1257 | build_make_write(u32 **p, struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | unsigned int ptr) |
| 1259 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1260 | unsigned int mode = (_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID |
| 1261 | | _PAGE_DIRTY); |
| 1262 | |
| 1263 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * Check if PTE can be modified, if not branch to LABEL. Regardless |
| 1268 | * restore PTE with value from PTR when done. |
| 1269 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1270 | static void __cpuinit |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1271 | build_pte_modifiable(u32 **p, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1273 | { |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1274 | if (use_bbit_insns()) { |
| 1275 | uasm_il_bbit0(p, r, pte, ilog2(_PAGE_WRITE), lid); |
| 1276 | uasm_i_nop(p); |
| 1277 | } else { |
| 1278 | uasm_i_andi(p, pte, pte, _PAGE_WRITE); |
| 1279 | uasm_il_beqz(p, r, pte, lid); |
| 1280 | iPTE_LW(p, pte, ptr); |
| 1281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 1284 | #ifndef CONFIG_MIPS_PGD_C0_CONTEXT |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 1285 | |
| 1286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | /* |
| 1288 | * R3000 style TLB load/store/modify handlers. |
| 1289 | */ |
| 1290 | |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1291 | /* |
| 1292 | * This places the pte into ENTRYLO0 and writes it with tlbwi. |
| 1293 | * Then it returns. |
| 1294 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1295 | static void __cpuinit |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1296 | build_r3000_pte_reload_tlbwi(u32 **p, unsigned int pte, unsigned int tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1298 | uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 1299 | uasm_i_mfc0(p, tmp, C0_EPC); /* cp0 delay */ |
| 1300 | uasm_i_tlbwi(p); |
| 1301 | uasm_i_jr(p, tmp); |
| 1302 | uasm_i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | /* |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1306 | * This places the pte into ENTRYLO0 and writes it with tlbwi |
| 1307 | * or tlbwr as appropriate. This is because the index register |
| 1308 | * may have the probe fail bit set as a result of a trap on a |
| 1309 | * kseg2 access, i.e. without refill. Then it returns. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1311 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1312 | build_r3000_tlb_reload_write(u32 **p, struct uasm_label **l, |
| 1313 | struct uasm_reloc **r, unsigned int pte, |
| 1314 | unsigned int tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1316 | uasm_i_mfc0(p, tmp, C0_INDEX); |
| 1317 | uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 1318 | uasm_il_bltz(p, r, tmp, label_r3000_write_probe_fail); /* cp0 delay */ |
| 1319 | uasm_i_mfc0(p, tmp, C0_EPC); /* branch delay */ |
| 1320 | uasm_i_tlbwi(p); /* cp0 delay */ |
| 1321 | uasm_i_jr(p, tmp); |
| 1322 | uasm_i_rfe(p); /* branch delay */ |
| 1323 | uasm_l_r3000_write_probe_fail(l, *p); |
| 1324 | uasm_i_tlbwr(p); /* cp0 delay */ |
| 1325 | uasm_i_jr(p, tmp); |
| 1326 | uasm_i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1329 | static void __cpuinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | build_r3000_tlbchange_handler_head(u32 **p, unsigned int pte, |
| 1331 | unsigned int ptr) |
| 1332 | { |
| 1333 | long pgdc = (long)pgd_current; |
| 1334 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1335 | uasm_i_mfc0(p, pte, C0_BADVADDR); |
| 1336 | uasm_i_lui(p, ptr, uasm_rel_hi(pgdc)); /* cp0 delay */ |
| 1337 | uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr); |
| 1338 | uasm_i_srl(p, pte, pte, 22); /* load delay */ |
| 1339 | uasm_i_sll(p, pte, pte, 2); |
| 1340 | uasm_i_addu(p, ptr, ptr, pte); |
| 1341 | uasm_i_mfc0(p, pte, C0_CONTEXT); |
| 1342 | uasm_i_lw(p, ptr, 0, ptr); /* cp0 delay */ |
| 1343 | uasm_i_andi(p, pte, pte, 0xffc); /* load delay */ |
| 1344 | uasm_i_addu(p, ptr, ptr, pte); |
| 1345 | uasm_i_lw(p, pte, 0, ptr); |
| 1346 | uasm_i_tlbp(p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1349 | static void __cpuinit build_r3000_tlb_load_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | { |
| 1351 | u32 *p = handle_tlbl; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1352 | struct uasm_label *l = labels; |
| 1353 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
| 1355 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1356 | memset(labels, 0, sizeof(labels)); |
| 1357 | memset(relocs, 0, sizeof(relocs)); |
| 1358 | |
| 1359 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1360 | build_pte_present(&p, &r, K0, K1, label_nopage_tlbl); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1361 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | build_make_valid(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1363 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1365 | uasm_l_nopage_tlbl(&l, p); |
| 1366 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1367 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
| 1369 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1370 | panic("TLB load handler fastpath space exceeded"); |
| 1371 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1372 | uasm_resolve_relocs(relocs, labels); |
| 1373 | pr_debug("Wrote TLB load handler fastpath (%u instructions).\n", |
| 1374 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1376 | dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1379 | static void __cpuinit build_r3000_tlb_store_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { |
| 1381 | u32 *p = handle_tlbs; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1382 | struct uasm_label *l = labels; |
| 1383 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
| 1385 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1386 | memset(labels, 0, sizeof(labels)); |
| 1387 | memset(relocs, 0, sizeof(relocs)); |
| 1388 | |
| 1389 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1390 | build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1391 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1393 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1395 | uasm_l_nopage_tlbs(&l, p); |
| 1396 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1397 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
| 1399 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1400 | panic("TLB store handler fastpath space exceeded"); |
| 1401 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1402 | uasm_resolve_relocs(relocs, labels); |
| 1403 | pr_debug("Wrote TLB store handler fastpath (%u instructions).\n", |
| 1404 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1406 | dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1409 | static void __cpuinit build_r3000_tlb_modify_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | { |
| 1411 | u32 *p = handle_tlbm; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1412 | struct uasm_label *l = labels; |
| 1413 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
| 1415 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1416 | memset(labels, 0, sizeof(labels)); |
| 1417 | memset(relocs, 0, sizeof(relocs)); |
| 1418 | |
| 1419 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1420 | build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1421 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1423 | build_r3000_pte_reload_tlbwi(&p, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1425 | uasm_l_nopage_tlbm(&l, p); |
| 1426 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1427 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
| 1429 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1430 | panic("TLB modify handler fastpath space exceeded"); |
| 1431 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1432 | uasm_resolve_relocs(relocs, labels); |
| 1433 | pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n", |
| 1434 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1436 | dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | } |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 1438 | #endif /* CONFIG_MIPS_PGD_C0_CONTEXT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
| 1440 | /* |
| 1441 | * R4000 style TLB load/store/modify handlers. |
| 1442 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1443 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1444 | build_r4000_tlbchange_handler_head(u32 **p, struct uasm_label **l, |
| 1445 | struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | unsigned int ptr) |
| 1447 | { |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1448 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | build_get_pmde64(p, l, r, pte, ptr); /* get pmd in ptr */ |
| 1450 | #else |
| 1451 | build_get_pgde32(p, pte, ptr); /* get pgd in ptr */ |
| 1452 | #endif |
| 1453 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 1454 | #ifdef CONFIG_HUGETLB_PAGE |
| 1455 | /* |
| 1456 | * For huge tlb entries, pmd doesn't contain an address but |
| 1457 | * instead contains the tlb pte. Check the PAGE_HUGE bit and |
| 1458 | * see if we need to jump to huge tlb processing. |
| 1459 | */ |
| 1460 | build_is_huge_pte(p, r, pte, ptr, label_tlb_huge_update); |
| 1461 | #endif |
| 1462 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1463 | UASM_i_MFC0(p, pte, C0_BADVADDR); |
| 1464 | UASM_i_LW(p, ptr, 0, ptr); |
| 1465 | UASM_i_SRL(p, pte, pte, PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2); |
| 1466 | uasm_i_andi(p, pte, pte, (PTRS_PER_PTE - 1) << PTE_T_LOG2); |
| 1467 | UASM_i_ADDU(p, ptr, ptr, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
| 1469 | #ifdef CONFIG_SMP |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1470 | uasm_l_smp_pgtable_change(l, *p); |
| 1471 | #endif |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1472 | iPTE_LW(p, pte, ptr); /* get even pte */ |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1473 | if (!m4kc_tlbp_war()) |
| 1474 | build_tlb_probe_entry(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1477 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1478 | build_r4000_tlbchange_handler_tail(u32 **p, struct uasm_label **l, |
| 1479 | struct uasm_reloc **r, unsigned int tmp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | unsigned int ptr) |
| 1481 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1482 | uasm_i_ori(p, ptr, ptr, sizeof(pte_t)); |
| 1483 | uasm_i_xori(p, ptr, ptr, sizeof(pte_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | build_update_entries(p, tmp, ptr); |
| 1485 | build_tlb_write_entry(p, l, r, tlb_indexed); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1486 | uasm_l_leave(l, *p); |
| 1487 | uasm_i_eret(p); /* return from trap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1489 | #ifdef CONFIG_64BIT |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 1490 | build_get_pgd_vmalloc64(p, l, r, tmp, ptr, not_refill); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | #endif |
| 1492 | } |
| 1493 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1494 | static void __cpuinit build_r4000_tlb_load_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | { |
| 1496 | u32 *p = handle_tlbl; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1497 | struct uasm_label *l = labels; |
| 1498 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
| 1500 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1501 | memset(labels, 0, sizeof(labels)); |
| 1502 | memset(relocs, 0, sizeof(relocs)); |
| 1503 | |
| 1504 | if (bcm1250_m3_war()) { |
Ralf Baechle | 3d45285 | 2010-03-23 17:56:38 +0100 | [diff] [blame] | 1505 | unsigned int segbits = 44; |
| 1506 | |
| 1507 | uasm_i_dmfc0(&p, K0, C0_BADVADDR); |
| 1508 | uasm_i_dmfc0(&p, K1, C0_ENTRYHI); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1509 | uasm_i_xor(&p, K0, K0, K1); |
David Daney | 3be6022 | 2010-04-28 12:16:17 -0700 | [diff] [blame] | 1510 | uasm_i_dsrl_safe(&p, K1, K0, 62); |
| 1511 | uasm_i_dsrl_safe(&p, K0, K0, 12 + 1); |
| 1512 | uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits); |
Ralf Baechle | 3d45285 | 2010-03-23 17:56:38 +0100 | [diff] [blame] | 1513 | uasm_i_or(&p, K0, K0, K1); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1514 | uasm_il_bnez(&p, &r, K0, label_leave); |
| 1515 | /* No need for uasm_i_nop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1519 | build_pte_present(&p, &r, K0, K1, label_nopage_tlbl); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1520 | if (m4kc_tlbp_war()) |
| 1521 | build_tlb_probe_entry(&p); |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1522 | |
| 1523 | if (kernel_uses_smartmips_rixi) { |
| 1524 | /* |
| 1525 | * If the page is not _PAGE_VALID, RI or XI could not |
| 1526 | * have triggered it. Skip the expensive test.. |
| 1527 | */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1528 | if (use_bbit_insns()) { |
| 1529 | uasm_il_bbit0(&p, &r, K0, ilog2(_PAGE_VALID), |
| 1530 | label_tlbl_goaround1); |
| 1531 | } else { |
| 1532 | uasm_i_andi(&p, K0, K0, _PAGE_VALID); |
| 1533 | uasm_il_beqz(&p, &r, K0, label_tlbl_goaround1); |
| 1534 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1535 | uasm_i_nop(&p); |
| 1536 | |
| 1537 | uasm_i_tlbr(&p); |
| 1538 | /* Examine entrylo 0 or 1 based on ptr. */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1539 | if (use_bbit_insns()) { |
| 1540 | uasm_i_bbit0(&p, K1, ilog2(sizeof(pte_t)), 8); |
| 1541 | } else { |
| 1542 | uasm_i_andi(&p, K0, K1, sizeof(pte_t)); |
| 1543 | uasm_i_beqz(&p, K0, 8); |
| 1544 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1545 | |
| 1546 | UASM_i_MFC0(&p, K0, C0_ENTRYLO0); /* load it in the delay slot*/ |
| 1547 | UASM_i_MFC0(&p, K0, C0_ENTRYLO1); /* load it if ptr is odd */ |
| 1548 | /* |
| 1549 | * If the entryLo (now in K0) is valid (bit 1), RI or |
| 1550 | * XI must have triggered it. |
| 1551 | */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1552 | if (use_bbit_insns()) { |
| 1553 | uasm_il_bbit1(&p, &r, K0, 1, label_nopage_tlbl); |
| 1554 | /* Reload the PTE value */ |
| 1555 | iPTE_LW(&p, K0, K1); |
| 1556 | uasm_l_tlbl_goaround1(&l, p); |
| 1557 | } else { |
| 1558 | uasm_i_andi(&p, K0, K0, 2); |
| 1559 | uasm_il_bnez(&p, &r, K0, label_nopage_tlbl); |
| 1560 | uasm_l_tlbl_goaround1(&l, p); |
| 1561 | /* Reload the PTE value */ |
| 1562 | iPTE_LW(&p, K0, K1); |
| 1563 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | build_make_valid(&p, &r, K0, K1); |
| 1566 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1567 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 1568 | #ifdef CONFIG_HUGETLB_PAGE |
| 1569 | /* |
| 1570 | * This is the entry point when build_r4000_tlbchange_handler_head |
| 1571 | * spots a huge page. |
| 1572 | */ |
| 1573 | uasm_l_tlb_huge_update(&l, p); |
| 1574 | iPTE_LW(&p, K0, K1); |
| 1575 | build_pte_present(&p, &r, K0, K1, label_nopage_tlbl); |
| 1576 | build_tlb_probe_entry(&p); |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1577 | |
| 1578 | if (kernel_uses_smartmips_rixi) { |
| 1579 | /* |
| 1580 | * If the page is not _PAGE_VALID, RI or XI could not |
| 1581 | * have triggered it. Skip the expensive test.. |
| 1582 | */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1583 | if (use_bbit_insns()) { |
| 1584 | uasm_il_bbit0(&p, &r, K0, ilog2(_PAGE_VALID), |
| 1585 | label_tlbl_goaround2); |
| 1586 | } else { |
| 1587 | uasm_i_andi(&p, K0, K0, _PAGE_VALID); |
| 1588 | uasm_il_beqz(&p, &r, K0, label_tlbl_goaround2); |
| 1589 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1590 | uasm_i_nop(&p); |
| 1591 | |
| 1592 | uasm_i_tlbr(&p); |
| 1593 | /* Examine entrylo 0 or 1 based on ptr. */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1594 | if (use_bbit_insns()) { |
| 1595 | uasm_i_bbit0(&p, K1, ilog2(sizeof(pte_t)), 8); |
| 1596 | } else { |
| 1597 | uasm_i_andi(&p, K0, K1, sizeof(pte_t)); |
| 1598 | uasm_i_beqz(&p, K0, 8); |
| 1599 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1600 | UASM_i_MFC0(&p, K0, C0_ENTRYLO0); /* load it in the delay slot*/ |
| 1601 | UASM_i_MFC0(&p, K0, C0_ENTRYLO1); /* load it if ptr is odd */ |
| 1602 | /* |
| 1603 | * If the entryLo (now in K0) is valid (bit 1), RI or |
| 1604 | * XI must have triggered it. |
| 1605 | */ |
David Daney | cc33ae4 | 2010-12-20 15:54:50 -0800 | [diff] [blame^] | 1606 | if (use_bbit_insns()) { |
| 1607 | uasm_il_bbit0(&p, &r, K0, 1, label_tlbl_goaround2); |
| 1608 | } else { |
| 1609 | uasm_i_andi(&p, K0, K0, 2); |
| 1610 | uasm_il_beqz(&p, &r, K0, label_tlbl_goaround2); |
| 1611 | } |
David Daney | 6dd9344 | 2010-02-10 15:12:47 -0800 | [diff] [blame] | 1612 | /* Reload the PTE value */ |
| 1613 | iPTE_LW(&p, K0, K1); |
| 1614 | |
| 1615 | /* |
| 1616 | * We clobbered C0_PAGEMASK, restore it. On the other branch |
| 1617 | * it is restored in build_huge_tlb_write_entry. |
| 1618 | */ |
| 1619 | build_restore_pagemask(&p, &r, K0, label_nopage_tlbl); |
| 1620 | |
| 1621 | uasm_l_tlbl_goaround2(&l, p); |
| 1622 | } |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 1623 | uasm_i_ori(&p, K0, K0, (_PAGE_ACCESSED | _PAGE_VALID)); |
| 1624 | build_huge_handler_tail(&p, &r, &l, K0, K1); |
| 1625 | #endif |
| 1626 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1627 | uasm_l_nopage_tlbl(&l, p); |
| 1628 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1629 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
| 1631 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1632 | panic("TLB load handler fastpath space exceeded"); |
| 1633 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1634 | uasm_resolve_relocs(relocs, labels); |
| 1635 | pr_debug("Wrote TLB load handler fastpath (%u instructions).\n", |
| 1636 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1638 | dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1641 | static void __cpuinit build_r4000_tlb_store_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | { |
| 1643 | u32 *p = handle_tlbs; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1644 | struct uasm_label *l = labels; |
| 1645 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
| 1647 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1648 | memset(labels, 0, sizeof(labels)); |
| 1649 | memset(relocs, 0, sizeof(relocs)); |
| 1650 | |
| 1651 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1652 | build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1653 | if (m4kc_tlbp_war()) |
| 1654 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | build_make_write(&p, &r, K0, K1); |
| 1656 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1657 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 1658 | #ifdef CONFIG_HUGETLB_PAGE |
| 1659 | /* |
| 1660 | * This is the entry point when |
| 1661 | * build_r4000_tlbchange_handler_head spots a huge page. |
| 1662 | */ |
| 1663 | uasm_l_tlb_huge_update(&l, p); |
| 1664 | iPTE_LW(&p, K0, K1); |
| 1665 | build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs); |
| 1666 | build_tlb_probe_entry(&p); |
| 1667 | uasm_i_ori(&p, K0, K0, |
| 1668 | _PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY); |
| 1669 | build_huge_handler_tail(&p, &r, &l, K0, K1); |
| 1670 | #endif |
| 1671 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1672 | uasm_l_nopage_tlbs(&l, p); |
| 1673 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1674 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
| 1676 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1677 | panic("TLB store handler fastpath space exceeded"); |
| 1678 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1679 | uasm_resolve_relocs(relocs, labels); |
| 1680 | pr_debug("Wrote TLB store handler fastpath (%u instructions).\n", |
| 1681 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1683 | dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1686 | static void __cpuinit build_r4000_tlb_modify_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | { |
| 1688 | u32 *p = handle_tlbm; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1689 | struct uasm_label *l = labels; |
| 1690 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | |
| 1692 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1693 | memset(labels, 0, sizeof(labels)); |
| 1694 | memset(relocs, 0, sizeof(relocs)); |
| 1695 | |
| 1696 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
David Daney | bd1437e | 2009-05-08 15:10:50 -0700 | [diff] [blame] | 1697 | build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1698 | if (m4kc_tlbp_war()) |
| 1699 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | /* Present and writable bits set, set accessed and dirty bits. */ |
| 1701 | build_make_write(&p, &r, K0, K1); |
| 1702 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1703 | |
David Daney | fd062c8 | 2009-05-27 17:47:44 -0700 | [diff] [blame] | 1704 | #ifdef CONFIG_HUGETLB_PAGE |
| 1705 | /* |
| 1706 | * This is the entry point when |
| 1707 | * build_r4000_tlbchange_handler_head spots a huge page. |
| 1708 | */ |
| 1709 | uasm_l_tlb_huge_update(&l, p); |
| 1710 | iPTE_LW(&p, K0, K1); |
| 1711 | build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm); |
| 1712 | build_tlb_probe_entry(&p); |
| 1713 | uasm_i_ori(&p, K0, K0, |
| 1714 | _PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY); |
| 1715 | build_huge_handler_tail(&p, &r, &l, K0, K1); |
| 1716 | #endif |
| 1717 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1718 | uasm_l_nopage_tlbm(&l, p); |
| 1719 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1720 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | |
| 1722 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1723 | panic("TLB modify handler fastpath space exceeded"); |
| 1724 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1725 | uasm_resolve_relocs(relocs, labels); |
| 1726 | pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n", |
| 1727 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1729 | dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1732 | void __cpuinit build_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | { |
| 1734 | /* |
| 1735 | * The refill handler is generated per-CPU, multi-node systems |
| 1736 | * may have local storage for it. The other handlers are only |
| 1737 | * needed once. |
| 1738 | */ |
| 1739 | static int run_once = 0; |
| 1740 | |
David Daney | 1ec5632 | 2010-04-28 12:16:18 -0700 | [diff] [blame] | 1741 | #ifdef CONFIG_64BIT |
| 1742 | check_for_high_segbits = current_cpu_data.vmbits > (PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3); |
| 1743 | #endif |
| 1744 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1745 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | case CPU_R2000: |
| 1747 | case CPU_R3000: |
| 1748 | case CPU_R3000A: |
| 1749 | case CPU_R3081E: |
| 1750 | case CPU_TX3912: |
| 1751 | case CPU_TX3922: |
| 1752 | case CPU_TX3927: |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 1753 | #ifndef CONFIG_MIPS_PGD_C0_CONTEXT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | build_r3000_tlb_refill_handler(); |
| 1755 | if (!run_once) { |
| 1756 | build_r3000_tlb_load_handler(); |
| 1757 | build_r3000_tlb_store_handler(); |
| 1758 | build_r3000_tlb_modify_handler(); |
| 1759 | run_once++; |
| 1760 | } |
David Daney | 8262228 | 2009-10-14 12:16:56 -0700 | [diff] [blame] | 1761 | #else |
| 1762 | panic("No R3000 TLB refill handler"); |
| 1763 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | break; |
| 1765 | |
| 1766 | case CPU_R6000: |
| 1767 | case CPU_R6000A: |
| 1768 | panic("No R6000 TLB refill handler yet"); |
| 1769 | break; |
| 1770 | |
| 1771 | case CPU_R8000: |
| 1772 | panic("No R8000 TLB refill handler yet"); |
| 1773 | break; |
| 1774 | |
| 1775 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | if (!run_once) { |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 1777 | #ifdef CONFIG_MIPS_PGD_C0_CONTEXT |
| 1778 | build_r4000_setup_pgd(); |
| 1779 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | build_r4000_tlb_load_handler(); |
| 1781 | build_r4000_tlb_store_handler(); |
| 1782 | build_r4000_tlb_modify_handler(); |
| 1783 | run_once++; |
| 1784 | } |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 1785 | build_r4000_tlb_refill_handler(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } |
| 1787 | } |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1788 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1789 | void __cpuinit flush_tlb_handlers(void) |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1790 | { |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1791 | local_flush_icache_range((unsigned long)handle_tlbl, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1792 | (unsigned long)handle_tlbl + sizeof(handle_tlbl)); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1793 | local_flush_icache_range((unsigned long)handle_tlbs, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1794 | (unsigned long)handle_tlbs + sizeof(handle_tlbs)); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1795 | local_flush_icache_range((unsigned long)handle_tlbm, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1796 | (unsigned long)handle_tlbm + sizeof(handle_tlbm)); |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 1797 | #ifdef CONFIG_MIPS_PGD_C0_CONTEXT |
| 1798 | local_flush_icache_range((unsigned long)tlbmiss_handler_setup_pgd, |
| 1799 | (unsigned long)tlbmiss_handler_setup_pgd + sizeof(handle_tlbm)); |
| 1800 | #endif |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1801 | } |