tlb_nohash_low.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*
  2. * This file contains low-level functions for performing various
  3. * types of TLB invalidations on various processors with no hash
  4. * table.
  5. *
  6. * This file implements the following functions for all no-hash
  7. * processors. Some aren't implemented for some variants. Some
  8. * are inline in tlbflush.h
  9. *
  10. * - tlbil_va
  11. * - tlbil_pid
  12. * - tlbil_all
  13. * - tlbivax_bcast
  14. *
  15. * Code mostly moved over from misc_32.S
  16. *
  17. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  18. *
  19. * Partially rewritten by Cort Dougan (cort@cs.nmt.edu)
  20. * Paul Mackerras, Kumar Gala and Benjamin Herrenschmidt.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License
  24. * as published by the Free Software Foundation; either version
  25. * 2 of the License, or (at your option) any later version.
  26. *
  27. */
  28. #include <asm/reg.h>
  29. #include <asm/page.h>
  30. #include <asm/cputable.h>
  31. #include <asm/mmu.h>
  32. #include <asm/ppc_asm.h>
  33. #include <asm/asm-offsets.h>
  34. #include <asm/processor.h>
  35. #include <asm/bug.h>
  36. #include <asm/asm-compat.h>
  37. #include <asm/feature-fixups.h>
  38. #if defined(CONFIG_40x)
  39. /*
  40. * 40x implementation needs only tlbil_va
  41. */
  42. _GLOBAL(__tlbil_va)
  43. /* We run the search with interrupts disabled because we have to change
  44. * the PID and I don't want to preempt when that happens.
  45. */
  46. mfmsr r5
  47. mfspr r6,SPRN_PID
  48. wrteei 0
  49. mtspr SPRN_PID,r4
  50. tlbsx. r3, 0, r3
  51. mtspr SPRN_PID,r6
  52. wrtee r5
  53. bne 1f
  54. sync
  55. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is
  56. * clear. Since 25 is the V bit in the TLB_TAG, loading this value
  57. * will invalidate the TLB entry. */
  58. tlbwe r3, r3, TLB_TAG
  59. isync
  60. 1: blr
  61. #elif defined(CONFIG_PPC_8xx)
  62. /*
  63. * Nothing to do for 8xx, everything is inline
  64. */
  65. #elif defined(CONFIG_44x) /* Includes 47x */
  66. /*
  67. * 440 implementation uses tlbsx/we for tlbil_va and a full sweep
  68. * of the TLB for everything else.
  69. */
  70. _GLOBAL(__tlbil_va)
  71. mfspr r5,SPRN_MMUCR
  72. mfmsr r10
  73. /*
  74. * We write 16 bits of STID since 47x supports that much, we
  75. * will never be passed out of bounds values on 440 (hopefully)
  76. */
  77. rlwimi r5,r4,0,16,31
  78. /* We have to run the search with interrupts disabled, otherwise
  79. * an interrupt which causes a TLB miss can clobber the MMUCR
  80. * between the mtspr and the tlbsx.
  81. *
  82. * Critical and Machine Check interrupts take care of saving
  83. * and restoring MMUCR, so only normal interrupts have to be
  84. * taken care of.
  85. */
  86. wrteei 0
  87. mtspr SPRN_MMUCR,r5
  88. tlbsx. r6,0,r3
  89. bne 10f
  90. sync
  91. BEGIN_MMU_FTR_SECTION
  92. b 2f
  93. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
  94. /* On 440 There are only 64 TLB entries, so r3 < 64, which means bit
  95. * 22, is clear. Since 22 is the V bit in the TLB_PAGEID, loading this
  96. * value will invalidate the TLB entry.
  97. */
  98. tlbwe r6,r6,PPC44x_TLB_PAGEID
  99. isync
  100. 10: wrtee r10
  101. blr
  102. 2:
  103. #ifdef CONFIG_PPC_47x
  104. oris r7,r6,0x8000 /* specify way explicitly */
  105. clrrwi r4,r3,12 /* get an EPN for the hashing with V = 0 */
  106. ori r4,r4,PPC47x_TLBE_SIZE
  107. tlbwe r4,r7,0 /* write it */
  108. isync
  109. wrtee r10
  110. blr
  111. #else /* CONFIG_PPC_47x */
  112. 1: trap
  113. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,0;
  114. #endif /* !CONFIG_PPC_47x */
  115. _GLOBAL(_tlbil_all)
  116. _GLOBAL(_tlbil_pid)
  117. BEGIN_MMU_FTR_SECTION
  118. b 2f
  119. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
  120. li r3,0
  121. sync
  122. /* Load high watermark */
  123. lis r4,tlb_44x_hwater@ha
  124. lwz r5,tlb_44x_hwater@l(r4)
  125. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  126. addi r3,r3,1
  127. cmpw 0,r3,r5
  128. ble 1b
  129. isync
  130. blr
  131. 2:
  132. #ifdef CONFIG_PPC_47x
  133. /* 476 variant. There's not simple way to do this, hopefully we'll
  134. * try to limit the amount of such full invalidates
  135. */
  136. mfmsr r11 /* Interrupts off */
  137. wrteei 0
  138. li r3,-1 /* Current set */
  139. lis r10,tlb_47x_boltmap@h
  140. ori r10,r10,tlb_47x_boltmap@l
  141. lis r7,0x8000 /* Specify way explicitly */
  142. b 9f /* For each set */
  143. 1: li r9,4 /* Number of ways */
  144. li r4,0 /* Current way */
  145. li r6,0 /* Default entry value 0 */
  146. andi. r0,r8,1 /* Check if way 0 is bolted */
  147. mtctr r9 /* Load way counter */
  148. bne- 3f /* Bolted, skip loading it */
  149. 2: /* For each way */
  150. or r5,r3,r4 /* Make way|index for tlbre */
  151. rlwimi r5,r5,16,8,15 /* Copy index into position */
  152. tlbre r6,r5,0 /* Read entry */
  153. 3: addis r4,r4,0x2000 /* Next way */
  154. andi. r0,r6,PPC47x_TLB0_VALID /* Valid entry ? */
  155. beq 4f /* Nope, skip it */
  156. rlwimi r7,r5,0,1,2 /* Insert way number */
  157. rlwinm r6,r6,0,21,19 /* Clear V */
  158. tlbwe r6,r7,0 /* Write it */
  159. 4: bdnz 2b /* Loop for each way */
  160. srwi r8,r8,1 /* Next boltmap bit */
  161. 9: cmpwi cr1,r3,255 /* Last set done ? */
  162. addi r3,r3,1 /* Next set */
  163. beq cr1,1f /* End of loop */
  164. andi. r0,r3,0x1f /* Need to load a new boltmap word ? */
  165. bne 1b /* No, loop */
  166. lwz r8,0(r10) /* Load boltmap entry */
  167. addi r10,r10,4 /* Next word */
  168. b 1b /* Then loop */
  169. 1: isync /* Sync shadows */
  170. wrtee r11
  171. #else /* CONFIG_PPC_47x */
  172. 1: trap
  173. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,0;
  174. #endif /* !CONFIG_PPC_47x */
  175. blr
  176. #ifdef CONFIG_PPC_47x
  177. /*
  178. * _tlbivax_bcast is only on 47x. We don't bother doing a runtime
  179. * check though, it will blow up soon enough if we mistakenly try
  180. * to use it on a 440.
  181. */
  182. _GLOBAL(_tlbivax_bcast)
  183. mfspr r5,SPRN_MMUCR
  184. mfmsr r10
  185. rlwimi r5,r4,0,16,31
  186. wrteei 0
  187. mtspr SPRN_MMUCR,r5
  188. isync
  189. PPC_TLBIVAX(0, R3)
  190. isync
  191. eieio
  192. tlbsync
  193. BEGIN_FTR_SECTION
  194. b 1f
  195. END_FTR_SECTION_IFSET(CPU_FTR_476_DD2)
  196. sync
  197. wrtee r10
  198. blr
  199. /*
  200. * DD2 HW could hang if in instruction fetch happens before msync completes.
  201. * Touch enough instruction cache lines to ensure cache hits
  202. */
  203. 1: mflr r9
  204. bl 2f
  205. 2: mflr r6
  206. li r7,32
  207. PPC_ICBT(0,R6,R7) /* touch next cache line */
  208. add r6,r6,r7
  209. PPC_ICBT(0,R6,R7) /* touch next cache line */
  210. add r6,r6,r7
  211. PPC_ICBT(0,R6,R7) /* touch next cache line */
  212. sync
  213. nop
  214. nop
  215. nop
  216. nop
  217. nop
  218. nop
  219. nop
  220. nop
  221. mtlr r9
  222. wrtee r10
  223. blr
  224. #endif /* CONFIG_PPC_47x */
  225. #elif defined(CONFIG_FSL_BOOKE)
  226. /*
  227. * FSL BookE implementations.
  228. *
  229. * Since feature sections are using _SECTION_ELSE we need
  230. * to have the larger code path before the _SECTION_ELSE
  231. */
  232. /*
  233. * Flush MMU TLB on the local processor
  234. */
  235. _GLOBAL(_tlbil_all)
  236. BEGIN_MMU_FTR_SECTION
  237. li r3,(MMUCSR0_TLBFI)@l
  238. mtspr SPRN_MMUCSR0, r3
  239. 1:
  240. mfspr r3,SPRN_MMUCSR0
  241. andi. r3,r3,MMUCSR0_TLBFI@l
  242. bne 1b
  243. MMU_FTR_SECTION_ELSE
  244. PPC_TLBILX_ALL(0,R0)
  245. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
  246. msync
  247. isync
  248. blr
  249. _GLOBAL(_tlbil_pid)
  250. BEGIN_MMU_FTR_SECTION
  251. slwi r3,r3,16
  252. mfmsr r10
  253. wrteei 0
  254. mfspr r4,SPRN_MAS6 /* save MAS6 */
  255. mtspr SPRN_MAS6,r3
  256. PPC_TLBILX_PID(0,R0)
  257. mtspr SPRN_MAS6,r4 /* restore MAS6 */
  258. wrtee r10
  259. MMU_FTR_SECTION_ELSE
  260. li r3,(MMUCSR0_TLBFI)@l
  261. mtspr SPRN_MMUCSR0, r3
  262. 1:
  263. mfspr r3,SPRN_MMUCSR0
  264. andi. r3,r3,MMUCSR0_TLBFI@l
  265. bne 1b
  266. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBILX)
  267. msync
  268. isync
  269. blr
  270. /*
  271. * Flush MMU TLB for a particular address, but only on the local processor
  272. * (no broadcast)
  273. */
  274. _GLOBAL(__tlbil_va)
  275. mfmsr r10
  276. wrteei 0
  277. slwi r4,r4,16
  278. ori r4,r4,(MAS6_ISIZE(BOOK3E_PAGESZ_4K))@l
  279. mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  280. BEGIN_MMU_FTR_SECTION
  281. tlbsx 0,r3
  282. mfspr r4,SPRN_MAS1 /* check valid */
  283. andis. r3,r4,MAS1_VALID@h
  284. beq 1f
  285. rlwinm r4,r4,0,1,31
  286. mtspr SPRN_MAS1,r4
  287. tlbwe
  288. MMU_FTR_SECTION_ELSE
  289. PPC_TLBILX_VA(0,R3)
  290. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
  291. msync
  292. isync
  293. 1: wrtee r10
  294. blr
  295. #elif defined(CONFIG_PPC_BOOK3E)
  296. /*
  297. * New Book3E (>= 2.06) implementation
  298. *
  299. * Note: We may be able to get away without the interrupt masking stuff
  300. * if we save/restore MAS6 on exceptions that might modify it
  301. */
  302. _GLOBAL(_tlbil_pid)
  303. slwi r4,r3,MAS6_SPID_SHIFT
  304. mfmsr r10
  305. wrteei 0
  306. mtspr SPRN_MAS6,r4
  307. PPC_TLBILX_PID(0,R0)
  308. wrtee r10
  309. msync
  310. isync
  311. blr
  312. _GLOBAL(_tlbil_pid_noind)
  313. slwi r4,r3,MAS6_SPID_SHIFT
  314. mfmsr r10
  315. ori r4,r4,MAS6_SIND
  316. wrteei 0
  317. mtspr SPRN_MAS6,r4
  318. PPC_TLBILX_PID(0,R0)
  319. wrtee r10
  320. msync
  321. isync
  322. blr
  323. _GLOBAL(_tlbil_all)
  324. PPC_TLBILX_ALL(0,R0)
  325. msync
  326. isync
  327. blr
  328. _GLOBAL(_tlbil_va)
  329. mfmsr r10
  330. wrteei 0
  331. cmpwi cr0,r6,0
  332. slwi r4,r4,MAS6_SPID_SHIFT
  333. rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
  334. beq 1f
  335. rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
  336. 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  337. PPC_TLBILX_VA(0,R3)
  338. msync
  339. isync
  340. wrtee r10
  341. blr
  342. _GLOBAL(_tlbivax_bcast)
  343. mfmsr r10
  344. wrteei 0
  345. cmpwi cr0,r6,0
  346. slwi r4,r4,MAS6_SPID_SHIFT
  347. rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
  348. beq 1f
  349. rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
  350. 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  351. PPC_TLBIVAX(0,R3)
  352. eieio
  353. tlbsync
  354. sync
  355. wrtee r10
  356. blr
  357. _GLOBAL(set_context)
  358. #ifdef CONFIG_BDI_SWITCH
  359. /* Context switch the PTE pointer for the Abatron BDI2000.
  360. * The PGDIR is the second parameter.
  361. */
  362. lis r5, abatron_pteptrs@h
  363. ori r5, r5, abatron_pteptrs@l
  364. stw r4, 0x4(r5)
  365. #endif
  366. mtspr SPRN_PID,r3
  367. isync /* Force context change */
  368. blr
  369. #else
  370. #error Unsupported processor type !
  371. #endif
  372. #if defined(CONFIG_PPC_FSL_BOOK3E)
  373. /*
  374. * extern void loadcam_entry(unsigned int index)
  375. *
  376. * Load TLBCAM[index] entry in to the L2 CAM MMU
  377. * Must preserve r7, r8, r9, r10 and r11
  378. */
  379. _GLOBAL(loadcam_entry)
  380. mflr r5
  381. LOAD_REG_ADDR_PIC(r4, TLBCAM)
  382. mtlr r5
  383. mulli r5,r3,TLBCAM_SIZE
  384. add r3,r5,r4
  385. lwz r4,TLBCAM_MAS0(r3)
  386. mtspr SPRN_MAS0,r4
  387. lwz r4,TLBCAM_MAS1(r3)
  388. mtspr SPRN_MAS1,r4
  389. PPC_LL r4,TLBCAM_MAS2(r3)
  390. mtspr SPRN_MAS2,r4
  391. lwz r4,TLBCAM_MAS3(r3)
  392. mtspr SPRN_MAS3,r4
  393. BEGIN_MMU_FTR_SECTION
  394. lwz r4,TLBCAM_MAS7(r3)
  395. mtspr SPRN_MAS7,r4
  396. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  397. isync
  398. tlbwe
  399. isync
  400. blr
  401. /*
  402. * Load multiple TLB entries at once, using an alternate-space
  403. * trampoline so that we don't have to care about whether the same
  404. * TLB entry maps us before and after.
  405. *
  406. * r3 = first entry to write
  407. * r4 = number of entries to write
  408. * r5 = temporary tlb entry
  409. */
  410. _GLOBAL(loadcam_multi)
  411. mflr r8
  412. /* Don't switch to AS=1 if already there */
  413. mfmsr r11
  414. andi. r11,r11,MSR_IS
  415. bne 10f
  416. /*
  417. * Set up temporary TLB entry that is the same as what we're
  418. * running from, but in AS=1.
  419. */
  420. bl 1f
  421. 1: mflr r6
  422. tlbsx 0,r8
  423. mfspr r6,SPRN_MAS1
  424. ori r6,r6,MAS1_TS
  425. mtspr SPRN_MAS1,r6
  426. mfspr r6,SPRN_MAS0
  427. rlwimi r6,r5,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
  428. mr r7,r5
  429. mtspr SPRN_MAS0,r6
  430. isync
  431. tlbwe
  432. isync
  433. /* Switch to AS=1 */
  434. mfmsr r6
  435. ori r6,r6,MSR_IS|MSR_DS
  436. mtmsr r6
  437. isync
  438. 10:
  439. mr r9,r3
  440. add r10,r3,r4
  441. 2: bl loadcam_entry
  442. addi r9,r9,1
  443. cmpw r9,r10
  444. mr r3,r9
  445. blt 2b
  446. /* Don't return to AS=0 if we were in AS=1 at function start */
  447. andi. r11,r11,MSR_IS
  448. bne 3f
  449. /* Return to AS=0 and clear the temporary entry */
  450. mfmsr r6
  451. rlwinm. r6,r6,0,~(MSR_IS|MSR_DS)
  452. mtmsr r6
  453. isync
  454. li r6,0
  455. mtspr SPRN_MAS1,r6
  456. rlwinm r6,r7,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
  457. oris r6,r6,MAS0_TLBSEL(1)@h
  458. mtspr SPRN_MAS0,r6
  459. isync
  460. tlbwe
  461. isync
  462. 3:
  463. mtlr r8
  464. blr
  465. #endif