blob: 7633abc1a16bc24bc146d185b5e1e16fd06da40b [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/*
Robert P. J. Day8d56db92016-07-15 13:44:45 -0400147 * Unless otherwise overridden, 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
wdenk0442ed82002-11-03 10:24:00 +0000185
186/*
187 * Set up GOT: Global Offset Table
188 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100189 * Use r12 to access the GOT
wdenk0442ed82002-11-03 10:24:00 +0000190 */
Stefan Roeseb3859f22014-03-04 15:34:35 +0100191#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000192 START_GOT
193 GOT_ENTRY(_GOT2_TABLE_)
194 GOT_ENTRY(_FIXUP_TABLE_)
195
196 GOT_ENTRY(_start)
197 GOT_ENTRY(_start_of_vectors)
198 GOT_ENTRY(_end_of_vectors)
199 GOT_ENTRY(transfer_to_handler)
200
wdenkb9a83a92003-05-30 12:48:29 +0000201 GOT_ENTRY(__init_end)
Simon Glassed70c8f2013-03-14 06:54:53 +0000202 GOT_ENTRY(__bss_end)
wdenkbf2f8c92003-05-22 22:52:13 +0000203 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000204 END_GOT
Stefan Roeseb3859f22014-03-04 15:34:35 +0100205#endif /* CONFIG_SPL_BUILD */
wdenk0442ed82002-11-03 10:24:00 +0000206
Ricardo Ribalda Delgadob3843812010-12-07 14:27:56 +0100207#if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_BOOT_FROM_XMD)
Stefan Roesec20ef322009-05-11 13:46:14 +0200208 /*
209 * 4xx RAM-booting U-Boot image is started from offset 0
210 */
211 .text
212 bl _start_440
213#endif
214
Stefan Roese07038ad2013-04-02 10:37:04 +0200215#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
216 /*
217 * This is the entry of the real U-Boot from a board port
218 * that supports SPL booting on the PPC4xx. We only need
219 * to call board_init_f() here. Everything else has already
220 * been done in the SPL u-boot version.
221 */
222 GET_GOT /* initialize GOT access */
223 bl board_init_f /* run 1st part of board init code (in Flash)*/
224 /* NOTREACHED - board_init_f() does not return */
225#endif
226
wdenk0442ed82002-11-03 10:24:00 +0000227/*
228 * 440 Startup -- on reset only the top 4k of the effective
229 * address space is mapped in by an entry in the instruction
230 * and data shadow TLB. The .bootpg section is located in the
231 * top 4k & does only what's necessary to map in the the rest
232 * of the boot rom. Once the boot rom is mapped in we can
233 * proceed with normal startup.
234 *
235 * NOTE: CS0 only covers the top 2MB of the effective address
236 * space after reset.
237 */
238
239#if defined(CONFIG_440)
240 .section .bootpg,"ax"
241 .globl _start_440
242
243/**************************************************************************/
244_start_440:
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200245 /*--------------------------------------------------------------------+
246 | 440EPX BUP Change - Hardware team request
247 +--------------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200248#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
249 sync
250 nop
251 nop
252#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200253 /*----------------------------------------------------------------+
254 | Core bug fix. Clear the esr
255 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200256 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200257 mtspr SPRN_ESR,r0
wdenk0442ed82002-11-03 10:24:00 +0000258 /*----------------------------------------------------------------*/
259 /* Clear and set up some registers. */
260 /*----------------------------------------------------------------*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200261 iccci r0,r0 /* NOTE: operands not used for 440 */
262 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000263 sync
264 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200265 mtspr SPRN_SRR0,r0
266 mtspr SPRN_SRR1,r0
267 mtspr SPRN_CSRR0,r0
268 mtspr SPRN_CSRR1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200269 /* NOTE: 440GX adds machine check status regs */
270#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200271 mtspr SPRN_MCSRR0,r0
272 mtspr SPRN_MCSRR1,r0
273 mfspr r1,SPRN_MCSR
274 mtspr SPRN_MCSR,r1
wdenk544e9732004-02-06 23:19:44 +0000275#endif
Stefan Roese0100cc12006-11-22 13:20:50 +0100276
277 /*----------------------------------------------------------------*/
278 /* CCR0 init */
279 /*----------------------------------------------------------------*/
280 /* Disable store gathering & broadcast, guarantee inst/data
281 * cache block touch, force load/store alignment
282 * (see errata 1.12: 440_33)
283 */
284 lis r1,0x0030 /* store gathering & broadcast disable */
285 ori r1,r1,0x6000 /* cache touch */
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200286 mtspr SPRN_CCR0,r1
Stefan Roese0100cc12006-11-22 13:20:50 +0100287
wdenk0442ed82002-11-03 10:24:00 +0000288 /*----------------------------------------------------------------*/
289 /* Initialize debug */
290 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200291 mfspr r1,SPRN_DBCR0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200292 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
293 bne skip_debug_init /* if set, don't clear debug register */
Victor Gallardob52cde92010-09-16 11:32:04 -0700294 mfspr r1,SPRN_CCR0
295 ori r1,r1,CCR0_DTB@l /* Disable Trace Broadcast */
296 mtspr SPRN_CCR0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200297 mtspr SPRN_DBCR0,r0
298 mtspr SPRN_DBCR1,r0
299 mtspr SPRN_DBCR2,r0
300 mtspr SPRN_IAC1,r0
301 mtspr SPRN_IAC2,r0
302 mtspr SPRN_IAC3,r0
303 mtspr SPRN_DAC1,r0
304 mtspr SPRN_DAC2,r0
305 mtspr SPRN_DVC1,r0
306 mtspr SPRN_DVC2,r0
wdenk0442ed82002-11-03 10:24:00 +0000307
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200308 mfspr r1,SPRN_DBSR
309 mtspr SPRN_DBSR,r1 /* Clear all valid bits */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200310skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000311
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200312#if defined (CONFIG_440SPE)
313 /*----------------------------------------------------------------+
314 | Initialize Core Configuration Reg1.
315 | a. ICDPEI: Record even parity. Normal operation.
316 | b. ICTPEI: Record even parity. Normal operation.
317 | c. DCTPEI: Record even parity. Normal operation.
318 | d. DCDPEI: Record even parity. Normal operation.
319 | e. DCUPEI: Record even parity. Normal operation.
320 | f. DCMPEI: Record even parity. Normal operation.
321 | g. FCOM: Normal operation
322 | h. MMUPEI: Record even parity. Normal operation.
323 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200324 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200325 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200326 li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200327 mtspr SPRN_CCR1, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200328
329 /*----------------------------------------------------------------+
330 | Reset the timebase.
331 | The previous write to CCR1 sets the timebase source.
332 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200333 mtspr SPRN_TBWL, r0
334 mtspr SPRN_TBWU, r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200335#endif
336
wdenk0442ed82002-11-03 10:24:00 +0000337 /*----------------------------------------------------------------*/
338 /* Setup interrupt vectors */
339 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200340 mtspr SPRN_IVPR,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200341 li r1,0x0100
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200342 mtspr SPRN_IVOR0,r1 /* Critical input */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200343 li r1,0x0200
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200344 mtspr SPRN_IVOR1,r1 /* Machine check */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200345 li r1,0x0300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200346 mtspr SPRN_IVOR2,r1 /* Data storage */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200347 li r1,0x0400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200348 mtspr SPRN_IVOR3,r1 /* Instruction storage */
wdenk0442ed82002-11-03 10:24:00 +0000349 li r1,0x0500
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200350 mtspr SPRN_IVOR4,r1 /* External interrupt */
wdenk0442ed82002-11-03 10:24:00 +0000351 li r1,0x0600
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200352 mtspr SPRN_IVOR5,r1 /* Alignment */
wdenk0442ed82002-11-03 10:24:00 +0000353 li r1,0x0700
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200354 mtspr SPRN_IVOR6,r1 /* Program check */
wdenk0442ed82002-11-03 10:24:00 +0000355 li r1,0x0800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200356 mtspr SPRN_IVOR7,r1 /* Floating point unavailable */
wdenk0442ed82002-11-03 10:24:00 +0000357 li r1,0x0c00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200358 mtspr SPRN_IVOR8,r1 /* System call */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200359 li r1,0x0a00
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200360 mtspr SPRN_IVOR9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200361 li r1,0x0900
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200362 mtspr SPRN_IVOR10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000363 li r1,0x1300
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200364 mtspr SPRN_IVOR13,r1 /* Data TLB error */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200365 li r1,0x1400
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200366 mtspr SPRN_IVOR14,r1 /* Instr TLB error */
wdenk0442ed82002-11-03 10:24:00 +0000367 li r1,0x2000
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200368 mtspr SPRN_IVOR15,r1 /* Debug */
wdenk0442ed82002-11-03 10:24:00 +0000369
370 /*----------------------------------------------------------------*/
371 /* Configure cache regions */
372 /*----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200373 mtspr SPRN_INV0,r0
374 mtspr SPRN_INV1,r0
375 mtspr SPRN_INV2,r0
376 mtspr SPRN_INV3,r0
377 mtspr SPRN_DNV0,r0
378 mtspr SPRN_DNV1,r0
379 mtspr SPRN_DNV2,r0
380 mtspr SPRN_DNV3,r0
381 mtspr SPRN_ITV0,r0
382 mtspr SPRN_ITV1,r0
383 mtspr SPRN_ITV2,r0
384 mtspr SPRN_ITV3,r0
385 mtspr SPRN_DTV0,r0
386 mtspr SPRN_DTV1,r0
387 mtspr SPRN_DTV2,r0
388 mtspr SPRN_DTV3,r0
wdenk0442ed82002-11-03 10:24:00 +0000389
390 /*----------------------------------------------------------------*/
391 /* Cache victim limits */
392 /*----------------------------------------------------------------*/
393 /* floors 0, ceiling max to use the entire cache -- nothing locked
394 */
395 lis r1,0x0001
396 ori r1,r1,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200397 mtspr SPRN_IVLIM,r1
398 mtspr SPRN_DVLIM,r1
wdenk0442ed82002-11-03 10:24:00 +0000399
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200400 /*----------------------------------------------------------------+
401 |Initialize MMUCR[STID] = 0.
402 +-----------------------------------------------------------------*/
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200403 mfspr r0,SPRN_MMUCR
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200404 addis r1,0,0xFFFF
405 ori r1,r1,0xFF00
406 and r0,r0,r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200407 mtspr SPRN_MMUCR,r0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200408
wdenk0442ed82002-11-03 10:24:00 +0000409 /*----------------------------------------------------------------*/
410 /* Clear all TLB entries -- TID = 0, TS = 0 */
411 /*----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200412 addis r0,0,0x0000
Stefan Roesed0c43952009-07-14 15:53:08 +0200413#ifdef CONFIG_SYS_RAMBOOT
Stefan Roesec20ef322009-05-11 13:46:14 +0200414 li r4,0 /* Start with TLB #0 */
Stefan Roesed0c43952009-07-14 15:53:08 +0200415#else
416 li r4,1 /* Start with TLB #1 */
417#endif
418 li r1,64 /* 64 TLB entries */
419 sub r1,r1,r4 /* calculate last TLB # */
420 mtctr r1
Stefan Roesec20ef322009-05-11 13:46:14 +0200421rsttlb:
422#ifdef CONFIG_SYS_RAMBOOT
423 tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
424 rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
425 beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
426#endif
427 tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
428 tlbwe r0,r4,1
429 tlbwe r0,r4,2
430tlbnxt: addi r4,r4,1 /* Next TLB */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200431 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000432
433 /*----------------------------------------------------------------*/
434 /* TLB entry setup -- step thru tlbtab */
435 /*----------------------------------------------------------------*/
Stefan Roese97251f92010-04-09 14:03:59 +0200436#if defined(CONFIG_440SPE_REVA)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200437 /*----------------------------------------------------------------*/
438 /* We have different TLB tables for revA and rev B of 440SPe */
439 /*----------------------------------------------------------------*/
440 mfspr r1, PVR
441 lis r0,0x5342
442 ori r0,r0,0x1891
443 cmpw r7,r1,r0
444 bne r7,..revA
445 bl tlbtabB
446 b ..goon
447..revA:
448 bl tlbtabA
449..goon:
450#else
wdenk0442ed82002-11-03 10:24:00 +0000451 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200452#endif
wdenk0442ed82002-11-03 10:24:00 +0000453 mr r5,r0
454 li r1,0x003f /* 64 TLB entries max */
455 mtctr r1
456 li r4,0 /* TLB # */
457
458 addi r5,r5,-4
Stefan Roesec20ef322009-05-11 13:46:14 +02004591:
460#ifdef CONFIG_SYS_RAMBOOT
461 tlbre r3,r4,0 /* Read contents from TLB word #0 */
462 rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
463 bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
464#endif
465 lwzu r0,4(r5)
wdenk0442ed82002-11-03 10:24:00 +0000466 cmpwi r0,0
467 beq 2f /* 0 marks end */
468 lwzu r1,4(r5)
469 lwzu r2,4(r5)
470 tlbwe r0,r4,0 /* TLB Word 0 */
471 tlbwe r1,r4,1 /* TLB Word 1 */
472 tlbwe r2,r4,2 /* TLB Word 2 */
Stefan Roesec20ef322009-05-11 13:46:14 +0200473tlbnx2: addi r4,r4,1 /* Next TLB */
wdenk0442ed82002-11-03 10:24:00 +0000474 bdnz 1b
475
476 /*----------------------------------------------------------------*/
477 /* Continue from 'normal' start */
478 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +02004792:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200480 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000481 b _start
482
4833: li r0,0
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200484 mtspr SPRN_SRR1,r0 /* Keep things disabled for now */
wdenk0442ed82002-11-03 10:24:00 +0000485 mflr r1
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200486 mtspr SPRN_SRR0,r1
wdenk0442ed82002-11-03 10:24:00 +0000487 rfi
stroese434979e2003-05-23 11:18:02 +0000488#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000489
490/*
491 * r3 - 1st arg to board_init(): IMMP pointer
492 * r4 - 2nd arg to board_init(): boot flag
493 */
Stefan Roeseb3859f22014-03-04 15:34:35 +0100494#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +0000495 .text
496 .long 0x27051956 /* U-Boot Magic Number */
497 .globl version_string
498version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +0200499 .ascii U_BOOT_VERSION_STRING, "\0"
wdenk0442ed82002-11-03 10:24:00 +0000500
wdenk0442ed82002-11-03 10:24:00 +0000501 . = EXC_OFF_SYS_RESET
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200502 .globl _start_of_vectors
503_start_of_vectors:
504
505/* Critical input. */
506 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
507
508#ifdef CONFIG_440
509/* Machine check */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200510 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200511#else
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200512 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200513#endif /* CONFIG_440 */
514
515/* Data Storage exception. */
516 STD_EXCEPTION(0x300, DataStorage, UnknownException)
517
518/* Instruction Storage exception. */
519 STD_EXCEPTION(0x400, InstStorage, UnknownException)
520
521/* External Interrupt exception. */
522 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
523
524/* Alignment exception. */
525 . = 0x600
526Alignment:
527 EXCEPTION_PROLOG(SRR0, SRR1)
528 mfspr r4,DAR
529 stw r4,_DAR(r21)
530 mfspr r5,DSISR
531 stw r5,_DSISR(r21)
532 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100533 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200534
535/* Program check exception */
536 . = 0x700
537ProgramCheck:
538 EXCEPTION_PROLOG(SRR0, SRR1)
539 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100540 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
541 MSR_KERNEL, COPY_EE)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200542
543#ifdef CONFIG_440
544 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
545 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
546 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roese80d99a42007-06-19 16:42:31 +0200547#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200548 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
549
550#ifdef CONFIG_440
551 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
552 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
553#else
554 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
555 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
556 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
557#endif
558 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
559
560 .globl _end_of_vectors
561_end_of_vectors:
562 . = _START_OFFSET
Stefan Roese42fbddd2006-09-07 11:51:23 +0200563#endif
wdenk0442ed82002-11-03 10:24:00 +0000564 .globl _start
565_start:
566
Stefan Roese07038ad2013-04-02 10:37:04 +0200567#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
568 /*
569 * This is the entry of the real U-Boot from a board port
570 * that supports SPL booting on the PPC4xx. We only need
571 * to call board_init_f() here. Everything else has already
572 * been done in the SPL u-boot version.
573 */
574 GET_GOT /* initialize GOT access */
575 bl board_init_f /* run 1st part of board init code (in Flash)*/
576 /* NOTREACHED - board_init_f() does not return */
577#endif
578
wdenk0442ed82002-11-03 10:24:00 +0000579/*****************************************************************************/
580#if defined(CONFIG_440)
581
582 /*----------------------------------------------------------------*/
583 /* Clear and set up some registers. */
584 /*----------------------------------------------------------------*/
585 li r0,0x0000
586 lis r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200587 mtspr SPRN_DEC,r0 /* prevent dec exceptions */
588 mtspr SPRN_TBWL,r0 /* prevent fit & wdt exceptions */
589 mtspr SPRN_TBWU,r0
590 mtspr SPRN_TSR,r1 /* clear all timer exception status */
591 mtspr SPRN_TCR,r0 /* disable all */
592 mtspr SPRN_ESR,r0 /* clear exception syndrome register */
wdenk0442ed82002-11-03 10:24:00 +0000593 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000594
595 /*----------------------------------------------------------------*/
596 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200597 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000598 /* value you need in this case 0x8cff 0000 should do the trick */
599 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200600#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000601 lis r1,0xffff
602 ori r1,r1,0xffff
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200603 mtspr SPRN_DBSR,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200604 lis r0,CONFIG_SYS_INIT_DBCR@h
605 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200606 mtspr SPRN_DBCR0,r0
wdenk0442ed82002-11-03 10:24:00 +0000607 isync
608#endif
609
610 /*----------------------------------------------------------------*/
611 /* Setup the internal SRAM */
612 /*----------------------------------------------------------------*/
613 li r0,0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200614
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200615#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roese326c9712005-08-01 16:41:48 +0200616 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200617 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
618 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200619 addis r4,r0,CONFIG_SYS_INIT_RAM_SIZE@h
620 ori r4,r4,CONFIG_SYS_INIT_RAM_SIZE@l
Stefan Roese326c9712005-08-01 16:41:48 +0200621 rlwinm. r5,r4,0,27,31
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200622 rlwinm r5,r4,27,5,31
623 beq ..d_ran
624 addi r5,r5,0x0001
Stefan Roese326c9712005-08-01 16:41:48 +0200625..d_ran:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200626 mtctr r5
Stefan Roese326c9712005-08-01 16:41:48 +0200627..d_ag:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200628 dcbz r0,r3
629 addi r3,r3,32
630 bdnz ..d_ag
Stefan Roesea86bde32008-01-09 10:23:16 +0100631
632 /*
633 * Lock the init-ram/stack in d-cache, so that other regions
634 * may use d-cache as well
635 * Note, that this current implementation locks exactly 4k
636 * of d-cache, so please make sure that you don't define a
637 * bigger init-ram area. Take a look at the lwmon5 440EPx
638 * implementation as a reference.
639 */
640 msync
641 isync
642 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
643 lis r1,0x0201
644 ori r1,r1,0xf808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200645 mtspr SPRN_DVLIM,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100646 lis r1,0x0808
647 ori r1,r1,0x0808
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200648 mtspr SPRN_DNV0,r1
649 mtspr SPRN_DNV1,r1
650 mtspr SPRN_DNV2,r1
651 mtspr SPRN_DNV3,r1
652 mtspr SPRN_DTV0,r1
653 mtspr SPRN_DTV1,r1
654 mtspr SPRN_DTV2,r1
655 mtspr SPRN_DTV3,r1
Stefan Roesea86bde32008-01-09 10:23:16 +0100656 msync
657 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200658#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200659
660 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
661#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
662 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roesecc019d12008-03-11 15:05:50 +0100663#if defined(CONFIG_440GX) || \
664 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -0700665 defined(CONFIG_460SX)
Dave Mitchell3c3734172008-11-20 14:00:49 -0600666 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
Masahiro Yamadae168aae2014-09-29 01:37:59 +0900667#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
Dave Mitchell5c057592008-11-20 14:09:50 -0600668 lis r1, 0x0000
669 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
670 mtdcr L2_CACHE_CFG,r1
wdenk544e9732004-02-06 23:19:44 +0000671#endif
wdenk0442ed82002-11-03 10:24:00 +0000672
Stefan Roese42fbddd2006-09-07 11:51:23 +0200673 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000674 ori r2,r2,0xffff
Dave Mitchell3c3734172008-11-20 14:00:49 -0600675 mfdcr r1,ISRAM0_DPC
wdenk0442ed82002-11-03 10:24:00 +0000676 and r1,r1,r2 /* Disable parity check */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600677 mtdcr ISRAM0_DPC,r1
678 mfdcr r1,ISRAM0_PMEG
Stefan Roese42fbddd2006-09-07 11:51:23 +0200679 and r1,r1,r2 /* Disable pwr mgmt */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600680 mtdcr ISRAM0_PMEG,r1
wdenk0442ed82002-11-03 10:24:00 +0000681
682 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese99644742005-11-29 18:18:21 +0100683#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000684 ori r1,r1,0x0980 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600685 mtdcr ISRAM0_SB0CR,r1
wdenk544e9732004-02-06 23:19:44 +0000686 lis r1,0x8001
687 ori r1,r1,0x0980 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600688 mtdcr ISRAM0_SB1CR,r1
wdenk544e9732004-02-06 23:19:44 +0000689 lis r1, 0x8002
690 ori r1,r1, 0x0980 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600691 mtdcr ISRAM0_SB2CR,r1
wdenk544e9732004-02-06 23:19:44 +0000692 lis r1, 0x8003
693 ori r1,r1, 0x0980 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600694 mtdcr ISRAM0_SB3CR,r1
Tirumala Marri95ac4282010-09-28 14:15:14 -0700695#elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || \
Masahiro Yamadae168aae2014-09-29 01:37:59 +0900696 defined(CONFIG_460GT)
Dave Mitchell5c057592008-11-20 14:09:50 -0600697 lis r1,0x0000 /* BAS = X_0000_0000 */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200698 ori r1,r1,0x0984 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600699 mtdcr ISRAM0_SB0CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200700 lis r1,0x0001
701 ori r1,r1,0x0984 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600702 mtdcr ISRAM0_SB1CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200703 lis r1, 0x0002
704 ori r1,r1, 0x0984 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600705 mtdcr ISRAM0_SB2CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200706 lis r1, 0x0003
707 ori r1,r1, 0x0984 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600708 mtdcr ISRAM0_SB3CR,r1
Masahiro Yamadae168aae2014-09-29 01:37:59 +0900709#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
Dave Mitchell5c057592008-11-20 14:09:50 -0600710 lis r2,0x7fff
711 ori r2,r2,0xffff
712 mfdcr r1,ISRAM1_DPC
713 and r1,r1,r2 /* Disable parity check */
Wolfgang Denk55334c72008-12-16 01:02:17 +0100714 mtdcr ISRAM1_DPC,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600715 mfdcr r1,ISRAM1_PMEG
716 and r1,r1,r2 /* Disable pwr mgmt */
717 mtdcr ISRAM1_PMEG,r1
718
719 lis r1,0x0004 /* BAS = 4_0004_0000 */
Tirumala Marri95ac4282010-09-28 14:15:14 -0700720 ori r1,r1,ISRAM1_SIZE /* ocm size */
Dave Mitchell5c057592008-11-20 14:09:50 -0600721 mtdcr ISRAM1_SB0CR,r1
722#endif
Feng Kan224bc962008-07-08 22:47:31 -0700723#elif defined(CONFIG_460SX)
724 lis r1,0x0000 /* BAS = 0000_0000 */
725 ori r1,r1,0x0B84 /* first 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600726 mtdcr ISRAM0_SB0CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700727 lis r1,0x0001
728 ori r1,r1,0x0B84 /* second 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600729 mtdcr ISRAM0_SB1CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700730 lis r1, 0x0002
731 ori r1,r1, 0x0B84 /* third 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600732 mtdcr ISRAM0_SB2CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700733 lis r1, 0x0003
734 ori r1,r1, 0x0B84 /* fourth 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600735 mtdcr ISRAM0_SB3CR,r1
Stefan Roese42fbddd2006-09-07 11:51:23 +0200736#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000737 ori r1,r1,0x0380 /* 8k rw */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600738 mtdcr ISRAM0_SB0CR,r1
739 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
Stefan Roese326c9712005-08-01 16:41:48 +0200740#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200741#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000742
743 /*----------------------------------------------------------------*/
744 /* Setup the stack in internal SRAM */
745 /*----------------------------------------------------------------*/
Dirk Eibachbd855662016-08-01 16:34:49 +0200746 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
747 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
748 /*
749 * Reserve space for globals and store address for initialization
750 * with board_init_f_init_reserve() in r14
751 */
752 mr r3, r1
753 bl board_init_f_alloc_reserve
754 mr r1, r3
755 mr r14, r3
wdenk0442ed82002-11-03 10:24:00 +0000756 li r0,0
757 stwu r0,-4(r1)
758 stwu r0,-4(r1) /* Terminate call chain */
759
760 stwu r1,-8(r1) /* Save back chain and move SP */
761 lis r0,RESET_VECTOR@h /* Address of reset vector */
762 ori r0,r0, RESET_VECTOR@l
763 stwu r1,-8(r1) /* Save back chain and move SP */
764 stw r0,+12(r1) /* Save return addr (underflow vect) */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200765
Stefan Roese07038ad2013-04-02 10:37:04 +0200766#ifndef CONFIG_SPL_BUILD
wdenk0442ed82002-11-03 10:24:00 +0000767 GET_GOT
Stefan Roese07038ad2013-04-02 10:37:04 +0200768#endif
Stefan Roesec443fe92005-11-22 13:20:42 +0100769
770 bl cpu_init_f /* run low-level CPU init code (from Flash) */
Dirk Eibachbd855662016-08-01 16:34:49 +0200771 /* address for globals was stored in r14 */
772 mr r3, r14
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +0100773 bl board_init_f_init_reserve
Simon Glasse2966012015-02-07 11:51:42 -0700774 li r3, 0
wdenk0442ed82002-11-03 10:24:00 +0000775 bl board_init_f
Peter Tyser0c44caf2010-09-14 19:13:53 -0500776 /* NOTREACHED - board_init_f() does not return */
wdenk0442ed82002-11-03 10:24:00 +0000777
778#endif /* CONFIG_440 */
779
780/*****************************************************************************/
Matthias Fuchse54a67f2013-08-07 12:10:38 +0200781#if defined(CONFIG_405GP) || \
Stefan Roese17ffbc82007-03-21 13:38:59 +0100782 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200783 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000784 /*----------------------------------------------------------------------- */
785 /* Clear and set up some registers. */
786 /*----------------------------------------------------------------------- */
787 addi r4,r0,0x0000
Stefan Roese153b3e22007-10-05 17:10:59 +0200788#if !defined(CONFIG_405EX)
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200789 mtspr SPRN_SGR,r4
Stefan Roese153b3e22007-10-05 17:10:59 +0200790#else
791 /*
792 * On 405EX, completely clearing the SGR leads to PPC hangup
793 * upon PCIe configuration access. The PCIe memory regions
794 * need to be guarded!
795 */
796 lis r3,0x0000
797 ori r3,r3,0x7FFC
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200798 mtspr SPRN_SGR,r3
Stefan Roese153b3e22007-10-05 17:10:59 +0200799#endif
Matthias Fuchs730b2d22009-07-22 17:27:56 +0200800 mtspr SPRN_DCWR,r4
wdenk0442ed82002-11-03 10:24:00 +0000801 mtesr r4 /* clear Exception Syndrome Reg */
802 mttcr r4 /* clear Timer Control Reg */
803 mtxer r4 /* clear Fixed-Point Exception Reg */
804 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000805 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
806 /* dbsr is cleared by setting bits to 1) */
807 mtdbsr r4 /* clear/reset the dbsr */
808
Grant Ericksonb6933412008-05-22 14:44:14 -0700809 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000810 bl invalidate_icache
811 bl invalidate_dcache
812
Grant Ericksonb6933412008-05-22 14:44:14 -0700813 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200814 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
815 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700816 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000817 isync
818
Grant Ericksonb6933412008-05-22 14:44:14 -0700819 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200820 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
821 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700822 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000823
Ricardo Ribalda Delgado78ea77e2008-10-21 18:29:46 +0200824#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
825 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000826 /*----------------------------------------------------------------------- */
827 /* Tune the speed and size for flash CS0 */
828 /*----------------------------------------------------------------------- */
829 bl ext_bus_cntlr_init
830#endif
Stefan Roese7d72e022008-06-02 14:35:44 +0200831
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200832#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roese153b3e22007-10-05 17:10:59 +0200833 /*
Grant Ericksonb6933412008-05-22 14:44:14 -0700834 * For boards that don't have OCM and can't use the data cache
835 * for their primordial stack, setup stack here directly after the
836 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roese153b3e22007-10-05 17:10:59 +0200837 */
Dirk Eibachbd855662016-08-01 16:34:49 +0200838 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
839 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
840 /*
841 * Reserve space for globals and store address for initialization
842 * with board_init_f_init_reserve() in r14
843 */
844 mr r3, r1
845 bl board_init_f_alloc_reserve
846 mr r1, r3
847 mr r14, r3
Stefan Roese153b3e22007-10-05 17:10:59 +0200848
849 li r0, 0 /* Make room for stack frame header and */
850 stwu r0, -4(r1) /* clear final stack frame so that */
851 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
852 /*
853 * Set up a dummy frame to store reset vector as return address.
854 * this causes stack underflow to reset board.
855 */
856 stwu r1, -8(r1) /* Save back chain and move SP */
857 lis r0, RESET_VECTOR@h /* Address of reset vector */
858 ori r0, r0, RESET_VECTOR@l
859 stwu r1, -8(r1) /* Save back chain and move SP */
860 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200861#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000862
stroese434979e2003-05-23 11:18:02 +0000863#if defined(CONFIG_405EP)
864 /*----------------------------------------------------------------------- */
865 /* DMA Status, clear to come up clean */
866 /*----------------------------------------------------------------------- */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200867 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200868 ori r3,r3, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200869 mtdcr DMASR, r3
stroese434979e2003-05-23 11:18:02 +0000870
Wolfgang Denka1be4762008-05-20 16:00:29 +0200871 bl ppc405ep_init /* do ppc405ep specific init */
stroese434979e2003-05-23 11:18:02 +0000872#endif /* CONFIG_405EP */
873
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200874#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roese17ffbc82007-03-21 13:38:59 +0100875#if defined(CONFIG_405EZ)
876 /********************************************************************
877 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
878 *******************************************************************/
879 /*
880 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200881 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roese17ffbc82007-03-21 13:38:59 +0100882 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200883 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
884 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese80d99a42007-06-19 16:42:31 +0200885 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200886 mtdcr OCM0_PLBCR1,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100887 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200888 mtdcr OCM0_PLBCR2,r3 /* Set PLB Access */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100889 isync
890
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200891 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
892 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200893 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese918010a2009-09-09 16:25:29 +0200894 mtdcr OCM0_DSRC1, r3 /* Set Data Side */
895 mtdcr OCM0_ISRC1, r3 /* Set Instruction Side */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100896 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Stefan Roese918010a2009-09-09 16:25:29 +0200897 mtdcr OCM0_DSRC2, r3 /* Set Data Side */
898 mtdcr OCM0_ISRC2, r3 /* Set Instruction Side */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200899 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roese918010a2009-09-09 16:25:29 +0200900 mtdcr OCM0_DISDPC,r3
Stefan Roese17ffbc82007-03-21 13:38:59 +0100901
902 isync
Stefan Roesef6c7b762007-03-24 15:45:34 +0100903#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000904 /********************************************************************
905 * Setup OCM - On Chip Memory
906 *******************************************************************/
907 /* Setup OCM */
wdenk57b2d802003-06-27 21:31:46 +0000908 lis r0, 0x7FFF
909 ori r0, r0, 0xFFFF
Stefan Roese918010a2009-09-09 16:25:29 +0200910 mfdcr r3, OCM0_ISCNTL /* get instr-side IRAM config */
911 mfdcr r4, OCM0_DSCNTL /* get data-side IRAM config */
Stefan Roesef6c7b762007-03-24 15:45:34 +0100912 and r3, r3, r0 /* disable data-side IRAM */
913 and r4, r4, r0 /* disable data-side IRAM */
Stefan Roese918010a2009-09-09 16:25:29 +0200914 mtdcr OCM0_ISCNTL, r3 /* set instr-side IRAM config */
915 mtdcr OCM0_DSCNTL, r4 /* set data-side IRAM config */
wdenk57b2d802003-06-27 21:31:46 +0000916 isync
wdenk0442ed82002-11-03 10:24:00 +0000917
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200918 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
919 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200920 mtdcr OCM0_DSARC, r3
wdenk0442ed82002-11-03 10:24:00 +0000921 addis r4, 0, 0xC000 /* OCM data area enabled */
Stefan Roese918010a2009-09-09 16:25:29 +0200922 mtdcr OCM0_DSCNTL, r4
wdenk57b2d802003-06-27 21:31:46 +0000923 isync
Stefan Roese17ffbc82007-03-21 13:38:59 +0100924#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +0000925#endif
926
927 /*----------------------------------------------------------------------- */
928 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
929 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200930#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonb6933412008-05-22 14:44:14 -0700931 li r4, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +0200932 mtdcr EBC0_CFGADDR, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200933 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
934 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Stefan Roese918010a2009-09-09 16:25:29 +0200935 mtdcr EBC0_CFGDATA, r4
wdenk0442ed82002-11-03 10:24:00 +0000936
Grant Ericksonb6933412008-05-22 14:44:14 -0700937 addi r4, 0, PBxCR
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_PBxCR@h
940 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@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 /*
944 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200945 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonb6933412008-05-22 14:44:14 -0700946 */
947 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200948 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
949 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +0000950 mtdccr r4
951
Grant Ericksonb6933412008-05-22 14:44:14 -0700952 /*
953 * Preallocate data cache lines to be used to avoid a subsequent
954 * cache miss and an ensuing machine check exception when exceptions
955 * are enabled.
956 */
957 li r0, 0
958
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200959 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
960 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +0000961
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200962 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
963 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +0000964
Grant Ericksonb6933412008-05-22 14:44:14 -0700965 /*
966 * Convert the size, in bytes, to the number of cache lines/blocks
967 * to preallocate.
968 */
969 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
970 srwi r5, r4, L1_CACHE_SHIFT
971 beq ..load_counter
972 addi r5, r5, 0x0001
973..load_counter:
974 mtctr r5
975
976 /* Preallocate the computed number of cache blocks. */
977..alloc_dcache_block:
978 dcba r0, r3
979 addi r3, r3, L1_CACHE_BYTES
980 bdnz ..alloc_dcache_block
981 sync
982
983 /*
984 * Load the initial stack pointer and data area and convert the size,
985 * in bytes, to the number of words to initialize to a known value.
986 */
Dirk Eibachbd855662016-08-01 16:34:49 +0200987 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
988 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
989 /*
990 * Reserve space for globals and store address for initialization
991 * with board_init_f_init_reserve() in r14
992 */
993 mr r3, r1
994 bl board_init_f_alloc_reserve
995 mr r1, r3
996 mr r14, r3
Grant Ericksonb6933412008-05-22 14:44:14 -0700997
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +0200998 lis r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@h
999 ori r4, r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +00001000 mtctr r4
1001
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001002 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001003 ori r2, r2, CONFIG_SYS_INIT_RAM_SIZE@l
wdenk0442ed82002-11-03 10:24:00 +00001004
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001005 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1006 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001007
1008..stackloop:
Grant Ericksonb6933412008-05-22 14:44:14 -07001009 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001010 bdnz ..stackloop
1011
Grant Ericksonb6933412008-05-22 14:44:14 -07001012 /*
1013 * Make room for stack frame header and clear final stack frame so
1014 * that stack backtraces terminate cleanly.
1015 */
Dirk Eibachbd855662016-08-01 16:34:49 +02001016 li r0, 0
Grant Ericksonb6933412008-05-22 14:44:14 -07001017 stwu r0, -4(r1)
1018 stwu r0, -4(r1)
1019
wdenk0442ed82002-11-03 10:24:00 +00001020 /*
1021 * Set up a dummy frame to store reset vector as return address.
1022 * this causes stack underflow to reset board.
1023 */
1024 stwu r1, -8(r1) /* Save back chain and move SP */
1025 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1026 ori r0, r0, RESET_VECTOR@l
1027 stwu r1, -8(r1) /* Save back chain and move SP */
1028 stw r0, +12(r1) /* Save return addr (underflow vect) */
1029
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001030#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1031 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001032 /*
1033 * Stack in OCM.
1034 */
Dirk Eibachbd855662016-08-01 16:34:49 +02001035 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
1036 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
1037 /*
1038 * Reserve space for globals and store address for initialization
1039 * with board_init_f_init_reserve() in r14
1040 */
1041 mr r3, r1
1042 bl board_init_f_alloc_reserve
1043 mr r1, r3
1044 mr r14, r3
wdenk0442ed82002-11-03 10:24:00 +00001045
1046 /* Set up a zeroized stack frame so that backtrace works right */
1047 li r0, 0
1048 stwu r0, -4(r1)
1049 stwu r0, -4(r1)
1050
1051 /*
1052 * Set up a dummy frame to store reset vector as return address.
1053 * this causes stack underflow to reset board.
1054 */
1055 stwu r1, -8(r1) /* Save back chain and move SP */
1056 lis r0, RESET_VECTOR@h /* Address of reset vector */
1057 ori r0, r0, RESET_VECTOR@l
1058 stwu r1, -8(r1) /* Save back chain and move SP */
1059 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001060#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001061
wdenk0442ed82002-11-03 10:24:00 +00001062 GET_GOT /* initialize GOT access */
1063
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001064 bl cpu_init_f /* run low-level CPU init code (from Flash) */
Dirk Eibachbd855662016-08-01 16:34:49 +02001065 /* address for globals was stored in r14 */
1066 mr r3, r14
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +01001067 bl board_init_f_init_reserve
Simon Glasse2966012015-02-07 11:51:42 -07001068 li r3, 0
wdenk0442ed82002-11-03 10:24:00 +00001069 bl board_init_f /* run first part of init code (from Flash) */
Peter Tyser0c44caf2010-09-14 19:13:53 -05001070 /* NOTREACHED - board_init_f() does not return */
1071
Matthias Fuchse54a67f2013-08-07 12:10:38 +02001072#endif /* CONFIG_405GP || CONFIG_405 || CONFIG_405EP */
wdenk232fe0b2003-09-02 22:48:03 +00001073 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001074
1075
Stefan Roeseb3859f22014-03-04 15:34:35 +01001076#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001077/*
1078 * This code finishes saving the registers to the exception frame
1079 * and jumps to the appropriate handler for the exception.
1080 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1081 */
1082 .globl transfer_to_handler
1083transfer_to_handler:
1084 stw r22,_NIP(r21)
1085 lis r22,MSR_POW@h
1086 andc r23,r23,r22
1087 stw r23,_MSR(r21)
1088 SAVE_GPR(7, r21)
1089 SAVE_4GPRS(8, r21)
1090 SAVE_8GPRS(12, r21)
1091 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001092 mflr r23
1093 andi. r24,r23,0x3f00 /* get vector offset */
1094 stw r24,TRAP(r21)
1095 li r22,0
1096 stw r22,RESULT(r21)
1097 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001098 lwz r24,0(r23) /* virtual address of handler */
1099 lwz r23,4(r23) /* where to go when done */
1100 mtspr SRR0,r24
1101 mtspr SRR1,r20
1102 mtlr r23
1103 SYNC
1104 rfi /* jump to handler, enable MMU */
1105
1106int_return:
1107 mfmsr r28 /* Disable interrupts */
1108 li r4,0
1109 ori r4,r4,MSR_EE
1110 andc r28,r28,r4
1111 SYNC /* Some chip revs need this... */
1112 mtmsr r28
1113 SYNC
1114 lwz r2,_CTR(r1)
1115 lwz r0,_LINK(r1)
1116 mtctr r2
1117 mtlr r0
1118 lwz r2,_XER(r1)
1119 lwz r0,_CCR(r1)
1120 mtspr XER,r2
1121 mtcrf 0xFF,r0
1122 REST_10GPRS(3, r1)
1123 REST_10GPRS(13, r1)
1124 REST_8GPRS(23, r1)
1125 REST_GPR(31, r1)
1126 lwz r2,_NIP(r1) /* Restore environment */
1127 lwz r0,_MSR(r1)
1128 mtspr SRR0,r2
1129 mtspr SRR1,r0
1130 lwz r0,GPR0(r1)
1131 lwz r2,GPR2(r1)
1132 lwz r1,GPR1(r1)
1133 SYNC
1134 rfi
1135
1136crit_return:
1137 mfmsr r28 /* Disable interrupts */
1138 li r4,0
1139 ori r4,r4,MSR_EE
1140 andc r28,r28,r4
1141 SYNC /* Some chip revs need this... */
1142 mtmsr r28
1143 SYNC
1144 lwz r2,_CTR(r1)
1145 lwz r0,_LINK(r1)
1146 mtctr r2
1147 mtlr r0
1148 lwz r2,_XER(r1)
1149 lwz r0,_CCR(r1)
1150 mtspr XER,r2
1151 mtcrf 0xFF,r0
1152 REST_10GPRS(3, r1)
1153 REST_10GPRS(13, r1)
1154 REST_8GPRS(23, r1)
1155 REST_GPR(31, r1)
1156 lwz r2,_NIP(r1) /* Restore environment */
1157 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001158 mtspr SPRN_CSRR0,r2
1159 mtspr SPRN_CSRR1,r0
wdenk0442ed82002-11-03 10:24:00 +00001160 lwz r0,GPR0(r1)
1161 lwz r2,GPR2(r1)
1162 lwz r1,GPR1(r1)
1163 SYNC
1164 rfci
1165
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001166#ifdef CONFIG_440
1167mck_return:
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001168 mfmsr r28 /* Disable interrupts */
1169 li r4,0
1170 ori r4,r4,MSR_EE
1171 andc r28,r28,r4
1172 SYNC /* Some chip revs need this... */
1173 mtmsr r28
1174 SYNC
1175 lwz r2,_CTR(r1)
1176 lwz r0,_LINK(r1)
1177 mtctr r2
1178 mtlr r0
1179 lwz r2,_XER(r1)
1180 lwz r0,_CCR(r1)
1181 mtspr XER,r2
1182 mtcrf 0xFF,r0
1183 REST_10GPRS(3, r1)
1184 REST_10GPRS(13, r1)
1185 REST_8GPRS(23, r1)
1186 REST_GPR(31, r1)
1187 lwz r2,_NIP(r1) /* Restore environment */
1188 lwz r0,_MSR(r1)
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001189 mtspr SPRN_MCSRR0,r2
1190 mtspr SPRN_MCSRR1,r0
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001191 lwz r0,GPR0(r1)
1192 lwz r2,GPR2(r1)
1193 lwz r1,GPR1(r1)
1194 SYNC
1195 rfmci
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001196#endif /* CONFIG_440 */
1197
1198
wdenk0442ed82002-11-03 10:24:00 +00001199 .globl get_pvr
1200get_pvr:
1201 mfspr r3, PVR
1202 blr
1203
wdenk0442ed82002-11-03 10:24:00 +00001204/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001205/* Function: out16 */
1206/* Description: Output 16 bits */
1207/*------------------------------------------------------------------------------- */
1208 .globl out16
1209out16:
1210 sth r4,0x0000(r3)
1211 blr
1212
1213/*------------------------------------------------------------------------------- */
1214/* Function: out16r */
1215/* Description: Byte reverse and output 16 bits */
1216/*------------------------------------------------------------------------------- */
1217 .globl out16r
1218out16r:
1219 sthbrx r4,r0,r3
1220 blr
1221
1222/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001223/* Function: out32r */
1224/* Description: Byte reverse and output 32 bits */
1225/*------------------------------------------------------------------------------- */
1226 .globl out32r
1227out32r:
1228 stwbrx r4,r0,r3
1229 blr
1230
1231/*------------------------------------------------------------------------------- */
1232/* Function: in16 */
1233/* Description: Input 16 bits */
1234/*------------------------------------------------------------------------------- */
1235 .globl in16
1236in16:
1237 lhz r3,0x0000(r3)
1238 blr
1239
1240/*------------------------------------------------------------------------------- */
1241/* Function: in16r */
1242/* Description: Input 16 bits and byte reverse */
1243/*------------------------------------------------------------------------------- */
1244 .globl in16r
1245in16r:
1246 lhbrx r3,r0,r3
1247 blr
1248
1249/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001250/* Function: in32r */
1251/* Description: Input 32 bits and byte reverse */
1252/*------------------------------------------------------------------------------- */
1253 .globl in32r
1254in32r:
1255 lwbrx r3,r0,r3
1256 blr
1257
Stefan Roese07038ad2013-04-02 10:37:04 +02001258#if !defined(CONFIG_SPL_BUILD)
wdenk0442ed82002-11-03 10:24:00 +00001259/*
1260 * void relocate_code (addr_sp, gd, addr_moni)
1261 *
1262 * This "function" does not return, instead it continues in RAM
1263 * after relocating the monitor code.
1264 *
Grant Ericksonb6933412008-05-22 14:44:14 -07001265 * r3 = Relocated stack pointer
1266 * r4 = Relocated global data pointer
1267 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001268 */
1269 .globl relocate_code
1270relocate_code:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001271#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001272 /*
Stefan Roese593a0fb2010-11-26 15:45:34 +01001273 * We need to flush the initial global data (gd_t) and bd_info
1274 * before the dcache will be invalidated.
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001275 */
1276
Grant Ericksonb6933412008-05-22 14:44:14 -07001277 /* Save registers */
1278 mr r9, r3
1279 mr r10, r4
1280 mr r11, r5
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001281
Stefan Roese593a0fb2010-11-26 15:45:34 +01001282 /*
1283 * Flush complete dcache, this is faster than flushing the
1284 * ranges for global_data and bd_info instead.
1285 */
1286 bl flush_dcache
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001287
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001288#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonb6933412008-05-22 14:44:14 -07001289 /*
1290 * Undo the earlier data cache set-up for the primordial stack and
1291 * data area. First, invalidate the data cache and then disable data
1292 * cacheability for that area. Finally, restore the EBC values, if
1293 * any.
1294 */
1295
1296 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001297 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1298 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001299
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001300 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
1301 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001302 add r4, r4, r3
1303
1304 bl invalidate_dcache_range
1305
1306 /* Disable cacheability for the region */
1307 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001308 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1309 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001310 and r3, r3, r4
1311 mtdccr r3
1312
1313 /* Restore the EBC parameters */
1314 li r3, PBxAP
Stefan Roese918010a2009-09-09 16:25:29 +02001315 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001316 lis r3, PBxAP_VAL@h
1317 ori r3, r3, PBxAP_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001318 mtdcr EBC0_CFGDATA, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001319
1320 li r3, PBxCR
Stefan Roese918010a2009-09-09 16:25:29 +02001321 mtdcr EBC0_CFGADDR, r3
Grant Ericksonb6933412008-05-22 14:44:14 -07001322 lis r3, PBxCR_VAL@h
1323 ori r3, r3, PBxCR_VAL@l
Stefan Roese918010a2009-09-09 16:25:29 +02001324 mtdcr EBC0_CFGDATA, r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001325#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonb6933412008-05-22 14:44:14 -07001326
1327 /* Restore registers */
1328 mr r3, r9
1329 mr r4, r10
1330 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001331#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesea86bde32008-01-09 10:23:16 +01001332
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001333#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesea86bde32008-01-09 10:23:16 +01001334 /*
1335 * Unlock the previously locked d-cache
1336 */
1337 msync
1338 isync
1339 /* set TFLOOR/NFLOOR to 0 again */
1340 lis r6,0x0001
1341 ori r6,r6,0xf800
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001342 mtspr SPRN_DVLIM,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001343 lis r6,0x0000
1344 ori r6,r6,0x0000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001345 mtspr SPRN_DNV0,r6
1346 mtspr SPRN_DNV1,r6
1347 mtspr SPRN_DNV2,r6
1348 mtspr SPRN_DNV3,r6
1349 mtspr SPRN_DTV0,r6
1350 mtspr SPRN_DTV1,r6
1351 mtspr SPRN_DTV2,r6
1352 mtspr SPRN_DTV3,r6
Stefan Roesea86bde32008-01-09 10:23:16 +01001353 msync
1354 isync
Stefan Roese04bb5fc2010-08-31 11:27:14 +02001355
1356 /* Invalidate data cache, now no longer our stack */
1357 dccci 0,0
1358 sync
1359 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001360#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesea86bde32008-01-09 10:23:16 +01001361
Stefan Roese9eba0c82006-06-02 16:18:04 +02001362 /*
1363 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1364 * to speed up the boot process. Now this cache needs to be disabled.
1365 */
Stefan Roese1d568062010-05-27 16:45:20 +02001366#if defined(CONFIG_440)
Stefan Roesefe05a022008-11-20 11:46:20 +01001367 /* Clear all potential pending exceptions */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001368 mfspr r1,SPRN_MCSR
1369 mtspr SPRN_MCSR,r1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001370 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Stefan Roese326c9712005-08-01 16:41:48 +02001371 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese99644742005-11-29 18:18:21 +01001372 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001373 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roese9eba0c82006-06-02 16:18:04 +02001374 sync
Stefan Roese326c9712005-08-01 16:41:48 +02001375 isync
Stefan Roese1d568062010-05-27 16:45:20 +02001376#endif /* defined(CONFIG_440) */
wdenk0442ed82002-11-03 10:24:00 +00001377 mr r1, r3 /* Set new stack pointer */
1378 mr r9, r4 /* Save copy of Init Data pointer */
1379 mr r10, r5 /* Save copy of Destination Address */
1380
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001381 GET_GOT
wdenk0442ed82002-11-03 10:24:00 +00001382 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001383 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1384 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +00001385 lwz r5, GOT(__init_end)
1386 sub r5, r5, r4
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001387 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001388
1389 /*
1390 * Fix GOT pointer:
1391 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001392 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001393 *
1394 * Offset:
1395 */
1396 sub r15, r10, r4
1397
1398 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001399 add r12, r12, r15
Grant Ericksonb6933412008-05-22 14:44:14 -07001400 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001401 add r30, r30, r15
1402
1403 /*
1404 * Now relocate code
1405 */
1406
1407 cmplw cr1,r3,r4
1408 addi r0,r5,3
1409 srwi. r0,r0,2
1410 beq cr1,4f /* In place copy is not necessary */
1411 beq 7f /* Protect against 0 count */
1412 mtctr r0
1413 bge cr1,2f
1414
1415 la r8,-4(r4)
1416 la r7,-4(r3)
14171: lwzu r0,4(r8)
1418 stwu r0,4(r7)
1419 bdnz 1b
1420 b 4f
1421
14222: slwi r0,r0,2
1423 add r8,r4,r0
1424 add r7,r3,r0
14253: lwzu r0,-4(r8)
1426 stwu r0,-4(r7)
1427 bdnz 3b
1428
1429/*
1430 * Now flush the cache: note that we must start from a cache aligned
1431 * address. Otherwise we might miss one cache line.
1432 */
14334: cmpwi r6,0
1434 add r5,r3,r5
1435 beq 7f /* Always flush prefetch queue in any case */
1436 subi r0,r6,1
1437 andc r3,r3,r0
1438 mr r4,r3
14395: dcbst 0,r4
1440 add r4,r4,r6
1441 cmplw r4,r5
1442 blt 5b
1443 sync /* Wait for all dcbst to complete on bus */
1444 mr r4,r3
14456: icbi 0,r4
1446 add r4,r4,r6
1447 cmplw r4,r5
1448 blt 6b
14497: sync /* Wait for all icbi to complete on bus */
1450 isync
1451
1452/*
1453 * We are done. Do not return, instead branch to second part of board
1454 * initialization, now running from RAM.
1455 */
1456
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001457 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001458 mtlr r0
1459 blr /* NEVER RETURNS! */
1460
1461in_ram:
1462
1463 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001464 * Relocation Function, r12 point to got2+0x8000
wdenk0442ed82002-11-03 10:24:00 +00001465 *
1466 * Adjust got2 pointers, no need to check for 0, this code
1467 * already puts a few entries in the table.
1468 */
1469 li r0,__got2_entries@sectoff@l
1470 la r3,GOT(_GOT2_TABLE_)
1471 lwz r11,GOT(_GOT2_TABLE_)
1472 mtctr r0
1473 sub r11,r3,r11
1474 addi r3,r3,-4
14751: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001476 cmpwi r0,0
1477 beq- 2f
wdenk0442ed82002-11-03 10:24:00 +00001478 add r0,r0,r11
1479 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +020014802: bdnz 1b
wdenk0442ed82002-11-03 10:24:00 +00001481
1482 /*
1483 * Now adjust the fixups and the pointers to the fixups
1484 * in case we need to move ourselves again.
1485 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02001486 li r0,__fixup_entries@sectoff@l
wdenk0442ed82002-11-03 10:24:00 +00001487 lwz r3,GOT(_FIXUP_TABLE_)
1488 cmpwi r0,0
1489 mtctr r0
1490 addi r3,r3,-4
1491 beq 4f
14923: lwzu r4,4(r3)
1493 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001494 cmpwi r0,0
wdenk0442ed82002-11-03 10:24:00 +00001495 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +01001496 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02001497 beq- 5f
wdenk0442ed82002-11-03 10:24:00 +00001498 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +020014995: bdnz 3b
wdenk0442ed82002-11-03 10:24:00 +000015004:
1501clear_bss:
1502 /*
1503 * Now clear BSS segment
1504 */
wdenkbf2f8c92003-05-22 22:52:13 +00001505 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +00001506 lwz r4,GOT(__bss_end)
wdenk0442ed82002-11-03 10:24:00 +00001507
1508 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001509 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001510
1511 li r0, 0
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001512
1513 andi. r5, r4, 3
1514 beq 6f
1515 sub r4, r4, r5
1516 mtctr r5
1517 mr r5, r4
15185: stb r0, 0(r5)
1519 addi r5, r5, 1
1520 bdnz 5b
15216:
wdenk0442ed82002-11-03 10:24:00 +00001522 stw r0, 0(r3)
1523 addi r3, r3, 4
1524 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001525 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001526
Anatolij Gustschin720025b2007-12-05 17:43:20 +010015277:
wdenk0442ed82002-11-03 10:24:00 +00001528 mr r3, r9 /* Init Data pointer */
1529 mr r4, r10 /* Destination Address */
1530 bl board_init_r
1531
wdenk0442ed82002-11-03 10:24:00 +00001532 /*
1533 * Copy exception vector code to low memory
1534 *
1535 * r3: dest_addr
1536 * r7: source address, r8: end address, r9: target address
1537 */
1538 .globl trap_init
1539trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001540 mflr r4 /* save link register */
1541 GET_GOT
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001542 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001543 lwz r8, GOT(_end_of_vectors)
1544
wdenk4e112c12003-06-03 23:54:09 +00001545 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001546
1547 cmplw 0, r7, r8
1548 bgelr /* return if r7>=r8 - just in case */
wdenk0442ed82002-11-03 10:24:00 +000015491:
1550 lwz r0, 0(r7)
1551 stw r0, 0(r9)
1552 addi r7, r7, 4
1553 addi r9, r9, 4
1554 cmplw 0, r7, r8
1555 bne 1b
1556
1557 /*
1558 * relocate `hdlr' and `int_return' entries
1559 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001560 li r7, .L_MachineCheck - _start + _START_OFFSET
1561 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000015622:
1563 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001564 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001565 cmplw 0, r7, r8
1566 blt 2b
1567
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001568 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001569 bl trap_reloc
1570
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001571 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001572 bl trap_reloc
1573
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001574#ifdef CONFIG_440
1575 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001576 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001577
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001578 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001579 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001580
1581 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001582 bl trap_reloc
Stefan Roese80d99a42007-06-19 16:42:31 +02001583
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001584 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1585 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001586
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001587 li r7, .L_DataTLBError - _start + _START_OFFSET
1588 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001589#else /* CONFIG_440 */
1590 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001591 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001592
1593 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001594 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001595
1596 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001597 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001598#endif /* CONFIG_440 */
1599
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001600 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1601 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001602
Stefan Roese42fbddd2006-09-07 11:51:23 +02001603#if !defined(CONFIG_440)
Stefan Roese7b12aa82006-03-13 09:42:28 +01001604 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1605 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1606 mtmsr r7 /* change MSR */
1607#else
Stefan Roese42fbddd2006-09-07 11:51:23 +02001608 bl __440_msr_set
1609 b __440_msr_continue
Stefan Roese7b12aa82006-03-13 09:42:28 +01001610
Stefan Roese42fbddd2006-09-07 11:51:23 +02001611__440_msr_set:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001612 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1613 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001614 mtspr SPRN_SRR1,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001615 mflr r7
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001616 mtspr SPRN_SRR0,r7
Stefan Roese7b12aa82006-03-13 09:42:28 +01001617 rfi
Stefan Roese42fbddd2006-09-07 11:51:23 +02001618__440_msr_continue:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001619#endif
1620
wdenk0442ed82002-11-03 10:24:00 +00001621 mtlr r4 /* restore link register */
1622 blr
Stefan Roese07038ad2013-04-02 10:37:04 +02001623#endif /* CONFIG_SPL_BUILD */
wdenk0442ed82002-11-03 10:24:00 +00001624
Stefan Roese42743512007-06-01 15:27:11 +02001625#if defined(CONFIG_440)
1626/*----------------------------------------------------------------------------+
1627| dcbz_area.
1628+----------------------------------------------------------------------------*/
1629 function_prolog(dcbz_area)
1630 rlwinm. r5,r4,0,27,31
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001631 rlwinm r5,r4,27,5,31
1632 beq ..d_ra2
1633 addi r5,r5,0x0001
1634..d_ra2:mtctr r5
1635..d_ag2:dcbz r0,r3
1636 addi r3,r3,32
1637 bdnz ..d_ag2
Stefan Roese42743512007-06-01 15:27:11 +02001638 sync
1639 blr
1640 function_epilog(dcbz_area)
Stefan Roese42743512007-06-01 15:27:11 +02001641#endif /* CONFIG_440 */
Stefan Roeseb3859f22014-03-04 15:34:35 +01001642#endif /* CONFIG_SPL_BUILD */
stroese434979e2003-05-23 11:18:02 +00001643
Stefan Roese42743512007-06-01 15:27:11 +02001644/*------------------------------------------------------------------------------- */
1645/* Function: in8 */
1646/* Description: Input 8 bits */
1647/*------------------------------------------------------------------------------- */
1648 .globl in8
1649in8:
1650 lbz r3,0x0000(r3)
1651 blr
1652
1653/*------------------------------------------------------------------------------- */
1654/* Function: out8 */
1655/* Description: Output 8 bits */
1656/*------------------------------------------------------------------------------- */
1657 .globl out8
1658out8:
1659 stb r4,0x0000(r3)
1660 blr
1661
1662/*------------------------------------------------------------------------------- */
1663/* Function: out32 */
1664/* Description: Output 32 bits */
1665/*------------------------------------------------------------------------------- */
1666 .globl out32
1667out32:
1668 stw r4,0x0000(r3)
1669 blr
1670
1671/*------------------------------------------------------------------------------- */
1672/* Function: in32 */
1673/* Description: Input 32 bits */
1674/*------------------------------------------------------------------------------- */
1675 .globl in32
1676in32:
1677 lwz 3,0x0000(3)
1678 blr
stroese434979e2003-05-23 11:18:02 +00001679
1680/**************************************************************************/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001681/* PPC405EP specific stuff */
stroese434979e2003-05-23 11:18:02 +00001682/**************************************************************************/
1683#ifdef CONFIG_405EP
1684ppc405ep_init:
stroese5ad6d4d2003-12-09 14:54:43 +00001685
Stefan Roese326c9712005-08-01 16:41:48 +02001686#ifdef CONFIG_BUBINGA
stroese5ad6d4d2003-12-09 14:54:43 +00001687 /*
1688 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1689 * function) to support FPGA and NVRAM accesses below.
1690 */
1691
1692 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1693 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001694 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1695 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001696 stw r4,0(r3)
1697 lis r3,GPIO0_OSRL@h
1698 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001699 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1700 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001701 stw r4,0(r3)
1702
1703 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1704 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001705 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1706 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroese5ad6d4d2003-12-09 14:54:43 +00001707 stw r4,0(r3)
1708 lis r3,GPIO0_ISR1L@h
1709 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001710 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1711 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroese5ad6d4d2003-12-09 14:54:43 +00001712 stw r4,0(r3)
1713
1714 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1715 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001716 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1717 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001718 stw r4,0(r3)
1719 lis r3,GPIO0_TSRL@h
1720 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001721 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1722 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001723 stw r4,0(r3)
1724
1725 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1726 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001727 lis r4,CONFIG_SYS_GPIO0_TCR@h
1728 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001729 stw r4,0(r3)
1730
Stefan Roese918010a2009-09-09 16:25:29 +02001731 li r3,PB1AP /* program EBC bank 1 for RTC access */
1732 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001733 lis r3,CONFIG_SYS_EBC_PB1AP@h
1734 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001735 mtdcr EBC0_CFGDATA,r3
1736 li r3,PB1CR
1737 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001738 lis r3,CONFIG_SYS_EBC_PB1CR@h
1739 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001740 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001741
Stefan Roese918010a2009-09-09 16:25:29 +02001742 li r3,PB1AP /* program EBC bank 1 for RTC access */
1743 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001744 lis r3,CONFIG_SYS_EBC_PB1AP@h
1745 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001746 mtdcr EBC0_CFGDATA,r3
1747 li r3,PB1CR
1748 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001749 lis r3,CONFIG_SYS_EBC_PB1CR@h
1750 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001751 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001752
Stefan Roese918010a2009-09-09 16:25:29 +02001753 li r3,PB4AP /* program EBC bank 4 for FPGA access */
1754 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001755 lis r3,CONFIG_SYS_EBC_PB4AP@h
1756 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
Stefan Roese918010a2009-09-09 16:25:29 +02001757 mtdcr EBC0_CFGDATA,r3
1758 li r3,PB4CR
1759 mtdcr EBC0_CFGADDR,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001760 lis r3,CONFIG_SYS_EBC_PB4CR@h
1761 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
Stefan Roese918010a2009-09-09 16:25:29 +02001762 mtdcr EBC0_CFGDATA,r3
stroese5ad6d4d2003-12-09 14:54:43 +00001763#endif
stroese434979e2003-05-23 11:18:02 +00001764
wdenk57b2d802003-06-27 21:31:46 +00001765 /*
1766 !-----------------------------------------------------------------------
1767 ! Check to see if chip is in bypass mode.
1768 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1769 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001770 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1771 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk57b2d802003-06-27 21:31:46 +00001772 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001773 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001774 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001775 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001776 cmpi cr0,0,r4,0x1
stroese434979e2003-05-23 11:18:02 +00001777
Wolfgang Denka1be4762008-05-20 16:00:29 +02001778 beq pll_done /* if SSCS =b'1' then PLL has */
1779 /* already been set */
1780 /* and CPU has been reset */
1781 /* so skip to next section */
stroese434979e2003-05-23 11:18:02 +00001782
Stefan Roese326c9712005-08-01 16:41:48 +02001783#ifdef CONFIG_BUBINGA
stroese434979e2003-05-23 11:18:02 +00001784 /*
wdenk57b2d802003-06-27 21:31:46 +00001785 !-----------------------------------------------------------------------
1786 ! Read NVRAM to get value to write in PLLMR.
1787 ! If value has not been correctly saved, write default value
1788 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1789 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1790 !
1791 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001792 ! structure in openbios.h. Changing the beginning of
1793 ! the structure will break this code.
wdenk57b2d802003-06-27 21:31:46 +00001794 !
1795 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001796 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001797 addis r3,0,NVRAM_BASE@h
1798 addi r3,r3,NVRAM_BASE@l
stroese434979e2003-05-23 11:18:02 +00001799
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001800 lwz r4, 0(r3)
1801 addis r5,0,NVRVFY1@h
1802 addi r5,r5,NVRVFY1@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001803 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001804 bne ..no_pllset
1805 addi r3,r3,4
1806 lwz r4, 0(r3)
1807 addis r5,0,NVRVFY2@h
1808 addi r5,r5,NVRVFY2@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001809 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001810 bne ..no_pllset
1811 addi r3,r3,8 /* Skip over conf_size */
1812 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1813 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1814 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1815 cmpi cr0,0,r5,1 /* See if PLL is locked */
1816 beq pll_write
stroese434979e2003-05-23 11:18:02 +00001817..no_pllset:
Stefan Roese326c9712005-08-01 16:41:48 +02001818#endif /* CONFIG_BUBINGA */
stroese434979e2003-05-23 11:18:02 +00001819
Wolfgang Denka1be4762008-05-20 16:00:29 +02001820 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1821 ori r3,r3,PLLMR0_DEFAULT@l /* */
1822 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1823 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroese434979e2003-05-23 11:18:02 +00001824
Stefan Roesea5d182e2007-08-14 14:44:41 +020018251:
Wolfgang Denka1be4762008-05-20 16:00:29 +02001826 b pll_write /* Write the CPC0_PLLMR with new value */
stroese434979e2003-05-23 11:18:02 +00001827
1828pll_done:
wdenk57b2d802003-06-27 21:31:46 +00001829 /*
1830 !-----------------------------------------------------------------------
1831 ! Clear Soft Reset Register
1832 ! This is needed to enable PCI if not booting from serial EPROM
1833 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001834 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001835 addi r3, 0, 0x0
1836 mtdcr CPC0_SRR, r3
stroese434979e2003-05-23 11:18:02 +00001837
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001838 addis r3,0,0x0010
1839 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001840pci_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001841 bdnz pci_wait
stroese434979e2003-05-23 11:18:02 +00001842
Wolfgang Denka1be4762008-05-20 16:00:29 +02001843 blr /* return to main code */
stroese434979e2003-05-23 11:18:02 +00001844
1845/*
1846!-----------------------------------------------------------------------------
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001847! Function: pll_write
1848! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1849! That is:
1850! 1. Pll is first disabled (de-activated by putting in bypass mode)
1851! 2. PLL is reset
1852! 3. Clock dividers are set while PLL is held in reset and bypassed
1853! 4. PLL Reset is cleared
1854! 5. Wait 100us for PLL to lock
1855! 6. A core reset is performed
stroese434979e2003-05-23 11:18:02 +00001856! Input: r3 = Value to write to CPC0_PLLMR0
1857! Input: r4 = Value to write to CPC0_PLLMR1
1858! Output r3 = none
1859!-----------------------------------------------------------------------------
1860*/
Matthias Fuchsd8079162009-07-06 16:27:33 +02001861 .globl pll_write
stroese434979e2003-05-23 11:18:02 +00001862pll_write:
wdenk57b2d802003-06-27 21:31:46 +00001863 mfdcr r5, CPC0_UCR
1864 andis. r5,r5,0xFFFF
Wolfgang Denka1be4762008-05-20 16:00:29 +02001865 ori r5,r5,0x0101 /* Stop the UART clocks */
1866 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroese434979e2003-05-23 11:18:02 +00001867
wdenk57b2d802003-06-27 21:31:46 +00001868 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001869 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001870 mtdcr CPC0_PLLMR1,r5
Wolfgang Denka1be4762008-05-20 16:00:29 +02001871 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001872 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001873
Wolfgang Denka1be4762008-05-20 16:00:29 +02001874 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
1875 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
1876 oris r5,r5,0x4000 /* Set PLL Reset */
1877 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
1878 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001879 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00001880
1881 /*
wdenk57b2d802003-06-27 21:31:46 +00001882 ! Wait min of 100us for PLL to lock.
1883 ! See CMOS 27E databook for more info.
1884 ! At 200MHz, that means waiting 20,000 instructions
stroese434979e2003-05-23 11:18:02 +00001885 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001886 addi r3,0,20000 /* 2000 = 0x4e20 */
1887 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001888pll_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001889 bdnz pll_wait
stroese434979e2003-05-23 11:18:02 +00001890
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001891 oris r5,r5,0x8000 /* Enable PLL */
1892 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroese434979e2003-05-23 11:18:02 +00001893
wdenk57b2d802003-06-27 21:31:46 +00001894 /*
1895 * Reset CPU to guarantee timings are OK
1896 * Not sure if this is needed...
1897 */
1898 addis r3,0,0x1000
Matthias Fuchs730b2d22009-07-22 17:27:56 +02001899 mtspr SPRN_DBCR0,r3 /* This will cause a CPU core reset, and */
Wolfgang Denka1be4762008-05-20 16:00:29 +02001900 /* execution will continue from the poweron */
1901 /* vector of 0xfffffffc */
stroese434979e2003-05-23 11:18:02 +00001902#endif /* CONFIG_405EP */
Stefan Roesea8856e32007-02-20 10:57:08 +01001903
1904#if defined(CONFIG_440)
Stefan Roesea8856e32007-02-20 10:57:08 +01001905/*----------------------------------------------------------------------------+
1906| mttlb3.
1907+----------------------------------------------------------------------------*/
1908 function_prolog(mttlb3)
1909 TLBWE(4,3,2)
1910 blr
1911 function_epilog(mttlb3)
1912
1913/*----------------------------------------------------------------------------+
1914| mftlb3.
1915+----------------------------------------------------------------------------*/
1916 function_prolog(mftlb3)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001917 TLBRE(3,3,2)
Stefan Roesea8856e32007-02-20 10:57:08 +01001918 blr
1919 function_epilog(mftlb3)
1920
1921/*----------------------------------------------------------------------------+
1922| mttlb2.
1923+----------------------------------------------------------------------------*/
1924 function_prolog(mttlb2)
1925 TLBWE(4,3,1)
1926 blr
1927 function_epilog(mttlb2)
1928
1929/*----------------------------------------------------------------------------+
1930| mftlb2.
1931+----------------------------------------------------------------------------*/
1932 function_prolog(mftlb2)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001933 TLBRE(3,3,1)
Stefan Roesea8856e32007-02-20 10:57:08 +01001934 blr
1935 function_epilog(mftlb2)
1936
1937/*----------------------------------------------------------------------------+
1938| mttlb1.
1939+----------------------------------------------------------------------------*/
1940 function_prolog(mttlb1)
1941 TLBWE(4,3,0)
1942 blr
1943 function_epilog(mttlb1)
1944
1945/*----------------------------------------------------------------------------+
1946| mftlb1.
1947+----------------------------------------------------------------------------*/
1948 function_prolog(mftlb1)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01001949 TLBRE(3,3,0)
Stefan Roesea8856e32007-02-20 10:57:08 +01001950 blr
1951 function_epilog(mftlb1)
1952#endif /* CONFIG_440 */