tlb_nohash_low.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. * 47x variant of icbt
  177. */
  178. # define ICBT(CT,RA,RB) \
  179. .long 0x7c00002c | ((CT) << 21) | ((RA) << 16) | ((RB) << 11)
  180. /*
  181. * _tlbivax_bcast is only on 47x. We don't bother doing a runtime
  182. * check though, it will blow up soon enough if we mistakenly try
  183. * to use it on a 440.
  184. */
  185. _GLOBAL(_tlbivax_bcast)
  186. mfspr r5,SPRN_MMUCR
  187. mfmsr r10
  188. rlwimi r5,r4,0,16,31
  189. wrteei 0
  190. mtspr SPRN_MMUCR,r5
  191. isync
  192. /* tlbivax 0,r3 - use .long to avoid binutils deps */
  193. .long 0x7c000624 | (r3 << 11)
  194. isync
  195. eieio
  196. tlbsync
  197. BEGIN_FTR_SECTION
  198. b 1f
  199. END_FTR_SECTION_IFSET(CPU_FTR_476_DD2)
  200. sync
  201. wrtee r10
  202. blr
  203. /*
  204. * DD2 HW could hang if in instruction fetch happens before msync completes.
  205. * Touch enough instruction cache lines to ensure cache hits
  206. */
  207. 1: mflr r9
  208. bl 2f
  209. 2: mflr r6
  210. li r7,32
  211. ICBT(0,r6,r7) /* touch next cache line */
  212. add r6,r6,r7
  213. ICBT(0,r6,r7) /* touch next cache line */
  214. add r6,r6,r7
  215. ICBT(0,r6,r7) /* touch next cache line */
  216. sync
  217. nop
  218. nop
  219. nop
  220. nop
  221. nop
  222. nop
  223. nop
  224. nop
  225. mtlr r9
  226. wrtee r10
  227. blr
  228. #endif /* CONFIG_PPC_47x */
  229. #elif defined(CONFIG_FSL_BOOKE)
  230. /*
  231. * FSL BookE implementations.
  232. *
  233. * Since feature sections are using _SECTION_ELSE we need
  234. * to have the larger code path before the _SECTION_ELSE
  235. */
  236. /*
  237. * Flush MMU TLB on the local processor
  238. */
  239. _GLOBAL(_tlbil_all)
  240. BEGIN_MMU_FTR_SECTION
  241. li r3,(MMUCSR0_TLBFI)@l
  242. mtspr SPRN_MMUCSR0, r3
  243. 1:
  244. mfspr r3,SPRN_MMUCSR0
  245. andi. r3,r3,MMUCSR0_TLBFI@l
  246. bne 1b
  247. MMU_FTR_SECTION_ELSE
  248. PPC_TLBILX_ALL(0,0)
  249. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
  250. msync
  251. isync
  252. blr
  253. _GLOBAL(_tlbil_pid)
  254. BEGIN_MMU_FTR_SECTION
  255. slwi r3,r3,16
  256. mfmsr r10
  257. wrteei 0
  258. mfspr r4,SPRN_MAS6 /* save MAS6 */
  259. mtspr SPRN_MAS6,r3
  260. PPC_TLBILX_PID(0,0)
  261. mtspr SPRN_MAS6,r4 /* restore MAS6 */
  262. wrtee r10
  263. MMU_FTR_SECTION_ELSE
  264. li r3,(MMUCSR0_TLBFI)@l
  265. mtspr SPRN_MMUCSR0, r3
  266. 1:
  267. mfspr r3,SPRN_MMUCSR0
  268. andi. r3,r3,MMUCSR0_TLBFI@l
  269. bne 1b
  270. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBILX)
  271. msync
  272. isync
  273. blr
  274. /*
  275. * Flush MMU TLB for a particular address, but only on the local processor
  276. * (no broadcast)
  277. */
  278. _GLOBAL(__tlbil_va)
  279. mfmsr r10
  280. wrteei 0
  281. slwi r4,r4,16
  282. ori r4,r4,(MAS6_ISIZE(BOOK3E_PAGESZ_4K))@l
  283. mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  284. BEGIN_MMU_FTR_SECTION
  285. tlbsx 0,r3
  286. mfspr r4,SPRN_MAS1 /* check valid */
  287. andis. r3,r4,MAS1_VALID@h
  288. beq 1f
  289. rlwinm r4,r4,0,1,31
  290. mtspr SPRN_MAS1,r4
  291. tlbwe
  292. MMU_FTR_SECTION_ELSE
  293. PPC_TLBILX_VA(0,r3)
  294. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
  295. msync
  296. isync
  297. 1: wrtee r10
  298. blr
  299. #elif defined(CONFIG_PPC_BOOK3E)
  300. /*
  301. * New Book3E (>= 2.06) implementation
  302. *
  303. * Note: We may be able to get away without the interrupt masking stuff
  304. * if we save/restore MAS6 on exceptions that might modify it
  305. */
  306. _GLOBAL(_tlbil_pid)
  307. slwi r4,r3,MAS6_SPID_SHIFT
  308. mfmsr r10
  309. wrteei 0
  310. mtspr SPRN_MAS6,r4
  311. PPC_TLBILX_PID(0,0)
  312. wrtee r10
  313. msync
  314. isync
  315. blr
  316. _GLOBAL(_tlbil_pid_noind)
  317. slwi r4,r3,MAS6_SPID_SHIFT
  318. mfmsr r10
  319. ori r4,r4,MAS6_SIND
  320. wrteei 0
  321. mtspr SPRN_MAS6,r4
  322. PPC_TLBILX_PID(0,0)
  323. wrtee r10
  324. msync
  325. isync
  326. blr
  327. _GLOBAL(_tlbil_all)
  328. PPC_TLBILX_ALL(0,0)
  329. msync
  330. isync
  331. blr
  332. _GLOBAL(_tlbil_va)
  333. mfmsr r10
  334. wrteei 0
  335. cmpwi cr0,r6,0
  336. slwi r4,r4,MAS6_SPID_SHIFT
  337. rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
  338. beq 1f
  339. rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
  340. 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  341. PPC_TLBILX_VA(0,r3)
  342. msync
  343. isync
  344. wrtee r10
  345. blr
  346. _GLOBAL(_tlbivax_bcast)
  347. mfmsr r10
  348. wrteei 0
  349. cmpwi cr0,r6,0
  350. slwi r4,r4,MAS6_SPID_SHIFT
  351. rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
  352. beq 1f
  353. rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
  354. 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  355. PPC_TLBIVAX(0,r3)
  356. eieio
  357. tlbsync
  358. sync
  359. wrtee r10
  360. blr
  361. _GLOBAL(set_context)
  362. #ifdef CONFIG_BDI_SWITCH
  363. /* Context switch the PTE pointer for the Abatron BDI2000.
  364. * The PGDIR is the second parameter.
  365. */
  366. lis r5, abatron_pteptrs@h
  367. ori r5, r5, abatron_pteptrs@l
  368. stw r4, 0x4(r5)
  369. #endif
  370. mtspr SPRN_PID,r3
  371. isync /* Force context change */
  372. blr
  373. #else
  374. #error Unsupported processor type !
  375. #endif
  376. #if defined(CONFIG_PPC_FSL_BOOK3E)
  377. /*
  378. * extern void loadcam_entry(unsigned int index)
  379. *
  380. * Load TLBCAM[index] entry in to the L2 CAM MMU
  381. */
  382. _GLOBAL(loadcam_entry)
  383. LOAD_REG_ADDR(r4, TLBCAM)
  384. mulli r5,r3,TLBCAM_SIZE
  385. add r3,r5,r4
  386. lwz r4,TLBCAM_MAS0(r3)
  387. mtspr SPRN_MAS0,r4
  388. lwz r4,TLBCAM_MAS1(r3)
  389. mtspr SPRN_MAS1,r4
  390. PPC_LL r4,TLBCAM_MAS2(r3)
  391. mtspr SPRN_MAS2,r4
  392. lwz r4,TLBCAM_MAS3(r3)
  393. mtspr SPRN_MAS3,r4
  394. BEGIN_MMU_FTR_SECTION
  395. lwz r4,TLBCAM_MAS7(r3)
  396. mtspr SPRN_MAS7,r4
  397. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  398. isync
  399. tlbwe
  400. isync
  401. blr
  402. #endif