blob: e72c37c75ba011fb4ca76ba3c9312cf099c7ed96 [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
wdenk0442ed82002-11-03 10:24:00 +000034#include <ppc_asm.tmpl>
35#include <ppc_defs.h>
36
37#include <asm/cache.h>
38#include <asm/mmu.h>
Dave Mitchell3c3734172008-11-20 14:00:49 -060039#include <asm/ppc4xx-isram.h>
wdenk0442ed82002-11-03 10:24:00 +000040
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041#ifdef CONFIG_SYS_INIT_DCACHE_CS
42# if (CONFIG_SYS_INIT_DCACHE_CS == 0)
Stefan Roese918010a2009-09-09 16:25:29 +020043# define PBxAP PB1AP
44# define PBxCR PB0CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045# if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
46# define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
47# define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
Grant Ericksonb6933412008-05-22 14:44:14 -070048# endif
wdenk0442ed82002-11-03 10:24:00 +000049# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050# if (CONFIG_SYS_INIT_DCACHE_CS == 1)
Stefan Roese918010a2009-09-09 16:25:29 +020051# define PBxAP PB1AP
52# define PBxCR PB1CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053# if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
54# define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
55# define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
Grant Ericksonb6933412008-05-22 14:44:14 -070056# endif
wdenk0442ed82002-11-03 10:24:00 +000057# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058# if (CONFIG_SYS_INIT_DCACHE_CS == 2)
Stefan Roese918010a2009-09-09 16:25:29 +020059# define PBxAP PB2AP
60# define PBxCR PB2CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061# if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
62# define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
63# define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
Grant Ericksonb6933412008-05-22 14:44:14 -070064# endif
wdenk0442ed82002-11-03 10:24:00 +000065# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066# if (CONFIG_SYS_INIT_DCACHE_CS == 3)
Stefan Roese918010a2009-09-09 16:25:29 +020067# define PBxAP PB3AP
68# define PBxCR PB3CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069# if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
70# define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
71# define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
Grant Ericksonb6933412008-05-22 14:44:14 -070072# endif
wdenk0442ed82002-11-03 10:24:00 +000073# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074# if (CONFIG_SYS_INIT_DCACHE_CS == 4)
Stefan Roese918010a2009-09-09 16:25:29 +020075# define PBxAP PB4AP
76# define PBxCR PB4CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077# if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
78# define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
79# define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
Grant Ericksonb6933412008-05-22 14:44:14 -070080# endif
wdenk0442ed82002-11-03 10:24:00 +000081# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082# if (CONFIG_SYS_INIT_DCACHE_CS == 5)
Stefan Roese918010a2009-09-09 16:25:29 +020083# define PBxAP PB5AP
84# define PBxCR PB5CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085# if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
86# define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
87# define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
Grant Ericksonb6933412008-05-22 14:44:14 -070088# endif
wdenk0442ed82002-11-03 10:24:00 +000089# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090# if (CONFIG_SYS_INIT_DCACHE_CS == 6)
Stefan Roese918010a2009-09-09 16:25:29 +020091# define PBxAP PB6AP
92# define PBxCR PB6CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093# if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
94# define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
95# define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
Grant Ericksonb6933412008-05-22 14:44:14 -070096# endif
wdenk0442ed82002-11-03 10:24:00 +000097# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098# if (CONFIG_SYS_INIT_DCACHE_CS == 7)
Stefan Roese918010a2009-09-09 16:25:29 +020099# define PBxAP PB7AP
100# define PBxCR PB7CR
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101# if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
102# define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
103# define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700104# endif
105# endif
106# ifndef PBxAP_VAL
107# define PBxAP_VAL 0
108# endif
109# ifndef PBxCR_VAL
110# define PBxCR_VAL 0
111# endif
112/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200113 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
Grant Ericksonb6933412008-05-22 14:44:14 -0700114 * used as temporary stack pointer for the primordial stack
115 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116# ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
117# define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700118 EBC_BXAP_TWT_ENCODE(7) | \
119 EBC_BXAP_BCE_DISABLE | \
120 EBC_BXAP_BCT_2TRANS | \
121 EBC_BXAP_CSN_ENCODE(0) | \
122 EBC_BXAP_OEN_ENCODE(0) | \
123 EBC_BXAP_WBN_ENCODE(0) | \
124 EBC_BXAP_WBF_ENCODE(0) | \
125 EBC_BXAP_TH_ENCODE(2) | \
126 EBC_BXAP_RE_DISABLED | \
127 EBC_BXAP_SOR_NONDELAYED | \
128 EBC_BXAP_BEM_WRITEONLY | \
129 EBC_BXAP_PEN_DISABLED)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130# endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
131# ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
132# define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700133 EBC_BXCR_BS_64MB | \
134 EBC_BXCR_BU_RW | \
135 EBC_BXCR_BW_16BIT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136# endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
137# ifndef CONFIG_SYS_INIT_RAM_PATTERN
138# define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
wdenk0442ed82002-11-03 10:24:00 +0000139# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +0000141
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200142#if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_SIZE > (4 << 10)))
143#error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_SIZE!
Stefan Roese0fb8ab92008-01-30 14:48:28 +0100144#endif
145
Grant Ericksonb6933412008-05-22 14:44:14 -0700146/*
147 * Unless otherwise overriden, enable two 128MB cachable instruction regions
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
149 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
Grant Ericksonb6933412008-05-22 14:44:14 -0700150 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151#if !defined(CONFIG_SYS_FLASH_BASE)
Stefan Roese7d72e022008-06-02 14:35:44 +0200152/* If not already defined, set it to the "last" 128MByte region */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153# define CONFIG_SYS_FLASH_BASE 0xf8000000
Stefan Roese7d72e022008-06-02 14:35:44 +0200154#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200155#if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
156# define CONFIG_SYS_ICACHE_SACR_VALUE \
157 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
158 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
159 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
160#endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700161
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162#if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
163# define CONFIG_SYS_DCACHE_SACR_VALUE \
Grant Ericksonb6933412008-05-22 14:44:14 -0700164 (0x00000000)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165#endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700166
Stefan Roese1d568062010-05-27 16:45:20 +0200167#if !defined(CONFIG_SYS_TLB_FOR_BOOT_FLASH)
168#define CONFIG_SYS_TLB_FOR_BOOT_FLASH 0 /* use TLB 0 as default */
169#endif
170
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200171#define function_prolog(func_name) .text; \
Stefan Roese42743512007-06-01 15:27:11 +0200172 .align 2; \
173 .globl func_name; \
174 func_name:
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200175#define function_epilog(func_name) .type func_name,@function; \
Stefan Roese42743512007-06-01 15:27:11 +0200176 .size func_name,.-func_name
177
wdenk0442ed82002-11-03 10:24:00 +0000178/* We don't want the MMU yet.
179*/
180#undef MSR_KERNEL
181#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
182
183
184 .extern ext_bus_cntlr_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200185#ifdef CONFIG_NAND_U_BOOT
186 .extern reconfig_tlb0
187#endif
wdenk0442ed82002-11-03 10:24:00 +0000188
189/*
190 * Set up GOT: Global Offset Table
191 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100192 * Use r12 to access the GOT
wdenk0442ed82002-11-03 10:24:00 +0000193 */
Stefan Roese07038ad2013-04-02 10:37:04 +0200194#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000195 START_GOT
196 GOT_ENTRY(_GOT2_TABLE_)
197 GOT_ENTRY(_FIXUP_TABLE_)
198
199 GOT_ENTRY(_start)
200 GOT_ENTRY(_start_of_vectors)
201 GOT_ENTRY(_end_of_vectors)
202 GOT_ENTRY(transfer_to_handler)
203
wdenkb9a83a92003-05-30 12:48:29 +0000204 GOT_ENTRY(__init_end)
Simon Glassed70c8f2013-03-14 06:54:53 +0000205 GOT_ENTRY(__bss_end)
wdenkbf2f8c92003-05-22 22:52:13 +0000206 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000207 END_GOT
Stefan Roese42fbddd2006-09-07 11:51:23 +0200208#endif /* CONFIG_NAND_SPL */
209
Stefan Roese07038ad2013-04-02 10:37:04 +0200210#if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL) && \
211 !defined(CONFIG_SPL_BUILD)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200212 /*
213 * NAND U-Boot image is started from offset 0
214 */
215 .text
Stefan Roese23d8d342007-06-06 11:42:13 +0200216#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200217 bl reconfig_tlb0
Stefan Roese23d8d342007-06-06 11:42:13 +0200218#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200219 GET_GOT
220 bl cpu_init_f /* run low-level CPU init code (from Flash) */
221 bl board_init_f
Peter Tyser0c44caf2010-09-14 19:13:53 -0500222 /* NOTREACHED - board_init_f() does not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200223#endif
wdenk0442ed82002-11-03 10:24:00 +0000224
Ricardo Ribalda Delgadob3843812010-12-07 14:27:56 +0100225#if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_BOOT_FROM_XMD)
Stefan Roesec20ef322009-05-11 13:46:14 +0200226 /*
227 * 4xx RAM-booting U-Boot image is started from offset 0
228 */
229 .text
230 bl _start_440
231#endif
232
Stefan Roese07038ad2013-04-02 10:37:04 +0200233#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
234 /*
235 * This is the entry of the real U-Boot from a board port
236 * that supports SPL booting on the PPC4xx. We only need
237 * to call board_init_f() here. Everything else has already
238 * been done in the SPL u-boot version.
239 */
240 GET_GOT /* initialize GOT access */
241 bl board_init_f /* run 1st part of board init code (in Flash)*/
242 /* NOTREACHED - board_init_f() does not return */
243#endif
244
wdenk0442ed82002-11-03 10:24:00 +0000245/*
246 * 440 Startup -- on reset only the top 4k of the effective
247 * address space is mapped in by an entry in the instruction
248 * and data shadow TLB. The .bootpg section is located in the
249 * top 4k & does only what's necessary to map in the the rest
250 * of the boot rom. Once the boot rom is mapped in we can
251 * proceed with normal startup.
252 *
253 * NOTE: CS0 only covers the top 2MB of the effective address
254 * space after reset.
255 */
256
257#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200258#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000259 .section .bootpg,"ax"
Stefan Roese42fbddd2006-09-07 11:51:23 +0200260#endif
wdenk0442ed82002-11-03 10:24:00 +0000261 .globl _start_440
262
263/**************************************************************************/
264_start_440:
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200265 /*--------------------------------------------------------------------+
266 | 440EPX BUP Change - Hardware team request
267 +--------------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200268#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
269 sync
270 nop
271 nop
272#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200273 /*----------------------------------------------------------------+
274 | Core bug fix. Clear the esr
275 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200276 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200277 mtspr SPRN_ESR,r0
wdenk0442ed82002-11-03 10:24:00 +0000278 /*----------------------------------------------------------------*/
279 /* Clear and set up some registers. */
280 /*----------------------------------------------------------------*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200281 iccci r0,r0 /* NOTE: operands not used for 440 */
282 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000283 sync
284 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200285 mtspr SPRN_SRR0,r0
286 mtspr SPRN_SRR1,r0
287 mtspr SPRN_CSRR0,r0
288 mtspr SPRN_CSRR1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200289 /* NOTE: 440GX adds machine check status regs */
290#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200291 mtspr SPRN_MCSRR0,r0
292 mtspr SPRN_MCSRR1,r0
293 mfspr r1,SPRN_MCSR
294 mtspr SPRN_MCSR,r1
wdenk544e9732004-02-06 23:19:44 +0000295#endif
Stefan Roese0100cc12006-11-22 13:20:50 +0100296
297 /*----------------------------------------------------------------*/
298 /* CCR0 init */
299 /*----------------------------------------------------------------*/
300 /* Disable store gathering & broadcast, guarantee inst/data
301 * cache block touch, force load/store alignment
302 * (see errata 1.12: 440_33)
303 */
304 lis r1,0x0030 /* store gathering & broadcast disable */
305 ori r1,r1,0x6000 /* cache touch */
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200306 mtspr SPRN_CCR0,r1
Stefan Roese0100cc12006-11-22 13:20:50 +0100307
wdenk0442ed82002-11-03 10:24:00 +0000308 /*----------------------------------------------------------------*/
309 /* Initialize debug */
310 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200311 mfspr r1,SPRN_DBCR0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200312 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
313 bne skip_debug_init /* if set, don't clear debug register */
Victor Gallardob52cde92010-09-16 11:32:04 -0700314 mfspr r1,SPRN_CCR0
315 ori r1,r1,CCR0_DTB@l /* Disable Trace Broadcast */
316 mtspr SPRN_CCR0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200317 mtspr SPRN_DBCR0,r0
318 mtspr SPRN_DBCR1,r0
319 mtspr SPRN_DBCR2,r0
320 mtspr SPRN_IAC1,r0
321 mtspr SPRN_IAC2,r0
322 mtspr SPRN_IAC3,r0
323 mtspr SPRN_DAC1,r0
324 mtspr SPRN_DAC2,r0
325 mtspr SPRN_DVC1,r0
326 mtspr SPRN_DVC2,r0
wdenk0442ed82002-11-03 10:24:00 +0000327
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200328 mfspr r1,SPRN_DBSR
329 mtspr SPRN_DBSR,r1 /* Clear all valid bits */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200330skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000331
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200332#if defined (CONFIG_440SPE)
333 /*----------------------------------------------------------------+
334 | Initialize Core Configuration Reg1.
335 | a. ICDPEI: Record even parity. Normal operation.
336 | b. ICTPEI: Record even parity. Normal operation.
337 | c. DCTPEI: Record even parity. Normal operation.
338 | d. DCDPEI: Record even parity. Normal operation.
339 | e. DCUPEI: Record even parity. Normal operation.
340 | f. DCMPEI: Record even parity. Normal operation.
341 | g. FCOM: Normal operation
342 | h. MMUPEI: Record even parity. Normal operation.
343 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200344 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200345 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200346 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200347 mtspr SPRN_CCR1, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200348
349 /*----------------------------------------------------------------+
350 | Reset the timebase.
351 | The previous write to CCR1 sets the timebase source.
352 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200353 mtspr SPRN_TBWL, r0
354 mtspr SPRN_TBWU, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200355#endif
356
wdenk0442ed82002-11-03 10:24:00 +0000357 /*----------------------------------------------------------------*/
358 /* Setup interrupt vectors */
359 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200360 mtspr SPRN_IVPR,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200361 li r1,0x0100
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200362 mtspr SPRN_IVOR0,r1 /* Critical input */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200363 li r1,0x0200
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200364 mtspr SPRN_IVOR1,r1 /* Machine check */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200365 li r1,0x0300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200366 mtspr SPRN_IVOR2,r1 /* Data storage */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200367 li r1,0x0400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200368 mtspr SPRN_IVOR3,r1 /* Instruction storage */
wdenk0442ed82002-11-03 10:24:00 +0000369 li r1,0x0500
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200370 mtspr SPRN_IVOR4,r1 /* External interrupt */
wdenk0442ed82002-11-03 10:24:00 +0000371 li r1,0x0600
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200372 mtspr SPRN_IVOR5,r1 /* Alignment */
wdenk0442ed82002-11-03 10:24:00 +0000373 li r1,0x0700
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200374 mtspr SPRN_IVOR6,r1 /* Program check */
wdenk0442ed82002-11-03 10:24:00 +0000375 li r1,0x0800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200376 mtspr SPRN_IVOR7,r1 /* Floating point unavailable */
wdenk0442ed82002-11-03 10:24:00 +0000377 li r1,0x0c00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200378 mtspr SPRN_IVOR8,r1 /* System call */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200379 li r1,0x0a00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200380 mtspr SPRN_IVOR9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200381 li r1,0x0900
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200382 mtspr SPRN_IVOR10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000383 li r1,0x1300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200384 mtspr SPRN_IVOR13,r1 /* Data TLB error */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200385 li r1,0x1400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200386 mtspr SPRN_IVOR14,r1 /* Instr TLB error */
wdenk0442ed82002-11-03 10:24:00 +0000387 li r1,0x2000
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200388 mtspr SPRN_IVOR15,r1 /* Debug */
wdenk0442ed82002-11-03 10:24:00 +0000389
390 /*----------------------------------------------------------------*/
391 /* Configure cache regions */
392 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200393 mtspr SPRN_INV0,r0
394 mtspr SPRN_INV1,r0
395 mtspr SPRN_INV2,r0
396 mtspr SPRN_INV3,r0
397 mtspr SPRN_DNV0,r0
398 mtspr SPRN_DNV1,r0
399 mtspr SPRN_DNV2,r0
400 mtspr SPRN_DNV3,r0
401 mtspr SPRN_ITV0,r0
402 mtspr SPRN_ITV1,r0
403 mtspr SPRN_ITV2,r0
404 mtspr SPRN_ITV3,r0
405 mtspr SPRN_DTV0,r0
406 mtspr SPRN_DTV1,r0
407 mtspr SPRN_DTV2,r0
408 mtspr SPRN_DTV3,r0
wdenk0442ed82002-11-03 10:24:00 +0000409
410 /*----------------------------------------------------------------*/
411 /* Cache victim limits */
412 /*----------------------------------------------------------------*/
413 /* floors 0, ceiling max to use the entire cache -- nothing locked
414 */
415 lis r1,0x0001
416 ori r1,r1,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200417 mtspr SPRN_IVLIM,r1
418 mtspr SPRN_DVLIM,r1
wdenk0442ed82002-11-03 10:24:00 +0000419
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200420 /*----------------------------------------------------------------+
421 |Initialize MMUCR[STID] = 0.
422 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200423 mfspr r0,SPRN_MMUCR
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200424 addis r1,0,0xFFFF
425 ori r1,r1,0xFF00
426 and r0,r0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200427 mtspr SPRN_MMUCR,r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200428
wdenk0442ed82002-11-03 10:24:00 +0000429 /*----------------------------------------------------------------*/
430 /* Clear all TLB entries -- TID = 0, TS = 0 */
431 /*----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200432 addis r0,0,0x0000
Stefan Roesed0c43952009-07-14 15:53:08 +0200433#ifdef CONFIG_SYS_RAMBOOT
Stefan Roesec20ef322009-05-11 13:46:14 +0200434 li r4,0 /* Start with TLB #0 */
Stefan Roesed0c43952009-07-14 15:53:08 +0200435#else
436 li r4,1 /* Start with TLB #1 */
437#endif
438 li r1,64 /* 64 TLB entries */
439 sub r1,r1,r4 /* calculate last TLB # */
440 mtctr r1
Stefan Roesec20ef322009-05-11 13:46:14 +0200441rsttlb:
442#ifdef CONFIG_SYS_RAMBOOT
443 tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
444 rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
445 beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
446#endif
447 tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
448 tlbwe r0,r4,1
449 tlbwe r0,r4,2
450tlbnxt: addi r4,r4,1 /* Next TLB */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200451 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000452
453 /*----------------------------------------------------------------*/
454 /* TLB entry setup -- step thru tlbtab */
455 /*----------------------------------------------------------------*/
Stefan Roese97251f92010-04-09 14:03:59 +0200456#if defined(CONFIG_440SPE_REVA)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200457 /*----------------------------------------------------------------*/
458 /* We have different TLB tables for revA and rev B of 440SPe */
459 /*----------------------------------------------------------------*/
460 mfspr r1, PVR
461 lis r0,0x5342
462 ori r0,r0,0x1891
463 cmpw r7,r1,r0
464 bne r7,..revA
465 bl tlbtabB
466 b ..goon
467..revA:
468 bl tlbtabA
469..goon:
470#else
wdenk0442ed82002-11-03 10:24:00 +0000471 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200472#endif
wdenk0442ed82002-11-03 10:24:00 +0000473 mr r5,r0
474 li r1,0x003f /* 64 TLB entries max */
475 mtctr r1
476 li r4,0 /* TLB # */
477
478 addi r5,r5,-4
Stefan Roesec20ef322009-05-11 13:46:14 +02004791:
480#ifdef CONFIG_SYS_RAMBOOT
481 tlbre r3,r4,0 /* Read contents from TLB word #0 */
482 rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
483 bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
484#endif
485 lwzu r0,4(r5)
wdenk0442ed82002-11-03 10:24:00 +0000486 cmpwi r0,0
487 beq 2f /* 0 marks end */
488 lwzu r1,4(r5)
489 lwzu r2,4(r5)
490 tlbwe r0,r4,0 /* TLB Word 0 */
491 tlbwe r1,r4,1 /* TLB Word 1 */
492 tlbwe r2,r4,2 /* TLB Word 2 */
Stefan Roesec20ef322009-05-11 13:46:14 +0200493tlbnx2: addi r4,r4,1 /* Next TLB */
wdenk0442ed82002-11-03 10:24:00 +0000494 bdnz 1b
495
496 /*----------------------------------------------------------------*/
497 /* Continue from 'normal' start */
498 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +02004992:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200500 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000501 b _start
502
5033: li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200504 mtspr SPRN_SRR1,r0 /* Keep things disabled for now */
wdenk0442ed82002-11-03 10:24:00 +0000505 mflr r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200506 mtspr SPRN_SRR0,r1
wdenk0442ed82002-11-03 10:24:00 +0000507 rfi
stroese434979e2003-05-23 11:18:02 +0000508#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000509
510/*
511 * r3 - 1st arg to board_init(): IMMP pointer
512 * r4 - 2nd arg to board_init(): boot flag
513 */
Stefan Roese07038ad2013-04-02 10:37:04 +0200514#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000515 .text
516 .long 0x27051956 /* U-Boot Magic Number */
517 .globl version_string
518version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +0200519 .ascii U_BOOT_VERSION_STRING, "\0"
wdenk0442ed82002-11-03 10:24:00 +0000520
wdenk0442ed82002-11-03 10:24:00 +0000521 . = EXC_OFF_SYS_RESET
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200522 .globl _start_of_vectors
523_start_of_vectors:
524
525/* Critical input. */
526 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
527
528#ifdef CONFIG_440
529/* Machine check */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200530 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200531#else
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200532 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200533#endif /* CONFIG_440 */
534
535/* Data Storage exception. */
536 STD_EXCEPTION(0x300, DataStorage, UnknownException)
537
538/* Instruction Storage exception. */
539 STD_EXCEPTION(0x400, InstStorage, UnknownException)
540
541/* External Interrupt exception. */
542 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
543
544/* Alignment exception. */
545 . = 0x600
546Alignment:
547 EXCEPTION_PROLOG(SRR0, SRR1)
548 mfspr r4,DAR
549 stw r4,_DAR(r21)
550 mfspr r5,DSISR
551 stw r5,_DSISR(r21)
552 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100553 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200554
555/* Program check exception */
556 . = 0x700
557ProgramCheck:
558 EXCEPTION_PROLOG(SRR0, SRR1)
559 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100560 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
561 MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200562
563#ifdef CONFIG_440
564 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
565 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
566 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roese80d99a42007-06-19 16:42:31 +0200567#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200568 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
569
570#ifdef CONFIG_440
571 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
572 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
573#else
574 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
575 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
576 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
577#endif
578 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
579
580 .globl _end_of_vectors
581_end_of_vectors:
582 . = _START_OFFSET
Stefan Roese42fbddd2006-09-07 11:51:23 +0200583#endif
wdenk0442ed82002-11-03 10:24:00 +0000584 .globl _start
585_start:
586
Stefan Roese07038ad2013-04-02 10:37:04 +0200587#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
588 /*
589 * This is the entry of the real U-Boot from a board port
590 * that supports SPL booting on the PPC4xx. We only need
591 * to call board_init_f() here. Everything else has already
592 * been done in the SPL u-boot version.
593 */
594 GET_GOT /* initialize GOT access */
595 bl board_init_f /* run 1st part of board init code (in Flash)*/
596 /* NOTREACHED - board_init_f() does not return */
597#endif
598
wdenk0442ed82002-11-03 10:24:00 +0000599/*****************************************************************************/
600#if defined(CONFIG_440)
601
602 /*----------------------------------------------------------------*/
603 /* Clear and set up some registers. */
604 /*----------------------------------------------------------------*/
605 li r0,0x0000
606 lis r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200607 mtspr SPRN_DEC,r0 /* prevent dec exceptions */
608 mtspr SPRN_TBWL,r0 /* prevent fit & wdt exceptions */
609 mtspr SPRN_TBWU,r0
610 mtspr SPRN_TSR,r1 /* clear all timer exception status */
611 mtspr SPRN_TCR,r0 /* disable all */
612 mtspr SPRN_ESR,r0 /* clear exception syndrome register */
wdenk0442ed82002-11-03 10:24:00 +0000613 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000614
615 /*----------------------------------------------------------------*/
616 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200617 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000618 /* value you need in this case 0x8cff 0000 should do the trick */
619 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200620#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000621 lis r1,0xffff
622 ori r1,r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200623 mtspr SPRN_DBSR,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200624 lis r0,CONFIG_SYS_INIT_DBCR@h
625 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200626 mtspr SPRN_DBCR0,r0
wdenk0442ed82002-11-03 10:24:00 +0000627 isync
628#endif
629
630 /*----------------------------------------------------------------*/
631 /* Setup the internal SRAM */
632 /*----------------------------------------------------------------*/
633 li r0,0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200634
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200635#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roese326c9712005-08-01 16:41:48 +0200636 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200637 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
638 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200639 addis r4,r0,CONFIG_SYS_INIT_RAM_SIZE@h
640 ori r4,r4,CONFIG_SYS_INIT_RAM_SIZE@l
Stefan Roese326c9712005-08-01 16:41:48 +0200641 rlwinm. r5,r4,0,27,31
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200642 rlwinm r5,r4,27,5,31
643 beq ..d_ran
644 addi r5,r5,0x0001
Stefan Roese326c9712005-08-01 16:41:48 +0200645..d_ran:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200646 mtctr r5
Stefan Roese326c9712005-08-01 16:41:48 +0200647..d_ag:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200648 dcbz r0,r3
649 addi r3,r3,32
650 bdnz ..d_ag
Stefan Roesea86bde32008-01-09 10:23:16 +0100651
652 /*
653 * Lock the init-ram/stack in d-cache, so that other regions
654 * may use d-cache as well
655 * Note, that this current implementation locks exactly 4k
656 * of d-cache, so please make sure that you don't define a
657 * bigger init-ram area. Take a look at the lwmon5 440EPx
658 * implementation as a reference.
659 */
660 msync
661 isync
662 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
663 lis r1,0x0201
664 ori r1,r1,0xf808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200665 mtspr SPRN_DVLIM,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100666 lis r1,0x0808
667 ori r1,r1,0x0808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200668 mtspr SPRN_DNV0,r1
669 mtspr SPRN_DNV1,r1
670 mtspr SPRN_DNV2,r1
671 mtspr SPRN_DNV3,r1
672 mtspr SPRN_DTV0,r1
673 mtspr SPRN_DTV1,r1
674 mtspr SPRN_DTV2,r1
675 mtspr SPRN_DTV3,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100676 msync
677 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200678#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200679
680 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
681#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
682 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roesecc019d12008-03-11 15:05:50 +0100683#if defined(CONFIG_440GX) || \
684 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -0700685 defined(CONFIG_460SX)
Dave Mitchell3c3734172008-11-20 14:00:49 -0600686 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
Tirumala Marri95ac4282010-09-28 14:15:14 -0700687#elif defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
688 defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600689 lis r1, 0x0000
690 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
691 mtdcr L2_CACHE_CFG,r1
wdenk544e9732004-02-06 23:19:44 +0000692#endif
wdenk0442ed82002-11-03 10:24:00 +0000693
Stefan Roese42fbddd2006-09-07 11:51:23 +0200694 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000695 ori r2,r2,0xffff
Dave Mitchell3c3734172008-11-20 14:00:49 -0600696 mfdcr r1,ISRAM0_DPC
wdenk0442ed82002-11-03 10:24:00 +0000697 and r1,r1,r2 /* Disable parity check */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600698 mtdcr ISRAM0_DPC,r1
699 mfdcr r1,ISRAM0_PMEG
Stefan Roese42fbddd2006-09-07 11:51:23 +0200700 and r1,r1,r2 /* Disable pwr mgmt */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600701 mtdcr ISRAM0_PMEG,r1
wdenk0442ed82002-11-03 10:24:00 +0000702
703 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese99644742005-11-29 18:18:21 +0100704#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000705 ori r1,r1,0x0980 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600706 mtdcr ISRAM0_SB0CR,r1
wdenk544e9732004-02-06 23:19:44 +0000707 lis r1,0x8001
708 ori r1,r1,0x0980 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600709 mtdcr ISRAM0_SB1CR,r1
wdenk544e9732004-02-06 23:19:44 +0000710 lis r1, 0x8002
711 ori r1,r1, 0x0980 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600712 mtdcr ISRAM0_SB2CR,r1
wdenk544e9732004-02-06 23:19:44 +0000713 lis r1, 0x8003
714 ori r1,r1, 0x0980 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600715 mtdcr ISRAM0_SB3CR,r1
Tirumala Marri95ac4282010-09-28 14:15:14 -0700716#elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || \
717 defined(CONFIG_460GT) || defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600718 lis r1,0x0000 /* BAS = X_0000_0000 */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200719 ori r1,r1,0x0984 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600720 mtdcr ISRAM0_SB0CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200721 lis r1,0x0001
722 ori r1,r1,0x0984 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600723 mtdcr ISRAM0_SB1CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200724 lis r1, 0x0002
725 ori r1,r1, 0x0984 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600726 mtdcr ISRAM0_SB2CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200727 lis r1, 0x0003
728 ori r1,r1, 0x0984 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600729 mtdcr ISRAM0_SB3CR,r1
Tirumala Marri95ac4282010-09-28 14:15:14 -0700730#if defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
731 defined(CONFIG_APM821XX)
Dave Mitchell5c057592008-11-20 14:09:50 -0600732 lis r2,0x7fff
733 ori r2,r2,0xffff
734 mfdcr r1,ISRAM1_DPC
735 and r1,r1,r2 /* Disable parity check */
Wolfgang Denk55334c72008-12-16 01:02:17 +0100736 mtdcr ISRAM1_DPC,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600737 mfdcr r1,ISRAM1_PMEG
738 and r1,r1,r2 /* Disable pwr mgmt */
739 mtdcr ISRAM1_PMEG,r1
740
741 lis r1,0x0004 /* BAS = 4_0004_0000 */
Tirumala Marri95ac4282010-09-28 14:15:14 -0700742 ori r1,r1,ISRAM1_SIZE /* ocm size */
Dave Mitchell5c057592008-11-20 14:09:50 -0600743 mtdcr ISRAM1_SB0CR,r1
744#endif
Feng Kan224bc962008-07-08 22:47:31 -0700745#elif defined(CONFIG_460SX)
746 lis r1,0x0000 /* BAS = 0000_0000 */
747 ori r1,r1,0x0B84 /* first 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600748 mtdcr ISRAM0_SB0CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700749 lis r1,0x0001
750 ori r1,r1,0x0B84 /* second 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600751 mtdcr ISRAM0_SB1CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700752 lis r1, 0x0002
753 ori r1,r1, 0x0B84 /* third 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600754 mtdcr ISRAM0_SB2CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700755 lis r1, 0x0003
756 ori r1,r1, 0x0B84 /* fourth 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600757 mtdcr ISRAM0_SB3CR,r1
Stefan Roese42fbddd2006-09-07 11:51:23 +0200758#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000759 ori r1,r1,0x0380 /* 8k rw */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600760 mtdcr ISRAM0_SB0CR,r1
761 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
Stefan Roese326c9712005-08-01 16:41:48 +0200762#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200763#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000764
765 /*----------------------------------------------------------------*/
766 /* Setup the stack in internal SRAM */
767 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200768 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
769 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
wdenk0442ed82002-11-03 10:24:00 +0000770 li r0,0
771 stwu r0,-4(r1)
772 stwu r0,-4(r1) /* Terminate call chain */
773
774 stwu r1,-8(r1) /* Save back chain and move SP */
775 lis r0,RESET_VECTOR@h /* Address of reset vector */
776 ori r0,r0, RESET_VECTOR@l
777 stwu r1,-8(r1) /* Save back chain and move SP */
778 stw r0,+12(r1) /* Save return addr (underflow vect) */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200779
Stefan Roese42fbddd2006-09-07 11:51:23 +0200780#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +0200781 bl nand_boot_common /* will not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200782#else
Stefan Roese07038ad2013-04-02 10:37:04 +0200783#ifndef CONFIG_SPL_BUILD
wdenk0442ed82002-11-03 10:24:00 +0000784 GET_GOT
Stefan Roese07038ad2013-04-02 10:37:04 +0200785#endif
Stefan Roesec443fe92005-11-22 13:20:42 +0100786
787 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +0000788 bl board_init_f
Peter Tyser0c44caf2010-09-14 19:13:53 -0500789 /* NOTREACHED - board_init_f() does not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200790#endif
wdenk0442ed82002-11-03 10:24:00 +0000791
792#endif /* CONFIG_440 */
793
794/*****************************************************************************/
Matthias Fuchse54a67f2013-08-07 12:10:38 +0200795#if defined(CONFIG_405GP) || \
Stefan Roese17ffbc82007-03-21 13:38:59 +0100796 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200797 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000798 /*----------------------------------------------------------------------- */
799 /* Clear and set up some registers. */
800 /*----------------------------------------------------------------------- */
801 addi r4,r0,0x0000
Stefan Roese153b3e22007-10-05 17:10:59 +0200802#if !defined(CONFIG_405EX)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200803 mtspr SPRN_SGR,r4
Stefan Roese153b3e22007-10-05 17:10:59 +0200804#else
805 /*
806 * On 405EX, completely clearing the SGR leads to PPC hangup
807 * upon PCIe configuration access. The PCIe memory regions
808 * need to be guarded!
809 */
810 lis r3,0x0000
811 ori r3,r3,0x7FFC
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200812 mtspr SPRN_SGR,r3
Stefan Roese153b3e22007-10-05 17:10:59 +0200813#endif
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200814 mtspr SPRN_DCWR,r4
wdenk0442ed82002-11-03 10:24:00 +0000815 mtesr r4 /* clear Exception Syndrome Reg */
816 mttcr r4 /* clear Timer Control Reg */
817 mtxer r4 /* clear Fixed-Point Exception Reg */
818 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000819 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
820 /* dbsr is cleared by setting bits to 1) */
821 mtdbsr r4 /* clear/reset the dbsr */
822
Grant Ericksonb6933412008-05-22 14:44:14 -0700823 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000824 bl invalidate_icache
825 bl invalidate_dcache
826
Grant Ericksonb6933412008-05-22 14:44:14 -0700827 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200828 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
829 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700830 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000831 isync
832
Grant Ericksonb6933412008-05-22 14:44:14 -0700833 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200834 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
835 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700836 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000837
Ricardo Ribalda Delgado78ea77e2008-10-21 18:29:46 +0200838#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
839 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000840 /*----------------------------------------------------------------------- */
841 /* Tune the speed and size for flash CS0 */
842 /*----------------------------------------------------------------------- */
843 bl ext_bus_cntlr_init
844#endif
Stefan Roese7d72e022008-06-02 14:35:44 +0200845
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200846#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roese153b3e22007-10-05 17:10:59 +0200847 /*
Grant Ericksonb6933412008-05-22 14:44:14 -0700848 * For boards that don't have OCM and can't use the data cache
849 * for their primordial stack, setup stack here directly after the
850 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roese153b3e22007-10-05 17:10:59 +0200851 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200852 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
853 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
Stefan Roese153b3e22007-10-05 17:10:59 +0200854
855 li r0, 0 /* Make room for stack frame header and */
856 stwu r0, -4(r1) /* clear final stack frame so that */
857 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
858 /*
859 * Set up a dummy frame to store reset vector as return address.
860 * this causes stack underflow to reset board.
861 */
862 stwu r1, -8(r1) /* Save back chain and move SP */
863 lis r0, RESET_VECTOR@h /* Address of reset vector */
864 ori r0, r0, RESET_VECTOR@l
865 stwu r1, -8(r1) /* Save back chain and move SP */
866 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200867#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000868
stroese434979e2003-05-23 11:18:02 +0000869#if defined(CONFIG_405EP)
870 /*----------------------------------------------------------------------- */
871 /* DMA Status, clear to come up clean */
872 /*----------------------------------------------------------------------- */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200873 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200874 ori r3,r3, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200875 mtdcr DMASR, r3
stroese434979e2003-05-23 11:18:02 +0000876
Wolfgang Denka1be4762008-05-20 16:00:29 +0200877 bl ppc405ep_init /* do ppc405ep specific init */
stroese434979e2003-05-23 11:18:02 +0000878#endif /* CONFIG_405EP */
879
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200880#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roese17ffbc82007-03-21 13:38:59 +0100881#if defined(CONFIG_405EZ)
882 /********************************************************************
883 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
884 *******************************************************************/
885 /*
886 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200887 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roese17ffbc82007-03-21 13:38:59 +0100888 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200889 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
890 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese80d99a42007-06-19 16:42:31 +0200891 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200892 mtdcr OCM0_PLBCR1,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100893 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200894 mtdcr OCM0_PLBCR2,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100895 isync
896
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200897 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
898 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200899 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200900 mtdcr OCM0_DSRC1, r3 /* Set Data Side */
901 mtdcr OCM0_ISRC1, r3 /* Set Instruction Side */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100902 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200903 mtdcr OCM0_DSRC2, r3 /* Set Data Side */
904 mtdcr OCM0_ISRC2, r3 /* Set Instruction Side */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200905 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roese918010a2009-09-09 16:25:29 +0200906 mtdcr OCM0_DISDPC,r3
Stefan Roese17ffbc82007-03-21 13:38:59 +0100907
908 isync
Stefan Roesef6c7b762007-03-24 15:45:34 +0100909#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000910 /********************************************************************
911 * Setup OCM - On Chip Memory
912 *******************************************************************/
913 /* Setup OCM */
wdenk57b2d802003-06-27 21:31:46 +0000914 lis r0, 0x7FFF
915 ori r0, r0, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200916 mfdcr r3, OCM0_ISCNTL /* get instr-side IRAM config */
917 mfdcr r4, OCM0_DSCNTL /* get data-side IRAM config */
Stefan Roesef6c7b762007-03-24 15:45:34 +0100918 and r3, r3, r0 /* disable data-side IRAM */
919 and r4, r4, r0 /* disable data-side IRAM */
Stefan Roese918010a2009-09-09 16:25:29 +0200920 mtdcr OCM0_ISCNTL, r3 /* set instr-side IRAM config */
921 mtdcr OCM0_DSCNTL, r4 /* set data-side IRAM config */
wdenk57b2d802003-06-27 21:31:46 +0000922 isync
wdenk0442ed82002-11-03 10:24:00 +0000923
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200924 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
925 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200926 mtdcr OCM0_DSARC, r3
wdenk0442ed82002-11-03 10:24:00 +0000927 addis r4, 0, 0xC000 /* OCM data area enabled */
Stefan Roese918010a2009-09-09 16:25:29 +0200928 mtdcr OCM0_DSCNTL, r4
wdenk57b2d802003-06-27 21:31:46 +0000929 isync
Stefan Roese17ffbc82007-03-21 13:38:59 +0100930#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000931#endif
932
933 /*----------------------------------------------------------------------- */
934 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
935 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200936#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonb6933412008-05-22 14:44:14 -0700937 li r4, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +0200938 mtdcr EBC0_CFGADDR, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200939 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
940 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200941 mtdcr EBC0_CFGDATA, r4
wdenk0442ed82002-11-03 10:24:00 +0000942
Grant Ericksonb6933412008-05-22 14:44:14 -0700943 addi r4, 0, PBxCR
Stefan Roese918010a2009-09-09 16:25:29 +0200944 mtdcr EBC0_CFGADDR, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200945 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
946 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200947 mtdcr EBC0_CFGDATA, r4
wdenk0442ed82002-11-03 10:24:00 +0000948
Grant Ericksonb6933412008-05-22 14:44:14 -0700949 /*
950 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200951 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonb6933412008-05-22 14:44:14 -0700952 */
953 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200954 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
955 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +0000956 mtdccr r4
957
Grant Ericksonb6933412008-05-22 14:44:14 -0700958 /*
959 * Preallocate data cache lines to be used to avoid a subsequent
960 * cache miss and an ensuing machine check exception when exceptions
961 * are enabled.
962 */
963 li r0, 0
964
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200965 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
966 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +0000967
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200968 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
969 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +0000970
Grant Ericksonb6933412008-05-22 14:44:14 -0700971 /*
972 * Convert the size, in bytes, to the number of cache lines/blocks
973 * to preallocate.
974 */
975 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
976 srwi r5, r4, L1_CACHE_SHIFT
977 beq ..load_counter
978 addi r5, r5, 0x0001
979..load_counter:
980 mtctr r5
981
982 /* Preallocate the computed number of cache blocks. */
983..alloc_dcache_block:
984 dcba r0, r3
985 addi r3, r3, L1_CACHE_BYTES
986 bdnz ..alloc_dcache_block
987 sync
988
989 /*
990 * Load the initial stack pointer and data area and convert the size,
991 * in bytes, to the number of words to initialize to a known value.
992 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200993 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
994 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700995
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200996 lis r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@h
997 ori r4, r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +0000998 mtctr r4
999
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001000 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001001 ori r2, r2, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +00001002
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001003 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1004 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001005
1006..stackloop:
Grant Ericksonb6933412008-05-22 14:44:14 -07001007 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001008 bdnz ..stackloop
1009
Grant Ericksonb6933412008-05-22 14:44:14 -07001010 /*
1011 * Make room for stack frame header and clear final stack frame so
1012 * that stack backtraces terminate cleanly.
1013 */
1014 stwu r0, -4(r1)
1015 stwu r0, -4(r1)
1016
wdenk0442ed82002-11-03 10:24:00 +00001017 /*
1018 * Set up a dummy frame to store reset vector as return address.
1019 * this causes stack underflow to reset board.
1020 */
1021 stwu r1, -8(r1) /* Save back chain and move SP */
1022 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1023 ori r0, r0, RESET_VECTOR@l
1024 stwu r1, -8(r1) /* Save back chain and move SP */
1025 stw r0, +12(r1) /* Save return addr (underflow vect) */
1026
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001027#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1028 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001029 /*
1030 * Stack in OCM.
1031 */
1032
1033 /* Set up Stack at top of OCM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001034 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1035 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
wdenk0442ed82002-11-03 10:24:00 +00001036
1037 /* Set up a zeroized stack frame so that backtrace works right */
1038 li r0, 0
1039 stwu r0, -4(r1)
1040 stwu r0, -4(r1)
1041
1042 /*
1043 * Set up a dummy frame to store reset vector as return address.
1044 * this causes stack underflow to reset board.
1045 */
1046 stwu r1, -8(r1) /* Save back chain and move SP */
1047 lis r0, RESET_VECTOR@h /* Address of reset vector */
1048 ori r0, r0, RESET_VECTOR@l
1049 stwu r1, -8(r1) /* Save back chain and move SP */
1050 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001051#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001052
Stefan Roese23d8d342007-06-06 11:42:13 +02001053#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +02001054 bl nand_boot_common /* will not return */
Stefan Roese23d8d342007-06-06 11:42:13 +02001055#else
wdenk0442ed82002-11-03 10:24:00 +00001056 GET_GOT /* initialize GOT access */
1057
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001058 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +00001059
wdenk0442ed82002-11-03 10:24:00 +00001060 bl board_init_f /* run first part of init code (from Flash) */
Peter Tyser0c44caf2010-09-14 19:13:53 -05001061 /* NOTREACHED - board_init_f() does not return */
1062
Stefan Roese23d8d342007-06-06 11:42:13 +02001063#endif /* CONFIG_NAND_SPL */
wdenk0442ed82002-11-03 10:24:00 +00001064
Matthias Fuchse54a67f2013-08-07 12:10:38 +02001065#endif /* CONFIG_405GP || CONFIG_405 || CONFIG_405EP */
wdenk232fe0b2003-09-02 22:48:03 +00001066 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001067
1068
Stefan Roese07038ad2013-04-02 10:37:04 +02001069#if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001070/*
1071 * This code finishes saving the registers to the exception frame
1072 * and jumps to the appropriate handler for the exception.
1073 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1074 */
1075 .globl transfer_to_handler
1076transfer_to_handler:
1077 stw r22,_NIP(r21)
1078 lis r22,MSR_POW@h
1079 andc r23,r23,r22
1080 stw r23,_MSR(r21)
1081 SAVE_GPR(7, r21)
1082 SAVE_4GPRS(8, r21)
1083 SAVE_8GPRS(12, r21)
1084 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001085 mflr r23
1086 andi. r24,r23,0x3f00 /* get vector offset */
1087 stw r24,TRAP(r21)
1088 li r22,0
1089 stw r22,RESULT(r21)
1090 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001091 lwz r24,0(r23) /* virtual address of handler */
1092 lwz r23,4(r23) /* where to go when done */
1093 mtspr SRR0,r24
1094 mtspr SRR1,r20
1095 mtlr r23
1096 SYNC
1097 rfi /* jump to handler, enable MMU */
1098
1099int_return:
1100 mfmsr r28 /* Disable interrupts */
1101 li r4,0
1102 ori r4,r4,MSR_EE
1103 andc r28,r28,r4
1104 SYNC /* Some chip revs need this... */
1105 mtmsr r28
1106 SYNC
1107 lwz r2,_CTR(r1)
1108 lwz r0,_LINK(r1)
1109 mtctr r2
1110 mtlr r0
1111 lwz r2,_XER(r1)
1112 lwz r0,_CCR(r1)
1113 mtspr XER,r2
1114 mtcrf 0xFF,r0
1115 REST_10GPRS(3, r1)
1116 REST_10GPRS(13, r1)
1117 REST_8GPRS(23, r1)
1118 REST_GPR(31, r1)
1119 lwz r2,_NIP(r1) /* Restore environment */
1120 lwz r0,_MSR(r1)
1121 mtspr SRR0,r2
1122 mtspr SRR1,r0
1123 lwz r0,GPR0(r1)
1124 lwz r2,GPR2(r1)
1125 lwz r1,GPR1(r1)
1126 SYNC
1127 rfi
1128
1129crit_return:
1130 mfmsr r28 /* Disable interrupts */
1131 li r4,0
1132 ori r4,r4,MSR_EE
1133 andc r28,r28,r4
1134 SYNC /* Some chip revs need this... */
1135 mtmsr r28
1136 SYNC
1137 lwz r2,_CTR(r1)
1138 lwz r0,_LINK(r1)
1139 mtctr r2
1140 mtlr r0
1141 lwz r2,_XER(r1)
1142 lwz r0,_CCR(r1)
1143 mtspr XER,r2
1144 mtcrf 0xFF,r0
1145 REST_10GPRS(3, r1)
1146 REST_10GPRS(13, r1)
1147 REST_8GPRS(23, r1)
1148 REST_GPR(31, r1)
1149 lwz r2,_NIP(r1) /* Restore environment */
1150 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001151 mtspr SPRN_CSRR0,r2
1152 mtspr SPRN_CSRR1,r0
wdenk0442ed82002-11-03 10:24:00 +00001153 lwz r0,GPR0(r1)
1154 lwz r2,GPR2(r1)
1155 lwz r1,GPR1(r1)
1156 SYNC
1157 rfci
1158
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001159#ifdef CONFIG_440
1160mck_return:
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001161 mfmsr r28 /* Disable interrupts */
1162 li r4,0
1163 ori r4,r4,MSR_EE
1164 andc r28,r28,r4
1165 SYNC /* Some chip revs need this... */
1166 mtmsr r28
1167 SYNC
1168 lwz r2,_CTR(r1)
1169 lwz r0,_LINK(r1)
1170 mtctr r2
1171 mtlr r0
1172 lwz r2,_XER(r1)
1173 lwz r0,_CCR(r1)
1174 mtspr XER,r2
1175 mtcrf 0xFF,r0
1176 REST_10GPRS(3, r1)
1177 REST_10GPRS(13, r1)
1178 REST_8GPRS(23, r1)
1179 REST_GPR(31, r1)
1180 lwz r2,_NIP(r1) /* Restore environment */
1181 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001182 mtspr SPRN_MCSRR0,r2
1183 mtspr SPRN_MCSRR1,r0
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001184 lwz r0,GPR0(r1)
1185 lwz r2,GPR2(r1)
1186 lwz r1,GPR1(r1)
1187 SYNC
1188 rfmci
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001189#endif /* CONFIG_440 */
1190
1191
wdenk0442ed82002-11-03 10:24:00 +00001192 .globl get_pvr
1193get_pvr:
1194 mfspr r3, PVR
1195 blr
1196
wdenk0442ed82002-11-03 10:24:00 +00001197/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001198/* Function: out16 */
1199/* Description: Output 16 bits */
1200/*------------------------------------------------------------------------------- */
1201 .globl out16
1202out16:
1203 sth r4,0x0000(r3)
1204 blr
1205
1206/*------------------------------------------------------------------------------- */
1207/* Function: out16r */
1208/* Description: Byte reverse and output 16 bits */
1209/*------------------------------------------------------------------------------- */
1210 .globl out16r
1211out16r:
1212 sthbrx r4,r0,r3
1213 blr
1214
1215/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001216/* Function: out32r */
1217/* Description: Byte reverse and output 32 bits */
1218/*------------------------------------------------------------------------------- */
1219 .globl out32r
1220out32r:
1221 stwbrx r4,r0,r3
1222 blr
1223
1224/*------------------------------------------------------------------------------- */
1225/* Function: in16 */
1226/* Description: Input 16 bits */
1227/*------------------------------------------------------------------------------- */
1228 .globl in16
1229in16:
1230 lhz r3,0x0000(r3)
1231 blr
1232
1233/*------------------------------------------------------------------------------- */
1234/* Function: in16r */
1235/* Description: Input 16 bits and byte reverse */
1236/*------------------------------------------------------------------------------- */
1237 .globl in16r
1238in16r:
1239 lhbrx r3,r0,r3
1240 blr
1241
1242/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001243/* Function: in32r */
1244/* Description: Input 32 bits and byte reverse */
1245/*------------------------------------------------------------------------------- */
1246 .globl in32r
1247in32r:
1248 lwbrx r3,r0,r3
1249 blr
1250
Stefan Roese07038ad2013-04-02 10:37:04 +02001251#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001252/*
1253 * void relocate_code (addr_sp, gd, addr_moni)
1254 *
1255 * This "function" does not return, instead it continues in RAM
1256 * after relocating the monitor code.
1257 *
Grant Ericksonb6933412008-05-22 14:44:14 -07001258 * r3 = Relocated stack pointer
1259 * r4 = Relocated global data pointer
1260 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001261 */
1262 .globl relocate_code
1263relocate_code:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001264#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001265 /*
Stefan Roese593a0fb2010-11-26 15:45:34 +01001266 * We need to flush the initial global data (gd_t) and bd_info
1267 * before the dcache will be invalidated.
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001268 */
1269
Grant Ericksonb6933412008-05-22 14:44:14 -07001270 /* Save registers */
1271 mr r9, r3
1272 mr r10, r4
1273 mr r11, r5
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001274
Stefan Roese593a0fb2010-11-26 15:45:34 +01001275 /*
1276 * Flush complete dcache, this is faster than flushing the
1277 * ranges for global_data and bd_info instead.
1278 */
1279 bl flush_dcache
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001280
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001281#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonb6933412008-05-22 14:44:14 -07001282 /*
1283 * Undo the earlier data cache set-up for the primordial stack and
1284 * data area. First, invalidate the data cache and then disable data
1285 * cacheability for that area. Finally, restore the EBC values, if
1286 * any.
1287 */
1288
1289 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001290 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1291 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001292
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001293 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
1294 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001295 add r4, r4, r3
1296
1297 bl invalidate_dcache_range
1298
1299 /* Disable cacheability for the region */
1300 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001301 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1302 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001303 and r3, r3, r4
1304 mtdccr r3
1305
1306 /* Restore the EBC parameters */
1307 li r3, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +02001308 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001309 lis r3, PBxAP_VAL@h
1310 ori r3, r3, PBxAP_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001311 mtdcr EBC0_CFGDATA, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001312
1313 li r3, PBxCR
Stefan Roese918010a2009-09-09 16:25:29 +02001314 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001315 lis r3, PBxCR_VAL@h
1316 ori r3, r3, PBxCR_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001317 mtdcr EBC0_CFGDATA, r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001318#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonb6933412008-05-22 14:44:14 -07001319
1320 /* Restore registers */
1321 mr r3, r9
1322 mr r4, r10
1323 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001324#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesea86bde32008-01-09 10:23:16 +01001325
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001326#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesea86bde32008-01-09 10:23:16 +01001327 /*
1328 * Unlock the previously locked d-cache
1329 */
1330 msync
1331 isync
1332 /* set TFLOOR/NFLOOR to 0 again */
1333 lis r6,0x0001
1334 ori r6,r6,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001335 mtspr SPRN_DVLIM,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001336 lis r6,0x0000
1337 ori r6,r6,0x0000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001338 mtspr SPRN_DNV0,r6
1339 mtspr SPRN_DNV1,r6
1340 mtspr SPRN_DNV2,r6
1341 mtspr SPRN_DNV3,r6
1342 mtspr SPRN_DTV0,r6
1343 mtspr SPRN_DTV1,r6
1344 mtspr SPRN_DTV2,r6
1345 mtspr SPRN_DTV3,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001346 msync
1347 isync
Stefan Roese04bb5fc2010-08-31 11:27:14 +02001348
1349 /* Invalidate data cache, now no longer our stack */
1350 dccci 0,0
1351 sync
1352 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001353#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesea86bde32008-01-09 10:23:16 +01001354
Stefan Roese9eba0c82006-06-02 16:18:04 +02001355 /*
1356 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1357 * to speed up the boot process. Now this cache needs to be disabled.
1358 */
Stefan Roese1d568062010-05-27 16:45:20 +02001359#if defined(CONFIG_440)
Stefan Roesefe05a022008-11-20 11:46:20 +01001360 /* Clear all potential pending exceptions */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001361 mfspr r1,SPRN_MCSR
1362 mtspr SPRN_MCSR,r1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001363 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Stefan Roese326c9712005-08-01 16:41:48 +02001364 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese99644742005-11-29 18:18:21 +01001365 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001366 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roese9eba0c82006-06-02 16:18:04 +02001367 sync
Stefan Roese326c9712005-08-01 16:41:48 +02001368 isync
Stefan Roese1d568062010-05-27 16:45:20 +02001369#endif /* defined(CONFIG_440) */
wdenk0442ed82002-11-03 10:24:00 +00001370 mr r1, r3 /* Set new stack pointer */
1371 mr r9, r4 /* Save copy of Init Data pointer */
1372 mr r10, r5 /* Save copy of Destination Address */
1373
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001374 GET_GOT
wdenk0442ed82002-11-03 10:24:00 +00001375 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001376 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1377 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +00001378 lwz r5, GOT(__init_end)
1379 sub r5, r5, r4
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001380 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001381
1382 /*
1383 * Fix GOT pointer:
1384 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001385 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001386 *
1387 * Offset:
1388 */
1389 sub r15, r10, r4
1390
1391 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001392 add r12, r12, r15
Grant Ericksonb6933412008-05-22 14:44:14 -07001393 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001394 add r30, r30, r15
1395
1396 /*
1397 * Now relocate code
1398 */
1399
1400 cmplw cr1,r3,r4
1401 addi r0,r5,3
1402 srwi. r0,r0,2
1403 beq cr1,4f /* In place copy is not necessary */
1404 beq 7f /* Protect against 0 count */
1405 mtctr r0
1406 bge cr1,2f
1407
1408 la r8,-4(r4)
1409 la r7,-4(r3)
14101: lwzu r0,4(r8)
1411 stwu r0,4(r7)
1412 bdnz 1b
1413 b 4f
1414
14152: slwi r0,r0,2
1416 add r8,r4,r0
1417 add r7,r3,r0
14183: lwzu r0,-4(r8)
1419 stwu r0,-4(r7)
1420 bdnz 3b
1421
1422/*
1423 * Now flush the cache: note that we must start from a cache aligned
1424 * address. Otherwise we might miss one cache line.
1425 */
14264: cmpwi r6,0
1427 add r5,r3,r5
1428 beq 7f /* Always flush prefetch queue in any case */
1429 subi r0,r6,1
1430 andc r3,r3,r0
1431 mr r4,r3
14325: dcbst 0,r4
1433 add r4,r4,r6
1434 cmplw r4,r5
1435 blt 5b
1436 sync /* Wait for all dcbst to complete on bus */
1437 mr r4,r3
14386: icbi 0,r4
1439 add r4,r4,r6
1440 cmplw r4,r5
1441 blt 6b
14427: sync /* Wait for all icbi to complete on bus */
1443 isync
1444
1445/*
1446 * We are done. Do not return, instead branch to second part of board
1447 * initialization, now running from RAM.
1448 */
1449
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001450 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001451 mtlr r0
1452 blr /* NEVER RETURNS! */
1453
1454in_ram:
1455
1456 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001457 * Relocation Function, r12 point to got2+0x8000
wdenk0442ed82002-11-03 10:24:00 +00001458 *
1459 * Adjust got2 pointers, no need to check for 0, this code
1460 * already puts a few entries in the table.
1461 */
1462 li r0,__got2_entries@sectoff@l
1463 la r3,GOT(_GOT2_TABLE_)
1464 lwz r11,GOT(_GOT2_TABLE_)
1465 mtctr r0
1466 sub r11,r3,r11
1467 addi r3,r3,-4
14681: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001469 cmpwi r0,0
1470 beq- 2f
wdenk0442ed82002-11-03 10:24:00 +00001471 add r0,r0,r11
1472 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +020014732: bdnz 1b
wdenk0442ed82002-11-03 10:24:00 +00001474
1475 /*
1476 * Now adjust the fixups and the pointers to the fixups
1477 * in case we need to move ourselves again.
1478 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001479 li r0,__fixup_entries@sectoff@l
wdenk0442ed82002-11-03 10:24:00 +00001480 lwz r3,GOT(_FIXUP_TABLE_)
1481 cmpwi r0,0
1482 mtctr r0
1483 addi r3,r3,-4
1484 beq 4f
14853: lwzu r4,4(r3)
1486 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001487 cmpwi r0,0
wdenk0442ed82002-11-03 10:24:00 +00001488 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +01001489 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001490 beq- 5f
wdenk0442ed82002-11-03 10:24:00 +00001491 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +020014925: bdnz 3b
wdenk0442ed82002-11-03 10:24:00 +000014934:
1494clear_bss:
1495 /*
1496 * Now clear BSS segment
1497 */
wdenkbf2f8c92003-05-22 22:52:13 +00001498 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +00001499 lwz r4,GOT(__bss_end)
wdenk0442ed82002-11-03 10:24:00 +00001500
1501 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001502 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001503
1504 li r0, 0
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001505
1506 andi. r5, r4, 3
1507 beq 6f
1508 sub r4, r4, r5
1509 mtctr r5
1510 mr r5, r4
15115: stb r0, 0(r5)
1512 addi r5, r5, 1
1513 bdnz 5b
15146:
wdenk0442ed82002-11-03 10:24:00 +00001515 stw r0, 0(r3)
1516 addi r3, r3, 4
1517 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001518 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001519
Anatolij Gustschin720025b2007-12-05 17:43:20 +010015207:
wdenk0442ed82002-11-03 10:24:00 +00001521 mr r3, r9 /* Init Data pointer */
1522 mr r4, r10 /* Destination Address */
1523 bl board_init_r
1524
wdenk0442ed82002-11-03 10:24:00 +00001525 /*
1526 * Copy exception vector code to low memory
1527 *
1528 * r3: dest_addr
1529 * r7: source address, r8: end address, r9: target address
1530 */
1531 .globl trap_init
1532trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001533 mflr r4 /* save link register */
1534 GET_GOT
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001535 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001536 lwz r8, GOT(_end_of_vectors)
1537
wdenk4e112c12003-06-03 23:54:09 +00001538 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001539
1540 cmplw 0, r7, r8
1541 bgelr /* return if r7>=r8 - just in case */
wdenk0442ed82002-11-03 10:24:00 +000015421:
1543 lwz r0, 0(r7)
1544 stw r0, 0(r9)
1545 addi r7, r7, 4
1546 addi r9, r9, 4
1547 cmplw 0, r7, r8
1548 bne 1b
1549
1550 /*
1551 * relocate `hdlr' and `int_return' entries
1552 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001553 li r7, .L_MachineCheck - _start + _START_OFFSET
1554 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000015552:
1556 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001557 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001558 cmplw 0, r7, r8
1559 blt 2b
1560
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001561 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001562 bl trap_reloc
1563
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001564 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001565 bl trap_reloc
1566
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001567#ifdef CONFIG_440
1568 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001569 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001570
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001571 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001572 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001573
1574 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001575 bl trap_reloc
Stefan Roese80d99a42007-06-19 16:42:31 +02001576
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001577 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1578 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001579
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001580 li r7, .L_DataTLBError - _start + _START_OFFSET
1581 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001582#else /* CONFIG_440 */
1583 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001584 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001585
1586 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001587 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001588
1589 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001590 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001591#endif /* CONFIG_440 */
1592
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001593 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1594 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001595
Stefan Roese42fbddd2006-09-07 11:51:23 +02001596#if !defined(CONFIG_440)
Stefan Roese7b12aa82006-03-13 09:42:28 +01001597 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1598 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1599 mtmsr r7 /* change MSR */
1600#else
Stefan Roese42fbddd2006-09-07 11:51:23 +02001601 bl __440_msr_set
1602 b __440_msr_continue
Stefan Roese7b12aa82006-03-13 09:42:28 +01001603
Stefan Roese42fbddd2006-09-07 11:51:23 +02001604__440_msr_set:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001605 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1606 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001607 mtspr SPRN_SRR1,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001608 mflr r7
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001609 mtspr SPRN_SRR0,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001610 rfi
Stefan Roese42fbddd2006-09-07 11:51:23 +02001611__440_msr_continue:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001612#endif
1613
wdenk0442ed82002-11-03 10:24:00 +00001614 mtlr r4 /* restore link register */
1615 blr
Stefan Roese07038ad2013-04-02 10:37:04 +02001616#endif /* CONFIG_SPL_BUILD */
wdenk0442ed82002-11-03 10:24:00 +00001617
Stefan Roese42743512007-06-01 15:27:11 +02001618#if defined(CONFIG_440)
1619/*----------------------------------------------------------------------------+
1620| dcbz_area.
1621+----------------------------------------------------------------------------*/
1622 function_prolog(dcbz_area)
1623 rlwinm. r5,r4,0,27,31
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001624 rlwinm r5,r4,27,5,31
1625 beq ..d_ra2
1626 addi r5,r5,0x0001
1627..d_ra2:mtctr r5
1628..d_ag2:dcbz r0,r3
1629 addi r3,r3,32
1630 bdnz ..d_ag2
Stefan Roese42743512007-06-01 15:27:11 +02001631 sync
1632 blr
1633 function_epilog(dcbz_area)
Stefan Roese42743512007-06-01 15:27:11 +02001634#endif /* CONFIG_440 */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001635#endif /* CONFIG_NAND_SPL */
stroese434979e2003-05-23 11:18:02 +00001636
Stefan Roese42743512007-06-01 15:27:11 +02001637/*------------------------------------------------------------------------------- */
1638/* Function: in8 */
1639/* Description: Input 8 bits */
1640/*------------------------------------------------------------------------------- */
1641 .globl in8
1642in8:
1643 lbz r3,0x0000(r3)
1644 blr
1645
1646/*------------------------------------------------------------------------------- */
1647/* Function: out8 */
1648/* Description: Output 8 bits */
1649/*------------------------------------------------------------------------------- */
1650 .globl out8
1651out8:
1652 stb r4,0x0000(r3)
1653 blr
1654
1655/*------------------------------------------------------------------------------- */
1656/* Function: out32 */
1657/* Description: Output 32 bits */
1658/*------------------------------------------------------------------------------- */
1659 .globl out32
1660out32:
1661 stw r4,0x0000(r3)
1662 blr
1663
1664/*------------------------------------------------------------------------------- */
1665/* Function: in32 */
1666/* Description: Input 32 bits */
1667/*------------------------------------------------------------------------------- */
1668 .globl in32
1669in32:
1670 lwz 3,0x0000(3)
1671 blr
stroese434979e2003-05-23 11:18:02 +00001672
1673/**************************************************************************/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001674/* PPC405EP specific stuff */
stroese434979e2003-05-23 11:18:02 +00001675/**************************************************************************/
1676#ifdef CONFIG_405EP
1677ppc405ep_init:
stroese5ad6d4d2003-12-09 14:54:43 +00001678
Stefan Roese326c9712005-08-01 16:41:48 +02001679#ifdef CONFIG_BUBINGA
stroese5ad6d4d2003-12-09 14:54:43 +00001680 /*
1681 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1682 * function) to support FPGA and NVRAM accesses below.
1683 */
1684
1685 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1686 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001687 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1688 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001689 stw r4,0(r3)
1690 lis r3,GPIO0_OSRL@h
1691 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001692 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1693 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001694 stw r4,0(r3)
1695
1696 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1697 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001698 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1699 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroese5ad6d4d2003-12-09 14:54:43 +00001700 stw r4,0(r3)
1701 lis r3,GPIO0_ISR1L@h
1702 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001703 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1704 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroese5ad6d4d2003-12-09 14:54:43 +00001705 stw r4,0(r3)
1706
1707 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1708 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001709 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1710 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001711 stw r4,0(r3)
1712 lis r3,GPIO0_TSRL@h
1713 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001714 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1715 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001716 stw r4,0(r3)
1717
1718 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1719 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001720 lis r4,CONFIG_SYS_GPIO0_TCR@h
1721 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001722 stw r4,0(r3)
1723
Stefan Roese918010a2009-09-09 16:25:29 +02001724 li r3,PB1AP /* program EBC bank 1 for RTC access */
1725 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001726 lis r3,CONFIG_SYS_EBC_PB1AP@h
1727 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001728 mtdcr EBC0_CFGDATA,r3
1729 li r3,PB1CR
1730 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001731 lis r3,CONFIG_SYS_EBC_PB1CR@h
1732 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001733 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001734
Stefan Roese918010a2009-09-09 16:25:29 +02001735 li r3,PB1AP /* program EBC bank 1 for RTC access */
1736 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001737 lis r3,CONFIG_SYS_EBC_PB1AP@h
1738 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001739 mtdcr EBC0_CFGDATA,r3
1740 li r3,PB1CR
1741 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001742 lis r3,CONFIG_SYS_EBC_PB1CR@h
1743 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001744 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001745
Stefan Roese918010a2009-09-09 16:25:29 +02001746 li r3,PB4AP /* program EBC bank 4 for FPGA access */
1747 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001748 lis r3,CONFIG_SYS_EBC_PB4AP@h
1749 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001750 mtdcr EBC0_CFGDATA,r3
1751 li r3,PB4CR
1752 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001753 lis r3,CONFIG_SYS_EBC_PB4CR@h
1754 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001755 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001756#endif
stroese434979e2003-05-23 11:18:02 +00001757
wdenk57b2d802003-06-27 21:31:46 +00001758 /*
1759 !-----------------------------------------------------------------------
1760 ! Check to see if chip is in bypass mode.
1761 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1762 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001763 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1764 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk57b2d802003-06-27 21:31:46 +00001765 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001766 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001767 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001768 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001769 cmpi cr0,0,r4,0x1
stroese434979e2003-05-23 11:18:02 +00001770
Wolfgang Denka1be4762008-05-20 16:00:29 +02001771 beq pll_done /* if SSCS =b'1' then PLL has */
1772 /* already been set */
1773 /* and CPU has been reset */
1774 /* so skip to next section */
stroese434979e2003-05-23 11:18:02 +00001775
Stefan Roese326c9712005-08-01 16:41:48 +02001776#ifdef CONFIG_BUBINGA
stroese434979e2003-05-23 11:18:02 +00001777 /*
wdenk57b2d802003-06-27 21:31:46 +00001778 !-----------------------------------------------------------------------
1779 ! Read NVRAM to get value to write in PLLMR.
1780 ! If value has not been correctly saved, write default value
1781 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1782 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1783 !
1784 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001785 ! structure in openbios.h. Changing the beginning of
1786 ! the structure will break this code.
wdenk57b2d802003-06-27 21:31:46 +00001787 !
1788 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001789 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001790 addis r3,0,NVRAM_BASE@h
1791 addi r3,r3,NVRAM_BASE@l
stroese434979e2003-05-23 11:18:02 +00001792
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001793 lwz r4, 0(r3)
1794 addis r5,0,NVRVFY1@h
1795 addi r5,r5,NVRVFY1@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001796 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001797 bne ..no_pllset
1798 addi r3,r3,4
1799 lwz r4, 0(r3)
1800 addis r5,0,NVRVFY2@h
1801 addi r5,r5,NVRVFY2@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001802 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001803 bne ..no_pllset
1804 addi r3,r3,8 /* Skip over conf_size */
1805 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1806 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1807 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1808 cmpi cr0,0,r5,1 /* See if PLL is locked */
1809 beq pll_write
stroese434979e2003-05-23 11:18:02 +00001810..no_pllset:
Stefan Roese326c9712005-08-01 16:41:48 +02001811#endif /* CONFIG_BUBINGA */
stroese434979e2003-05-23 11:18:02 +00001812
John Otken9aa36772007-07-26 17:49:11 +02001813#ifdef CONFIG_TAIHU
1814 mfdcr r4, CPC0_BOOT
1815 andi. r5, r4, CPC0_BOOT_SEP@l
1816 bne strap_1 /* serial eeprom present */
1817 addis r5,0,CPLD_REG0_ADDR@h
1818 ori r5,r5,CPLD_REG0_ADDR@l
1819 andi. r5, r5, 0x10
1820 bne _pci_66mhz
1821#endif /* CONFIG_TAIHU */
1822
Stefan Roesea5d182e2007-08-14 14:44:41 +02001823#if defined(CONFIG_ZEUS)
1824 mfdcr r4, CPC0_BOOT
1825 andi. r5, r4, CPC0_BOOT_SEP@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001826 bne strap_1 /* serial eeprom present */
Stefan Roesea5d182e2007-08-14 14:44:41 +02001827 lis r3,0x0000
1828 addi r3,r3,0x3030
1829 lis r4,0x8042
1830 addi r4,r4,0x223e
1831 b 1f
1832strap_1:
1833 mfdcr r3, CPC0_PLLMR0
1834 mfdcr r4, CPC0_PLLMR1
1835 b 1f
1836#endif
1837
Wolfgang Denka1be4762008-05-20 16:00:29 +02001838 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1839 ori r3,r3,PLLMR0_DEFAULT@l /* */
1840 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1841 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroese434979e2003-05-23 11:18:02 +00001842
John Otken9aa36772007-07-26 17:49:11 +02001843#ifdef CONFIG_TAIHU
1844 b 1f
1845_pci_66mhz:
1846 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1847 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1848 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1849 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1850 b 1f
1851strap_1:
1852 mfdcr r3, CPC0_PLLMR0
1853 mfdcr r4, CPC0_PLLMR1
John Otken9aa36772007-07-26 17:49:11 +02001854#endif /* CONFIG_TAIHU */
1855
Stefan Roesea5d182e2007-08-14 14:44:41 +020018561:
Wolfgang Denka1be4762008-05-20 16:00:29 +02001857 b pll_write /* Write the CPC0_PLLMR with new value */
stroese434979e2003-05-23 11:18:02 +00001858
1859pll_done:
wdenk57b2d802003-06-27 21:31:46 +00001860 /*
1861 !-----------------------------------------------------------------------
1862 ! Clear Soft Reset Register
1863 ! This is needed to enable PCI if not booting from serial EPROM
1864 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001865 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001866 addi r3, 0, 0x0
1867 mtdcr CPC0_SRR, r3
stroese434979e2003-05-23 11:18:02 +00001868
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001869 addis r3,0,0x0010
1870 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001871pci_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001872 bdnz pci_wait
stroese434979e2003-05-23 11:18:02 +00001873
Wolfgang Denka1be4762008-05-20 16:00:29 +02001874 blr /* return to main code */
stroese434979e2003-05-23 11:18:02 +00001875
1876/*
1877!-----------------------------------------------------------------------------
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001878! Function: pll_write
1879! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1880! That is:
1881! 1. Pll is first disabled (de-activated by putting in bypass mode)
1882! 2. PLL is reset
1883! 3. Clock dividers are set while PLL is held in reset and bypassed
1884! 4. PLL Reset is cleared
1885! 5. Wait 100us for PLL to lock
1886! 6. A core reset is performed
stroese434979e2003-05-23 11:18:02 +00001887! Input: r3 = Value to write to CPC0_PLLMR0
1888! Input: r4 = Value to write to CPC0_PLLMR1
1889! Output r3 = none
1890!-----------------------------------------------------------------------------
1891*/
Matthias Fuchsd8079162009-07-06 16:27:33 +02001892 .globl pll_write
stroese434979e2003-05-23 11:18:02 +00001893pll_write:
wdenk57b2d802003-06-27 21:31:46 +00001894 mfdcr r5, CPC0_UCR
1895 andis. r5,r5,0xFFFF
Wolfgang Denka1be4762008-05-20 16:00:29 +02001896 ori r5,r5,0x0101 /* Stop the UART clocks */
1897 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroese434979e2003-05-23 11:18:02 +00001898
wdenk57b2d802003-06-27 21:31:46 +00001899 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001900 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001901 mtdcr CPC0_PLLMR1,r5
Wolfgang Denka1be4762008-05-20 16:00:29 +02001902 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001903 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001904
Wolfgang Denka1be4762008-05-20 16:00:29 +02001905 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
1906 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
1907 oris r5,r5,0x4000 /* Set PLL Reset */
1908 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
1909 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001910 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001911
1912 /*
wdenk57b2d802003-06-27 21:31:46 +00001913 ! Wait min of 100us for PLL to lock.
1914 ! See CMOS 27E databook for more info.
1915 ! At 200MHz, that means waiting 20,000 instructions
stroese434979e2003-05-23 11:18:02 +00001916 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001917 addi r3,0,20000 /* 2000 = 0x4e20 */
1918 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001919pll_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001920 bdnz pll_wait
stroese434979e2003-05-23 11:18:02 +00001921
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001922 oris r5,r5,0x8000 /* Enable PLL */
1923 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroese434979e2003-05-23 11:18:02 +00001924
wdenk57b2d802003-06-27 21:31:46 +00001925 /*
1926 * Reset CPU to guarantee timings are OK
1927 * Not sure if this is needed...
1928 */
1929 addis r3,0,0x1000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001930 mtspr SPRN_DBCR0,r3 /* This will cause a CPU core reset, and */
Wolfgang Denka1be4762008-05-20 16:00:29 +02001931 /* execution will continue from the poweron */
1932 /* vector of 0xfffffffc */
stroese434979e2003-05-23 11:18:02 +00001933#endif /* CONFIG_405EP */
Stefan Roesea8856e32007-02-20 10:57:08 +01001934
1935#if defined(CONFIG_440)
Stefan Roesea8856e32007-02-20 10:57:08 +01001936/*----------------------------------------------------------------------------+
1937| mttlb3.
1938+----------------------------------------------------------------------------*/
1939 function_prolog(mttlb3)
1940 TLBWE(4,3,2)
1941 blr
1942 function_epilog(mttlb3)
1943
1944/*----------------------------------------------------------------------------+
1945| mftlb3.
1946+----------------------------------------------------------------------------*/
1947 function_prolog(mftlb3)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001948 TLBRE(3,3,2)
Stefan Roesea8856e32007-02-20 10:57:08 +01001949 blr
1950 function_epilog(mftlb3)
1951
1952/*----------------------------------------------------------------------------+
1953| mttlb2.
1954+----------------------------------------------------------------------------*/
1955 function_prolog(mttlb2)
1956 TLBWE(4,3,1)
1957 blr
1958 function_epilog(mttlb2)
1959
1960/*----------------------------------------------------------------------------+
1961| mftlb2.
1962+----------------------------------------------------------------------------*/
1963 function_prolog(mftlb2)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001964 TLBRE(3,3,1)
Stefan Roesea8856e32007-02-20 10:57:08 +01001965 blr
1966 function_epilog(mftlb2)
1967
1968/*----------------------------------------------------------------------------+
1969| mttlb1.
1970+----------------------------------------------------------------------------*/
1971 function_prolog(mttlb1)
1972 TLBWE(4,3,0)
1973 blr
1974 function_epilog(mttlb1)
1975
1976/*----------------------------------------------------------------------------+
1977| mftlb1.
1978+----------------------------------------------------------------------------*/
1979 function_prolog(mftlb1)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001980 TLBRE(3,3,0)
Stefan Roesea8856e32007-02-20 10:57:08 +01001981 blr
1982 function_epilog(mftlb1)
1983#endif /* CONFIG_440 */
Stefan Roese7d72e022008-06-02 14:35:44 +02001984
1985#if defined(CONFIG_NAND_SPL)
1986/*
1987 * void nand_boot_relocate(dst, src, bytes)
1988 *
1989 * r3 = Destination address to copy code to (in SDRAM)
1990 * r4 = Source address to copy code from
1991 * r5 = size to copy in bytes
1992 */
1993nand_boot_relocate:
1994 mr r6,r3
1995 mr r7,r4
1996 mflr r8
1997
1998 /*
1999 * Copy SPL from icache into SDRAM
2000 */
2001 subi r3,r3,4
2002 subi r4,r4,4
2003 srwi r5,r5,2
2004 mtctr r5
2005..spl_loop:
2006 lwzu r0,4(r4)
2007 stwu r0,4(r3)
2008 bdnz ..spl_loop
2009
2010 /*
2011 * Calculate "corrected" link register, so that we "continue"
2012 * in execution in destination range
2013 */
2014 sub r3,r7,r6 /* r3 = src - dst */
2015 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2016 mtlr r8
2017 blr
2018
2019nand_boot_common:
2020 /*
2021 * First initialize SDRAM. It has to be available *before* calling
2022 * nand_boot().
2023 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002024 lis r3,CONFIG_SYS_SDRAM_BASE@h
2025 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002026 bl initdram
2027
2028 /*
2029 * Now copy the 4k SPL code into SDRAM and continue execution
2030 * from there.
2031 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002032 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2033 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2034 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2035 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2036 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2037 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002038 bl nand_boot_relocate
2039
2040 /*
2041 * We're running from SDRAM now!!!
2042 *
2043 * It is necessary for 4xx systems to relocate from running at
2044 * the original location (0xfffffxxx) to somewhere else (SDRAM
2045 * preferably). This is because CS0 needs to be reconfigured for
2046 * NAND access. And we can't reconfigure this CS when currently
2047 * "running" from it.
2048 */
2049
2050 /*
2051 * Finally call nand_boot() to load main NAND U-Boot image from
2052 * NAND and jump to it.
2053 */
2054 bl nand_boot /* will not return */
2055#endif /* CONFIG_NAND_SPL */