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 | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 8 | * Copyright (C) 2004,2005,2006 by Thiemo Seufer |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 9 | * Copyright (C) 2005, 2007 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 | |
| 22 | #include <stdarg.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/mm.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/string.h> |
| 28 | #include <linux/init.h> |
| 29 | |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 30 | #include <asm/bugs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/cacheflush.h> |
| 33 | #include <asm/mmu_context.h> |
| 34 | #include <asm/inst.h> |
| 35 | #include <asm/elf.h> |
| 36 | #include <asm/smp.h> |
| 37 | #include <asm/war.h> |
| 38 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 39 | static inline int r45k_bvahwbug(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 r4k_250MHZhwbug(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | /* XXX: We should probe for the presence of this bug, but we don't. */ |
| 48 | return 0; |
| 49 | } |
| 50 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 51 | static inline int __maybe_unused bcm1250_m3_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | return BCM1250_M3_WAR; |
| 54 | } |
| 55 | |
Ralf Baechle | aeffdbb | 2007-10-11 23:46:14 +0100 | [diff] [blame] | 56 | static inline int __maybe_unused r10000_llsc_war(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | return R10000_LLSC_WAR; |
| 59 | } |
| 60 | |
| 61 | /* |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 62 | * Found by experiment: At least some revisions of the 4kc throw under |
| 63 | * some circumstances a machine check exception, triggered by invalid |
| 64 | * values in the index register. Delaying the tlbp instruction until |
| 65 | * after the next branch, plus adding an additional nop in front of |
| 66 | * tlbwi/tlbwr avoids the invalid index register values. Nobody knows |
| 67 | * why; it's not an issue caused by the core RTL. |
| 68 | * |
| 69 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 70 | static __init int __attribute__((unused)) m4kc_tlbp_war(void) |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 71 | { |
| 72 | return (current_cpu_data.processor_id & 0xffff00) == |
| 73 | (PRID_COMP_MIPS | PRID_IMP_4KC); |
| 74 | } |
| 75 | |
| 76 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * A little micro-assembler, intended for TLB refill handler |
| 78 | * synthesizing. It is intentionally kept simple, does only support |
| 79 | * a subset of instructions, and does not try to hide pipeline effects |
| 80 | * like branch delay slots. |
| 81 | */ |
| 82 | |
| 83 | enum fields |
| 84 | { |
| 85 | RS = 0x001, |
| 86 | RT = 0x002, |
| 87 | RD = 0x004, |
| 88 | RE = 0x008, |
| 89 | SIMM = 0x010, |
| 90 | UIMM = 0x020, |
| 91 | BIMM = 0x040, |
| 92 | JIMM = 0x080, |
| 93 | FUNC = 0x100, |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 94 | SET = 0x200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Thiemo Seufer | 603c338 | 2007-09-05 12:11:22 +0100 | [diff] [blame] | 97 | #define OP_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #define OP_SH 26 |
| 99 | #define RS_MASK 0x1f |
| 100 | #define RS_SH 21 |
| 101 | #define RT_MASK 0x1f |
| 102 | #define RT_SH 16 |
| 103 | #define RD_MASK 0x1f |
| 104 | #define RD_SH 11 |
| 105 | #define RE_MASK 0x1f |
| 106 | #define RE_SH 6 |
| 107 | #define IMM_MASK 0xffff |
| 108 | #define IMM_SH 0 |
| 109 | #define JIMM_MASK 0x3ffffff |
| 110 | #define JIMM_SH 0 |
Thiemo Seufer | 603c338 | 2007-09-05 12:11:22 +0100 | [diff] [blame] | 111 | #define FUNC_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define FUNC_SH 0 |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 113 | #define SET_MASK 0x7 |
| 114 | #define SET_SH 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | enum opcode { |
| 117 | insn_invalid, |
| 118 | insn_addu, insn_addiu, insn_and, insn_andi, insn_beq, |
| 119 | insn_beql, insn_bgez, insn_bgezl, insn_bltz, insn_bltzl, |
| 120 | insn_bne, insn_daddu, insn_daddiu, insn_dmfc0, insn_dmtc0, |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 121 | insn_dsll, insn_dsll32, insn_dsra, insn_dsrl, insn_dsrl32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | insn_dsubu, insn_eret, insn_j, insn_jal, insn_jr, insn_ld, |
| 123 | insn_ll, insn_lld, insn_lui, insn_lw, insn_mfc0, insn_mtc0, |
| 124 | insn_ori, insn_rfe, insn_sc, insn_scd, insn_sd, insn_sll, |
| 125 | insn_sra, insn_srl, insn_subu, insn_sw, insn_tlbp, insn_tlbwi, |
| 126 | insn_tlbwr, insn_xor, insn_xori |
| 127 | }; |
| 128 | |
| 129 | struct insn { |
| 130 | enum opcode opcode; |
| 131 | u32 match; |
| 132 | enum fields fields; |
| 133 | }; |
| 134 | |
| 135 | /* This macro sets the non-variable bits of an instruction. */ |
| 136 | #define M(a, b, c, d, e, f) \ |
| 137 | ((a) << OP_SH \ |
| 138 | | (b) << RS_SH \ |
| 139 | | (c) << RT_SH \ |
| 140 | | (d) << RD_SH \ |
| 141 | | (e) << RE_SH \ |
| 142 | | (f) << FUNC_SH) |
| 143 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 144 | static __initdata struct insn insn_table[] = { |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 145 | { insn_addiu, M(addiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 146 | { insn_addu, M(spec_op, 0, 0, 0, 0, addu_op), RS | RT | RD }, |
| 147 | { insn_and, M(spec_op, 0, 0, 0, 0, and_op), RS | RT | RD }, |
| 148 | { insn_andi, M(andi_op, 0, 0, 0, 0, 0), RS | RT | UIMM }, |
| 149 | { insn_beq, M(beq_op, 0, 0, 0, 0, 0), RS | RT | BIMM }, |
| 150 | { insn_beql, M(beql_op, 0, 0, 0, 0, 0), RS | RT | BIMM }, |
| 151 | { insn_bgez, M(bcond_op, 0, bgez_op, 0, 0, 0), RS | BIMM }, |
| 152 | { insn_bgezl, M(bcond_op, 0, bgezl_op, 0, 0, 0), RS | BIMM }, |
| 153 | { insn_bltz, M(bcond_op, 0, bltz_op, 0, 0, 0), RS | BIMM }, |
| 154 | { insn_bltzl, M(bcond_op, 0, bltzl_op, 0, 0, 0), RS | BIMM }, |
| 155 | { insn_bne, M(bne_op, 0, 0, 0, 0, 0), RS | RT | BIMM }, |
| 156 | { insn_daddiu, M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 157 | { insn_daddu, M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD }, |
| 158 | { insn_dmfc0, M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET}, |
| 159 | { insn_dmtc0, M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET}, |
| 160 | { insn_dsll, M(spec_op, 0, 0, 0, 0, dsll_op), RT | RD | RE }, |
| 161 | { insn_dsll32, M(spec_op, 0, 0, 0, 0, dsll32_op), RT | RD | RE }, |
| 162 | { insn_dsra, M(spec_op, 0, 0, 0, 0, dsra_op), RT | RD | RE }, |
| 163 | { insn_dsrl, M(spec_op, 0, 0, 0, 0, dsrl_op), RT | RD | RE }, |
| 164 | { insn_dsrl32, M(spec_op, 0, 0, 0, 0, dsrl32_op), RT | RD | RE }, |
| 165 | { insn_dsubu, M(spec_op, 0, 0, 0, 0, dsubu_op), RS | RT | RD }, |
| 166 | { insn_eret, M(cop0_op, cop_op, 0, 0, 0, eret_op), 0 }, |
| 167 | { insn_j, M(j_op, 0, 0, 0, 0, 0), JIMM }, |
| 168 | { insn_jal, M(jal_op, 0, 0, 0, 0, 0), JIMM }, |
| 169 | { insn_jr, M(spec_op, 0, 0, 0, 0, jr_op), RS }, |
| 170 | { insn_ld, M(ld_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 171 | { insn_ll, M(ll_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 172 | { insn_lld, M(lld_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 173 | { insn_lui, M(lui_op, 0, 0, 0, 0, 0), RT | SIMM }, |
| 174 | { insn_lw, M(lw_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 175 | { insn_mfc0, M(cop0_op, mfc_op, 0, 0, 0, 0), RT | RD | SET}, |
| 176 | { insn_mtc0, M(cop0_op, mtc_op, 0, 0, 0, 0), RT | RD | SET}, |
| 177 | { insn_ori, M(ori_op, 0, 0, 0, 0, 0), RS | RT | UIMM }, |
| 178 | { insn_rfe, M(cop0_op, cop_op, 0, 0, 0, rfe_op), 0 }, |
| 179 | { insn_sc, M(sc_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 180 | { insn_scd, M(scd_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 181 | { insn_sd, M(sd_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 182 | { insn_sll, M(spec_op, 0, 0, 0, 0, sll_op), RT | RD | RE }, |
| 183 | { insn_sra, M(spec_op, 0, 0, 0, 0, sra_op), RT | RD | RE }, |
| 184 | { insn_srl, M(spec_op, 0, 0, 0, 0, srl_op), RT | RD | RE }, |
| 185 | { insn_subu, M(spec_op, 0, 0, 0, 0, subu_op), RS | RT | RD }, |
| 186 | { insn_sw, M(sw_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, |
| 187 | { insn_tlbp, M(cop0_op, cop_op, 0, 0, 0, tlbp_op), 0 }, |
| 188 | { insn_tlbwi, M(cop0_op, cop_op, 0, 0, 0, tlbwi_op), 0 }, |
| 189 | { insn_tlbwr, M(cop0_op, cop_op, 0, 0, 0, tlbwr_op), 0 }, |
| 190 | { insn_xor, M(spec_op, 0, 0, 0, 0, xor_op), RS | RT | RD }, |
| 191 | { insn_xori, M(xori_op, 0, 0, 0, 0, 0), RS | RT | UIMM }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { insn_invalid, 0, 0 } |
| 193 | }; |
| 194 | |
| 195 | #undef M |
| 196 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 197 | static __init u32 build_rs(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | if (arg & ~RS_MASK) |
| 200 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 201 | |
| 202 | return (arg & RS_MASK) << RS_SH; |
| 203 | } |
| 204 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 205 | static __init u32 build_rt(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { |
| 207 | if (arg & ~RT_MASK) |
| 208 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 209 | |
| 210 | return (arg & RT_MASK) << RT_SH; |
| 211 | } |
| 212 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 213 | static __init u32 build_rd(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | if (arg & ~RD_MASK) |
| 216 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 217 | |
| 218 | return (arg & RD_MASK) << RD_SH; |
| 219 | } |
| 220 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 221 | static __init u32 build_re(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | if (arg & ~RE_MASK) |
| 224 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 225 | |
| 226 | return (arg & RE_MASK) << RE_SH; |
| 227 | } |
| 228 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 229 | static __init u32 build_simm(s32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | if (arg > 0x7fff || arg < -0x8000) |
| 232 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 233 | |
| 234 | return arg & 0xffff; |
| 235 | } |
| 236 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 237 | static __init u32 build_uimm(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | if (arg & ~IMM_MASK) |
| 240 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 241 | |
| 242 | return arg & IMM_MASK; |
| 243 | } |
| 244 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 245 | static __init u32 build_bimm(s32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | if (arg > 0x1ffff || arg < -0x20000) |
| 248 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 249 | |
| 250 | if (arg & 0x3) |
| 251 | printk(KERN_WARNING "Invalid TLB synthesizer branch target\n"); |
| 252 | |
| 253 | return ((arg < 0) ? (1 << 15) : 0) | ((arg >> 2) & 0x7fff); |
| 254 | } |
| 255 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 256 | static __init u32 build_jimm(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | if (arg & ~((JIMM_MASK) << 2)) |
| 259 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 260 | |
| 261 | return (arg >> 2) & JIMM_MASK; |
| 262 | } |
| 263 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 264 | static __init u32 build_func(u32 arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | if (arg & ~FUNC_MASK) |
| 267 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 268 | |
| 269 | return arg & FUNC_MASK; |
| 270 | } |
| 271 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 272 | static __init u32 build_set(u32 arg) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 273 | { |
| 274 | if (arg & ~SET_MASK) |
| 275 | printk(KERN_WARNING "TLB synthesizer field overflow\n"); |
| 276 | |
| 277 | return arg & SET_MASK; |
| 278 | } |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* |
| 281 | * The order of opcode arguments is implicitly left to right, |
| 282 | * starting with RS and ending with FUNC or IMM. |
| 283 | */ |
| 284 | static void __init build_insn(u32 **buf, enum opcode opc, ...) |
| 285 | { |
| 286 | struct insn *ip = NULL; |
| 287 | unsigned int i; |
| 288 | va_list ap; |
| 289 | u32 op; |
| 290 | |
| 291 | for (i = 0; insn_table[i].opcode != insn_invalid; i++) |
| 292 | if (insn_table[i].opcode == opc) { |
| 293 | ip = &insn_table[i]; |
| 294 | break; |
| 295 | } |
| 296 | |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 297 | if (!ip || (opc == insn_daddiu && r4k_daddiu_bug())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | panic("Unsupported TLB synthesizer instruction %d", opc); |
| 299 | |
| 300 | op = ip->match; |
| 301 | va_start(ap, opc); |
| 302 | if (ip->fields & RS) op |= build_rs(va_arg(ap, u32)); |
| 303 | if (ip->fields & RT) op |= build_rt(va_arg(ap, u32)); |
| 304 | if (ip->fields & RD) op |= build_rd(va_arg(ap, u32)); |
| 305 | if (ip->fields & RE) op |= build_re(va_arg(ap, u32)); |
| 306 | if (ip->fields & SIMM) op |= build_simm(va_arg(ap, s32)); |
| 307 | if (ip->fields & UIMM) op |= build_uimm(va_arg(ap, u32)); |
| 308 | if (ip->fields & BIMM) op |= build_bimm(va_arg(ap, s32)); |
| 309 | if (ip->fields & JIMM) op |= build_jimm(va_arg(ap, u32)); |
| 310 | if (ip->fields & FUNC) op |= build_func(va_arg(ap, u32)); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 311 | if (ip->fields & SET) op |= build_set(va_arg(ap, u32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | va_end(ap); |
| 313 | |
| 314 | **buf = op; |
| 315 | (*buf)++; |
| 316 | } |
| 317 | |
| 318 | #define I_u1u2u3(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 319 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | unsigned int b, unsigned int c) \ |
| 321 | { \ |
| 322 | build_insn(buf, insn##op, a, b, c); \ |
| 323 | } |
| 324 | |
| 325 | #define I_u2u1u3(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 326 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | unsigned int b, unsigned int c) \ |
| 328 | { \ |
| 329 | build_insn(buf, insn##op, b, a, c); \ |
| 330 | } |
| 331 | |
| 332 | #define I_u3u1u2(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 333 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | unsigned int b, unsigned int c) \ |
| 335 | { \ |
| 336 | build_insn(buf, insn##op, b, c, a); \ |
| 337 | } |
| 338 | |
| 339 | #define I_u1u2s3(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 340 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | unsigned int b, signed int c) \ |
| 342 | { \ |
| 343 | build_insn(buf, insn##op, a, b, c); \ |
| 344 | } |
| 345 | |
| 346 | #define I_u2s3u1(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 347 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | signed int b, unsigned int c) \ |
| 349 | { \ |
| 350 | build_insn(buf, insn##op, c, a, b); \ |
| 351 | } |
| 352 | |
| 353 | #define I_u2u1s3(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 354 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | unsigned int b, signed int c) \ |
| 356 | { \ |
| 357 | build_insn(buf, insn##op, b, a, c); \ |
| 358 | } |
| 359 | |
| 360 | #define I_u1u2(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 361 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | unsigned int b) \ |
| 363 | { \ |
| 364 | build_insn(buf, insn##op, a, b); \ |
| 365 | } |
| 366 | |
| 367 | #define I_u1s2(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 368 | static inline void __init i##op(u32 **buf, unsigned int a, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | signed int b) \ |
| 370 | { \ |
| 371 | build_insn(buf, insn##op, a, b); \ |
| 372 | } |
| 373 | |
| 374 | #define I_u1(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 375 | static inline void __init i##op(u32 **buf, unsigned int a) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { \ |
| 377 | build_insn(buf, insn##op, a); \ |
| 378 | } |
| 379 | |
| 380 | #define I_0(op) \ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 381 | static inline void __init i##op(u32 **buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { \ |
| 383 | build_insn(buf, insn##op); \ |
| 384 | } |
| 385 | |
| 386 | I_u2u1s3(_addiu); |
| 387 | I_u3u1u2(_addu); |
| 388 | I_u2u1u3(_andi); |
| 389 | I_u3u1u2(_and); |
| 390 | I_u1u2s3(_beq); |
| 391 | I_u1u2s3(_beql); |
| 392 | I_u1s2(_bgez); |
| 393 | I_u1s2(_bgezl); |
| 394 | I_u1s2(_bltz); |
| 395 | I_u1s2(_bltzl); |
| 396 | I_u1u2s3(_bne); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 397 | I_u1u2u3(_dmfc0); |
| 398 | I_u1u2u3(_dmtc0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | I_u2u1s3(_daddiu); |
| 400 | I_u3u1u2(_daddu); |
| 401 | I_u2u1u3(_dsll); |
| 402 | I_u2u1u3(_dsll32); |
| 403 | I_u2u1u3(_dsra); |
| 404 | I_u2u1u3(_dsrl); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 405 | I_u2u1u3(_dsrl32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | I_u3u1u2(_dsubu); |
| 407 | I_0(_eret); |
| 408 | I_u1(_j); |
| 409 | I_u1(_jal); |
| 410 | I_u1(_jr); |
| 411 | I_u2s3u1(_ld); |
| 412 | I_u2s3u1(_ll); |
| 413 | I_u2s3u1(_lld); |
| 414 | I_u1s2(_lui); |
| 415 | I_u2s3u1(_lw); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 416 | I_u1u2u3(_mfc0); |
| 417 | I_u1u2u3(_mtc0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | I_u2u1u3(_ori); |
| 419 | I_0(_rfe); |
| 420 | I_u2s3u1(_sc); |
| 421 | I_u2s3u1(_scd); |
| 422 | I_u2s3u1(_sd); |
| 423 | I_u2u1u3(_sll); |
| 424 | I_u2u1u3(_sra); |
| 425 | I_u2u1u3(_srl); |
| 426 | I_u3u1u2(_subu); |
| 427 | I_u2s3u1(_sw); |
| 428 | I_0(_tlbp); |
| 429 | I_0(_tlbwi); |
| 430 | I_0(_tlbwr); |
| 431 | I_u3u1u2(_xor) |
| 432 | I_u2u1u3(_xori); |
| 433 | |
| 434 | /* |
| 435 | * handling labels |
| 436 | */ |
| 437 | |
| 438 | enum label_id { |
| 439 | label_invalid, |
| 440 | label_second_part, |
| 441 | label_leave, |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 442 | #ifdef MODULE_START |
| 443 | label_module_alloc, |
| 444 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | label_vmalloc, |
| 446 | label_vmalloc_done, |
| 447 | label_tlbw_hazard, |
| 448 | label_split, |
| 449 | label_nopage_tlbl, |
| 450 | label_nopage_tlbs, |
| 451 | label_nopage_tlbm, |
| 452 | label_smp_pgtable_change, |
| 453 | label_r3000_write_probe_fail, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | struct label { |
| 457 | u32 *addr; |
| 458 | enum label_id lab; |
| 459 | }; |
| 460 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 461 | static __init void build_label(struct label **lab, u32 *addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | enum label_id l) |
| 463 | { |
| 464 | (*lab)->addr = addr; |
| 465 | (*lab)->lab = l; |
| 466 | (*lab)++; |
| 467 | } |
| 468 | |
| 469 | #define L_LA(lb) \ |
| 470 | static inline void l##lb(struct label **lab, u32 *addr) \ |
| 471 | { \ |
| 472 | build_label(lab, addr, label##lb); \ |
| 473 | } |
| 474 | |
| 475 | L_LA(_second_part) |
| 476 | L_LA(_leave) |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 477 | #ifdef MODULE_START |
| 478 | L_LA(_module_alloc) |
| 479 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | L_LA(_vmalloc) |
| 481 | L_LA(_vmalloc_done) |
| 482 | L_LA(_tlbw_hazard) |
| 483 | L_LA(_split) |
| 484 | L_LA(_nopage_tlbl) |
| 485 | L_LA(_nopage_tlbs) |
| 486 | L_LA(_nopage_tlbm) |
| 487 | L_LA(_smp_pgtable_change) |
| 488 | L_LA(_r3000_write_probe_fail) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | /* convenience macros for instructions */ |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 491 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | # define i_LW(buf, rs, rt, off) i_ld(buf, rs, rt, off) |
| 493 | # define i_SW(buf, rs, rt, off) i_sd(buf, rs, rt, off) |
| 494 | # define i_SLL(buf, rs, rt, sh) i_dsll(buf, rs, rt, sh) |
| 495 | # define i_SRA(buf, rs, rt, sh) i_dsra(buf, rs, rt, sh) |
| 496 | # define i_SRL(buf, rs, rt, sh) i_dsrl(buf, rs, rt, sh) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 497 | # define i_MFC0(buf, rt, rd...) i_dmfc0(buf, rt, rd) |
| 498 | # define i_MTC0(buf, rt, rd...) i_dmtc0(buf, rt, rd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | # define i_ADDIU(buf, rs, rt, val) i_daddiu(buf, rs, rt, val) |
| 500 | # define i_ADDU(buf, rs, rt, rd) i_daddu(buf, rs, rt, rd) |
| 501 | # define i_SUBU(buf, rs, rt, rd) i_dsubu(buf, rs, rt, rd) |
| 502 | # define i_LL(buf, rs, rt, off) i_lld(buf, rs, rt, off) |
| 503 | # define i_SC(buf, rs, rt, off) i_scd(buf, rs, rt, off) |
| 504 | #else |
| 505 | # define i_LW(buf, rs, rt, off) i_lw(buf, rs, rt, off) |
| 506 | # define i_SW(buf, rs, rt, off) i_sw(buf, rs, rt, off) |
| 507 | # define i_SLL(buf, rs, rt, sh) i_sll(buf, rs, rt, sh) |
| 508 | # define i_SRA(buf, rs, rt, sh) i_sra(buf, rs, rt, sh) |
| 509 | # define i_SRL(buf, rs, rt, sh) i_srl(buf, rs, rt, sh) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 510 | # define i_MFC0(buf, rt, rd...) i_mfc0(buf, rt, rd) |
| 511 | # define i_MTC0(buf, rt, rd...) i_mtc0(buf, rt, rd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | # define i_ADDIU(buf, rs, rt, val) i_addiu(buf, rs, rt, val) |
| 513 | # define i_ADDU(buf, rs, rt, rd) i_addu(buf, rs, rt, rd) |
| 514 | # define i_SUBU(buf, rs, rt, rd) i_subu(buf, rs, rt, rd) |
| 515 | # define i_LL(buf, rs, rt, off) i_ll(buf, rs, rt, off) |
| 516 | # define i_SC(buf, rs, rt, off) i_sc(buf, rs, rt, off) |
| 517 | #endif |
| 518 | |
| 519 | #define i_b(buf, off) i_beq(buf, 0, 0, off) |
| 520 | #define i_beqz(buf, rs, off) i_beq(buf, rs, 0, off) |
| 521 | #define i_beqzl(buf, rs, off) i_beql(buf, rs, 0, off) |
| 522 | #define i_bnez(buf, rs, off) i_bne(buf, rs, 0, off) |
| 523 | #define i_bnezl(buf, rs, off) i_bnel(buf, rs, 0, off) |
| 524 | #define i_move(buf, a, b) i_ADDU(buf, a, 0, b) |
| 525 | #define i_nop(buf) i_sll(buf, 0, 0, 0) |
| 526 | #define i_ssnop(buf) i_sll(buf, 0, 0, 1) |
| 527 | #define i_ehb(buf) i_sll(buf, 0, 0, 3) |
| 528 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 529 | static __init int __maybe_unused in_compat_space_p(long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
| 531 | /* Is this address in 32bit compat space? */ |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 532 | #ifdef CONFIG_64BIT |
Ralf Baechle | 3ef33e6 | 2005-07-08 20:10:17 +0000 | [diff] [blame] | 533 | return (((addr) & 0xffffffff00000000L) == 0xffffffff00000000L); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 534 | #else |
| 535 | return 1; |
| 536 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 539 | static __init int __maybe_unused rel_highest(long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 541 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | return ((((val + 0x800080008000L) >> 48) & 0xffff) ^ 0x8000) - 0x8000; |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 543 | #else |
| 544 | return 0; |
| 545 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 548 | static __init int __maybe_unused rel_higher(long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 550 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return ((((val + 0x80008000L) >> 32) & 0xffff) ^ 0x8000) - 0x8000; |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 552 | #else |
| 553 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | #endif |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 557 | static __init int rel_hi(long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
| 559 | return ((((val + 0x8000L) >> 16) & 0xffff) ^ 0x8000) - 0x8000; |
| 560 | } |
| 561 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 562 | static __init int rel_lo(long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
| 564 | return ((val & 0xffff) ^ 0x8000) - 0x8000; |
| 565 | } |
| 566 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 567 | static __init void i_LA_mostly(u32 **buf, unsigned int rs, long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | if (!in_compat_space_p(addr)) { |
| 570 | i_lui(buf, rs, rel_highest(addr)); |
| 571 | if (rel_higher(addr)) |
| 572 | i_daddiu(buf, rs, rs, rel_higher(addr)); |
| 573 | if (rel_hi(addr)) { |
| 574 | i_dsll(buf, rs, rs, 16); |
| 575 | i_daddiu(buf, rs, rs, rel_hi(addr)); |
| 576 | i_dsll(buf, rs, rs, 16); |
| 577 | } else |
| 578 | i_dsll32(buf, rs, rs, 0); |
| 579 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | i_lui(buf, rs, rel_hi(addr)); |
| 581 | } |
| 582 | |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 583 | static __init void __maybe_unused i_LA(u32 **buf, unsigned int rs, long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
| 585 | i_LA_mostly(buf, rs, addr); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 586 | if (rel_lo(addr)) { |
| 587 | if (!in_compat_space_p(addr)) |
| 588 | i_daddiu(buf, rs, rs, rel_lo(addr)); |
| 589 | else |
| 590 | i_addiu(buf, rs, rs, rel_lo(addr)); |
| 591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /* |
| 595 | * handle relocations |
| 596 | */ |
| 597 | |
| 598 | struct reloc { |
| 599 | u32 *addr; |
| 600 | unsigned int type; |
| 601 | enum label_id lab; |
| 602 | }; |
| 603 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 604 | static __init void r_mips_pc16(struct reloc **rel, u32 *addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | enum label_id l) |
| 606 | { |
| 607 | (*rel)->addr = addr; |
| 608 | (*rel)->type = R_MIPS_PC16; |
| 609 | (*rel)->lab = l; |
| 610 | (*rel)++; |
| 611 | } |
| 612 | |
| 613 | static inline void __resolve_relocs(struct reloc *rel, struct label *lab) |
| 614 | { |
| 615 | long laddr = (long)lab->addr; |
| 616 | long raddr = (long)rel->addr; |
| 617 | |
| 618 | switch (rel->type) { |
| 619 | case R_MIPS_PC16: |
| 620 | *rel->addr |= build_bimm(laddr - (raddr + 4)); |
| 621 | break; |
| 622 | |
| 623 | default: |
| 624 | panic("Unsupported TLB synthesizer relocation %d", |
| 625 | rel->type); |
| 626 | } |
| 627 | } |
| 628 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 629 | static __init void resolve_relocs(struct reloc *rel, struct label *lab) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | struct label *l; |
| 632 | |
| 633 | for (; rel->lab != label_invalid; rel++) |
| 634 | for (l = lab; l->lab != label_invalid; l++) |
| 635 | if (rel->lab == l->lab) |
| 636 | __resolve_relocs(rel, l); |
| 637 | } |
| 638 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 639 | static __init void move_relocs(struct reloc *rel, u32 *first, u32 *end, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | long off) |
| 641 | { |
| 642 | for (; rel->lab != label_invalid; rel++) |
| 643 | if (rel->addr >= first && rel->addr < end) |
| 644 | rel->addr += off; |
| 645 | } |
| 646 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 647 | static __init void move_labels(struct label *lab, u32 *first, u32 *end, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | long off) |
| 649 | { |
| 650 | for (; lab->lab != label_invalid; lab++) |
| 651 | if (lab->addr >= first && lab->addr < end) |
| 652 | lab->addr += off; |
| 653 | } |
| 654 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 655 | static __init void copy_handler(struct reloc *rel, struct label *lab, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | u32 *first, u32 *end, u32 *target) |
| 657 | { |
| 658 | long off = (long)(target - first); |
| 659 | |
| 660 | memcpy(target, first, (end - first) * sizeof(u32)); |
| 661 | |
| 662 | move_relocs(rel, first, end, off); |
| 663 | move_labels(lab, first, end, off); |
| 664 | } |
| 665 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 666 | static __init int __maybe_unused insn_has_bdelay(struct reloc *rel, |
David Rientjes | e8b6d40 | 2007-05-10 22:51:05 -0700 | [diff] [blame] | 667 | u32 *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
| 669 | for (; rel->lab != label_invalid; rel++) { |
| 670 | if (rel->addr == addr |
| 671 | && (rel->type == R_MIPS_PC16 |
| 672 | || rel->type == R_MIPS_26)) |
| 673 | return 1; |
| 674 | } |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* convenience functions for labeled branches */ |
David Rientjes | e8b6d40 | 2007-05-10 22:51:05 -0700 | [diff] [blame] | 680 | static void __init __maybe_unused |
Ralf Baechle | 1443e48 | 2006-03-08 15:37:26 +0000 | [diff] [blame] | 681 | il_bltz(u32 **p, struct reloc **r, unsigned int reg, enum label_id l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
| 683 | r_mips_pc16(r, *p, l); |
| 684 | i_bltz(p, reg, 0); |
| 685 | } |
| 686 | |
David Rientjes | e8b6d40 | 2007-05-10 22:51:05 -0700 | [diff] [blame] | 687 | static void __init __maybe_unused il_b(u32 **p, struct reloc **r, |
| 688 | enum label_id l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
| 690 | r_mips_pc16(r, *p, l); |
| 691 | i_b(p, 0); |
| 692 | } |
| 693 | |
Ralf Baechle | 1443e48 | 2006-03-08 15:37:26 +0000 | [diff] [blame] | 694 | static void __init il_beqz(u32 **p, struct reloc **r, unsigned int reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | enum label_id l) |
| 696 | { |
| 697 | r_mips_pc16(r, *p, l); |
| 698 | i_beqz(p, reg, 0); |
| 699 | } |
| 700 | |
David Rientjes | e8b6d40 | 2007-05-10 22:51:05 -0700 | [diff] [blame] | 701 | static void __init __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | il_beqzl(u32 **p, struct reloc **r, unsigned int reg, enum label_id l) |
| 703 | { |
| 704 | r_mips_pc16(r, *p, l); |
| 705 | i_beqzl(p, reg, 0); |
| 706 | } |
| 707 | |
Ralf Baechle | 1443e48 | 2006-03-08 15:37:26 +0000 | [diff] [blame] | 708 | static void __init il_bnez(u32 **p, struct reloc **r, unsigned int reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | enum label_id l) |
| 710 | { |
| 711 | r_mips_pc16(r, *p, l); |
| 712 | i_bnez(p, reg, 0); |
| 713 | } |
| 714 | |
Ralf Baechle | 1443e48 | 2006-03-08 15:37:26 +0000 | [diff] [blame] | 715 | static void __init il_bgezl(u32 **p, struct reloc **r, unsigned int reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | enum label_id l) |
| 717 | { |
| 718 | r_mips_pc16(r, *p, l); |
| 719 | i_bgezl(p, reg, 0); |
| 720 | } |
| 721 | |
David Rientjes | e8b6d40 | 2007-05-10 22:51:05 -0700 | [diff] [blame] | 722 | static void __init __maybe_unused |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 723 | il_bgez(u32 **p, struct reloc **r, unsigned int reg, enum label_id l) |
| 724 | { |
| 725 | r_mips_pc16(r, *p, l); |
| 726 | i_bgez(p, reg, 0); |
| 727 | } |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | /* The only general purpose registers allowed in TLB handlers. */ |
| 730 | #define K0 26 |
| 731 | #define K1 27 |
| 732 | |
| 733 | /* Some CP0 registers */ |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 734 | #define C0_INDEX 0, 0 |
| 735 | #define C0_ENTRYLO0 2, 0 |
| 736 | #define C0_TCBIND 2, 2 |
| 737 | #define C0_ENTRYLO1 3, 0 |
| 738 | #define C0_CONTEXT 4, 0 |
| 739 | #define C0_BADVADDR 8, 0 |
| 740 | #define C0_ENTRYHI 10, 0 |
| 741 | #define C0_EPC 14, 0 |
| 742 | #define C0_XCONTEXT 20, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 744 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | # define GET_CONTEXT(buf, reg) i_MFC0(buf, reg, C0_XCONTEXT) |
| 746 | #else |
| 747 | # define GET_CONTEXT(buf, reg) i_MFC0(buf, reg, C0_CONTEXT) |
| 748 | #endif |
| 749 | |
| 750 | /* The worst case length of the handler is around 18 instructions for |
| 751 | * R3000-style TLBs and up to 63 instructions for R4000-style TLBs. |
| 752 | * Maximum space available is 32 instructions for R3000 and 64 |
| 753 | * instructions for R4000. |
| 754 | * |
| 755 | * We deliberately chose a buffer size of 128, so we won't scribble |
| 756 | * over anything important on overflow before we panic. |
| 757 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 758 | static __initdata u32 tlb_handler[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | /* simply assume worst case size for labels and relocs */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 761 | static __initdata struct label labels[128]; |
| 762 | static __initdata struct reloc relocs[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
| 764 | /* |
| 765 | * The R3000 TLB handler is simple. |
| 766 | */ |
| 767 | static void __init build_r3000_tlb_refill_handler(void) |
| 768 | { |
| 769 | long pgdc = (long)pgd_current; |
| 770 | u32 *p; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 771 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
| 773 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 774 | p = tlb_handler; |
| 775 | |
| 776 | i_mfc0(&p, K0, C0_BADVADDR); |
| 777 | i_lui(&p, K1, rel_hi(pgdc)); /* cp0 delay */ |
| 778 | i_lw(&p, K1, rel_lo(pgdc), K1); |
| 779 | i_srl(&p, K0, K0, 22); /* load delay */ |
| 780 | i_sll(&p, K0, K0, 2); |
| 781 | i_addu(&p, K1, K1, K0); |
| 782 | i_mfc0(&p, K0, C0_CONTEXT); |
| 783 | i_lw(&p, K1, 0, K1); /* cp0 delay */ |
| 784 | i_andi(&p, K0, K0, 0xffc); /* load delay */ |
| 785 | i_addu(&p, K1, K1, K0); |
| 786 | i_lw(&p, K0, 0, K1); |
| 787 | i_nop(&p); /* load delay */ |
| 788 | i_mtc0(&p, K0, C0_ENTRYLO0); |
| 789 | i_mfc0(&p, K1, C0_EPC); /* cp0 delay */ |
| 790 | i_tlbwr(&p); /* cp0 delay */ |
| 791 | i_jr(&p, K1); |
| 792 | i_rfe(&p); /* branch delay */ |
| 793 | |
| 794 | if (p > tlb_handler + 32) |
| 795 | panic("TLB refill handler space exceeded"); |
| 796 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 797 | pr_info("Synthesized TLB refill handler (%u instructions).\n", |
| 798 | (unsigned int)(p - tlb_handler)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 800 | pr_debug("\t.set push\n"); |
| 801 | pr_debug("\t.set noreorder\n"); |
| 802 | for (i = 0; i < (p - tlb_handler); i++) |
| 803 | pr_debug("\t.word 0x%08x\n", tlb_handler[i]); |
| 804 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 806 | memcpy((void *)ebase, tlb_handler, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /* |
| 810 | * The R4000 TLB handler is much more complicated. We have two |
| 811 | * consecutive handler areas with 32 instructions space each. |
| 812 | * Since they aren't used at the same time, we can overflow in the |
| 813 | * other one.To keep things simple, we first assume linear space, |
| 814 | * then we relocate it to the final handler layout as needed. |
| 815 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 816 | static __initdata u32 final_handler[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* |
| 819 | * Hazards |
| 820 | * |
| 821 | * From the IDT errata for the QED RM5230 (Nevada), processor revision 1.0: |
| 822 | * 2. A timing hazard exists for the TLBP instruction. |
| 823 | * |
| 824 | * stalling_instruction |
| 825 | * TLBP |
| 826 | * |
| 827 | * The JTLB is being read for the TLBP throughout the stall generated by the |
| 828 | * previous instruction. This is not really correct as the stalling instruction |
| 829 | * can modify the address used to access the JTLB. The failure symptom is that |
| 830 | * the TLBP instruction will use an address created for the stalling instruction |
| 831 | * and not the address held in C0_ENHI and thus report the wrong results. |
| 832 | * |
| 833 | * The software work-around is to not allow the instruction preceding the TLBP |
| 834 | * to stall - make it an NOP or some other instruction guaranteed not to stall. |
| 835 | * |
| 836 | * Errata 2 will not be fixed. This errata is also on the R5000. |
| 837 | * |
| 838 | * As if we MIPS hackers wouldn't know how to nop pipelines happy ... |
| 839 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 840 | static __init void __maybe_unused build_tlb_probe_entry(u32 **p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 842 | switch (current_cpu_type()) { |
Thiemo Seufer | f5b4d95 | 2005-09-09 17:11:50 +0000 | [diff] [blame] | 843 | /* Found by experiment: R4600 v2.0 needs this, too. */ |
| 844 | case CPU_R4600: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | case CPU_R5000: |
| 846 | case CPU_R5000A: |
| 847 | case CPU_NEVADA: |
| 848 | i_nop(p); |
| 849 | i_tlbp(p); |
| 850 | break; |
| 851 | |
| 852 | default: |
| 853 | i_tlbp(p); |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | /* |
| 859 | * Write random or indexed TLB entry, and care about the hazards from |
| 860 | * the preceeding mtc0 and for the following eret. |
| 861 | */ |
| 862 | enum tlb_write_entry { tlb_random, tlb_indexed }; |
| 863 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 864 | static __init void build_tlb_write_entry(u32 **p, struct label **l, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | struct reloc **r, |
| 866 | enum tlb_write_entry wmode) |
| 867 | { |
| 868 | void(*tlbw)(u32 **) = NULL; |
| 869 | |
| 870 | switch (wmode) { |
| 871 | case tlb_random: tlbw = i_tlbwr; break; |
| 872 | case tlb_indexed: tlbw = i_tlbwi; break; |
| 873 | } |
| 874 | |
Ralf Baechle | 161548b | 2008-01-29 10:14:54 +0000 | [diff] [blame] | 875 | if (cpu_has_mips_r2) { |
| 876 | i_ehb(p); |
| 877 | tlbw(p); |
| 878 | return; |
| 879 | } |
| 880 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 881 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | case CPU_R4000PC: |
| 883 | case CPU_R4000SC: |
| 884 | case CPU_R4000MC: |
| 885 | case CPU_R4400PC: |
| 886 | case CPU_R4400SC: |
| 887 | case CPU_R4400MC: |
| 888 | /* |
| 889 | * This branch uses up a mtc0 hazard nop slot and saves |
| 890 | * two nops after the tlbw instruction. |
| 891 | */ |
| 892 | il_bgezl(p, r, 0, label_tlbw_hazard); |
| 893 | tlbw(p); |
| 894 | l_tlbw_hazard(l, *p); |
| 895 | i_nop(p); |
| 896 | break; |
| 897 | |
| 898 | case CPU_R4600: |
| 899 | case CPU_R4700: |
| 900 | case CPU_R5000: |
| 901 | case CPU_R5000A: |
Maciej W. Rozycki | 2c93e12 | 2005-06-30 10:51:01 +0000 | [diff] [blame] | 902 | i_nop(p); |
| 903 | tlbw(p); |
| 904 | i_nop(p); |
| 905 | break; |
| 906 | |
| 907 | case CPU_R4300: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | case CPU_5KC: |
| 909 | case CPU_TX49XX: |
| 910 | case CPU_AU1000: |
| 911 | case CPU_AU1100: |
| 912 | case CPU_AU1500: |
| 913 | case CPU_AU1550: |
Pete Popov | e3ad1c2 | 2005-03-01 06:33:16 +0000 | [diff] [blame] | 914 | case CPU_AU1200: |
Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 915 | case CPU_PR4450: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | i_nop(p); |
| 917 | tlbw(p); |
| 918 | break; |
| 919 | |
| 920 | case CPU_R10000: |
| 921 | case CPU_R12000: |
Kumba | 44d921b | 2006-05-16 22:23:59 -0400 | [diff] [blame] | 922 | case CPU_R14000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | case CPU_4KC: |
| 924 | case CPU_SB1: |
Andrew Isaacson | 93ce2f52 | 2005-10-19 23:56:20 -0700 | [diff] [blame] | 925 | case CPU_SB1A: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | case CPU_4KSC: |
| 927 | case CPU_20KC: |
| 928 | case CPU_25KF: |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 929 | case CPU_BCM3302: |
| 930 | case CPU_BCM4710: |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 931 | case CPU_LOONGSON2: |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 932 | if (m4kc_tlbp_war()) |
| 933 | i_nop(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | tlbw(p); |
| 935 | break; |
| 936 | |
| 937 | case CPU_NEVADA: |
| 938 | i_nop(p); /* QED specifies 2 nops hazard */ |
| 939 | /* |
| 940 | * This branch uses up a mtc0 hazard nop slot and saves |
| 941 | * a nop after the tlbw instruction. |
| 942 | */ |
| 943 | il_bgezl(p, r, 0, label_tlbw_hazard); |
| 944 | tlbw(p); |
| 945 | l_tlbw_hazard(l, *p); |
| 946 | break; |
| 947 | |
| 948 | case CPU_RM7000: |
| 949 | i_nop(p); |
| 950 | i_nop(p); |
| 951 | i_nop(p); |
| 952 | i_nop(p); |
| 953 | tlbw(p); |
| 954 | break; |
| 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | case CPU_RM9000: |
| 957 | /* |
| 958 | * When the JTLB is updated by tlbwi or tlbwr, a subsequent |
| 959 | * use of the JTLB for instructions should not occur for 4 |
| 960 | * cpu cycles and use for data translations should not occur |
| 961 | * for 3 cpu cycles. |
| 962 | */ |
| 963 | i_ssnop(p); |
| 964 | i_ssnop(p); |
| 965 | i_ssnop(p); |
| 966 | i_ssnop(p); |
| 967 | tlbw(p); |
| 968 | i_ssnop(p); |
| 969 | i_ssnop(p); |
| 970 | i_ssnop(p); |
| 971 | i_ssnop(p); |
| 972 | break; |
| 973 | |
| 974 | case CPU_VR4111: |
| 975 | case CPU_VR4121: |
| 976 | case CPU_VR4122: |
| 977 | case CPU_VR4181: |
| 978 | case CPU_VR4181A: |
| 979 | i_nop(p); |
| 980 | i_nop(p); |
| 981 | tlbw(p); |
| 982 | i_nop(p); |
| 983 | i_nop(p); |
| 984 | break; |
| 985 | |
| 986 | case CPU_VR4131: |
| 987 | case CPU_VR4133: |
Ralf Baechle | 7623deb | 2005-08-29 16:49:55 +0000 | [diff] [blame] | 988 | case CPU_R5432: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | i_nop(p); |
| 990 | i_nop(p); |
| 991 | tlbw(p); |
| 992 | break; |
| 993 | |
| 994 | default: |
| 995 | panic("No TLB refill handler yet (CPU type: %d)", |
| 996 | current_cpu_data.cputype); |
| 997 | break; |
| 998 | } |
| 999 | } |
| 1000 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1001 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | /* |
| 1003 | * TMP and PTR are scratch. |
| 1004 | * TMP will be clobbered, PTR will hold the pmd entry. |
| 1005 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1006 | static __init void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | build_get_pmde64(u32 **p, struct label **l, struct reloc **r, |
| 1008 | unsigned int tmp, unsigned int ptr) |
| 1009 | { |
| 1010 | long pgdc = (long)pgd_current; |
| 1011 | |
| 1012 | /* |
| 1013 | * The vmalloc handling is not in the hotpath. |
| 1014 | */ |
| 1015 | i_dmfc0(p, tmp, C0_BADVADDR); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 1016 | #ifdef MODULE_START |
| 1017 | il_bltz(p, r, tmp, label_module_alloc); |
| 1018 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | il_bltz(p, r, tmp, label_vmalloc); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 1020 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | /* No i_nop needed here, since the next insn doesn't touch TMP. */ |
| 1022 | |
| 1023 | #ifdef CONFIG_SMP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1024 | # ifdef CONFIG_MIPS_MT_SMTC |
| 1025 | /* |
| 1026 | * SMTC uses TCBind value as "CPU" index |
| 1027 | */ |
| 1028 | i_mfc0(p, ptr, C0_TCBIND); |
| 1029 | i_dsrl(p, ptr, ptr, 19); |
| 1030 | # else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | /* |
Thiemo Seufer | 1b3a6e9 | 2005-04-01 14:07:13 +0000 | [diff] [blame] | 1032 | * 64 bit SMP running in XKPHYS has smp_processor_id() << 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | * stored in CONTEXT. |
| 1034 | */ |
Thiemo Seufer | 1b3a6e9 | 2005-04-01 14:07:13 +0000 | [diff] [blame] | 1035 | i_dmfc0(p, ptr, C0_CONTEXT); |
| 1036 | i_dsrl(p, ptr, ptr, 23); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1037 | #endif |
Thiemo Seufer | 1b3a6e9 | 2005-04-01 14:07:13 +0000 | [diff] [blame] | 1038 | i_LA_mostly(p, tmp, pgdc); |
| 1039 | i_daddu(p, ptr, ptr, tmp); |
| 1040 | i_dmfc0(p, tmp, C0_BADVADDR); |
| 1041 | i_ld(p, ptr, rel_lo(pgdc), ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | #else |
| 1043 | i_LA_mostly(p, ptr, pgdc); |
| 1044 | i_ld(p, ptr, rel_lo(pgdc), ptr); |
| 1045 | #endif |
| 1046 | |
| 1047 | l_vmalloc_done(l, *p); |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 1048 | |
| 1049 | if (PGDIR_SHIFT - 3 < 32) /* get pgd offset in bytes */ |
| 1050 | i_dsrl(p, tmp, tmp, PGDIR_SHIFT-3); |
| 1051 | else |
| 1052 | i_dsrl32(p, tmp, tmp, PGDIR_SHIFT - 3 - 32); |
| 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3); |
| 1055 | i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */ |
| 1056 | i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 1057 | i_ld(p, ptr, 0, ptr); /* get pmd pointer */ |
| 1058 | i_dsrl(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */ |
| 1059 | i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3); |
| 1060 | i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */ |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * BVADDR is the faulting address, PTR is scratch. |
| 1065 | * PTR will hold the pgd for vmalloc. |
| 1066 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1067 | static __init void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r, |
| 1069 | unsigned int bvaddr, unsigned int ptr) |
| 1070 | { |
| 1071 | long swpd = (long)swapper_pg_dir; |
| 1072 | |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 1073 | #ifdef MODULE_START |
| 1074 | long modd = (long)module_pg_dir; |
| 1075 | |
| 1076 | l_module_alloc(l, *p); |
| 1077 | /* |
| 1078 | * Assumption: |
| 1079 | * VMALLOC_START >= 0xc000000000000000UL |
| 1080 | * MODULE_START >= 0xe000000000000000UL |
| 1081 | */ |
| 1082 | i_SLL(p, ptr, bvaddr, 2); |
| 1083 | il_bgez(p, r, ptr, label_vmalloc); |
| 1084 | |
| 1085 | if (in_compat_space_p(MODULE_START) && !rel_lo(MODULE_START)) { |
| 1086 | i_lui(p, ptr, rel_hi(MODULE_START)); /* delay slot */ |
| 1087 | } else { |
| 1088 | /* unlikely configuration */ |
| 1089 | i_nop(p); /* delay slot */ |
| 1090 | i_LA(p, ptr, MODULE_START); |
| 1091 | } |
| 1092 | i_dsubu(p, bvaddr, bvaddr, ptr); |
| 1093 | |
| 1094 | if (in_compat_space_p(modd) && !rel_lo(modd)) { |
| 1095 | il_b(p, r, label_vmalloc_done); |
| 1096 | i_lui(p, ptr, rel_hi(modd)); |
| 1097 | } else { |
| 1098 | i_LA_mostly(p, ptr, modd); |
| 1099 | il_b(p, r, label_vmalloc_done); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 1100 | if (in_compat_space_p(modd)) |
| 1101 | i_addiu(p, ptr, ptr, rel_lo(modd)); |
| 1102 | else |
| 1103 | i_daddiu(p, ptr, ptr, rel_lo(modd)); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | l_vmalloc(l, *p); |
| 1107 | if (in_compat_space_p(MODULE_START) && !rel_lo(MODULE_START) && |
| 1108 | MODULE_START << 32 == VMALLOC_START) |
| 1109 | i_dsll32(p, ptr, ptr, 0); /* typical case */ |
| 1110 | else |
| 1111 | i_LA(p, ptr, VMALLOC_START); |
| 1112 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | l_vmalloc(l, *p); |
| 1114 | i_LA(p, ptr, VMALLOC_START); |
Atsushi Nemoto | 656be92 | 2006-10-26 00:08:31 +0900 | [diff] [blame] | 1115 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | i_dsubu(p, bvaddr, bvaddr, ptr); |
| 1117 | |
| 1118 | if (in_compat_space_p(swpd) && !rel_lo(swpd)) { |
| 1119 | il_b(p, r, label_vmalloc_done); |
| 1120 | i_lui(p, ptr, rel_hi(swpd)); |
| 1121 | } else { |
| 1122 | i_LA_mostly(p, ptr, swpd); |
| 1123 | il_b(p, r, label_vmalloc_done); |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame^] | 1124 | if (in_compat_space_p(swpd)) |
| 1125 | i_addiu(p, ptr, ptr, rel_lo(swpd)); |
| 1126 | else |
| 1127 | i_daddiu(p, ptr, ptr, rel_lo(swpd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1131 | #else /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
| 1133 | /* |
| 1134 | * TMP and PTR are scratch. |
| 1135 | * TMP will be clobbered, PTR will hold the pgd entry. |
| 1136 | */ |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1137 | static __init void __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr) |
| 1139 | { |
| 1140 | long pgdc = (long)pgd_current; |
| 1141 | |
| 1142 | /* 32 bit SMP has smp_processor_id() stored in CONTEXT. */ |
| 1143 | #ifdef CONFIG_SMP |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1144 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1145 | /* |
| 1146 | * SMTC uses TCBind value as "CPU" index |
| 1147 | */ |
| 1148 | i_mfc0(p, ptr, C0_TCBIND); |
| 1149 | i_LA_mostly(p, tmp, pgdc); |
| 1150 | i_srl(p, ptr, ptr, 19); |
| 1151 | #else |
| 1152 | /* |
| 1153 | * smp_processor_id() << 3 is stored in CONTEXT. |
| 1154 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | i_mfc0(p, ptr, C0_CONTEXT); |
| 1156 | i_LA_mostly(p, tmp, pgdc); |
| 1157 | i_srl(p, ptr, ptr, 23); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1158 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | i_addu(p, ptr, tmp, ptr); |
| 1160 | #else |
| 1161 | i_LA_mostly(p, ptr, pgdc); |
| 1162 | #endif |
| 1163 | i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */ |
| 1164 | i_lw(p, ptr, rel_lo(pgdc), ptr); |
| 1165 | i_srl(p, tmp, tmp, PGDIR_SHIFT); /* get pgd only bits */ |
| 1166 | i_sll(p, tmp, tmp, PGD_T_LOG2); |
| 1167 | i_addu(p, ptr, ptr, tmp); /* add in pgd offset */ |
| 1168 | } |
| 1169 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1170 | #endif /* !CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1172 | static __init void build_adjust_context(u32 **p, unsigned int ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | { |
Ralf Baechle | 242954b | 2006-10-24 02:29:01 +0100 | [diff] [blame] | 1174 | unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1); |
| 1176 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1177 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | case CPU_VR41XX: |
| 1179 | case CPU_VR4111: |
| 1180 | case CPU_VR4121: |
| 1181 | case CPU_VR4122: |
| 1182 | case CPU_VR4131: |
| 1183 | case CPU_VR4181: |
| 1184 | case CPU_VR4181A: |
| 1185 | case CPU_VR4133: |
| 1186 | shift += 2; |
| 1187 | break; |
| 1188 | |
| 1189 | default: |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | if (shift) |
| 1194 | i_SRL(p, ctx, ctx, shift); |
| 1195 | i_andi(p, ctx, ctx, mask); |
| 1196 | } |
| 1197 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1198 | static __init void build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | { |
| 1200 | /* |
| 1201 | * Bug workaround for the Nevada. It seems as if under certain |
| 1202 | * circumstances the move from cp0_context might produce a |
| 1203 | * bogus result when the mfc0 instruction and its consumer are |
| 1204 | * in a different cacheline or a load instruction, probably any |
| 1205 | * memory reference, is between them. |
| 1206 | */ |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1207 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | case CPU_NEVADA: |
| 1209 | i_LW(p, ptr, 0, ptr); |
| 1210 | GET_CONTEXT(p, tmp); /* get context reg */ |
| 1211 | break; |
| 1212 | |
| 1213 | default: |
| 1214 | GET_CONTEXT(p, tmp); /* get context reg */ |
| 1215 | i_LW(p, ptr, 0, ptr); |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | build_adjust_context(p, tmp); |
| 1220 | i_ADDU(p, ptr, ptr, tmp); /* add in offset */ |
| 1221 | } |
| 1222 | |
Ralf Baechle | 6f1ca1d | 2007-10-12 15:39:45 +0100 | [diff] [blame] | 1223 | static __init void build_update_entries(u32 **p, unsigned int tmp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | unsigned int ptep) |
| 1225 | { |
| 1226 | /* |
| 1227 | * 64bit address support (36bit on a 32bit CPU) in a 32bit |
| 1228 | * Kernel is a special case. Only a few CPUs use it. |
| 1229 | */ |
| 1230 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 1231 | if (cpu_has_64bits) { |
| 1232 | i_ld(p, tmp, 0, ptep); /* get even pte */ |
| 1233 | i_ld(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
| 1234 | i_dsrl(p, tmp, tmp, 6); /* convert to entrylo0 */ |
| 1235 | i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 1236 | i_dsrl(p, ptep, ptep, 6); /* convert to entrylo1 */ |
| 1237 | i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
| 1238 | } else { |
| 1239 | int pte_off_even = sizeof(pte_t) / 2; |
| 1240 | int pte_off_odd = pte_off_even + sizeof(pte_t); |
| 1241 | |
| 1242 | /* The pte entries are pre-shifted */ |
| 1243 | i_lw(p, tmp, pte_off_even, ptep); /* get even pte */ |
| 1244 | i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 1245 | i_lw(p, ptep, pte_off_odd, ptep); /* get odd pte */ |
| 1246 | i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
| 1247 | } |
| 1248 | #else |
| 1249 | i_LW(p, tmp, 0, ptep); /* get even pte */ |
| 1250 | i_LW(p, ptep, sizeof(pte_t), ptep); /* get odd pte */ |
| 1251 | if (r45k_bvahwbug()) |
| 1252 | build_tlb_probe_entry(p); |
| 1253 | i_SRL(p, tmp, tmp, 6); /* convert to entrylo0 */ |
| 1254 | if (r4k_250MHZhwbug()) |
| 1255 | i_mtc0(p, 0, C0_ENTRYLO0); |
| 1256 | i_mtc0(p, tmp, C0_ENTRYLO0); /* load it */ |
| 1257 | i_SRL(p, ptep, ptep, 6); /* convert to entrylo1 */ |
| 1258 | if (r45k_bvahwbug()) |
| 1259 | i_mfc0(p, tmp, C0_INDEX); |
| 1260 | if (r4k_250MHZhwbug()) |
| 1261 | i_mtc0(p, 0, C0_ENTRYLO1); |
| 1262 | i_mtc0(p, ptep, C0_ENTRYLO1); /* load it */ |
| 1263 | #endif |
| 1264 | } |
| 1265 | |
| 1266 | static void __init build_r4000_tlb_refill_handler(void) |
| 1267 | { |
| 1268 | u32 *p = tlb_handler; |
| 1269 | struct label *l = labels; |
| 1270 | struct reloc *r = relocs; |
| 1271 | u32 *f; |
| 1272 | unsigned int final_len; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1273 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | memset(tlb_handler, 0, sizeof(tlb_handler)); |
| 1276 | memset(labels, 0, sizeof(labels)); |
| 1277 | memset(relocs, 0, sizeof(relocs)); |
| 1278 | memset(final_handler, 0, sizeof(final_handler)); |
| 1279 | |
| 1280 | /* |
| 1281 | * create the plain linear handler |
| 1282 | */ |
| 1283 | if (bcm1250_m3_war()) { |
| 1284 | i_MFC0(&p, K0, C0_BADVADDR); |
| 1285 | i_MFC0(&p, K1, C0_ENTRYHI); |
| 1286 | i_xor(&p, K0, K0, K1); |
| 1287 | i_SRL(&p, K0, K0, PAGE_SHIFT + 1); |
| 1288 | il_bnez(&p, &r, K0, label_leave); |
| 1289 | /* No need for i_nop */ |
| 1290 | } |
| 1291 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1292 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | build_get_pmde64(&p, &l, &r, K0, K1); /* get pmd in K1 */ |
| 1294 | #else |
| 1295 | build_get_pgde32(&p, K0, K1); /* get pgd in K1 */ |
| 1296 | #endif |
| 1297 | |
| 1298 | build_get_ptep(&p, K0, K1); |
| 1299 | build_update_entries(&p, K0, K1); |
| 1300 | build_tlb_write_entry(&p, &l, &r, tlb_random); |
| 1301 | l_leave(&l, p); |
| 1302 | i_eret(&p); /* return from trap */ |
| 1303 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1304 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | build_get_pgd_vmalloc64(&p, &l, &r, K0, K1); |
| 1306 | #endif |
| 1307 | |
| 1308 | /* |
| 1309 | * Overflow check: For the 64bit handler, we need at least one |
| 1310 | * free instruction slot for the wrap-around branch. In worst |
| 1311 | * case, if the intended insertion point is a delay slot, we |
Matt LaPlante | 4b3f686 | 2006-10-03 22:21:02 +0200 | [diff] [blame] | 1312 | * need three, with the second nop'ed and the third being |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | * unused. |
| 1314 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 1315 | /* Loongson2 ebase is different than r4k, we have more space */ |
| 1316 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | if ((p - tlb_handler) > 64) |
| 1318 | panic("TLB refill handler space exceeded"); |
| 1319 | #else |
| 1320 | if (((p - tlb_handler) > 63) |
| 1321 | || (((p - tlb_handler) > 61) |
| 1322 | && insn_has_bdelay(relocs, tlb_handler + 29))) |
| 1323 | panic("TLB refill handler space exceeded"); |
| 1324 | #endif |
| 1325 | |
| 1326 | /* |
| 1327 | * Now fold the handler in the TLB refill handler space. |
| 1328 | */ |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 1329 | #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | f = final_handler; |
| 1331 | /* Simplest case, just copy the handler. */ |
| 1332 | copy_handler(relocs, labels, tlb_handler, p, f); |
| 1333 | final_len = p - tlb_handler; |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1334 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | f = final_handler + 32; |
| 1336 | if ((p - tlb_handler) <= 32) { |
| 1337 | /* Just copy the handler. */ |
| 1338 | copy_handler(relocs, labels, tlb_handler, p, f); |
| 1339 | final_len = p - tlb_handler; |
| 1340 | } else { |
| 1341 | u32 *split = tlb_handler + 30; |
| 1342 | |
| 1343 | /* |
| 1344 | * Find the split point. |
| 1345 | */ |
| 1346 | if (insn_has_bdelay(relocs, split - 1)) |
| 1347 | split--; |
| 1348 | |
| 1349 | /* Copy first part of the handler. */ |
| 1350 | copy_handler(relocs, labels, tlb_handler, split, f); |
| 1351 | f += split - tlb_handler; |
| 1352 | |
| 1353 | /* Insert branch. */ |
| 1354 | l_split(&l, final_handler); |
| 1355 | il_b(&f, &r, label_split); |
| 1356 | if (insn_has_bdelay(relocs, split)) |
| 1357 | i_nop(&f); |
| 1358 | else { |
| 1359 | copy_handler(relocs, labels, split, split + 1, f); |
| 1360 | move_labels(labels, f, f + 1, -1); |
| 1361 | f++; |
| 1362 | split++; |
| 1363 | } |
| 1364 | |
| 1365 | /* Copy the rest of the handler. */ |
| 1366 | copy_handler(relocs, labels, split, p, final_handler); |
| 1367 | final_len = (f - (final_handler + 32)) + (p - split); |
| 1368 | } |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1369 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1372 | pr_info("Synthesized TLB refill handler (%u instructions).\n", |
| 1373 | final_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1375 | f = final_handler; |
Fuxin Zhang | 2a21c73 | 2007-06-06 14:52:43 +0800 | [diff] [blame] | 1376 | #if defined(CONFIG_64BIT) && !defined(CONFIG_CPU_LOONGSON2) |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1377 | if (final_len > 32) |
| 1378 | final_len = 64; |
| 1379 | else |
| 1380 | f = final_handler + 32; |
Maciej W. Rozycki | 4c0a2d4 | 2005-06-29 10:43:51 +0000 | [diff] [blame] | 1381 | #endif /* CONFIG_64BIT */ |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1382 | pr_debug("\t.set push\n"); |
| 1383 | pr_debug("\t.set noreorder\n"); |
| 1384 | for (i = 0; i < final_len; i++) |
| 1385 | pr_debug("\t.word 0x%08x\n", f[i]); |
| 1386 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 1388 | memcpy((void *)ebase, final_handler, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | /* |
| 1392 | * TLB load/store/modify handlers. |
| 1393 | * |
| 1394 | * Only the fastpath gets synthesized at runtime, the slowpath for |
| 1395 | * do_page_fault remains normal asm. |
| 1396 | */ |
| 1397 | extern void tlb_do_page_fault_0(void); |
| 1398 | extern void tlb_do_page_fault_1(void); |
| 1399 | |
| 1400 | #define __tlb_handler_align \ |
| 1401 | __attribute__((__aligned__(1 << CONFIG_MIPS_L1_CACHE_SHIFT))) |
| 1402 | |
| 1403 | /* |
| 1404 | * 128 instructions for the fastpath handler is generous and should |
| 1405 | * never be exceeded. |
| 1406 | */ |
| 1407 | #define FASTPATH_SIZE 128 |
| 1408 | |
| 1409 | u32 __tlb_handler_align handle_tlbl[FASTPATH_SIZE]; |
| 1410 | u32 __tlb_handler_align handle_tlbs[FASTPATH_SIZE]; |
| 1411 | u32 __tlb_handler_align handle_tlbm[FASTPATH_SIZE]; |
| 1412 | |
| 1413 | static void __init |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1414 | iPTE_LW(u32 **p, struct label **l, unsigned int pte, unsigned int ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | { |
| 1416 | #ifdef CONFIG_SMP |
| 1417 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1418 | if (cpu_has_64bits) |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1419 | i_lld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | else |
| 1421 | # endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1422 | i_LL(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | #else |
| 1424 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1425 | if (cpu_has_64bits) |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1426 | i_ld(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | else |
| 1428 | # endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1429 | i_LW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | #endif |
| 1431 | } |
| 1432 | |
| 1433 | static void __init |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1434 | iPTE_SW(u32 **p, struct reloc **r, unsigned int pte, unsigned int ptr, |
| 1435 | unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1437 | #ifdef CONFIG_64BIT_PHYS_ADDR |
| 1438 | unsigned int hwmode = mode & (_PAGE_VALID | _PAGE_DIRTY); |
| 1439 | #endif |
| 1440 | |
| 1441 | i_ori(p, pte, pte, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | #ifdef CONFIG_SMP |
| 1443 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1444 | if (cpu_has_64bits) |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1445 | i_scd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | else |
| 1447 | # endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1448 | i_SC(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
| 1450 | if (r10000_llsc_war()) |
| 1451 | il_beqzl(p, r, pte, label_smp_pgtable_change); |
| 1452 | else |
| 1453 | il_beqz(p, r, pte, label_smp_pgtable_change); |
| 1454 | |
| 1455 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1456 | if (!cpu_has_64bits) { |
| 1457 | /* no i_nop needed */ |
| 1458 | i_ll(p, pte, sizeof(pte_t) / 2, ptr); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1459 | i_ori(p, pte, pte, hwmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | i_sc(p, pte, sizeof(pte_t) / 2, ptr); |
| 1461 | il_beqz(p, r, pte, label_smp_pgtable_change); |
| 1462 | /* no i_nop needed */ |
| 1463 | i_lw(p, pte, 0, ptr); |
| 1464 | } else |
| 1465 | i_nop(p); |
| 1466 | # else |
| 1467 | i_nop(p); |
| 1468 | # endif |
| 1469 | #else |
| 1470 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1471 | if (cpu_has_64bits) |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1472 | i_sd(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | else |
| 1474 | # endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1475 | i_SW(p, pte, 0, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
| 1477 | # ifdef CONFIG_64BIT_PHYS_ADDR |
| 1478 | if (!cpu_has_64bits) { |
| 1479 | i_lw(p, pte, sizeof(pte_t) / 2, ptr); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1480 | i_ori(p, pte, pte, hwmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | i_sw(p, pte, sizeof(pte_t) / 2, ptr); |
| 1482 | i_lw(p, pte, 0, ptr); |
| 1483 | } |
| 1484 | # endif |
| 1485 | #endif |
| 1486 | } |
| 1487 | |
| 1488 | /* |
| 1489 | * Check if PTE is present, if not then jump to LABEL. PTR points to |
| 1490 | * the page table where this PTE is located, PTE will be re-loaded |
| 1491 | * with it's original value. |
| 1492 | */ |
| 1493 | static void __init |
| 1494 | build_pte_present(u32 **p, struct label **l, struct reloc **r, |
| 1495 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1496 | { |
| 1497 | i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 1498 | i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_READ); |
| 1499 | il_bnez(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1500 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /* Make PTE valid, store result in PTR. */ |
| 1504 | static void __init |
| 1505 | build_make_valid(u32 **p, struct reloc **r, unsigned int pte, |
| 1506 | unsigned int ptr) |
| 1507 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1508 | unsigned int mode = _PAGE_VALID | _PAGE_ACCESSED; |
| 1509 | |
| 1510 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | * Check if PTE can be written to, if not branch to LABEL. Regardless |
| 1515 | * restore PTE with value from PTR when done. |
| 1516 | */ |
| 1517 | static void __init |
| 1518 | build_pte_writable(u32 **p, struct label **l, struct reloc **r, |
| 1519 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1520 | { |
| 1521 | i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 1522 | i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE); |
| 1523 | il_bnez(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1524 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /* Make PTE writable, update software status bits as well, then store |
| 1528 | * at PTR. |
| 1529 | */ |
| 1530 | static void __init |
| 1531 | build_make_write(u32 **p, struct reloc **r, unsigned int pte, |
| 1532 | unsigned int ptr) |
| 1533 | { |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1534 | unsigned int mode = (_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID |
| 1535 | | _PAGE_DIRTY); |
| 1536 | |
| 1537 | iPTE_SW(p, r, pte, ptr, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /* |
| 1541 | * Check if PTE can be modified, if not branch to LABEL. Regardless |
| 1542 | * restore PTE with value from PTR when done. |
| 1543 | */ |
| 1544 | static void __init |
| 1545 | build_pte_modifiable(u32 **p, struct label **l, struct reloc **r, |
| 1546 | unsigned int pte, unsigned int ptr, enum label_id lid) |
| 1547 | { |
| 1548 | i_andi(p, pte, pte, _PAGE_WRITE); |
| 1549 | il_beqz(p, r, pte, lid); |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1550 | iPTE_LW(p, l, pte, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /* |
| 1554 | * R3000 style TLB load/store/modify handlers. |
| 1555 | */ |
| 1556 | |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1557 | /* |
| 1558 | * This places the pte into ENTRYLO0 and writes it with tlbwi. |
| 1559 | * Then it returns. |
| 1560 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | static void __init |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1562 | 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] | 1563 | { |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1564 | i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 1565 | i_mfc0(p, tmp, C0_EPC); /* cp0 delay */ |
| 1566 | i_tlbwi(p); |
| 1567 | i_jr(p, tmp); |
| 1568 | i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | /* |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1572 | * This places the pte into ENTRYLO0 and writes it with tlbwi |
| 1573 | * or tlbwr as appropriate. This is because the index register |
| 1574 | * may have the probe fail bit set as a result of a trap on a |
| 1575 | * kseg2 access, i.e. without refill. Then it returns. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | */ |
| 1577 | static void __init |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1578 | build_r3000_tlb_reload_write(u32 **p, struct label **l, struct reloc **r, |
| 1579 | unsigned int pte, unsigned int tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | { |
| 1581 | i_mfc0(p, tmp, C0_INDEX); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1582 | i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */ |
| 1583 | il_bltz(p, r, tmp, label_r3000_write_probe_fail); /* cp0 delay */ |
| 1584 | i_mfc0(p, tmp, C0_EPC); /* branch delay */ |
| 1585 | i_tlbwi(p); /* cp0 delay */ |
| 1586 | i_jr(p, tmp); |
| 1587 | i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | l_r3000_write_probe_fail(l, *p); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1589 | i_tlbwr(p); /* cp0 delay */ |
| 1590 | i_jr(p, tmp); |
| 1591 | i_rfe(p); /* branch delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static void __init |
| 1595 | build_r3000_tlbchange_handler_head(u32 **p, unsigned int pte, |
| 1596 | unsigned int ptr) |
| 1597 | { |
| 1598 | long pgdc = (long)pgd_current; |
| 1599 | |
| 1600 | i_mfc0(p, pte, C0_BADVADDR); |
| 1601 | i_lui(p, ptr, rel_hi(pgdc)); /* cp0 delay */ |
| 1602 | i_lw(p, ptr, rel_lo(pgdc), ptr); |
| 1603 | i_srl(p, pte, pte, 22); /* load delay */ |
| 1604 | i_sll(p, pte, pte, 2); |
| 1605 | i_addu(p, ptr, ptr, pte); |
| 1606 | i_mfc0(p, pte, C0_CONTEXT); |
| 1607 | i_lw(p, ptr, 0, ptr); /* cp0 delay */ |
| 1608 | i_andi(p, pte, pte, 0xffc); /* load delay */ |
| 1609 | i_addu(p, ptr, ptr, pte); |
| 1610 | i_lw(p, pte, 0, ptr); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1611 | i_tlbp(p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | static void __init build_r3000_tlb_load_handler(void) |
| 1615 | { |
| 1616 | u32 *p = handle_tlbl; |
| 1617 | struct label *l = labels; |
| 1618 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1619 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
| 1621 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1622 | memset(labels, 0, sizeof(labels)); |
| 1623 | memset(relocs, 0, sizeof(relocs)); |
| 1624 | |
| 1625 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1626 | build_pte_present(&p, &l, &r, K0, K1, label_nopage_tlbl); |
Maciej W. Rozycki | d925c26 | 2005-06-13 20:12:01 +0000 | [diff] [blame] | 1627 | i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | build_make_valid(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1629 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
| 1631 | l_nopage_tlbl(&l, p); |
| 1632 | i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1633 | i_nop(&p); |
| 1634 | |
| 1635 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1636 | panic("TLB load handler fastpath space exceeded"); |
| 1637 | |
| 1638 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1639 | pr_info("Synthesized TLB load handler fastpath (%u instructions).\n", |
| 1640 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1642 | pr_debug("\t.set push\n"); |
| 1643 | pr_debug("\t.set noreorder\n"); |
| 1644 | for (i = 0; i < (p - handle_tlbl); i++) |
| 1645 | pr_debug("\t.word 0x%08x\n", handle_tlbl[i]); |
| 1646 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | static void __init build_r3000_tlb_store_handler(void) |
| 1650 | { |
| 1651 | u32 *p = handle_tlbs; |
| 1652 | struct label *l = labels; |
| 1653 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1654 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
| 1656 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1657 | memset(labels, 0, sizeof(labels)); |
| 1658 | memset(relocs, 0, sizeof(relocs)); |
| 1659 | |
| 1660 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1661 | build_pte_writable(&p, &l, &r, K0, K1, label_nopage_tlbs); |
Maciej W. Rozycki | d925c26 | 2005-06-13 20:12:01 +0000 | [diff] [blame] | 1662 | i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1664 | build_r3000_tlb_reload_write(&p, &l, &r, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
| 1666 | l_nopage_tlbs(&l, p); |
| 1667 | i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1668 | i_nop(&p); |
| 1669 | |
| 1670 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1671 | panic("TLB store handler fastpath space exceeded"); |
| 1672 | |
| 1673 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1674 | pr_info("Synthesized TLB store handler fastpath (%u instructions).\n", |
| 1675 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1677 | pr_debug("\t.set push\n"); |
| 1678 | pr_debug("\t.set noreorder\n"); |
| 1679 | for (i = 0; i < (p - handle_tlbs); i++) |
| 1680 | pr_debug("\t.word 0x%08x\n", handle_tlbs[i]); |
| 1681 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | static void __init build_r3000_tlb_modify_handler(void) |
| 1685 | { |
| 1686 | u32 *p = handle_tlbm; |
| 1687 | struct label *l = labels; |
| 1688 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1689 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
| 1691 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1692 | memset(labels, 0, sizeof(labels)); |
| 1693 | memset(relocs, 0, sizeof(relocs)); |
| 1694 | |
| 1695 | build_r3000_tlbchange_handler_head(&p, K0, K1); |
| 1696 | build_pte_modifiable(&p, &l, &r, K0, K1, label_nopage_tlbm); |
Maciej W. Rozycki | d925c26 | 2005-06-13 20:12:01 +0000 | [diff] [blame] | 1697 | i_nop(&p); /* load delay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | build_make_write(&p, &r, K0, K1); |
Maciej W. Rozycki | fded2e5 | 2005-06-13 20:24:00 +0000 | [diff] [blame] | 1699 | build_r3000_pte_reload_tlbwi(&p, K0, K1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
| 1701 | l_nopage_tlbm(&l, p); |
| 1702 | i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1703 | i_nop(&p); |
| 1704 | |
| 1705 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1706 | panic("TLB modify handler fastpath space exceeded"); |
| 1707 | |
| 1708 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1709 | pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n", |
| 1710 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1712 | pr_debug("\t.set push\n"); |
| 1713 | pr_debug("\t.set noreorder\n"); |
| 1714 | for (i = 0; i < (p - handle_tlbm); i++) |
| 1715 | pr_debug("\t.word 0x%08x\n", handle_tlbm[i]); |
| 1716 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | /* |
| 1720 | * R4000 style TLB load/store/modify handlers. |
| 1721 | */ |
| 1722 | static void __init |
| 1723 | build_r4000_tlbchange_handler_head(u32 **p, struct label **l, |
| 1724 | struct reloc **r, unsigned int pte, |
| 1725 | unsigned int ptr) |
| 1726 | { |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1727 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | build_get_pmde64(p, l, r, pte, ptr); /* get pmd in ptr */ |
| 1729 | #else |
| 1730 | build_get_pgde32(p, pte, ptr); /* get pgd in ptr */ |
| 1731 | #endif |
| 1732 | |
| 1733 | i_MFC0(p, pte, C0_BADVADDR); |
| 1734 | i_LW(p, ptr, 0, ptr); |
| 1735 | i_SRL(p, pte, pte, PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2); |
| 1736 | i_andi(p, pte, pte, (PTRS_PER_PTE - 1) << PTE_T_LOG2); |
| 1737 | i_ADDU(p, ptr, ptr, pte); |
| 1738 | |
| 1739 | #ifdef CONFIG_SMP |
| 1740 | l_smp_pgtable_change(l, *p); |
| 1741 | # endif |
Thiemo Seufer | 63b2d2f | 2005-04-28 08:52:57 +0000 | [diff] [blame] | 1742 | iPTE_LW(p, l, pte, ptr); /* get even pte */ |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1743 | if (!m4kc_tlbp_war()) |
| 1744 | build_tlb_probe_entry(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | static void __init |
| 1748 | build_r4000_tlbchange_handler_tail(u32 **p, struct label **l, |
| 1749 | struct reloc **r, unsigned int tmp, |
| 1750 | unsigned int ptr) |
| 1751 | { |
| 1752 | i_ori(p, ptr, ptr, sizeof(pte_t)); |
| 1753 | i_xori(p, ptr, ptr, sizeof(pte_t)); |
| 1754 | build_update_entries(p, tmp, ptr); |
| 1755 | build_tlb_write_entry(p, l, r, tlb_indexed); |
| 1756 | l_leave(l, *p); |
| 1757 | i_eret(p); /* return from trap */ |
| 1758 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1759 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | build_get_pgd_vmalloc64(p, l, r, tmp, ptr); |
| 1761 | #endif |
| 1762 | } |
| 1763 | |
| 1764 | static void __init build_r4000_tlb_load_handler(void) |
| 1765 | { |
| 1766 | u32 *p = handle_tlbl; |
| 1767 | struct label *l = labels; |
| 1768 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1769 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
| 1771 | memset(handle_tlbl, 0, sizeof(handle_tlbl)); |
| 1772 | memset(labels, 0, sizeof(labels)); |
| 1773 | memset(relocs, 0, sizeof(relocs)); |
| 1774 | |
| 1775 | if (bcm1250_m3_war()) { |
| 1776 | i_MFC0(&p, K0, C0_BADVADDR); |
| 1777 | i_MFC0(&p, K1, C0_ENTRYHI); |
| 1778 | i_xor(&p, K0, K0, K1); |
| 1779 | i_SRL(&p, K0, K0, PAGE_SHIFT + 1); |
| 1780 | il_bnez(&p, &r, K0, label_leave); |
| 1781 | /* No need for i_nop */ |
| 1782 | } |
| 1783 | |
| 1784 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1785 | build_pte_present(&p, &l, &r, K0, K1, label_nopage_tlbl); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1786 | if (m4kc_tlbp_war()) |
| 1787 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | build_make_valid(&p, &r, K0, K1); |
| 1789 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1790 | |
| 1791 | l_nopage_tlbl(&l, p); |
| 1792 | i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff); |
| 1793 | i_nop(&p); |
| 1794 | |
| 1795 | if ((p - handle_tlbl) > FASTPATH_SIZE) |
| 1796 | panic("TLB load handler fastpath space exceeded"); |
| 1797 | |
| 1798 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1799 | pr_info("Synthesized TLB load handler fastpath (%u instructions).\n", |
| 1800 | (unsigned int)(p - handle_tlbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1802 | pr_debug("\t.set push\n"); |
| 1803 | pr_debug("\t.set noreorder\n"); |
| 1804 | for (i = 0; i < (p - handle_tlbl); i++) |
| 1805 | pr_debug("\t.word 0x%08x\n", handle_tlbl[i]); |
| 1806 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | static void __init build_r4000_tlb_store_handler(void) |
| 1810 | { |
| 1811 | u32 *p = handle_tlbs; |
| 1812 | struct label *l = labels; |
| 1813 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1814 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
| 1816 | memset(handle_tlbs, 0, sizeof(handle_tlbs)); |
| 1817 | memset(labels, 0, sizeof(labels)); |
| 1818 | memset(relocs, 0, sizeof(relocs)); |
| 1819 | |
| 1820 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1821 | build_pte_writable(&p, &l, &r, K0, K1, label_nopage_tlbs); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1822 | if (m4kc_tlbp_war()) |
| 1823 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | build_make_write(&p, &r, K0, K1); |
| 1825 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1826 | |
| 1827 | l_nopage_tlbs(&l, p); |
| 1828 | i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1829 | i_nop(&p); |
| 1830 | |
| 1831 | if ((p - handle_tlbs) > FASTPATH_SIZE) |
| 1832 | panic("TLB store handler fastpath space exceeded"); |
| 1833 | |
| 1834 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1835 | pr_info("Synthesized TLB store handler fastpath (%u instructions).\n", |
| 1836 | (unsigned int)(p - handle_tlbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1838 | pr_debug("\t.set push\n"); |
| 1839 | pr_debug("\t.set noreorder\n"); |
| 1840 | for (i = 0; i < (p - handle_tlbs); i++) |
| 1841 | pr_debug("\t.word 0x%08x\n", handle_tlbs[i]); |
| 1842 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | static void __init build_r4000_tlb_modify_handler(void) |
| 1846 | { |
| 1847 | u32 *p = handle_tlbm; |
| 1848 | struct label *l = labels; |
| 1849 | struct reloc *r = relocs; |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1850 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | |
| 1852 | memset(handle_tlbm, 0, sizeof(handle_tlbm)); |
| 1853 | memset(labels, 0, sizeof(labels)); |
| 1854 | memset(relocs, 0, sizeof(relocs)); |
| 1855 | |
| 1856 | build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1); |
| 1857 | build_pte_modifiable(&p, &l, &r, K0, K1, label_nopage_tlbm); |
Maciej W. Rozycki | 8df5bea | 2006-08-23 14:26:50 +0100 | [diff] [blame] | 1858 | if (m4kc_tlbp_war()) |
| 1859 | build_tlb_probe_entry(&p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | /* Present and writable bits set, set accessed and dirty bits. */ |
| 1861 | build_make_write(&p, &r, K0, K1); |
| 1862 | build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1); |
| 1863 | |
| 1864 | l_nopage_tlbm(&l, p); |
| 1865 | i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff); |
| 1866 | i_nop(&p); |
| 1867 | |
| 1868 | if ((p - handle_tlbm) > FASTPATH_SIZE) |
| 1869 | panic("TLB modify handler fastpath space exceeded"); |
| 1870 | |
| 1871 | resolve_relocs(relocs, labels); |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1872 | pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n", |
| 1873 | (unsigned int)(p - handle_tlbm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
Thiemo Seufer | 115f2a4 | 2006-07-09 01:47:06 +0100 | [diff] [blame] | 1875 | pr_debug("\t.set push\n"); |
| 1876 | pr_debug("\t.set noreorder\n"); |
| 1877 | for (i = 0; i < (p - handle_tlbm); i++) |
| 1878 | pr_debug("\t.word 0x%08x\n", handle_tlbm[i]); |
| 1879 | pr_debug("\t.set pop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | void __init build_tlb_refill_handler(void) |
| 1883 | { |
| 1884 | /* |
| 1885 | * The refill handler is generated per-CPU, multi-node systems |
| 1886 | * may have local storage for it. The other handlers are only |
| 1887 | * needed once. |
| 1888 | */ |
| 1889 | static int run_once = 0; |
| 1890 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1891 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | case CPU_R2000: |
| 1893 | case CPU_R3000: |
| 1894 | case CPU_R3000A: |
| 1895 | case CPU_R3081E: |
| 1896 | case CPU_TX3912: |
| 1897 | case CPU_TX3922: |
| 1898 | case CPU_TX3927: |
| 1899 | build_r3000_tlb_refill_handler(); |
| 1900 | if (!run_once) { |
| 1901 | build_r3000_tlb_load_handler(); |
| 1902 | build_r3000_tlb_store_handler(); |
| 1903 | build_r3000_tlb_modify_handler(); |
| 1904 | run_once++; |
| 1905 | } |
| 1906 | break; |
| 1907 | |
| 1908 | case CPU_R6000: |
| 1909 | case CPU_R6000A: |
| 1910 | panic("No R6000 TLB refill handler yet"); |
| 1911 | break; |
| 1912 | |
| 1913 | case CPU_R8000: |
| 1914 | panic("No R8000 TLB refill handler yet"); |
| 1915 | break; |
| 1916 | |
| 1917 | default: |
| 1918 | build_r4000_tlb_refill_handler(); |
| 1919 | if (!run_once) { |
| 1920 | build_r4000_tlb_load_handler(); |
| 1921 | build_r4000_tlb_store_handler(); |
| 1922 | build_r4000_tlb_modify_handler(); |
| 1923 | run_once++; |
| 1924 | } |
| 1925 | } |
| 1926 | } |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1927 | |
| 1928 | void __init flush_tlb_handlers(void) |
| 1929 | { |
| 1930 | flush_icache_range((unsigned long)handle_tlbl, |
| 1931 | (unsigned long)handle_tlbl + sizeof(handle_tlbl)); |
| 1932 | flush_icache_range((unsigned long)handle_tlbs, |
| 1933 | (unsigned long)handle_tlbs + sizeof(handle_tlbs)); |
| 1934 | flush_icache_range((unsigned long)handle_tlbm, |
| 1935 | (unsigned long)handle_tlbm + sizeof(handle_tlbm)); |
| 1936 | } |