cpu_setup_6xx.S 11 KB

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