release.S 11 KB

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