tlbex.c 44 KB

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