release.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright 2008-2010 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. /* Enable branch prediction */
  65. lis r3,BUCSR_ENABLE@h
  66. ori r3,r3,BUCSR_ENABLE@l
  67. mtspr SPRN_BUCSR,r3
  68. /* Ensure TB is 0 */
  69. li r3,0
  70. mttbl r3
  71. mttbu r3
  72. /* Enable/invalidate the I-Cache */
  73. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  74. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  75. mtspr SPRN_L1CSR1,r2
  76. 1:
  77. mfspr r3,SPRN_L1CSR1
  78. and. r1,r3,r2
  79. bne 1b
  80. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  81. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  82. mtspr SPRN_L1CSR1,r3
  83. isync
  84. 2:
  85. mfspr r3,SPRN_L1CSR1
  86. andi. r1,r3,L1CSR1_ICE@l
  87. beq 2b
  88. /* Enable/invalidate the D-Cache */
  89. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  90. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  91. mtspr SPRN_L1CSR0,r2
  92. 1:
  93. mfspr r3,SPRN_L1CSR0
  94. and. r1,r3,r2
  95. bne 1b
  96. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  97. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  98. mtspr SPRN_L1CSR0,r3
  99. isync
  100. 2:
  101. mfspr r3,SPRN_L1CSR0
  102. andi. r1,r3,L1CSR0_DCE@l
  103. beq 2b
  104. #define toreset(x) (x - __secondary_start_page + 0xfffff000)
  105. /* get our PIR to figure out our table entry */
  106. lis r3,toreset(__spin_table)@h
  107. ori r3,r3,toreset(__spin_table)@l
  108. /* r10 has the base address for the entry */
  109. mfspr r0,SPRN_PIR
  110. #ifdef CONFIG_E500MC
  111. rlwinm r4,r0,27,27,31
  112. #else
  113. mr r4,r0
  114. #endif
  115. slwi r8,r4,5
  116. add r10,r3,r8
  117. #if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING)
  118. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  119. slwi r8,r4,1
  120. addi r8,r8,32
  121. mtspr L1CSR2,r8
  122. #endif
  123. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22)
  124. mfspr r8,L1CSR2
  125. oris r8,r8,(L1CSR2_DCWS)@h
  126. mtspr L1CSR2,r8
  127. #endif
  128. #ifdef CONFIG_BACKSIDE_L2_CACHE
  129. /* Enable/invalidate the L2 cache */
  130. msync
  131. lis r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h
  132. ori r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l
  133. mtspr SPRN_L2CSR0,r2
  134. 1:
  135. mfspr r3,SPRN_L2CSR0
  136. and. r1,r3,r2
  137. bne 1b
  138. #ifdef CONFIG_SYS_CACHE_STASHING
  139. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  140. addi r3,r8,1
  141. mtspr SPRN_L2CSR1,r3
  142. #endif
  143. lis r3,CONFIG_SYS_INIT_L2CSR0@h
  144. ori r3,r3,CONFIG_SYS_INIT_L2CSR0@l
  145. mtspr SPRN_L2CSR0,r3
  146. isync
  147. 2:
  148. mfspr r3,SPRN_L2CSR0
  149. andis. r1,r3,L2CSR0_L2E@h
  150. beq 2b
  151. #endif
  152. #define EPAPR_MAGIC (0x45504150)
  153. #define ENTRY_ADDR_UPPER 0
  154. #define ENTRY_ADDR_LOWER 4
  155. #define ENTRY_R3_UPPER 8
  156. #define ENTRY_R3_LOWER 12
  157. #define ENTRY_RESV 16
  158. #define ENTRY_PIR 20
  159. #define ENTRY_R6_UPPER 24
  160. #define ENTRY_R6_LOWER 28
  161. #define ENTRY_SIZE 32
  162. /* setup the entry */
  163. li r3,0
  164. li r8,1
  165. stw r0,ENTRY_PIR(r10)
  166. stw r3,ENTRY_ADDR_UPPER(r10)
  167. stw r8,ENTRY_ADDR_LOWER(r10)
  168. stw r3,ENTRY_R3_UPPER(r10)
  169. stw r4,ENTRY_R3_LOWER(r10)
  170. stw r3,ENTRY_R6_UPPER(r10)
  171. stw r3,ENTRY_R6_LOWER(r10)
  172. /* load r13 with the address of the 'bootpg' in SDRAM */
  173. lis r13,toreset(__bootpg_addr)@h
  174. ori r13,r13,toreset(__bootpg_addr)@l
  175. lwz r13,0(r13)
  176. /* setup mapping for AS = 1, and jump there */
  177. lis r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h
  178. mtspr SPRN_MAS0,r11
  179. lis r11,(MAS1_VALID|MAS1_IPROT)@h
  180. ori r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
  181. mtspr SPRN_MAS1,r11
  182. oris r11,r13,(MAS2_I|MAS2_G)@h
  183. ori r11,r13,(MAS2_I|MAS2_G)@l
  184. mtspr SPRN_MAS2,r11
  185. oris r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h
  186. ori r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l
  187. mtspr SPRN_MAS3,r11
  188. tlbwe
  189. bl 1f
  190. 1: mflr r11
  191. /*
  192. * OR in 0xfff to create a mask of the bootpg SDRAM address. We use
  193. * this mask to fixup the cpu spin table and the address that we want
  194. * to jump to, eg change them from 0xfffffxxx to 0x7ffffxxx if the
  195. * bootpg is at 0x7ffff000 in SDRAM.
  196. */
  197. ori r13,r13,0xfff
  198. and r11, r11, r13
  199. and r10, r10, r13
  200. addi r11,r11,(2f-1b)
  201. mfmsr r13
  202. ori r12,r13,MSR_IS|MSR_DS@l
  203. mtspr SPRN_SRR0,r11
  204. mtspr SPRN_SRR1,r12
  205. rfi
  206. /* spin waiting for addr */
  207. 2:
  208. lwz r4,ENTRY_ADDR_LOWER(r10)
  209. andi. r11,r4,1
  210. bne 2b
  211. isync
  212. /* setup IVORs to match fixed offsets */
  213. #include "fixed_ivor.S"
  214. /* get the upper bits of the addr */
  215. lwz r11,ENTRY_ADDR_UPPER(r10)
  216. /* setup branch addr */
  217. mtspr SPRN_SRR0,r4
  218. /* mark the entry as released */
  219. li r8,3
  220. stw r8,ENTRY_ADDR_LOWER(r10)
  221. /* mask by ~64M to setup our tlb we will jump to */
  222. rlwinm r12,r4,0,0,5
  223. /* setup r3, r4, r5, r6, r7, r8, r9 */
  224. lwz r3,ENTRY_R3_LOWER(r10)
  225. li r4,0
  226. li r5,0
  227. lwz r6,ENTRY_R6_LOWER(r10)
  228. lis r7,(64*1024*1024)@h
  229. li r8,0
  230. li r9,0
  231. /* load up the pir */
  232. lwz r0,ENTRY_PIR(r10)
  233. mtspr SPRN_PIR,r0
  234. mfspr r0,SPRN_PIR
  235. stw r0,ENTRY_PIR(r10)
  236. mtspr IVPR,r12
  237. /*
  238. * Coming here, we know the cpu has one TLB mapping in TLB1[0]
  239. * which maps 0xfffff000-0xffffffff one-to-one. We set up a
  240. * second mapping that maps addr 1:1 for 64M, and then we jump to
  241. * addr
  242. */
  243. lis r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h
  244. mtspr SPRN_MAS0,r10
  245. lis r10,(MAS1_VALID|MAS1_IPROT)@h
  246. ori r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
  247. mtspr SPRN_MAS1,r10
  248. /* WIMGE = 0b00000 for now */
  249. mtspr SPRN_MAS2,r12
  250. ori r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR)
  251. mtspr SPRN_MAS3,r12
  252. #ifdef CONFIG_ENABLE_36BIT_PHYS
  253. mtspr SPRN_MAS7,r11
  254. #endif
  255. tlbwe
  256. /* Now we have another mapping for this page, so we jump to that
  257. * mapping
  258. */
  259. mtspr SPRN_SRR1,r13
  260. rfi
  261. /*
  262. * Allocate some space for the SDRAM address of the bootpg.
  263. * This variable has to be in the boot page so that it can
  264. * be accessed by secondary cores when they come out of reset.
  265. */
  266. .globl __bootpg_addr
  267. __bootpg_addr:
  268. .long 0
  269. .align L1_CACHE_SHIFT
  270. .globl __spin_table
  271. __spin_table:
  272. .space CONFIG_MAX_CPUS*ENTRY_SIZE
  273. /* Fill in the empty space. The actual reset vector is
  274. * the last word of the page */
  275. __secondary_start_code_end:
  276. .space 4092 - (__secondary_start_code_end - __secondary_start_page)
  277. __secondary_reset_vector:
  278. b __secondary_start_page