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) |
| 11 | * |
| 12 | * ... and the days got worse and worse and now you see |
| 13 | * I've gone completly out of my mind. |
| 14 | * |
| 15 | * They're coming to take me a away haha |
| 16 | * they're coming to take me a away hoho hihi haha |
| 17 | * to the funny farm where code is beautiful all the time ... |
| 18 | * |
| 19 | * (Condolences to Napoleon XIV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 22 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/init.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/war.h> |
| 30 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 31 | #include "uasm.h" |
| 32 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 33 | static inline int r45k_bvahwbug(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | /* XXX: We should probe for the presence of this bug, but we don't. */ |
| 36 | return 0; |
| 37 | } |
| 38 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 39 | static inline int r4k_250MHZhwbug(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | /* XXX: We should probe for the presence of this bug, but we don't. */ |
| 42 | return 0; |
| 43 | } |
| 44 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 45 | static inline int __maybe_unused bcm1250_m3_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | return BCM1250_M3_WAR; |
| 48 | } |
| 49 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 50 | static inline int __maybe_unused r10000_llsc_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | return R10000_LLSC_WAR; |
| 53 | } |
| 54 | |
| 55 | /* |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 56 | * Found by experiment: At least some revisions of the 4kc throw under |
| 57 | * some circumstances a machine check exception, triggered by invalid |
| 58 | * values in the index register. Delaying the tlbp instruction until |
| 59 | * after the next branch, plus adding an additional nop in front of |
| 60 | * tlbwi/tlbwr avoids the invalid index register values. Nobody knows |
| 61 | * why; it's not an issue caused by the core RTL. |
| 62 | * |
| 63 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 64 | static int __cpuinit m4kc_tlbp_war(void) |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 65 | { |
| 66 | return (current_cpu_data.processor_id & 0xffff00) == |
| 67 | (PRID_COMP_MIPS | PRID_IMP_4KC); |
| 68 | } |
| 69 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 70 | /* Handle labels (which must be positive integers). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | enum label_id { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 72 | label_second_part = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | label_leave, |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 74 | #ifdef MODULE_START |
| 75 | label_module_alloc, |
| 76 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | label_vmalloc, |
| 78 | label_vmalloc_done, |
| 79 | label_tlbw_hazard, |
| 80 | label_split, |
| 81 | label_nopage_tlbl, |
| 82 | label_nopage_tlbs, |
| 83 | label_nopage_tlbm, |
| 84 | label_smp_pgtable_change, |
| 85 | label_r3000_write_probe_fail, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 88 | UASM_L_LA(_second_part) |
| 89 | UASM_L_LA(_leave) |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 90 | #ifdef MODULE_START |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 91 | UASM_L_LA(_module_alloc) |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 92 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 93 | UASM_L_LA(_vmalloc) |
| 94 | UASM_L_LA(_vmalloc_done) |
| 95 | UASM_L_LA(_tlbw_hazard) |
| 96 | UASM_L_LA(_split) |
| 97 | UASM_L_LA(_nopage_tlbl) |
| 98 | UASM_L_LA(_nopage_tlbs) |
| 99 | UASM_L_LA(_nopage_tlbm) |
| 100 | UASM_L_LA(_smp_pgtable_change) |
| 101 | UASM_L_LA(_r3000_write_probe_fail) |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 102 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 103 | /* |
| 104 | * For debug purposes. |
| 105 | */ |
| 106 | static inline void dump_handler(const u32 *handler, int count) |
| 107 | { |
| 108 | int i; |
| 109 | |
| 110 | pr_debug("\t.set push\n"); |
| 111 | pr_debug("\t.set noreorder\n"); |
| 112 | |
| 113 | for (i = 0; i < count; i++) |
| 114 | pr_debug("\t%p\t.word 0x%08x\n", &handler[i], handler[i]); |
| 115 | |
| 116 | pr_debug("\t.set pop\n"); |
| 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* The only general purpose registers allowed in TLB handlers. */ |
| 120 | #define K0 26 |
| 121 | #define K1 27 |
| 122 | |
| 123 | /* Some CP0 registers */ |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 124 | #define C0_INDEX 0, 0 |
| 125 | #define C0_ENTRYLO0 2, 0 |
| 126 | #define C0_TCBIND 2, 2 |
| 127 | #define C0_ENTRYLO1 3, 0 |
| 128 | #define C0_CONTEXT 4, 0 |
| 129 | #define C0_BADVADDR 8, 0 |
| 130 | #define C0_ENTRYHI 10, 0 |
| 131 | #define C0_EPC 14, 0 |
| 132 | #define C0_XCONTEXT 20, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 134 | #ifdef CONFIG_64BIT |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 135 | # define GET_CONTEXT(buf, reg) UASM_i_MFC0(buf, reg, C0_XCONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 137 | # define GET_CONTEXT(buf, reg) UASM_i_MFC0(buf, reg, C0_CONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
| 140 | /* The worst case length of the handler is around 18 instructions for |
| 141 | * R3000-style TLBs and up to 63 instructions for R4000-style TLBs. |
| 142 | * Maximum space available is 32 instructions for R3000 and 64 |
| 143 | * instructions for R4000. |
| 144 | * |
| 145 | * We deliberately chose a buffer size of 128, so we won't scribble |
| 146 | * over anything important on overflow before we panic. |
| 147 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 148 | static u32 tlb_handler[128] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | /* simply assume worst case size for labels and relocs */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 151 | static struct uasm_label labels[128] __cpuinitdata; |
| 152 | static struct uasm_reloc relocs[128] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * The R3000 TLB handler is simple. |
| 156 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 157 | static void __cpuinit build_r3000_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
| 159 | long pgdc = (long)pgd_current; |
| 160 | u32 *p; |
| 161 | |
| 162 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 163 | p = tlb_handler; |
| 164 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 165 | uasm_i_mfc0(&p, K0, C0_BADVADDR); |
| 166 | uasm_i_lui(&p, K1, uasm_rel_hi(pgdc)); /* cp0 delay */ |
| 167 | uasm_i_lw(&p, K1, uasm_rel_lo(pgdc), K1); |
| 168 | uasm_i_srl(&p, K0, K0, 22); /* load delay */ |
| 169 | uasm_i_sll(&p, K0, K0, 2); |
| 170 | uasm_i_addu(&p, K1, K1, K0); |
| 171 | uasm_i_mfc0(&p, K0, C0_CONTEXT); |
| 172 | uasm_i_lw(&p, K1, 0, K1); /* cp0 delay */ |
| 173 | uasm_i_andi(&p, K0, K0, 0xffc); /* load delay */ |
| 174 | uasm_i_addu(&p, K1, K1, K0); |
| 175 | uasm_i_lw(&p, K0, 0, K1); |
| 176 | uasm_i_nop(&p); /* load delay */ |
| 177 | uasm_i_mtc0(&p, K0, C0_ENTRYLO0); |
| 178 | uasm_i_mfc0(&p, K1, C0_EPC); /* cp0 delay */ |
| 179 | uasm_i_tlbwr(&p); /* cp0 delay */ |
| 180 | uasm_i_jr(&p, K1); |
| 181 | uasm_i_rfe(&p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | if (p > tlb_handler + 32) |
| 184 | panic("TLB refill handler space exceeded"); |
| 185 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 186 | pr_debug("Wrote TLB refill handler (%u instructions).\n", |
| 187 | (unsigned int)(p - tlb_handler)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 189 | memcpy((void *)ebase, tlb_handler, 0x80); |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 190 | |
| 191 | dump_handler((u32 *)ebase, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * The R4000 TLB handler is much more complicated. We have two |
| 196 | * consecutive handler areas with 32 instructions space each. |
| 197 | * Since they aren't used at the same time, we can overflow in the |
| 198 | * other one.To keep things simple, we first assume linear space, |
| 199 | * then we relocate it to the final handler layout as needed. |
| 200 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 201 | static u32 final_handler[64] __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Hazards |
| 205 | * |
| 206 | * From the IDT errata for the QED RM5230 (Nevada), processor revision 1.0: |
| 207 | * 2. A timing hazard exists for the TLBP instruction. |
| 208 | * |
| 209 | * stalling_instruction |
| 210 | * TLBP |
| 211 | * |
| 212 | * The JTLB is being read for the TLBP throughout the stall generated by the |
| 213 | * previous instruction. This is not really correct as the stalling instruction |
| 214 | * can modify the address used to access the JTLB. The failure symptom is that |
| 215 | * the TLBP instruction will use an address created for the stalling instruction |
| 216 | * and not the address held in C0_ENHI and thus report the wrong results. |
| 217 | * |
| 218 | * The software work-around is to not allow the instruction preceding the TLBP |
| 219 | * to stall - make it an NOP or some other instruction guaranteed not to stall. |
| 220 | * |
| 221 | * Errata 2 will not be fixed. This errata is also on the R5000. |
| 222 | * |
| 223 | * As if we MIPS hackers wouldn't know how to nop pipelines happy ... |
| 224 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 225 | static void __cpuinit __maybe_unused build_tlb_probe_entry(u32 **p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 227 | switch (current_cpu_type()) { |
Thomas Bogendoerfer | 326e2e1 | 2008-05-12 13:55:42 +0200 | [diff] [blame] | 228 | /* Found by experiment: R4600 v2.0/R4700 needs this, too. */ |
Thiemo Seufer | f5b4d95 | 2005-09-09 17:11:50 +0000 | [diff] [blame] | 229 | case CPU_R4600: |
Thomas Bogendoerfer | 326e2e1 | 2008-05-12 13:55:42 +0200 | [diff] [blame] | 230 | case CPU_R4700: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | case CPU_R5000: |
| 232 | case CPU_R5000A: |
| 233 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 234 | uasm_i_nop(p); |
| 235 | uasm_i_tlbp(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | break; |
| 237 | |
| 238 | default: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 239 | uasm_i_tlbp(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Write random or indexed TLB entry, and care about the hazards from |
| 246 | * the preceeding mtc0 and for the following eret. |
| 247 | */ |
| 248 | enum tlb_write_entry { tlb_random, tlb_indexed }; |
| 249 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 250 | 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] | 251 | struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | enum tlb_write_entry wmode) |
| 253 | { |
| 254 | void(*tlbw)(u32 **) = NULL; |
| 255 | |
| 256 | switch (wmode) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 257 | case tlb_random: tlbw = uasm_i_tlbwr; break; |
| 258 | case tlb_indexed: tlbw = uasm_i_tlbwi; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Ralf Baechle | 161548b | 2008-01-29 10:14:54 +0000 | [diff] [blame] | 261 | if (cpu_has_mips_r2) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 262 | uasm_i_ehb(p); |
Ralf Baechle | 161548b | 2008-01-29 10:14:54 +0000 | [diff] [blame] | 263 | tlbw(p); |
| 264 | return; |
| 265 | } |
| 266 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 267 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | case CPU_R4000PC: |
| 269 | case CPU_R4000SC: |
| 270 | case CPU_R4000MC: |
| 271 | case CPU_R4400PC: |
| 272 | case CPU_R4400SC: |
| 273 | case CPU_R4400MC: |
| 274 | /* |
| 275 | * This branch uses up a mtc0 hazard nop slot and saves |
| 276 | * two nops after the tlbw instruction. |
| 277 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 278 | uasm_il_bgezl(p, r, 0, label_tlbw_hazard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 280 | uasm_l_tlbw_hazard(l, *p); |
| 281 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | break; |
| 283 | |
| 284 | case CPU_R4600: |
| 285 | case CPU_R4700: |
| 286 | case CPU_R5000: |
| 287 | case CPU_R5000A: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 288 | uasm_i_nop(p); |
Maciej W. Rozycki | 2c93e12 | 2005-06-30 10:51:01 +0000 | [diff] [blame] | 289 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 290 | uasm_i_nop(p); |
Maciej W. Rozycki | 2c93e12 | 2005-06-30 10:51:01 +0000 | [diff] [blame] | 291 | break; |
| 292 | |
| 293 | case CPU_R4300: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | case CPU_5KC: |
| 295 | case CPU_TX49XX: |
Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 296 | case CPU_PR4450: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 297 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | tlbw(p); |
| 299 | break; |
| 300 | |
| 301 | case CPU_R10000: |
| 302 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 303 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | case CPU_4KC: |
Thomas Bogendoerfer | b1ec4c8 | 2008-03-26 16:42:54 +0100 | [diff] [blame] | 305 | case CPU_4KEC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | case CPU_SB1: |
Andrew Isaacson | 93ce2f52 | 2005-10-19 23:56:20 -0700 | [diff] [blame] | 307 | case CPU_SB1A: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | case CPU_4KSC: |
| 309 | case CPU_20KC: |
| 310 | case CPU_25KF: |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 311 | case CPU_BCM3302: |
| 312 | case CPU_BCM4710: |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 313 | case CPU_LOONGSON2: |
David Daney | ec454d8 | 2008-12-11 15:33:35 -0800 | [diff] [blame] | 314 | case CPU_CAVIUM_OCTEON: |
Shinya Kuribayashi | a644b27 | 2009-03-03 18:05:51 +0900 | [diff] [blame] | 315 | case CPU_R5500: |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 316 | if (m4kc_tlbp_war()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 317 | uasm_i_nop(p); |
Manuel Lauss | 2f794d0 | 2009-03-25 17:49:30 +0100 | [diff] [blame] | 318 | case CPU_ALCHEMY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | tlbw(p); |
| 320 | break; |
| 321 | |
| 322 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 323 | uasm_i_nop(p); /* QED specifies 2 nops hazard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* |
| 325 | * This branch uses up a mtc0 hazard nop slot and saves |
| 326 | * a nop after the tlbw instruction. |
| 327 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 328 | uasm_il_bgezl(p, r, 0, label_tlbw_hazard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 330 | uasm_l_tlbw_hazard(l, *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | break; |
| 332 | |
| 333 | case CPU_RM7000: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 334 | uasm_i_nop(p); |
| 335 | uasm_i_nop(p); |
| 336 | uasm_i_nop(p); |
| 337 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | tlbw(p); |
| 339 | break; |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | case CPU_RM9000: |
| 342 | /* |
| 343 | * When the JTLB is updated by tlbwi or tlbwr, a subsequent |
| 344 | * use of the JTLB for instructions should not occur for 4 |
| 345 | * cpu cycles and use for data translations should not occur |
| 346 | * for 3 cpu cycles. |
| 347 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 348 | uasm_i_ssnop(p); |
| 349 | uasm_i_ssnop(p); |
| 350 | uasm_i_ssnop(p); |
| 351 | uasm_i_ssnop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 353 | uasm_i_ssnop(p); |
| 354 | uasm_i_ssnop(p); |
| 355 | uasm_i_ssnop(p); |
| 356 | uasm_i_ssnop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | break; |
| 358 | |
| 359 | case CPU_VR4111: |
| 360 | case CPU_VR4121: |
| 361 | case CPU_VR4122: |
| 362 | case CPU_VR4181: |
| 363 | case CPU_VR4181A: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 364 | uasm_i_nop(p); |
| 365 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | tlbw(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 367 | uasm_i_nop(p); |
| 368 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | break; |
| 370 | |
| 371 | case CPU_VR4131: |
| 372 | case CPU_VR4133: |
Ralf Baechle | 7623deb | 2005-08-29 16:49:55 +0000 | [diff] [blame] | 373 | case CPU_R5432: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 374 | uasm_i_nop(p); |
| 375 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | tlbw(p); |
| 377 | break; |
| 378 | |
| 379 | default: |
| 380 | panic("No TLB refill handler yet (CPU type: %d)", |
| 381 | current_cpu_data.cputype); |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 386 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* |
| 388 | * TMP and PTR are scratch. |
| 389 | * TMP will be clobbered, PTR will hold the pmd entry. |
| 390 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 391 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 392 | 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] | 393 | unsigned int tmp, unsigned int ptr) |
| 394 | { |
| 395 | long pgdc = (long)pgd_current; |
| 396 | |
| 397 | /* |
| 398 | * The vmalloc handling is not in the hotpath. |
| 399 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 400 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 401 | #ifdef MODULE_START |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 402 | uasm_il_bltz(p, r, tmp, label_module_alloc); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 403 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 404 | uasm_il_bltz(p, r, tmp, label_vmalloc); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 405 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 406 | /* 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] | 407 | |
| 408 | #ifdef CONFIG_SMP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 409 | # ifdef CONFIG_MIPS_MT_SMTC |
| 410 | /* |
| 411 | * SMTC uses TCBind value as "CPU" index |
| 412 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 413 | uasm_i_mfc0(p, ptr, C0_TCBIND); |
| 414 | uasm_i_dsrl(p, ptr, ptr, 19); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 415 | # else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* |
Thiemo Seufer | 1b3a6e9 | 2005-04-01 14:07:13 +0000 | [diff] [blame] | 417 | * 64 bit SMP running in XKPHYS has smp_processor_id() << 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | * stored in CONTEXT. |
| 419 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 420 | uasm_i_dmfc0(p, ptr, C0_CONTEXT); |
| 421 | uasm_i_dsrl(p, ptr, ptr, 23); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 422 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 423 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 424 | uasm_i_daddu(p, ptr, ptr, tmp); |
| 425 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); |
| 426 | uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 428 | UASM_i_LA_mostly(p, ptr, pgdc); |
| 429 | uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | #endif |
| 431 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 432 | uasm_l_vmalloc_done(l, *p); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 433 | |
| 434 | if (PGDIR_SHIFT - 3 < 32) /* get pgd offset in bytes */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 435 | uasm_i_dsrl(p, tmp, tmp, PGDIR_SHIFT-3); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 436 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 437 | uasm_i_dsrl32(p, tmp, tmp, PGDIR_SHIFT - 3 - 32); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 438 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 439 | uasm_i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3); |
| 440 | uasm_i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */ |
| 441 | uasm_i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 442 | uasm_i_ld(p, ptr, 0, ptr); /* get pmd pointer */ |
| 443 | uasm_i_dsrl(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */ |
| 444 | uasm_i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3); |
| 445 | uasm_i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* |
| 449 | * BVADDR is the faulting address, PTR is scratch. |
| 450 | * PTR will hold the pgd for vmalloc. |
| 451 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 452 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 453 | build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | unsigned int bvaddr, unsigned int ptr) |
| 455 | { |
| 456 | long swpd = (long)swapper_pg_dir; |
| 457 | |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 458 | #ifdef MODULE_START |
| 459 | long modd = (long)module_pg_dir; |
| 460 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 461 | uasm_l_module_alloc(l, *p); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 462 | /* |
| 463 | * Assumption: |
| 464 | * VMALLOC_START >= 0xc000000000000000UL |
| 465 | * MODULE_START >= 0xe000000000000000UL |
| 466 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 467 | UASM_i_SLL(p, ptr, bvaddr, 2); |
| 468 | uasm_il_bgez(p, r, ptr, label_vmalloc); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 469 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 470 | if (uasm_in_compat_space_p(MODULE_START) && |
| 471 | !uasm_rel_lo(MODULE_START)) { |
| 472 | uasm_i_lui(p, ptr, uasm_rel_hi(MODULE_START)); /* delay slot */ |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 473 | } else { |
| 474 | /* unlikely configuration */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 475 | uasm_i_nop(p); /* delay slot */ |
| 476 | UASM_i_LA(p, ptr, MODULE_START); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 477 | } |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 478 | uasm_i_dsubu(p, bvaddr, bvaddr, ptr); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 479 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 480 | if (uasm_in_compat_space_p(modd) && !uasm_rel_lo(modd)) { |
| 481 | uasm_il_b(p, r, label_vmalloc_done); |
| 482 | uasm_i_lui(p, ptr, uasm_rel_hi(modd)); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 483 | } else { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 484 | UASM_i_LA_mostly(p, ptr, modd); |
| 485 | uasm_il_b(p, r, label_vmalloc_done); |
| 486 | if (uasm_in_compat_space_p(modd)) |
| 487 | uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(modd)); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 488 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 489 | uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(modd)); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 490 | } |
| 491 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 492 | uasm_l_vmalloc(l, *p); |
| 493 | if (uasm_in_compat_space_p(MODULE_START) && |
| 494 | !uasm_rel_lo(MODULE_START) && |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 495 | MODULE_START << 32 == VMALLOC_START) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 496 | uasm_i_dsll32(p, ptr, ptr, 0); /* typical case */ |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 497 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 498 | UASM_i_LA(p, ptr, VMALLOC_START); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 499 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 500 | uasm_l_vmalloc(l, *p); |
| 501 | UASM_i_LA(p, ptr, VMALLOC_START); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 502 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 503 | uasm_i_dsubu(p, bvaddr, bvaddr, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 505 | if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) { |
| 506 | uasm_il_b(p, r, label_vmalloc_done); |
| 507 | uasm_i_lui(p, ptr, uasm_rel_hi(swpd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } else { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 509 | UASM_i_LA_mostly(p, ptr, swpd); |
| 510 | uasm_il_b(p, r, label_vmalloc_done); |
| 511 | if (uasm_in_compat_space_p(swpd)) |
| 512 | uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd)); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 513 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 514 | uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 518 | #else /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * TMP and PTR are scratch. |
| 522 | * TMP will be clobbered, PTR will hold the pgd entry. |
| 523 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 524 | static void __cpuinit __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr) |
| 526 | { |
| 527 | long pgdc = (long)pgd_current; |
| 528 | |
| 529 | /* 32 bit SMP has smp_processor_id() stored in CONTEXT. */ |
| 530 | #ifdef CONFIG_SMP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 531 | #ifdef CONFIG_MIPS_MT_SMTC |
| 532 | /* |
| 533 | * SMTC uses TCBind value as "CPU" index |
| 534 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 535 | uasm_i_mfc0(p, ptr, C0_TCBIND); |
| 536 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 537 | uasm_i_srl(p, ptr, ptr, 19); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 538 | #else |
| 539 | /* |
| 540 | * smp_processor_id() << 3 is stored in CONTEXT. |
| 541 | */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 542 | uasm_i_mfc0(p, ptr, C0_CONTEXT); |
| 543 | UASM_i_LA_mostly(p, tmp, pgdc); |
| 544 | uasm_i_srl(p, ptr, ptr, 23); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 545 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 546 | uasm_i_addu(p, ptr, tmp, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 548 | UASM_i_LA_mostly(p, ptr, pgdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | #endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 550 | uasm_i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 551 | uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr); |
| 552 | uasm_i_srl(p, tmp, tmp, PGDIR_SHIFT); /* get pgd only bits */ |
| 553 | uasm_i_sll(p, tmp, tmp, PGD_T_LOG2); |
| 554 | uasm_i_addu(p, ptr, ptr, tmp); /* add in pgd offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 557 | #endif /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 559 | static void __cpuinit build_adjust_context(u32 **p, unsigned int ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 561 | unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1); |
| 563 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 564 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | case CPU_VR41XX: |
| 566 | case CPU_VR4111: |
| 567 | case CPU_VR4121: |
| 568 | case CPU_VR4122: |
| 569 | case CPU_VR4131: |
| 570 | case CPU_VR4181: |
| 571 | case CPU_VR4181A: |
| 572 | case CPU_VR4133: |
| 573 | shift += 2; |
| 574 | break; |
| 575 | |
| 576 | default: |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | if (shift) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 581 | UASM_i_SRL(p, ctx, ctx, shift); |
| 582 | uasm_i_andi(p, ctx, ctx, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 585 | 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] | 586 | { |
| 587 | /* |
| 588 | * Bug workaround for the Nevada. It seems as if under certain |
| 589 | * circumstances the move from cp0_context might produce a |
| 590 | * bogus result when the mfc0 instruction and its consumer are |
| 591 | * in a different cacheline or a load instruction, probably any |
| 592 | * memory reference, is between them. |
| 593 | */ |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 594 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | case CPU_NEVADA: |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 596 | UASM_i_LW(p, ptr, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | GET_CONTEXT(p, tmp); /* get context reg */ |
| 598 | break; |
| 599 | |
| 600 | default: |
| 601 | GET_CONTEXT(p, tmp); /* get context reg */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 602 | UASM_i_LW(p, ptr, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | break; |
| 604 | } |
| 605 | |
| 606 | build_adjust_context(p, tmp); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 607 | UASM_i_ADDU(p, ptr, ptr, tmp); /* add in offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 610 | static void __cpuinit build_update_entries(u32 **p, unsigned int tmp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | unsigned int ptep) |
| 612 | { |
| 613 | /* |
| 614 | * 64bit address support (36bit on a 32bit CPU) in a 32bit |
| 615 | * Kernel is a special case. Only a few CPUs use it. |
| 616 | */ |
| 617 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 618 | if (cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 619 | uasm_i_ld(p, tmp, 0, ptep); /* get even pte */ |
| 620 | uasm_i_ld(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
| 621 | uasm_i_dsrl(p, tmp, tmp, 6); /* convert to entrylo0 */ |
| 622 | uasm_i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 623 | uasm_i_dsrl(p, ptep, ptep, 6); /* convert to entrylo1 */ |
| 624 | uasm_i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } else { |
| 626 | int pte_off_even = sizeof(pte_t) / 2; |
| 627 | int pte_off_odd = pte_off_even + sizeof(pte_t); |
| 628 | |
| 629 | /* The pte entries are pre-shifted */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 630 | uasm_i_lw(p, tmp, pte_off_even, ptep); /* get even pte */ |
| 631 | uasm_i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 632 | uasm_i_lw(p, ptep, pte_off_odd, ptep); /* get odd pte */ |
| 633 | uasm_i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
| 635 | #else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 636 | UASM_i_LW(p, tmp, 0, ptep); /* get even pte */ |
| 637 | UASM_i_LW(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | if (r45k_bvahwbug()) |
| 639 | build_tlb_probe_entry(p); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 640 | UASM_i_SRL(p, tmp, tmp, 6); /* convert to entrylo0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | if (r4k_250MHZhwbug()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 642 | uasm_i_mtc0(p, 0, C0_ENTRYLO0); |
| 643 | uasm_i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 644 | UASM_i_SRL(p, ptep, ptep, 6); /* convert to entrylo1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | if (r45k_bvahwbug()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 646 | uasm_i_mfc0(p, tmp, C0_INDEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | if (r4k_250MHZhwbug()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 648 | uasm_i_mtc0(p, 0, C0_ENTRYLO1); |
| 649 | uasm_i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | #endif |
| 651 | } |
| 652 | |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 653 | /* |
| 654 | * For a 64-bit kernel, we are using the 64-bit XTLB refill exception |
| 655 | * because EXL == 0. If we wrap, we can also use the 32 instruction |
| 656 | * slots before the XTLB refill exception handler which belong to the |
| 657 | * unused TLB refill exception. |
| 658 | */ |
| 659 | #define MIPS64_REFILL_INSNS 32 |
| 660 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 661 | static void __cpuinit build_r4000_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
| 663 | u32 *p = tlb_handler; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 664 | struct uasm_label *l = labels; |
| 665 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | u32 *f; |
| 667 | unsigned int final_len; |
| 668 | |
| 669 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 670 | memset(labels, 0, sizeof(labels)); |
| 671 | memset(relocs, 0, sizeof(relocs)); |
| 672 | memset(final_handler, 0, sizeof(final_handler)); |
| 673 | |
| 674 | /* |
| 675 | * create the plain linear handler |
| 676 | */ |
| 677 | if (bcm1250_m3_war()) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 678 | UASM_i_MFC0(&p, K0, C0_BADVADDR); |
| 679 | UASM_i_MFC0(&p, K1, C0_ENTRYHI); |
| 680 | uasm_i_xor(&p, K0, K0, K1); |
| 681 | UASM_i_SRL(&p, K0, K0, PAGE_SHIFT + 1); |
| 682 | uasm_il_bnez(&p, &r, K0, label_leave); |
| 683 | /* No need for uasm_i_nop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 686 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | build_get_pmde64(&p, &l, &r, K0, K1); /* get pmd in K1 */ |
| 688 | #else |
| 689 | build_get_pgde32(&p, K0, K1); /* get pgd in K1 */ |
| 690 | #endif |
| 691 | |
| 692 | build_get_ptep(&p, K0, K1); |
| 693 | build_update_entries(&p, K0, K1); |
| 694 | build_tlb_write_entry(&p, &l, &r, tlb_random); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 695 | uasm_l_leave(&l, p); |
| 696 | uasm_i_eret(&p); /* return from trap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 698 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | build_get_pgd_vmalloc64(&p, &l, &r, K0, K1); |
| 700 | #endif |
| 701 | |
| 702 | /* |
| 703 | * Overflow check: For the 64bit handler, we need at least one |
| 704 | * free instruction slot for the wrap-around branch. In worst |
| 705 | * case, if the intended insertion point is a delay slot, we |
Matt LaPlante | 4b3f686 | 2006-10-03 22:21:02 +0200 | [diff] [blame] | 706 | * need three, with the second nop'ed and the third being |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | * unused. |
| 708 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 709 | /* Loongson2 ebase is different than r4k, we have more space */ |
| 710 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if ((p - tlb_handler) > 64) |
| 712 | panic("TLB refill handler space exceeded"); |
| 713 | #else |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 714 | if (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 1) |
| 715 | || (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 3) |
| 716 | && uasm_insn_has_bdelay(relocs, |
| 717 | tlb_handler + MIPS64_REFILL_INSNS - 3))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | panic("TLB refill handler space exceeded"); |
| 719 | #endif |
| 720 | |
| 721 | /* |
| 722 | * Now fold the handler in the TLB refill handler space. |
| 723 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 724 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | f = final_handler; |
| 726 | /* Simplest case, just copy the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 727 | uasm_copy_handler(relocs, labels, tlb_handler, p, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | final_len = p - tlb_handler; |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 729 | #else /* CONFIG_64BIT */ |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 730 | f = final_handler + MIPS64_REFILL_INSNS; |
| 731 | if ((p - tlb_handler) <= MIPS64_REFILL_INSNS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | /* Just copy the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 733 | uasm_copy_handler(relocs, labels, tlb_handler, p, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | final_len = p - tlb_handler; |
| 735 | } else { |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 736 | #ifdef MODULE_START |
| 737 | const enum label_id ls = label_module_alloc; |
| 738 | #else |
| 739 | const enum label_id ls = label_vmalloc; |
| 740 | #endif |
| 741 | u32 *split; |
| 742 | int ov = 0; |
| 743 | int i; |
| 744 | |
| 745 | for (i = 0; i < ARRAY_SIZE(labels) && labels[i].lab != ls; i++) |
| 746 | ; |
| 747 | BUG_ON(i == ARRAY_SIZE(labels)); |
| 748 | split = labels[i].addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | /* |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 751 | * See if we have overflown one way or the other. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | */ |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 753 | if (split > tlb_handler + MIPS64_REFILL_INSNS || |
| 754 | split < p - MIPS64_REFILL_INSNS) |
| 755 | ov = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 757 | if (ov) { |
| 758 | /* |
| 759 | * Split two instructions before the end. One |
| 760 | * for the branch and one for the instruction |
| 761 | * in the delay slot. |
| 762 | */ |
| 763 | split = tlb_handler + MIPS64_REFILL_INSNS - 2; |
| 764 | |
| 765 | /* |
| 766 | * If the branch would fall in a delay slot, |
| 767 | * we must back up an additional instruction |
| 768 | * so that it is no longer in a delay slot. |
| 769 | */ |
| 770 | if (uasm_insn_has_bdelay(relocs, split - 1)) |
| 771 | split--; |
| 772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* Copy first part of the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 774 | uasm_copy_handler(relocs, labels, tlb_handler, split, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | f += split - tlb_handler; |
| 776 | |
David Daney | 95affdd | 2009-05-20 11:40:59 -0700 | [diff] [blame^] | 777 | if (ov) { |
| 778 | /* Insert branch. */ |
| 779 | uasm_l_split(&l, final_handler); |
| 780 | uasm_il_b(&f, &r, label_split); |
| 781 | if (uasm_insn_has_bdelay(relocs, split)) |
| 782 | uasm_i_nop(&f); |
| 783 | else { |
| 784 | uasm_copy_handler(relocs, labels, |
| 785 | split, split + 1, f); |
| 786 | uasm_move_labels(labels, f, f + 1, -1); |
| 787 | f++; |
| 788 | split++; |
| 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | /* Copy the rest of the handler. */ |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 793 | uasm_copy_handler(relocs, labels, split, p, final_handler); |
David Daney | e6f72d3 | 2009-05-20 11:40:58 -0700 | [diff] [blame] | 794 | final_len = (f - (final_handler + MIPS64_REFILL_INSNS)) + |
| 795 | (p - split); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 797 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 799 | uasm_resolve_relocs(relocs, labels); |
| 800 | pr_debug("Wrote TLB refill handler (%u instructions).\n", |
| 801 | final_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 803 | memcpy((void *)ebase, final_handler, 0x100); |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 804 | |
| 805 | dump_handler((u32 *)ebase, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* |
| 809 | * TLB load/store/modify handlers. |
| 810 | * |
| 811 | * Only the fastpath gets synthesized at runtime, the slowpath for |
| 812 | * do_page_fault remains normal asm. |
| 813 | */ |
| 814 | extern void tlb_do_page_fault_0(void); |
| 815 | extern void tlb_do_page_fault_1(void); |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | /* |
| 818 | * 128 instructions for the fastpath handler is generous and should |
| 819 | * never be exceeded. |
| 820 | */ |
| 821 | #define FASTPATH_SIZE 128 |
| 822 | |
Franck Bui-Huu | cbdbe07 | 2007-10-18 09:11:16 +0200 | [diff] [blame] | 823 | u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned; |
| 824 | u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned; |
| 825 | u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 827 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 828 | iPTE_LW(u32 **p, struct uasm_label **l, unsigned int pte, unsigned int ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
| 830 | #ifdef CONFIG_SMP |
| 831 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 832 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 833 | uasm_i_lld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | else |
| 835 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 836 | UASM_i_LL(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | #else |
| 838 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 839 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 840 | uasm_i_ld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | else |
| 842 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 843 | UASM_i_LW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | #endif |
| 845 | } |
| 846 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 847 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 848 | 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] | 849 | unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 851 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 852 | unsigned int hwmode = mode & (_PAGE_VALID | _PAGE_DIRTY); |
| 853 | #endif |
| 854 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 855 | uasm_i_ori(p, pte, pte, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | #ifdef CONFIG_SMP |
| 857 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 858 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 859 | uasm_i_scd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | else |
| 861 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 862 | UASM_i_SC(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | if (r10000_llsc_war()) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 865 | uasm_il_beqzl(p, r, pte, label_smp_pgtable_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 867 | uasm_il_beqz(p, r, pte, label_smp_pgtable_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 870 | if (!cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 871 | /* no uasm_i_nop needed */ |
| 872 | uasm_i_ll(p, pte, sizeof(pte_t) / 2, ptr); |
| 873 | uasm_i_ori(p, pte, pte, hwmode); |
| 874 | uasm_i_sc(p, pte, sizeof(pte_t) / 2, ptr); |
| 875 | uasm_il_beqz(p, r, pte, label_smp_pgtable_change); |
| 876 | /* no uasm_i_nop needed */ |
| 877 | uasm_i_lw(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 879 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | # else |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 881 | uasm_i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | # endif |
| 883 | #else |
| 884 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 885 | if (cpu_has_64bits) |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 886 | uasm_i_sd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | else |
| 888 | # endif |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 889 | UASM_i_SW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 892 | if (!cpu_has_64bits) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 893 | uasm_i_lw(p, pte, sizeof(pte_t) / 2, ptr); |
| 894 | uasm_i_ori(p, pte, pte, hwmode); |
| 895 | uasm_i_sw(p, pte, sizeof(pte_t) / 2, ptr); |
| 896 | uasm_i_lw(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | # endif |
| 899 | #endif |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | * Check if PTE is present, if not then jump to LABEL. PTR points to |
| 904 | * the page table where this PTE is located, PTE will be re-loaded |
| 905 | * with it's original value. |
| 906 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 907 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 908 | build_pte_present(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 910 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 911 | uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 912 | uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 913 | uasm_il_bnez(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 914 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* Make PTE valid, store result in PTR. */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 918 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 919 | build_make_valid(u32 **p, struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | unsigned int ptr) |
| 921 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 922 | unsigned int mode = _PAGE_VALID | _PAGE_ACCESSED; |
| 923 | |
| 924 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /* |
| 928 | * Check if PTE can be written to, if not branch to LABEL. Regardless |
| 929 | * restore PTE with value from PTR when done. |
| 930 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 931 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 932 | build_pte_writable(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 934 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 935 | uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 936 | uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 937 | uasm_il_bnez(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 938 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* Make PTE writable, update software status bits as well, then store |
| 942 | * at PTR. |
| 943 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 944 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 945 | build_make_write(u32 **p, struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | unsigned int ptr) |
| 947 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 948 | unsigned int mode = (_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID |
| 949 | | _PAGE_DIRTY); |
| 950 | |
| 951 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /* |
| 955 | * Check if PTE can be modified, if not branch to LABEL. Regardless |
| 956 | * restore PTE with value from PTR when done. |
| 957 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 958 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 959 | build_pte_modifiable(u32 **p, struct uasm_label **l, struct uasm_reloc **r, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 961 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 962 | uasm_i_andi(p, pte, pte, _PAGE_WRITE); |
| 963 | uasm_il_beqz(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 964 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /* |
| 968 | * R3000 style TLB load/store/modify handlers. |
| 969 | */ |
| 970 | |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 971 | /* |
| 972 | * This places the pte into ENTRYLO0 and writes it with tlbwi. |
| 973 | * Then it returns. |
| 974 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 975 | static void __cpuinit |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 976 | 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] | 977 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 978 | uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 979 | uasm_i_mfc0(p, tmp, C0_EPC); /* cp0 delay */ |
| 980 | uasm_i_tlbwi(p); |
| 981 | uasm_i_jr(p, tmp); |
| 982 | uasm_i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /* |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 986 | * This places the pte into ENTRYLO0 and writes it with tlbwi |
| 987 | * or tlbwr as appropriate. This is because the index register |
| 988 | * may have the probe fail bit set as a result of a trap on a |
| 989 | * kseg2 access, i.e. without refill. Then it returns. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 991 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 992 | build_r3000_tlb_reload_write(u32 **p, struct uasm_label **l, |
| 993 | struct uasm_reloc **r, unsigned int pte, |
| 994 | unsigned int tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 996 | uasm_i_mfc0(p, tmp, C0_INDEX); |
| 997 | uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 998 | uasm_il_bltz(p, r, tmp, label_r3000_write_probe_fail); /* cp0 delay */ |
| 999 | uasm_i_mfc0(p, tmp, C0_EPC); /* branch delay */ |
| 1000 | uasm_i_tlbwi(p); /* cp0 delay */ |
| 1001 | uasm_i_jr(p, tmp); |
| 1002 | uasm_i_rfe(p); /* branch delay */ |
| 1003 | uasm_l_r3000_write_probe_fail(l, *p); |
| 1004 | uasm_i_tlbwr(p); /* cp0 delay */ |
| 1005 | uasm_i_jr(p, tmp); |
| 1006 | uasm_i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1009 | static void __cpuinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | build_r3000_tlbchange_handler_head(u32 **p, unsigned int pte, |
| 1011 | unsigned int ptr) |
| 1012 | { |
| 1013 | long pgdc = (long)pgd_current; |
| 1014 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1015 | uasm_i_mfc0(p, pte, C0_BADVADDR); |
| 1016 | uasm_i_lui(p, ptr, uasm_rel_hi(pgdc)); /* cp0 delay */ |
| 1017 | uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr); |
| 1018 | uasm_i_srl(p, pte, pte, 22); /* load delay */ |
| 1019 | uasm_i_sll(p, pte, pte, 2); |
| 1020 | uasm_i_addu(p, ptr, ptr, pte); |
| 1021 | uasm_i_mfc0(p, pte, C0_CONTEXT); |
| 1022 | uasm_i_lw(p, ptr, 0, ptr); /* cp0 delay */ |
| 1023 | uasm_i_andi(p, pte, pte, 0xffc); /* load delay */ |
| 1024 | uasm_i_addu(p, ptr, ptr, pte); |
| 1025 | uasm_i_lw(p, pte, 0, ptr); |
| 1026 | uasm_i_tlbp(p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1029 | static void __cpuinit build_r3000_tlb_load_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
| 1031 | u32 *p = handle_tlbl; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1032 | struct uasm_label *l = labels; |
| 1033 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
| 1035 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1036 | memset(labels, 0, sizeof(labels)); |
| 1037 | memset(relocs, 0, sizeof(relocs)); |
| 1038 | |
| 1039 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1040 | build_pte_present(&p, &l, &r, K0, K1, label_nopage_tlbl); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1041 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | build_make_valid(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1043 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1045 | uasm_l_nopage_tlbl(&l, p); |
| 1046 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1047 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1050 | panic("TLB load handler fastpath space exceeded"); |
| 1051 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1052 | uasm_resolve_relocs(relocs, labels); |
| 1053 | pr_debug("Wrote TLB load handler fastpath (%u instructions).\n", |
| 1054 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1056 | dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1059 | static void __cpuinit build_r3000_tlb_store_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { |
| 1061 | u32 *p = handle_tlbs; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1062 | struct uasm_label *l = labels; |
| 1063 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1066 | memset(labels, 0, sizeof(labels)); |
| 1067 | memset(relocs, 0, sizeof(relocs)); |
| 1068 | |
| 1069 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1070 | build_pte_writable(&p, &l, &r, K0, K1, label_nopage_tlbs); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1071 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1073 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1075 | uasm_l_nopage_tlbs(&l, p); |
| 1076 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1077 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1080 | panic("TLB store handler fastpath space exceeded"); |
| 1081 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1082 | uasm_resolve_relocs(relocs, labels); |
| 1083 | pr_debug("Wrote TLB store handler fastpath (%u instructions).\n", |
| 1084 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1086 | dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1089 | static void __cpuinit build_r3000_tlb_modify_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
| 1091 | u32 *p = handle_tlbm; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1092 | struct uasm_label *l = labels; |
| 1093 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1096 | memset(labels, 0, sizeof(labels)); |
| 1097 | memset(relocs, 0, sizeof(relocs)); |
| 1098 | |
| 1099 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1100 | build_pte_modifiable(&p, &l, &r, K0, K1, label_nopage_tlbm); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1101 | uasm_i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1103 | build_r3000_pte_reload_tlbwi(&p, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1105 | uasm_l_nopage_tlbm(&l, p); |
| 1106 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1107 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1110 | panic("TLB modify handler fastpath space exceeded"); |
| 1111 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1112 | uasm_resolve_relocs(relocs, labels); |
| 1113 | pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n", |
| 1114 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1116 | dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | /* |
| 1120 | * R4000 style TLB load/store/modify handlers. |
| 1121 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1122 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1123 | build_r4000_tlbchange_handler_head(u32 **p, struct uasm_label **l, |
| 1124 | struct uasm_reloc **r, unsigned int pte, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | unsigned int ptr) |
| 1126 | { |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1127 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | build_get_pmde64(p, l, r, pte, ptr); /* get pmd in ptr */ |
| 1129 | #else |
| 1130 | build_get_pgde32(p, pte, ptr); /* get pgd in ptr */ |
| 1131 | #endif |
| 1132 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1133 | UASM_i_MFC0(p, pte, C0_BADVADDR); |
| 1134 | UASM_i_LW(p, ptr, 0, ptr); |
| 1135 | UASM_i_SRL(p, pte, pte, PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2); |
| 1136 | uasm_i_andi(p, pte, pte, (PTRS_PER_PTE - 1) << PTE_T_LOG2); |
| 1137 | UASM_i_ADDU(p, ptr, ptr, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
| 1139 | #ifdef CONFIG_SMP |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1140 | uasm_l_smp_pgtable_change(l, *p); |
| 1141 | #endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1142 | iPTE_LW(p, l, pte, ptr); /* get even pte */ |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1143 | if (!m4kc_tlbp_war()) |
| 1144 | build_tlb_probe_entry(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1147 | static void __cpuinit |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1148 | build_r4000_tlbchange_handler_tail(u32 **p, struct uasm_label **l, |
| 1149 | struct uasm_reloc **r, unsigned int tmp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | unsigned int ptr) |
| 1151 | { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1152 | uasm_i_ori(p, ptr, ptr, sizeof(pte_t)); |
| 1153 | uasm_i_xori(p, ptr, ptr, sizeof(pte_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | build_update_entries(p, tmp, ptr); |
| 1155 | build_tlb_write_entry(p, l, r, tlb_indexed); |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1156 | uasm_l_leave(l, *p); |
| 1157 | uasm_i_eret(p); /* return from trap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1159 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | build_get_pgd_vmalloc64(p, l, r, tmp, ptr); |
| 1161 | #endif |
| 1162 | } |
| 1163 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1164 | static void __cpuinit build_r4000_tlb_load_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
| 1166 | u32 *p = handle_tlbl; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1167 | struct uasm_label *l = labels; |
| 1168 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
| 1170 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1171 | memset(labels, 0, sizeof(labels)); |
| 1172 | memset(relocs, 0, sizeof(relocs)); |
| 1173 | |
| 1174 | if (bcm1250_m3_war()) { |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1175 | UASM_i_MFC0(&p, K0, C0_BADVADDR); |
| 1176 | UASM_i_MFC0(&p, K1, C0_ENTRYHI); |
| 1177 | uasm_i_xor(&p, K0, K0, K1); |
| 1178 | UASM_i_SRL(&p, K0, K0, PAGE_SHIFT + 1); |
| 1179 | uasm_il_bnez(&p, &r, K0, label_leave); |
| 1180 | /* No need for uasm_i_nop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1184 | build_pte_present(&p, &l, &r, K0, K1, label_nopage_tlbl); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1185 | if (m4kc_tlbp_war()) |
| 1186 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | build_make_valid(&p, &r, K0, K1); |
| 1188 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1189 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1190 | uasm_l_nopage_tlbl(&l, p); |
| 1191 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1192 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1195 | panic("TLB load handler fastpath space exceeded"); |
| 1196 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1197 | uasm_resolve_relocs(relocs, labels); |
| 1198 | pr_debug("Wrote TLB load handler fastpath (%u instructions).\n", |
| 1199 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1201 | dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1204 | static void __cpuinit build_r4000_tlb_store_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | { |
| 1206 | u32 *p = handle_tlbs; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1207 | struct uasm_label *l = labels; |
| 1208 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
| 1210 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1211 | memset(labels, 0, sizeof(labels)); |
| 1212 | memset(relocs, 0, sizeof(relocs)); |
| 1213 | |
| 1214 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1215 | build_pte_writable(&p, &l, &r, K0, K1, label_nopage_tlbs); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1216 | if (m4kc_tlbp_war()) |
| 1217 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | build_make_write(&p, &r, K0, K1); |
| 1219 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1220 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1221 | uasm_l_nopage_tlbs(&l, p); |
| 1222 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1223 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1226 | panic("TLB store handler fastpath space exceeded"); |
| 1227 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1228 | uasm_resolve_relocs(relocs, labels); |
| 1229 | pr_debug("Wrote TLB store handler fastpath (%u instructions).\n", |
| 1230 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1232 | dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1235 | static void __cpuinit build_r4000_tlb_modify_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | { |
| 1237 | u32 *p = handle_tlbm; |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1238 | struct uasm_label *l = labels; |
| 1239 | struct uasm_reloc *r = relocs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
| 1241 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1242 | memset(labels, 0, sizeof(labels)); |
| 1243 | memset(relocs, 0, sizeof(relocs)); |
| 1244 | |
| 1245 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1246 | build_pte_modifiable(&p, &l, &r, K0, K1, label_nopage_tlbm); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1247 | if (m4kc_tlbp_war()) |
| 1248 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | /* Present and writable bits set, set accessed and dirty bits. */ |
| 1250 | build_make_write(&p, &r, K0, K1); |
| 1251 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1252 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1253 | uasm_l_nopage_tlbm(&l, p); |
| 1254 | uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1255 | uasm_i_nop(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
| 1257 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1258 | panic("TLB modify handler fastpath space exceeded"); |
| 1259 | |
Thiemo Seufer | e30ec45 | 2008-01-28 20:05:38 +0000 | [diff] [blame] | 1260 | uasm_resolve_relocs(relocs, labels); |
| 1261 | pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n", |
| 1262 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Franck Bui-Huu | 92b1e6a | 2007-10-18 09:11:17 +0200 | [diff] [blame] | 1264 | dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1267 | void __cpuinit build_tlb_refill_handler(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | { |
| 1269 | /* |
| 1270 | * The refill handler is generated per-CPU, multi-node systems |
| 1271 | * may have local storage for it. The other handlers are only |
| 1272 | * needed once. |
| 1273 | */ |
| 1274 | static int run_once = 0; |
| 1275 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1276 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | case CPU_R2000: |
| 1278 | case CPU_R3000: |
| 1279 | case CPU_R3000A: |
| 1280 | case CPU_R3081E: |
| 1281 | case CPU_TX3912: |
| 1282 | case CPU_TX3922: |
| 1283 | case CPU_TX3927: |
| 1284 | build_r3000_tlb_refill_handler(); |
| 1285 | if (!run_once) { |
| 1286 | build_r3000_tlb_load_handler(); |
| 1287 | build_r3000_tlb_store_handler(); |
| 1288 | build_r3000_tlb_modify_handler(); |
| 1289 | run_once++; |
| 1290 | } |
| 1291 | break; |
| 1292 | |
| 1293 | case CPU_R6000: |
| 1294 | case CPU_R6000A: |
| 1295 | panic("No R6000 TLB refill handler yet"); |
| 1296 | break; |
| 1297 | |
| 1298 | case CPU_R8000: |
| 1299 | panic("No R8000 TLB refill handler yet"); |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
| 1303 | build_r4000_tlb_refill_handler(); |
| 1304 | if (!run_once) { |
| 1305 | build_r4000_tlb_load_handler(); |
| 1306 | build_r4000_tlb_store_handler(); |
| 1307 | build_r4000_tlb_modify_handler(); |
| 1308 | run_once++; |
| 1309 | } |
| 1310 | } |
| 1311 | } |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1312 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1313 | void __cpuinit flush_tlb_handlers(void) |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1314 | { |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1315 | local_flush_icache_range((unsigned long)handle_tlbl, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1316 | (unsigned long)handle_tlbl + sizeof(handle_tlbl)); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1317 | local_flush_icache_range((unsigned long)handle_tlbs, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1318 | (unsigned long)handle_tlbs + sizeof(handle_tlbs)); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1319 | local_flush_icache_range((unsigned long)handle_tlbm, |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1320 | (unsigned long)handle_tlbm + sizeof(handle_tlbm)); |
| 1321 | } |