tlbex.c 44 KB

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