start.S 44 KB

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