cpu_setup_6xx.S 11 KB

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