start.S 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  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_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_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_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. 1: sync
  629. lwz r0, 0(r3)
  630. twi 0, r0, 0
  631. isync
  632. and. r1, r0, r4
  633. bne 1b
  634. lis r4, (L2CSR0_L2E|L2CSR0_L2PE)@h
  635. ori r4, r4, (L2CSR0_L2REP_MODE)@l
  636. sync
  637. stw r4, 0(r3) /* enable L2 */
  638. delete_ccsr_l2_tlb:
  639. delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, r3
  640. #endif
  641. /*
  642. * Enable the L1. On e6500, this has to be done
  643. * after the L2 is up.
  644. */
  645. #ifdef CONFIG_SYS_CACHE_STASHING
  646. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  647. li r2,(32 + 0)
  648. mtspr L1CSR2,r2
  649. #endif
  650. /* Enable/invalidate the I-Cache */
  651. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  652. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  653. mtspr SPRN_L1CSR1,r2
  654. 1:
  655. mfspr r3,SPRN_L1CSR1
  656. and. r1,r3,r2
  657. bne 1b
  658. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  659. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  660. mtspr SPRN_L1CSR1,r3
  661. isync
  662. 2:
  663. mfspr r3,SPRN_L1CSR1
  664. andi. r1,r3,L1CSR1_ICE@l
  665. beq 2b
  666. /* Enable/invalidate the D-Cache */
  667. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  668. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  669. mtspr SPRN_L1CSR0,r2
  670. 1:
  671. mfspr r3,SPRN_L1CSR0
  672. and. r1,r3,r2
  673. bne 1b
  674. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  675. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  676. mtspr SPRN_L1CSR0,r3
  677. isync
  678. 2:
  679. mfspr r3,SPRN_L1CSR0
  680. andi. r1,r3,L1CSR0_DCE@l
  681. beq 2b
  682. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  683. #define DCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
  684. #define LAW_SIZE_1M 0x13
  685. #define DCSRBAR_LAWAR (LAW_EN | (0x1d << 20) | LAW_SIZE_1M)
  686. cmpwi r27,0
  687. beq 9f
  688. /*
  689. * Create a TLB entry for CCSR
  690. *
  691. * We're executing out of TLB1 entry in r14, and that's the only
  692. * TLB entry that exists. To allocate some TLB entries for our
  693. * own use, flip a bit high enough that we won't flip it again
  694. * via incrementing.
  695. */
  696. xori r8, r14, 32
  697. lis r0, MAS0_TLBSEL(1)@h
  698. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  699. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@h
  700. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@l
  701. lis r7, CONFIG_SYS_CCSRBAR@h
  702. ori r7, r7, CONFIG_SYS_CCSRBAR@l
  703. ori r2, r7, MAS2_I|MAS2_G
  704. lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
  705. ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
  706. lis r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  707. ori r4, r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  708. mtspr MAS0, r0
  709. mtspr MAS1, r1
  710. mtspr MAS2, r2
  711. mtspr MAS3, r3
  712. mtspr MAS7, r4
  713. isync
  714. tlbwe
  715. isync
  716. msync
  717. /* Map DCSR temporarily to physical address zero */
  718. li r0, 0
  719. lis r3, DCSRBAR_LAWAR@h
  720. ori r3, r3, DCSRBAR_LAWAR@l
  721. stw r0, 0xc00(r7) /* LAWBARH0 */
  722. stw r0, 0xc04(r7) /* LAWBARL0 */
  723. sync
  724. stw r3, 0xc08(r7) /* LAWAR0 */
  725. /* Read back from LAWAR to ensure the update is complete. */
  726. lwz r3, 0xc08(r7) /* LAWAR0 */
  727. isync
  728. /* Create a TLB entry for DCSR at zero */
  729. addi r9, r8, 1
  730. lis r0, MAS0_TLBSEL(1)@h
  731. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  732. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@h
  733. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@l
  734. li r6, 0 /* DCSR effective address */
  735. ori r2, r6, MAS2_I|MAS2_G
  736. li r3, MAS3_SW|MAS3_SR
  737. li r4, 0
  738. mtspr MAS0, r0
  739. mtspr MAS1, r1
  740. mtspr MAS2, r2
  741. mtspr MAS3, r3
  742. mtspr MAS7, r4
  743. isync
  744. tlbwe
  745. isync
  746. msync
  747. /* enable the timebase */
  748. #define CTBENR 0xe2084
  749. li r3, 1
  750. addis r4, r7, CTBENR@ha
  751. stw r3, CTBENR@l(r4)
  752. lwz r3, CTBENR@l(r4)
  753. twi 0,r3,0
  754. isync
  755. .macro erratum_set_ccsr offset value
  756. addis r3, r7, \offset@ha
  757. lis r4, \value@h
  758. addi r3, r3, \offset@l
  759. ori r4, r4, \value@l
  760. bl erratum_set_value
  761. .endm
  762. .macro erratum_set_dcsr offset value
  763. addis r3, r6, \offset@ha
  764. lis r4, \value@h
  765. addi r3, r3, \offset@l
  766. ori r4, r4, \value@l
  767. bl erratum_set_value
  768. .endm
  769. erratum_set_dcsr 0xb0e08 0xe0201800
  770. erratum_set_dcsr 0xb0e18 0xe0201800
  771. erratum_set_dcsr 0xb0e38 0xe0400000
  772. erratum_set_dcsr 0xb0008 0x00900000
  773. erratum_set_dcsr 0xb0e40 0xe00a0000
  774. erratum_set_ccsr 0x18600 CONFIG_SYS_FSL_CORENET_SNOOPVEC_COREONLY
  775. #ifdef CONFIG_RAMBOOT_PBL
  776. erratum_set_ccsr 0x10f00 0x495e5000
  777. #else
  778. erratum_set_ccsr 0x10f00 0x415e5000
  779. #endif
  780. erratum_set_ccsr 0x11f00 0x415e5000
  781. /* Make temp mapping uncacheable again, if it was initially */
  782. bl 2f
  783. 2: mflr r3
  784. tlbsx 0, r3
  785. mfspr r4, MAS2
  786. rlwimi r4, r15, 0, MAS2_I
  787. rlwimi r4, r15, 0, MAS2_G
  788. mtspr MAS2, r4
  789. isync
  790. tlbwe
  791. isync
  792. msync
  793. /* Clear the cache */
  794. lis r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  795. ori r3,r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  796. sync
  797. isync
  798. mtspr SPRN_L1CSR1,r3
  799. isync
  800. 2: sync
  801. mfspr r4,SPRN_L1CSR1
  802. and. r4,r4,r3
  803. bne 2b
  804. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  805. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  806. sync
  807. isync
  808. mtspr SPRN_L1CSR1,r3
  809. isync
  810. 2: sync
  811. mfspr r4,SPRN_L1CSR1
  812. and. r4,r4,r3
  813. beq 2b
  814. /* Remove temporary mappings */
  815. lis r0, MAS0_TLBSEL(1)@h
  816. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  817. li r3, 0
  818. mtspr MAS0, r0
  819. mtspr MAS1, r3
  820. isync
  821. tlbwe
  822. isync
  823. msync
  824. li r3, 0
  825. stw r3, 0xc08(r7) /* LAWAR0 */
  826. lwz r3, 0xc08(r7)
  827. isync
  828. lis r0, MAS0_TLBSEL(1)@h
  829. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  830. li r3, 0
  831. mtspr MAS0, r0
  832. mtspr MAS1, r3
  833. isync
  834. tlbwe
  835. isync
  836. msync
  837. b 9f
  838. /* r3 = addr, r4 = value, clobbers r5, r11, r12 */
  839. erratum_set_value:
  840. /* Lock two cache lines into I-Cache */
  841. sync
  842. mfspr r11, SPRN_L1CSR1
  843. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  844. sync
  845. isync
  846. mtspr SPRN_L1CSR1, r11
  847. isync
  848. mflr r12
  849. bl 5f
  850. 5: mflr r5
  851. addi r5, r5, 2f - 5b
  852. icbtls 0, 0, r5
  853. addi r5, r5, 64
  854. sync
  855. mfspr r11, SPRN_L1CSR1
  856. 3: andi. r11, r11, L1CSR1_ICUL
  857. bne 3b
  858. icbtls 0, 0, r5
  859. addi r5, r5, 64
  860. sync
  861. mfspr r11, SPRN_L1CSR1
  862. 3: andi. r11, r11, L1CSR1_ICUL
  863. bne 3b
  864. b 2f
  865. .align 6
  866. /* Inside a locked cacheline, wait a while, write, then wait a while */
  867. 2: sync
  868. mfspr r5, SPRN_TBRL
  869. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  870. 4: mfspr r5, SPRN_TBRL
  871. subf. r5, r5, r11
  872. bgt 4b
  873. stw r4, 0(r3)
  874. mfspr r5, SPRN_TBRL
  875. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  876. 4: mfspr r5, SPRN_TBRL
  877. subf. r5, r5, r11
  878. bgt 4b
  879. sync
  880. /*
  881. * Fill out the rest of this cache line and the next with nops,
  882. * to ensure that nothing outside the locked area will be
  883. * fetched due to a branch.
  884. */
  885. .rept 19
  886. nop
  887. .endr
  888. sync
  889. mfspr r11, SPRN_L1CSR1
  890. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  891. sync
  892. isync
  893. mtspr SPRN_L1CSR1, r11
  894. isync
  895. mtlr r12
  896. blr
  897. 9:
  898. #endif
  899. create_init_ram_area:
  900. lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
  901. ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
  902. #ifdef NOR_BOOT
  903. /* create a temp mapping in AS=1 to the 4M boot window */
  904. create_tlb1_entry 15, \
  905. 1, BOOKE_PAGESZ_4M, \
  906. CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
  907. 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  908. 0, r6
  909. #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
  910. /* create a temp mapping in AS = 1 for Flash mapping
  911. * created by PBL for ISBC code
  912. */
  913. create_tlb1_entry 15, \
  914. 1, BOOKE_PAGESZ_1M, \
  915. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  916. CONFIG_SYS_PBI_FLASH_WINDOW & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  917. 0, r6
  918. #else
  919. /*
  920. * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
  921. * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
  922. */
  923. create_tlb1_entry 15, \
  924. 1, BOOKE_PAGESZ_1M, \
  925. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  926. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  927. 0, r6
  928. #endif
  929. /* create a temp mapping in AS=1 to the stack */
  930. #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
  931. defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
  932. create_tlb1_entry 14, \
  933. 1, BOOKE_PAGESZ_16K, \
  934. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  935. CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, MAS3_SX|MAS3_SW|MAS3_SR, \
  936. CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH, r6
  937. #else
  938. create_tlb1_entry 14, \
  939. 1, BOOKE_PAGESZ_16K, \
  940. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  941. CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, \
  942. 0, r6
  943. #endif
  944. lis r6,MSR_IS|MSR_DS|MSR_DE@h
  945. ori r6,r6,MSR_IS|MSR_DS|MSR_DE@l
  946. lis r7,switch_as@h
  947. ori r7,r7,switch_as@l
  948. mtspr SPRN_SRR0,r7
  949. mtspr SPRN_SRR1,r6
  950. rfi
  951. switch_as:
  952. /* L1 DCache is used for initial RAM */
  953. /* Allocate Initial RAM in data cache.
  954. */
  955. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  956. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  957. mfspr r2, L1CFG0
  958. andi. r2, r2, 0x1ff
  959. /* cache size * 1024 / (2 * L1 line size) */
  960. slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
  961. mtctr r2
  962. li r0,0
  963. 1:
  964. dcbz r0,r3
  965. dcbtls 0,r0,r3
  966. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  967. bdnz 1b
  968. /* Jump out the last 4K page and continue to 'normal' start */
  969. #if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)
  970. /* We assume that we're already running at the address we're linked at */
  971. b _start_cont
  972. #else
  973. /* Calculate absolute address in FLASH and jump there */
  974. /*--------------------------------------------------------------*/
  975. lis r3,CONFIG_SYS_MONITOR_BASE@h
  976. ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
  977. addi r3,r3,_start_cont - _start
  978. mtlr r3
  979. blr
  980. #endif
  981. .text
  982. .globl _start
  983. _start:
  984. .long 0x27051956 /* U-BOOT Magic Number */
  985. .globl version_string
  986. version_string:
  987. .ascii U_BOOT_VERSION_STRING, "\0"
  988. .align 4
  989. .globl _start_cont
  990. _start_cont:
  991. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  992. lis r3,(CONFIG_SYS_INIT_RAM_ADDR)@h
  993. ori r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
  994. li r0,0
  995. stw r0,0(r3) /* Terminate Back Chain */
  996. stw r0,+4(r3) /* NULL return address. */
  997. mr r1,r3 /* Transfer to SP(r1) */
  998. GET_GOT
  999. /* Pass our potential ePAPR device tree pointer to cpu_init_early_f */
  1000. mr r3, r24
  1001. bl cpu_init_early_f
  1002. /* switch back to AS = 0 */
  1003. lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
  1004. ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
  1005. mtmsr r3
  1006. isync
  1007. bl cpu_init_f /* return boot_flag for calling board_init_f */
  1008. bl board_init_f
  1009. isync
  1010. /* NOTREACHED - board_init_f() does not return */
  1011. #ifndef MINIMAL_SPL
  1012. .globl _start_of_vectors
  1013. _start_of_vectors:
  1014. /* Critical input. */
  1015. CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
  1016. /* Machine check */
  1017. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  1018. /* Data Storage exception. */
  1019. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  1020. /* Instruction Storage exception. */
  1021. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  1022. /* External Interrupt exception. */
  1023. STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
  1024. /* Alignment exception. */
  1025. Alignment:
  1026. EXCEPTION_PROLOG(SRR0, SRR1)
  1027. mfspr r4,DAR
  1028. stw r4,_DAR(r21)
  1029. mfspr r5,DSISR
  1030. stw r5,_DSISR(r21)
  1031. addi r3,r1,STACK_FRAME_OVERHEAD
  1032. EXC_XFER_TEMPLATE(0x600, Alignment, AlignmentException,
  1033. MSR_KERNEL, COPY_EE)
  1034. /* Program check exception */
  1035. ProgramCheck:
  1036. EXCEPTION_PROLOG(SRR0, SRR1)
  1037. addi r3,r1,STACK_FRAME_OVERHEAD
  1038. EXC_XFER_TEMPLATE(0x700, ProgramCheck, ProgramCheckException,
  1039. MSR_KERNEL, COPY_EE)
  1040. /* No FPU on MPC85xx. This exception is not supposed to happen.
  1041. */
  1042. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  1043. STD_EXCEPTION(0x0900, SystemCall, UnknownException)
  1044. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  1045. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  1046. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  1047. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  1048. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  1049. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  1050. .globl _end_of_vectors
  1051. _end_of_vectors:
  1052. . = . + (0x100 - ( . & 0xff )) /* align for debug */
  1053. /*
  1054. * This code finishes saving the registers to the exception frame
  1055. * and jumps to the appropriate handler for the exception.
  1056. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  1057. * r23 is the address of the handler.
  1058. */
  1059. .globl transfer_to_handler
  1060. transfer_to_handler:
  1061. SAVE_GPR(7, r21)
  1062. SAVE_4GPRS(8, r21)
  1063. SAVE_8GPRS(12, r21)
  1064. SAVE_8GPRS(24, r21)
  1065. li r22,0
  1066. stw r22,RESULT(r21)
  1067. mtspr SPRG2,r22 /* r1 is now kernel sp */
  1068. mtctr r23 /* virtual address of handler */
  1069. mtmsr r20
  1070. bctrl
  1071. int_return:
  1072. mfmsr r28 /* Disable interrupts */
  1073. li r4,0
  1074. ori r4,r4,MSR_EE
  1075. andc r28,r28,r4
  1076. SYNC /* Some chip revs need this... */
  1077. mtmsr r28
  1078. SYNC
  1079. lwz r2,_CTR(r1)
  1080. lwz r0,_LINK(r1)
  1081. mtctr r2
  1082. mtlr r0
  1083. lwz r2,_XER(r1)
  1084. lwz r0,_CCR(r1)
  1085. mtspr XER,r2
  1086. mtcrf 0xFF,r0
  1087. REST_10GPRS(3, r1)
  1088. REST_10GPRS(13, r1)
  1089. REST_8GPRS(23, r1)
  1090. REST_GPR(31, r1)
  1091. lwz r2,_NIP(r1) /* Restore environment */
  1092. lwz r0,_MSR(r1)
  1093. mtspr SRR0,r2
  1094. mtspr SRR1,r0
  1095. lwz r0,GPR0(r1)
  1096. lwz r2,GPR2(r1)
  1097. lwz r1,GPR1(r1)
  1098. SYNC
  1099. rfi
  1100. /* Cache functions.
  1101. */
  1102. .globl flush_icache
  1103. flush_icache:
  1104. .globl invalidate_icache
  1105. invalidate_icache:
  1106. mfspr r0,L1CSR1
  1107. ori r0,r0,L1CSR1_ICFI
  1108. msync
  1109. isync
  1110. mtspr L1CSR1,r0
  1111. isync
  1112. blr /* entire I cache */
  1113. .globl invalidate_dcache
  1114. invalidate_dcache:
  1115. mfspr r0,L1CSR0
  1116. ori r0,r0,L1CSR0_DCFI
  1117. msync
  1118. isync
  1119. mtspr L1CSR0,r0
  1120. isync
  1121. blr
  1122. .globl icache_enable
  1123. icache_enable:
  1124. mflr r8
  1125. bl invalidate_icache
  1126. mtlr r8
  1127. isync
  1128. mfspr r4,L1CSR1
  1129. ori r4,r4,0x0001
  1130. oris r4,r4,0x0001
  1131. mtspr L1CSR1,r4
  1132. isync
  1133. blr
  1134. .globl icache_disable
  1135. icache_disable:
  1136. mfspr r0,L1CSR1
  1137. lis r3,0
  1138. ori r3,r3,L1CSR1_ICE
  1139. andc r0,r0,r3
  1140. mtspr L1CSR1,r0
  1141. isync
  1142. blr
  1143. .globl icache_status
  1144. icache_status:
  1145. mfspr r3,L1CSR1
  1146. andi. r3,r3,L1CSR1_ICE
  1147. blr
  1148. .globl dcache_enable
  1149. dcache_enable:
  1150. mflr r8
  1151. bl invalidate_dcache
  1152. mtlr r8
  1153. isync
  1154. mfspr r0,L1CSR0
  1155. ori r0,r0,0x0001
  1156. oris r0,r0,0x0001
  1157. msync
  1158. isync
  1159. mtspr L1CSR0,r0
  1160. isync
  1161. blr
  1162. .globl dcache_disable
  1163. dcache_disable:
  1164. mfspr r3,L1CSR0
  1165. lis r4,0
  1166. ori r4,r4,L1CSR0_DCE
  1167. andc r3,r3,r4
  1168. mtspr L1CSR0,r3
  1169. isync
  1170. blr
  1171. .globl dcache_status
  1172. dcache_status:
  1173. mfspr r3,L1CSR0
  1174. andi. r3,r3,L1CSR0_DCE
  1175. blr
  1176. .globl get_pvr
  1177. get_pvr:
  1178. mfspr r3,PVR
  1179. blr
  1180. .globl get_svr
  1181. get_svr:
  1182. mfspr r3,SVR
  1183. blr
  1184. /*------------------------------------------------------------------------------- */
  1185. /* Function: in8 */
  1186. /* Description: Input 8 bits */
  1187. /*------------------------------------------------------------------------------- */
  1188. .globl in8
  1189. in8:
  1190. lbz r3,0x0000(r3)
  1191. blr
  1192. /*------------------------------------------------------------------------------- */
  1193. /* Function: out8 */
  1194. /* Description: Output 8 bits */
  1195. /*------------------------------------------------------------------------------- */
  1196. .globl out8
  1197. out8:
  1198. stb r4,0x0000(r3)
  1199. sync
  1200. blr
  1201. /*------------------------------------------------------------------------------- */
  1202. /* Function: out16 */
  1203. /* Description: Output 16 bits */
  1204. /*------------------------------------------------------------------------------- */
  1205. .globl out16
  1206. out16:
  1207. sth r4,0x0000(r3)
  1208. sync
  1209. blr
  1210. /*------------------------------------------------------------------------------- */
  1211. /* Function: out16r */
  1212. /* Description: Byte reverse and output 16 bits */
  1213. /*------------------------------------------------------------------------------- */
  1214. .globl out16r
  1215. out16r:
  1216. sthbrx r4,r0,r3
  1217. sync
  1218. blr
  1219. /*------------------------------------------------------------------------------- */
  1220. /* Function: out32 */
  1221. /* Description: Output 32 bits */
  1222. /*------------------------------------------------------------------------------- */
  1223. .globl out32
  1224. out32:
  1225. stw r4,0x0000(r3)
  1226. sync
  1227. blr
  1228. /*------------------------------------------------------------------------------- */
  1229. /* Function: out32r */
  1230. /* Description: Byte reverse and output 32 bits */
  1231. /*------------------------------------------------------------------------------- */
  1232. .globl out32r
  1233. out32r:
  1234. stwbrx r4,r0,r3
  1235. sync
  1236. blr
  1237. /*------------------------------------------------------------------------------- */
  1238. /* Function: in16 */
  1239. /* Description: Input 16 bits */
  1240. /*------------------------------------------------------------------------------- */
  1241. .globl in16
  1242. in16:
  1243. lhz r3,0x0000(r3)
  1244. blr
  1245. /*------------------------------------------------------------------------------- */
  1246. /* Function: in16r */
  1247. /* Description: Input 16 bits and byte reverse */
  1248. /*------------------------------------------------------------------------------- */
  1249. .globl in16r
  1250. in16r:
  1251. lhbrx r3,r0,r3
  1252. blr
  1253. /*------------------------------------------------------------------------------- */
  1254. /* Function: in32 */
  1255. /* Description: Input 32 bits */
  1256. /*------------------------------------------------------------------------------- */
  1257. .globl in32
  1258. in32:
  1259. lwz 3,0x0000(3)
  1260. blr
  1261. /*------------------------------------------------------------------------------- */
  1262. /* Function: in32r */
  1263. /* Description: Input 32 bits and byte reverse */
  1264. /*------------------------------------------------------------------------------- */
  1265. .globl in32r
  1266. in32r:
  1267. lwbrx r3,r0,r3
  1268. blr
  1269. #endif /* !MINIMAL_SPL */
  1270. /*------------------------------------------------------------------------------*/
  1271. /*
  1272. * void write_tlb(mas0, mas1, mas2, mas3, mas7)
  1273. */
  1274. .globl write_tlb
  1275. write_tlb:
  1276. mtspr MAS0,r3
  1277. mtspr MAS1,r4
  1278. mtspr MAS2,r5
  1279. mtspr MAS3,r6
  1280. #ifdef CONFIG_ENABLE_36BIT_PHYS
  1281. mtspr MAS7,r7
  1282. #endif
  1283. li r3,0
  1284. #ifdef CONFIG_SYS_BOOK3E_HV
  1285. mtspr MAS8,r3
  1286. #endif
  1287. isync
  1288. tlbwe
  1289. msync
  1290. isync
  1291. blr
  1292. /*
  1293. * void relocate_code (addr_sp, gd, addr_moni)
  1294. *
  1295. * This "function" does not return, instead it continues in RAM
  1296. * after relocating the monitor code.
  1297. *
  1298. * r3 = dest
  1299. * r4 = src
  1300. * r5 = length in bytes
  1301. * r6 = cachelinesize
  1302. */
  1303. .globl relocate_code
  1304. relocate_code:
  1305. mr r1,r3 /* Set new stack pointer */
  1306. mr r9,r4 /* Save copy of Init Data pointer */
  1307. mr r10,r5 /* Save copy of Destination Address */
  1308. GET_GOT
  1309. #ifndef CONFIG_SPL_SKIP_RELOCATE
  1310. mr r3,r5 /* Destination Address */
  1311. lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  1312. ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
  1313. lwz r5,GOT(__init_end)
  1314. sub r5,r5,r4
  1315. li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  1316. /*
  1317. * Fix GOT pointer:
  1318. *
  1319. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  1320. *
  1321. * Offset:
  1322. */
  1323. sub r15,r10,r4
  1324. /* First our own GOT */
  1325. add r12,r12,r15
  1326. /* the the one used by the C code */
  1327. add r30,r30,r15
  1328. /*
  1329. * Now relocate code
  1330. */
  1331. cmplw cr1,r3,r4
  1332. addi r0,r5,3
  1333. srwi. r0,r0,2
  1334. beq cr1,4f /* In place copy is not necessary */
  1335. beq 7f /* Protect against 0 count */
  1336. mtctr r0
  1337. bge cr1,2f
  1338. la r8,-4(r4)
  1339. la r7,-4(r3)
  1340. 1: lwzu r0,4(r8)
  1341. stwu r0,4(r7)
  1342. bdnz 1b
  1343. b 4f
  1344. 2: slwi r0,r0,2
  1345. add r8,r4,r0
  1346. add r7,r3,r0
  1347. 3: lwzu r0,-4(r8)
  1348. stwu r0,-4(r7)
  1349. bdnz 3b
  1350. /*
  1351. * Now flush the cache: note that we must start from a cache aligned
  1352. * address. Otherwise we might miss one cache line.
  1353. */
  1354. 4: cmpwi r6,0
  1355. add r5,r3,r5
  1356. beq 7f /* Always flush prefetch queue in any case */
  1357. subi r0,r6,1
  1358. andc r3,r3,r0
  1359. mr r4,r3
  1360. 5: dcbst 0,r4
  1361. add r4,r4,r6
  1362. cmplw r4,r5
  1363. blt 5b
  1364. sync /* Wait for all dcbst to complete on bus */
  1365. mr r4,r3
  1366. 6: icbi 0,r4
  1367. add r4,r4,r6
  1368. cmplw r4,r5
  1369. blt 6b
  1370. 7: sync /* Wait for all icbi to complete on bus */
  1371. isync
  1372. /*
  1373. * We are done. Do not return, instead branch to second part of board
  1374. * initialization, now running from RAM.
  1375. */
  1376. addi r0,r10,in_ram - _start
  1377. /*
  1378. * As IVPR is going to point RAM address,
  1379. * Make sure IVOR15 has valid opcode to support debugger
  1380. */
  1381. mtspr IVOR15,r0
  1382. /*
  1383. * Re-point the IVPR at RAM
  1384. */
  1385. mtspr IVPR,r10
  1386. mtlr r0
  1387. blr /* NEVER RETURNS! */
  1388. #endif
  1389. .globl in_ram
  1390. in_ram:
  1391. /*
  1392. * Relocation Function, r12 point to got2+0x8000
  1393. *
  1394. * Adjust got2 pointers, no need to check for 0, this code
  1395. * already puts a few entries in the table.
  1396. */
  1397. li r0,__got2_entries@sectoff@l
  1398. la r3,GOT(_GOT2_TABLE_)
  1399. lwz r11,GOT(_GOT2_TABLE_)
  1400. mtctr r0
  1401. sub r11,r3,r11
  1402. addi r3,r3,-4
  1403. 1: lwzu r0,4(r3)
  1404. cmpwi r0,0
  1405. beq- 2f
  1406. add r0,r0,r11
  1407. stw r0,0(r3)
  1408. 2: bdnz 1b
  1409. /*
  1410. * Now adjust the fixups and the pointers to the fixups
  1411. * in case we need to move ourselves again.
  1412. */
  1413. li r0,__fixup_entries@sectoff@l
  1414. lwz r3,GOT(_FIXUP_TABLE_)
  1415. cmpwi r0,0
  1416. mtctr r0
  1417. addi r3,r3,-4
  1418. beq 4f
  1419. 3: lwzu r4,4(r3)
  1420. lwzux r0,r4,r11
  1421. cmpwi r0,0
  1422. add r0,r0,r11
  1423. stw r4,0(r3)
  1424. beq- 5f
  1425. stw r0,0(r4)
  1426. 5: bdnz 3b
  1427. 4:
  1428. clear_bss:
  1429. /*
  1430. * Now clear BSS segment
  1431. */
  1432. lwz r3,GOT(__bss_start)
  1433. lwz r4,GOT(__bss_end)
  1434. cmplw 0,r3,r4
  1435. beq 6f
  1436. li r0,0
  1437. 5:
  1438. stw r0,0(r3)
  1439. addi r3,r3,4
  1440. cmplw 0,r3,r4
  1441. blt 5b
  1442. 6:
  1443. mr r3,r9 /* Init Data pointer */
  1444. mr r4,r10 /* Destination Address */
  1445. bl board_init_r
  1446. #ifndef MINIMAL_SPL
  1447. /*
  1448. * Copy exception vector code to low memory
  1449. *
  1450. * r3: dest_addr
  1451. * r7: source address, r8: end address, r9: target address
  1452. */
  1453. .globl trap_init
  1454. trap_init:
  1455. /* Update IVORs as per relocation */
  1456. mtspr IVPR,r3
  1457. li r4,CriticalInput@l
  1458. mtspr IVOR0,r4 /* 0: Critical input */
  1459. li r4,MachineCheck@l
  1460. mtspr IVOR1,r4 /* 1: Machine check */
  1461. li r4,DataStorage@l
  1462. mtspr IVOR2,r4 /* 2: Data storage */
  1463. li r4,InstStorage@l
  1464. mtspr IVOR3,r4 /* 3: Instruction storage */
  1465. li r4,ExtInterrupt@l
  1466. mtspr IVOR4,r4 /* 4: External interrupt */
  1467. li r4,Alignment@l
  1468. mtspr IVOR5,r4 /* 5: Alignment */
  1469. li r4,ProgramCheck@l
  1470. mtspr IVOR6,r4 /* 6: Program check */
  1471. li r4,FPUnavailable@l
  1472. mtspr IVOR7,r4 /* 7: floating point unavailable */
  1473. li r4,SystemCall@l
  1474. mtspr IVOR8,r4 /* 8: System call */
  1475. /* 9: Auxiliary processor unavailable(unsupported) */
  1476. li r4,Decrementer@l
  1477. mtspr IVOR10,r4 /* 10: Decrementer */
  1478. li r4,IntervalTimer@l
  1479. mtspr IVOR11,r4 /* 11: Interval timer */
  1480. li r4,WatchdogTimer@l
  1481. mtspr IVOR12,r4 /* 12: Watchdog timer */
  1482. li r4,DataTLBError@l
  1483. mtspr IVOR13,r4 /* 13: Data TLB error */
  1484. li r4,InstructionTLBError@l
  1485. mtspr IVOR14,r4 /* 14: Instruction TLB error */
  1486. li r4,DebugBreakpoint@l
  1487. mtspr IVOR15,r4 /* 15: Debug */
  1488. blr
  1489. .globl unlock_ram_in_cache
  1490. unlock_ram_in_cache:
  1491. /* invalidate the INIT_RAM section */
  1492. lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
  1493. ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
  1494. mfspr r4,L1CFG0
  1495. andi. r4,r4,0x1ff
  1496. slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
  1497. mtctr r4
  1498. 1: dcbi r0,r3
  1499. dcblc r0,r3
  1500. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  1501. bdnz 1b
  1502. sync
  1503. /* Invalidate the TLB entries for the cache */
  1504. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  1505. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  1506. tlbivax 0,r3
  1507. addi r3,r3,0x1000
  1508. tlbivax 0,r3
  1509. addi r3,r3,0x1000
  1510. tlbivax 0,r3
  1511. addi r3,r3,0x1000
  1512. tlbivax 0,r3
  1513. isync
  1514. blr
  1515. .globl flush_dcache
  1516. flush_dcache:
  1517. mfspr r3,SPRN_L1CFG0
  1518. rlwinm r5,r3,9,3 /* Extract cache block size */
  1519. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  1520. * are currently defined.
  1521. */
  1522. li r4,32
  1523. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  1524. * log2(number of ways)
  1525. */
  1526. slw r5,r4,r5 /* r5 = cache block size */
  1527. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  1528. mulli r7,r7,13 /* An 8-way cache will require 13
  1529. * loads per set.
  1530. */
  1531. slw r7,r7,r6
  1532. /* save off HID0 and set DCFA */
  1533. mfspr r8,SPRN_HID0
  1534. ori r9,r8,HID0_DCFA@l
  1535. mtspr SPRN_HID0,r9
  1536. isync
  1537. lis r4,0
  1538. mtctr r7
  1539. 1: lwz r3,0(r4) /* Load... */
  1540. add r4,r4,r5
  1541. bdnz 1b
  1542. msync
  1543. lis r4,0
  1544. mtctr r7
  1545. 1: dcbf 0,r4 /* ...and flush. */
  1546. add r4,r4,r5
  1547. bdnz 1b
  1548. /* restore HID0 */
  1549. mtspr SPRN_HID0,r8
  1550. isync
  1551. blr
  1552. #endif /* !MINIMAL_SPL */