tlbex.c 57 KB

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