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