tlbex.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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. case CPU_JZRISC:
  367. tlbw(p);
  368. uasm_i_nop(p);
  369. break;
  370. default:
  371. panic("No TLB refill handler yet (CPU type: %d)",
  372. current_cpu_data.cputype);
  373. break;
  374. }
  375. }
  376. static __cpuinit __maybe_unused void build_convert_pte_to_entrylo(u32 **p,
  377. unsigned int reg)
  378. {
  379. if (kernel_uses_smartmips_rixi) {
  380. UASM_i_SRL(p, reg, reg, ilog2(_PAGE_NO_EXEC));
  381. UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
  382. } else {
  383. #ifdef CONFIG_64BIT_PHYS_ADDR
  384. uasm_i_dsrl_safe(p, reg, reg, ilog2(_PAGE_GLOBAL));
  385. #else
  386. UASM_i_SRL(p, reg, reg, ilog2(_PAGE_GLOBAL));
  387. #endif
  388. }
  389. }
  390. #ifdef CONFIG_HUGETLB_PAGE
  391. static __cpuinit void build_restore_pagemask(u32 **p,
  392. struct uasm_reloc **r,
  393. unsigned int tmp,
  394. enum label_id lid)
  395. {
  396. /* Reset default page size */
  397. if (PM_DEFAULT_MASK >> 16) {
  398. uasm_i_lui(p, tmp, PM_DEFAULT_MASK >> 16);
  399. uasm_i_ori(p, tmp, tmp, PM_DEFAULT_MASK & 0xffff);
  400. uasm_il_b(p, r, lid);
  401. uasm_i_mtc0(p, tmp, C0_PAGEMASK);
  402. } else if (PM_DEFAULT_MASK) {
  403. uasm_i_ori(p, tmp, 0, PM_DEFAULT_MASK);
  404. uasm_il_b(p, r, lid);
  405. uasm_i_mtc0(p, tmp, C0_PAGEMASK);
  406. } else {
  407. uasm_il_b(p, r, lid);
  408. uasm_i_mtc0(p, 0, C0_PAGEMASK);
  409. }
  410. }
  411. static __cpuinit void build_huge_tlb_write_entry(u32 **p,
  412. struct uasm_label **l,
  413. struct uasm_reloc **r,
  414. unsigned int tmp,
  415. enum tlb_write_entry wmode)
  416. {
  417. /* Set huge page tlb entry size */
  418. uasm_i_lui(p, tmp, PM_HUGE_MASK >> 16);
  419. uasm_i_ori(p, tmp, tmp, PM_HUGE_MASK & 0xffff);
  420. uasm_i_mtc0(p, tmp, C0_PAGEMASK);
  421. build_tlb_write_entry(p, l, r, wmode);
  422. build_restore_pagemask(p, r, tmp, label_leave);
  423. }
  424. /*
  425. * Check if Huge PTE is present, if so then jump to LABEL.
  426. */
  427. static void __cpuinit
  428. build_is_huge_pte(u32 **p, struct uasm_reloc **r, unsigned int tmp,
  429. unsigned int pmd, int lid)
  430. {
  431. UASM_i_LW(p, tmp, 0, pmd);
  432. uasm_i_andi(p, tmp, tmp, _PAGE_HUGE);
  433. uasm_il_bnez(p, r, tmp, lid);
  434. }
  435. static __cpuinit void build_huge_update_entries(u32 **p,
  436. unsigned int pte,
  437. unsigned int tmp)
  438. {
  439. int small_sequence;
  440. /*
  441. * A huge PTE describes an area the size of the
  442. * configured huge page size. This is twice the
  443. * of the large TLB entry size we intend to use.
  444. * A TLB entry half the size of the configured
  445. * huge page size is configured into entrylo0
  446. * and entrylo1 to cover the contiguous huge PTE
  447. * address space.
  448. */
  449. small_sequence = (HPAGE_SIZE >> 7) < 0x10000;
  450. /* We can clobber tmp. It isn't used after this.*/
  451. if (!small_sequence)
  452. uasm_i_lui(p, tmp, HPAGE_SIZE >> (7 + 16));
  453. build_convert_pte_to_entrylo(p, pte);
  454. UASM_i_MTC0(p, pte, C0_ENTRYLO0); /* load it */
  455. /* convert to entrylo1 */
  456. if (small_sequence)
  457. UASM_i_ADDIU(p, pte, pte, HPAGE_SIZE >> 7);
  458. else
  459. UASM_i_ADDU(p, pte, pte, tmp);
  460. UASM_i_MTC0(p, pte, C0_ENTRYLO1); /* load it */
  461. }
  462. static __cpuinit void build_huge_handler_tail(u32 **p,
  463. struct uasm_reloc **r,
  464. struct uasm_label **l,
  465. unsigned int pte,
  466. unsigned int ptr)
  467. {
  468. #ifdef CONFIG_SMP
  469. UASM_i_SC(p, pte, 0, ptr);
  470. uasm_il_beqz(p, r, pte, label_tlb_huge_update);
  471. UASM_i_LW(p, pte, 0, ptr); /* Needed because SC killed our PTE */
  472. #else
  473. UASM_i_SW(p, pte, 0, ptr);
  474. #endif
  475. build_huge_update_entries(p, pte, ptr);
  476. build_huge_tlb_write_entry(p, l, r, pte, tlb_indexed);
  477. }
  478. #endif /* CONFIG_HUGETLB_PAGE */
  479. #ifdef CONFIG_64BIT
  480. /*
  481. * TMP and PTR are scratch.
  482. * TMP will be clobbered, PTR will hold the pmd entry.
  483. */
  484. static void __cpuinit
  485. build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
  486. unsigned int tmp, unsigned int ptr)
  487. {
  488. #ifndef CONFIG_MIPS_PGD_C0_CONTEXT
  489. long pgdc = (long)pgd_current;
  490. #endif
  491. /*
  492. * The vmalloc handling is not in the hotpath.
  493. */
  494. uasm_i_dmfc0(p, tmp, C0_BADVADDR);
  495. if (check_for_high_segbits) {
  496. /*
  497. * The kernel currently implicitely assumes that the
  498. * MIPS SEGBITS parameter for the processor is
  499. * (PGDIR_SHIFT+PGDIR_BITS) or less, and will never
  500. * allocate virtual addresses outside the maximum
  501. * range for SEGBITS = (PGDIR_SHIFT+PGDIR_BITS). But
  502. * that doesn't prevent user code from accessing the
  503. * higher xuseg addresses. Here, we make sure that
  504. * everything but the lower xuseg addresses goes down
  505. * the module_alloc/vmalloc path.
  506. */
  507. uasm_i_dsrl_safe(p, ptr, tmp, PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3);
  508. uasm_il_bnez(p, r, ptr, label_vmalloc);
  509. } else {
  510. uasm_il_bltz(p, r, tmp, label_vmalloc);
  511. }
  512. /* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */
  513. #ifdef CONFIG_MIPS_PGD_C0_CONTEXT
  514. /*
  515. * &pgd << 11 stored in CONTEXT [23..63].
  516. */
  517. UASM_i_MFC0(p, ptr, C0_CONTEXT);
  518. uasm_i_dins(p, ptr, 0, 0, 23); /* Clear lower 23 bits of context. */
  519. uasm_i_ori(p, ptr, ptr, 0x540); /* 1 0 1 0 1 << 6 xkphys cached */
  520. uasm_i_drotr(p, ptr, ptr, 11);
  521. #elif defined(CONFIG_SMP)
  522. # ifdef CONFIG_MIPS_MT_SMTC
  523. /*
  524. * SMTC uses TCBind value as "CPU" index
  525. */
  526. uasm_i_mfc0(p, ptr, C0_TCBIND);
  527. uasm_i_dsrl_safe(p, ptr, ptr, 19);
  528. # else
  529. /*
  530. * 64 bit SMP running in XKPHYS has smp_processor_id() << 3
  531. * stored in CONTEXT.
  532. */
  533. uasm_i_dmfc0(p, ptr, C0_CONTEXT);
  534. uasm_i_dsrl_safe(p, ptr, ptr, 23);
  535. # endif
  536. UASM_i_LA_mostly(p, tmp, pgdc);
  537. uasm_i_daddu(p, ptr, ptr, tmp);
  538. uasm_i_dmfc0(p, tmp, C0_BADVADDR);
  539. uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr);
  540. #else
  541. UASM_i_LA_mostly(p, ptr, pgdc);
  542. uasm_i_ld(p, ptr, uasm_rel_lo(pgdc), ptr);
  543. #endif
  544. uasm_l_vmalloc_done(l, *p);
  545. /* get pgd offset in bytes */
  546. uasm_i_dsrl_safe(p, tmp, tmp, PGDIR_SHIFT - 3);
  547. uasm_i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3);
  548. uasm_i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */
  549. #ifndef __PAGETABLE_PMD_FOLDED
  550. uasm_i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */
  551. uasm_i_ld(p, ptr, 0, ptr); /* get pmd pointer */
  552. uasm_i_dsrl_safe(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */
  553. uasm_i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3);
  554. uasm_i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */
  555. #endif
  556. }
  557. enum vmalloc64_mode {not_refill, refill};
  558. /*
  559. * BVADDR is the faulting address, PTR is scratch.
  560. * PTR will hold the pgd for vmalloc.
  561. */
  562. static void __cpuinit
  563. build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
  564. unsigned int bvaddr, unsigned int ptr,
  565. enum vmalloc64_mode mode)
  566. {
  567. long swpd = (long)swapper_pg_dir;
  568. int single_insn_swpd;
  569. int did_vmalloc_branch = 0;
  570. single_insn_swpd = uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd);
  571. uasm_l_vmalloc(l, *p);
  572. if (mode == refill && check_for_high_segbits) {
  573. if (single_insn_swpd) {
  574. uasm_il_bltz(p, r, bvaddr, label_vmalloc_done);
  575. uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
  576. did_vmalloc_branch = 1;
  577. /* fall through */
  578. } else {
  579. uasm_il_bgez(p, r, bvaddr, label_large_segbits_fault);
  580. }
  581. }
  582. if (!did_vmalloc_branch) {
  583. if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) {
  584. uasm_il_b(p, r, label_vmalloc_done);
  585. uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
  586. } else {
  587. UASM_i_LA_mostly(p, ptr, swpd);
  588. uasm_il_b(p, r, label_vmalloc_done);
  589. if (uasm_in_compat_space_p(swpd))
  590. uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd));
  591. else
  592. uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd));
  593. }
  594. }
  595. if (mode == refill && check_for_high_segbits) {
  596. uasm_l_large_segbits_fault(l, *p);
  597. /*
  598. * We get here if we are an xsseg address, or if we are
  599. * an xuseg address above (PGDIR_SHIFT+PGDIR_BITS) boundary.
  600. *
  601. * Ignoring xsseg (assume disabled so would generate
  602. * (address errors?), the only remaining possibility
  603. * is the upper xuseg addresses. On processors with
  604. * TLB_SEGBITS <= PGDIR_SHIFT+PGDIR_BITS, these
  605. * addresses would have taken an address error. We try
  606. * to mimic that here by taking a load/istream page
  607. * fault.
  608. */
  609. UASM_i_LA(p, ptr, (unsigned long)tlb_do_page_fault_0);
  610. uasm_i_jr(p, ptr);
  611. uasm_i_nop(p);
  612. }
  613. }
  614. #else /* !CONFIG_64BIT */
  615. /*
  616. * TMP and PTR are scratch.
  617. * TMP will be clobbered, PTR will hold the pgd entry.
  618. */
  619. static void __cpuinit __maybe_unused
  620. build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr)
  621. {
  622. long pgdc = (long)pgd_current;
  623. /* 32 bit SMP has smp_processor_id() stored in CONTEXT. */
  624. #ifdef CONFIG_SMP
  625. #ifdef CONFIG_MIPS_MT_SMTC
  626. /*
  627. * SMTC uses TCBind value as "CPU" index
  628. */
  629. uasm_i_mfc0(p, ptr, C0_TCBIND);
  630. UASM_i_LA_mostly(p, tmp, pgdc);
  631. uasm_i_srl(p, ptr, ptr, 19);
  632. #else
  633. /*
  634. * smp_processor_id() << 3 is stored in CONTEXT.
  635. */
  636. uasm_i_mfc0(p, ptr, C0_CONTEXT);
  637. UASM_i_LA_mostly(p, tmp, pgdc);
  638. uasm_i_srl(p, ptr, ptr, 23);
  639. #endif
  640. uasm_i_addu(p, ptr, tmp, ptr);
  641. #else
  642. UASM_i_LA_mostly(p, ptr, pgdc);
  643. #endif
  644. uasm_i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */
  645. uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr);
  646. uasm_i_srl(p, tmp, tmp, PGDIR_SHIFT); /* get pgd only bits */
  647. uasm_i_sll(p, tmp, tmp, PGD_T_LOG2);
  648. uasm_i_addu(p, ptr, ptr, tmp); /* add in pgd offset */
  649. }
  650. #endif /* !CONFIG_64BIT */
  651. static void __cpuinit build_adjust_context(u32 **p, unsigned int ctx)
  652. {
  653. unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12;
  654. unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1);
  655. switch (current_cpu_type()) {
  656. case CPU_VR41XX:
  657. case CPU_VR4111:
  658. case CPU_VR4121:
  659. case CPU_VR4122:
  660. case CPU_VR4131:
  661. case CPU_VR4181:
  662. case CPU_VR4181A:
  663. case CPU_VR4133:
  664. shift += 2;
  665. break;
  666. default:
  667. break;
  668. }
  669. if (shift)
  670. UASM_i_SRL(p, ctx, ctx, shift);
  671. uasm_i_andi(p, ctx, ctx, mask);
  672. }
  673. static void __cpuinit build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr)
  674. {
  675. /*
  676. * Bug workaround for the Nevada. It seems as if under certain
  677. * circumstances the move from cp0_context might produce a
  678. * bogus result when the mfc0 instruction and its consumer are
  679. * in a different cacheline or a load instruction, probably any
  680. * memory reference, is between them.
  681. */
  682. switch (current_cpu_type()) {
  683. case CPU_NEVADA:
  684. UASM_i_LW(p, ptr, 0, ptr);
  685. GET_CONTEXT(p, tmp); /* get context reg */
  686. break;
  687. default:
  688. GET_CONTEXT(p, tmp); /* get context reg */
  689. UASM_i_LW(p, ptr, 0, ptr);
  690. break;
  691. }
  692. build_adjust_context(p, tmp);
  693. UASM_i_ADDU(p, ptr, ptr, tmp); /* add in offset */
  694. }
  695. static void __cpuinit build_update_entries(u32 **p, unsigned int tmp,
  696. unsigned int ptep)
  697. {
  698. /*
  699. * 64bit address support (36bit on a 32bit CPU) in a 32bit
  700. * Kernel is a special case. Only a few CPUs use it.
  701. */
  702. #ifdef CONFIG_64BIT_PHYS_ADDR
  703. if (cpu_has_64bits) {
  704. uasm_i_ld(p, tmp, 0, ptep); /* get even pte */
  705. uasm_i_ld(p, ptep, sizeof(pte_t), ptep); /* get odd pte */
  706. if (kernel_uses_smartmips_rixi) {
  707. UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_NO_EXEC));
  708. UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_NO_EXEC));
  709. UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
  710. UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
  711. UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
  712. } else {
  713. uasm_i_dsrl_safe(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */
  714. UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
  715. uasm_i_dsrl_safe(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */
  716. }
  717. UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */
  718. } else {
  719. int pte_off_even = sizeof(pte_t) / 2;
  720. int pte_off_odd = pte_off_even + sizeof(pte_t);
  721. /* The pte entries are pre-shifted */
  722. uasm_i_lw(p, tmp, pte_off_even, ptep); /* get even pte */
  723. UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
  724. uasm_i_lw(p, ptep, pte_off_odd, ptep); /* get odd pte */
  725. UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */
  726. }
  727. #else
  728. UASM_i_LW(p, tmp, 0, ptep); /* get even pte */
  729. UASM_i_LW(p, ptep, sizeof(pte_t), ptep); /* get odd pte */
  730. if (r45k_bvahwbug())
  731. build_tlb_probe_entry(p);
  732. if (kernel_uses_smartmips_rixi) {
  733. UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_NO_EXEC));
  734. UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_NO_EXEC));
  735. UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
  736. if (r4k_250MHZhwbug())
  737. UASM_i_MTC0(p, 0, C0_ENTRYLO0);
  738. UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
  739. UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
  740. } else {
  741. UASM_i_SRL(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */
  742. if (r4k_250MHZhwbug())
  743. UASM_i_MTC0(p, 0, C0_ENTRYLO0);
  744. UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
  745. UASM_i_SRL(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */
  746. if (r45k_bvahwbug())
  747. uasm_i_mfc0(p, tmp, C0_INDEX);
  748. }
  749. if (r4k_250MHZhwbug())
  750. UASM_i_MTC0(p, 0, C0_ENTRYLO1);
  751. UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */
  752. #endif
  753. }
  754. /*
  755. * For a 64-bit kernel, we are using the 64-bit XTLB refill exception
  756. * because EXL == 0. If we wrap, we can also use the 32 instruction
  757. * slots before the XTLB refill exception handler which belong to the
  758. * unused TLB refill exception.
  759. */
  760. #define MIPS64_REFILL_INSNS 32
  761. static void __cpuinit build_r4000_tlb_refill_handler(void)
  762. {
  763. u32 *p = tlb_handler;
  764. struct uasm_label *l = labels;
  765. struct uasm_reloc *r = relocs;
  766. u32 *f;
  767. unsigned int final_len;
  768. memset(tlb_handler, 0, sizeof(tlb_handler));
  769. memset(labels, 0, sizeof(labels));
  770. memset(relocs, 0, sizeof(relocs));
  771. memset(final_handler, 0, sizeof(final_handler));
  772. /*
  773. * create the plain linear handler
  774. */
  775. if (bcm1250_m3_war()) {
  776. unsigned int segbits = 44;
  777. uasm_i_dmfc0(&p, K0, C0_BADVADDR);
  778. uasm_i_dmfc0(&p, K1, C0_ENTRYHI);
  779. uasm_i_xor(&p, K0, K0, K1);
  780. uasm_i_dsrl_safe(&p, K1, K0, 62);
  781. uasm_i_dsrl_safe(&p, K0, K0, 12 + 1);
  782. uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits);
  783. uasm_i_or(&p, K0, K0, K1);
  784. uasm_il_bnez(&p, &r, K0, label_leave);
  785. /* No need for uasm_i_nop */
  786. }
  787. #ifdef CONFIG_64BIT
  788. build_get_pmde64(&p, &l, &r, K0, K1); /* get pmd in K1 */
  789. #else
  790. build_get_pgde32(&p, K0, K1); /* get pgd in K1 */
  791. #endif
  792. #ifdef CONFIG_HUGETLB_PAGE
  793. build_is_huge_pte(&p, &r, K0, K1, label_tlb_huge_update);
  794. #endif
  795. build_get_ptep(&p, K0, K1);
  796. build_update_entries(&p, K0, K1);
  797. build_tlb_write_entry(&p, &l, &r, tlb_random);
  798. uasm_l_leave(&l, p);
  799. uasm_i_eret(&p); /* return from trap */
  800. #ifdef CONFIG_HUGETLB_PAGE
  801. uasm_l_tlb_huge_update(&l, p);
  802. UASM_i_LW(&p, K0, 0, K1);
  803. build_huge_update_entries(&p, K0, K1);
  804. build_huge_tlb_write_entry(&p, &l, &r, K0, tlb_random);
  805. #endif
  806. #ifdef CONFIG_64BIT
  807. build_get_pgd_vmalloc64(&p, &l, &r, K0, K1, refill);
  808. #endif
  809. /*
  810. * Overflow check: For the 64bit handler, we need at least one
  811. * free instruction slot for the wrap-around branch. In worst
  812. * case, if the intended insertion point is a delay slot, we
  813. * need three, with the second nop'ed and the third being
  814. * unused.
  815. */
  816. /* Loongson2 ebase is different than r4k, we have more space */
  817. #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2)
  818. if ((p - tlb_handler) > 64)
  819. panic("TLB refill handler space exceeded");
  820. #else
  821. if (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 1)
  822. || (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 3)
  823. && uasm_insn_has_bdelay(relocs,
  824. tlb_handler + MIPS64_REFILL_INSNS - 3)))
  825. panic("TLB refill handler space exceeded");
  826. #endif
  827. /*
  828. * Now fold the handler in the TLB refill handler space.
  829. */
  830. #if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2)
  831. f = final_handler;
  832. /* Simplest case, just copy the handler. */
  833. uasm_copy_handler(relocs, labels, tlb_handler, p, f);
  834. final_len = p - tlb_handler;
  835. #else /* CONFIG_64BIT */
  836. f = final_handler + MIPS64_REFILL_INSNS;
  837. if ((p - tlb_handler) <= MIPS64_REFILL_INSNS) {
  838. /* Just copy the handler. */
  839. uasm_copy_handler(relocs, labels, tlb_handler, p, f);
  840. final_len = p - tlb_handler;
  841. } else {
  842. #if defined(CONFIG_HUGETLB_PAGE)
  843. const enum label_id ls = label_tlb_huge_update;
  844. #else
  845. const enum label_id ls = label_vmalloc;
  846. #endif
  847. u32 *split;
  848. int ov = 0;
  849. int i;
  850. for (i = 0; i < ARRAY_SIZE(labels) && labels[i].lab != ls; i++)
  851. ;
  852. BUG_ON(i == ARRAY_SIZE(labels));
  853. split = labels[i].addr;
  854. /*
  855. * See if we have overflown one way or the other.
  856. */
  857. if (split > tlb_handler + MIPS64_REFILL_INSNS ||
  858. split < p - MIPS64_REFILL_INSNS)
  859. ov = 1;
  860. if (ov) {
  861. /*
  862. * Split two instructions before the end. One
  863. * for the branch and one for the instruction
  864. * in the delay slot.
  865. */
  866. split = tlb_handler + MIPS64_REFILL_INSNS - 2;
  867. /*
  868. * If the branch would fall in a delay slot,
  869. * we must back up an additional instruction
  870. * so that it is no longer in a delay slot.
  871. */
  872. if (uasm_insn_has_bdelay(relocs, split - 1))
  873. split--;
  874. }
  875. /* Copy first part of the handler. */
  876. uasm_copy_handler(relocs, labels, tlb_handler, split, f);
  877. f += split - tlb_handler;
  878. if (ov) {
  879. /* Insert branch. */
  880. uasm_l_split(&l, final_handler);
  881. uasm_il_b(&f, &r, label_split);
  882. if (uasm_insn_has_bdelay(relocs, split))
  883. uasm_i_nop(&f);
  884. else {
  885. uasm_copy_handler(relocs, labels,
  886. split, split + 1, f);
  887. uasm_move_labels(labels, f, f + 1, -1);
  888. f++;
  889. split++;
  890. }
  891. }
  892. /* Copy the rest of the handler. */
  893. uasm_copy_handler(relocs, labels, split, p, final_handler);
  894. final_len = (f - (final_handler + MIPS64_REFILL_INSNS)) +
  895. (p - split);
  896. }
  897. #endif /* CONFIG_64BIT */
  898. uasm_resolve_relocs(relocs, labels);
  899. pr_debug("Wrote TLB refill handler (%u instructions).\n",
  900. final_len);
  901. memcpy((void *)ebase, final_handler, 0x100);
  902. dump_handler((u32 *)ebase, 64);
  903. }
  904. /*
  905. * 128 instructions for the fastpath handler is generous and should
  906. * never be exceeded.
  907. */
  908. #define FASTPATH_SIZE 128
  909. u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned;
  910. u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned;
  911. u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned;
  912. static void __cpuinit
  913. iPTE_LW(u32 **p, unsigned int pte, unsigned int ptr)
  914. {
  915. #ifdef CONFIG_SMP
  916. # ifdef CONFIG_64BIT_PHYS_ADDR
  917. if (cpu_has_64bits)
  918. uasm_i_lld(p, pte, 0, ptr);
  919. else
  920. # endif
  921. UASM_i_LL(p, pte, 0, ptr);
  922. #else
  923. # ifdef CONFIG_64BIT_PHYS_ADDR
  924. if (cpu_has_64bits)
  925. uasm_i_ld(p, pte, 0, ptr);
  926. else
  927. # endif
  928. UASM_i_LW(p, pte, 0, ptr);
  929. #endif
  930. }
  931. static void __cpuinit
  932. iPTE_SW(u32 **p, struct uasm_reloc **r, unsigned int pte, unsigned int ptr,
  933. unsigned int mode)
  934. {
  935. #ifdef CONFIG_64BIT_PHYS_ADDR
  936. unsigned int hwmode = mode & (_PAGE_VALID | _PAGE_DIRTY);
  937. #endif
  938. uasm_i_ori(p, pte, pte, mode);
  939. #ifdef CONFIG_SMP
  940. # ifdef CONFIG_64BIT_PHYS_ADDR
  941. if (cpu_has_64bits)
  942. uasm_i_scd(p, pte, 0, ptr);
  943. else
  944. # endif
  945. UASM_i_SC(p, pte, 0, ptr);
  946. if (r10000_llsc_war())
  947. uasm_il_beqzl(p, r, pte, label_smp_pgtable_change);
  948. else
  949. uasm_il_beqz(p, r, pte, label_smp_pgtable_change);
  950. # ifdef CONFIG_64BIT_PHYS_ADDR
  951. if (!cpu_has_64bits) {
  952. /* no uasm_i_nop needed */
  953. uasm_i_ll(p, pte, sizeof(pte_t) / 2, ptr);
  954. uasm_i_ori(p, pte, pte, hwmode);
  955. uasm_i_sc(p, pte, sizeof(pte_t) / 2, ptr);
  956. uasm_il_beqz(p, r, pte, label_smp_pgtable_change);
  957. /* no uasm_i_nop needed */
  958. uasm_i_lw(p, pte, 0, ptr);
  959. } else
  960. uasm_i_nop(p);
  961. # else
  962. uasm_i_nop(p);
  963. # endif
  964. #else
  965. # ifdef CONFIG_64BIT_PHYS_ADDR
  966. if (cpu_has_64bits)
  967. uasm_i_sd(p, pte, 0, ptr);
  968. else
  969. # endif
  970. UASM_i_SW(p, pte, 0, ptr);
  971. # ifdef CONFIG_64BIT_PHYS_ADDR
  972. if (!cpu_has_64bits) {
  973. uasm_i_lw(p, pte, sizeof(pte_t) / 2, ptr);
  974. uasm_i_ori(p, pte, pte, hwmode);
  975. uasm_i_sw(p, pte, sizeof(pte_t) / 2, ptr);
  976. uasm_i_lw(p, pte, 0, ptr);
  977. }
  978. # endif
  979. #endif
  980. }
  981. /*
  982. * Check if PTE is present, if not then jump to LABEL. PTR points to
  983. * the page table where this PTE is located, PTE will be re-loaded
  984. * with it's original value.
  985. */
  986. static void __cpuinit
  987. build_pte_present(u32 **p, struct uasm_reloc **r,
  988. unsigned int pte, unsigned int ptr, enum label_id lid)
  989. {
  990. if (kernel_uses_smartmips_rixi) {
  991. uasm_i_andi(p, pte, pte, _PAGE_PRESENT);
  992. uasm_il_beqz(p, r, pte, lid);
  993. } else {
  994. uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_READ);
  995. uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_READ);
  996. uasm_il_bnez(p, r, pte, lid);
  997. }
  998. iPTE_LW(p, pte, ptr);
  999. }
  1000. /* Make PTE valid, store result in PTR. */
  1001. static void __cpuinit
  1002. build_make_valid(u32 **p, struct uasm_reloc **r, unsigned int pte,
  1003. unsigned int ptr)
  1004. {
  1005. unsigned int mode = _PAGE_VALID | _PAGE_ACCESSED;
  1006. iPTE_SW(p, r, pte, ptr, mode);
  1007. }
  1008. /*
  1009. * Check if PTE can be written to, if not branch to LABEL. Regardless
  1010. * restore PTE with value from PTR when done.
  1011. */
  1012. static void __cpuinit
  1013. build_pte_writable(u32 **p, struct uasm_reloc **r,
  1014. unsigned int pte, unsigned int ptr, enum label_id lid)
  1015. {
  1016. uasm_i_andi(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE);
  1017. uasm_i_xori(p, pte, pte, _PAGE_PRESENT | _PAGE_WRITE);
  1018. uasm_il_bnez(p, r, pte, lid);
  1019. iPTE_LW(p, pte, ptr);
  1020. }
  1021. /* Make PTE writable, update software status bits as well, then store
  1022. * at PTR.
  1023. */
  1024. static void __cpuinit
  1025. build_make_write(u32 **p, struct uasm_reloc **r, unsigned int pte,
  1026. unsigned int ptr)
  1027. {
  1028. unsigned int mode = (_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID
  1029. | _PAGE_DIRTY);
  1030. iPTE_SW(p, r, pte, ptr, mode);
  1031. }
  1032. /*
  1033. * Check if PTE can be modified, if not branch to LABEL. Regardless
  1034. * restore PTE with value from PTR when done.
  1035. */
  1036. static void __cpuinit
  1037. build_pte_modifiable(u32 **p, struct uasm_reloc **r,
  1038. unsigned int pte, unsigned int ptr, enum label_id lid)
  1039. {
  1040. uasm_i_andi(p, pte, pte, _PAGE_WRITE);
  1041. uasm_il_beqz(p, r, pte, lid);
  1042. iPTE_LW(p, pte, ptr);
  1043. }
  1044. #ifndef CONFIG_MIPS_PGD_C0_CONTEXT
  1045. /*
  1046. * R3000 style TLB load/store/modify handlers.
  1047. */
  1048. /*
  1049. * This places the pte into ENTRYLO0 and writes it with tlbwi.
  1050. * Then it returns.
  1051. */
  1052. static void __cpuinit
  1053. build_r3000_pte_reload_tlbwi(u32 **p, unsigned int pte, unsigned int tmp)
  1054. {
  1055. uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */
  1056. uasm_i_mfc0(p, tmp, C0_EPC); /* cp0 delay */
  1057. uasm_i_tlbwi(p);
  1058. uasm_i_jr(p, tmp);
  1059. uasm_i_rfe(p); /* branch delay */
  1060. }
  1061. /*
  1062. * This places the pte into ENTRYLO0 and writes it with tlbwi
  1063. * or tlbwr as appropriate. This is because the index register
  1064. * may have the probe fail bit set as a result of a trap on a
  1065. * kseg2 access, i.e. without refill. Then it returns.
  1066. */
  1067. static void __cpuinit
  1068. build_r3000_tlb_reload_write(u32 **p, struct uasm_label **l,
  1069. struct uasm_reloc **r, unsigned int pte,
  1070. unsigned int tmp)
  1071. {
  1072. uasm_i_mfc0(p, tmp, C0_INDEX);
  1073. uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */
  1074. uasm_il_bltz(p, r, tmp, label_r3000_write_probe_fail); /* cp0 delay */
  1075. uasm_i_mfc0(p, tmp, C0_EPC); /* branch delay */
  1076. uasm_i_tlbwi(p); /* cp0 delay */
  1077. uasm_i_jr(p, tmp);
  1078. uasm_i_rfe(p); /* branch delay */
  1079. uasm_l_r3000_write_probe_fail(l, *p);
  1080. uasm_i_tlbwr(p); /* cp0 delay */
  1081. uasm_i_jr(p, tmp);
  1082. uasm_i_rfe(p); /* branch delay */
  1083. }
  1084. static void __cpuinit
  1085. build_r3000_tlbchange_handler_head(u32 **p, unsigned int pte,
  1086. unsigned int ptr)
  1087. {
  1088. long pgdc = (long)pgd_current;
  1089. uasm_i_mfc0(p, pte, C0_BADVADDR);
  1090. uasm_i_lui(p, ptr, uasm_rel_hi(pgdc)); /* cp0 delay */
  1091. uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr);
  1092. uasm_i_srl(p, pte, pte, 22); /* load delay */
  1093. uasm_i_sll(p, pte, pte, 2);
  1094. uasm_i_addu(p, ptr, ptr, pte);
  1095. uasm_i_mfc0(p, pte, C0_CONTEXT);
  1096. uasm_i_lw(p, ptr, 0, ptr); /* cp0 delay */
  1097. uasm_i_andi(p, pte, pte, 0xffc); /* load delay */
  1098. uasm_i_addu(p, ptr, ptr, pte);
  1099. uasm_i_lw(p, pte, 0, ptr);
  1100. uasm_i_tlbp(p); /* load delay */
  1101. }
  1102. static void __cpuinit build_r3000_tlb_load_handler(void)
  1103. {
  1104. u32 *p = handle_tlbl;
  1105. struct uasm_label *l = labels;
  1106. struct uasm_reloc *r = relocs;
  1107. memset(handle_tlbl, 0, sizeof(handle_tlbl));
  1108. memset(labels, 0, sizeof(labels));
  1109. memset(relocs, 0, sizeof(relocs));
  1110. build_r3000_tlbchange_handler_head(&p, K0, K1);
  1111. build_pte_present(&p, &r, K0, K1, label_nopage_tlbl);
  1112. uasm_i_nop(&p); /* load delay */
  1113. build_make_valid(&p, &r, K0, K1);
  1114. build_r3000_tlb_reload_write(&p, &l, &r, K0, K1);
  1115. uasm_l_nopage_tlbl(&l, p);
  1116. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff);
  1117. uasm_i_nop(&p);
  1118. if ((p - handle_tlbl) > FASTPATH_SIZE)
  1119. panic("TLB load handler fastpath space exceeded");
  1120. uasm_resolve_relocs(relocs, labels);
  1121. pr_debug("Wrote TLB load handler fastpath (%u instructions).\n",
  1122. (unsigned int)(p - handle_tlbl));
  1123. dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl));
  1124. }
  1125. static void __cpuinit build_r3000_tlb_store_handler(void)
  1126. {
  1127. u32 *p = handle_tlbs;
  1128. struct uasm_label *l = labels;
  1129. struct uasm_reloc *r = relocs;
  1130. memset(handle_tlbs, 0, sizeof(handle_tlbs));
  1131. memset(labels, 0, sizeof(labels));
  1132. memset(relocs, 0, sizeof(relocs));
  1133. build_r3000_tlbchange_handler_head(&p, K0, K1);
  1134. build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs);
  1135. uasm_i_nop(&p); /* load delay */
  1136. build_make_write(&p, &r, K0, K1);
  1137. build_r3000_tlb_reload_write(&p, &l, &r, K0, K1);
  1138. uasm_l_nopage_tlbs(&l, p);
  1139. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
  1140. uasm_i_nop(&p);
  1141. if ((p - handle_tlbs) > FASTPATH_SIZE)
  1142. panic("TLB store handler fastpath space exceeded");
  1143. uasm_resolve_relocs(relocs, labels);
  1144. pr_debug("Wrote TLB store handler fastpath (%u instructions).\n",
  1145. (unsigned int)(p - handle_tlbs));
  1146. dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs));
  1147. }
  1148. static void __cpuinit build_r3000_tlb_modify_handler(void)
  1149. {
  1150. u32 *p = handle_tlbm;
  1151. struct uasm_label *l = labels;
  1152. struct uasm_reloc *r = relocs;
  1153. memset(handle_tlbm, 0, sizeof(handle_tlbm));
  1154. memset(labels, 0, sizeof(labels));
  1155. memset(relocs, 0, sizeof(relocs));
  1156. build_r3000_tlbchange_handler_head(&p, K0, K1);
  1157. build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm);
  1158. uasm_i_nop(&p); /* load delay */
  1159. build_make_write(&p, &r, K0, K1);
  1160. build_r3000_pte_reload_tlbwi(&p, K0, K1);
  1161. uasm_l_nopage_tlbm(&l, p);
  1162. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
  1163. uasm_i_nop(&p);
  1164. if ((p - handle_tlbm) > FASTPATH_SIZE)
  1165. panic("TLB modify handler fastpath space exceeded");
  1166. uasm_resolve_relocs(relocs, labels);
  1167. pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n",
  1168. (unsigned int)(p - handle_tlbm));
  1169. dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm));
  1170. }
  1171. #endif /* CONFIG_MIPS_PGD_C0_CONTEXT */
  1172. /*
  1173. * R4000 style TLB load/store/modify handlers.
  1174. */
  1175. static void __cpuinit
  1176. build_r4000_tlbchange_handler_head(u32 **p, struct uasm_label **l,
  1177. struct uasm_reloc **r, unsigned int pte,
  1178. unsigned int ptr)
  1179. {
  1180. #ifdef CONFIG_64BIT
  1181. build_get_pmde64(p, l, r, pte, ptr); /* get pmd in ptr */
  1182. #else
  1183. build_get_pgde32(p, pte, ptr); /* get pgd in ptr */
  1184. #endif
  1185. #ifdef CONFIG_HUGETLB_PAGE
  1186. /*
  1187. * For huge tlb entries, pmd doesn't contain an address but
  1188. * instead contains the tlb pte. Check the PAGE_HUGE bit and
  1189. * see if we need to jump to huge tlb processing.
  1190. */
  1191. build_is_huge_pte(p, r, pte, ptr, label_tlb_huge_update);
  1192. #endif
  1193. UASM_i_MFC0(p, pte, C0_BADVADDR);
  1194. UASM_i_LW(p, ptr, 0, ptr);
  1195. UASM_i_SRL(p, pte, pte, PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2);
  1196. uasm_i_andi(p, pte, pte, (PTRS_PER_PTE - 1) << PTE_T_LOG2);
  1197. UASM_i_ADDU(p, ptr, ptr, pte);
  1198. #ifdef CONFIG_SMP
  1199. uasm_l_smp_pgtable_change(l, *p);
  1200. #endif
  1201. iPTE_LW(p, pte, ptr); /* get even pte */
  1202. if (!m4kc_tlbp_war())
  1203. build_tlb_probe_entry(p);
  1204. }
  1205. static void __cpuinit
  1206. build_r4000_tlbchange_handler_tail(u32 **p, struct uasm_label **l,
  1207. struct uasm_reloc **r, unsigned int tmp,
  1208. unsigned int ptr)
  1209. {
  1210. uasm_i_ori(p, ptr, ptr, sizeof(pte_t));
  1211. uasm_i_xori(p, ptr, ptr, sizeof(pte_t));
  1212. build_update_entries(p, tmp, ptr);
  1213. build_tlb_write_entry(p, l, r, tlb_indexed);
  1214. uasm_l_leave(l, *p);
  1215. uasm_i_eret(p); /* return from trap */
  1216. #ifdef CONFIG_64BIT
  1217. build_get_pgd_vmalloc64(p, l, r, tmp, ptr, not_refill);
  1218. #endif
  1219. }
  1220. static void __cpuinit build_r4000_tlb_load_handler(void)
  1221. {
  1222. u32 *p = handle_tlbl;
  1223. struct uasm_label *l = labels;
  1224. struct uasm_reloc *r = relocs;
  1225. memset(handle_tlbl, 0, sizeof(handle_tlbl));
  1226. memset(labels, 0, sizeof(labels));
  1227. memset(relocs, 0, sizeof(relocs));
  1228. if (bcm1250_m3_war()) {
  1229. unsigned int segbits = 44;
  1230. uasm_i_dmfc0(&p, K0, C0_BADVADDR);
  1231. uasm_i_dmfc0(&p, K1, C0_ENTRYHI);
  1232. uasm_i_xor(&p, K0, K0, K1);
  1233. uasm_i_dsrl_safe(&p, K1, K0, 62);
  1234. uasm_i_dsrl_safe(&p, K0, K0, 12 + 1);
  1235. uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits);
  1236. uasm_i_or(&p, K0, K0, K1);
  1237. uasm_il_bnez(&p, &r, K0, label_leave);
  1238. /* No need for uasm_i_nop */
  1239. }
  1240. build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1);
  1241. build_pte_present(&p, &r, K0, K1, label_nopage_tlbl);
  1242. if (m4kc_tlbp_war())
  1243. build_tlb_probe_entry(&p);
  1244. if (kernel_uses_smartmips_rixi) {
  1245. /*
  1246. * If the page is not _PAGE_VALID, RI or XI could not
  1247. * have triggered it. Skip the expensive test..
  1248. */
  1249. uasm_i_andi(&p, K0, K0, _PAGE_VALID);
  1250. uasm_il_beqz(&p, &r, K0, label_tlbl_goaround1);
  1251. uasm_i_nop(&p);
  1252. uasm_i_tlbr(&p);
  1253. /* Examine entrylo 0 or 1 based on ptr. */
  1254. uasm_i_andi(&p, K0, K1, sizeof(pte_t));
  1255. uasm_i_beqz(&p, K0, 8);
  1256. UASM_i_MFC0(&p, K0, C0_ENTRYLO0); /* load it in the delay slot*/
  1257. UASM_i_MFC0(&p, K0, C0_ENTRYLO1); /* load it if ptr is odd */
  1258. /*
  1259. * If the entryLo (now in K0) is valid (bit 1), RI or
  1260. * XI must have triggered it.
  1261. */
  1262. uasm_i_andi(&p, K0, K0, 2);
  1263. uasm_il_bnez(&p, &r, K0, label_nopage_tlbl);
  1264. uasm_l_tlbl_goaround1(&l, p);
  1265. /* Reload the PTE value */
  1266. iPTE_LW(&p, K0, K1);
  1267. }
  1268. build_make_valid(&p, &r, K0, K1);
  1269. build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1);
  1270. #ifdef CONFIG_HUGETLB_PAGE
  1271. /*
  1272. * This is the entry point when build_r4000_tlbchange_handler_head
  1273. * spots a huge page.
  1274. */
  1275. uasm_l_tlb_huge_update(&l, p);
  1276. iPTE_LW(&p, K0, K1);
  1277. build_pte_present(&p, &r, K0, K1, label_nopage_tlbl);
  1278. build_tlb_probe_entry(&p);
  1279. if (kernel_uses_smartmips_rixi) {
  1280. /*
  1281. * If the page is not _PAGE_VALID, RI or XI could not
  1282. * have triggered it. Skip the expensive test..
  1283. */
  1284. uasm_i_andi(&p, K0, K0, _PAGE_VALID);
  1285. uasm_il_beqz(&p, &r, K0, label_tlbl_goaround2);
  1286. uasm_i_nop(&p);
  1287. uasm_i_tlbr(&p);
  1288. /* Examine entrylo 0 or 1 based on ptr. */
  1289. uasm_i_andi(&p, K0, K1, sizeof(pte_t));
  1290. uasm_i_beqz(&p, K0, 8);
  1291. UASM_i_MFC0(&p, K0, C0_ENTRYLO0); /* load it in the delay slot*/
  1292. UASM_i_MFC0(&p, K0, C0_ENTRYLO1); /* load it if ptr is odd */
  1293. /*
  1294. * If the entryLo (now in K0) is valid (bit 1), RI or
  1295. * XI must have triggered it.
  1296. */
  1297. uasm_i_andi(&p, K0, K0, 2);
  1298. uasm_il_beqz(&p, &r, K0, label_tlbl_goaround2);
  1299. /* Reload the PTE value */
  1300. iPTE_LW(&p, K0, K1);
  1301. /*
  1302. * We clobbered C0_PAGEMASK, restore it. On the other branch
  1303. * it is restored in build_huge_tlb_write_entry.
  1304. */
  1305. build_restore_pagemask(&p, &r, K0, label_nopage_tlbl);
  1306. uasm_l_tlbl_goaround2(&l, p);
  1307. }
  1308. uasm_i_ori(&p, K0, K0, (_PAGE_ACCESSED | _PAGE_VALID));
  1309. build_huge_handler_tail(&p, &r, &l, K0, K1);
  1310. #endif
  1311. uasm_l_nopage_tlbl(&l, p);
  1312. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff);
  1313. uasm_i_nop(&p);
  1314. if ((p - handle_tlbl) > FASTPATH_SIZE)
  1315. panic("TLB load handler fastpath space exceeded");
  1316. uasm_resolve_relocs(relocs, labels);
  1317. pr_debug("Wrote TLB load handler fastpath (%u instructions).\n",
  1318. (unsigned int)(p - handle_tlbl));
  1319. dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl));
  1320. }
  1321. static void __cpuinit build_r4000_tlb_store_handler(void)
  1322. {
  1323. u32 *p = handle_tlbs;
  1324. struct uasm_label *l = labels;
  1325. struct uasm_reloc *r = relocs;
  1326. memset(handle_tlbs, 0, sizeof(handle_tlbs));
  1327. memset(labels, 0, sizeof(labels));
  1328. memset(relocs, 0, sizeof(relocs));
  1329. build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1);
  1330. build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs);
  1331. if (m4kc_tlbp_war())
  1332. build_tlb_probe_entry(&p);
  1333. build_make_write(&p, &r, K0, K1);
  1334. build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1);
  1335. #ifdef CONFIG_HUGETLB_PAGE
  1336. /*
  1337. * This is the entry point when
  1338. * build_r4000_tlbchange_handler_head spots a huge page.
  1339. */
  1340. uasm_l_tlb_huge_update(&l, p);
  1341. iPTE_LW(&p, K0, K1);
  1342. build_pte_writable(&p, &r, K0, K1, label_nopage_tlbs);
  1343. build_tlb_probe_entry(&p);
  1344. uasm_i_ori(&p, K0, K0,
  1345. _PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY);
  1346. build_huge_handler_tail(&p, &r, &l, K0, K1);
  1347. #endif
  1348. uasm_l_nopage_tlbs(&l, p);
  1349. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
  1350. uasm_i_nop(&p);
  1351. if ((p - handle_tlbs) > FASTPATH_SIZE)
  1352. panic("TLB store handler fastpath space exceeded");
  1353. uasm_resolve_relocs(relocs, labels);
  1354. pr_debug("Wrote TLB store handler fastpath (%u instructions).\n",
  1355. (unsigned int)(p - handle_tlbs));
  1356. dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs));
  1357. }
  1358. static void __cpuinit build_r4000_tlb_modify_handler(void)
  1359. {
  1360. u32 *p = handle_tlbm;
  1361. struct uasm_label *l = labels;
  1362. struct uasm_reloc *r = relocs;
  1363. memset(handle_tlbm, 0, sizeof(handle_tlbm));
  1364. memset(labels, 0, sizeof(labels));
  1365. memset(relocs, 0, sizeof(relocs));
  1366. build_r4000_tlbchange_handler_head(&p, &l, &r, K0, K1);
  1367. build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm);
  1368. if (m4kc_tlbp_war())
  1369. build_tlb_probe_entry(&p);
  1370. /* Present and writable bits set, set accessed and dirty bits. */
  1371. build_make_write(&p, &r, K0, K1);
  1372. build_r4000_tlbchange_handler_tail(&p, &l, &r, K0, K1);
  1373. #ifdef CONFIG_HUGETLB_PAGE
  1374. /*
  1375. * This is the entry point when
  1376. * build_r4000_tlbchange_handler_head spots a huge page.
  1377. */
  1378. uasm_l_tlb_huge_update(&l, p);
  1379. iPTE_LW(&p, K0, K1);
  1380. build_pte_modifiable(&p, &r, K0, K1, label_nopage_tlbm);
  1381. build_tlb_probe_entry(&p);
  1382. uasm_i_ori(&p, K0, K0,
  1383. _PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY);
  1384. build_huge_handler_tail(&p, &r, &l, K0, K1);
  1385. #endif
  1386. uasm_l_nopage_tlbm(&l, p);
  1387. uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
  1388. uasm_i_nop(&p);
  1389. if ((p - handle_tlbm) > FASTPATH_SIZE)
  1390. panic("TLB modify handler fastpath space exceeded");
  1391. uasm_resolve_relocs(relocs, labels);
  1392. pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n",
  1393. (unsigned int)(p - handle_tlbm));
  1394. dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm));
  1395. }
  1396. void __cpuinit build_tlb_refill_handler(void)
  1397. {
  1398. /*
  1399. * The refill handler is generated per-CPU, multi-node systems
  1400. * may have local storage for it. The other handlers are only
  1401. * needed once.
  1402. */
  1403. static int run_once = 0;
  1404. #ifdef CONFIG_64BIT
  1405. check_for_high_segbits = current_cpu_data.vmbits > (PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3);
  1406. #endif
  1407. switch (current_cpu_type()) {
  1408. case CPU_R2000:
  1409. case CPU_R3000:
  1410. case CPU_R3000A:
  1411. case CPU_R3081E:
  1412. case CPU_TX3912:
  1413. case CPU_TX3922:
  1414. case CPU_TX3927:
  1415. #ifndef CONFIG_MIPS_PGD_C0_CONTEXT
  1416. build_r3000_tlb_refill_handler();
  1417. if (!run_once) {
  1418. build_r3000_tlb_load_handler();
  1419. build_r3000_tlb_store_handler();
  1420. build_r3000_tlb_modify_handler();
  1421. run_once++;
  1422. }
  1423. #else
  1424. panic("No R3000 TLB refill handler");
  1425. #endif
  1426. break;
  1427. case CPU_R6000:
  1428. case CPU_R6000A:
  1429. panic("No R6000 TLB refill handler yet");
  1430. break;
  1431. case CPU_R8000:
  1432. panic("No R8000 TLB refill handler yet");
  1433. break;
  1434. default:
  1435. build_r4000_tlb_refill_handler();
  1436. if (!run_once) {
  1437. build_r4000_tlb_load_handler();
  1438. build_r4000_tlb_store_handler();
  1439. build_r4000_tlb_modify_handler();
  1440. run_once++;
  1441. }
  1442. }
  1443. }
  1444. void __cpuinit flush_tlb_handlers(void)
  1445. {
  1446. local_flush_icache_range((unsigned long)handle_tlbl,
  1447. (unsigned long)handle_tlbl + sizeof(handle_tlbl));
  1448. local_flush_icache_range((unsigned long)handle_tlbs,
  1449. (unsigned long)handle_tlbs + sizeof(handle_tlbs));
  1450. local_flush_icache_range((unsigned long)handle_tlbm,
  1451. (unsigned long)handle_tlbm + sizeof(handle_tlbm));
  1452. }