tlbex.c 57 KB

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