tlbex.c 57 KB

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