tlbex.c 58 KB

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