tlb_nohash_low.S 10 KB

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