release.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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_CACHE_STASHING
  164. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  165. slwi r8,r4,1
  166. addi r8,r8,32
  167. mtspr L1CSR2,r8
  168. #endif
  169. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
  170. defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
  171. /*
  172. * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  173. * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  174. * also appleis to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1
  175. */
  176. mfspr r3,SPRN_SVR
  177. rlwinm r6,r3,24,~0x800 /* clear E bit */
  178. lis r5,SVR_P4080@h
  179. ori r5,r5,SVR_P4080@l
  180. cmpw r6,r5
  181. bne 1f
  182. rlwinm r3,r3,0,0xf0
  183. li r5,0x30
  184. cmpw r3,r5
  185. bge 2f
  186. 1:
  187. #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011
  188. lis r3,toreset(enable_cpu_a011_workaround)@ha
  189. lwz r3,toreset(enable_cpu_a011_workaround)@l(r3)
  190. cmpwi r3,0
  191. beq 2f
  192. #endif
  193. mfspr r3,L1CSR2
  194. oris r3,r3,(L1CSR2_DCWS)@h
  195. mtspr L1CSR2,r3
  196. 2:
  197. #endif
  198. #ifdef CONFIG_SYS_FSL_ERRATUM_A005812
  199. /*
  200. * A-005812 workaround sets bit 32 of SPR 976 for SoCs running in
  201. * write shadow mode. This code should run after other code setting
  202. * DCWS.
  203. */
  204. mfspr r3,L1CSR2
  205. andis. r3,r3,(L1CSR2_DCWS)@h
  206. beq 1f
  207. mfspr r3, SPRN_HDBCR0
  208. oris r3, r3, 0x8000
  209. mtspr SPRN_HDBCR0, r3
  210. 1:
  211. #endif
  212. #ifdef CONFIG_BACKSIDE_L2_CACHE
  213. /* skip L2 setup on P2040/P2040E as they have no L2 */
  214. mfspr r3,SPRN_SVR
  215. rlwinm r6,r3,24,~0x800 /* clear E bit of SVR */
  216. lis r3,SVR_P2040@h
  217. ori r3,r3,SVR_P2040@l
  218. cmpw r6,r3
  219. beq 3f
  220. /* Enable/invalidate the L2 cache */
  221. msync
  222. lis r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h
  223. ori r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l
  224. mtspr SPRN_L2CSR0,r2
  225. 1:
  226. mfspr r3,SPRN_L2CSR0
  227. and. r1,r3,r2
  228. bne 1b
  229. #ifdef CONFIG_SYS_CACHE_STASHING
  230. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  231. addi r3,r8,1
  232. mtspr SPRN_L2CSR1,r3
  233. #endif
  234. lis r3,CONFIG_SYS_INIT_L2CSR0@h
  235. ori r3,r3,CONFIG_SYS_INIT_L2CSR0@l
  236. mtspr SPRN_L2CSR0,r3
  237. isync
  238. 2:
  239. mfspr r3,SPRN_L2CSR0
  240. andis. r1,r3,L2CSR0_L2E@h
  241. beq 2b
  242. #endif
  243. 3:
  244. /* setup mapping for the spin table, WIMGE=0b00100 */
  245. lis r13,toreset(__spin_table_addr)@h
  246. ori r13,r13,toreset(__spin_table_addr)@l
  247. lwz r13,0(r13)
  248. /* mask by 4K */
  249. rlwinm r13,r13,0,0,19
  250. lis r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h
  251. mtspr SPRN_MAS0,r11
  252. lis r11,(MAS1_VALID|MAS1_IPROT)@h
  253. ori r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
  254. mtspr SPRN_MAS1,r11
  255. oris r11,r13,(MAS2_M|MAS2_G)@h
  256. ori r11,r13,(MAS2_M|MAS2_G)@l
  257. mtspr SPRN_MAS2,r11
  258. oris r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h
  259. ori r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l
  260. mtspr SPRN_MAS3,r11
  261. li r11,0
  262. mtspr SPRN_MAS7,r11
  263. tlbwe
  264. /*
  265. * __bootpg_addr has the address of __second_half_boot_page
  266. * jump there in AS=1 space with cache enabled
  267. */
  268. lis r13,toreset(__bootpg_addr)@h
  269. ori r13,r13,toreset(__bootpg_addr)@l
  270. lwz r11,0(r13)
  271. mtspr SPRN_SRR0,r11
  272. mfmsr r13
  273. ori r12,r13,MSR_IS|MSR_DS@l
  274. mtspr SPRN_SRR1,r12
  275. rfi
  276. /*
  277. * Allocate some space for the SDRAM address of the bootpg.
  278. * This variable has to be in the boot page so that it can
  279. * be accessed by secondary cores when they come out of reset.
  280. */
  281. .align L1_CACHE_SHIFT
  282. .globl __bootpg_addr
  283. __bootpg_addr:
  284. .long 0
  285. .global __spin_table_addr
  286. __spin_table_addr:
  287. .long 0
  288. /*
  289. * This variable is set by cpu_init_r() after parsing hwconfig
  290. * to enable workaround for erratum NMG_CPU_A011.
  291. */
  292. .align L1_CACHE_SHIFT
  293. .global enable_cpu_a011_workaround
  294. enable_cpu_a011_workaround:
  295. .long 1
  296. /* Fill in the empty space. The actual reset vector is
  297. * the last word of the page */
  298. __secondary_start_code_end:
  299. .space 4092 - (__secondary_start_code_end - __secondary_start_page)
  300. __secondary_reset_vector:
  301. b __secondary_start_page
  302. /* this is a separated page for the spin table and cacheable boot code */
  303. .align L1_CACHE_SHIFT
  304. .global __second_half_boot_page
  305. __second_half_boot_page:
  306. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  307. lis r3,(spin_table_compat - __second_half_boot_page)@h
  308. ori r3,r3,(spin_table_compat - __second_half_boot_page)@l
  309. add r3,r3,r11 /* r11 has the address of __second_half_boot_page */
  310. lwz r14,0(r3)
  311. #endif
  312. #define ENTRY_ADDR_UPPER 0
  313. #define ENTRY_ADDR_LOWER 4
  314. #define ENTRY_R3_UPPER 8
  315. #define ENTRY_R3_LOWER 12
  316. #define ENTRY_RESV 16
  317. #define ENTRY_PIR 20
  318. #define ENTRY_SIZE 64
  319. /*
  320. * setup the entry
  321. * r10 has the base address of the spin table.
  322. * spin table is defined as
  323. * struct {
  324. * uint64_t entry_addr;
  325. * uint64_t r3;
  326. * uint32_t rsvd1;
  327. * uint32_t pir;
  328. * };
  329. * we pad this struct to 64 bytes so each entry is in its own cacheline
  330. */
  331. li r3,0
  332. li r8,1
  333. mfspr r4,SPRN_PIR
  334. stw r3,ENTRY_ADDR_UPPER(r10)
  335. stw r3,ENTRY_R3_UPPER(r10)
  336. stw r4,ENTRY_R3_LOWER(r10)
  337. stw r3,ENTRY_RESV(r10)
  338. stw r4,ENTRY_PIR(r10)
  339. msync
  340. stw r8,ENTRY_ADDR_LOWER(r10)
  341. /* spin waiting for addr */
  342. 3:
  343. /*
  344. * To comply with ePAPR 1.1, the spin table has been moved to cache-enabled
  345. * memory. Old OS may not work with this change. A patch is waiting to be
  346. * accepted for Linux kernel. Other OS needs similar fix to spin table.
  347. * For OSes with old spin table code, we can enable this temporary fix by
  348. * setting environmental variable "spin_table_compat". For new OSes, set
  349. * "spin_table_compat=no". After Linux is fixed, we can remove this macro
  350. * and related code. For now, it is enabled by default.
  351. */
  352. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  353. cmpwi r14,0
  354. beq 4f
  355. dcbf 0, r10
  356. sync
  357. 4:
  358. #endif
  359. lwz r4,ENTRY_ADDR_LOWER(r10)
  360. andi. r11,r4,1
  361. bne 3b
  362. isync
  363. /* get the upper bits of the addr */
  364. lwz r11,ENTRY_ADDR_UPPER(r10)
  365. /* setup branch addr */
  366. mtspr SPRN_SRR0,r4
  367. /* mark the entry as released */
  368. li r8,3
  369. stw r8,ENTRY_ADDR_LOWER(r10)
  370. /* mask by ~64M to setup our tlb we will jump to */
  371. rlwinm r12,r4,0,0,5
  372. /*
  373. * setup r3, r4, r5, r6, r7, r8, r9
  374. * r3 contains the value to put in the r3 register at secondary cpu
  375. * entry. The high 32-bits are ignored on 32-bit chip implementations.
  376. * 64-bit chip implementations however shall load all 64-bits
  377. */
  378. #ifdef CONFIG_SYS_PPC64
  379. ld r3,ENTRY_R3_UPPER(r10)
  380. #else
  381. lwz r3,ENTRY_R3_LOWER(r10)
  382. #endif
  383. li r4,0
  384. li r5,0
  385. li r6,0
  386. lis r7,(64*1024*1024)@h
  387. li r8,0
  388. li r9,0
  389. /* load up the pir */
  390. lwz r0,ENTRY_PIR(r10)
  391. mtspr SPRN_PIR,r0
  392. mfspr r0,SPRN_PIR
  393. stw r0,ENTRY_PIR(r10)
  394. mtspr IVPR,r12
  395. /*
  396. * Coming here, we know the cpu has one TLB mapping in TLB1[0]
  397. * which maps 0xfffff000-0xffffffff one-to-one. We set up a
  398. * second mapping that maps addr 1:1 for 64M, and then we jump to
  399. * addr
  400. */
  401. lis r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h
  402. mtspr SPRN_MAS0,r10
  403. lis r10,(MAS1_VALID|MAS1_IPROT)@h
  404. ori r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
  405. mtspr SPRN_MAS1,r10
  406. /* WIMGE = 0b00000 for now */
  407. mtspr SPRN_MAS2,r12
  408. ori r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR)
  409. mtspr SPRN_MAS3,r12
  410. #ifdef CONFIG_ENABLE_36BIT_PHYS
  411. mtspr SPRN_MAS7,r11
  412. #endif
  413. tlbwe
  414. /* Now we have another mapping for this page, so we jump to that
  415. * mapping
  416. */
  417. mtspr SPRN_SRR1,r13
  418. rfi
  419. .align 6
  420. .globl __spin_table
  421. __spin_table:
  422. .space CONFIG_MAX_CPUS*ENTRY_SIZE
  423. #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
  424. .align L1_CACHE_SHIFT
  425. .global spin_table_compat
  426. spin_table_compat:
  427. .long 1
  428. #endif
  429. __spin_table_end:
  430. .space 4096 - (__spin_table_end - __spin_table)