cpu_setup_e500.S 6.9 KB

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