blob: 38bbc5a9bce5676b25ebeae74a251c16dbea9490 [file] [log] [blame]
wdenk0442ed82002-11-03 10:24:00 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
Stefan Roesef6c7b762007-03-24 15:45:34 +01005 * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
Grant Ericksonb6933412008-05-22 14:44:14 -07006 * Copyright (c) 2008 Nuovation System Designs, LLC
7 * Grant Erickson <gerickson@nuovations.com>
wdenk0442ed82002-11-03 10:24:00 +00008 *
Wolfgang Denk815c9672013-09-17 11:24:06 +02009 * SPDX-License-Identifier: GPL-2.0 IBM-pibs
Wolfgang Denk09675ef2007-06-20 18:14:24 +020010 */
wdenk0442ed82002-11-03 10:24:00 +000011
Stefan Roesecd2c7122010-11-26 15:43:17 +010012/*
13 * Startup code for IBM/AMCC PowerPC 4xx (PPC4xx) based boards
wdenk0442ed82002-11-03 10:24:00 +000014 *
Stefan Roesecd2c7122010-11-26 15:43:17 +010015 * The following description only applies to the NOR flash style booting.
16 * NAND booting is different. For more details about NAND booting on 4xx
17 * take a look at doc/README.nand-boot-ppc440.
wdenk0442ed82002-11-03 10:24:00 +000018 *
Stefan Roesecd2c7122010-11-26 15:43:17 +010019 * The CPU starts at address 0xfffffffc (last word in the address space).
20 * The U-Boot image therefore has to be located in the "upper" area of the
21 * flash (e.g. 512MiB - 0xfff80000 ... 0xffffffff). The default value for
22 * the boot chip-select (CS0) is quite big and covers this area. On the
23 * 405EX this is for example 0xffe00000 ... 0xffffffff. U-Boot will
24 * reconfigure this CS0 (and other chip-selects as well when configured
25 * this way) in the boot process to the "correct" values matching the
26 * board layout.
wdenk0442ed82002-11-03 10:24:00 +000027 */
Stefan Roesecd2c7122010-11-26 15:43:17 +010028
Wolfgang Denk0191e472010-10-26 14:34:52 +020029#include <asm-offsets.h>
wdenk0442ed82002-11-03 10:24:00 +000030#include <config.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020031#include <asm/ppc4xx.h>
wdenk0442ed82002-11-03 10:24:00 +000032#include <version.h>
33
34#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
35
36#include <ppc_asm.tmpl>
37#include <ppc_defs.h>
38
39#include <asm/cache.h>
40#include <asm/mmu.h>
Dave Mitchell3c3734172008-11-20 14:00:49 -060041#include <asm/ppc4xx-isram.h>
wdenk0442ed82002-11-03 10:24:00 +000042
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043#ifdef CONFIG_SYS_INIT_DCACHE_CS
44# if (CONFIG_SYS_INIT_DCACHE_CS == 0)
Stefan Roese918010a2009-09-09 16:25:29 +020045# define PBxAP PB1AP
46# define PBxCR PB0CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047# if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
48# define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
49# define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
Grant Ericksonb6933412008-05-22 14:44:14 -070050# endif
wdenk0442ed82002-11-03 10:24:00 +000051# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052# if (CONFIG_SYS_INIT_DCACHE_CS == 1)
Stefan Roese918010a2009-09-09 16:25:29 +020053# define PBxAP PB1AP
54# define PBxCR PB1CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055# if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
56# define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
57# define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
Grant Ericksonb6933412008-05-22 14:44:14 -070058# endif
wdenk0442ed82002-11-03 10:24:00 +000059# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060# if (CONFIG_SYS_INIT_DCACHE_CS == 2)
Stefan Roese918010a2009-09-09 16:25:29 +020061# define PBxAP PB2AP
62# define PBxCR PB2CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063# if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
64# define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
65# define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
Grant Ericksonb6933412008-05-22 14:44:14 -070066# endif
wdenk0442ed82002-11-03 10:24:00 +000067# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068# if (CONFIG_SYS_INIT_DCACHE_CS == 3)
Stefan Roese918010a2009-09-09 16:25:29 +020069# define PBxAP PB3AP
70# define PBxCR PB3CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071# if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
72# define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
73# define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
Grant Ericksonb6933412008-05-22 14:44:14 -070074# endif
wdenk0442ed82002-11-03 10:24:00 +000075# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020076# if (CONFIG_SYS_INIT_DCACHE_CS == 4)
Stefan Roese918010a2009-09-09 16:25:29 +020077# define PBxAP PB4AP
78# define PBxCR PB4CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079# if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
80# define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
81# define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
Grant Ericksonb6933412008-05-22 14:44:14 -070082# endif
wdenk0442ed82002-11-03 10:24:00 +000083# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084# if (CONFIG_SYS_INIT_DCACHE_CS == 5)
Stefan Roese918010a2009-09-09 16:25:29 +020085# define PBxAP PB5AP
86# define PBxCR PB5CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087# if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
88# define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
89# define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
Grant Ericksonb6933412008-05-22 14:44:14 -070090# endif
wdenk0442ed82002-11-03 10:24:00 +000091# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092# if (CONFIG_SYS_INIT_DCACHE_CS == 6)
Stefan Roese918010a2009-09-09 16:25:29 +020093# define PBxAP PB6AP
94# define PBxCR PB6CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095# if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
96# define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
97# define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
Grant Ericksonb6933412008-05-22 14:44:14 -070098# endif
wdenk0442ed82002-11-03 10:24:00 +000099# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100# if (CONFIG_SYS_INIT_DCACHE_CS == 7)
Stefan Roese918010a2009-09-09 16:25:29 +0200101# define PBxAP PB7AP
102# define PBxCR PB7CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103# if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
104# define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
105# define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700106# endif
107# endif
108# ifndef PBxAP_VAL
109# define PBxAP_VAL 0
110# endif
111# ifndef PBxCR_VAL
112# define PBxCR_VAL 0
113# endif
114/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
Grant Ericksonb6933412008-05-22 14:44:14 -0700116 * used as temporary stack pointer for the primordial stack
117 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118# ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
119# define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700120 EBC_BXAP_TWT_ENCODE(7) | \
121 EBC_BXAP_BCE_DISABLE | \
122 EBC_BXAP_BCT_2TRANS | \
123 EBC_BXAP_CSN_ENCODE(0) | \
124 EBC_BXAP_OEN_ENCODE(0) | \
125 EBC_BXAP_WBN_ENCODE(0) | \
126 EBC_BXAP_WBF_ENCODE(0) | \
127 EBC_BXAP_TH_ENCODE(2) | \
128 EBC_BXAP_RE_DISABLED | \
129 EBC_BXAP_SOR_NONDELAYED | \
130 EBC_BXAP_BEM_WRITEONLY | \
131 EBC_BXAP_PEN_DISABLED)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200132# endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
133# ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
134# define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700135 EBC_BXCR_BS_64MB | \
136 EBC_BXCR_BU_RW | \
137 EBC_BXCR_BW_16BIT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138# endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
139# ifndef CONFIG_SYS_INIT_RAM_PATTERN
140# define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
wdenk0442ed82002-11-03 10:24:00 +0000141# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +0000143
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200144#if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_SIZE > (4 << 10)))
145#error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_SIZE!
Stefan Roese0fb8ab92008-01-30 14:48:28 +0100146#endif
147
Grant Ericksonb6933412008-05-22 14:44:14 -0700148/*
149 * Unless otherwise overriden, enable two 128MB cachable instruction regions
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
151 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
Grant Ericksonb6933412008-05-22 14:44:14 -0700152 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153#if !defined(CONFIG_SYS_FLASH_BASE)
Stefan Roese7d72e022008-06-02 14:35:44 +0200154/* If not already defined, set it to the "last" 128MByte region */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200155# define CONFIG_SYS_FLASH_BASE 0xf8000000
Stefan Roese7d72e022008-06-02 14:35:44 +0200156#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157#if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
158# define CONFIG_SYS_ICACHE_SACR_VALUE \
159 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
160 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
161 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
162#endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700163
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164#if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
165# define CONFIG_SYS_DCACHE_SACR_VALUE \
Grant Ericksonb6933412008-05-22 14:44:14 -0700166 (0x00000000)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200167#endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700168
Stefan Roese1d568062010-05-27 16:45:20 +0200169#if !defined(CONFIG_SYS_TLB_FOR_BOOT_FLASH)
170#define CONFIG_SYS_TLB_FOR_BOOT_FLASH 0 /* use TLB 0 as default */
171#endif
172
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200173#define function_prolog(func_name) .text; \
Stefan Roese42743512007-06-01 15:27:11 +0200174 .align 2; \
175 .globl func_name; \
176 func_name:
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200177#define function_epilog(func_name) .type func_name,@function; \
Stefan Roese42743512007-06-01 15:27:11 +0200178 .size func_name,.-func_name
179
wdenk0442ed82002-11-03 10:24:00 +0000180/* We don't want the MMU yet.
181*/
182#undef MSR_KERNEL
183#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
184
185
186 .extern ext_bus_cntlr_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200187#ifdef CONFIG_NAND_U_BOOT
188 .extern reconfig_tlb0
189#endif
wdenk0442ed82002-11-03 10:24:00 +0000190
191/*
192 * Set up GOT: Global Offset Table
193 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100194 * Use r12 to access the GOT
wdenk0442ed82002-11-03 10:24:00 +0000195 */
Stefan Roese07038ad2013-04-02 10:37:04 +0200196#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000197 START_GOT
198 GOT_ENTRY(_GOT2_TABLE_)
199 GOT_ENTRY(_FIXUP_TABLE_)
200
201 GOT_ENTRY(_start)
202 GOT_ENTRY(_start_of_vectors)
203 GOT_ENTRY(_end_of_vectors)
204 GOT_ENTRY(transfer_to_handler)
205
wdenkb9a83a92003-05-30 12:48:29 +0000206 GOT_ENTRY(__init_end)
Simon Glassed70c8f2013-03-14 06:54:53 +0000207 GOT_ENTRY(__bss_end)
wdenkbf2f8c92003-05-22 22:52:13 +0000208 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000209 END_GOT
Stefan Roese42fbddd2006-09-07 11:51:23 +0200210#endif /* CONFIG_NAND_SPL */
211
Stefan Roese07038ad2013-04-02 10:37:04 +0200212#if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL) && \
213 !defined(CONFIG_SPL_BUILD)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200214 /*
215 * NAND U-Boot image is started from offset 0
216 */
217 .text
Stefan Roese23d8d342007-06-06 11:42:13 +0200218#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200219 bl reconfig_tlb0
Stefan Roese23d8d342007-06-06 11:42:13 +0200220#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200221 GET_GOT
222 bl cpu_init_f /* run low-level CPU init code (from Flash) */
223 bl board_init_f
Peter Tyser0c44caf2010-09-14 19:13:53 -0500224 /* NOTREACHED - board_init_f() does not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200225#endif
wdenk0442ed82002-11-03 10:24:00 +0000226
Ricardo Ribalda Delgadob3843812010-12-07 14:27:56 +0100227#if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_BOOT_FROM_XMD)
Stefan Roesec20ef322009-05-11 13:46:14 +0200228 /*
229 * 4xx RAM-booting U-Boot image is started from offset 0
230 */
231 .text
232 bl _start_440
233#endif
234
Stefan Roese07038ad2013-04-02 10:37:04 +0200235#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
236 /*
237 * This is the entry of the real U-Boot from a board port
238 * that supports SPL booting on the PPC4xx. We only need
239 * to call board_init_f() here. Everything else has already
240 * been done in the SPL u-boot version.
241 */
242 GET_GOT /* initialize GOT access */
243 bl board_init_f /* run 1st part of board init code (in Flash)*/
244 /* NOTREACHED - board_init_f() does not return */
245#endif
246
wdenk0442ed82002-11-03 10:24:00 +0000247/*
248 * 440 Startup -- on reset only the top 4k of the effective
249 * address space is mapped in by an entry in the instruction
250 * and data shadow TLB. The .bootpg section is located in the
251 * top 4k & does only what's necessary to map in the the rest
252 * of the boot rom. Once the boot rom is mapped in we can
253 * proceed with normal startup.
254 *
255 * NOTE: CS0 only covers the top 2MB of the effective address
256 * space after reset.
257 */
258
259#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200260#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000261 .section .bootpg,"ax"
Stefan Roese42fbddd2006-09-07 11:51:23 +0200262#endif
wdenk0442ed82002-11-03 10:24:00 +0000263 .globl _start_440
264
265/**************************************************************************/
266_start_440:
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200267 /*--------------------------------------------------------------------+
268 | 440EPX BUP Change - Hardware team request
269 +--------------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200270#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
271 sync
272 nop
273 nop
274#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200275 /*----------------------------------------------------------------+
276 | Core bug fix. Clear the esr
277 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200278 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200279 mtspr SPRN_ESR,r0
wdenk0442ed82002-11-03 10:24:00 +0000280 /*----------------------------------------------------------------*/
281 /* Clear and set up some registers. */
282 /*----------------------------------------------------------------*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200283 iccci r0,r0 /* NOTE: operands not used for 440 */
284 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000285 sync
286 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200287 mtspr SPRN_SRR0,r0
288 mtspr SPRN_SRR1,r0
289 mtspr SPRN_CSRR0,r0
290 mtspr SPRN_CSRR1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200291 /* NOTE: 440GX adds machine check status regs */
292#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200293 mtspr SPRN_MCSRR0,r0
294 mtspr SPRN_MCSRR1,r0
295 mfspr r1,SPRN_MCSR
296 mtspr SPRN_MCSR,r1
wdenk544e9732004-02-06 23:19:44 +0000297#endif
Stefan Roese0100cc12006-11-22 13:20:50 +0100298
299 /*----------------------------------------------------------------*/
300 /* CCR0 init */
301 /*----------------------------------------------------------------*/
302 /* Disable store gathering & broadcast, guarantee inst/data
303 * cache block touch, force load/store alignment
304 * (see errata 1.12: 440_33)
305 */
306 lis r1,0x0030 /* store gathering & broadcast disable */
307 ori r1,r1,0x6000 /* cache touch */
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200308 mtspr SPRN_CCR0,r1
Stefan Roese0100cc12006-11-22 13:20:50 +0100309
wdenk0442ed82002-11-03 10:24:00 +0000310 /*----------------------------------------------------------------*/
311 /* Initialize debug */
312 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200313 mfspr r1,SPRN_DBCR0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200314 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
315 bne skip_debug_init /* if set, don't clear debug register */
Victor Gallardob52cde92010-09-16 11:32:04 -0700316 mfspr r1,SPRN_CCR0
317 ori r1,r1,CCR0_DTB@l /* Disable Trace Broadcast */
318 mtspr SPRN_CCR0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200319 mtspr SPRN_DBCR0,r0
320 mtspr SPRN_DBCR1,r0
321 mtspr SPRN_DBCR2,r0
322 mtspr SPRN_IAC1,r0
323 mtspr SPRN_IAC2,r0
324 mtspr SPRN_IAC3,r0
325 mtspr SPRN_DAC1,r0
326 mtspr SPRN_DAC2,r0
327 mtspr SPRN_DVC1,r0
328 mtspr SPRN_DVC2,r0
wdenk0442ed82002-11-03 10:24:00 +0000329
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200330 mfspr r1,SPRN_DBSR
331 mtspr SPRN_DBSR,r1 /* Clear all valid bits */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200332skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000333
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200334#if defined (CONFIG_440SPE)
335 /*----------------------------------------------------------------+
336 | Initialize Core Configuration Reg1.
337 | a. ICDPEI: Record even parity. Normal operation.
338 | b. ICTPEI: Record even parity. Normal operation.
339 | c. DCTPEI: Record even parity. Normal operation.
340 | d. DCDPEI: Record even parity. Normal operation.
341 | e. DCUPEI: Record even parity. Normal operation.
342 | f. DCMPEI: Record even parity. Normal operation.
343 | g. FCOM: Normal operation
344 | h. MMUPEI: Record even parity. Normal operation.
345 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200346 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200347 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200348 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200349 mtspr SPRN_CCR1, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200350
351 /*----------------------------------------------------------------+
352 | Reset the timebase.
353 | The previous write to CCR1 sets the timebase source.
354 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200355 mtspr SPRN_TBWL, r0
356 mtspr SPRN_TBWU, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200357#endif
358
wdenk0442ed82002-11-03 10:24:00 +0000359 /*----------------------------------------------------------------*/
360 /* Setup interrupt vectors */
361 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200362 mtspr SPRN_IVPR,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200363 li r1,0x0100
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200364 mtspr SPRN_IVOR0,r1 /* Critical input */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200365 li r1,0x0200
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200366 mtspr SPRN_IVOR1,r1 /* Machine check */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200367 li r1,0x0300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200368 mtspr SPRN_IVOR2,r1 /* Data storage */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200369 li r1,0x0400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200370 mtspr SPRN_IVOR3,r1 /* Instruction storage */
wdenk0442ed82002-11-03 10:24:00 +0000371 li r1,0x0500
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200372 mtspr SPRN_IVOR4,r1 /* External interrupt */
wdenk0442ed82002-11-03 10:24:00 +0000373 li r1,0x0600
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200374 mtspr SPRN_IVOR5,r1 /* Alignment */
wdenk0442ed82002-11-03 10:24:00 +0000375 li r1,0x0700
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200376 mtspr SPRN_IVOR6,r1 /* Program check */
wdenk0442ed82002-11-03 10:24:00 +0000377 li r1,0x0800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200378 mtspr SPRN_IVOR7,r1 /* Floating point unavailable */
wdenk0442ed82002-11-03 10:24:00 +0000379 li r1,0x0c00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200380 mtspr SPRN_IVOR8,r1 /* System call */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200381 li r1,0x0a00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200382 mtspr SPRN_IVOR9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200383 li r1,0x0900
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200384 mtspr SPRN_IVOR10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000385 li r1,0x1300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200386 mtspr SPRN_IVOR13,r1 /* Data TLB error */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200387 li r1,0x1400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200388 mtspr SPRN_IVOR14,r1 /* Instr TLB error */
wdenk0442ed82002-11-03 10:24:00 +0000389 li r1,0x2000
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200390 mtspr SPRN_IVOR15,r1 /* Debug */
wdenk0442ed82002-11-03 10:24:00 +0000391
392 /*----------------------------------------------------------------*/
393 /* Configure cache regions */
394 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200395 mtspr SPRN_INV0,r0
396 mtspr SPRN_INV1,r0
397 mtspr SPRN_INV2,r0
398 mtspr SPRN_INV3,r0
399 mtspr SPRN_DNV0,r0
400 mtspr SPRN_DNV1,r0
401 mtspr SPRN_DNV2,r0
402 mtspr SPRN_DNV3,r0
403 mtspr SPRN_ITV0,r0
404 mtspr SPRN_ITV1,r0
405 mtspr SPRN_ITV2,r0
406 mtspr SPRN_ITV3,r0
407 mtspr SPRN_DTV0,r0
408 mtspr SPRN_DTV1,r0
409 mtspr SPRN_DTV2,r0
410 mtspr SPRN_DTV3,r0
wdenk0442ed82002-11-03 10:24:00 +0000411
412 /*----------------------------------------------------------------*/
413 /* Cache victim limits */
414 /*----------------------------------------------------------------*/
415 /* floors 0, ceiling max to use the entire cache -- nothing locked
416 */
417 lis r1,0x0001
418 ori r1,r1,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200419 mtspr SPRN_IVLIM,r1
420 mtspr SPRN_DVLIM,r1
wdenk0442ed82002-11-03 10:24:00 +0000421
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200422 /*----------------------------------------------------------------+
423 |Initialize MMUCR[STID] = 0.
424 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200425 mfspr r0,SPRN_MMUCR
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200426 addis r1,0,0xFFFF
427 ori r1,r1,0xFF00
428 and r0,r0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200429 mtspr SPRN_MMUCR,r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200430
wdenk0442ed82002-11-03 10:24:00 +0000431 /*----------------------------------------------------------------*/
432 /* Clear all TLB entries -- TID = 0, TS = 0 */
433 /*----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200434 addis r0,0,0x0000
Stefan Roesed0c43952009-07-14 15:53:08 +0200435#ifdef CONFIG_SYS_RAMBOOT
Stefan Roesec20ef322009-05-11 13:46:14 +0200436 li r4,0 /* Start with TLB #0 */
Stefan Roesed0c43952009-07-14 15:53:08 +0200437#else
438 li r4,1 /* Start with TLB #1 */
439#endif
440 li r1,64 /* 64 TLB entries */
441 sub r1,r1,r4 /* calculate last TLB # */
442 mtctr r1
Stefan Roesec20ef322009-05-11 13:46:14 +0200443rsttlb:
444#ifdef CONFIG_SYS_RAMBOOT
445 tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
446 rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
447 beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
448#endif
449 tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
450 tlbwe r0,r4,1
451 tlbwe r0,r4,2
452tlbnxt: addi r4,r4,1 /* Next TLB */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200453 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000454
455 /*----------------------------------------------------------------*/
456 /* TLB entry setup -- step thru tlbtab */
457 /*----------------------------------------------------------------*/
Stefan Roese97251f92010-04-09 14:03:59 +0200458#if defined(CONFIG_440SPE_REVA)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200459 /*----------------------------------------------------------------*/
460 /* We have different TLB tables for revA and rev B of 440SPe */
461 /*----------------------------------------------------------------*/
462 mfspr r1, PVR
463 lis r0,0x5342
464 ori r0,r0,0x1891
465 cmpw r7,r1,r0
466 bne r7,..revA
467 bl tlbtabB
468 b ..goon
469..revA:
470 bl tlbtabA
471..goon:
472#else
wdenk0442ed82002-11-03 10:24:00 +0000473 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200474#endif
wdenk0442ed82002-11-03 10:24:00 +0000475 mr r5,r0
476 li r1,0x003f /* 64 TLB entries max */
477 mtctr r1
478 li r4,0 /* TLB # */
479
480 addi r5,r5,-4
Stefan Roesec20ef322009-05-11 13:46:14 +02004811:
482#ifdef CONFIG_SYS_RAMBOOT
483 tlbre r3,r4,0 /* Read contents from TLB word #0 */
484 rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
485 bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
486#endif
487 lwzu r0,4(r5)
wdenk0442ed82002-11-03 10:24:00 +0000488 cmpwi r0,0
489 beq 2f /* 0 marks end */
490 lwzu r1,4(r5)
491 lwzu r2,4(r5)
492 tlbwe r0,r4,0 /* TLB Word 0 */
493 tlbwe r1,r4,1 /* TLB Word 1 */
494 tlbwe r2,r4,2 /* TLB Word 2 */
Stefan Roesec20ef322009-05-11 13:46:14 +0200495tlbnx2: addi r4,r4,1 /* Next TLB */
wdenk0442ed82002-11-03 10:24:00 +0000496 bdnz 1b
497
498 /*----------------------------------------------------------------*/
499 /* Continue from 'normal' start */
500 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +02005012:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200502 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000503 b _start
504
5053: li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200506 mtspr SPRN_SRR1,r0 /* Keep things disabled for now */
wdenk0442ed82002-11-03 10:24:00 +0000507 mflr r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200508 mtspr SPRN_SRR0,r1
wdenk0442ed82002-11-03 10:24:00 +0000509 rfi
stroese434979e2003-05-23 11:18:02 +0000510#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000511
512/*
513 * r3 - 1st arg to board_init(): IMMP pointer
514 * r4 - 2nd arg to board_init(): boot flag
515 */
Stefan Roese07038ad2013-04-02 10:37:04 +0200516#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000517 .text
518 .long 0x27051956 /* U-Boot Magic Number */
519 .globl version_string
520version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +0200521 .ascii U_BOOT_VERSION_STRING, "\0"
wdenk0442ed82002-11-03 10:24:00 +0000522
wdenk0442ed82002-11-03 10:24:00 +0000523 . = EXC_OFF_SYS_RESET
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200524 .globl _start_of_vectors
525_start_of_vectors:
526
527/* Critical input. */
528 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
529
530#ifdef CONFIG_440
531/* Machine check */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200532 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200533#else
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200534 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200535#endif /* CONFIG_440 */
536
537/* Data Storage exception. */
538 STD_EXCEPTION(0x300, DataStorage, UnknownException)
539
540/* Instruction Storage exception. */
541 STD_EXCEPTION(0x400, InstStorage, UnknownException)
542
543/* External Interrupt exception. */
544 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
545
546/* Alignment exception. */
547 . = 0x600
548Alignment:
549 EXCEPTION_PROLOG(SRR0, SRR1)
550 mfspr r4,DAR
551 stw r4,_DAR(r21)
552 mfspr r5,DSISR
553 stw r5,_DSISR(r21)
554 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100555 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200556
557/* Program check exception */
558 . = 0x700
559ProgramCheck:
560 EXCEPTION_PROLOG(SRR0, SRR1)
561 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100562 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
563 MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200564
565#ifdef CONFIG_440
566 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
567 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
568 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roese80d99a42007-06-19 16:42:31 +0200569#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200570 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
571
572#ifdef CONFIG_440
573 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
574 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
575#else
576 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
577 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
578 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
579#endif
580 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
581
582 .globl _end_of_vectors
583_end_of_vectors:
584 . = _START_OFFSET
Stefan Roese42fbddd2006-09-07 11:51:23 +0200585#endif
wdenk0442ed82002-11-03 10:24:00 +0000586 .globl _start
587_start:
588
Stefan Roese07038ad2013-04-02 10:37:04 +0200589#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
590 /*
591 * This is the entry of the real U-Boot from a board port
592 * that supports SPL booting on the PPC4xx. We only need
593 * to call board_init_f() here. Everything else has already
594 * been done in the SPL u-boot version.
595 */
596 GET_GOT /* initialize GOT access */
597 bl board_init_f /* run 1st part of board init code (in Flash)*/
598 /* NOTREACHED - board_init_f() does not return */
599#endif
600
wdenk0442ed82002-11-03 10:24:00 +0000601/*****************************************************************************/
602#if defined(CONFIG_440)
603
604 /*----------------------------------------------------------------*/
605 /* Clear and set up some registers. */
606 /*----------------------------------------------------------------*/
607 li r0,0x0000
608 lis r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200609 mtspr SPRN_DEC,r0 /* prevent dec exceptions */
610 mtspr SPRN_TBWL,r0 /* prevent fit & wdt exceptions */
611 mtspr SPRN_TBWU,r0
612 mtspr SPRN_TSR,r1 /* clear all timer exception status */
613 mtspr SPRN_TCR,r0 /* disable all */
614 mtspr SPRN_ESR,r0 /* clear exception syndrome register */
wdenk0442ed82002-11-03 10:24:00 +0000615 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000616
617 /*----------------------------------------------------------------*/
618 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200619 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000620 /* value you need in this case 0x8cff 0000 should do the trick */
621 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200622#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000623 lis r1,0xffff
624 ori r1,r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200625 mtspr SPRN_DBSR,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200626 lis r0,CONFIG_SYS_INIT_DBCR@h
627 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200628 mtspr SPRN_DBCR0,r0
wdenk0442ed82002-11-03 10:24:00 +0000629 isync
630#endif
631
632 /*----------------------------------------------------------------*/
633 /* Setup the internal SRAM */
634 /*----------------------------------------------------------------*/
635 li r0,0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200636
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200637#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roese326c9712005-08-01 16:41:48 +0200638 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200639 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
640 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200641 addis r4,r0,CONFIG_SYS_INIT_RAM_SIZE@h
642 ori r4,r4,CONFIG_SYS_INIT_RAM_SIZE@l
Stefan Roese326c9712005-08-01 16:41:48 +0200643 rlwinm. r5,r4,0,27,31
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200644 rlwinm r5,r4,27,5,31
645 beq ..d_ran
646 addi r5,r5,0x0001
Stefan Roese326c9712005-08-01 16:41:48 +0200647..d_ran:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200648 mtctr r5
Stefan Roese326c9712005-08-01 16:41:48 +0200649..d_ag:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200650 dcbz r0,r3
651 addi r3,r3,32
652 bdnz ..d_ag
Stefan Roesea86bde32008-01-09 10:23:16 +0100653
654 /*
655 * Lock the init-ram/stack in d-cache, so that other regions
656 * may use d-cache as well
657 * Note, that this current implementation locks exactly 4k
658 * of d-cache, so please make sure that you don't define a
659 * bigger init-ram area. Take a look at the lwmon5 440EPx
660 * implementation as a reference.
661 */
662 msync
663 isync
664 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
665 lis r1,0x0201
666 ori r1,r1,0xf808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200667 mtspr SPRN_DVLIM,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100668 lis r1,0x0808
669 ori r1,r1,0x0808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200670 mtspr SPRN_DNV0,r1
671 mtspr SPRN_DNV1,r1
672 mtspr SPRN_DNV2,r1
673 mtspr SPRN_DNV3,r1
674 mtspr SPRN_DTV0,r1
675 mtspr SPRN_DTV1,r1
676 mtspr SPRN_DTV2,r1
677 mtspr SPRN_DTV3,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100678 msync
679 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200680#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200681
682 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
683#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
684 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roesecc019d12008-03-11 15:05:50 +0100685#if defined(CONFIG_440GX) || \
686 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -0700687 defined(CONFIG_460SX)
Dave Mitchell3c3734172008-11-20 14:00:49 -0600688 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
Tirumala Marri95ac4282010-09-28 14:15:14 -0700689#elif defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
690 defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600691 lis r1, 0x0000
692 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
693 mtdcr L2_CACHE_CFG,r1
wdenk544e9732004-02-06 23:19:44 +0000694#endif
wdenk0442ed82002-11-03 10:24:00 +0000695
Stefan Roese42fbddd2006-09-07 11:51:23 +0200696 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000697 ori r2,r2,0xffff
Dave Mitchell3c3734172008-11-20 14:00:49 -0600698 mfdcr r1,ISRAM0_DPC
wdenk0442ed82002-11-03 10:24:00 +0000699 and r1,r1,r2 /* Disable parity check */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600700 mtdcr ISRAM0_DPC,r1
701 mfdcr r1,ISRAM0_PMEG
Stefan Roese42fbddd2006-09-07 11:51:23 +0200702 and r1,r1,r2 /* Disable pwr mgmt */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600703 mtdcr ISRAM0_PMEG,r1
wdenk0442ed82002-11-03 10:24:00 +0000704
705 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese99644742005-11-29 18:18:21 +0100706#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000707 ori r1,r1,0x0980 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600708 mtdcr ISRAM0_SB0CR,r1
wdenk544e9732004-02-06 23:19:44 +0000709 lis r1,0x8001
710 ori r1,r1,0x0980 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600711 mtdcr ISRAM0_SB1CR,r1
wdenk544e9732004-02-06 23:19:44 +0000712 lis r1, 0x8002
713 ori r1,r1, 0x0980 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600714 mtdcr ISRAM0_SB2CR,r1
wdenk544e9732004-02-06 23:19:44 +0000715 lis r1, 0x8003
716 ori r1,r1, 0x0980 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600717 mtdcr ISRAM0_SB3CR,r1
Tirumala Marri95ac4282010-09-28 14:15:14 -0700718#elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || \
719 defined(CONFIG_460GT) || defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600720 lis r1,0x0000 /* BAS = X_0000_0000 */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200721 ori r1,r1,0x0984 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600722 mtdcr ISRAM0_SB0CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200723 lis r1,0x0001
724 ori r1,r1,0x0984 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600725 mtdcr ISRAM0_SB1CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200726 lis r1, 0x0002
727 ori r1,r1, 0x0984 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600728 mtdcr ISRAM0_SB2CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200729 lis r1, 0x0003
730 ori r1,r1, 0x0984 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600731 mtdcr ISRAM0_SB3CR,r1
Tirumala Marri95ac4282010-09-28 14:15:14 -0700732#if defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
733 defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600734 lis r2,0x7fff
735 ori r2,r2,0xffff
736 mfdcr r1,ISRAM1_DPC
737 and r1,r1,r2 /* Disable parity check */
Wolfgang Denk55334c72008-12-16 01:02:17 +0100738 mtdcr ISRAM1_DPC,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600739 mfdcr r1,ISRAM1_PMEG
740 and r1,r1,r2 /* Disable pwr mgmt */
741 mtdcr ISRAM1_PMEG,r1
742
743 lis r1,0x0004 /* BAS = 4_0004_0000 */
Tirumala Marri95ac4282010-09-28 14:15:14 -0700744 ori r1,r1,ISRAM1_SIZE /* ocm size */
Dave Mitchell5c057592008-11-20 14:09:50 -0600745 mtdcr ISRAM1_SB0CR,r1
746#endif
Feng Kan224bc962008-07-08 22:47:31 -0700747#elif defined(CONFIG_460SX)
748 lis r1,0x0000 /* BAS = 0000_0000 */
749 ori r1,r1,0x0B84 /* first 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600750 mtdcr ISRAM0_SB0CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700751 lis r1,0x0001
752 ori r1,r1,0x0B84 /* second 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600753 mtdcr ISRAM0_SB1CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700754 lis r1, 0x0002
755 ori r1,r1, 0x0B84 /* third 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600756 mtdcr ISRAM0_SB2CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700757 lis r1, 0x0003
758 ori r1,r1, 0x0B84 /* fourth 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600759 mtdcr ISRAM0_SB3CR,r1
Stefan Roese42fbddd2006-09-07 11:51:23 +0200760#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000761 ori r1,r1,0x0380 /* 8k rw */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600762 mtdcr ISRAM0_SB0CR,r1
763 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
Stefan Roese326c9712005-08-01 16:41:48 +0200764#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200765#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000766
767 /*----------------------------------------------------------------*/
768 /* Setup the stack in internal SRAM */
769 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200770 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
771 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
wdenk0442ed82002-11-03 10:24:00 +0000772 li r0,0
773 stwu r0,-4(r1)
774 stwu r0,-4(r1) /* Terminate call chain */
775
776 stwu r1,-8(r1) /* Save back chain and move SP */
777 lis r0,RESET_VECTOR@h /* Address of reset vector */
778 ori r0,r0, RESET_VECTOR@l
779 stwu r1,-8(r1) /* Save back chain and move SP */
780 stw r0,+12(r1) /* Save return addr (underflow vect) */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200781
Stefan Roese42fbddd2006-09-07 11:51:23 +0200782#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +0200783 bl nand_boot_common /* will not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200784#else
Stefan Roese07038ad2013-04-02 10:37:04 +0200785#ifndef CONFIG_SPL_BUILD
wdenk0442ed82002-11-03 10:24:00 +0000786 GET_GOT
Stefan Roese07038ad2013-04-02 10:37:04 +0200787#endif
Stefan Roesec443fe92005-11-22 13:20:42 +0100788
789 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +0000790 bl board_init_f
Peter Tyser0c44caf2010-09-14 19:13:53 -0500791 /* NOTREACHED - board_init_f() does not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200792#endif
wdenk0442ed82002-11-03 10:24:00 +0000793
794#endif /* CONFIG_440 */
795
796/*****************************************************************************/
Matthias Fuchse54a67f2013-08-07 12:10:38 +0200797#if defined(CONFIG_405GP) || \
Stefan Roese17ffbc82007-03-21 13:38:59 +0100798 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200799 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000800 /*----------------------------------------------------------------------- */
801 /* Clear and set up some registers. */
802 /*----------------------------------------------------------------------- */
803 addi r4,r0,0x0000
Stefan Roese153b3e22007-10-05 17:10:59 +0200804#if !defined(CONFIG_405EX)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200805 mtspr SPRN_SGR,r4
Stefan Roese153b3e22007-10-05 17:10:59 +0200806#else
807 /*
808 * On 405EX, completely clearing the SGR leads to PPC hangup
809 * upon PCIe configuration access. The PCIe memory regions
810 * need to be guarded!
811 */
812 lis r3,0x0000
813 ori r3,r3,0x7FFC
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200814 mtspr SPRN_SGR,r3
Stefan Roese153b3e22007-10-05 17:10:59 +0200815#endif
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200816 mtspr SPRN_DCWR,r4
wdenk0442ed82002-11-03 10:24:00 +0000817 mtesr r4 /* clear Exception Syndrome Reg */
818 mttcr r4 /* clear Timer Control Reg */
819 mtxer r4 /* clear Fixed-Point Exception Reg */
820 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000821 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
822 /* dbsr is cleared by setting bits to 1) */
823 mtdbsr r4 /* clear/reset the dbsr */
824
Grant Ericksonb6933412008-05-22 14:44:14 -0700825 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000826 bl invalidate_icache
827 bl invalidate_dcache
828
Grant Ericksonb6933412008-05-22 14:44:14 -0700829 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200830 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
831 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700832 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000833 isync
834
Grant Ericksonb6933412008-05-22 14:44:14 -0700835 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200836 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
837 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700838 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000839
Ricardo Ribalda Delgado78ea77e2008-10-21 18:29:46 +0200840#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
841 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000842 /*----------------------------------------------------------------------- */
843 /* Tune the speed and size for flash CS0 */
844 /*----------------------------------------------------------------------- */
845 bl ext_bus_cntlr_init
846#endif
Stefan Roese7d72e022008-06-02 14:35:44 +0200847
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200848#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roese153b3e22007-10-05 17:10:59 +0200849 /*
Grant Ericksonb6933412008-05-22 14:44:14 -0700850 * For boards that don't have OCM and can't use the data cache
851 * for their primordial stack, setup stack here directly after the
852 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roese153b3e22007-10-05 17:10:59 +0200853 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200854 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
855 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
Stefan Roese153b3e22007-10-05 17:10:59 +0200856
857 li r0, 0 /* Make room for stack frame header and */
858 stwu r0, -4(r1) /* clear final stack frame so that */
859 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
860 /*
861 * Set up a dummy frame to store reset vector as return address.
862 * this causes stack underflow to reset board.
863 */
864 stwu r1, -8(r1) /* Save back chain and move SP */
865 lis r0, RESET_VECTOR@h /* Address of reset vector */
866 ori r0, r0, RESET_VECTOR@l
867 stwu r1, -8(r1) /* Save back chain and move SP */
868 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200869#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000870
stroese434979e2003-05-23 11:18:02 +0000871#if defined(CONFIG_405EP)
872 /*----------------------------------------------------------------------- */
873 /* DMA Status, clear to come up clean */
874 /*----------------------------------------------------------------------- */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200875 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200876 ori r3,r3, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200877 mtdcr DMASR, r3
stroese434979e2003-05-23 11:18:02 +0000878
Wolfgang Denka1be4762008-05-20 16:00:29 +0200879 bl ppc405ep_init /* do ppc405ep specific init */
stroese434979e2003-05-23 11:18:02 +0000880#endif /* CONFIG_405EP */
881
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200882#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roese17ffbc82007-03-21 13:38:59 +0100883#if defined(CONFIG_405EZ)
884 /********************************************************************
885 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
886 *******************************************************************/
887 /*
888 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200889 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roese17ffbc82007-03-21 13:38:59 +0100890 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200891 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
892 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese80d99a42007-06-19 16:42:31 +0200893 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200894 mtdcr OCM0_PLBCR1,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100895 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200896 mtdcr OCM0_PLBCR2,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100897 isync
898
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200899 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
900 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200901 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200902 mtdcr OCM0_DSRC1, r3 /* Set Data Side */
903 mtdcr OCM0_ISRC1, r3 /* Set Instruction Side */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100904 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200905 mtdcr OCM0_DSRC2, r3 /* Set Data Side */
906 mtdcr OCM0_ISRC2, r3 /* Set Instruction Side */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200907 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roese918010a2009-09-09 16:25:29 +0200908 mtdcr OCM0_DISDPC,r3
Stefan Roese17ffbc82007-03-21 13:38:59 +0100909
910 isync
Stefan Roesef6c7b762007-03-24 15:45:34 +0100911#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000912 /********************************************************************
913 * Setup OCM - On Chip Memory
914 *******************************************************************/
915 /* Setup OCM */
wdenk57b2d802003-06-27 21:31:46 +0000916 lis r0, 0x7FFF
917 ori r0, r0, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200918 mfdcr r3, OCM0_ISCNTL /* get instr-side IRAM config */
919 mfdcr r4, OCM0_DSCNTL /* get data-side IRAM config */
Stefan Roesef6c7b762007-03-24 15:45:34 +0100920 and r3, r3, r0 /* disable data-side IRAM */
921 and r4, r4, r0 /* disable data-side IRAM */
Stefan Roese918010a2009-09-09 16:25:29 +0200922 mtdcr OCM0_ISCNTL, r3 /* set instr-side IRAM config */
923 mtdcr OCM0_DSCNTL, r4 /* set data-side IRAM config */
wdenk57b2d802003-06-27 21:31:46 +0000924 isync
wdenk0442ed82002-11-03 10:24:00 +0000925
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200926 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
927 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200928 mtdcr OCM0_DSARC, r3
wdenk0442ed82002-11-03 10:24:00 +0000929 addis r4, 0, 0xC000 /* OCM data area enabled */
Stefan Roese918010a2009-09-09 16:25:29 +0200930 mtdcr OCM0_DSCNTL, r4
wdenk57b2d802003-06-27 21:31:46 +0000931 isync
Stefan Roese17ffbc82007-03-21 13:38:59 +0100932#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000933#endif
934
935 /*----------------------------------------------------------------------- */
936 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
937 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200938#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonb6933412008-05-22 14:44:14 -0700939 li r4, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +0200940 mtdcr EBC0_CFGADDR, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200941 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
942 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200943 mtdcr EBC0_CFGDATA, r4
wdenk0442ed82002-11-03 10:24:00 +0000944
Grant Ericksonb6933412008-05-22 14:44:14 -0700945 addi r4, 0, PBxCR
Stefan Roese918010a2009-09-09 16:25:29 +0200946 mtdcr EBC0_CFGADDR, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200947 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
948 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200949 mtdcr EBC0_CFGDATA, r4
wdenk0442ed82002-11-03 10:24:00 +0000950
Grant Ericksonb6933412008-05-22 14:44:14 -0700951 /*
952 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200953 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonb6933412008-05-22 14:44:14 -0700954 */
955 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200956 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
957 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +0000958 mtdccr r4
959
Grant Ericksonb6933412008-05-22 14:44:14 -0700960 /*
961 * Preallocate data cache lines to be used to avoid a subsequent
962 * cache miss and an ensuing machine check exception when exceptions
963 * are enabled.
964 */
965 li r0, 0
966
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200967 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
968 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +0000969
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200970 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
971 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +0000972
Grant Ericksonb6933412008-05-22 14:44:14 -0700973 /*
974 * Convert the size, in bytes, to the number of cache lines/blocks
975 * to preallocate.
976 */
977 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
978 srwi r5, r4, L1_CACHE_SHIFT
979 beq ..load_counter
980 addi r5, r5, 0x0001
981..load_counter:
982 mtctr r5
983
984 /* Preallocate the computed number of cache blocks. */
985..alloc_dcache_block:
986 dcba r0, r3
987 addi r3, r3, L1_CACHE_BYTES
988 bdnz ..alloc_dcache_block
989 sync
990
991 /*
992 * Load the initial stack pointer and data area and convert the size,
993 * in bytes, to the number of words to initialize to a known value.
994 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200995 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
996 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700997
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200998 lis r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@h
999 ori r4, r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +00001000 mtctr r4
1001
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001002 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001003 ori r2, r2, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +00001004
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001005 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1006 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001007
1008..stackloop:
Grant Ericksonb6933412008-05-22 14:44:14 -07001009 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001010 bdnz ..stackloop
1011
Grant Ericksonb6933412008-05-22 14:44:14 -07001012 /*
1013 * Make room for stack frame header and clear final stack frame so
1014 * that stack backtraces terminate cleanly.
1015 */
1016 stwu r0, -4(r1)
1017 stwu r0, -4(r1)
1018
wdenk0442ed82002-11-03 10:24:00 +00001019 /*
1020 * Set up a dummy frame to store reset vector as return address.
1021 * this causes stack underflow to reset board.
1022 */
1023 stwu r1, -8(r1) /* Save back chain and move SP */
1024 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1025 ori r0, r0, RESET_VECTOR@l
1026 stwu r1, -8(r1) /* Save back chain and move SP */
1027 stw r0, +12(r1) /* Save return addr (underflow vect) */
1028
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001029#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1030 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001031 /*
1032 * Stack in OCM.
1033 */
1034
1035 /* Set up Stack at top of OCM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001036 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1037 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
wdenk0442ed82002-11-03 10:24:00 +00001038
1039 /* Set up a zeroized stack frame so that backtrace works right */
1040 li r0, 0
1041 stwu r0, -4(r1)
1042 stwu r0, -4(r1)
1043
1044 /*
1045 * Set up a dummy frame to store reset vector as return address.
1046 * this causes stack underflow to reset board.
1047 */
1048 stwu r1, -8(r1) /* Save back chain and move SP */
1049 lis r0, RESET_VECTOR@h /* Address of reset vector */
1050 ori r0, r0, RESET_VECTOR@l
1051 stwu r1, -8(r1) /* Save back chain and move SP */
1052 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001053#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001054
Stefan Roese23d8d342007-06-06 11:42:13 +02001055#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +02001056 bl nand_boot_common /* will not return */
Stefan Roese23d8d342007-06-06 11:42:13 +02001057#else
wdenk0442ed82002-11-03 10:24:00 +00001058 GET_GOT /* initialize GOT access */
1059
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001060 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +00001061
wdenk0442ed82002-11-03 10:24:00 +00001062 bl board_init_f /* run first part of init code (from Flash) */
Peter Tyser0c44caf2010-09-14 19:13:53 -05001063 /* NOTREACHED - board_init_f() does not return */
1064
Stefan Roese23d8d342007-06-06 11:42:13 +02001065#endif /* CONFIG_NAND_SPL */
wdenk0442ed82002-11-03 10:24:00 +00001066
Matthias Fuchse54a67f2013-08-07 12:10:38 +02001067#endif /* CONFIG_405GP || CONFIG_405 || CONFIG_405EP */
wdenk232fe0b2003-09-02 22:48:03 +00001068 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001069
1070
Stefan Roese07038ad2013-04-02 10:37:04 +02001071#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001072/*
1073 * This code finishes saving the registers to the exception frame
1074 * and jumps to the appropriate handler for the exception.
1075 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1076 */
1077 .globl transfer_to_handler
1078transfer_to_handler:
1079 stw r22,_NIP(r21)
1080 lis r22,MSR_POW@h
1081 andc r23,r23,r22
1082 stw r23,_MSR(r21)
1083 SAVE_GPR(7, r21)
1084 SAVE_4GPRS(8, r21)
1085 SAVE_8GPRS(12, r21)
1086 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001087 mflr r23
1088 andi. r24,r23,0x3f00 /* get vector offset */
1089 stw r24,TRAP(r21)
1090 li r22,0
1091 stw r22,RESULT(r21)
1092 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001093 lwz r24,0(r23) /* virtual address of handler */
1094 lwz r23,4(r23) /* where to go when done */
1095 mtspr SRR0,r24
1096 mtspr SRR1,r20
1097 mtlr r23
1098 SYNC
1099 rfi /* jump to handler, enable MMU */
1100
1101int_return:
1102 mfmsr r28 /* Disable interrupts */
1103 li r4,0
1104 ori r4,r4,MSR_EE
1105 andc r28,r28,r4
1106 SYNC /* Some chip revs need this... */
1107 mtmsr r28
1108 SYNC
1109 lwz r2,_CTR(r1)
1110 lwz r0,_LINK(r1)
1111 mtctr r2
1112 mtlr r0
1113 lwz r2,_XER(r1)
1114 lwz r0,_CCR(r1)
1115 mtspr XER,r2
1116 mtcrf 0xFF,r0
1117 REST_10GPRS(3, r1)
1118 REST_10GPRS(13, r1)
1119 REST_8GPRS(23, r1)
1120 REST_GPR(31, r1)
1121 lwz r2,_NIP(r1) /* Restore environment */
1122 lwz r0,_MSR(r1)
1123 mtspr SRR0,r2
1124 mtspr SRR1,r0
1125 lwz r0,GPR0(r1)
1126 lwz r2,GPR2(r1)
1127 lwz r1,GPR1(r1)
1128 SYNC
1129 rfi
1130
1131crit_return:
1132 mfmsr r28 /* Disable interrupts */
1133 li r4,0
1134 ori r4,r4,MSR_EE
1135 andc r28,r28,r4
1136 SYNC /* Some chip revs need this... */
1137 mtmsr r28
1138 SYNC
1139 lwz r2,_CTR(r1)
1140 lwz r0,_LINK(r1)
1141 mtctr r2
1142 mtlr r0
1143 lwz r2,_XER(r1)
1144 lwz r0,_CCR(r1)
1145 mtspr XER,r2
1146 mtcrf 0xFF,r0
1147 REST_10GPRS(3, r1)
1148 REST_10GPRS(13, r1)
1149 REST_8GPRS(23, r1)
1150 REST_GPR(31, r1)
1151 lwz r2,_NIP(r1) /* Restore environment */
1152 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001153 mtspr SPRN_CSRR0,r2
1154 mtspr SPRN_CSRR1,r0
wdenk0442ed82002-11-03 10:24:00 +00001155 lwz r0,GPR0(r1)
1156 lwz r2,GPR2(r1)
1157 lwz r1,GPR1(r1)
1158 SYNC
1159 rfci
1160
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001161#ifdef CONFIG_440
1162mck_return:
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001163 mfmsr r28 /* Disable interrupts */
1164 li r4,0
1165 ori r4,r4,MSR_EE
1166 andc r28,r28,r4
1167 SYNC /* Some chip revs need this... */
1168 mtmsr r28
1169 SYNC
1170 lwz r2,_CTR(r1)
1171 lwz r0,_LINK(r1)
1172 mtctr r2
1173 mtlr r0
1174 lwz r2,_XER(r1)
1175 lwz r0,_CCR(r1)
1176 mtspr XER,r2
1177 mtcrf 0xFF,r0
1178 REST_10GPRS(3, r1)
1179 REST_10GPRS(13, r1)
1180 REST_8GPRS(23, r1)
1181 REST_GPR(31, r1)
1182 lwz r2,_NIP(r1) /* Restore environment */
1183 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001184 mtspr SPRN_MCSRR0,r2
1185 mtspr SPRN_MCSRR1,r0
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001186 lwz r0,GPR0(r1)
1187 lwz r2,GPR2(r1)
1188 lwz r1,GPR1(r1)
1189 SYNC
1190 rfmci
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001191#endif /* CONFIG_440 */
1192
1193
wdenk0442ed82002-11-03 10:24:00 +00001194 .globl get_pvr
1195get_pvr:
1196 mfspr r3, PVR
1197 blr
1198
wdenk0442ed82002-11-03 10:24:00 +00001199/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001200/* Function: out16 */
1201/* Description: Output 16 bits */
1202/*------------------------------------------------------------------------------- */
1203 .globl out16
1204out16:
1205 sth r4,0x0000(r3)
1206 blr
1207
1208/*------------------------------------------------------------------------------- */
1209/* Function: out16r */
1210/* Description: Byte reverse and output 16 bits */
1211/*------------------------------------------------------------------------------- */
1212 .globl out16r
1213out16r:
1214 sthbrx r4,r0,r3
1215 blr
1216
1217/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001218/* Function: out32r */
1219/* Description: Byte reverse and output 32 bits */
1220/*------------------------------------------------------------------------------- */
1221 .globl out32r
1222out32r:
1223 stwbrx r4,r0,r3
1224 blr
1225
1226/*------------------------------------------------------------------------------- */
1227/* Function: in16 */
1228/* Description: Input 16 bits */
1229/*------------------------------------------------------------------------------- */
1230 .globl in16
1231in16:
1232 lhz r3,0x0000(r3)
1233 blr
1234
1235/*------------------------------------------------------------------------------- */
1236/* Function: in16r */
1237/* Description: Input 16 bits and byte reverse */
1238/*------------------------------------------------------------------------------- */
1239 .globl in16r
1240in16r:
1241 lhbrx r3,r0,r3
1242 blr
1243
1244/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001245/* Function: in32r */
1246/* Description: Input 32 bits and byte reverse */
1247/*------------------------------------------------------------------------------- */
1248 .globl in32r
1249in32r:
1250 lwbrx r3,r0,r3
1251 blr
1252
Stefan Roese07038ad2013-04-02 10:37:04 +02001253#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001254/*
1255 * void relocate_code (addr_sp, gd, addr_moni)
1256 *
1257 * This "function" does not return, instead it continues in RAM
1258 * after relocating the monitor code.
1259 *
Grant Ericksonb6933412008-05-22 14:44:14 -07001260 * r3 = Relocated stack pointer
1261 * r4 = Relocated global data pointer
1262 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001263 */
1264 .globl relocate_code
1265relocate_code:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001266#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001267 /*
Stefan Roese593a0fb2010-11-26 15:45:34 +01001268 * We need to flush the initial global data (gd_t) and bd_info
1269 * before the dcache will be invalidated.
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001270 */
1271
Grant Ericksonb6933412008-05-22 14:44:14 -07001272 /* Save registers */
1273 mr r9, r3
1274 mr r10, r4
1275 mr r11, r5
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001276
Stefan Roese593a0fb2010-11-26 15:45:34 +01001277 /*
1278 * Flush complete dcache, this is faster than flushing the
1279 * ranges for global_data and bd_info instead.
1280 */
1281 bl flush_dcache
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001282
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001283#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonb6933412008-05-22 14:44:14 -07001284 /*
1285 * Undo the earlier data cache set-up for the primordial stack and
1286 * data area. First, invalidate the data cache and then disable data
1287 * cacheability for that area. Finally, restore the EBC values, if
1288 * any.
1289 */
1290
1291 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001292 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1293 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001294
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001295 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
1296 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001297 add r4, r4, r3
1298
1299 bl invalidate_dcache_range
1300
1301 /* Disable cacheability for the region */
1302 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001303 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1304 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001305 and r3, r3, r4
1306 mtdccr r3
1307
1308 /* Restore the EBC parameters */
1309 li r3, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +02001310 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001311 lis r3, PBxAP_VAL@h
1312 ori r3, r3, PBxAP_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001313 mtdcr EBC0_CFGDATA, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001314
1315 li r3, PBxCR
Stefan Roese918010a2009-09-09 16:25:29 +02001316 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001317 lis r3, PBxCR_VAL@h
1318 ori r3, r3, PBxCR_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001319 mtdcr EBC0_CFGDATA, r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001320#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonb6933412008-05-22 14:44:14 -07001321
1322 /* Restore registers */
1323 mr r3, r9
1324 mr r4, r10
1325 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001326#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesea86bde32008-01-09 10:23:16 +01001327
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001328#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesea86bde32008-01-09 10:23:16 +01001329 /*
1330 * Unlock the previously locked d-cache
1331 */
1332 msync
1333 isync
1334 /* set TFLOOR/NFLOOR to 0 again */
1335 lis r6,0x0001
1336 ori r6,r6,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001337 mtspr SPRN_DVLIM,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001338 lis r6,0x0000
1339 ori r6,r6,0x0000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001340 mtspr SPRN_DNV0,r6
1341 mtspr SPRN_DNV1,r6
1342 mtspr SPRN_DNV2,r6
1343 mtspr SPRN_DNV3,r6
1344 mtspr SPRN_DTV0,r6
1345 mtspr SPRN_DTV1,r6
1346 mtspr SPRN_DTV2,r6
1347 mtspr SPRN_DTV3,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001348 msync
1349 isync
Stefan Roese04bb5fc2010-08-31 11:27:14 +02001350
1351 /* Invalidate data cache, now no longer our stack */
1352 dccci 0,0
1353 sync
1354 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001355#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesea86bde32008-01-09 10:23:16 +01001356
Stefan Roese9eba0c82006-06-02 16:18:04 +02001357 /*
1358 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1359 * to speed up the boot process. Now this cache needs to be disabled.
1360 */
Stefan Roese1d568062010-05-27 16:45:20 +02001361#if defined(CONFIG_440)
Stefan Roesefe05a022008-11-20 11:46:20 +01001362 /* Clear all potential pending exceptions */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001363 mfspr r1,SPRN_MCSR
1364 mtspr SPRN_MCSR,r1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001365 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Stefan Roese326c9712005-08-01 16:41:48 +02001366 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese99644742005-11-29 18:18:21 +01001367 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001368 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roese9eba0c82006-06-02 16:18:04 +02001369 sync
Stefan Roese326c9712005-08-01 16:41:48 +02001370 isync
Stefan Roese1d568062010-05-27 16:45:20 +02001371#endif /* defined(CONFIG_440) */
wdenk0442ed82002-11-03 10:24:00 +00001372 mr r1, r3 /* Set new stack pointer */
1373 mr r9, r4 /* Save copy of Init Data pointer */
1374 mr r10, r5 /* Save copy of Destination Address */
1375
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001376 GET_GOT
wdenk0442ed82002-11-03 10:24:00 +00001377 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001378 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1379 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +00001380 lwz r5, GOT(__init_end)
1381 sub r5, r5, r4
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001382 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001383
1384 /*
1385 * Fix GOT pointer:
1386 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001387 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001388 *
1389 * Offset:
1390 */
1391 sub r15, r10, r4
1392
1393 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001394 add r12, r12, r15
Grant Ericksonb6933412008-05-22 14:44:14 -07001395 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001396 add r30, r30, r15
1397
1398 /*
1399 * Now relocate code
1400 */
1401
1402 cmplw cr1,r3,r4
1403 addi r0,r5,3
1404 srwi. r0,r0,2
1405 beq cr1,4f /* In place copy is not necessary */
1406 beq 7f /* Protect against 0 count */
1407 mtctr r0
1408 bge cr1,2f
1409
1410 la r8,-4(r4)
1411 la r7,-4(r3)
14121: lwzu r0,4(r8)
1413 stwu r0,4(r7)
1414 bdnz 1b
1415 b 4f
1416
14172: slwi r0,r0,2
1418 add r8,r4,r0
1419 add r7,r3,r0
14203: lwzu r0,-4(r8)
1421 stwu r0,-4(r7)
1422 bdnz 3b
1423
1424/*
1425 * Now flush the cache: note that we must start from a cache aligned
1426 * address. Otherwise we might miss one cache line.
1427 */
14284: cmpwi r6,0
1429 add r5,r3,r5
1430 beq 7f /* Always flush prefetch queue in any case */
1431 subi r0,r6,1
1432 andc r3,r3,r0
1433 mr r4,r3
14345: dcbst 0,r4
1435 add r4,r4,r6
1436 cmplw r4,r5
1437 blt 5b
1438 sync /* Wait for all dcbst to complete on bus */
1439 mr r4,r3
14406: icbi 0,r4
1441 add r4,r4,r6
1442 cmplw r4,r5
1443 blt 6b
14447: sync /* Wait for all icbi to complete on bus */
1445 isync
1446
1447/*
1448 * We are done. Do not return, instead branch to second part of board
1449 * initialization, now running from RAM.
1450 */
1451
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001452 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001453 mtlr r0
1454 blr /* NEVER RETURNS! */
1455
1456in_ram:
1457
1458 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001459 * Relocation Function, r12 point to got2+0x8000
wdenk0442ed82002-11-03 10:24:00 +00001460 *
1461 * Adjust got2 pointers, no need to check for 0, this code
1462 * already puts a few entries in the table.
1463 */
1464 li r0,__got2_entries@sectoff@l
1465 la r3,GOT(_GOT2_TABLE_)
1466 lwz r11,GOT(_GOT2_TABLE_)
1467 mtctr r0
1468 sub r11,r3,r11
1469 addi r3,r3,-4
14701: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001471 cmpwi r0,0
1472 beq- 2f
wdenk0442ed82002-11-03 10:24:00 +00001473 add r0,r0,r11
1474 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +020014752: bdnz 1b
wdenk0442ed82002-11-03 10:24:00 +00001476
1477 /*
1478 * Now adjust the fixups and the pointers to the fixups
1479 * in case we need to move ourselves again.
1480 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001481 li r0,__fixup_entries@sectoff@l
wdenk0442ed82002-11-03 10:24:00 +00001482 lwz r3,GOT(_FIXUP_TABLE_)
1483 cmpwi r0,0
1484 mtctr r0
1485 addi r3,r3,-4
1486 beq 4f
14873: lwzu r4,4(r3)
1488 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001489 cmpwi r0,0
wdenk0442ed82002-11-03 10:24:00 +00001490 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +01001491 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001492 beq- 5f
wdenk0442ed82002-11-03 10:24:00 +00001493 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +020014945: bdnz 3b
wdenk0442ed82002-11-03 10:24:00 +000014954:
1496clear_bss:
1497 /*
1498 * Now clear BSS segment
1499 */
wdenkbf2f8c92003-05-22 22:52:13 +00001500 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +00001501 lwz r4,GOT(__bss_end)
wdenk0442ed82002-11-03 10:24:00 +00001502
1503 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001504 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001505
1506 li r0, 0
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001507
1508 andi. r5, r4, 3
1509 beq 6f
1510 sub r4, r4, r5
1511 mtctr r5
1512 mr r5, r4
15135: stb r0, 0(r5)
1514 addi r5, r5, 1
1515 bdnz 5b
15166:
wdenk0442ed82002-11-03 10:24:00 +00001517 stw r0, 0(r3)
1518 addi r3, r3, 4
1519 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001520 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001521
Anatolij Gustschin720025b2007-12-05 17:43:20 +010015227:
wdenk0442ed82002-11-03 10:24:00 +00001523 mr r3, r9 /* Init Data pointer */
1524 mr r4, r10 /* Destination Address */
1525 bl board_init_r
1526
wdenk0442ed82002-11-03 10:24:00 +00001527 /*
1528 * Copy exception vector code to low memory
1529 *
1530 * r3: dest_addr
1531 * r7: source address, r8: end address, r9: target address
1532 */
1533 .globl trap_init
1534trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001535 mflr r4 /* save link register */
1536 GET_GOT
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001537 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001538 lwz r8, GOT(_end_of_vectors)
1539
wdenk4e112c12003-06-03 23:54:09 +00001540 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001541
1542 cmplw 0, r7, r8
1543 bgelr /* return if r7>=r8 - just in case */
wdenk0442ed82002-11-03 10:24:00 +000015441:
1545 lwz r0, 0(r7)
1546 stw r0, 0(r9)
1547 addi r7, r7, 4
1548 addi r9, r9, 4
1549 cmplw 0, r7, r8
1550 bne 1b
1551
1552 /*
1553 * relocate `hdlr' and `int_return' entries
1554 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001555 li r7, .L_MachineCheck - _start + _START_OFFSET
1556 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000015572:
1558 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001559 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001560 cmplw 0, r7, r8
1561 blt 2b
1562
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001563 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001564 bl trap_reloc
1565
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001566 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001567 bl trap_reloc
1568
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001569#ifdef CONFIG_440
1570 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001571 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001572
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001573 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001574 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001575
1576 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001577 bl trap_reloc
Stefan Roese80d99a42007-06-19 16:42:31 +02001578
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001579 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1580 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001581
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001582 li r7, .L_DataTLBError - _start + _START_OFFSET
1583 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001584#else /* CONFIG_440 */
1585 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001586 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001587
1588 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001589 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001590
1591 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001592 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001593#endif /* CONFIG_440 */
1594
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001595 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1596 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001597
Stefan Roese42fbddd2006-09-07 11:51:23 +02001598#if !defined(CONFIG_440)
Stefan Roese7b12aa82006-03-13 09:42:28 +01001599 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1600 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1601 mtmsr r7 /* change MSR */
1602#else
Stefan Roese42fbddd2006-09-07 11:51:23 +02001603 bl __440_msr_set
1604 b __440_msr_continue
Stefan Roese7b12aa82006-03-13 09:42:28 +01001605
Stefan Roese42fbddd2006-09-07 11:51:23 +02001606__440_msr_set:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001607 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1608 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001609 mtspr SPRN_SRR1,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001610 mflr r7
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001611 mtspr SPRN_SRR0,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001612 rfi
Stefan Roese42fbddd2006-09-07 11:51:23 +02001613__440_msr_continue:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001614#endif
1615
wdenk0442ed82002-11-03 10:24:00 +00001616 mtlr r4 /* restore link register */
1617 blr
Stefan Roese07038ad2013-04-02 10:37:04 +02001618#endif /* CONFIG_SPL_BUILD */
wdenk0442ed82002-11-03 10:24:00 +00001619
Stefan Roese42743512007-06-01 15:27:11 +02001620#if defined(CONFIG_440)
1621/*----------------------------------------------------------------------------+
1622| dcbz_area.
1623+----------------------------------------------------------------------------*/
1624 function_prolog(dcbz_area)
1625 rlwinm. r5,r4,0,27,31
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001626 rlwinm r5,r4,27,5,31
1627 beq ..d_ra2
1628 addi r5,r5,0x0001
1629..d_ra2:mtctr r5
1630..d_ag2:dcbz r0,r3
1631 addi r3,r3,32
1632 bdnz ..d_ag2
Stefan Roese42743512007-06-01 15:27:11 +02001633 sync
1634 blr
1635 function_epilog(dcbz_area)
Stefan Roese42743512007-06-01 15:27:11 +02001636#endif /* CONFIG_440 */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001637#endif /* CONFIG_NAND_SPL */
stroese434979e2003-05-23 11:18:02 +00001638
Stefan Roese42743512007-06-01 15:27:11 +02001639/*------------------------------------------------------------------------------- */
1640/* Function: in8 */
1641/* Description: Input 8 bits */
1642/*------------------------------------------------------------------------------- */
1643 .globl in8
1644in8:
1645 lbz r3,0x0000(r3)
1646 blr
1647
1648/*------------------------------------------------------------------------------- */
1649/* Function: out8 */
1650/* Description: Output 8 bits */
1651/*------------------------------------------------------------------------------- */
1652 .globl out8
1653out8:
1654 stb r4,0x0000(r3)
1655 blr
1656
1657/*------------------------------------------------------------------------------- */
1658/* Function: out32 */
1659/* Description: Output 32 bits */
1660/*------------------------------------------------------------------------------- */
1661 .globl out32
1662out32:
1663 stw r4,0x0000(r3)
1664 blr
1665
1666/*------------------------------------------------------------------------------- */
1667/* Function: in32 */
1668/* Description: Input 32 bits */
1669/*------------------------------------------------------------------------------- */
1670 .globl in32
1671in32:
1672 lwz 3,0x0000(3)
1673 blr
stroese434979e2003-05-23 11:18:02 +00001674
1675/**************************************************************************/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001676/* PPC405EP specific stuff */
stroese434979e2003-05-23 11:18:02 +00001677/**************************************************************************/
1678#ifdef CONFIG_405EP
1679ppc405ep_init:
stroese5ad6d4d2003-12-09 14:54:43 +00001680
Stefan Roese326c9712005-08-01 16:41:48 +02001681#ifdef CONFIG_BUBINGA
stroese5ad6d4d2003-12-09 14:54:43 +00001682 /*
1683 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1684 * function) to support FPGA and NVRAM accesses below.
1685 */
1686
1687 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1688 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001689 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1690 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001691 stw r4,0(r3)
1692 lis r3,GPIO0_OSRL@h
1693 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001694 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1695 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001696 stw r4,0(r3)
1697
1698 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1699 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001700 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1701 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroese5ad6d4d2003-12-09 14:54:43 +00001702 stw r4,0(r3)
1703 lis r3,GPIO0_ISR1L@h
1704 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001705 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1706 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroese5ad6d4d2003-12-09 14:54:43 +00001707 stw r4,0(r3)
1708
1709 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1710 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001711 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1712 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001713 stw r4,0(r3)
1714 lis r3,GPIO0_TSRL@h
1715 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001716 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1717 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001718 stw r4,0(r3)
1719
1720 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1721 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001722 lis r4,CONFIG_SYS_GPIO0_TCR@h
1723 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001724 stw r4,0(r3)
1725
Stefan Roese918010a2009-09-09 16:25:29 +02001726 li r3,PB1AP /* program EBC bank 1 for RTC access */
1727 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001728 lis r3,CONFIG_SYS_EBC_PB1AP@h
1729 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001730 mtdcr EBC0_CFGDATA,r3
1731 li r3,PB1CR
1732 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001733 lis r3,CONFIG_SYS_EBC_PB1CR@h
1734 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001735 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001736
Stefan Roese918010a2009-09-09 16:25:29 +02001737 li r3,PB1AP /* program EBC bank 1 for RTC access */
1738 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001739 lis r3,CONFIG_SYS_EBC_PB1AP@h
1740 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001741 mtdcr EBC0_CFGDATA,r3
1742 li r3,PB1CR
1743 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001744 lis r3,CONFIG_SYS_EBC_PB1CR@h
1745 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001746 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001747
Stefan Roese918010a2009-09-09 16:25:29 +02001748 li r3,PB4AP /* program EBC bank 4 for FPGA access */
1749 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001750 lis r3,CONFIG_SYS_EBC_PB4AP@h
1751 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001752 mtdcr EBC0_CFGDATA,r3
1753 li r3,PB4CR
1754 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001755 lis r3,CONFIG_SYS_EBC_PB4CR@h
1756 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001757 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001758#endif
stroese434979e2003-05-23 11:18:02 +00001759
wdenk57b2d802003-06-27 21:31:46 +00001760 /*
1761 !-----------------------------------------------------------------------
1762 ! Check to see if chip is in bypass mode.
1763 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1764 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001765 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1766 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk57b2d802003-06-27 21:31:46 +00001767 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001768 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001769 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001770 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001771 cmpi cr0,0,r4,0x1
stroese434979e2003-05-23 11:18:02 +00001772
Wolfgang Denka1be4762008-05-20 16:00:29 +02001773 beq pll_done /* if SSCS =b'1' then PLL has */
1774 /* already been set */
1775 /* and CPU has been reset */
1776 /* so skip to next section */
stroese434979e2003-05-23 11:18:02 +00001777
Stefan Roese326c9712005-08-01 16:41:48 +02001778#ifdef CONFIG_BUBINGA
stroese434979e2003-05-23 11:18:02 +00001779 /*
wdenk57b2d802003-06-27 21:31:46 +00001780 !-----------------------------------------------------------------------
1781 ! Read NVRAM to get value to write in PLLMR.
1782 ! If value has not been correctly saved, write default value
1783 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1784 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1785 !
1786 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001787 ! structure in openbios.h. Changing the beginning of
1788 ! the structure will break this code.
wdenk57b2d802003-06-27 21:31:46 +00001789 !
1790 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001791 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001792 addis r3,0,NVRAM_BASE@h
1793 addi r3,r3,NVRAM_BASE@l
stroese434979e2003-05-23 11:18:02 +00001794
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001795 lwz r4, 0(r3)
1796 addis r5,0,NVRVFY1@h
1797 addi r5,r5,NVRVFY1@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001798 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001799 bne ..no_pllset
1800 addi r3,r3,4
1801 lwz r4, 0(r3)
1802 addis r5,0,NVRVFY2@h
1803 addi r5,r5,NVRVFY2@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001804 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001805 bne ..no_pllset
1806 addi r3,r3,8 /* Skip over conf_size */
1807 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1808 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1809 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1810 cmpi cr0,0,r5,1 /* See if PLL is locked */
1811 beq pll_write
stroese434979e2003-05-23 11:18:02 +00001812..no_pllset:
Stefan Roese326c9712005-08-01 16:41:48 +02001813#endif /* CONFIG_BUBINGA */
stroese434979e2003-05-23 11:18:02 +00001814
John Otken9aa36772007-07-26 17:49:11 +02001815#ifdef CONFIG_TAIHU
1816 mfdcr r4, CPC0_BOOT
1817 andi. r5, r4, CPC0_BOOT_SEP@l
1818 bne strap_1 /* serial eeprom present */
1819 addis r5,0,CPLD_REG0_ADDR@h
1820 ori r5,r5,CPLD_REG0_ADDR@l
1821 andi. r5, r5, 0x10
1822 bne _pci_66mhz
1823#endif /* CONFIG_TAIHU */
1824
Stefan Roesea5d182e2007-08-14 14:44:41 +02001825#if defined(CONFIG_ZEUS)
1826 mfdcr r4, CPC0_BOOT
1827 andi. r5, r4, CPC0_BOOT_SEP@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001828 bne strap_1 /* serial eeprom present */
Stefan Roesea5d182e2007-08-14 14:44:41 +02001829 lis r3,0x0000
1830 addi r3,r3,0x3030
1831 lis r4,0x8042
1832 addi r4,r4,0x223e
1833 b 1f
1834strap_1:
1835 mfdcr r3, CPC0_PLLMR0
1836 mfdcr r4, CPC0_PLLMR1
1837 b 1f
1838#endif
1839
Wolfgang Denka1be4762008-05-20 16:00:29 +02001840 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1841 ori r3,r3,PLLMR0_DEFAULT@l /* */
1842 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1843 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroese434979e2003-05-23 11:18:02 +00001844
John Otken9aa36772007-07-26 17:49:11 +02001845#ifdef CONFIG_TAIHU
1846 b 1f
1847_pci_66mhz:
1848 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1849 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1850 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1851 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1852 b 1f
1853strap_1:
1854 mfdcr r3, CPC0_PLLMR0
1855 mfdcr r4, CPC0_PLLMR1
John Otken9aa36772007-07-26 17:49:11 +02001856#endif /* CONFIG_TAIHU */
1857
Stefan Roesea5d182e2007-08-14 14:44:41 +020018581:
Wolfgang Denka1be4762008-05-20 16:00:29 +02001859 b pll_write /* Write the CPC0_PLLMR with new value */
stroese434979e2003-05-23 11:18:02 +00001860
1861pll_done:
wdenk57b2d802003-06-27 21:31:46 +00001862 /*
1863 !-----------------------------------------------------------------------
1864 ! Clear Soft Reset Register
1865 ! This is needed to enable PCI if not booting from serial EPROM
1866 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001867 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001868 addi r3, 0, 0x0
1869 mtdcr CPC0_SRR, r3
stroese434979e2003-05-23 11:18:02 +00001870
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001871 addis r3,0,0x0010
1872 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001873pci_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001874 bdnz pci_wait
stroese434979e2003-05-23 11:18:02 +00001875
Wolfgang Denka1be4762008-05-20 16:00:29 +02001876 blr /* return to main code */
stroese434979e2003-05-23 11:18:02 +00001877
1878/*
1879!-----------------------------------------------------------------------------
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001880! Function: pll_write
1881! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1882! That is:
1883! 1. Pll is first disabled (de-activated by putting in bypass mode)
1884! 2. PLL is reset
1885! 3. Clock dividers are set while PLL is held in reset and bypassed
1886! 4. PLL Reset is cleared
1887! 5. Wait 100us for PLL to lock
1888! 6. A core reset is performed
stroese434979e2003-05-23 11:18:02 +00001889! Input: r3 = Value to write to CPC0_PLLMR0
1890! Input: r4 = Value to write to CPC0_PLLMR1
1891! Output r3 = none
1892!-----------------------------------------------------------------------------
1893*/
Matthias Fuchsd8079162009-07-06 16:27:33 +02001894 .globl pll_write
stroese434979e2003-05-23 11:18:02 +00001895pll_write:
wdenk57b2d802003-06-27 21:31:46 +00001896 mfdcr r5, CPC0_UCR
1897 andis. r5,r5,0xFFFF
Wolfgang Denka1be4762008-05-20 16:00:29 +02001898 ori r5,r5,0x0101 /* Stop the UART clocks */
1899 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroese434979e2003-05-23 11:18:02 +00001900
wdenk57b2d802003-06-27 21:31:46 +00001901 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001902 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001903 mtdcr CPC0_PLLMR1,r5
Wolfgang Denka1be4762008-05-20 16:00:29 +02001904 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001905 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001906
Wolfgang Denka1be4762008-05-20 16:00:29 +02001907 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
1908 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
1909 oris r5,r5,0x4000 /* Set PLL Reset */
1910 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
1911 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001912 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001913
1914 /*
wdenk57b2d802003-06-27 21:31:46 +00001915 ! Wait min of 100us for PLL to lock.
1916 ! See CMOS 27E databook for more info.
1917 ! At 200MHz, that means waiting 20,000 instructions
stroese434979e2003-05-23 11:18:02 +00001918 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001919 addi r3,0,20000 /* 2000 = 0x4e20 */
1920 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001921pll_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001922 bdnz pll_wait
stroese434979e2003-05-23 11:18:02 +00001923
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001924 oris r5,r5,0x8000 /* Enable PLL */
1925 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroese434979e2003-05-23 11:18:02 +00001926
wdenk57b2d802003-06-27 21:31:46 +00001927 /*
1928 * Reset CPU to guarantee timings are OK
1929 * Not sure if this is needed...
1930 */
1931 addis r3,0,0x1000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001932 mtspr SPRN_DBCR0,r3 /* This will cause a CPU core reset, and */
Wolfgang Denka1be4762008-05-20 16:00:29 +02001933 /* execution will continue from the poweron */
1934 /* vector of 0xfffffffc */
stroese434979e2003-05-23 11:18:02 +00001935#endif /* CONFIG_405EP */
Stefan Roesea8856e32007-02-20 10:57:08 +01001936
1937#if defined(CONFIG_440)
Stefan Roesea8856e32007-02-20 10:57:08 +01001938/*----------------------------------------------------------------------------+
1939| mttlb3.
1940+----------------------------------------------------------------------------*/
1941 function_prolog(mttlb3)
1942 TLBWE(4,3,2)
1943 blr
1944 function_epilog(mttlb3)
1945
1946/*----------------------------------------------------------------------------+
1947| mftlb3.
1948+----------------------------------------------------------------------------*/
1949 function_prolog(mftlb3)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001950 TLBRE(3,3,2)
Stefan Roesea8856e32007-02-20 10:57:08 +01001951 blr
1952 function_epilog(mftlb3)
1953
1954/*----------------------------------------------------------------------------+
1955| mttlb2.
1956+----------------------------------------------------------------------------*/
1957 function_prolog(mttlb2)
1958 TLBWE(4,3,1)
1959 blr
1960 function_epilog(mttlb2)
1961
1962/*----------------------------------------------------------------------------+
1963| mftlb2.
1964+----------------------------------------------------------------------------*/
1965 function_prolog(mftlb2)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001966 TLBRE(3,3,1)
Stefan Roesea8856e32007-02-20 10:57:08 +01001967 blr
1968 function_epilog(mftlb2)
1969
1970/*----------------------------------------------------------------------------+
1971| mttlb1.
1972+----------------------------------------------------------------------------*/
1973 function_prolog(mttlb1)
1974 TLBWE(4,3,0)
1975 blr
1976 function_epilog(mttlb1)
1977
1978/*----------------------------------------------------------------------------+
1979| mftlb1.
1980+----------------------------------------------------------------------------*/
1981 function_prolog(mftlb1)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001982 TLBRE(3,3,0)
Stefan Roesea8856e32007-02-20 10:57:08 +01001983 blr
1984 function_epilog(mftlb1)
1985#endif /* CONFIG_440 */
Stefan Roese7d72e022008-06-02 14:35:44 +02001986
1987#if defined(CONFIG_NAND_SPL)
1988/*
1989 * void nand_boot_relocate(dst, src, bytes)
1990 *
1991 * r3 = Destination address to copy code to (in SDRAM)
1992 * r4 = Source address to copy code from
1993 * r5 = size to copy in bytes
1994 */
1995nand_boot_relocate:
1996 mr r6,r3
1997 mr r7,r4
1998 mflr r8
1999
2000 /*
2001 * Copy SPL from icache into SDRAM
2002 */
2003 subi r3,r3,4
2004 subi r4,r4,4
2005 srwi r5,r5,2
2006 mtctr r5
2007..spl_loop:
2008 lwzu r0,4(r4)
2009 stwu r0,4(r3)
2010 bdnz ..spl_loop
2011
2012 /*
2013 * Calculate "corrected" link register, so that we "continue"
2014 * in execution in destination range
2015 */
2016 sub r3,r7,r6 /* r3 = src - dst */
2017 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2018 mtlr r8
2019 blr
2020
2021nand_boot_common:
2022 /*
2023 * First initialize SDRAM. It has to be available *before* calling
2024 * nand_boot().
2025 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002026 lis r3,CONFIG_SYS_SDRAM_BASE@h
2027 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002028 bl initdram
2029
2030 /*
2031 * Now copy the 4k SPL code into SDRAM and continue execution
2032 * from there.
2033 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002034 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2035 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2036 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2037 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2038 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2039 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002040 bl nand_boot_relocate
2041
2042 /*
2043 * We're running from SDRAM now!!!
2044 *
2045 * It is necessary for 4xx systems to relocate from running at
2046 * the original location (0xfffffxxx) to somewhere else (SDRAM
2047 * preferably). This is because CS0 needs to be reconfigured for
2048 * NAND access. And we can't reconfigure this CS when currently
2049 * "running" from it.
2050 */
2051
2052 /*
2053 * Finally call nand_boot() to load main NAND U-Boot image from
2054 * NAND and jump to it.
2055 */
2056 bl nand_boot /* will not return */
2057#endif /* CONFIG_NAND_SPL */