release.S 11 KB

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