cpu_setup_e500.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * This file contains low level CPU setup functions.
  4. * Kumar Gala <[email protected]>
  5. * Copyright 2009 Freescale Semiconductor, Inc.
  6. *
  7. * Based on cpu_setup_6xx code by
  8. * Benjamin Herrenschmidt <[email protected]>
  9. */
  10. #include <asm/page.h>
  11. #include <asm/processor.h>
  12. #include <asm/cputable.h>
  13. #include <asm/ppc_asm.h>
  14. #include <asm/nohash/mmu-e500.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/mpc85xx.h>
  17. _GLOBAL(__e500_icache_setup)
  18. mfspr r0, SPRN_L1CSR1
  19. andi. r3, r0, L1CSR1_ICE
  20. bnelr /* Already enabled */
  21. oris r0, r0, L1CSR1_CPE@h
  22. ori r0, r0, (L1CSR1_ICFI | L1CSR1_ICLFR | L1CSR1_ICE)
  23. mtspr SPRN_L1CSR1, r0 /* Enable I-Cache */
  24. isync
  25. blr
  26. _GLOBAL(__e500_dcache_setup)
  27. mfspr r0, SPRN_L1CSR0
  28. andi. r3, r0, L1CSR0_DCE
  29. bnelr /* Already enabled */
  30. msync
  31. isync
  32. li r0, 0
  33. mtspr SPRN_L1CSR0, r0 /* Disable */
  34. msync
  35. isync
  36. li r0, (L1CSR0_DCFI | L1CSR0_CLFC)
  37. mtspr SPRN_L1CSR0, r0 /* Invalidate */
  38. isync
  39. 1: mfspr r0, SPRN_L1CSR0
  40. andi. r3, r0, L1CSR0_CLFC
  41. bne+ 1b /* Wait for lock bits reset */
  42. oris r0, r0, L1CSR0_CPE@h
  43. ori r0, r0, L1CSR0_DCE
  44. msync
  45. isync
  46. mtspr SPRN_L1CSR0, r0 /* Enable */
  47. isync
  48. blr
  49. /*
  50. * FIXME - we haven't yet done testing to determine a reasonable default
  51. * value for PW20_WAIT_IDLE_BIT.
  52. */
  53. #define PW20_WAIT_IDLE_BIT 50 /* 1ms, TB frequency is 41.66MHZ */
  54. _GLOBAL(setup_pw20_idle)
  55. mfspr r3, SPRN_PWRMGTCR0
  56. /* Set PW20_WAIT bit, enable pw20 state*/
  57. ori r3, r3, PWRMGTCR0_PW20_WAIT
  58. li r11, PW20_WAIT_IDLE_BIT
  59. /* Set Automatic PW20 Core Idle Count */
  60. rlwimi r3, r11, PWRMGTCR0_PW20_ENT_SHIFT, PWRMGTCR0_PW20_ENT
  61. mtspr SPRN_PWRMGTCR0, r3
  62. blr
  63. /*
  64. * FIXME - we haven't yet done testing to determine a reasonable default
  65. * value for AV_WAIT_IDLE_BIT.
  66. */
  67. #define AV_WAIT_IDLE_BIT 50 /* 1ms, TB frequency is 41.66MHZ */
  68. _GLOBAL(setup_altivec_idle)
  69. mfspr r3, SPRN_PWRMGTCR0
  70. /* Enable Altivec Idle */
  71. oris r3, r3, PWRMGTCR0_AV_IDLE_PD_EN@h
  72. li r11, AV_WAIT_IDLE_BIT
  73. /* Set Automatic AltiVec Idle Count */
  74. rlwimi r3, r11, PWRMGTCR0_AV_IDLE_CNT_SHIFT, PWRMGTCR0_AV_IDLE_CNT
  75. mtspr SPRN_PWRMGTCR0, r3
  76. blr
  77. #ifdef CONFIG_PPC_E500MC
  78. _GLOBAL(__setup_cpu_e6500)
  79. mflr r6
  80. #ifdef CONFIG_PPC64
  81. bl setup_altivec_ivors
  82. /* Touch IVOR42 only if the CPU supports E.HV category */
  83. mfspr r10,SPRN_MMUCFG
  84. rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
  85. beq 1f
  86. bl setup_lrat_ivor
  87. 1:
  88. #endif
  89. bl setup_pw20_idle
  90. bl setup_altivec_idle
  91. bl __setup_cpu_e5500
  92. mtlr r6
  93. blr
  94. #endif /* CONFIG_PPC_E500MC */
  95. #ifdef CONFIG_PPC32
  96. #ifdef CONFIG_PPC_E500
  97. #ifndef CONFIG_PPC_E500MC
  98. _GLOBAL(__setup_cpu_e500v1)
  99. _GLOBAL(__setup_cpu_e500v2)
  100. mflr r4
  101. bl __e500_icache_setup
  102. bl __e500_dcache_setup
  103. bl __setup_e500_ivors
  104. #if defined(CONFIG_FSL_RIO) || defined(CONFIG_FSL_PCI)
  105. /* Ensure that RFXE is set */
  106. mfspr r3,SPRN_HID1
  107. oris r3,r3,HID1_RFXE@h
  108. mtspr SPRN_HID1,r3
  109. #endif
  110. mtlr r4
  111. blr
  112. #else /* CONFIG_PPC_E500MC */
  113. _GLOBAL(__setup_cpu_e500mc)
  114. _GLOBAL(__setup_cpu_e5500)
  115. mflr r5
  116. bl __e500_icache_setup
  117. bl __e500_dcache_setup
  118. bl __setup_e500mc_ivors
  119. /*
  120. * We only want to touch IVOR38-41 if we're running on hardware
  121. * that supports category E.HV. The architectural way to determine
  122. * this is MMUCFG[LPIDSIZE].
  123. */
  124. mfspr r3, SPRN_MMUCFG
  125. rlwinm. r3, r3, 0, MMUCFG_LPIDSIZE
  126. beq 1f
  127. bl __setup_ehv_ivors
  128. b 2f
  129. 1:
  130. lwz r3, CPU_SPEC_FEATURES(r4)
  131. /* We need this check as cpu_setup is also called for
  132. * the secondary cores. So, if we have already cleared
  133. * the feature on the primary core, avoid doing it on the
  134. * secondary core.
  135. */
  136. andi. r6, r3, CPU_FTR_EMB_HV
  137. beq 2f
  138. rlwinm r3, r3, 0, ~CPU_FTR_EMB_HV
  139. stw r3, CPU_SPEC_FEATURES(r4)
  140. 2:
  141. mtlr r5
  142. blr
  143. #endif /* CONFIG_PPC_E500MC */
  144. #endif /* CONFIG_PPC_E500 */
  145. #endif /* CONFIG_PPC32 */
  146. #ifdef CONFIG_PPC_BOOK3E_64
  147. _GLOBAL(__restore_cpu_e6500)
  148. mflr r5
  149. bl setup_altivec_ivors
  150. /* Touch IVOR42 only if the CPU supports E.HV category */
  151. mfspr r10,SPRN_MMUCFG
  152. rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
  153. beq 1f
  154. bl setup_lrat_ivor
  155. 1:
  156. bl setup_pw20_idle
  157. bl setup_altivec_idle
  158. bl __restore_cpu_e5500
  159. mtlr r5
  160. blr
  161. _GLOBAL(__restore_cpu_e5500)
  162. mflr r4
  163. bl __e500_icache_setup
  164. bl __e500_dcache_setup
  165. bl __setup_base_ivors
  166. bl setup_perfmon_ivor
  167. bl setup_doorbell_ivors
  168. /*
  169. * We only want to touch IVOR38-41 if we're running on hardware
  170. * that supports category E.HV. The architectural way to determine
  171. * this is MMUCFG[LPIDSIZE].
  172. */
  173. mfspr r10,SPRN_MMUCFG
  174. rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
  175. beq 1f
  176. bl setup_ehv_ivors
  177. 1:
  178. mtlr r4
  179. blr
  180. _GLOBAL(__setup_cpu_e5500)
  181. mflr r5
  182. bl __e500_icache_setup
  183. bl __e500_dcache_setup
  184. bl __setup_base_ivors
  185. bl setup_perfmon_ivor
  186. bl setup_doorbell_ivors
  187. /*
  188. * We only want to touch IVOR38-41 if we're running on hardware
  189. * that supports category E.HV. The architectural way to determine
  190. * this is MMUCFG[LPIDSIZE].
  191. */
  192. mfspr r10,SPRN_MMUCFG
  193. rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
  194. beq 1f
  195. bl setup_ehv_ivors
  196. b 2f
  197. 1:
  198. ld r10,CPU_SPEC_FEATURES(r4)
  199. LOAD_REG_IMMEDIATE(r9,CPU_FTR_EMB_HV)
  200. andc r10,r10,r9
  201. std r10,CPU_SPEC_FEATURES(r4)
  202. 2:
  203. mtlr r5
  204. blr
  205. #endif
  206. /* flush L1 data cache, it can apply to e500v2, e500mc and e5500 */
  207. _GLOBAL(flush_dcache_L1)
  208. mfmsr r10
  209. wrteei 0
  210. mfspr r3,SPRN_L1CFG0
  211. rlwinm r5,r3,9,3 /* Extract cache block size */
  212. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  213. * are currently defined.
  214. */
  215. li r4,32
  216. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  217. * log2(number of ways)
  218. */
  219. slw r5,r4,r5 /* r5 = cache block size */
  220. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  221. mulli r7,r7,13 /* An 8-way cache will require 13
  222. * loads per set.
  223. */
  224. slw r7,r7,r6
  225. /* save off HID0 and set DCFA */
  226. mfspr r8,SPRN_HID0
  227. ori r9,r8,HID0_DCFA@l
  228. mtspr SPRN_HID0,r9
  229. isync
  230. LOAD_REG_IMMEDIATE(r6, KERNELBASE)
  231. mr r4, r6
  232. mtctr r7
  233. 1: lwz r3,0(r4) /* Load... */
  234. add r4,r4,r5
  235. bdnz 1b
  236. msync
  237. mr r4, r6
  238. mtctr r7
  239. 1: dcbf 0,r4 /* ...and flush. */
  240. add r4,r4,r5
  241. bdnz 1b
  242. /* restore HID0 */
  243. mtspr SPRN_HID0,r8
  244. isync
  245. wrtee r10
  246. blr
  247. has_L2_cache:
  248. /* skip L2 cache on P2040/P2040E as they have no L2 cache */
  249. mfspr r3, SPRN_SVR
  250. /* shift right by 8 bits and clear E bit of SVR */
  251. rlwinm r4, r3, 24, ~0x800
  252. lis r3, SVR_P2040@h
  253. ori r3, r3, SVR_P2040@l
  254. cmpw r4, r3
  255. beq 1f
  256. li r3, 1
  257. blr
  258. 1:
  259. li r3, 0
  260. blr
  261. /* flush backside L2 cache */
  262. flush_backside_L2_cache:
  263. mflr r10
  264. bl has_L2_cache
  265. mtlr r10
  266. cmpwi r3, 0
  267. beq 2f
  268. /* Flush the L2 cache */
  269. mfspr r3, SPRN_L2CSR0
  270. ori r3, r3, L2CSR0_L2FL@l
  271. msync
  272. isync
  273. mtspr SPRN_L2CSR0,r3
  274. isync
  275. /* check if it is complete */
  276. 1: mfspr r3,SPRN_L2CSR0
  277. andi. r3, r3, L2CSR0_L2FL@l
  278. bne 1b
  279. 2:
  280. blr
  281. _GLOBAL(cpu_down_flush_e500v2)
  282. mflr r0
  283. bl flush_dcache_L1
  284. mtlr r0
  285. blr
  286. _GLOBAL(cpu_down_flush_e500mc)
  287. _GLOBAL(cpu_down_flush_e5500)
  288. mflr r0
  289. bl flush_dcache_L1
  290. bl flush_backside_L2_cache
  291. mtlr r0
  292. blr
  293. /* L1 Data Cache of e6500 contains no modified data, no flush is required */
  294. _GLOBAL(cpu_down_flush_e6500)
  295. blr