cpu_setup_6xx.S 11 KB

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