blob: dbbd8e588c587c4948eb6bd5d5f961d4d3b0b331 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Prabhakar Kushwaha2153b572012-02-14 22:49:29 +00002 * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc.
wdenk9c53f402003-10-15 23:53:47 +00003 * Copyright (C) 2003 Motorola,Inc.
wdenk9c53f402003-10-15 23:53:47 +00004 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00006 */
7
8/* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
9 *
10 * The processor starts at 0xfffffffc and the code is first executed in the
11 * last 4K page(0xfffff000-0xffffffff) in flash/rom.
12 *
13 */
14
Wolfgang Denk0191e472010-10-26 14:34:52 +020015#include <asm-offsets.h>
wdenk9c53f402003-10-15 23:53:47 +000016#include <config.h>
17#include <mpc85xx.h>
18#include <version.h>
19
wdenk9c53f402003-10-15 23:53:47 +000020#include <ppc_asm.tmpl>
21#include <ppc_defs.h>
22
23#include <asm/cache.h>
24#include <asm/mmu.h>
25
wdenk9c53f402003-10-15 23:53:47 +000026#undef MSR_KERNEL
Andy Flemingf08233c2007-08-14 01:34:21 -050027#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
wdenk9c53f402003-10-15 23:53:47 +000028
Scott Wood7c810902012-09-20 16:35:21 -050029#if defined(CONFIG_NAND_SPL) || \
30 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
31#define MINIMAL_SPL
32#endif
33
Liu Gangee9d7532013-06-28 17:58:37 +080034#if !defined(CONFIG_SPL) && !defined(CONFIG_SYS_RAMBOOT) && \
35 !defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SRIO_PCIE_BOOT_SLAVE)
Scott Wood7c810902012-09-20 16:35:21 -050036#define NOR_BOOT
37#endif
38
wdenk9c53f402003-10-15 23:53:47 +000039/*
40 * Set up GOT: Global Offset Table
41 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010042 * Use r12 to access the GOT
wdenk9c53f402003-10-15 23:53:47 +000043 */
44 START_GOT
45 GOT_ENTRY(_GOT2_TABLE_)
46 GOT_ENTRY(_FIXUP_TABLE_)
47
Scott Wood7c810902012-09-20 16:35:21 -050048#ifndef MINIMAL_SPL
wdenk9c53f402003-10-15 23:53:47 +000049 GOT_ENTRY(_start)
50 GOT_ENTRY(_start_of_vectors)
51 GOT_ENTRY(_end_of_vectors)
52 GOT_ENTRY(transfer_to_handler)
Mingkai Hu0255cd72009-09-11 14:19:10 +080053#endif
wdenk9c53f402003-10-15 23:53:47 +000054
55 GOT_ENTRY(__init_end)
Simon Glassed70c8f2013-03-14 06:54:53 +000056 GOT_ENTRY(__bss_end)
wdenk9c53f402003-10-15 23:53:47 +000057 GOT_ENTRY(__bss_start)
58 END_GOT
59
60/*
61 * e500 Startup -- after reset only the last 4KB of the effective
62 * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
63 * section is located at THIS LAST page and basically does three
64 * things: clear some registers, set up exception tables and
65 * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
66 * continue the boot procedure.
67
68 * Once the boot rom is mapped by TLB entries we can proceed
69 * with normal startup.
70 *
71 */
72
Andy Flemingf08233c2007-08-14 01:34:21 -050073 .section .bootpg,"ax"
74 .globl _start_e500
wdenk9c53f402003-10-15 23:53:47 +000075
76_start_e500:
Prabhakar Kushwaha8f3e8922012-04-29 23:56:30 +000077/* Enable debug exception */
78 li r1,MSR_DE
79 mtmsr r1
wdenka445ddf2004-06-09 00:34:46 +000080
Scott Wood80806962012-08-14 10:14:53 +000081#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
82 mfspr r3,SPRN_SVR
83 rlwinm r3,r3,0,0xff
84 li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
85 cmpw r3,r4
86 beq 1f
87
88#ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
89 li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
90 cmpw r3,r4
91 beq 1f
92#endif
93
94 /* Not a supported revision affected by erratum */
95 li r27,0
96 b 2f
97
981: li r27,1 /* Remember for later that we have the erratum */
99 /* Erratum says set bits 55:60 to 001001 */
100 msync
101 isync
Andy Flemingeab55c02013-03-25 07:33:10 +0000102 mfspr r3,SPRN_HDBCR0
Scott Wood80806962012-08-14 10:14:53 +0000103 li r4,0x48
104 rlwimi r3,r4,0,0x1f8
Andy Flemingeab55c02013-03-25 07:33:10 +0000105 mtspr SPRN_HDBCR0,r3
Scott Wood80806962012-08-14 10:14:53 +0000106 isync
1072:
108#endif
York Sun0cc59072013-08-20 15:09:43 -0700109#ifdef CONFIG_SYS_FSL_ERRATUM_A005125
110 msync
111 isync
112 mfspr r3, SPRN_HDBCR0
113 oris r3, r3, 0x0080
114 mtspr SPRN_HDBCR0, r3
115#endif
116
Scott Wood80806962012-08-14 10:14:53 +0000117
Ruchika Gupta8ca8d822010-12-15 17:02:08 +0000118#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC)
119 /* ISBC uses L2 as stack.
120 * Disable L2 cache here so that u-boot can enable it later
121 * as part of it's normal flow
122 */
123
124 /* Check if L2 is enabled */
125 mfspr r3, SPRN_L2CSR0
126 lis r2, L2CSR0_L2E@h
127 ori r2, r2, L2CSR0_L2E@l
128 and. r4, r3, r2
129 beq l2_disabled
130
131 mfspr r3, SPRN_L2CSR0
132 /* Flush L2 cache */
133 lis r2,(L2CSR0_L2FL)@h
134 ori r2, r2, (L2CSR0_L2FL)@l
135 or r3, r2, r3
136 sync
137 isync
138 mtspr SPRN_L2CSR0,r3
139 isync
1401:
141 mfspr r3, SPRN_L2CSR0
142 and. r1, r3, r2
143 bne 1b
144
145 mfspr r3, SPRN_L2CSR0
146 lis r2, L2CSR0_L2E@h
147 ori r2, r2, L2CSR0_L2E@l
148 andc r4, r3, r2
149 sync
150 isync
151 mtspr SPRN_L2CSR0,r4
152 isync
153
154l2_disabled:
155#endif
156
Andy Flemingf08233c2007-08-14 01:34:21 -0500157/* clear registers/arrays not reset by hardware */
wdenk9c53f402003-10-15 23:53:47 +0000158
Andy Flemingf08233c2007-08-14 01:34:21 -0500159 /* L1 */
160 li r0,2
161 mtspr L1CSR0,r0 /* invalidate d-cache */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200162 mtspr L1CSR1,r0 /* invalidate i-cache */
wdenk9c53f402003-10-15 23:53:47 +0000163
164 mfspr r1,DBSR
165 mtspr DBSR,r1 /* Clear all valid bits */
166
wdenk9c53f402003-10-15 23:53:47 +0000167
York Sun0f2f2a32012-10-08 07:44:07 +0000168 .macro create_tlb1_entry esel ts tsize epn wimg rpn perm phy_high scratch
169 lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
170 ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
171 mtspr MAS0, \scratch
172 lis \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@h
173 ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 1, 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
190 .macro create_tlb0_entry esel ts tsize epn wimg rpn perm phy_high scratch
191 lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
192 ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
193 mtspr MAS0, \scratch
194 lis \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@h
195 ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@l
196 mtspr MAS1, \scratch
197 lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
198 ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
199 mtspr MAS2, \scratch
200 lis \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
201 ori \scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
202 mtspr MAS3, \scratch
203 lis \scratch, \phy_high@h
204 ori \scratch, \scratch, \phy_high@l
205 mtspr MAS7, \scratch
206 isync
207 msync
208 tlbwe
209 isync
210 .endm
211
212 .macro delete_tlb1_entry esel scratch
213 lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
214 ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
215 mtspr MAS0, \scratch
216 li \scratch, 0
217 mtspr MAS1, \scratch
218 isync
219 msync
220 tlbwe
221 isync
222 .endm
223
224 .macro delete_tlb0_entry esel epn wimg scratch
225 lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
226 ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
227 mtspr MAS0, \scratch
228 li \scratch, 0
229 mtspr MAS1, \scratch
230 lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
231 ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
232 mtspr MAS2, \scratch
233 isync
234 msync
235 tlbwe
236 isync
237 .endm
238
Scott Wood7c810902012-09-20 16:35:21 -0500239/* Interrupt vectors do not fit in minimal SPL. */
240#if !defined(MINIMAL_SPL)
wdenk9c53f402003-10-15 23:53:47 +0000241 /* Setup interrupt vectors */
Haiying Wang439a7bf2010-11-10 15:37:13 -0500242 lis r1,CONFIG_SYS_MONITOR_BASE@h
Andy Flemingf08233c2007-08-14 01:34:21 -0500243 mtspr IVPR,r1
wdenk9c53f402003-10-15 23:53:47 +0000244
Prabhakar Kushwaha2153b572012-02-14 22:49:29 +0000245 lis r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@h
246 ori r3,r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@l
247
248 addi r4,r3,CriticalInput - _start + _START_OFFSET
249 mtspr IVOR0,r4 /* 0: Critical input */
250 addi r4,r3,MachineCheck - _start + _START_OFFSET
251 mtspr IVOR1,r4 /* 1: Machine check */
252 addi r4,r3,DataStorage - _start + _START_OFFSET
253 mtspr IVOR2,r4 /* 2: Data storage */
254 addi r4,r3,InstStorage - _start + _START_OFFSET
255 mtspr IVOR3,r4 /* 3: Instruction storage */
256 addi r4,r3,ExtInterrupt - _start + _START_OFFSET
257 mtspr IVOR4,r4 /* 4: External interrupt */
258 addi r4,r3,Alignment - _start + _START_OFFSET
259 mtspr IVOR5,r4 /* 5: Alignment */
260 addi r4,r3,ProgramCheck - _start + _START_OFFSET
261 mtspr IVOR6,r4 /* 6: Program check */
262 addi r4,r3,FPUnavailable - _start + _START_OFFSET
263 mtspr IVOR7,r4 /* 7: floating point unavailable */
264 addi r4,r3,SystemCall - _start + _START_OFFSET
265 mtspr IVOR8,r4 /* 8: System call */
wdenk9c53f402003-10-15 23:53:47 +0000266 /* 9: Auxiliary processor unavailable(unsupported) */
Prabhakar Kushwaha2153b572012-02-14 22:49:29 +0000267 addi r4,r3,Decrementer - _start + _START_OFFSET
268 mtspr IVOR10,r4 /* 10: Decrementer */
269 addi r4,r3,IntervalTimer - _start + _START_OFFSET
270 mtspr IVOR11,r4 /* 11: Interval timer */
271 addi r4,r3,WatchdogTimer - _start + _START_OFFSET
272 mtspr IVOR12,r4 /* 12: Watchdog timer */
273 addi r4,r3,DataTLBError - _start + _START_OFFSET
274 mtspr IVOR13,r4 /* 13: Data TLB error */
275 addi r4,r3,InstructionTLBError - _start + _START_OFFSET
276 mtspr IVOR14,r4 /* 14: Instruction TLB error */
277 addi r4,r3,DebugBreakpoint - _start + _START_OFFSET
278 mtspr IVOR15,r4 /* 15: Debug */
Prabhakar Kushwaha4a664222012-02-14 22:50:02 +0000279#endif
wdenk9c53f402003-10-15 23:53:47 +0000280
wdenk9c53f402003-10-15 23:53:47 +0000281 /* Clear and set up some registers. */
Kumar Gala9772ee72008-01-16 22:38:34 -0600282 li r0,0x0000
wdenk9c53f402003-10-15 23:53:47 +0000283 lis r1,0xffff
284 mtspr DEC,r0 /* prevent dec exceptions */
285 mttbl r0 /* prevent fit & wdt exceptions */
286 mttbu r0
287 mtspr TSR,r1 /* clear all timer exception status */
288 mtspr TCR,r0 /* disable all */
289 mtspr ESR,r0 /* clear exception syndrome register */
290 mtspr MCSR,r0 /* machine check syndrome register */
291 mtxer r0 /* clear integer exception register */
wdenk9c53f402003-10-15 23:53:47 +0000292
Scott Wood31e60102009-08-20 17:45:05 -0500293#ifdef CONFIG_SYS_BOOK3E_HV
294 mtspr MAS8,r0 /* make sure MAS8 is clear */
295#endif
296
wdenk9c53f402003-10-15 23:53:47 +0000297 /* Enable Time Base and Select Time Base Clock */
wdenk13eb2212004-07-09 23:27:13 +0000298 lis r0,HID0_EMCP@h /* Enable machine check */
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500299#if defined(CONFIG_ENABLE_36BIT_PHYS)
Kumar Gala9772ee72008-01-16 22:38:34 -0600300 ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500301#endif
Kumar Galae56f2c52009-03-19 09:16:10 -0500302#ifndef CONFIG_E500MC
Kumar Gala9772ee72008-01-16 22:38:34 -0600303 ori r0,r0,HID0_TBEN@l /* Enable Timebase */
Kumar Galae56f2c52009-03-19 09:16:10 -0500304#endif
wdenk9c53f402003-10-15 23:53:47 +0000305 mtspr HID0,r0
wdenk9c53f402003-10-15 23:53:47 +0000306
Kumar Gala9f4a6892008-10-23 01:47:38 -0500307#ifndef CONFIG_E500MC
Andy Flemingf08233c2007-08-14 01:34:21 -0500308 li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
Sandeep Gopalpet8709aed2010-03-12 10:45:02 +0530309 mfspr r3,PVR
310 andi. r3,r3, 0xff
311 cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */
312 blt 1f
313 /* Set MBDD bit also */
314 ori r0, r0, HID1_MBDD@l
3151:
wdenk9c53f402003-10-15 23:53:47 +0000316 mtspr HID1,r0
Kumar Gala9f4a6892008-10-23 01:47:38 -0500317#endif
wdenk9c53f402003-10-15 23:53:47 +0000318
Kumar Gala945e59a2011-11-22 06:51:15 -0600319#ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
Andy Flemingeab55c02013-03-25 07:33:10 +0000320 mfspr r3,SPRN_HDBCR1
Kumar Gala945e59a2011-11-22 06:51:15 -0600321 oris r3,r3,0x0100
Andy Flemingeab55c02013-03-25 07:33:10 +0000322 mtspr SPRN_HDBCR1,r3
Kumar Gala945e59a2011-11-22 06:51:15 -0600323#endif
324
wdenk9c53f402003-10-15 23:53:47 +0000325 /* Enable Branch Prediction */
326#if defined(CONFIG_BTB)
Kumar Gala5530cb82010-03-29 13:50:31 -0500327 lis r0,BUCSR_ENABLE@h
328 ori r0,r0,BUCSR_ENABLE@l
329 mtspr SPRN_BUCSR,r0
wdenk9c53f402003-10-15 23:53:47 +0000330#endif
331
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200332#if defined(CONFIG_SYS_INIT_DBCR)
wdenk9c53f402003-10-15 23:53:47 +0000333 lis r1,0xffff
334 ori r1,r1,0xffff
wdenk13eb2212004-07-09 23:27:13 +0000335 mtspr DBSR,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200336 lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
337 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
wdenk13eb2212004-07-09 23:27:13 +0000338 mtspr DBCR0,r0
wdenk9c53f402003-10-15 23:53:47 +0000339#endif
340
Haiying Wangc9849132009-03-27 17:02:44 -0400341#ifdef CONFIG_MPC8569
342#define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
343#define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
344
345 /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
346 * use address space which is more than 12bits, and it must be done in
347 * the 4K boot page. So we set this bit here.
348 */
349
350 /* create a temp mapping TLB0[0] for LBCR */
York Sun0f2f2a32012-10-08 07:44:07 +0000351 create_tlb0_entry 0, \
352 0, BOOKE_PAGESZ_4K, \
353 CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G, \
354 CONFIG_SYS_LBC_ADDR, MAS3_SW|MAS3_SR, \
355 0, r6
Haiying Wangc9849132009-03-27 17:02:44 -0400356
357 /* Set LBCR register */
358 lis r4,CONFIG_SYS_LBCR_ADDR@h
359 ori r4,r4,CONFIG_SYS_LBCR_ADDR@l
360
361 lis r5,CONFIG_SYS_LBC_LBCR@h
362 ori r5,r5,CONFIG_SYS_LBC_LBCR@l
363 stw r5,0(r4)
364 isync
365
366 /* invalidate this temp TLB */
367 lis r4,CONFIG_SYS_LBC_ADDR@h
368 ori r4,r4,CONFIG_SYS_LBC_ADDR@l
369 tlbivax 0,r4
370 isync
371
372#endif /* CONFIG_MPC8569 */
373
Timur Tabie769dea2011-08-03 16:30:10 -0500374/*
Timur Tabic9a1b772011-10-31 13:30:45 -0500375 * Search for the TLB that covers the code we're executing, and shrink it
376 * so that it covers only this 4K page. That will ensure that any other
377 * TLB we create won't interfere with it. We assume that the TLB exists,
Scott Wood2bfa0f42012-08-20 13:10:08 +0000378 * which is why we don't check the Valid bit of MAS1. We also assume
379 * it is in TLB1.
Timur Tabic9a1b772011-10-31 13:30:45 -0500380 *
381 * This is necessary, for example, when booting from the on-chip ROM,
382 * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
Timur Tabic9a1b772011-10-31 13:30:45 -0500383 */
384 bl nexti /* Find our address */
385nexti: mflr r1 /* R1 = our PC */
386 li r2, 0
387 mtspr MAS6, r2 /* Assume the current PID and AS are 0 */
388 isync
389 msync
390 tlbsx 0, r1 /* This must succeed */
391
Scott Wood2bfa0f42012-08-20 13:10:08 +0000392 mfspr r14, MAS0 /* Save ESEL for later */
393 rlwinm r14, r14, 16, 0xfff
394
Timur Tabic9a1b772011-10-31 13:30:45 -0500395 /* Set the size of the TLB to 4KB */
396 mfspr r3, MAS1
Scott Wood33a619c2013-01-18 15:45:58 +0000397 li r2, 0xF80
Timur Tabic9a1b772011-10-31 13:30:45 -0500398 andc r3, r3, r2 /* Clear the TSIZE bits */
399 ori r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
Scott Wood2bfa0f42012-08-20 13:10:08 +0000400 oris r3, r3, MAS1_IPROT@h
Timur Tabic9a1b772011-10-31 13:30:45 -0500401 mtspr MAS1, r3
402
403 /*
404 * Set the base address of the TLB to our PC. We assume that
405 * virtual == physical. We also assume that MAS2_EPN == MAS3_RPN.
406 */
407 lis r3, MAS2_EPN@h
408 ori r3, r3, MAS2_EPN@l /* R3 = MAS2_EPN */
409
410 and r1, r1, r3 /* Our PC, rounded down to the nearest page */
411
412 mfspr r2, MAS2
413 andc r2, r2, r3
414 or r2, r2, r1
Scott Wood80806962012-08-14 10:14:53 +0000415#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
416 cmpwi r27,0
417 beq 1f
418 andi. r15, r2, MAS2_I|MAS2_G /* save the old I/G for later */
419 rlwinm r2, r2, 0, ~MAS2_I
420 ori r2, r2, MAS2_G
4211:
422#endif
Timur Tabic9a1b772011-10-31 13:30:45 -0500423 mtspr MAS2, r2 /* Set the EPN to our PC base address */
424
425 mfspr r2, MAS3
426 andc r2, r2, r3
427 or r2, r2, r1
428 mtspr MAS3, r2 /* Set the RPN to our PC base address */
429
430 isync
431 msync
432 tlbwe
Scott Wood2bfa0f42012-08-20 13:10:08 +0000433
434/*
435 * Clear out any other TLB entries that may exist, to avoid conflicts.
436 * Our TLB entry is in r14.
437 */
438 li r0, TLBIVAX_ALL | TLBIVAX_TLB0
439 tlbivax 0, r0
440 tlbsync
441
442 mfspr r4, SPRN_TLB1CFG
443 rlwinm r4, r4, 0, TLBnCFG_NENTRY_MASK
444
445 li r3, 0
446 mtspr MAS1, r3
4471: cmpw r3, r14
Scott Wood2bfa0f42012-08-20 13:10:08 +0000448 rlwinm r5, r3, 16, MAS0_ESEL_MSK
449 addi r3, r3, 1
450 beq 2f /* skip the entry we're executing from */
451
452 oris r5, r5, MAS0_TLBSEL(1)@h
453 mtspr MAS0, r5
454
455 isync
456 tlbwe
457 isync
458 msync
459
4602: cmpw r3, r4
461 blt 1b
Timur Tabic9a1b772011-10-31 13:30:45 -0500462
Scott Woodd6a82882012-10-25 19:27:41 -0500463#if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && !defined(MINIMAL_SPL)
464/*
465 * TLB entry for debuggging in AS1
466 * Create temporary TLB entry in AS0 to handle debug exception
467 * As on debug exception MSR is cleared i.e. Address space is changed
468 * to 0. A TLB entry (in AS0) is required to handle debug exception generated
469 * in AS1.
470 */
471
Scott Wood7c810902012-09-20 16:35:21 -0500472#ifdef NOR_BOOT
Scott Woodd6a82882012-10-25 19:27:41 -0500473/*
474 * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
475 * bacause flash's virtual address maps to 0xff800000 - 0xffffffff.
476 * and this window is outside of 4K boot window.
477 */
478 create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
479 0, BOOKE_PAGESZ_4M, \
480 CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
481 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
482 0, r6
483
484#elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
485 create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
486 0, BOOKE_PAGESZ_1M, \
487 CONFIG_SYS_MONITOR_BASE, MAS2_I|MAS2_G, \
488 CONFIG_SYS_PBI_FLASH_WINDOW, MAS3_SX|MAS3_SW|MAS3_SR, \
489 0, r6
490#else
491/*
492 * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
493 * because "nexti" will resize TLB to 4K
494 */
495 create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
496 0, BOOKE_PAGESZ_256K, \
497 CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS2_I, \
498 CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS3_SX|MAS3_SW|MAS3_SR, \
499 0, r6
500#endif
501#endif
502
Timur Tabic9a1b772011-10-31 13:30:45 -0500503/*
Timur Tabie769dea2011-08-03 16:30:10 -0500504 * Relocate CCSR, if necessary. We relocate CCSR if (obviously) the default
505 * location is not where we want it. This typically happens on a 36-bit
506 * system, where we want to move CCSR to near the top of 36-bit address space.
507 *
508 * To move CCSR, we create two temporary TLBs, one for the old location, and
509 * another for the new location. On CoreNet systems, we also need to create
510 * a special, temporary LAW.
511 *
512 * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
513 * long-term TLBs, so we use TLB0 here.
514 */
515#if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
516
517#if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
518#error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
519#endif
520
Timur Tabie769dea2011-08-03 16:30:10 -0500521create_ccsr_new_tlb:
522 /*
523 * Create a TLB for the new location of CCSR. Register R8 is reserved
524 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
525 */
Scott Wood2bfa0f42012-08-20 13:10:08 +0000526 lis r8, CONFIG_SYS_CCSRBAR@h
527 ori r8, r8, CONFIG_SYS_CCSRBAR@l
528 lis r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
529 ori r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
York Sun0f2f2a32012-10-08 07:44:07 +0000530 create_tlb0_entry 0, \
531 0, BOOKE_PAGESZ_4K, \
532 CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, \
533 CONFIG_SYS_CCSRBAR_PHYS_LOW, MAS3_SW|MAS3_SR, \
534 CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
Timur Tabie769dea2011-08-03 16:30:10 -0500535 /*
Timur Tabi40402f02011-10-31 13:30:42 -0500536 * Create a TLB for the current location of CCSR. Register R9 is reserved
Timur Tabie769dea2011-08-03 16:30:10 -0500537 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
538 */
539create_ccsr_old_tlb:
York Sun0f2f2a32012-10-08 07:44:07 +0000540 create_tlb0_entry 1, \
541 0, BOOKE_PAGESZ_4K, \
542 CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, \
543 CONFIG_SYS_CCSRBAR_DEFAULT, MAS3_SW|MAS3_SR, \
544 0, r3 /* The default CCSR address is always a 32-bit number */
545
Timur Tabie769dea2011-08-03 16:30:10 -0500546
Timur Tabic19b0682011-10-31 13:30:44 -0500547 /*
548 * We have a TLB for what we think is the current (old) CCSR. Let's
549 * verify that, otherwise we won't be able to move it.
550 * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
551 * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
552 */
553verify_old_ccsr:
554 lis r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
555 ori r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
556#ifdef CONFIG_FSL_CORENET
557 lwz r1, 4(r9) /* CCSRBARL */
558#else
559 lwz r1, 0(r9) /* CCSRBAR, shifted right by 12 */
560 slwi r1, r1, 12
561#endif
562
563 cmpl 0, r0, r1
564
565 /*
566 * If the value we read from CCSRBARL is not what we expect, then
567 * enter an infinite loop. This will at least allow a debugger to
568 * halt execution and examine TLBs, etc. There's no point in going
569 * on.
570 */
571infinite_debug_loop:
572 bne infinite_debug_loop
573
Timur Tabie769dea2011-08-03 16:30:10 -0500574#ifdef CONFIG_FSL_CORENET
575
576#define CCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
577#define LAW_EN 0x80000000
578#define LAW_SIZE_4K 0xb
579#define CCSRBAR_LAWAR (LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
580#define CCSRAR_C 0x80000000 /* Commit */
581
582create_temp_law:
583 /*
584 * On CoreNet systems, we create the temporary LAW using a special LAW
585 * target ID of 0x1e. LAWBARH is at offset 0xc00 in CCSR.
586 */
587 lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
588 ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
589 lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
590 ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
591 lis r2, CCSRBAR_LAWAR@h
592 ori r2, r2, CCSRBAR_LAWAR@l
593
594 stw r0, 0xc00(r9) /* LAWBARH0 */
595 stw r1, 0xc04(r9) /* LAWBARL0 */
596 sync
597 stw r2, 0xc08(r9) /* LAWAR0 */
598
599 /*
600 * Read back from LAWAR to ensure the update is complete. e500mc
601 * cores also require an isync.
602 */
603 lwz r0, 0xc08(r9) /* LAWAR0 */
604 isync
605
606 /*
607 * Read the current CCSRBARH and CCSRBARL using load word instructions.
608 * Follow this with an isync instruction. This forces any outstanding
609 * accesses to configuration space to completion.
610 */
611read_old_ccsrbar:
612 lwz r0, 0(r9) /* CCSRBARH */
Timur Tabi40402f02011-10-31 13:30:42 -0500613 lwz r0, 4(r9) /* CCSRBARL */
Timur Tabie769dea2011-08-03 16:30:10 -0500614 isync
615
616 /*
617 * Write the new values for CCSRBARH and CCSRBARL to their old
618 * locations. The CCSRBARH has a shadow register. When the CCSRBARH
619 * has a new value written it loads a CCSRBARH shadow register. When
620 * the CCSRBARL is written, the CCSRBARH shadow register contents
621 * along with the CCSRBARL value are loaded into the CCSRBARH and
622 * CCSRBARL registers, respectively. Follow this with a sync
623 * instruction.
624 */
625write_new_ccsrbar:
626 lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
627 ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
628 lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
629 ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
630 lis r2, CCSRAR_C@h
631 ori r2, r2, CCSRAR_C@l
632
633 stw r0, 0(r9) /* Write to CCSRBARH */
634 sync /* Make sure we write to CCSRBARH first */
635 stw r1, 4(r9) /* Write to CCSRBARL */
636 sync
637
638 /*
639 * Write a 1 to the commit bit (C) of CCSRAR at the old location.
640 * Follow this with a sync instruction.
641 */
642 stw r2, 8(r9)
643 sync
644
645 /* Delete the temporary LAW */
646delete_temp_law:
647 li r1, 0
648 stw r1, 0xc08(r8)
649 sync
650 stw r1, 0xc00(r8)
651 stw r1, 0xc04(r8)
652 sync
653
654#else /* #ifdef CONFIG_FSL_CORENET */
655
656write_new_ccsrbar:
657 /*
658 * Read the current value of CCSRBAR using a load word instruction
659 * followed by an isync. This forces all accesses to configuration
660 * space to complete.
661 */
662 sync
663 lwz r0, 0(r9)
664 isync
665
666/* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
667#define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
668 (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
669
670 /* Write the new value to CCSRBAR. */
671 lis r0, CCSRBAR_PHYS_RS12@h
672 ori r0, r0, CCSRBAR_PHYS_RS12@l
673 stw r0, 0(r9)
674 sync
675
676 /*
677 * The manual says to perform a load of an address that does not
678 * access configuration space or the on-chip SRAM using an existing TLB,
679 * but that doesn't appear to be necessary. We will do the isync,
680 * though.
681 */
682 isync
683
684 /*
685 * Read the contents of CCSRBAR from its new location, followed by
686 * another isync.
687 */
688 lwz r0, 0(r8)
689 isync
690
691#endif /* #ifdef CONFIG_FSL_CORENET */
692
693 /* Delete the temporary TLBs */
694delete_temp_tlbs:
York Sun0f2f2a32012-10-08 07:44:07 +0000695 delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, r3
696 delete_tlb0_entry 1, CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, r3
Timur Tabie769dea2011-08-03 16:30:10 -0500697
Timur Tabie769dea2011-08-03 16:30:10 -0500698#endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
699
Prabhakar Kushwahacc3c5b62013-08-29 13:10:38 +0530700#if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
York Sunc3d87b12012-10-08 07:44:08 +0000701create_ccsr_l2_tlb:
702 /*
703 * Create a TLB for the MMR location of CCSR
704 * to access L2CSR0 register
705 */
706 create_tlb0_entry 0, \
707 0, BOOKE_PAGESZ_4K, \
708 CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, \
709 CONFIG_SYS_CCSRBAR_PHYS_LOW + 0xC20000, MAS3_SW|MAS3_SR, \
710 CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
711
712enable_l2_cluster_l2:
713 /* enable L2 cache */
714 lis r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@h
715 ori r3, r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@l
716 li r4, 33 /* stash id */
717 stw r4, 4(r3)
718 lis r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@h
719 ori r4, r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@l
720 sync
721 stw r4, 0(r3) /* invalidate L2 */
7221: sync
723 lwz r0, 0(r3)
724 twi 0, r0, 0
725 isync
726 and. r1, r0, r4
727 bne 1b
James Yang718fd952013-03-25 07:39:58 +0000728 lis r4, (L2CSR0_L2E|L2CSR0_L2PE)@h
James Yang284ce502013-03-25 07:40:03 +0000729 ori r4, r4, (L2CSR0_L2REP_MODE)@l
York Sunc3d87b12012-10-08 07:44:08 +0000730 sync
Andy Fleming5631c642013-03-25 07:33:14 +0000731 stw r4, 0(r3) /* enable L2 */
York Sunc3d87b12012-10-08 07:44:08 +0000732delete_ccsr_l2_tlb:
733 delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, r3
734#endif
735
Andy Fleming5631c642013-03-25 07:33:14 +0000736 /*
737 * Enable the L1. On e6500, this has to be done
738 * after the L2 is up.
739 */
740
741#ifdef CONFIG_SYS_CACHE_STASHING
742 /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
743 li r2,(32 + 0)
744 mtspr L1CSR2,r2
745#endif
746
747 /* Enable/invalidate the I-Cache */
748 lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
749 ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
750 mtspr SPRN_L1CSR1,r2
7511:
752 mfspr r3,SPRN_L1CSR1
753 and. r1,r3,r2
754 bne 1b
755
756 lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
757 ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
758 mtspr SPRN_L1CSR1,r3
759 isync
7602:
761 mfspr r3,SPRN_L1CSR1
762 andi. r1,r3,L1CSR1_ICE@l
763 beq 2b
764
765 /* Enable/invalidate the D-Cache */
766 lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
767 ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
768 mtspr SPRN_L1CSR0,r2
7691:
770 mfspr r3,SPRN_L1CSR0
771 and. r1,r3,r2
772 bne 1b
773
774 lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
775 ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
776 mtspr SPRN_L1CSR0,r3
777 isync
7782:
779 mfspr r3,SPRN_L1CSR0
780 andi. r1,r3,L1CSR0_DCE@l
781 beq 2b
Scott Wood80806962012-08-14 10:14:53 +0000782#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
783#define DCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
784#define LAW_SIZE_1M 0x13
785#define DCSRBAR_LAWAR (LAW_EN | (0x1d << 20) | LAW_SIZE_1M)
786
787 cmpwi r27,0
788 beq 9f
789
790 /*
791 * Create a TLB entry for CCSR
792 *
793 * We're executing out of TLB1 entry in r14, and that's the only
794 * TLB entry that exists. To allocate some TLB entries for our
795 * own use, flip a bit high enough that we won't flip it again
796 * via incrementing.
797 */
798
799 xori r8, r14, 32
800 lis r0, MAS0_TLBSEL(1)@h
801 rlwimi r0, r8, 16, MAS0_ESEL_MSK
802 lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@h
803 ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@l
804 lis r7, CONFIG_SYS_CCSRBAR@h
805 ori r7, r7, CONFIG_SYS_CCSRBAR@l
806 ori r2, r7, MAS2_I|MAS2_G
807 lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
808 ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
809 lis r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
810 ori r4, r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
811 mtspr MAS0, r0
812 mtspr MAS1, r1
813 mtspr MAS2, r2
814 mtspr MAS3, r3
815 mtspr MAS7, r4
816 isync
817 tlbwe
818 isync
819 msync
820
821 /* Map DCSR temporarily to physical address zero */
822 li r0, 0
823 lis r3, DCSRBAR_LAWAR@h
824 ori r3, r3, DCSRBAR_LAWAR@l
825
826 stw r0, 0xc00(r7) /* LAWBARH0 */
827 stw r0, 0xc04(r7) /* LAWBARL0 */
828 sync
829 stw r3, 0xc08(r7) /* LAWAR0 */
830
831 /* Read back from LAWAR to ensure the update is complete. */
832 lwz r3, 0xc08(r7) /* LAWAR0 */
833 isync
834
835 /* Create a TLB entry for DCSR at zero */
836
837 addi r9, r8, 1
838 lis r0, MAS0_TLBSEL(1)@h
839 rlwimi r0, r9, 16, MAS0_ESEL_MSK
840 lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@h
841 ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@l
842 li r6, 0 /* DCSR effective address */
843 ori r2, r6, MAS2_I|MAS2_G
844 li r3, MAS3_SW|MAS3_SR
845 li r4, 0
846 mtspr MAS0, r0
847 mtspr MAS1, r1
848 mtspr MAS2, r2
849 mtspr MAS3, r3
850 mtspr MAS7, r4
851 isync
852 tlbwe
853 isync
854 msync
855
856 /* enable the timebase */
857#define CTBENR 0xe2084
858 li r3, 1
859 addis r4, r7, CTBENR@ha
860 stw r3, CTBENR@l(r4)
861 lwz r3, CTBENR@l(r4)
862 twi 0,r3,0
863 isync
864
865 .macro erratum_set_ccsr offset value
866 addis r3, r7, \offset@ha
867 lis r4, \value@h
868 addi r3, r3, \offset@l
869 ori r4, r4, \value@l
870 bl erratum_set_value
871 .endm
872
873 .macro erratum_set_dcsr offset value
874 addis r3, r6, \offset@ha
875 lis r4, \value@h
876 addi r3, r3, \offset@l
877 ori r4, r4, \value@l
878 bl erratum_set_value
879 .endm
880
881 erratum_set_dcsr 0xb0e08 0xe0201800
882 erratum_set_dcsr 0xb0e18 0xe0201800
883 erratum_set_dcsr 0xb0e38 0xe0400000
884 erratum_set_dcsr 0xb0008 0x00900000
885 erratum_set_dcsr 0xb0e40 0xe00a0000
886 erratum_set_ccsr 0x18600 CONFIG_SYS_FSL_CORENET_SNOOPVEC_COREONLY
Dave Liu501c0102013-11-28 14:58:08 +0800887#ifdef CONFIG_RAMBOOT_PBL
888 erratum_set_ccsr 0x10f00 0x495e5000
889#else
Scott Wood80806962012-08-14 10:14:53 +0000890 erratum_set_ccsr 0x10f00 0x415e5000
Dave Liu501c0102013-11-28 14:58:08 +0800891#endif
Scott Wood80806962012-08-14 10:14:53 +0000892 erratum_set_ccsr 0x11f00 0x415e5000
893
894 /* Make temp mapping uncacheable again, if it was initially */
895 bl 2f
8962: mflr r3
897 tlbsx 0, r3
898 mfspr r4, MAS2
899 rlwimi r4, r15, 0, MAS2_I
900 rlwimi r4, r15, 0, MAS2_G
901 mtspr MAS2, r4
902 isync
903 tlbwe
904 isync
905 msync
906
907 /* Clear the cache */
908 lis r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
909 ori r3,r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
910 sync
911 isync
912 mtspr SPRN_L1CSR1,r3
913 isync
9142: sync
915 mfspr r4,SPRN_L1CSR1
916 and. r4,r4,r3
917 bne 2b
918
919 lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
920 ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
921 sync
922 isync
923 mtspr SPRN_L1CSR1,r3
924 isync
9252: sync
926 mfspr r4,SPRN_L1CSR1
927 and. r4,r4,r3
928 beq 2b
929
930 /* Remove temporary mappings */
931 lis r0, MAS0_TLBSEL(1)@h
932 rlwimi r0, r9, 16, MAS0_ESEL_MSK
933 li r3, 0
934 mtspr MAS0, r0
935 mtspr MAS1, r3
936 isync
937 tlbwe
938 isync
939 msync
940
941 li r3, 0
942 stw r3, 0xc08(r7) /* LAWAR0 */
943 lwz r3, 0xc08(r7)
944 isync
945
946 lis r0, MAS0_TLBSEL(1)@h
947 rlwimi r0, r8, 16, MAS0_ESEL_MSK
948 li r3, 0
949 mtspr MAS0, r0
950 mtspr MAS1, r3
951 isync
952 tlbwe
953 isync
954 msync
955
956 b 9f
957
958 /* r3 = addr, r4 = value, clobbers r5, r11, r12 */
959erratum_set_value:
960 /* Lock two cache lines into I-Cache */
961 sync
962 mfspr r11, SPRN_L1CSR1
963 rlwinm r11, r11, 0, ~L1CSR1_ICUL
964 sync
965 isync
966 mtspr SPRN_L1CSR1, r11
967 isync
968
969 mflr r12
970 bl 5f
9715: mflr r5
972 addi r5, r5, 2f - 5b
973 icbtls 0, 0, r5
974 addi r5, r5, 64
975
976 sync
977 mfspr r11, SPRN_L1CSR1
9783: andi. r11, r11, L1CSR1_ICUL
979 bne 3b
980
981 icbtls 0, 0, r5
982 addi r5, r5, 64
983
984 sync
985 mfspr r11, SPRN_L1CSR1
9863: andi. r11, r11, L1CSR1_ICUL
987 bne 3b
988
989 b 2f
990 .align 6
991 /* Inside a locked cacheline, wait a while, write, then wait a while */
9922: sync
993
994 mfspr r5, SPRN_TBRL
995 addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
9964: mfspr r5, SPRN_TBRL
997 subf. r5, r5, r11
998 bgt 4b
999
1000 stw r4, 0(r3)
1001
1002 mfspr r5, SPRN_TBRL
1003 addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
10044: mfspr r5, SPRN_TBRL
1005 subf. r5, r5, r11
1006 bgt 4b
1007
1008 sync
1009
1010 /*
1011 * Fill out the rest of this cache line and the next with nops,
1012 * to ensure that nothing outside the locked area will be
1013 * fetched due to a branch.
1014 */
1015 .rept 19
1016 nop
1017 .endr
1018
1019 sync
1020 mfspr r11, SPRN_L1CSR1
1021 rlwinm r11, r11, 0, ~L1CSR1_ICUL
1022 sync
1023 isync
1024 mtspr SPRN_L1CSR1, r11
1025 isync
1026
1027 mtlr r12
1028 blr
1029
10309:
1031#endif
1032
Timur Tabie769dea2011-08-03 16:30:10 -05001033create_init_ram_area:
Kumar Gala9772ee72008-01-16 22:38:34 -06001034 lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
1035 ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
1036
Scott Wood7c810902012-09-20 16:35:21 -05001037#ifdef NOR_BOOT
Mingkai Hu0255cd72009-09-11 14:19:10 +08001038 /* create a temp mapping in AS=1 to the 4M boot window */
York Sun0f2f2a32012-10-08 07:44:07 +00001039 create_tlb1_entry 15, \
1040 1, BOOKE_PAGESZ_4M, \
1041 CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
1042 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
1043 0, r6
Kumar Gala9772ee72008-01-16 22:38:34 -06001044
Ruchika Gupta8ca8d822010-12-15 17:02:08 +00001045#elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
1046 /* create a temp mapping in AS = 1 for Flash mapping
1047 * created by PBL for ISBC code
1048 */
York Sun0f2f2a32012-10-08 07:44:07 +00001049 create_tlb1_entry 15, \
1050 1, BOOKE_PAGESZ_1M, \
Scott Woodf2173162012-09-20 18:34:49 -05001051 CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
1052 CONFIG_SYS_PBI_FLASH_WINDOW & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
York Sun0f2f2a32012-10-08 07:44:07 +00001053 0, r6
Mingkai Hu0255cd72009-09-11 14:19:10 +08001054#else
1055 /*
Haiying Wang439a7bf2010-11-10 15:37:13 -05001056 * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
1057 * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
Mingkai Hu0255cd72009-09-11 14:19:10 +08001058 */
York Sun0f2f2a32012-10-08 07:44:07 +00001059 create_tlb1_entry 15, \
1060 1, BOOKE_PAGESZ_1M, \
Scott Woodf2173162012-09-20 18:34:49 -05001061 CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
1062 CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
York Sun0f2f2a32012-10-08 07:44:07 +00001063 0, r6
Mingkai Hu0255cd72009-09-11 14:19:10 +08001064#endif
Kumar Gala9772ee72008-01-16 22:38:34 -06001065
Kumar Gala9772ee72008-01-16 22:38:34 -06001066 /* create a temp mapping in AS=1 to the stack */
yorkc6093322010-07-02 22:25:57 +00001067#if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
1068 defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
York Sun0f2f2a32012-10-08 07:44:07 +00001069 create_tlb1_entry 14, \
1070 1, BOOKE_PAGESZ_16K, \
1071 CONFIG_SYS_INIT_RAM_ADDR, 0, \
1072 CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, MAS3_SX|MAS3_SW|MAS3_SR, \
1073 CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH, r6
1074
yorkc6093322010-07-02 22:25:57 +00001075#else
York Sun0f2f2a32012-10-08 07:44:07 +00001076 create_tlb1_entry 14, \
1077 1, BOOKE_PAGESZ_16K, \
1078 CONFIG_SYS_INIT_RAM_ADDR, 0, \
1079 CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, \
1080 0, r6
yorkc6093322010-07-02 22:25:57 +00001081#endif
Kumar Gala9772ee72008-01-16 22:38:34 -06001082
Prabhakar Kushwaha8f3e8922012-04-29 23:56:30 +00001083 lis r6,MSR_IS|MSR_DS|MSR_DE@h
1084 ori r6,r6,MSR_IS|MSR_DS|MSR_DE@l
Kumar Gala9772ee72008-01-16 22:38:34 -06001085 lis r7,switch_as@h
1086 ori r7,r7,switch_as@l
1087
1088 mtspr SPRN_SRR0,r7
1089 mtspr SPRN_SRR1,r6
1090 rfi
1091
1092switch_as:
Kumar Gala76e276b2007-08-07 18:07:27 -05001093/* L1 DCache is used for initial RAM */
1094
1095 /* Allocate Initial RAM in data cache.
1096 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001097 lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
1098 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
Kumar Gala938e14e2008-01-08 01:22:21 -06001099 mfspr r2, L1CFG0
1100 andi. r2, r2, 0x1ff
1101 /* cache size * 1024 / (2 * L1 line size) */
1102 slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
Kumar Gala76e276b2007-08-07 18:07:27 -05001103 mtctr r2
1104 li r0,0
11051:
1106 dcbz r0,r3
1107 dcbtls 0,r0,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001108 addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
Kumar Gala76e276b2007-08-07 18:07:27 -05001109 bdnz 1b
1110
Andy Flemingf08233c2007-08-14 01:34:21 -05001111 /* Jump out the last 4K page and continue to 'normal' start */
Scott Wood7c810902012-09-20 16:35:21 -05001112#if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)
1113 /* We assume that we're already running at the address we're linked at */
Andy Flemingf08233c2007-08-14 01:34:21 -05001114 b _start_cont
Kumar Gala76e276b2007-08-07 18:07:27 -05001115#else
1116 /* Calculate absolute address in FLASH and jump there */
1117 /*--------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001118 lis r3,CONFIG_SYS_MONITOR_BASE@h
1119 ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
Kumar Gala76e276b2007-08-07 18:07:27 -05001120 addi r3,r3,_start_cont - _start + _START_OFFSET
1121 mtlr r3
urwithsughosh@gmail.come9f4e342007-09-24 13:36:01 -04001122 blr
Kumar Gala76e276b2007-08-07 18:07:27 -05001123#endif
Andy Flemingf08233c2007-08-14 01:34:21 -05001124
Andy Flemingf08233c2007-08-14 01:34:21 -05001125 .text
1126 .globl _start
1127_start:
1128 .long 0x27051956 /* U-BOOT Magic Number */
1129 .globl version_string
1130version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +02001131 .ascii U_BOOT_VERSION_STRING, "\0"
Andy Flemingf08233c2007-08-14 01:34:21 -05001132
1133 .align 4
1134 .globl _start_cont
1135_start_cont:
wdenk9c53f402003-10-15 23:53:47 +00001136 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
Joakim Tjernlund258120c2012-07-23 10:58:02 +00001137 lis r3,(CONFIG_SYS_INIT_RAM_ADDR)@h
1138 ori r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
wdenk9c53f402003-10-15 23:53:47 +00001139 li r0,0
Joakim Tjernlund258120c2012-07-23 10:58:02 +00001140 stw r0,0(r3) /* Terminate Back Chain */
1141 stw r0,+4(r3) /* NULL return address. */
1142 mr r1,r3 /* Transfer to SP(r1) */
wdenk9c53f402003-10-15 23:53:47 +00001143
1144 GET_GOT
Kumar Gala9772ee72008-01-16 22:38:34 -06001145 bl cpu_init_early_f
1146
1147 /* switch back to AS = 0 */
1148 lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
1149 ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
1150 mtmsr r3
1151 isync
1152
wdenk9c53f402003-10-15 23:53:47 +00001153 bl cpu_init_f
wdenk9c53f402003-10-15 23:53:47 +00001154 bl board_init_f
wdenk13eb2212004-07-09 23:27:13 +00001155 isync
wdenk9c53f402003-10-15 23:53:47 +00001156
Peter Tyser0c44caf2010-09-14 19:13:53 -05001157 /* NOTREACHED - board_init_f() does not return */
1158
Scott Wood7c810902012-09-20 16:35:21 -05001159#ifndef MINIMAL_SPL
Andy Flemingf08233c2007-08-14 01:34:21 -05001160 . = EXC_OFF_SYS_RESET
wdenk9c53f402003-10-15 23:53:47 +00001161 .globl _start_of_vectors
1162_start_of_vectors:
Andy Flemingf08233c2007-08-14 01:34:21 -05001163
wdenk9c53f402003-10-15 23:53:47 +00001164/* Critical input. */
Andy Flemingf08233c2007-08-14 01:34:21 -05001165 CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
1166
1167/* Machine check */
1168 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
wdenk9c53f402003-10-15 23:53:47 +00001169
1170/* Data Storage exception. */
1171 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
1172
1173/* Instruction Storage exception. */
1174 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
1175
1176/* External Interrupt exception. */
Andy Flemingf08233c2007-08-14 01:34:21 -05001177 STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
wdenk9c53f402003-10-15 23:53:47 +00001178
1179/* Alignment exception. */
1180 . = 0x0600
1181Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +02001182 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk9c53f402003-10-15 23:53:47 +00001183 mfspr r4,DAR
1184 stw r4,_DAR(r21)
1185 mfspr r5,DSISR
1186 stw r5,_DSISR(r21)
1187 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +01001188 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenk9c53f402003-10-15 23:53:47 +00001189
1190/* Program check exception */
1191 . = 0x0700
1192ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +02001193 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk9c53f402003-10-15 23:53:47 +00001194 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +01001195 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
1196 MSR_KERNEL, COPY_EE)
wdenk9c53f402003-10-15 23:53:47 +00001197
1198 /* No FPU on MPC85xx. This exception is not supposed to happen.
1199 */
1200 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +00001201
wdenkf3da7cc2005-05-13 22:49:36 +00001202 . = 0x0900
wdenk9c53f402003-10-15 23:53:47 +00001203/*
1204 * r0 - SYSCALL number
1205 * r3-... arguments
1206 */
1207SystemCall:
Andy Flemingf08233c2007-08-14 01:34:21 -05001208 addis r11,r0,0 /* get functions table addr */
1209 ori r11,r11,0 /* Note: this code is patched in trap_init */
1210 addis r12,r0,0 /* get number of functions */
wdenkf3da7cc2005-05-13 22:49:36 +00001211 ori r12,r12,0
wdenk9c53f402003-10-15 23:53:47 +00001212
Andy Flemingf08233c2007-08-14 01:34:21 -05001213 cmplw 0,r0,r12
wdenkf3da7cc2005-05-13 22:49:36 +00001214 bge 1f
wdenk9c53f402003-10-15 23:53:47 +00001215
Andy Flemingf08233c2007-08-14 01:34:21 -05001216 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
wdenkf3da7cc2005-05-13 22:49:36 +00001217 add r11,r11,r0
1218 lwz r11,0(r11)
wdenk9c53f402003-10-15 23:53:47 +00001219
Andy Flemingf08233c2007-08-14 01:34:21 -05001220 li r20,0xd00-4 /* Get stack pointer */
wdenkf3da7cc2005-05-13 22:49:36 +00001221 lwz r12,0(r20)
Andy Flemingf08233c2007-08-14 01:34:21 -05001222 subi r12,r12,12 /* Adjust stack pointer */
wdenkf3da7cc2005-05-13 22:49:36 +00001223 li r0,0xc00+_end_back-SystemCall
Andy Flemingf08233c2007-08-14 01:34:21 -05001224 cmplw 0,r0,r12 /* Check stack overflow */
wdenkf3da7cc2005-05-13 22:49:36 +00001225 bgt 1f
1226 stw r12,0(r20)
wdenk9c53f402003-10-15 23:53:47 +00001227
wdenkf3da7cc2005-05-13 22:49:36 +00001228 mflr r0
1229 stw r0,0(r12)
1230 mfspr r0,SRR0
1231 stw r0,4(r12)
1232 mfspr r0,SRR1
1233 stw r0,8(r12)
wdenk9c53f402003-10-15 23:53:47 +00001234
wdenkf3da7cc2005-05-13 22:49:36 +00001235 li r12,0xc00+_back-SystemCall
1236 mtlr r12
1237 mtspr SRR0,r11
wdenk9c53f402003-10-15 23:53:47 +00001238
wdenkf3da7cc2005-05-13 22:49:36 +000012391: SYNC
wdenk9c53f402003-10-15 23:53:47 +00001240 rfi
1241_back:
1242
wdenkf3da7cc2005-05-13 22:49:36 +00001243 mfmsr r11 /* Disable interrupts */
1244 li r12,0
1245 ori r12,r12,MSR_EE
1246 andc r11,r11,r12
1247 SYNC /* Some chip revs need this... */
1248 mtmsr r11
wdenk9c53f402003-10-15 23:53:47 +00001249 SYNC
1250
wdenkf3da7cc2005-05-13 22:49:36 +00001251 li r12,0xd00-4 /* restore regs */
1252 lwz r12,0(r12)
wdenk9c53f402003-10-15 23:53:47 +00001253
wdenkf3da7cc2005-05-13 22:49:36 +00001254 lwz r11,0(r12)
1255 mtlr r11
1256 lwz r11,4(r12)
1257 mtspr SRR0,r11
1258 lwz r11,8(r12)
1259 mtspr SRR1,r11
wdenk9c53f402003-10-15 23:53:47 +00001260
wdenkf3da7cc2005-05-13 22:49:36 +00001261 addi r12,r12,12 /* Adjust stack pointer */
1262 li r20,0xd00-4
1263 stw r12,0(r20)
wdenk9c53f402003-10-15 23:53:47 +00001264
1265 SYNC
1266 rfi
1267_end_back:
1268
wdenkf3da7cc2005-05-13 22:49:36 +00001269 STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
1270 STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
1271 STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +00001272
wdenkf3da7cc2005-05-13 22:49:36 +00001273 STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
1274 STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
wdenk9c53f402003-10-15 23:53:47 +00001275
wdenkf3da7cc2005-05-13 22:49:36 +00001276 CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
wdenk9c53f402003-10-15 23:53:47 +00001277
wdenkf3da7cc2005-05-13 22:49:36 +00001278 .globl _end_of_vectors
wdenk9c53f402003-10-15 23:53:47 +00001279_end_of_vectors:
1280
1281
Andy Flemingf08233c2007-08-14 01:34:21 -05001282 . = . + (0x100 - ( . & 0xff )) /* align for debug */
wdenk9c53f402003-10-15 23:53:47 +00001283
1284/*
1285 * This code finishes saving the registers to the exception frame
1286 * and jumps to the appropriate handler for the exception.
1287 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1288 */
1289 .globl transfer_to_handler
1290transfer_to_handler:
1291 stw r22,_NIP(r21)
1292 lis r22,MSR_POW@h
1293 andc r23,r23,r22
1294 stw r23,_MSR(r21)
1295 SAVE_GPR(7, r21)
1296 SAVE_4GPRS(8, r21)
1297 SAVE_8GPRS(12, r21)
1298 SAVE_8GPRS(24, r21)
1299
1300 mflr r23
1301 andi. r24,r23,0x3f00 /* get vector offset */
1302 stw r24,TRAP(r21)
1303 li r22,0
1304 stw r22,RESULT(r21)
1305 mtspr SPRG2,r22 /* r1 is now kernel sp */
1306
1307 lwz r24,0(r23) /* virtual address of handler */
1308 lwz r23,4(r23) /* where to go when done */
1309 mtspr SRR0,r24
1310 mtspr SRR1,r20
1311 mtlr r23
1312 SYNC
1313 rfi /* jump to handler, enable MMU */
1314
1315int_return:
1316 mfmsr r28 /* Disable interrupts */
1317 li r4,0
1318 ori r4,r4,MSR_EE
1319 andc r28,r28,r4
1320 SYNC /* Some chip revs need this... */
1321 mtmsr r28
1322 SYNC
1323 lwz r2,_CTR(r1)
1324 lwz r0,_LINK(r1)
1325 mtctr r2
1326 mtlr r0
1327 lwz r2,_XER(r1)
1328 lwz r0,_CCR(r1)
1329 mtspr XER,r2
1330 mtcrf 0xFF,r0
1331 REST_10GPRS(3, r1)
1332 REST_10GPRS(13, r1)
1333 REST_8GPRS(23, r1)
1334 REST_GPR(31, r1)
1335 lwz r2,_NIP(r1) /* Restore environment */
1336 lwz r0,_MSR(r1)
1337 mtspr SRR0,r2
1338 mtspr SRR1,r0
1339 lwz r0,GPR0(r1)
1340 lwz r2,GPR2(r1)
1341 lwz r1,GPR1(r1)
1342 SYNC
1343 rfi
1344
1345crit_return:
1346 mfmsr r28 /* Disable interrupts */
1347 li r4,0
1348 ori r4,r4,MSR_EE
1349 andc r28,r28,r4
1350 SYNC /* Some chip revs need this... */
1351 mtmsr r28
1352 SYNC
1353 lwz r2,_CTR(r1)
1354 lwz r0,_LINK(r1)
1355 mtctr r2
1356 mtlr r0
1357 lwz r2,_XER(r1)
1358 lwz r0,_CCR(r1)
1359 mtspr XER,r2
1360 mtcrf 0xFF,r0
1361 REST_10GPRS(3, r1)
1362 REST_10GPRS(13, r1)
1363 REST_8GPRS(23, r1)
1364 REST_GPR(31, r1)
1365 lwz r2,_NIP(r1) /* Restore environment */
1366 lwz r0,_MSR(r1)
Andy Flemingf08233c2007-08-14 01:34:21 -05001367 mtspr SPRN_CSRR0,r2
1368 mtspr SPRN_CSRR1,r0
wdenk9c53f402003-10-15 23:53:47 +00001369 lwz r0,GPR0(r1)
1370 lwz r2,GPR2(r1)
1371 lwz r1,GPR1(r1)
1372 SYNC
1373 rfci
1374
Andy Flemingf08233c2007-08-14 01:34:21 -05001375mck_return:
1376 mfmsr r28 /* Disable interrupts */
1377 li r4,0
1378 ori r4,r4,MSR_EE
1379 andc r28,r28,r4
1380 SYNC /* Some chip revs need this... */
1381 mtmsr r28
1382 SYNC
1383 lwz r2,_CTR(r1)
1384 lwz r0,_LINK(r1)
1385 mtctr r2
1386 mtlr r0
1387 lwz r2,_XER(r1)
1388 lwz r0,_CCR(r1)
1389 mtspr XER,r2
1390 mtcrf 0xFF,r0
1391 REST_10GPRS(3, r1)
1392 REST_10GPRS(13, r1)
1393 REST_8GPRS(23, r1)
1394 REST_GPR(31, r1)
1395 lwz r2,_NIP(r1) /* Restore environment */
1396 lwz r0,_MSR(r1)
1397 mtspr SPRN_MCSRR0,r2
1398 mtspr SPRN_MCSRR1,r0
1399 lwz r0,GPR0(r1)
1400 lwz r2,GPR2(r1)
1401 lwz r1,GPR1(r1)
1402 SYNC
1403 rfmci
1404
wdenk9c53f402003-10-15 23:53:47 +00001405/* Cache functions.
1406*/
Matthew McClintockc83e7ef2011-05-23 08:38:53 +00001407.globl flush_icache
1408flush_icache:
Kumar Gala32090b32008-09-22 14:11:10 -05001409.globl invalidate_icache
wdenk9c53f402003-10-15 23:53:47 +00001410invalidate_icache:
1411 mfspr r0,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -05001412 ori r0,r0,L1CSR1_ICFI
1413 msync
1414 isync
wdenk9c53f402003-10-15 23:53:47 +00001415 mtspr L1CSR1,r0
1416 isync
Andy Flemingf08233c2007-08-14 01:34:21 -05001417 blr /* entire I cache */
wdenk9c53f402003-10-15 23:53:47 +00001418
Kumar Gala32090b32008-09-22 14:11:10 -05001419.globl invalidate_dcache
wdenk9c53f402003-10-15 23:53:47 +00001420invalidate_dcache:
1421 mfspr r0,L1CSR0
Andy Flemingf08233c2007-08-14 01:34:21 -05001422 ori r0,r0,L1CSR0_DCFI
wdenk9c53f402003-10-15 23:53:47 +00001423 msync
1424 isync
1425 mtspr L1CSR0,r0
1426 isync
1427 blr
1428
1429 .globl icache_enable
1430icache_enable:
1431 mflr r8
1432 bl invalidate_icache
1433 mtlr r8
1434 isync
1435 mfspr r4,L1CSR1
1436 ori r4,r4,0x0001
1437 oris r4,r4,0x0001
1438 mtspr L1CSR1,r4
1439 isync
1440 blr
1441
1442 .globl icache_disable
1443icache_disable:
1444 mfspr r0,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -05001445 lis r3,0
1446 ori r3,r3,L1CSR1_ICE
1447 andc r0,r0,r3
wdenk9c53f402003-10-15 23:53:47 +00001448 mtspr L1CSR1,r0
1449 isync
1450 blr
1451
1452 .globl icache_status
1453icache_status:
1454 mfspr r3,L1CSR1
Andy Flemingf08233c2007-08-14 01:34:21 -05001455 andi. r3,r3,L1CSR1_ICE
wdenk9c53f402003-10-15 23:53:47 +00001456 blr
1457
1458 .globl dcache_enable
1459dcache_enable:
1460 mflr r8
1461 bl invalidate_dcache
1462 mtlr r8
1463 isync
1464 mfspr r0,L1CSR0
1465 ori r0,r0,0x0001
1466 oris r0,r0,0x0001
1467 msync
1468 isync
1469 mtspr L1CSR0,r0
1470 isync
1471 blr
1472
1473 .globl dcache_disable
1474dcache_disable:
Andy Flemingf08233c2007-08-14 01:34:21 -05001475 mfspr r3,L1CSR0
1476 lis r4,0
1477 ori r4,r4,L1CSR0_DCE
1478 andc r3,r3,r4
Kumar Galafa103bf2011-01-05 10:33:46 -06001479 mtspr L1CSR0,r3
wdenk9c53f402003-10-15 23:53:47 +00001480 isync
1481 blr
1482
1483 .globl dcache_status
1484dcache_status:
1485 mfspr r3,L1CSR0
Andy Flemingf08233c2007-08-14 01:34:21 -05001486 andi. r3,r3,L1CSR0_DCE
wdenk9c53f402003-10-15 23:53:47 +00001487 blr
1488
1489 .globl get_pir
1490get_pir:
Andy Flemingf08233c2007-08-14 01:34:21 -05001491 mfspr r3,PIR
wdenk9c53f402003-10-15 23:53:47 +00001492 blr
1493
1494 .globl get_pvr
1495get_pvr:
Andy Flemingf08233c2007-08-14 01:34:21 -05001496 mfspr r3,PVR
wdenk9c53f402003-10-15 23:53:47 +00001497 blr
1498
wdenka445ddf2004-06-09 00:34:46 +00001499 .globl get_svr
1500get_svr:
Andy Flemingf08233c2007-08-14 01:34:21 -05001501 mfspr r3,SVR
wdenka445ddf2004-06-09 00:34:46 +00001502 blr
1503
wdenk9c53f402003-10-15 23:53:47 +00001504 .globl wr_tcr
1505wr_tcr:
Andy Flemingf08233c2007-08-14 01:34:21 -05001506 mtspr TCR,r3
wdenk9c53f402003-10-15 23:53:47 +00001507 blr
1508
1509/*------------------------------------------------------------------------------- */
1510/* Function: in8 */
1511/* Description: Input 8 bits */
1512/*------------------------------------------------------------------------------- */
1513 .globl in8
1514in8:
1515 lbz r3,0x0000(r3)
1516 blr
1517
1518/*------------------------------------------------------------------------------- */
1519/* Function: out8 */
1520/* Description: Output 8 bits */
1521/*------------------------------------------------------------------------------- */
1522 .globl out8
1523out8:
1524 stb r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -05001525 sync
wdenk9c53f402003-10-15 23:53:47 +00001526 blr
1527
1528/*------------------------------------------------------------------------------- */
1529/* Function: out16 */
1530/* Description: Output 16 bits */
1531/*------------------------------------------------------------------------------- */
1532 .globl out16
1533out16:
1534 sth r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -05001535 sync
wdenk9c53f402003-10-15 23:53:47 +00001536 blr
1537
1538/*------------------------------------------------------------------------------- */
1539/* Function: out16r */
1540/* Description: Byte reverse and output 16 bits */
1541/*------------------------------------------------------------------------------- */
1542 .globl out16r
1543out16r:
1544 sthbrx r4,r0,r3
Ed Swarthout7d6be302007-09-26 16:35:54 -05001545 sync
wdenk9c53f402003-10-15 23:53:47 +00001546 blr
1547
1548/*------------------------------------------------------------------------------- */
1549/* Function: out32 */
1550/* Description: Output 32 bits */
1551/*------------------------------------------------------------------------------- */
1552 .globl out32
1553out32:
1554 stw r4,0x0000(r3)
Ed Swarthout7d6be302007-09-26 16:35:54 -05001555 sync
wdenk9c53f402003-10-15 23:53:47 +00001556 blr
1557
1558/*------------------------------------------------------------------------------- */
1559/* Function: out32r */
1560/* Description: Byte reverse and output 32 bits */
1561/*------------------------------------------------------------------------------- */
1562 .globl out32r
1563out32r:
1564 stwbrx r4,r0,r3
Ed Swarthout7d6be302007-09-26 16:35:54 -05001565 sync
wdenk9c53f402003-10-15 23:53:47 +00001566 blr
1567
1568/*------------------------------------------------------------------------------- */
1569/* Function: in16 */
1570/* Description: Input 16 bits */
1571/*------------------------------------------------------------------------------- */
1572 .globl in16
1573in16:
1574 lhz r3,0x0000(r3)
1575 blr
1576
1577/*------------------------------------------------------------------------------- */
1578/* Function: in16r */
1579/* Description: Input 16 bits and byte reverse */
1580/*------------------------------------------------------------------------------- */
1581 .globl in16r
1582in16r:
1583 lhbrx r3,r0,r3
1584 blr
1585
1586/*------------------------------------------------------------------------------- */
1587/* Function: in32 */
1588/* Description: Input 32 bits */
1589/*------------------------------------------------------------------------------- */
1590 .globl in32
1591in32:
1592 lwz 3,0x0000(3)
1593 blr
1594
1595/*------------------------------------------------------------------------------- */
1596/* Function: in32r */
1597/* Description: Input 32 bits and byte reverse */
1598/*------------------------------------------------------------------------------- */
1599 .globl in32r
1600in32r:
1601 lwbrx r3,r0,r3
1602 blr
Scott Wood7c810902012-09-20 16:35:21 -05001603#endif /* !MINIMAL_SPL */
wdenk9c53f402003-10-15 23:53:47 +00001604
wdenk9c53f402003-10-15 23:53:47 +00001605/*------------------------------------------------------------------------------*/
1606
1607/*
Kumar Galac417c912009-09-11 11:27:00 -05001608 * void write_tlb(mas0, mas1, mas2, mas3, mas7)
1609 */
1610 .globl write_tlb
1611write_tlb:
1612 mtspr MAS0,r3
1613 mtspr MAS1,r4
1614 mtspr MAS2,r5
1615 mtspr MAS3,r6
1616#ifdef CONFIG_ENABLE_36BIT_PHYS
1617 mtspr MAS7,r7
1618#endif
1619 li r3,0
1620#ifdef CONFIG_SYS_BOOK3E_HV
1621 mtspr MAS8,r3
1622#endif
1623 isync
1624 tlbwe
1625 msync
1626 isync
1627 blr
1628
1629/*
wdenk9c53f402003-10-15 23:53:47 +00001630 * void relocate_code (addr_sp, gd, addr_moni)
1631 *
1632 * This "function" does not return, instead it continues in RAM
1633 * after relocating the monitor code.
1634 *
1635 * r3 = dest
1636 * r4 = src
1637 * r5 = length in bytes
1638 * r6 = cachelinesize
1639 */
1640 .globl relocate_code
1641relocate_code:
Andy Flemingf08233c2007-08-14 01:34:21 -05001642 mr r1,r3 /* Set new stack pointer */
1643 mr r9,r4 /* Save copy of Init Data pointer */
1644 mr r10,r5 /* Save copy of Destination Address */
wdenk9c53f402003-10-15 23:53:47 +00001645
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001646 GET_GOT
Andy Flemingf08233c2007-08-14 01:34:21 -05001647 mr r3,r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001648 lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1649 ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
wdenk9c53f402003-10-15 23:53:47 +00001650 lwz r5,GOT(__init_end)
1651 sub r5,r5,r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001652 li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenk9c53f402003-10-15 23:53:47 +00001653
1654 /*
1655 * Fix GOT pointer:
1656 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001657 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk9c53f402003-10-15 23:53:47 +00001658 *
1659 * Offset:
1660 */
Andy Flemingf08233c2007-08-14 01:34:21 -05001661 sub r15,r10,r4
wdenk9c53f402003-10-15 23:53:47 +00001662
1663 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001664 add r12,r12,r15
wdenk9c53f402003-10-15 23:53:47 +00001665 /* the the one used by the C code */
Andy Flemingf08233c2007-08-14 01:34:21 -05001666 add r30,r30,r15
wdenk9c53f402003-10-15 23:53:47 +00001667
1668 /*
1669 * Now relocate code
1670 */
1671
1672 cmplw cr1,r3,r4
1673 addi r0,r5,3
1674 srwi. r0,r0,2
1675 beq cr1,4f /* In place copy is not necessary */
1676 beq 7f /* Protect against 0 count */
1677 mtctr r0
1678 bge cr1,2f
1679
1680 la r8,-4(r4)
1681 la r7,-4(r3)
16821: lwzu r0,4(r8)
1683 stwu r0,4(r7)
1684 bdnz 1b
1685 b 4f
1686
16872: slwi r0,r0,2
1688 add r8,r4,r0
1689 add r7,r3,r0
16903: lwzu r0,-4(r8)
1691 stwu r0,-4(r7)
1692 bdnz 3b
1693
1694/*
1695 * Now flush the cache: note that we must start from a cache aligned
1696 * address. Otherwise we might miss one cache line.
1697 */
16984: cmpwi r6,0
1699 add r5,r3,r5
1700 beq 7f /* Always flush prefetch queue in any case */
1701 subi r0,r6,1
1702 andc r3,r3,r0
1703 mr r4,r3
17045: dcbst 0,r4
1705 add r4,r4,r6
1706 cmplw r4,r5
1707 blt 5b
1708 sync /* Wait for all dcbst to complete on bus */
1709 mr r4,r3
17106: icbi 0,r4
1711 add r4,r4,r6
1712 cmplw r4,r5
1713 blt 6b
17147: sync /* Wait for all icbi to complete on bus */
1715 isync
1716
1717/*
1718 * We are done. Do not return, instead branch to second part of board
1719 * initialization, now running from RAM.
1720 */
1721
Andy Flemingf08233c2007-08-14 01:34:21 -05001722 addi r0,r10,in_ram - _start + _START_OFFSET
Prabhakar Kushwahabc8d57c2012-04-29 23:56:43 +00001723
1724 /*
1725 * As IVPR is going to point RAM address,
1726 * Make sure IVOR15 has valid opcode to support debugger
1727 */
1728 mtspr IVOR15,r0
1729
1730 /*
1731 * Re-point the IVPR at RAM
1732 */
1733 mtspr IVPR,r10
1734
wdenk9c53f402003-10-15 23:53:47 +00001735 mtlr r0
1736 blr /* NEVER RETURNS! */
Andy Flemingf08233c2007-08-14 01:34:21 -05001737 .globl in_ram
wdenk9c53f402003-10-15 23:53:47 +00001738in_ram:
1739
1740 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001741 * Relocation Function, r12 point to got2+0x8000
wdenk9c53f402003-10-15 23:53:47 +00001742 *
1743 * Adjust got2 pointers, no need to check for 0, this code
1744 * already puts a few entries in the table.
1745 */
1746 li r0,__got2_entries@sectoff@l
1747 la r3,GOT(_GOT2_TABLE_)
1748 lwz r11,GOT(_GOT2_TABLE_)
1749 mtctr r0
1750 sub r11,r3,r11
1751 addi r3,r3,-4
17521: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001753 cmpwi r0,0
1754 beq- 2f
wdenk9c53f402003-10-15 23:53:47 +00001755 add r0,r0,r11
1756 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +020017572: bdnz 1b
wdenk9c53f402003-10-15 23:53:47 +00001758
1759 /*
1760 * Now adjust the fixups and the pointers to the fixups
1761 * in case we need to move ourselves again.
1762 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001763 li r0,__fixup_entries@sectoff@l
wdenk9c53f402003-10-15 23:53:47 +00001764 lwz r3,GOT(_FIXUP_TABLE_)
1765 cmpwi r0,0
1766 mtctr r0
1767 addi r3,r3,-4
1768 beq 4f
17693: lwzu r4,4(r3)
1770 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001771 cmpwi r0,0
wdenk9c53f402003-10-15 23:53:47 +00001772 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +01001773 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001774 beq- 5f
wdenk9c53f402003-10-15 23:53:47 +00001775 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +020017765: bdnz 3b
wdenk9c53f402003-10-15 23:53:47 +000017774:
1778clear_bss:
1779 /*
1780 * Now clear BSS segment
1781 */
1782 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +00001783 lwz r4,GOT(__bss_end)
wdenk9c53f402003-10-15 23:53:47 +00001784
Andy Flemingf08233c2007-08-14 01:34:21 -05001785 cmplw 0,r3,r4
wdenk9c53f402003-10-15 23:53:47 +00001786 beq 6f
1787
Andy Flemingf08233c2007-08-14 01:34:21 -05001788 li r0,0
wdenk9c53f402003-10-15 23:53:47 +000017895:
Andy Flemingf08233c2007-08-14 01:34:21 -05001790 stw r0,0(r3)
1791 addi r3,r3,4
1792 cmplw 0,r3,r4
Ying Zhang5ca62f22013-06-07 17:25:16 +08001793 blt 5b
wdenk9c53f402003-10-15 23:53:47 +000017946:
1795
Andy Flemingf08233c2007-08-14 01:34:21 -05001796 mr r3,r9 /* Init Data pointer */
1797 mr r4,r10 /* Destination Address */
wdenk9c53f402003-10-15 23:53:47 +00001798 bl board_init_r
1799
Scott Wood7c810902012-09-20 16:35:21 -05001800#ifndef MINIMAL_SPL
wdenk9c53f402003-10-15 23:53:47 +00001801 /*
1802 * Copy exception vector code to low memory
1803 *
1804 * r3: dest_addr
1805 * r7: source address, r8: end address, r9: target address
1806 */
wdenkf3da7cc2005-05-13 22:49:36 +00001807 .globl trap_init
wdenk9c53f402003-10-15 23:53:47 +00001808trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001809 mflr r4 /* save link register */
1810 GET_GOT
Andy Flemingf08233c2007-08-14 01:34:21 -05001811 lwz r7,GOT(_start_of_vectors)
1812 lwz r8,GOT(_end_of_vectors)
wdenk9c53f402003-10-15 23:53:47 +00001813
Andy Flemingf08233c2007-08-14 01:34:21 -05001814 li r9,0x100 /* reset vector always at 0x100 */
wdenk9c53f402003-10-15 23:53:47 +00001815
Andy Flemingf08233c2007-08-14 01:34:21 -05001816 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001817 bgelr /* return if r7>=r8 - just in case */
wdenk9c53f402003-10-15 23:53:47 +000018181:
Andy Flemingf08233c2007-08-14 01:34:21 -05001819 lwz r0,0(r7)
1820 stw r0,0(r9)
1821 addi r7,r7,4
1822 addi r9,r9,4
1823 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001824 bne 1b
wdenk9c53f402003-10-15 23:53:47 +00001825
1826 /*
1827 * relocate `hdlr' and `int_return' entries
1828 */
Andy Flemingf08233c2007-08-14 01:34:21 -05001829 li r7,.L_CriticalInput - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001830 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001831 li r7,.L_MachineCheck - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001832 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001833 li r7,.L_DataStorage - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001834 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001835 li r7,.L_InstStorage - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001836 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001837 li r7,.L_ExtInterrupt - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001838 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001839 li r7,.L_Alignment - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001840 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001841 li r7,.L_ProgramCheck - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001842 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001843 li r7,.L_FPUnavailable - _start + _START_OFFSET
wdenkf3da7cc2005-05-13 22:49:36 +00001844 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001845 li r7,.L_Decrementer - _start + _START_OFFSET
1846 bl trap_reloc
1847 li r7,.L_IntervalTimer - _start + _START_OFFSET
1848 li r8,_end_of_vectors - _start + _START_OFFSET
wdenk9c53f402003-10-15 23:53:47 +000018492:
wdenkf3da7cc2005-05-13 22:49:36 +00001850 bl trap_reloc
Andy Flemingf08233c2007-08-14 01:34:21 -05001851 addi r7,r7,0x100 /* next exception vector */
1852 cmplw 0,r7,r8
wdenkf3da7cc2005-05-13 22:49:36 +00001853 blt 2b
wdenk9c53f402003-10-15 23:53:47 +00001854
Prabhakar Kushwahaf8387862012-02-14 22:49:49 +00001855 /* Update IVORs as per relocated vector table address */
1856 li r7,0x0100
1857 mtspr IVOR0,r7 /* 0: Critical input */
1858 li r7,0x0200
1859 mtspr IVOR1,r7 /* 1: Machine check */
1860 li r7,0x0300
1861 mtspr IVOR2,r7 /* 2: Data storage */
1862 li r7,0x0400
1863 mtspr IVOR3,r7 /* 3: Instruction storage */
1864 li r7,0x0500
1865 mtspr IVOR4,r7 /* 4: External interrupt */
1866 li r7,0x0600
1867 mtspr IVOR5,r7 /* 5: Alignment */
1868 li r7,0x0700
1869 mtspr IVOR6,r7 /* 6: Program check */
1870 li r7,0x0800
1871 mtspr IVOR7,r7 /* 7: floating point unavailable */
1872 li r7,0x0900
1873 mtspr IVOR8,r7 /* 8: System call */
1874 /* 9: Auxiliary processor unavailable(unsupported) */
1875 li r7,0x0a00
1876 mtspr IVOR10,r7 /* 10: Decrementer */
1877 li r7,0x0b00
1878 mtspr IVOR11,r7 /* 11: Interval timer */
1879 li r7,0x0c00
1880 mtspr IVOR12,r7 /* 12: Watchdog timer */
1881 li r7,0x0d00
1882 mtspr IVOR13,r7 /* 13: Data TLB error */
1883 li r7,0x0e00
1884 mtspr IVOR14,r7 /* 14: Instruction TLB error */
1885 li r7,0x0f00
1886 mtspr IVOR15,r7 /* 15: Debug */
1887
wdenkf3da7cc2005-05-13 22:49:36 +00001888 lis r7,0x0
Andy Flemingf08233c2007-08-14 01:34:21 -05001889 mtspr IVPR,r7
wdenk9c53f402003-10-15 23:53:47 +00001890
wdenkf3da7cc2005-05-13 22:49:36 +00001891 mtlr r4 /* restore link register */
wdenk9c53f402003-10-15 23:53:47 +00001892 blr
1893
wdenk9c53f402003-10-15 23:53:47 +00001894.globl unlock_ram_in_cache
1895unlock_ram_in_cache:
1896 /* invalidate the INIT_RAM section */
Kumar Gala5c953ca2008-10-23 01:47:37 -05001897 lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
1898 ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
Kumar Gala938e14e2008-01-08 01:22:21 -06001899 mfspr r4,L1CFG0
1900 andi. r4,r4,0x1ff
1901 slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
Andy Flemingf08233c2007-08-14 01:34:21 -05001902 mtctr r4
Kumar Gala2a441212008-02-27 16:30:47 -060019031: dcbi r0,r3
York Sun52bf1022013-04-05 13:07:13 +00001904 dcblc r0,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001905 addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
wdenk9c53f402003-10-15 23:53:47 +00001906 bdnz 1b
Kumar Gala2a441212008-02-27 16:30:47 -06001907 sync
Andy Fleming5ba61fe2008-02-27 14:29:58 -06001908
1909 /* Invalidate the TLB entries for the cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001910 lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
1911 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
Andy Fleming5ba61fe2008-02-27 14:29:58 -06001912 tlbivax 0,r3
1913 addi r3,r3,0x1000
1914 tlbivax 0,r3
1915 addi r3,r3,0x1000
1916 tlbivax 0,r3
1917 addi r3,r3,0x1000
1918 tlbivax 0,r3
wdenk9c53f402003-10-15 23:53:47 +00001919 isync
1920 blr
Kumar Gala32090b32008-09-22 14:11:10 -05001921
1922.globl flush_dcache
1923flush_dcache:
1924 mfspr r3,SPRN_L1CFG0
1925
1926 rlwinm r5,r3,9,3 /* Extract cache block size */
1927 twlgti r5,1 /* Only 32 and 64 byte cache blocks
1928 * are currently defined.
1929 */
1930 li r4,32
1931 subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
1932 * log2(number of ways)
1933 */
1934 slw r5,r4,r5 /* r5 = cache block size */
1935
1936 rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
1937 mulli r7,r7,13 /* An 8-way cache will require 13
1938 * loads per set.
1939 */
1940 slw r7,r7,r6
1941
1942 /* save off HID0 and set DCFA */
1943 mfspr r8,SPRN_HID0
1944 ori r9,r8,HID0_DCFA@l
1945 mtspr SPRN_HID0,r9
1946 isync
1947
1948 lis r4,0
1949 mtctr r7
1950
19511: lwz r3,0(r4) /* Load... */
1952 add r4,r4,r5
1953 bdnz 1b
1954
1955 msync
1956 lis r4,0
1957 mtctr r7
1958
19591: dcbf 0,r4 /* ...and flush. */
1960 add r4,r4,r5
1961 bdnz 1b
1962
1963 /* restore HID0 */
1964 mtspr SPRN_HID0,r8
1965 isync
1966
1967 blr
Kumar Galac24a9052009-08-14 13:37:54 -05001968
1969.globl setup_ivors
1970setup_ivors:
1971
1972#include "fixed_ivor.S"
1973 blr
Scott Wood7c810902012-09-20 16:35:21 -05001974#endif /* !MINIMAL_SPL */