release.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*
  2. * Copyright 2008-2012 Freescale Semiconductor, Inc.
  3. * Kumar Gala <kumar.gala@freescale.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <asm-offsets.h>
  24. #include <config.h>
  25. #include <mpc85xx.h>
  26. #include <version.h>
  27. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  28. #include <ppc_asm.tmpl>
  29. #include <ppc_defs.h>
  30. #include <asm/cache.h>
  31. #include <asm/mmu.h>
  32. /* To boot secondary cpus, we need a place for them to start up.
  33. * Normally, they start at 0xfffffffc, but that's usually the
  34. * firmware, and we don't want to have to run the firmware again.
  35. * Instead, the primary cpu will set the BPTR to point here to
  36. * this page. We then set up the core, and head to
  37. * start_secondary. Note that this means that the code below
  38. * must never exceed 1023 instructions (the branch at the end
  39. * would then be the 1024th).
  40. */
  41. .globl __secondary_start_page
  42. .align 12
  43. __secondary_start_page:
  44. /* First do some preliminary setup */
  45. lis r3, HID0_EMCP@h /* enable machine check */
  46. #ifndef CONFIG_E500MC
  47. ori r3,r3,HID0_TBEN@l /* enable Timebase */
  48. #endif
  49. #ifdef CONFIG_PHYS_64BIT
  50. ori r3,r3,HID0_ENMAS7@l /* enable MAS7 updates */
  51. #endif
  52. mtspr SPRN_HID0,r3
  53. #ifndef CONFIG_E500MC
  54. li r3,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
  55. mfspr r0,PVR
  56. andi. r0,r0,0xff
  57. cmpwi r0,0x50@l /* if we are rev 5.0 or greater set MBDD */
  58. blt 1f
  59. /* Set MBDD bit also */
  60. ori r3, r3, HID1_MBDD@l
  61. 1:
  62. mtspr SPRN_HID1,r3
  63. #endif
  64. #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
  65. mfspr r3,977
  66. oris r3,r3,0x0100
  67. mtspr 977,r3
  68. #endif
  69. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  70. mfspr r3,SPRN_SVR
  71. rlwinm r3,r3,0,0xff
  72. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
  73. cmpw r3,r4
  74. beq 1f
  75. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  76. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  77. cmpw r3,r4
  78. beq 1f
  79. #endif
  80. /* Not a supported revision affected by erratum */
  81. b 2f
  82. 1: /* Erratum says set bits 55:60 to 001001 */
  83. msync
  84. isync
  85. mfspr r3,976
  86. li r4,0x48
  87. rlwimi r3,r4,0,0x1f8
  88. mtspr 976,r3
  89. isync
  90. 2:
  91. #endif
  92. /* Enable branch prediction */
  93. lis r3,BUCSR_ENABLE@h
  94. ori r3,r3,BUCSR_ENABLE@l
  95. mtspr SPRN_BUCSR,r3
  96. /* Ensure TB is 0 */
  97. li r3,0
  98. mttbl r3
  99. mttbu r3
  100. /* Enable/invalidate the I-Cache */
  101. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  102. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  103. mtspr SPRN_L1CSR1,r2
  104. 1:
  105. mfspr r3,SPRN_L1CSR1
  106. and. r1,r3,r2
  107. bne 1b
  108. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  109. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  110. mtspr SPRN_L1CSR1,r3
  111. isync
  112. 2:
  113. mfspr r3,SPRN_L1CSR1
  114. andi. r1,r3,L1CSR1_ICE@l
  115. beq 2b
  116. /* Enable/invalidate the D-Cache */
  117. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  118. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  119. mtspr SPRN_L1CSR0,r2
  120. 1:
  121. mfspr r3,SPRN_L1CSR0
  122. and. r1,r3,r2
  123. bne 1b
  124. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  125. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  126. mtspr SPRN_L1CSR0,r3
  127. isync
  128. 2:
  129. mfspr r3,SPRN_L1CSR0
  130. andi. r1,r3,L1CSR0_DCE@l
  131. beq 2b
  132. #define toreset(x) (x - __secondary_start_page + 0xfffff000)
  133. /* get our PIR to figure out our table entry */
  134. lis r3,toreset(__spin_table_addr)@h
  135. ori r3,r3,toreset(__spin_table_addr)@l
  136. lwz r3,0(r3)
  137. /*
  138. * r10 has the base address for the entry.
  139. * we cannot access it yet before setting up a new TLB
  140. */
  141. mfspr r0,SPRN_PIR
  142. #if defined(CONFIG_E6500)
  143. /*
  144. * PIR definition for E6500
  145. * 0-17 Reserved (logic 0s)
  146. * 8-19 CHIP_ID, 2'b00 - SoC 1
  147. * all others - reserved
  148. * 20-24 CLUSTER_ID 5'b00000 - CCM 1
  149. * all others - reserved
  150. * 25-26 CORE_CLUSTER_ID 2'b00 - cluster 1
  151. * 2'b01 - cluster 2
  152. * 2'b10 - cluster 3
  153. * 2'b11 - cluster 4
  154. * 27-28 CORE_ID 2'b00 - core 0
  155. * 2'b01 - core 1
  156. * 2'b10 - core 2
  157. * 2'b11 - core 3
  158. * 29-31 THREAD_ID 3'b000 - thread 0
  159. * 3'b001 - thread 1
  160. */
  161. rlwinm r4,r0,29,25,31
  162. #elif defined(CONFIG_E500MC)
  163. rlwinm r4,r0,27,27,31
  164. #else
  165. mr r4,r0
  166. #endif
  167. slwi r8,r4,6 /* spin table is padded to 64 byte */
  168. add r10,r3,r8
  169. #ifdef CONFIG_E6500
  170. mfspr r0,SPRN_PIR
  171. /*
  172. * core 0 thread 0: pir reset value 0x00, new pir 0
  173. * core 0 thread 1: pir reset value 0x01, new pir 1
  174. * core 1 thread 0: pir reset value 0x08, new pir 2
  175. * core 1 thread 1: pir reset value 0x09, new pir 3
  176. * core 2 thread 0: pir reset value 0x10, new pir 4
  177. * core 2 thread 1: pir reset value 0x11, new pir 5
  178. * etc.
  179. *
  180. * Only thread 0 of each core will be running, updating PIR doesn't
  181. * need to deal with the thread bits.
  182. */
  183. rlwinm r4,r0,30,24,30
  184. #endif
  185. mtspr SPRN_PIR,r4 /* write to PIR register */
  186. #ifdef CONFIG_SYS_CACHE_STASHING
  187. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  188. slwi r8,r4,1
  189. addi r8,r8,32
  190. mtspr L1CSR2,r8
  191. #endif
  192. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
  193. defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
  194. /*
  195. * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  196. * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  197. * also appleis to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1
  198. */
  199. mfspr r3,SPRN_SVR
  200. rlwinm r6,r3,24,~0x800 /* clear E bit */
  201. lis r5,SVR_P4080@h
  202. ori r5,r5,SVR_P4080@l
  203. cmpw r6,r5
  204. bne 1f
  205. rlwinm r3,r3,0,0xf0
  206. li r5,0x30
  207. cmpw r3,r5
  208. bge 2f
  209. 1:
  210. #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011
  211. lis r3,toreset(enable_cpu_a011_workaround)@ha
  212. lwz r3,toreset(enable_cpu_a011_workaround)@l(r3)
  213. cmpwi r3,0
  214. beq 2f
  215. #endif
  216. mfspr r3,L1CSR2
  217. oris r3,r3,(L1CSR2_DCWS)@h
  218. mtspr L1CSR2,r3
  219. 2:
  220. #endif
  221. #ifdef CONFIG_BACKSIDE_L2_CACHE
  222. /* skip L2 setup on P2040/P2040E as they have no L2 */
  223. mfspr r3,SPRN_SVR
  224. rlwinm r6,r3,24,~0x800 /* clear E bit of SVR */
  225. lis r3,SVR_P2040@h
  226. ori r3,r3,SVR_P2040@l
  227. cmpw r6,r3
  228. beq 3f
  229. /* Enable/invalidate the L2 cache */
  230. msync
  231. lis r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h
  232. ori r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l
  233. mtspr SPRN_L2CSR0,r2
  234. 1:
  235. mfspr r3,SPRN_L2CSR0
  236. and. r1,r3,r2
  237. bne 1b
  238. #ifdef CONFIG_SYS_CACHE_STASHING
  239. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  240. addi r3,r8,1
  241. mtspr SPRN_L2CSR1,r3
  242. #endif
  243. lis r3,CONFIG_SYS_INIT_L2CSR0@h
  244. ori r3,r3,CONFIG_SYS_INIT_L2CSR0@l
  245. mtspr SPRN_L2CSR0,r3
  246. isync
  247. 2:
  248. mfspr r3,SPRN_L2CSR0
  249. andis. r1,r3,L2CSR0_L2E@h
  250. beq 2b
  251. #endif
  252. 3:
  253. /* setup mapping for the spin table, WIMGE=0b00100 */
  254. lis r13,toreset(__spin_table_addr)@h
  255. ori r13,r13,toreset(__spin_table_addr)@l
  256. lwz r13,0(r13)
  257. /* mask by 4K */
  258. rlwinm r13,r13,0,0,19
  259. lis r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h
  260. mtspr SPRN_MAS0,r11
  261. lis r11,(MAS1_VALID|MAS1_IPROT)@h
  262. ori r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
  263. mtspr SPRN_MAS1,r11
  264. oris r11,r13,(MAS2_M|MAS2_G)@h
  265. ori r11,r13,(MAS2_M|MAS2_G)@l
  266. mtspr SPRN_MAS2,r11
  267. oris r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h
  268. ori r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l
  269. mtspr SPRN_MAS3,r11
  270. li r11,0
  271. mtspr SPRN_MAS7,r11
  272. tlbwe
  273. /*
  274. * __bootpg_addr has the address of __second_half_boot_page
  275. * jump there in AS=1 space with cache enabled
  276. */
  277. lis r13,toreset(__bootpg_addr)@h
  278. ori r13,r13,toreset(__bootpg_addr)@l
  279. lwz r11,0(r13)
  280. mtspr SPRN_SRR0,r11
  281. mfmsr r13
  282. ori r12,r13,MSR_IS|MSR_DS@l
  283. mtspr SPRN_SRR1,r12
  284. rfi
  285. /*
  286. * Allocate some space for the SDRAM address of the bootpg.
  287. * This variable has to be in the boot page so that it can
  288. * be accessed by secondary cores when they come out of reset.
  289. */
  290. .align L1_CACHE_SHIFT
  291. .globl __bootpg_addr
  292. __bootpg_addr:
  293. .long 0
  294. .global __spin_table_addr
  295. __spin_table_addr:
  296. .long 0
  297. /*
  298. * This variable is set by cpu_init_r() after parsing hwconfig
  299. * to enable workaround for erratum NMG_CPU_A011.
  300. */
  301. .align L1_CACHE_SHIFT
  302. .global enable_cpu_a011_workaround
  303. enable_cpu_a011_workaround:
  304. .long 1
  305. /* Fill in the empty space. The actual reset vector is
  306. * the last word of the page */
  307. __secondary_start_code_end:
  308. .space 4092 - (__secondary_start_code_end - __secondary_start_page)
  309. __secondary_reset_vector:
  310. b __secondary_start_page
  311. /* this is a separated page for the spin table and cacheable boot code */
  312. .align L1_CACHE_SHIFT
  313. .global __second_half_boot_page
  314. __second_half_boot_page:
  315. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  316. lis r3,(spin_table_compat - __second_half_boot_page)@h
  317. ori r3,r3,(spin_table_compat - __second_half_boot_page)@l
  318. add r3,r3,r11 /* r11 has the address of __second_half_boot_page */
  319. lwz r14,0(r3)
  320. #endif
  321. #define ENTRY_ADDR_UPPER 0
  322. #define ENTRY_ADDR_LOWER 4
  323. #define ENTRY_R3_UPPER 8
  324. #define ENTRY_R3_LOWER 12
  325. #define ENTRY_RESV 16
  326. #define ENTRY_PIR 20
  327. #define ENTRY_SIZE 64
  328. /*
  329. * setup the entry
  330. * r10 has the base address of the spin table.
  331. * spin table is defined as
  332. * struct {
  333. * uint64_t entry_addr;
  334. * uint64_t r3;
  335. * uint32_t rsvd1;
  336. * uint32_t pir;
  337. * };
  338. * we pad this struct to 64 bytes so each entry is in its own cacheline
  339. */
  340. li r3,0
  341. li r8,1
  342. mfspr r4,SPRN_PIR
  343. stw r3,ENTRY_ADDR_UPPER(r10)
  344. stw r3,ENTRY_R3_UPPER(r10)
  345. stw r4,ENTRY_R3_LOWER(r10)
  346. stw r3,ENTRY_RESV(r10)
  347. stw r4,ENTRY_PIR(r10)
  348. msync
  349. stw r8,ENTRY_ADDR_LOWER(r10)
  350. /* spin waiting for addr */
  351. 3:
  352. /*
  353. * To comply with ePAPR 1.1, the spin table has been moved to cache-enabled
  354. * memory. Old OS may not work with this change. A patch is waiting to be
  355. * accepted for Linux kernel. Other OS needs similar fix to spin table.
  356. * For OSes with old spin table code, we can enable this temporary fix by
  357. * setting environmental variable "spin_table_compat". For new OSes, set
  358. * "spin_table_compat=no". After Linux is fixed, we can remove this macro
  359. * and related code. For now, it is enabled by default.
  360. */
  361. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  362. cmpwi r14,0
  363. beq 4f
  364. dcbf 0, r10
  365. sync
  366. 4:
  367. #endif
  368. lwz r4,ENTRY_ADDR_LOWER(r10)
  369. andi. r11,r4,1
  370. bne 3b
  371. isync
  372. /* setup IVORs to match fixed offsets */
  373. #include "fixed_ivor.S"
  374. /* get the upper bits of the addr */
  375. lwz r11,ENTRY_ADDR_UPPER(r10)
  376. /* setup branch addr */
  377. mtspr SPRN_SRR0,r4
  378. /* mark the entry as released */
  379. li r8,3
  380. stw r8,ENTRY_ADDR_LOWER(r10)
  381. /* mask by ~64M to setup our tlb we will jump to */
  382. rlwinm r12,r4,0,0,5
  383. /*
  384. * setup r3, r4, r5, r6, r7, r8, r9
  385. * r3 contains the value to put in the r3 register at secondary cpu
  386. * entry. The high 32-bits are ignored on 32-bit chip implementations.
  387. * 64-bit chip implementations however shall load all 64-bits
  388. */
  389. #ifdef CONFIG_SYS_PPC64
  390. ld r3,ENTRY_R3_UPPER(r10)
  391. #else
  392. lwz r3,ENTRY_R3_LOWER(r10)
  393. #endif
  394. li r4,0
  395. li r5,0
  396. li r6,0
  397. lis r7,(64*1024*1024)@h
  398. li r8,0
  399. li r9,0
  400. /* load up the pir */
  401. lwz r0,ENTRY_PIR(r10)
  402. mtspr SPRN_PIR,r0
  403. mfspr r0,SPRN_PIR
  404. stw r0,ENTRY_PIR(r10)
  405. mtspr IVPR,r12
  406. /*
  407. * Coming here, we know the cpu has one TLB mapping in TLB1[0]
  408. * which maps 0xfffff000-0xffffffff one-to-one. We set up a
  409. * second mapping that maps addr 1:1 for 64M, and then we jump to
  410. * addr
  411. */
  412. lis r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h
  413. mtspr SPRN_MAS0,r10
  414. lis r10,(MAS1_VALID|MAS1_IPROT)@h
  415. ori r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
  416. mtspr SPRN_MAS1,r10
  417. /* WIMGE = 0b00000 for now */
  418. mtspr SPRN_MAS2,r12
  419. ori r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR)
  420. mtspr SPRN_MAS3,r12
  421. #ifdef CONFIG_ENABLE_36BIT_PHYS
  422. mtspr SPRN_MAS7,r11
  423. #endif
  424. tlbwe
  425. /* Now we have another mapping for this page, so we jump to that
  426. * mapping
  427. */
  428. mtspr SPRN_SRR1,r13
  429. rfi
  430. .align 6
  431. .globl __spin_table
  432. __spin_table:
  433. .space CONFIG_MAX_CPUS*ENTRY_SIZE
  434. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  435. .align L1_CACHE_SHIFT
  436. .global spin_table_compat
  437. spin_table_compat:
  438. .long 1
  439. #endif
  440. __spin_table_end:
  441. .space 4096 - (__spin_table_end - __spin_table)