cpu_setup_6xx.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * This file contains low level CPU setup functions.
  4. * Copyright (C) 2003 Benjamin Herrenschmidt ([email protected])
  5. */
  6. #include <asm/processor.h>
  7. #include <asm/page.h>
  8. #include <asm/cputable.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/asm-offsets.h>
  11. #include <asm/cache.h>
  12. #include <asm/mmu.h>
  13. #include <asm/feature-fixups.h>
  14. _GLOBAL(__setup_cpu_603)
  15. mflr r5
  16. BEGIN_MMU_FTR_SECTION
  17. li r10,0
  18. mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */
  19. END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
  20. BEGIN_FTR_SECTION
  21. bl __init_fpu_registers
  22. END_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
  23. bl setup_common_caches
  24. mtlr r5
  25. blr
  26. _GLOBAL(__setup_cpu_604)
  27. mflr r5
  28. bl setup_common_caches
  29. bl setup_604_hid0
  30. mtlr r5
  31. blr
  32. _GLOBAL(__setup_cpu_750)
  33. mflr r5
  34. bl __init_fpu_registers
  35. bl setup_common_caches
  36. bl setup_750_7400_hid0
  37. mtlr r5
  38. blr
  39. _GLOBAL(__setup_cpu_750cx)
  40. mflr r5
  41. bl __init_fpu_registers
  42. bl setup_common_caches
  43. bl setup_750_7400_hid0
  44. bl setup_750cx
  45. mtlr r5
  46. blr
  47. _GLOBAL(__setup_cpu_750fx)
  48. mflr r5
  49. bl __init_fpu_registers
  50. bl setup_common_caches
  51. bl setup_750_7400_hid0
  52. bl setup_750fx
  53. mtlr r5
  54. blr
  55. _GLOBAL(__setup_cpu_7400)
  56. mflr r5
  57. bl __init_fpu_registers
  58. bl setup_7400_workarounds
  59. bl setup_common_caches
  60. bl setup_750_7400_hid0
  61. mtlr r5
  62. blr
  63. _GLOBAL(__setup_cpu_7410)
  64. mflr r5
  65. bl __init_fpu_registers
  66. bl setup_7410_workarounds
  67. bl setup_common_caches
  68. bl setup_750_7400_hid0
  69. li r3,0
  70. mtspr SPRN_L2CR2,r3
  71. mtlr r5
  72. blr
  73. _GLOBAL(__setup_cpu_745x)
  74. mflr r5
  75. bl setup_common_caches
  76. bl setup_745x_specifics
  77. mtlr r5
  78. blr
  79. /* Enable caches for 603's, 604, 750 & 7400 */
  80. setup_common_caches:
  81. mfspr r11,SPRN_HID0
  82. andi. r0,r11,HID0_DCE
  83. ori r11,r11,HID0_ICE|HID0_DCE
  84. ori r8,r11,HID0_ICFI
  85. bne 1f /* don't invalidate the D-cache */
  86. ori r8,r8,HID0_DCI /* unless it wasn't enabled */
  87. 1: sync
  88. mtspr SPRN_HID0,r8 /* enable and invalidate caches */
  89. sync
  90. mtspr SPRN_HID0,r11 /* enable caches */
  91. sync
  92. isync
  93. blr
  94. /* 604, 604e, 604ev, ...
  95. * Enable superscalar execution & branch history table
  96. */
  97. setup_604_hid0:
  98. mfspr r11,SPRN_HID0
  99. ori r11,r11,HID0_SIED|HID0_BHTE
  100. ori r8,r11,HID0_BTCD
  101. sync
  102. mtspr SPRN_HID0,r8 /* flush branch target address cache */
  103. sync /* on 604e/604r */
  104. mtspr SPRN_HID0,r11
  105. sync
  106. isync
  107. blr
  108. /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
  109. * erratas we work around here.
  110. * Moto MPC710CE.pdf describes them, those are errata
  111. * #3, #4 and #5
  112. * Note that we assume the firmware didn't choose to
  113. * apply other workarounds (there are other ones documented
  114. * in the .pdf). It appear that Apple firmware only works
  115. * around #3 and with the same fix we use. We may want to
  116. * check if the CPU is using 60x bus mode in which case
  117. * the workaround for errata #4 is useless. Also, we may
  118. * want to explicitly clear HID0_NOPDST as this is not
  119. * needed once we have applied workaround #5 (though it's
  120. * not set by Apple's firmware at least).
  121. */
  122. setup_7400_workarounds:
  123. mfpvr r3
  124. rlwinm r3,r3,0,20,31
  125. cmpwi 0,r3,0x0207
  126. ble 1f
  127. blr
  128. setup_7410_workarounds:
  129. mfpvr r3
  130. rlwinm r3,r3,0,20,31
  131. cmpwi 0,r3,0x0100
  132. bnelr
  133. 1:
  134. mfspr r11,SPRN_MSSSR0
  135. /* Errata #3: Set L1OPQ_SIZE to 0x10 */
  136. rlwinm r11,r11,0,9,6
  137. oris r11,r11,0x0100
  138. /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
  139. oris r11,r11,0x0002
  140. /* Errata #5: Set DRLT_SIZE to 0x01 */
  141. rlwinm r11,r11,0,5,2
  142. oris r11,r11,0x0800
  143. sync
  144. mtspr SPRN_MSSSR0,r11
  145. sync
  146. isync
  147. blr
  148. /* 740/750/7400/7410
  149. * Enable Store Gathering (SGE), Address Broadcast (ABE),
  150. * Branch History Table (BHTE), Branch Target ICache (BTIC)
  151. * Dynamic Power Management (DPM), Speculative (SPD)
  152. * Clear Instruction cache throttling (ICTC)
  153. */
  154. setup_750_7400_hid0:
  155. mfspr r11,SPRN_HID0
  156. ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
  157. oris r11,r11,HID0_DPM@h
  158. BEGIN_FTR_SECTION
  159. xori r11,r11,HID0_BTIC
  160. END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
  161. BEGIN_FTR_SECTION
  162. xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
  163. END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
  164. li r3,HID0_SPD
  165. andc r11,r11,r3 /* clear SPD: enable speculative */
  166. li r3,0
  167. mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
  168. isync
  169. mtspr SPRN_HID0,r11
  170. sync
  171. isync
  172. blr
  173. /* 750cx specific
  174. * Looks like we have to disable NAP feature for some PLL settings...
  175. * (waiting for confirmation)
  176. */
  177. setup_750cx:
  178. mfspr r10, SPRN_HID1
  179. rlwinm r10,r10,4,28,31
  180. cmpwi cr0,r10,7
  181. cmpwi cr1,r10,9
  182. cmpwi cr2,r10,11
  183. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  184. cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
  185. bnelr
  186. lwz r6,CPU_SPEC_FEATURES(r4)
  187. li r7,CPU_FTR_CAN_NAP
  188. andc r6,r6,r7
  189. stw r6,CPU_SPEC_FEATURES(r4)
  190. blr
  191. /* 750fx specific
  192. */
  193. setup_750fx:
  194. blr
  195. /* MPC 745x
  196. * Enable Store Gathering (SGE), Branch Folding (FOLD)
  197. * Branch History Table (BHTE), Branch Target ICache (BTIC)
  198. * Dynamic Power Management (DPM), Speculative (SPD)
  199. * Ensure our data cache instructions really operate.
  200. * Timebase has to be running or we wouldn't have made it here,
  201. * just ensure we don't disable it.
  202. * Clear Instruction cache throttling (ICTC)
  203. * Enable L2 HW prefetch
  204. */
  205. setup_745x_specifics:
  206. /* We check for the presence of an L3 cache setup by
  207. * the firmware. If any, we disable NAP capability as
  208. * it's known to be bogus on rev 2.1 and earlier
  209. */
  210. BEGIN_FTR_SECTION
  211. mfspr r11,SPRN_L3CR
  212. andis. r11,r11,L3CR_L3E@h
  213. beq 1f
  214. END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
  215. lwz r6,CPU_SPEC_FEATURES(r4)
  216. andis. r0,r6,CPU_FTR_L3_DISABLE_NAP@h
  217. beq 1f
  218. li r7,CPU_FTR_CAN_NAP
  219. andc r6,r6,r7
  220. stw r6,CPU_SPEC_FEATURES(r4)
  221. 1:
  222. mfspr r11,SPRN_HID0
  223. /* All of the bits we have to set.....
  224. */
  225. ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
  226. ori r11,r11,HID0_LRSTK | HID0_BTIC
  227. oris r11,r11,HID0_DPM@h
  228. BEGIN_MMU_FTR_SECTION
  229. oris r11,r11,HID0_HIGH_BAT@h
  230. END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
  231. BEGIN_FTR_SECTION
  232. xori r11,r11,HID0_BTIC
  233. END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
  234. BEGIN_FTR_SECTION
  235. xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
  236. END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
  237. /* All of the bits we have to clear....
  238. */
  239. li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
  240. andc r11,r11,r3 /* clear SPD: enable speculative */
  241. li r3,0
  242. mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
  243. isync
  244. mtspr SPRN_HID0,r11
  245. sync
  246. isync
  247. /* Enable L2 HW prefetch, if L2 is enabled
  248. */
  249. mfspr r3,SPRN_L2CR
  250. andis. r3,r3,L2CR_L2E@h
  251. beqlr
  252. mfspr r3,SPRN_MSSCR0
  253. ori r3,r3,3
  254. sync
  255. mtspr SPRN_MSSCR0,r3
  256. sync
  257. isync
  258. blr
  259. /*
  260. * Initialize the FPU registers. This is needed to work around an errata
  261. * in some 750 cpus where using a not yet initialized FPU register after
  262. * power on reset may hang the CPU
  263. */
  264. _GLOBAL(__init_fpu_registers)
  265. mfmsr r10
  266. ori r11,r10,MSR_FP
  267. mtmsr r11
  268. isync
  269. addis r9,r3,empty_zero_page@ha
  270. addi r9,r9,empty_zero_page@l
  271. REST_32FPRS(0,r9)
  272. sync
  273. mtmsr r10
  274. isync
  275. blr
  276. _ASM_NOKPROBE_SYMBOL(__init_fpu_registers)
  277. /* Definitions for the table use to save CPU states */
  278. #define CS_HID0 0
  279. #define CS_HID1 4
  280. #define CS_HID2 8
  281. #define CS_MSSCR0 12
  282. #define CS_MSSSR0 16
  283. #define CS_ICTRL 20
  284. #define CS_LDSTCR 24
  285. #define CS_LDSTDB 28
  286. #define CS_SIZE 32
  287. .data
  288. .balign L1_CACHE_BYTES
  289. cpu_state_storage:
  290. .space CS_SIZE
  291. .balign L1_CACHE_BYTES,0
  292. .text
  293. /* Called in normal context to backup CPU 0 state. This
  294. * does not include cache settings. This function is also
  295. * called for machine sleep. This does not include the MMU
  296. * setup, BATs, etc... but rather the "special" registers
  297. * like HID0, HID1, MSSCR0, etc...
  298. */
  299. _GLOBAL(__save_cpu_setup)
  300. /* Some CR fields are volatile, we back it up all */
  301. mfcr r7
  302. /* Get storage ptr */
  303. lis r5,cpu_state_storage@h
  304. ori r5,r5,cpu_state_storage@l
  305. /* Save HID0 (common to all CONFIG_PPC_BOOK3S_32 cpus) */
  306. mfspr r3,SPRN_HID0
  307. stw r3,CS_HID0(r5)
  308. /* Now deal with CPU type dependent registers */
  309. mfspr r3,SPRN_PVR
  310. srwi r3,r3,16
  311. cmplwi cr0,r3,0x8000 /* 7450 */
  312. cmplwi cr1,r3,0x000c /* 7400 */
  313. cmplwi cr2,r3,0x800c /* 7410 */
  314. cmplwi cr3,r3,0x8001 /* 7455 */
  315. cmplwi cr4,r3,0x8002 /* 7457 */
  316. cmplwi cr5,r3,0x8003 /* 7447A */
  317. cmplwi cr6,r3,0x7000 /* 750FX */
  318. cmplwi cr7,r3,0x8004 /* 7448 */
  319. /* cr1 is 7400 || 7410 */
  320. cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
  321. /* cr0 is 74xx */
  322. cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
  323. cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
  324. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  325. cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
  326. cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
  327. bne 1f
  328. /* Backup 74xx specific regs */
  329. mfspr r4,SPRN_MSSCR0
  330. stw r4,CS_MSSCR0(r5)
  331. mfspr r4,SPRN_MSSSR0
  332. stw r4,CS_MSSSR0(r5)
  333. beq cr1,1f
  334. /* Backup 745x specific registers */
  335. mfspr r4,SPRN_HID1
  336. stw r4,CS_HID1(r5)
  337. mfspr r4,SPRN_ICTRL
  338. stw r4,CS_ICTRL(r5)
  339. mfspr r4,SPRN_LDSTCR
  340. stw r4,CS_LDSTCR(r5)
  341. mfspr r4,SPRN_LDSTDB
  342. stw r4,CS_LDSTDB(r5)
  343. 1:
  344. bne cr6,1f
  345. /* Backup 750FX specific registers */
  346. mfspr r4,SPRN_HID1
  347. stw r4,CS_HID1(r5)
  348. /* If rev 2.x, backup HID2 */
  349. mfspr r3,SPRN_PVR
  350. andi. r3,r3,0xff00
  351. cmpwi cr0,r3,0x0200
  352. bne 1f
  353. mfspr r4,SPRN_HID2
  354. stw r4,CS_HID2(r5)
  355. 1:
  356. mtcr r7
  357. blr
  358. /* Called with no MMU context (typically MSR:IR/DR off) to
  359. * restore CPU state as backed up by the previous
  360. * function. This does not include cache setting
  361. */
  362. _GLOBAL(__restore_cpu_setup)
  363. /* Some CR fields are volatile, we back it up all */
  364. mfcr r7
  365. /* Get storage ptr */
  366. lis r5,(cpu_state_storage-KERNELBASE)@h
  367. ori r5,r5,cpu_state_storage@l
  368. /* Restore HID0 */
  369. lwz r3,CS_HID0(r5)
  370. sync
  371. isync
  372. mtspr SPRN_HID0,r3
  373. sync
  374. isync
  375. /* Now deal with CPU type dependent registers */
  376. mfspr r3,SPRN_PVR
  377. srwi r3,r3,16
  378. cmplwi cr0,r3,0x8000 /* 7450 */
  379. cmplwi cr1,r3,0x000c /* 7400 */
  380. cmplwi cr2,r3,0x800c /* 7410 */
  381. cmplwi cr3,r3,0x8001 /* 7455 */
  382. cmplwi cr4,r3,0x8002 /* 7457 */
  383. cmplwi cr5,r3,0x8003 /* 7447A */
  384. cmplwi cr6,r3,0x7000 /* 750FX */
  385. cmplwi cr7,r3,0x8004 /* 7448 */
  386. /* cr1 is 7400 || 7410 */
  387. cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
  388. /* cr0 is 74xx */
  389. cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
  390. cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
  391. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  392. cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
  393. cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
  394. bne 2f
  395. /* Restore 74xx specific regs */
  396. lwz r4,CS_MSSCR0(r5)
  397. sync
  398. mtspr SPRN_MSSCR0,r4
  399. sync
  400. isync
  401. lwz r4,CS_MSSSR0(r5)
  402. sync
  403. mtspr SPRN_MSSSR0,r4
  404. sync
  405. isync
  406. bne cr2,1f
  407. /* Clear 7410 L2CR2 */
  408. li r4,0
  409. mtspr SPRN_L2CR2,r4
  410. 1: beq cr1,2f
  411. /* Restore 745x specific registers */
  412. lwz r4,CS_HID1(r5)
  413. sync
  414. mtspr SPRN_HID1,r4
  415. isync
  416. sync
  417. lwz r4,CS_ICTRL(r5)
  418. sync
  419. mtspr SPRN_ICTRL,r4
  420. isync
  421. sync
  422. lwz r4,CS_LDSTCR(r5)
  423. sync
  424. mtspr SPRN_LDSTCR,r4
  425. isync
  426. sync
  427. lwz r4,CS_LDSTDB(r5)
  428. sync
  429. mtspr SPRN_LDSTDB,r4
  430. isync
  431. sync
  432. 2: bne cr6,1f
  433. /* Restore 750FX specific registers
  434. * that is restore HID2 on rev 2.x and PLL config & switch
  435. * to PLL 0 on all
  436. */
  437. /* If rev 2.x, restore HID2 with low voltage bit cleared */
  438. mfspr r3,SPRN_PVR
  439. andi. r3,r3,0xff00
  440. cmpwi cr0,r3,0x0200
  441. bne 4f
  442. lwz r4,CS_HID2(r5)
  443. rlwinm r4,r4,0,19,17
  444. mtspr SPRN_HID2,r4
  445. sync
  446. 4:
  447. lwz r4,CS_HID1(r5)
  448. rlwinm r5,r4,0,16,14
  449. mtspr SPRN_HID1,r5
  450. /* Wait for PLL to stabilize */
  451. mftbl r5
  452. 3: mftbl r6
  453. sub r6,r6,r5
  454. cmplwi cr0,r6,10000
  455. ble 3b
  456. /* Setup final PLL */
  457. mtspr SPRN_HID1,r4
  458. 1:
  459. mtcr r7
  460. blr
  461. _ASM_NOKPROBE_SYMBOL(__restore_cpu_setup)