start.S 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  1. /*
  2. * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2003 Motorola,Inc.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
  8. *
  9. * The processor starts at 0xfffffffc and the code is first executed in the
  10. * last 4K page(0xfffff000-0xffffffff) in flash/rom.
  11. *
  12. */
  13. #include <asm-offsets.h>
  14. #include <config.h>
  15. #include <mpc85xx.h>
  16. #include <version.h>
  17. #include <ppc_asm.tmpl>
  18. #include <ppc_defs.h>
  19. #include <asm/cache.h>
  20. #include <asm/mmu.h>
  21. #undef MSR_KERNEL
  22. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  23. #define LAW_EN 0x80000000
  24. #if defined(CONFIG_NAND_SPL) || \
  25. (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
  26. #define MINIMAL_SPL
  27. #endif
  28. #if !defined(CONFIG_SPL) && !defined(CONFIG_SYS_RAMBOOT) && \
  29. !defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SRIO_PCIE_BOOT_SLAVE)
  30. #define NOR_BOOT
  31. #endif
  32. /*
  33. * Set up GOT: Global Offset Table
  34. *
  35. * Use r12 to access the GOT
  36. */
  37. START_GOT
  38. GOT_ENTRY(_GOT2_TABLE_)
  39. GOT_ENTRY(_FIXUP_TABLE_)
  40. #ifndef MINIMAL_SPL
  41. GOT_ENTRY(_start)
  42. GOT_ENTRY(_start_of_vectors)
  43. GOT_ENTRY(_end_of_vectors)
  44. GOT_ENTRY(transfer_to_handler)
  45. #endif
  46. GOT_ENTRY(__init_end)
  47. GOT_ENTRY(__bss_end)
  48. GOT_ENTRY(__bss_start)
  49. END_GOT
  50. /*
  51. * e500 Startup -- after reset only the last 4KB of the effective
  52. * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
  53. * section is located at THIS LAST page and basically does three
  54. * things: clear some registers, set up exception tables and
  55. * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
  56. * continue the boot procedure.
  57. * Once the boot rom is mapped by TLB entries we can proceed
  58. * with normal startup.
  59. *
  60. */
  61. .section .bootpg,"ax"
  62. .globl _start_e500
  63. _start_e500:
  64. /* Enable debug exception */
  65. li r1,MSR_DE
  66. mtmsr r1
  67. /*
  68. * If we got an ePAPR device tree pointer passed in as r3, we need that
  69. * later in cpu_init_early_f(). Save it to a safe register before we
  70. * clobber it so that we can fetch it from there later.
  71. */
  72. mr r24, r3
  73. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  74. mfspr r3,SPRN_SVR
  75. rlwinm r3,r3,0,0xff
  76. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
  77. cmpw r3,r4
  78. beq 1f
  79. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  80. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  81. cmpw r3,r4
  82. beq 1f
  83. #endif
  84. /* Not a supported revision affected by erratum */
  85. li r27,0
  86. b 2f
  87. 1: li r27,1 /* Remember for later that we have the erratum */
  88. /* Erratum says set bits 55:60 to 001001 */
  89. msync
  90. isync
  91. mfspr r3,SPRN_HDBCR0
  92. li r4,0x48
  93. rlwimi r3,r4,0,0x1f8
  94. mtspr SPRN_HDBCR0,r3
  95. isync
  96. 2:
  97. #endif
  98. #ifdef CONFIG_SYS_FSL_ERRATUM_A005125
  99. msync
  100. isync
  101. mfspr r3, SPRN_HDBCR0
  102. oris r3, r3, 0x0080
  103. mtspr SPRN_HDBCR0, r3
  104. #endif
  105. #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC) && \
  106. !defined(CONFIG_E6500)
  107. /* ISBC uses L2 as stack.
  108. * Disable L2 cache here so that u-boot can enable it later
  109. * as part of it's normal flow
  110. */
  111. /* Check if L2 is enabled */
  112. mfspr r3, SPRN_L2CSR0
  113. lis r2, L2CSR0_L2E@h
  114. ori r2, r2, L2CSR0_L2E@l
  115. and. r4, r3, r2
  116. beq l2_disabled
  117. mfspr r3, SPRN_L2CSR0
  118. /* Flush L2 cache */
  119. lis r2,(L2CSR0_L2FL)@h
  120. ori r2, r2, (L2CSR0_L2FL)@l
  121. or r3, r2, r3
  122. sync
  123. isync
  124. mtspr SPRN_L2CSR0,r3
  125. isync
  126. 1:
  127. mfspr r3, SPRN_L2CSR0
  128. and. r1, r3, r2
  129. bne 1b
  130. mfspr r3, SPRN_L2CSR0
  131. lis r2, L2CSR0_L2E@h
  132. ori r2, r2, L2CSR0_L2E@l
  133. andc r4, r3, r2
  134. sync
  135. isync
  136. mtspr SPRN_L2CSR0,r4
  137. isync
  138. l2_disabled:
  139. #endif
  140. /* clear registers/arrays not reset by hardware */
  141. /* L1 */
  142. li r0,2
  143. mtspr L1CSR0,r0 /* invalidate d-cache */
  144. mtspr L1CSR1,r0 /* invalidate i-cache */
  145. mfspr r1,DBSR
  146. mtspr DBSR,r1 /* Clear all valid bits */
  147. .macro create_tlb1_entry esel ts tsize epn wimg rpn perm phy_high scratch
  148. lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
  149. ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
  150. mtspr MAS0, \scratch
  151. lis \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@h
  152. ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@l
  153. mtspr MAS1, \scratch
  154. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  155. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  156. mtspr MAS2, \scratch
  157. lis \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
  158. ori \scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
  159. mtspr MAS3, \scratch
  160. lis \scratch, \phy_high@h
  161. ori \scratch, \scratch, \phy_high@l
  162. mtspr MAS7, \scratch
  163. isync
  164. msync
  165. tlbwe
  166. isync
  167. .endm
  168. .macro create_tlb0_entry esel ts tsize epn wimg rpn perm phy_high scratch
  169. lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
  170. ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
  171. mtspr MAS0, \scratch
  172. lis \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@h
  173. ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@l
  174. mtspr MAS1, \scratch
  175. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  176. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  177. mtspr MAS2, \scratch
  178. lis \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
  179. ori \scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
  180. mtspr MAS3, \scratch
  181. lis \scratch, \phy_high@h
  182. ori \scratch, \scratch, \phy_high@l
  183. mtspr MAS7, \scratch
  184. isync
  185. msync
  186. tlbwe
  187. isync
  188. .endm
  189. .macro delete_tlb1_entry esel scratch
  190. lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
  191. ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
  192. mtspr MAS0, \scratch
  193. li \scratch, 0
  194. mtspr MAS1, \scratch
  195. isync
  196. msync
  197. tlbwe
  198. isync
  199. .endm
  200. .macro delete_tlb0_entry esel epn wimg scratch
  201. lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
  202. ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
  203. mtspr MAS0, \scratch
  204. li \scratch, 0
  205. mtspr MAS1, \scratch
  206. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  207. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  208. mtspr MAS2, \scratch
  209. isync
  210. msync
  211. tlbwe
  212. isync
  213. .endm
  214. /* Interrupt vectors do not fit in minimal SPL. */
  215. #if !defined(MINIMAL_SPL)
  216. /* Setup interrupt vectors */
  217. lis r1,CONFIG_SYS_MONITOR_BASE@h
  218. mtspr IVPR,r1
  219. li r4,CriticalInput@l
  220. mtspr IVOR0,r4 /* 0: Critical input */
  221. li r4,MachineCheck@l
  222. mtspr IVOR1,r4 /* 1: Machine check */
  223. li r4,DataStorage@l
  224. mtspr IVOR2,r4 /* 2: Data storage */
  225. li r4,InstStorage@l
  226. mtspr IVOR3,r4 /* 3: Instruction storage */
  227. li r4,ExtInterrupt@l
  228. mtspr IVOR4,r4 /* 4: External interrupt */
  229. li r4,Alignment@l
  230. mtspr IVOR5,r4 /* 5: Alignment */
  231. li r4,ProgramCheck@l
  232. mtspr IVOR6,r4 /* 6: Program check */
  233. li r4,FPUnavailable@l
  234. mtspr IVOR7,r4 /* 7: floating point unavailable */
  235. li r4,SystemCall@l
  236. mtspr IVOR8,r4 /* 8: System call */
  237. /* 9: Auxiliary processor unavailable(unsupported) */
  238. li r4,Decrementer@l
  239. mtspr IVOR10,r4 /* 10: Decrementer */
  240. li r4,IntervalTimer@l
  241. mtspr IVOR11,r4 /* 11: Interval timer */
  242. li r4,WatchdogTimer@l
  243. mtspr IVOR12,r4 /* 12: Watchdog timer */
  244. li r4,DataTLBError@l
  245. mtspr IVOR13,r4 /* 13: Data TLB error */
  246. li r4,InstructionTLBError@l
  247. mtspr IVOR14,r4 /* 14: Instruction TLB error */
  248. li r4,DebugBreakpoint@l
  249. mtspr IVOR15,r4 /* 15: Debug */
  250. #endif
  251. /* Clear and set up some registers. */
  252. li r0,0x0000
  253. lis r1,0xffff
  254. mtspr DEC,r0 /* prevent dec exceptions */
  255. mttbl r0 /* prevent fit & wdt exceptions */
  256. mttbu r0
  257. mtspr TSR,r1 /* clear all timer exception status */
  258. mtspr TCR,r0 /* disable all */
  259. mtspr ESR,r0 /* clear exception syndrome register */
  260. mtspr MCSR,r0 /* machine check syndrome register */
  261. mtxer r0 /* clear integer exception register */
  262. #ifdef CONFIG_SYS_BOOK3E_HV
  263. mtspr MAS8,r0 /* make sure MAS8 is clear */
  264. #endif
  265. /* Enable Time Base and Select Time Base Clock */
  266. lis r0,HID0_EMCP@h /* Enable machine check */
  267. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  268. ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
  269. #endif
  270. #ifndef CONFIG_E500MC
  271. ori r0,r0,HID0_TBEN@l /* Enable Timebase */
  272. #endif
  273. mtspr HID0,r0
  274. #if !defined(CONFIG_E500MC) && !defined(CONFIG_ARCH_QEMU_E500)
  275. li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
  276. mfspr r3,PVR
  277. andi. r3,r3, 0xff
  278. cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */
  279. blt 1f
  280. /* Set MBDD bit also */
  281. ori r0, r0, HID1_MBDD@l
  282. 1:
  283. mtspr HID1,r0
  284. #endif
  285. #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
  286. mfspr r3,SPRN_HDBCR1
  287. oris r3,r3,0x0100
  288. mtspr SPRN_HDBCR1,r3
  289. #endif
  290. /* Enable Branch Prediction */
  291. #if defined(CONFIG_BTB)
  292. lis r0,BUCSR_ENABLE@h
  293. ori r0,r0,BUCSR_ENABLE@l
  294. mtspr SPRN_BUCSR,r0
  295. #endif
  296. #if defined(CONFIG_SYS_INIT_DBCR)
  297. lis r1,0xffff
  298. ori r1,r1,0xffff
  299. mtspr DBSR,r1 /* Clear all status bits */
  300. lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
  301. ori r0,r0,CONFIG_SYS_INIT_DBCR@l
  302. mtspr DBCR0,r0
  303. #endif
  304. #ifdef CONFIG_ARCH_MPC8569
  305. #define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
  306. #define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
  307. /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
  308. * use address space which is more than 12bits, and it must be done in
  309. * the 4K boot page. So we set this bit here.
  310. */
  311. /* create a temp mapping TLB0[0] for LBCR */
  312. create_tlb0_entry 0, \
  313. 0, BOOKE_PAGESZ_4K, \
  314. CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G, \
  315. CONFIG_SYS_LBC_ADDR, MAS3_SW|MAS3_SR, \
  316. 0, r6
  317. /* Set LBCR register */
  318. lis r4,CONFIG_SYS_LBCR_ADDR@h
  319. ori r4,r4,CONFIG_SYS_LBCR_ADDR@l
  320. lis r5,CONFIG_SYS_LBC_LBCR@h
  321. ori r5,r5,CONFIG_SYS_LBC_LBCR@l
  322. stw r5,0(r4)
  323. isync
  324. /* invalidate this temp TLB */
  325. lis r4,CONFIG_SYS_LBC_ADDR@h
  326. ori r4,r4,CONFIG_SYS_LBC_ADDR@l
  327. tlbivax 0,r4
  328. isync
  329. #endif /* CONFIG_ARCH_MPC8569 */
  330. /*
  331. * Search for the TLB that covers the code we're executing, and shrink it
  332. * so that it covers only this 4K page. That will ensure that any other
  333. * TLB we create won't interfere with it. We assume that the TLB exists,
  334. * which is why we don't check the Valid bit of MAS1. We also assume
  335. * it is in TLB1.
  336. *
  337. * This is necessary, for example, when booting from the on-chip ROM,
  338. * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
  339. */
  340. bl nexti /* Find our address */
  341. nexti: mflr r1 /* R1 = our PC */
  342. li r2, 0
  343. mtspr MAS6, r2 /* Assume the current PID and AS are 0 */
  344. isync
  345. msync
  346. tlbsx 0, r1 /* This must succeed */
  347. mfspr r14, MAS0 /* Save ESEL for later */
  348. rlwinm r14, r14, 16, 0xfff
  349. /* Set the size of the TLB to 4KB */
  350. mfspr r3, MAS1
  351. li r2, 0xF80
  352. andc r3, r3, r2 /* Clear the TSIZE bits */
  353. ori r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
  354. oris r3, r3, MAS1_IPROT@h
  355. mtspr MAS1, r3
  356. /*
  357. * Set the base address of the TLB to our PC. We assume that
  358. * virtual == physical. We also assume that MAS2_EPN == MAS3_RPN.
  359. */
  360. lis r3, MAS2_EPN@h
  361. ori r3, r3, MAS2_EPN@l /* R3 = MAS2_EPN */
  362. and r1, r1, r3 /* Our PC, rounded down to the nearest page */
  363. mfspr r2, MAS2
  364. andc r2, r2, r3
  365. or r2, r2, r1
  366. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  367. cmpwi r27,0
  368. beq 1f
  369. andi. r15, r2, MAS2_I|MAS2_G /* save the old I/G for later */
  370. rlwinm r2, r2, 0, ~MAS2_I
  371. ori r2, r2, MAS2_G
  372. 1:
  373. #endif
  374. mtspr MAS2, r2 /* Set the EPN to our PC base address */
  375. mfspr r2, MAS3
  376. andc r2, r2, r3
  377. or r2, r2, r1
  378. mtspr MAS3, r2 /* Set the RPN to our PC base address */
  379. isync
  380. msync
  381. tlbwe
  382. /*
  383. * Clear out any other TLB entries that may exist, to avoid conflicts.
  384. * Our TLB entry is in r14.
  385. */
  386. li r0, TLBIVAX_ALL | TLBIVAX_TLB0
  387. tlbivax 0, r0
  388. tlbsync
  389. mfspr r4, SPRN_TLB1CFG
  390. rlwinm r4, r4, 0, TLBnCFG_NENTRY_MASK
  391. li r3, 0
  392. mtspr MAS1, r3
  393. 1: cmpw r3, r14
  394. rlwinm r5, r3, 16, MAS0_ESEL_MSK
  395. addi r3, r3, 1
  396. beq 2f /* skip the entry we're executing from */
  397. oris r5, r5, MAS0_TLBSEL(1)@h
  398. mtspr MAS0, r5
  399. isync
  400. tlbwe
  401. isync
  402. msync
  403. 2: cmpw r3, r4
  404. blt 1b
  405. #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && !defined(MINIMAL_SPL) && \
  406. !defined(CONFIG_SECURE_BOOT)
  407. /*
  408. * TLB entry for debuggging in AS1
  409. * Create temporary TLB entry in AS0 to handle debug exception
  410. * As on debug exception MSR is cleared i.e. Address space is changed
  411. * to 0. A TLB entry (in AS0) is required to handle debug exception generated
  412. * in AS1.
  413. */
  414. #ifdef NOR_BOOT
  415. /*
  416. * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
  417. * bacause flash's virtual address maps to 0xff800000 - 0xffffffff.
  418. * and this window is outside of 4K boot window.
  419. */
  420. create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
  421. 0, BOOKE_PAGESZ_4M, \
  422. CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
  423. 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  424. 0, r6
  425. #else
  426. /*
  427. * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
  428. * because "nexti" will resize TLB to 4K
  429. */
  430. create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
  431. 0, BOOKE_PAGESZ_256K, \
  432. CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS2_I, \
  433. CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS3_SX|MAS3_SW|MAS3_SR, \
  434. 0, r6
  435. #endif
  436. #endif
  437. /*
  438. * Relocate CCSR, if necessary. We relocate CCSR if (obviously) the default
  439. * location is not where we want it. This typically happens on a 36-bit
  440. * system, where we want to move CCSR to near the top of 36-bit address space.
  441. *
  442. * To move CCSR, we create two temporary TLBs, one for the old location, and
  443. * another for the new location. On CoreNet systems, we also need to create
  444. * a special, temporary LAW.
  445. *
  446. * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
  447. * long-term TLBs, so we use TLB0 here.
  448. */
  449. #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
  450. #if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
  451. #error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
  452. #endif
  453. create_ccsr_new_tlb:
  454. /*
  455. * Create a TLB for the new location of CCSR. Register R8 is reserved
  456. * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
  457. */
  458. lis r8, CONFIG_SYS_CCSRBAR@h
  459. ori r8, r8, CONFIG_SYS_CCSRBAR@l
  460. lis r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
  461. ori r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
  462. create_tlb0_entry 0, \
  463. 0, BOOKE_PAGESZ_4K, \
  464. CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, \
  465. CONFIG_SYS_CCSRBAR_PHYS_LOW, MAS3_SW|MAS3_SR, \
  466. CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
  467. /*
  468. * Create a TLB for the current location of CCSR. Register R9 is reserved
  469. * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
  470. */
  471. create_ccsr_old_tlb:
  472. create_tlb0_entry 1, \
  473. 0, BOOKE_PAGESZ_4K, \
  474. CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, \
  475. CONFIG_SYS_CCSRBAR_DEFAULT, MAS3_SW|MAS3_SR, \
  476. 0, r3 /* The default CCSR address is always a 32-bit number */
  477. /*
  478. * We have a TLB for what we think is the current (old) CCSR. Let's
  479. * verify that, otherwise we won't be able to move it.
  480. * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
  481. * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
  482. */
  483. verify_old_ccsr:
  484. lis r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
  485. ori r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
  486. #ifdef CONFIG_FSL_CORENET
  487. lwz r1, 4(r9) /* CCSRBARL */
  488. #else
  489. lwz r1, 0(r9) /* CCSRBAR, shifted right by 12 */
  490. slwi r1, r1, 12
  491. #endif
  492. cmpl 0, r0, r1
  493. /*
  494. * If the value we read from CCSRBARL is not what we expect, then
  495. * enter an infinite loop. This will at least allow a debugger to
  496. * halt execution and examine TLBs, etc. There's no point in going
  497. * on.
  498. */
  499. infinite_debug_loop:
  500. bne infinite_debug_loop
  501. #ifdef CONFIG_FSL_CORENET
  502. #define CCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
  503. #define LAW_SIZE_4K 0xb
  504. #define CCSRBAR_LAWAR (LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
  505. #define CCSRAR_C 0x80000000 /* Commit */
  506. create_temp_law:
  507. /*
  508. * On CoreNet systems, we create the temporary LAW using a special LAW
  509. * target ID of 0x1e. LAWBARH is at offset 0xc00 in CCSR.
  510. */
  511. lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  512. ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  513. lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
  514. ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
  515. lis r2, CCSRBAR_LAWAR@h
  516. ori r2, r2, CCSRBAR_LAWAR@l
  517. stw r0, 0xc00(r9) /* LAWBARH0 */
  518. stw r1, 0xc04(r9) /* LAWBARL0 */
  519. sync
  520. stw r2, 0xc08(r9) /* LAWAR0 */
  521. /*
  522. * Read back from LAWAR to ensure the update is complete. e500mc
  523. * cores also require an isync.
  524. */
  525. lwz r0, 0xc08(r9) /* LAWAR0 */
  526. isync
  527. /*
  528. * Read the current CCSRBARH and CCSRBARL using load word instructions.
  529. * Follow this with an isync instruction. This forces any outstanding
  530. * accesses to configuration space to completion.
  531. */
  532. read_old_ccsrbar:
  533. lwz r0, 0(r9) /* CCSRBARH */
  534. lwz r0, 4(r9) /* CCSRBARL */
  535. isync
  536. /*
  537. * Write the new values for CCSRBARH and CCSRBARL to their old
  538. * locations. The CCSRBARH has a shadow register. When the CCSRBARH
  539. * has a new value written it loads a CCSRBARH shadow register. When
  540. * the CCSRBARL is written, the CCSRBARH shadow register contents
  541. * along with the CCSRBARL value are loaded into the CCSRBARH and
  542. * CCSRBARL registers, respectively. Follow this with a sync
  543. * instruction.
  544. */
  545. write_new_ccsrbar:
  546. lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  547. ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  548. lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
  549. ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
  550. lis r2, CCSRAR_C@h
  551. ori r2, r2, CCSRAR_C@l
  552. stw r0, 0(r9) /* Write to CCSRBARH */
  553. sync /* Make sure we write to CCSRBARH first */
  554. stw r1, 4(r9) /* Write to CCSRBARL */
  555. sync
  556. /*
  557. * Write a 1 to the commit bit (C) of CCSRAR at the old location.
  558. * Follow this with a sync instruction.
  559. */
  560. stw r2, 8(r9)
  561. sync
  562. /* Delete the temporary LAW */
  563. delete_temp_law:
  564. li r1, 0
  565. stw r1, 0xc08(r8)
  566. sync
  567. stw r1, 0xc00(r8)
  568. stw r1, 0xc04(r8)
  569. sync
  570. #else /* #ifdef CONFIG_FSL_CORENET */
  571. write_new_ccsrbar:
  572. /*
  573. * Read the current value of CCSRBAR using a load word instruction
  574. * followed by an isync. This forces all accesses to configuration
  575. * space to complete.
  576. */
  577. sync
  578. lwz r0, 0(r9)
  579. isync
  580. /* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
  581. #define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
  582. (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
  583. /* Write the new value to CCSRBAR. */
  584. lis r0, CCSRBAR_PHYS_RS12@h
  585. ori r0, r0, CCSRBAR_PHYS_RS12@l
  586. stw r0, 0(r9)
  587. sync
  588. /*
  589. * The manual says to perform a load of an address that does not
  590. * access configuration space or the on-chip SRAM using an existing TLB,
  591. * but that doesn't appear to be necessary. We will do the isync,
  592. * though.
  593. */
  594. isync
  595. /*
  596. * Read the contents of CCSRBAR from its new location, followed by
  597. * another isync.
  598. */
  599. lwz r0, 0(r8)
  600. isync
  601. #endif /* #ifdef CONFIG_FSL_CORENET */
  602. /* Delete the temporary TLBs */
  603. delete_temp_tlbs:
  604. delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, r3
  605. delete_tlb0_entry 1, CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, r3
  606. #endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
  607. #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  608. create_ccsr_l2_tlb:
  609. /*
  610. * Create a TLB for the MMR location of CCSR
  611. * to access L2CSR0 register
  612. */
  613. create_tlb0_entry 0, \
  614. 0, BOOKE_PAGESZ_4K, \
  615. CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, \
  616. CONFIG_SYS_CCSRBAR_PHYS_LOW + 0xC20000, MAS3_SW|MAS3_SR, \
  617. CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
  618. enable_l2_cluster_l2:
  619. /* enable L2 cache */
  620. lis r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@h
  621. ori r3, r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@l
  622. li r4, 33 /* stash id */
  623. stw r4, 4(r3)
  624. lis r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@h
  625. ori r4, r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@l
  626. sync
  627. stw r4, 0(r3) /* invalidate L2 */
  628. /* Poll till the bits are cleared */
  629. 1: sync
  630. lwz r0, 0(r3)
  631. twi 0, r0, 0
  632. isync
  633. and. r1, r0, r4
  634. bne 1b
  635. /* L2PE must be set before L2 cache is enabled */
  636. lis r4, (L2CSR0_L2PE)@h
  637. ori r4, r4, (L2CSR0_L2PE)@l
  638. sync
  639. stw r4, 0(r3) /* enable L2 parity/ECC error checking */
  640. /* Poll till the bit is set */
  641. 1: sync
  642. lwz r0, 0(r3)
  643. twi 0, r0, 0
  644. isync
  645. and. r1, r0, r4
  646. beq 1b
  647. lis r4, (L2CSR0_L2E|L2CSR0_L2PE)@h
  648. ori r4, r4, (L2CSR0_L2REP_MODE)@l
  649. sync
  650. stw r4, 0(r3) /* enable L2 */
  651. /* Poll till the bit is set */
  652. 1: sync
  653. lwz r0, 0(r3)
  654. twi 0, r0, 0
  655. isync
  656. and. r1, r0, r4
  657. beq 1b
  658. delete_ccsr_l2_tlb:
  659. delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, r3
  660. #endif
  661. /*
  662. * Enable the L1. On e6500, this has to be done
  663. * after the L2 is up.
  664. */
  665. #ifdef CONFIG_SYS_CACHE_STASHING
  666. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  667. li r2,(32 + 0)
  668. mtspr L1CSR2,r2
  669. #endif
  670. /* Enable/invalidate the I-Cache */
  671. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  672. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  673. mtspr SPRN_L1CSR1,r2
  674. 1:
  675. mfspr r3,SPRN_L1CSR1
  676. and. r1,r3,r2
  677. bne 1b
  678. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  679. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  680. mtspr SPRN_L1CSR1,r3
  681. isync
  682. 2:
  683. mfspr r3,SPRN_L1CSR1
  684. andi. r1,r3,L1CSR1_ICE@l
  685. beq 2b
  686. /* Enable/invalidate the D-Cache */
  687. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  688. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  689. mtspr SPRN_L1CSR0,r2
  690. 1:
  691. mfspr r3,SPRN_L1CSR0
  692. and. r1,r3,r2
  693. bne 1b
  694. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  695. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  696. mtspr SPRN_L1CSR0,r3
  697. isync
  698. 2:
  699. mfspr r3,SPRN_L1CSR0
  700. andi. r1,r3,L1CSR0_DCE@l
  701. beq 2b
  702. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  703. #define DCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
  704. #define LAW_SIZE_1M 0x13
  705. #define DCSRBAR_LAWAR (LAW_EN | (0x1d << 20) | LAW_SIZE_1M)
  706. cmpwi r27,0
  707. beq 9f
  708. /*
  709. * Create a TLB entry for CCSR
  710. *
  711. * We're executing out of TLB1 entry in r14, and that's the only
  712. * TLB entry that exists. To allocate some TLB entries for our
  713. * own use, flip a bit high enough that we won't flip it again
  714. * via incrementing.
  715. */
  716. xori r8, r14, 32
  717. lis r0, MAS0_TLBSEL(1)@h
  718. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  719. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@h
  720. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@l
  721. lis r7, CONFIG_SYS_CCSRBAR@h
  722. ori r7, r7, CONFIG_SYS_CCSRBAR@l
  723. ori r2, r7, MAS2_I|MAS2_G
  724. lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
  725. ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
  726. lis r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  727. ori r4, r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  728. mtspr MAS0, r0
  729. mtspr MAS1, r1
  730. mtspr MAS2, r2
  731. mtspr MAS3, r3
  732. mtspr MAS7, r4
  733. isync
  734. tlbwe
  735. isync
  736. msync
  737. /* Map DCSR temporarily to physical address zero */
  738. li r0, 0
  739. lis r3, DCSRBAR_LAWAR@h
  740. ori r3, r3, DCSRBAR_LAWAR@l
  741. stw r0, 0xc00(r7) /* LAWBARH0 */
  742. stw r0, 0xc04(r7) /* LAWBARL0 */
  743. sync
  744. stw r3, 0xc08(r7) /* LAWAR0 */
  745. /* Read back from LAWAR to ensure the update is complete. */
  746. lwz r3, 0xc08(r7) /* LAWAR0 */
  747. isync
  748. /* Create a TLB entry for DCSR at zero */
  749. addi r9, r8, 1
  750. lis r0, MAS0_TLBSEL(1)@h
  751. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  752. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@h
  753. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@l
  754. li r6, 0 /* DCSR effective address */
  755. ori r2, r6, MAS2_I|MAS2_G
  756. li r3, MAS3_SW|MAS3_SR
  757. li r4, 0
  758. mtspr MAS0, r0
  759. mtspr MAS1, r1
  760. mtspr MAS2, r2
  761. mtspr MAS3, r3
  762. mtspr MAS7, r4
  763. isync
  764. tlbwe
  765. isync
  766. msync
  767. /* enable the timebase */
  768. #define CTBENR 0xe2084
  769. li r3, 1
  770. addis r4, r7, CTBENR@ha
  771. stw r3, CTBENR@l(r4)
  772. lwz r3, CTBENR@l(r4)
  773. twi 0,r3,0
  774. isync
  775. .macro erratum_set_ccsr offset value
  776. addis r3, r7, \offset@ha
  777. lis r4, \value@h
  778. addi r3, r3, \offset@l
  779. ori r4, r4, \value@l
  780. bl erratum_set_value
  781. .endm
  782. .macro erratum_set_dcsr offset value
  783. addis r3, r6, \offset@ha
  784. lis r4, \value@h
  785. addi r3, r3, \offset@l
  786. ori r4, r4, \value@l
  787. bl erratum_set_value
  788. .endm
  789. erratum_set_dcsr 0xb0e08 0xe0201800
  790. erratum_set_dcsr 0xb0e18 0xe0201800
  791. erratum_set_dcsr 0xb0e38 0xe0400000
  792. erratum_set_dcsr 0xb0008 0x00900000
  793. erratum_set_dcsr 0xb0e40 0xe00a0000
  794. erratum_set_ccsr 0x18600 CONFIG_SYS_FSL_CORENET_SNOOPVEC_COREONLY
  795. #ifdef CONFIG_RAMBOOT_PBL
  796. erratum_set_ccsr 0x10f00 0x495e5000
  797. #else
  798. erratum_set_ccsr 0x10f00 0x415e5000
  799. #endif
  800. erratum_set_ccsr 0x11f00 0x415e5000
  801. /* Make temp mapping uncacheable again, if it was initially */
  802. bl 2f
  803. 2: mflr r3
  804. tlbsx 0, r3
  805. mfspr r4, MAS2
  806. rlwimi r4, r15, 0, MAS2_I
  807. rlwimi r4, r15, 0, MAS2_G
  808. mtspr MAS2, r4
  809. isync
  810. tlbwe
  811. isync
  812. msync
  813. /* Clear the cache */
  814. lis r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  815. ori r3,r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  816. sync
  817. isync
  818. mtspr SPRN_L1CSR1,r3
  819. isync
  820. 2: sync
  821. mfspr r4,SPRN_L1CSR1
  822. and. r4,r4,r3
  823. bne 2b
  824. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  825. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  826. sync
  827. isync
  828. mtspr SPRN_L1CSR1,r3
  829. isync
  830. 2: sync
  831. mfspr r4,SPRN_L1CSR1
  832. and. r4,r4,r3
  833. beq 2b
  834. /* Remove temporary mappings */
  835. lis r0, MAS0_TLBSEL(1)@h
  836. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  837. li r3, 0
  838. mtspr MAS0, r0
  839. mtspr MAS1, r3
  840. isync
  841. tlbwe
  842. isync
  843. msync
  844. li r3, 0
  845. stw r3, 0xc08(r7) /* LAWAR0 */
  846. lwz r3, 0xc08(r7)
  847. isync
  848. lis r0, MAS0_TLBSEL(1)@h
  849. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  850. li r3, 0
  851. mtspr MAS0, r0
  852. mtspr MAS1, r3
  853. isync
  854. tlbwe
  855. isync
  856. msync
  857. b 9f
  858. /* r3 = addr, r4 = value, clobbers r5, r11, r12 */
  859. erratum_set_value:
  860. /* Lock two cache lines into I-Cache */
  861. sync
  862. mfspr r11, SPRN_L1CSR1
  863. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  864. sync
  865. isync
  866. mtspr SPRN_L1CSR1, r11
  867. isync
  868. mflr r12
  869. bl 5f
  870. 5: mflr r5
  871. addi r5, r5, 2f - 5b
  872. icbtls 0, 0, r5
  873. addi r5, r5, 64
  874. sync
  875. mfspr r11, SPRN_L1CSR1
  876. 3: andi. r11, r11, L1CSR1_ICUL
  877. bne 3b
  878. icbtls 0, 0, r5
  879. addi r5, r5, 64
  880. sync
  881. mfspr r11, SPRN_L1CSR1
  882. 3: andi. r11, r11, L1CSR1_ICUL
  883. bne 3b
  884. b 2f
  885. .align 6
  886. /* Inside a locked cacheline, wait a while, write, then wait a while */
  887. 2: sync
  888. mfspr r5, SPRN_TBRL
  889. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  890. 4: mfspr r5, SPRN_TBRL
  891. subf. r5, r5, r11
  892. bgt 4b
  893. stw r4, 0(r3)
  894. mfspr r5, SPRN_TBRL
  895. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  896. 4: mfspr r5, SPRN_TBRL
  897. subf. r5, r5, r11
  898. bgt 4b
  899. sync
  900. /*
  901. * Fill out the rest of this cache line and the next with nops,
  902. * to ensure that nothing outside the locked area will be
  903. * fetched due to a branch.
  904. */
  905. .rept 19
  906. nop
  907. .endr
  908. sync
  909. mfspr r11, SPRN_L1CSR1
  910. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  911. sync
  912. isync
  913. mtspr SPRN_L1CSR1, r11
  914. isync
  915. mtlr r12
  916. blr
  917. 9:
  918. #endif
  919. create_init_ram_area:
  920. lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
  921. ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
  922. #ifdef NOR_BOOT
  923. /* create a temp mapping in AS=1 to the 4M boot window */
  924. create_tlb1_entry 15, \
  925. 1, BOOKE_PAGESZ_4M, \
  926. CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
  927. 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  928. 0, r6
  929. #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
  930. /* create a temp mapping in AS = 1 for Flash mapping
  931. * created by PBL for ISBC code
  932. */
  933. create_tlb1_entry 15, \
  934. 1, BOOKE_PAGESZ_1M, \
  935. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  936. CONFIG_SYS_PBI_FLASH_WINDOW & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  937. 0, r6
  938. /*
  939. * For Targets without CONFIG_SPL like P3, P5
  940. * and for targets with CONFIG_SPL like T1, T2, T4, only for
  941. * u-boot-spl i.e. CONFIG_SPL_BUILD
  942. */
  943. #elif defined(CONFIG_RAMBOOT_PBL) && defined(CONFIG_SECURE_BOOT) && \
  944. (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
  945. /* create a temp mapping in AS = 1 for mapping CONFIG_SYS_MONITOR_BASE
  946. * to L3 Address configured by PBL for ISBC code
  947. */
  948. create_tlb1_entry 15, \
  949. 1, BOOKE_PAGESZ_1M, \
  950. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  951. CONFIG_SYS_INIT_L3_ADDR & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  952. 0, r6
  953. #else
  954. /*
  955. * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
  956. * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
  957. */
  958. create_tlb1_entry 15, \
  959. 1, BOOKE_PAGESZ_1M, \
  960. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  961. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  962. 0, r6
  963. #endif
  964. /* create a temp mapping in AS=1 to the stack */
  965. #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
  966. defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
  967. create_tlb1_entry 14, \
  968. 1, BOOKE_PAGESZ_16K, \
  969. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  970. CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, MAS3_SX|MAS3_SW|MAS3_SR, \
  971. CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH, r6
  972. #else
  973. create_tlb1_entry 14, \
  974. 1, BOOKE_PAGESZ_16K, \
  975. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  976. CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, \
  977. 0, r6
  978. #endif
  979. lis r6,MSR_IS|MSR_DS|MSR_DE@h
  980. ori r6,r6,MSR_IS|MSR_DS|MSR_DE@l
  981. lis r7,switch_as@h
  982. ori r7,r7,switch_as@l
  983. mtspr SPRN_SRR0,r7
  984. mtspr SPRN_SRR1,r6
  985. rfi
  986. switch_as:
  987. /* L1 DCache is used for initial RAM */
  988. /* Allocate Initial RAM in data cache.
  989. */
  990. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  991. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  992. mfspr r2, L1CFG0
  993. andi. r2, r2, 0x1ff
  994. /* cache size * 1024 / (2 * L1 line size) */
  995. slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
  996. mtctr r2
  997. li r0,0
  998. 1:
  999. dcbz r0,r3
  1000. #ifdef CONFIG_E6500 /* Lock/unlock L2 cache instead of L1 */
  1001. dcbtls 2, r0, r3
  1002. #else
  1003. dcbtls 0, r0, r3
  1004. #endif
  1005. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  1006. bdnz 1b
  1007. /* Jump out the last 4K page and continue to 'normal' start */
  1008. #if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)
  1009. /* We assume that we're already running at the address we're linked at */
  1010. b _start_cont
  1011. #else
  1012. /* Calculate absolute address in FLASH and jump there */
  1013. /*--------------------------------------------------------------*/
  1014. lis r3,CONFIG_SYS_MONITOR_BASE@h
  1015. ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
  1016. addi r3,r3,_start_cont - _start
  1017. mtlr r3
  1018. blr
  1019. #endif
  1020. .text
  1021. .globl _start
  1022. _start:
  1023. .long 0x27051956 /* U-BOOT Magic Number */
  1024. .globl version_string
  1025. version_string:
  1026. .ascii U_BOOT_VERSION_STRING, "\0"
  1027. .align 4
  1028. .globl _start_cont
  1029. _start_cont:
  1030. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  1031. lis r3,(CONFIG_SYS_INIT_RAM_ADDR)@h
  1032. ori r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
  1033. #ifdef CONFIG_SYS_MALLOC_F_LEN
  1034. #if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
  1035. #error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM."
  1036. #endif
  1037. /* Leave 16+ byte for back chain termination and NULL return address */
  1038. subi r3,r3,((CONFIG_SYS_MALLOC_F_LEN+16+15)&~0xf)
  1039. #endif
  1040. /* End of RAM */
  1041. lis r4,(CONFIG_SYS_INIT_RAM_ADDR)@h
  1042. ori r4,r4,(CONFIG_SYS_INIT_RAM_SIZE)@l
  1043. li r0,0
  1044. 1: subi r4,r4,4
  1045. stw r0,0(r4)
  1046. cmplw r4,r3
  1047. bne 1b
  1048. #ifdef CONFIG_SYS_MALLOC_F_LEN
  1049. lis r4,(CONFIG_SYS_INIT_RAM_ADDR)@h
  1050. ori r4,r4,(CONFIG_SYS_GBL_DATA_OFFSET)@l
  1051. addi r3,r3,16 /* Pre-relocation malloc area */
  1052. stw r3,GD_MALLOC_BASE(r4)
  1053. subi r3,r3,16
  1054. #endif
  1055. li r0,0
  1056. stw r0,0(r3) /* Terminate Back Chain */
  1057. stw r0,+4(r3) /* NULL return address. */
  1058. mr r1,r3 /* Transfer to SP(r1) */
  1059. GET_GOT
  1060. /* Pass our potential ePAPR device tree pointer to cpu_init_early_f */
  1061. mr r3, r24
  1062. bl cpu_init_early_f
  1063. /* switch back to AS = 0 */
  1064. lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
  1065. ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
  1066. mtmsr r3
  1067. isync
  1068. bl cpu_init_f /* return boot_flag for calling board_init_f */
  1069. bl board_init_f
  1070. isync
  1071. /* NOTREACHED - board_init_f() does not return */
  1072. #ifndef MINIMAL_SPL
  1073. .globl _start_of_vectors
  1074. _start_of_vectors:
  1075. /* Critical input. */
  1076. CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
  1077. /* Machine check */
  1078. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  1079. /* Data Storage exception. */
  1080. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  1081. /* Instruction Storage exception. */
  1082. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  1083. /* External Interrupt exception. */
  1084. STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
  1085. /* Alignment exception. */
  1086. Alignment:
  1087. EXCEPTION_PROLOG(SRR0, SRR1)
  1088. mfspr r4,DAR
  1089. stw r4,_DAR(r21)
  1090. mfspr r5,DSISR
  1091. stw r5,_DSISR(r21)
  1092. addi r3,r1,STACK_FRAME_OVERHEAD
  1093. EXC_XFER_TEMPLATE(0x600, Alignment, AlignmentException,
  1094. MSR_KERNEL, COPY_EE)
  1095. /* Program check exception */
  1096. ProgramCheck:
  1097. EXCEPTION_PROLOG(SRR0, SRR1)
  1098. addi r3,r1,STACK_FRAME_OVERHEAD
  1099. EXC_XFER_TEMPLATE(0x700, ProgramCheck, ProgramCheckException,
  1100. MSR_KERNEL, COPY_EE)
  1101. /* No FPU on MPC85xx. This exception is not supposed to happen.
  1102. */
  1103. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  1104. STD_EXCEPTION(0x0900, SystemCall, UnknownException)
  1105. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  1106. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  1107. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  1108. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  1109. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  1110. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  1111. .globl _end_of_vectors
  1112. _end_of_vectors:
  1113. . = . + (0x100 - ( . & 0xff )) /* align for debug */
  1114. /*
  1115. * This code finishes saving the registers to the exception frame
  1116. * and jumps to the appropriate handler for the exception.
  1117. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  1118. * r23 is the address of the handler.
  1119. */
  1120. .globl transfer_to_handler
  1121. transfer_to_handler:
  1122. SAVE_GPR(7, r21)
  1123. SAVE_4GPRS(8, r21)
  1124. SAVE_8GPRS(12, r21)
  1125. SAVE_8GPRS(24, r21)
  1126. li r22,0
  1127. stw r22,RESULT(r21)
  1128. mtspr SPRG2,r22 /* r1 is now kernel sp */
  1129. mtctr r23 /* virtual address of handler */
  1130. mtmsr r20
  1131. bctrl
  1132. int_return:
  1133. mfmsr r28 /* Disable interrupts */
  1134. li r4,0
  1135. ori r4,r4,MSR_EE
  1136. andc r28,r28,r4
  1137. SYNC /* Some chip revs need this... */
  1138. mtmsr r28
  1139. SYNC
  1140. lwz r2,_CTR(r1)
  1141. lwz r0,_LINK(r1)
  1142. mtctr r2
  1143. mtlr r0
  1144. lwz r2,_XER(r1)
  1145. lwz r0,_CCR(r1)
  1146. mtspr XER,r2
  1147. mtcrf 0xFF,r0
  1148. REST_10GPRS(3, r1)
  1149. REST_10GPRS(13, r1)
  1150. REST_8GPRS(23, r1)
  1151. REST_GPR(31, r1)
  1152. lwz r2,_NIP(r1) /* Restore environment */
  1153. lwz r0,_MSR(r1)
  1154. mtspr SRR0,r2
  1155. mtspr SRR1,r0
  1156. lwz r0,GPR0(r1)
  1157. lwz r2,GPR2(r1)
  1158. lwz r1,GPR1(r1)
  1159. SYNC
  1160. rfi
  1161. /* Cache functions.
  1162. */
  1163. .globl flush_icache
  1164. flush_icache:
  1165. .globl invalidate_icache
  1166. invalidate_icache:
  1167. mfspr r0,L1CSR1
  1168. ori r0,r0,L1CSR1_ICFI
  1169. msync
  1170. isync
  1171. mtspr L1CSR1,r0
  1172. isync
  1173. blr /* entire I cache */
  1174. .globl invalidate_dcache
  1175. invalidate_dcache:
  1176. mfspr r0,L1CSR0
  1177. ori r0,r0,L1CSR0_DCFI
  1178. msync
  1179. isync
  1180. mtspr L1CSR0,r0
  1181. isync
  1182. blr
  1183. .globl icache_enable
  1184. icache_enable:
  1185. mflr r8
  1186. bl invalidate_icache
  1187. mtlr r8
  1188. isync
  1189. mfspr r4,L1CSR1
  1190. ori r4,r4,0x0001
  1191. oris r4,r4,0x0001
  1192. mtspr L1CSR1,r4
  1193. isync
  1194. blr
  1195. .globl icache_disable
  1196. icache_disable:
  1197. mfspr r0,L1CSR1
  1198. lis r3,0
  1199. ori r3,r3,L1CSR1_ICE
  1200. andc r0,r0,r3
  1201. mtspr L1CSR1,r0
  1202. isync
  1203. blr
  1204. .globl icache_status
  1205. icache_status:
  1206. mfspr r3,L1CSR1
  1207. andi. r3,r3,L1CSR1_ICE
  1208. blr
  1209. .globl dcache_enable
  1210. dcache_enable:
  1211. mflr r8
  1212. bl invalidate_dcache
  1213. mtlr r8
  1214. isync
  1215. mfspr r0,L1CSR0
  1216. ori r0,r0,0x0001
  1217. oris r0,r0,0x0001
  1218. msync
  1219. isync
  1220. mtspr L1CSR0,r0
  1221. isync
  1222. blr
  1223. .globl dcache_disable
  1224. dcache_disable:
  1225. mfspr r3,L1CSR0
  1226. lis r4,0
  1227. ori r4,r4,L1CSR0_DCE
  1228. andc r3,r3,r4
  1229. mtspr L1CSR0,r3
  1230. isync
  1231. blr
  1232. .globl dcache_status
  1233. dcache_status:
  1234. mfspr r3,L1CSR0
  1235. andi. r3,r3,L1CSR0_DCE
  1236. blr
  1237. .globl get_pvr
  1238. get_pvr:
  1239. mfspr r3,PVR
  1240. blr
  1241. .globl get_svr
  1242. get_svr:
  1243. mfspr r3,SVR
  1244. blr
  1245. /*------------------------------------------------------------------------------- */
  1246. /* Function: in8 */
  1247. /* Description: Input 8 bits */
  1248. /*------------------------------------------------------------------------------- */
  1249. .globl in8
  1250. in8:
  1251. lbz r3,0x0000(r3)
  1252. blr
  1253. /*------------------------------------------------------------------------------- */
  1254. /* Function: out8 */
  1255. /* Description: Output 8 bits */
  1256. /*------------------------------------------------------------------------------- */
  1257. .globl out8
  1258. out8:
  1259. stb r4,0x0000(r3)
  1260. sync
  1261. blr
  1262. /*------------------------------------------------------------------------------- */
  1263. /* Function: out16 */
  1264. /* Description: Output 16 bits */
  1265. /*------------------------------------------------------------------------------- */
  1266. .globl out16
  1267. out16:
  1268. sth r4,0x0000(r3)
  1269. sync
  1270. blr
  1271. /*------------------------------------------------------------------------------- */
  1272. /* Function: out16r */
  1273. /* Description: Byte reverse and output 16 bits */
  1274. /*------------------------------------------------------------------------------- */
  1275. .globl out16r
  1276. out16r:
  1277. sthbrx r4,r0,r3
  1278. sync
  1279. blr
  1280. /*------------------------------------------------------------------------------- */
  1281. /* Function: out32 */
  1282. /* Description: Output 32 bits */
  1283. /*------------------------------------------------------------------------------- */
  1284. .globl out32
  1285. out32:
  1286. stw r4,0x0000(r3)
  1287. sync
  1288. blr
  1289. /*------------------------------------------------------------------------------- */
  1290. /* Function: out32r */
  1291. /* Description: Byte reverse and output 32 bits */
  1292. /*------------------------------------------------------------------------------- */
  1293. .globl out32r
  1294. out32r:
  1295. stwbrx r4,r0,r3
  1296. sync
  1297. blr
  1298. /*------------------------------------------------------------------------------- */
  1299. /* Function: in16 */
  1300. /* Description: Input 16 bits */
  1301. /*------------------------------------------------------------------------------- */
  1302. .globl in16
  1303. in16:
  1304. lhz r3,0x0000(r3)
  1305. blr
  1306. /*------------------------------------------------------------------------------- */
  1307. /* Function: in16r */
  1308. /* Description: Input 16 bits and byte reverse */
  1309. /*------------------------------------------------------------------------------- */
  1310. .globl in16r
  1311. in16r:
  1312. lhbrx r3,r0,r3
  1313. blr
  1314. /*------------------------------------------------------------------------------- */
  1315. /* Function: in32 */
  1316. /* Description: Input 32 bits */
  1317. /*------------------------------------------------------------------------------- */
  1318. .globl in32
  1319. in32:
  1320. lwz 3,0x0000(3)
  1321. blr
  1322. /*------------------------------------------------------------------------------- */
  1323. /* Function: in32r */
  1324. /* Description: Input 32 bits and byte reverse */
  1325. /*------------------------------------------------------------------------------- */
  1326. .globl in32r
  1327. in32r:
  1328. lwbrx r3,r0,r3
  1329. blr
  1330. #endif /* !MINIMAL_SPL */
  1331. /*------------------------------------------------------------------------------*/
  1332. /*
  1333. * void write_tlb(mas0, mas1, mas2, mas3, mas7)
  1334. */
  1335. .globl write_tlb
  1336. write_tlb:
  1337. mtspr MAS0,r3
  1338. mtspr MAS1,r4
  1339. mtspr MAS2,r5
  1340. mtspr MAS3,r6
  1341. #ifdef CONFIG_ENABLE_36BIT_PHYS
  1342. mtspr MAS7,r7
  1343. #endif
  1344. li r3,0
  1345. #ifdef CONFIG_SYS_BOOK3E_HV
  1346. mtspr MAS8,r3
  1347. #endif
  1348. isync
  1349. tlbwe
  1350. msync
  1351. isync
  1352. blr
  1353. /*
  1354. * void relocate_code (addr_sp, gd, addr_moni)
  1355. *
  1356. * This "function" does not return, instead it continues in RAM
  1357. * after relocating the monitor code.
  1358. *
  1359. * r3 = dest
  1360. * r4 = src
  1361. * r5 = length in bytes
  1362. * r6 = cachelinesize
  1363. */
  1364. .globl relocate_code
  1365. relocate_code:
  1366. mr r1,r3 /* Set new stack pointer */
  1367. mr r9,r4 /* Save copy of Init Data pointer */
  1368. mr r10,r5 /* Save copy of Destination Address */
  1369. GET_GOT
  1370. #ifndef CONFIG_SPL_SKIP_RELOCATE
  1371. mr r3,r5 /* Destination Address */
  1372. lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  1373. ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
  1374. lwz r5,GOT(__init_end)
  1375. sub r5,r5,r4
  1376. li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  1377. /*
  1378. * Fix GOT pointer:
  1379. *
  1380. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  1381. *
  1382. * Offset:
  1383. */
  1384. sub r15,r10,r4
  1385. /* First our own GOT */
  1386. add r12,r12,r15
  1387. /* the the one used by the C code */
  1388. add r30,r30,r15
  1389. /*
  1390. * Now relocate code
  1391. */
  1392. cmplw cr1,r3,r4
  1393. addi r0,r5,3
  1394. srwi. r0,r0,2
  1395. beq cr1,4f /* In place copy is not necessary */
  1396. beq 7f /* Protect against 0 count */
  1397. mtctr r0
  1398. bge cr1,2f
  1399. la r8,-4(r4)
  1400. la r7,-4(r3)
  1401. 1: lwzu r0,4(r8)
  1402. stwu r0,4(r7)
  1403. bdnz 1b
  1404. b 4f
  1405. 2: slwi r0,r0,2
  1406. add r8,r4,r0
  1407. add r7,r3,r0
  1408. 3: lwzu r0,-4(r8)
  1409. stwu r0,-4(r7)
  1410. bdnz 3b
  1411. /*
  1412. * Now flush the cache: note that we must start from a cache aligned
  1413. * address. Otherwise we might miss one cache line.
  1414. */
  1415. 4: cmpwi r6,0
  1416. add r5,r3,r5
  1417. beq 7f /* Always flush prefetch queue in any case */
  1418. subi r0,r6,1
  1419. andc r3,r3,r0
  1420. mr r4,r3
  1421. 5: dcbst 0,r4
  1422. add r4,r4,r6
  1423. cmplw r4,r5
  1424. blt 5b
  1425. sync /* Wait for all dcbst to complete on bus */
  1426. mr r4,r3
  1427. 6: icbi 0,r4
  1428. add r4,r4,r6
  1429. cmplw r4,r5
  1430. blt 6b
  1431. 7: sync /* Wait for all icbi to complete on bus */
  1432. isync
  1433. /*
  1434. * We are done. Do not return, instead branch to second part of board
  1435. * initialization, now running from RAM.
  1436. */
  1437. addi r0,r10,in_ram - _start
  1438. /*
  1439. * As IVPR is going to point RAM address,
  1440. * Make sure IVOR15 has valid opcode to support debugger
  1441. */
  1442. mtspr IVOR15,r0
  1443. /*
  1444. * Re-point the IVPR at RAM
  1445. */
  1446. mtspr IVPR,r10
  1447. mtlr r0
  1448. blr /* NEVER RETURNS! */
  1449. #endif
  1450. .globl in_ram
  1451. in_ram:
  1452. /*
  1453. * Relocation Function, r12 point to got2+0x8000
  1454. *
  1455. * Adjust got2 pointers, no need to check for 0, this code
  1456. * already puts a few entries in the table.
  1457. */
  1458. li r0,__got2_entries@sectoff@l
  1459. la r3,GOT(_GOT2_TABLE_)
  1460. lwz r11,GOT(_GOT2_TABLE_)
  1461. mtctr r0
  1462. sub r11,r3,r11
  1463. addi r3,r3,-4
  1464. 1: lwzu r0,4(r3)
  1465. cmpwi r0,0
  1466. beq- 2f
  1467. add r0,r0,r11
  1468. stw r0,0(r3)
  1469. 2: bdnz 1b
  1470. /*
  1471. * Now adjust the fixups and the pointers to the fixups
  1472. * in case we need to move ourselves again.
  1473. */
  1474. li r0,__fixup_entries@sectoff@l
  1475. lwz r3,GOT(_FIXUP_TABLE_)
  1476. cmpwi r0,0
  1477. mtctr r0
  1478. addi r3,r3,-4
  1479. beq 4f
  1480. 3: lwzu r4,4(r3)
  1481. lwzux r0,r4,r11
  1482. cmpwi r0,0
  1483. add r0,r0,r11
  1484. stw r4,0(r3)
  1485. beq- 5f
  1486. stw r0,0(r4)
  1487. 5: bdnz 3b
  1488. 4:
  1489. clear_bss:
  1490. /*
  1491. * Now clear BSS segment
  1492. */
  1493. lwz r3,GOT(__bss_start)
  1494. lwz r4,GOT(__bss_end)
  1495. cmplw 0,r3,r4
  1496. beq 6f
  1497. li r0,0
  1498. 5:
  1499. stw r0,0(r3)
  1500. addi r3,r3,4
  1501. cmplw 0,r3,r4
  1502. blt 5b
  1503. 6:
  1504. mr r3,r9 /* Init Data pointer */
  1505. mr r4,r10 /* Destination Address */
  1506. bl board_init_r
  1507. #ifndef MINIMAL_SPL
  1508. /*
  1509. * Copy exception vector code to low memory
  1510. *
  1511. * r3: dest_addr
  1512. * r7: source address, r8: end address, r9: target address
  1513. */
  1514. .globl trap_init
  1515. trap_init:
  1516. mflr r11
  1517. bl _GLOBAL_OFFSET_TABLE_-4
  1518. mflr r12
  1519. /* Update IVORs as per relocation */
  1520. mtspr IVPR,r3
  1521. lwz r4,CriticalInput@got(r12)
  1522. mtspr IVOR0,r4 /* 0: Critical input */
  1523. lwz r4,MachineCheck@got(r12)
  1524. mtspr IVOR1,r4 /* 1: Machine check */
  1525. lwz r4,DataStorage@got(r12)
  1526. mtspr IVOR2,r4 /* 2: Data storage */
  1527. lwz r4,InstStorage@got(r12)
  1528. mtspr IVOR3,r4 /* 3: Instruction storage */
  1529. lwz r4,ExtInterrupt@got(r12)
  1530. mtspr IVOR4,r4 /* 4: External interrupt */
  1531. lwz r4,Alignment@got(r12)
  1532. mtspr IVOR5,r4 /* 5: Alignment */
  1533. lwz r4,ProgramCheck@got(r12)
  1534. mtspr IVOR6,r4 /* 6: Program check */
  1535. lwz r4,FPUnavailable@got(r12)
  1536. mtspr IVOR7,r4 /* 7: floating point unavailable */
  1537. lwz r4,SystemCall@got(r12)
  1538. mtspr IVOR8,r4 /* 8: System call */
  1539. /* 9: Auxiliary processor unavailable(unsupported) */
  1540. lwz r4,Decrementer@got(r12)
  1541. mtspr IVOR10,r4 /* 10: Decrementer */
  1542. lwz r4,IntervalTimer@got(r12)
  1543. mtspr IVOR11,r4 /* 11: Interval timer */
  1544. lwz r4,WatchdogTimer@got(r12)
  1545. mtspr IVOR12,r4 /* 12: Watchdog timer */
  1546. lwz r4,DataTLBError@got(r12)
  1547. mtspr IVOR13,r4 /* 13: Data TLB error */
  1548. lwz r4,InstructionTLBError@got(r12)
  1549. mtspr IVOR14,r4 /* 14: Instruction TLB error */
  1550. lwz r4,DebugBreakpoint@got(r12)
  1551. mtspr IVOR15,r4 /* 15: Debug */
  1552. mtlr r11
  1553. blr
  1554. .globl unlock_ram_in_cache
  1555. unlock_ram_in_cache:
  1556. /* invalidate the INIT_RAM section */
  1557. lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
  1558. ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
  1559. mfspr r4,L1CFG0
  1560. andi. r4,r4,0x1ff
  1561. slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
  1562. mtctr r4
  1563. 1: dcbi r0,r3
  1564. #ifdef CONFIG_E6500 /* lock/unlock L2 cache instead of L1 */
  1565. dcblc 2, r0, r3
  1566. #else
  1567. dcblc r0,r3
  1568. #endif
  1569. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  1570. bdnz 1b
  1571. sync
  1572. /* Invalidate the TLB entries for the cache */
  1573. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  1574. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  1575. tlbivax 0,r3
  1576. addi r3,r3,0x1000
  1577. tlbivax 0,r3
  1578. addi r3,r3,0x1000
  1579. tlbivax 0,r3
  1580. addi r3,r3,0x1000
  1581. tlbivax 0,r3
  1582. isync
  1583. blr
  1584. .globl flush_dcache
  1585. flush_dcache:
  1586. mfspr r3,SPRN_L1CFG0
  1587. rlwinm r5,r3,9,3 /* Extract cache block size */
  1588. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  1589. * are currently defined.
  1590. */
  1591. li r4,32
  1592. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  1593. * log2(number of ways)
  1594. */
  1595. slw r5,r4,r5 /* r5 = cache block size */
  1596. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  1597. mulli r7,r7,13 /* An 8-way cache will require 13
  1598. * loads per set.
  1599. */
  1600. slw r7,r7,r6
  1601. /* save off HID0 and set DCFA */
  1602. mfspr r8,SPRN_HID0
  1603. ori r9,r8,HID0_DCFA@l
  1604. mtspr SPRN_HID0,r9
  1605. isync
  1606. lis r4,0
  1607. mtctr r7
  1608. 1: lwz r3,0(r4) /* Load... */
  1609. add r4,r4,r5
  1610. bdnz 1b
  1611. msync
  1612. lis r4,0
  1613. mtctr r7
  1614. 1: dcbf 0,r4 /* ...and flush. */
  1615. add r4,r4,r5
  1616. bdnz 1b
  1617. /* restore HID0 */
  1618. mtspr SPRN_HID0,r8
  1619. isync
  1620. blr
  1621. #endif /* !MINIMAL_SPL */