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>
5 * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
6 * Copyright (c) 2008 Nuovation System Designs, LLC
7 * Grant Erickson <gerickson@nuovations.com>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 /*------------------------------------------------------------------------------+
28 * This source code is dual-licensed. You may use it under the terms of the
29 * GNU General Public License version 2, or under the license below.
31 * This source code has been made available to you by IBM on an AS-IS
32 * basis. Anyone receiving this source is licensed under IBM
33 * copyrights to use it in any way he or she deems fit, including
34 * copying it, modifying it, compiling it, and redistributing it either
35 * with or without modifications. No license under IBM patents or
36 * patent applications is to be implied by the copyright license.
38 * Any user of this software should understand that IBM cannot provide
39 * technical support for this software and will not be responsible for
40 * any consequences resulting from the use of this software.
42 * Any person who transfers this source code or any derivative work
43 * must include the IBM copyright notice, this paragraph, and the
44 * preceding two paragraphs in the transferred software.
46 * COPYRIGHT I B M CORPORATION 1995
47 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
48 *-------------------------------------------------------------------------------
52 * Startup code for IBM/AMCC PowerPC 4xx (PPC4xx) based boards
54 * The following description only applies to the NOR flash style booting.
55 * NAND booting is different. For more details about NAND booting on 4xx
56 * take a look at doc/README.nand-boot-ppc440.
58 * The CPU starts at address 0xfffffffc (last word in the address space).
59 * The U-Boot image therefore has to be located in the "upper" area of the
60 * flash (e.g. 512MiB - 0xfff80000 ... 0xffffffff). The default value for
61 * the boot chip-select (CS0) is quite big and covers this area. On the
62 * 405EX this is for example 0xffe00000 ... 0xffffffff. U-Boot will
63 * reconfigure this CS0 (and other chip-selects as well when configured
64 * this way) in the boot process to the "correct" values matching the
68 #include <asm-offsets.h>
70 #include <asm/ppc4xx.h>
73 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
75 #include <ppc_asm.tmpl>
78 #include <asm/cache.h>
80 #include <asm/ppc4xx-isram.h>
82 #ifdef CONFIG_SYS_INIT_DCACHE_CS
83 # if (CONFIG_SYS_INIT_DCACHE_CS == 0)
86 # if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
87 # define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
88 # define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
91 # if (CONFIG_SYS_INIT_DCACHE_CS == 1)
94 # if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
95 # define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
96 # define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
99 # if (CONFIG_SYS_INIT_DCACHE_CS == 2)
102 # if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
103 # define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
104 # define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
107 # if (CONFIG_SYS_INIT_DCACHE_CS == 3)
110 # if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
111 # define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
112 # define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
115 # if (CONFIG_SYS_INIT_DCACHE_CS == 4)
118 # if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
119 # define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
120 # define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
123 # if (CONFIG_SYS_INIT_DCACHE_CS == 5)
126 # if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
127 # define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
128 # define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
131 # if (CONFIG_SYS_INIT_DCACHE_CS == 6)
134 # if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
135 # define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
136 # define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
139 # if (CONFIG_SYS_INIT_DCACHE_CS == 7)
142 # if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
143 # define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
144 # define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
154 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
155 * used as temporary stack pointer for the primordial stack
157 # ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
158 # define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
159 EBC_BXAP_TWT_ENCODE(7) | \
160 EBC_BXAP_BCE_DISABLE | \
161 EBC_BXAP_BCT_2TRANS | \
162 EBC_BXAP_CSN_ENCODE(0) | \
163 EBC_BXAP_OEN_ENCODE(0) | \
164 EBC_BXAP_WBN_ENCODE(0) | \
165 EBC_BXAP_WBF_ENCODE(0) | \
166 EBC_BXAP_TH_ENCODE(2) | \
167 EBC_BXAP_RE_DISABLED | \
168 EBC_BXAP_SOR_NONDELAYED | \
169 EBC_BXAP_BEM_WRITEONLY | \
170 EBC_BXAP_PEN_DISABLED)
171 # endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
172 # ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
173 # define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
177 # endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
178 # ifndef CONFIG_SYS_INIT_RAM_PATTERN
179 # define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
181 #endif /* CONFIG_SYS_INIT_DCACHE_CS */
183 #if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_SIZE > (4 << 10)))
184 #error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_SIZE!
188 * Unless otherwise overriden, enable two 128MB cachable instruction regions
189 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
190 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
192 #if !defined(CONFIG_SYS_FLASH_BASE)
193 /* If not already defined, set it to the "last" 128MByte region */
194 # define CONFIG_SYS_FLASH_BASE 0xf8000000
196 #if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
197 # define CONFIG_SYS_ICACHE_SACR_VALUE \
198 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
199 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
200 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
201 #endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
203 #if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
204 # define CONFIG_SYS_DCACHE_SACR_VALUE \
206 #endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
208 #if !defined(CONFIG_SYS_TLB_FOR_BOOT_FLASH)
209 #define CONFIG_SYS_TLB_FOR_BOOT_FLASH 0 /* use TLB 0 as default */
212 #define function_prolog(func_name) .text; \
216 #define function_epilog(func_name) .type func_name,@function; \
217 .size func_name,.-func_name
219 /* We don't want the MMU yet.
222 #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
225 .extern ext_bus_cntlr_init
226 #ifdef CONFIG_NAND_U_BOOT
227 .extern reconfig_tlb0
231 * Set up GOT: Global Offset Table
233 * Use r12 to access the GOT
235 #if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
237 GOT_ENTRY(_GOT2_TABLE_)
238 GOT_ENTRY(_FIXUP_TABLE_)
241 GOT_ENTRY(_start_of_vectors)
242 GOT_ENTRY(_end_of_vectors)
243 GOT_ENTRY(transfer_to_handler)
245 GOT_ENTRY(__init_end)
247 GOT_ENTRY(__bss_start)
249 #endif /* CONFIG_NAND_SPL */
251 #if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL) && \
252 !defined(CONFIG_SPL_BUILD)
254 * NAND U-Boot image is started from offset 0
257 #if defined(CONFIG_440)
261 bl cpu_init_f /* run low-level CPU init code (from Flash) */
263 /* NOTREACHED - board_init_f() does not return */
266 #if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_BOOT_FROM_XMD)
268 * 4xx RAM-booting U-Boot image is started from offset 0
274 #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
276 * This is the entry of the real U-Boot from a board port
277 * that supports SPL booting on the PPC4xx. We only need
278 * to call board_init_f() here. Everything else has already
279 * been done in the SPL u-boot version.
281 GET_GOT /* initialize GOT access */
282 bl board_init_f /* run 1st part of board init code (in Flash)*/
283 /* NOTREACHED - board_init_f() does not return */
287 * 440 Startup -- on reset only the top 4k of the effective
288 * address space is mapped in by an entry in the instruction
289 * and data shadow TLB. The .bootpg section is located in the
290 * top 4k & does only what's necessary to map in the the rest
291 * of the boot rom. Once the boot rom is mapped in we can
292 * proceed with normal startup.
294 * NOTE: CS0 only covers the top 2MB of the effective address
298 #if defined(CONFIG_440)
299 #if !defined(CONFIG_NAND_SPL)
300 .section .bootpg,"ax"
304 /**************************************************************************/
306 /*--------------------------------------------------------------------+
307 | 440EPX BUP Change - Hardware team request
308 +--------------------------------------------------------------------*/
309 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
314 /*----------------------------------------------------------------+
315 | Core bug fix. Clear the esr
316 +-----------------------------------------------------------------*/
319 /*----------------------------------------------------------------*/
320 /* Clear and set up some registers. */
321 /*----------------------------------------------------------------*/
322 iccci r0,r0 /* NOTE: operands not used for 440 */
323 dccci r0,r0 /* NOTE: operands not used for 440 */
330 /* NOTE: 440GX adds machine check status regs */
331 #if defined(CONFIG_440) && !defined(CONFIG_440GP)
338 /*----------------------------------------------------------------*/
340 /*----------------------------------------------------------------*/
341 /* Disable store gathering & broadcast, guarantee inst/data
342 * cache block touch, force load/store alignment
343 * (see errata 1.12: 440_33)
345 lis r1,0x0030 /* store gathering & broadcast disable */
346 ori r1,r1,0x6000 /* cache touch */
349 /*----------------------------------------------------------------*/
350 /* Initialize debug */
351 /*----------------------------------------------------------------*/
353 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
354 bne skip_debug_init /* if set, don't clear debug register */
356 ori r1,r1,CCR0_DTB@l /* Disable Trace Broadcast */
370 mtspr SPRN_DBSR,r1 /* Clear all valid bits */
373 #if defined (CONFIG_440SPE)
374 /*----------------------------------------------------------------+
375 | Initialize Core Configuration Reg1.
376 | a. ICDPEI: Record even parity. Normal operation.
377 | b. ICTPEI: Record even parity. Normal operation.
378 | c. DCTPEI: Record even parity. Normal operation.
379 | d. DCDPEI: Record even parity. Normal operation.
380 | e. DCUPEI: Record even parity. Normal operation.
381 | f. DCMPEI: Record even parity. Normal operation.
382 | g. FCOM: Normal operation
383 | h. MMUPEI: Record even parity. Normal operation.
384 | i. FFF: Flush only as much data as necessary.
385 | j. TCS: Timebase increments from CPU clock.
386 +-----------------------------------------------------------------*/
390 /*----------------------------------------------------------------+
391 | Reset the timebase.
392 | The previous write to CCR1 sets the timebase source.
393 +-----------------------------------------------------------------*/
398 /*----------------------------------------------------------------*/
399 /* Setup interrupt vectors */
400 /*----------------------------------------------------------------*/
401 mtspr SPRN_IVPR,r0 /* Vectors start at 0x0000_0000 */
403 mtspr SPRN_IVOR0,r1 /* Critical input */
405 mtspr SPRN_IVOR1,r1 /* Machine check */
407 mtspr SPRN_IVOR2,r1 /* Data storage */
409 mtspr SPRN_IVOR3,r1 /* Instruction storage */
411 mtspr SPRN_IVOR4,r1 /* External interrupt */
413 mtspr SPRN_IVOR5,r1 /* Alignment */
415 mtspr SPRN_IVOR6,r1 /* Program check */
417 mtspr SPRN_IVOR7,r1 /* Floating point unavailable */
419 mtspr SPRN_IVOR8,r1 /* System call */
421 mtspr SPRN_IVOR9,r1 /* Auxiliary Processor unavailable */
423 mtspr SPRN_IVOR10,r1 /* Decrementer */
425 mtspr SPRN_IVOR13,r1 /* Data TLB error */
427 mtspr SPRN_IVOR14,r1 /* Instr TLB error */
429 mtspr SPRN_IVOR15,r1 /* Debug */
431 /*----------------------------------------------------------------*/
432 /* Configure cache regions */
433 /*----------------------------------------------------------------*/
451 /*----------------------------------------------------------------*/
452 /* Cache victim limits */
453 /*----------------------------------------------------------------*/
454 /* floors 0, ceiling max to use the entire cache -- nothing locked
461 /*----------------------------------------------------------------+
462 |Initialize MMUCR[STID] = 0.
463 +-----------------------------------------------------------------*/
470 /*----------------------------------------------------------------*/
471 /* Clear all TLB entries -- TID = 0, TS = 0 */
472 /*----------------------------------------------------------------*/
474 #ifdef CONFIG_SYS_RAMBOOT
475 li r4,0 /* Start with TLB #0 */
477 li r4,1 /* Start with TLB #1 */
479 li r1,64 /* 64 TLB entries */
480 sub r1,r1,r4 /* calculate last TLB # */
483 #ifdef CONFIG_SYS_RAMBOOT
484 tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
485 rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
486 beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
488 tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
491 tlbnxt: addi r4,r4,1 /* Next TLB */
494 /*----------------------------------------------------------------*/
495 /* TLB entry setup -- step thru tlbtab */
496 /*----------------------------------------------------------------*/
497 #if defined(CONFIG_440SPE_REVA)
498 /*----------------------------------------------------------------*/
499 /* We have different TLB tables for revA and rev B of 440SPe */
500 /*----------------------------------------------------------------*/
512 bl tlbtab /* Get tlbtab pointer */
515 li r1,0x003f /* 64 TLB entries max */
521 #ifdef CONFIG_SYS_RAMBOOT
522 tlbre r3,r4,0 /* Read contents from TLB word #0 */
523 rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
524 bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
528 beq 2f /* 0 marks end */
531 tlbwe r0,r4,0 /* TLB Word 0 */
532 tlbwe r1,r4,1 /* TLB Word 1 */
533 tlbwe r2,r4,2 /* TLB Word 2 */
534 tlbnx2: addi r4,r4,1 /* Next TLB */
537 /*----------------------------------------------------------------*/
538 /* Continue from 'normal' start */
539 /*----------------------------------------------------------------*/
545 mtspr SPRN_SRR1,r0 /* Keep things disabled for now */
549 #endif /* CONFIG_440 */
552 * r3 - 1st arg to board_init(): IMMP pointer
553 * r4 - 2nd arg to board_init(): boot flag
555 #if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
557 .long 0x27051956 /* U-Boot Magic Number */
558 .globl version_string
560 .ascii U_BOOT_VERSION_STRING, "\0"
562 . = EXC_OFF_SYS_RESET
563 .globl _start_of_vectors
566 /* Critical input. */
567 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
571 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
573 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
574 #endif /* CONFIG_440 */
576 /* Data Storage exception. */
577 STD_EXCEPTION(0x300, DataStorage, UnknownException)
579 /* Instruction Storage exception. */
580 STD_EXCEPTION(0x400, InstStorage, UnknownException)
582 /* External Interrupt exception. */
583 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
585 /* Alignment exception. */
588 EXCEPTION_PROLOG(SRR0, SRR1)
593 addi r3,r1,STACK_FRAME_OVERHEAD
594 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
596 /* Program check exception */
599 EXCEPTION_PROLOG(SRR0, SRR1)
600 addi r3,r1,STACK_FRAME_OVERHEAD
601 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
605 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
606 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
607 STD_EXCEPTION(0xa00, APU, UnknownException)
609 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
612 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
613 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
615 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
616 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
617 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
619 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
621 .globl _end_of_vectors
628 #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
630 * This is the entry of the real U-Boot from a board port
631 * that supports SPL booting on the PPC4xx. We only need
632 * to call board_init_f() here. Everything else has already
633 * been done in the SPL u-boot version.
635 GET_GOT /* initialize GOT access */
636 bl board_init_f /* run 1st part of board init code (in Flash)*/
637 /* NOTREACHED - board_init_f() does not return */
640 /*****************************************************************************/
641 #if defined(CONFIG_440)
643 /*----------------------------------------------------------------*/
644 /* Clear and set up some registers. */
645 /*----------------------------------------------------------------*/
648 mtspr SPRN_DEC,r0 /* prevent dec exceptions */
649 mtspr SPRN_TBWL,r0 /* prevent fit & wdt exceptions */
651 mtspr SPRN_TSR,r1 /* clear all timer exception status */
652 mtspr SPRN_TCR,r0 /* disable all */
653 mtspr SPRN_ESR,r0 /* clear exception syndrome register */
654 mtxer r0 /* clear integer exception register */
656 /*----------------------------------------------------------------*/
657 /* Debug setup -- some (not very good) ice's need an event*/
658 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
659 /* value you need in this case 0x8cff 0000 should do the trick */
660 /*----------------------------------------------------------------*/
661 #if defined(CONFIG_SYS_INIT_DBCR)
664 mtspr SPRN_DBSR,r1 /* Clear all status bits */
665 lis r0,CONFIG_SYS_INIT_DBCR@h
666 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
671 /*----------------------------------------------------------------*/
672 /* Setup the internal SRAM */
673 /*----------------------------------------------------------------*/
676 #ifdef CONFIG_SYS_INIT_RAM_DCACHE
677 /* Clear Dcache to use as RAM */
678 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
679 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
680 addis r4,r0,CONFIG_SYS_INIT_RAM_SIZE@h
681 ori r4,r4,CONFIG_SYS_INIT_RAM_SIZE@l
682 rlwinm. r5,r4,0,27,31
694 * Lock the init-ram/stack in d-cache, so that other regions
695 * may use d-cache as well
696 * Note, that this current implementation locks exactly 4k
697 * of d-cache, so please make sure that you don't define a
698 * bigger init-ram area. Take a look at the lwmon5 440EPx
699 * implementation as a reference.
703 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
719 #endif /* CONFIG_SYS_INIT_RAM_DCACHE */
721 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
722 #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
723 /* not all PPC's have internal SRAM usable as L2-cache */
724 #if defined(CONFIG_440GX) || \
725 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
726 defined(CONFIG_460SX)
727 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
728 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
729 defined(CONFIG_APM821XX)
731 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
732 mtdcr L2_CACHE_CFG,r1
738 and r1,r1,r2 /* Disable parity check */
741 and r1,r1,r2 /* Disable pwr mgmt */
744 lis r1,0x8000 /* BAS = 8000_0000 */
745 #if defined(CONFIG_440GX) || defined(CONFIG_440SP)
746 ori r1,r1,0x0980 /* first 64k */
747 mtdcr ISRAM0_SB0CR,r1
749 ori r1,r1,0x0980 /* second 64k */
750 mtdcr ISRAM0_SB1CR,r1
752 ori r1,r1, 0x0980 /* third 64k */
753 mtdcr ISRAM0_SB2CR,r1
755 ori r1,r1, 0x0980 /* fourth 64k */
756 mtdcr ISRAM0_SB3CR,r1
757 #elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || \
758 defined(CONFIG_460GT) || defined(CONFIG_APM821XX)
759 lis r1,0x0000 /* BAS = X_0000_0000 */
760 ori r1,r1,0x0984 /* first 64k */
761 mtdcr ISRAM0_SB0CR,r1
763 ori r1,r1,0x0984 /* second 64k */
764 mtdcr ISRAM0_SB1CR,r1
766 ori r1,r1, 0x0984 /* third 64k */
767 mtdcr ISRAM0_SB2CR,r1
769 ori r1,r1, 0x0984 /* fourth 64k */
770 mtdcr ISRAM0_SB3CR,r1
771 #if defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
772 defined(CONFIG_APM821XX)
776 and r1,r1,r2 /* Disable parity check */
779 and r1,r1,r2 /* Disable pwr mgmt */
782 lis r1,0x0004 /* BAS = 4_0004_0000 */
783 ori r1,r1,ISRAM1_SIZE /* ocm size */
784 mtdcr ISRAM1_SB0CR,r1
786 #elif defined(CONFIG_460SX)
787 lis r1,0x0000 /* BAS = 0000_0000 */
788 ori r1,r1,0x0B84 /* first 128k */
789 mtdcr ISRAM0_SB0CR,r1
791 ori r1,r1,0x0B84 /* second 128k */
792 mtdcr ISRAM0_SB1CR,r1
794 ori r1,r1, 0x0B84 /* third 128k */
795 mtdcr ISRAM0_SB2CR,r1
797 ori r1,r1, 0x0B84 /* fourth 128k */
798 mtdcr ISRAM0_SB3CR,r1
799 #elif defined(CONFIG_440GP)
800 ori r1,r1,0x0380 /* 8k rw */
801 mtdcr ISRAM0_SB0CR,r1
802 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
804 #endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
806 /*----------------------------------------------------------------*/
807 /* Setup the stack in internal SRAM */
808 /*----------------------------------------------------------------*/
809 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
810 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
813 stwu r0,-4(r1) /* Terminate call chain */
815 stwu r1,-8(r1) /* Save back chain and move SP */
816 lis r0,RESET_VECTOR@h /* Address of reset vector */
817 ori r0,r0, RESET_VECTOR@l
818 stwu r1,-8(r1) /* Save back chain and move SP */
819 stw r0,+12(r1) /* Save return addr (underflow vect) */
821 #ifdef CONFIG_NAND_SPL
822 bl nand_boot_common /* will not return */
824 #ifndef CONFIG_SPL_BUILD
828 bl cpu_init_f /* run low-level CPU init code (from Flash) */
830 /* NOTREACHED - board_init_f() does not return */
833 #endif /* CONFIG_440 */
835 /*****************************************************************************/
836 #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
837 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
838 defined(CONFIG_405EX) || defined(CONFIG_405)
839 /*----------------------------------------------------------------------- */
840 /* Clear and set up some registers. */
841 /*----------------------------------------------------------------------- */
843 #if !defined(CONFIG_405EX)
847 * On 405EX, completely clearing the SGR leads to PPC hangup
848 * upon PCIe configuration access. The PCIe memory regions
849 * need to be guarded!
856 mtesr r4 /* clear Exception Syndrome Reg */
857 mttcr r4 /* clear Timer Control Reg */
858 mtxer r4 /* clear Fixed-Point Exception Reg */
859 mtevpr r4 /* clear Exception Vector Prefix Reg */
860 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
861 /* dbsr is cleared by setting bits to 1) */
862 mtdbsr r4 /* clear/reset the dbsr */
864 /* Invalidate the i- and d-caches. */
868 /* Set-up icache cacheability. */
869 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
870 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
874 /* Set-up dcache cacheability. */
875 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
876 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
879 #if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
880 && !defined (CONFIG_XILINX_405)
881 /*----------------------------------------------------------------------- */
882 /* Tune the speed and size for flash CS0 */
883 /*----------------------------------------------------------------------- */
884 bl ext_bus_cntlr_init
887 #if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
889 * For boards that don't have OCM and can't use the data cache
890 * for their primordial stack, setup stack here directly after the
891 * SDRAM is initialized in ext_bus_cntlr_init.
893 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
894 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
896 li r0, 0 /* Make room for stack frame header and */
897 stwu r0, -4(r1) /* clear final stack frame so that */
898 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
900 * Set up a dummy frame to store reset vector as return address.
901 * this causes stack underflow to reset board.
903 stwu r1, -8(r1) /* Save back chain and move SP */
904 lis r0, RESET_VECTOR@h /* Address of reset vector */
905 ori r0, r0, RESET_VECTOR@l
906 stwu r1, -8(r1) /* Save back chain and move SP */
907 stw r0, +12(r1) /* Save return addr (underflow vect) */
908 #endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
910 #if defined(CONFIG_405EP)
911 /*----------------------------------------------------------------------- */
912 /* DMA Status, clear to come up clean */
913 /*----------------------------------------------------------------------- */
914 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
918 bl ppc405ep_init /* do ppc405ep specific init */
919 #endif /* CONFIG_405EP */
921 #if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
922 #if defined(CONFIG_405EZ)
923 /********************************************************************
924 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
925 *******************************************************************/
927 * We can map the OCM on the PLB3, so map it at
928 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
930 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
931 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
932 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
933 mtdcr OCM0_PLBCR1,r3 /* Set PLB Access */
934 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
935 mtdcr OCM0_PLBCR2,r3 /* Set PLB Access */
938 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
939 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
940 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
941 mtdcr OCM0_DSRC1, r3 /* Set Data Side */
942 mtdcr OCM0_ISRC1, r3 /* Set Instruction Side */
943 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
944 mtdcr OCM0_DSRC2, r3 /* Set Data Side */
945 mtdcr OCM0_ISRC2, r3 /* Set Instruction Side */
946 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
950 #else /* CONFIG_405EZ */
951 /********************************************************************
952 * Setup OCM - On Chip Memory
953 *******************************************************************/
957 mfdcr r3, OCM0_ISCNTL /* get instr-side IRAM config */
958 mfdcr r4, OCM0_DSCNTL /* get data-side IRAM config */
959 and r3, r3, r0 /* disable data-side IRAM */
960 and r4, r4, r0 /* disable data-side IRAM */
961 mtdcr OCM0_ISCNTL, r3 /* set instr-side IRAM config */
962 mtdcr OCM0_DSCNTL, r4 /* set data-side IRAM config */
965 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
966 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
968 addis r4, 0, 0xC000 /* OCM data area enabled */
969 mtdcr OCM0_DSCNTL, r4
971 #endif /* CONFIG_405EZ */
974 /*----------------------------------------------------------------------- */
975 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
976 /*----------------------------------------------------------------------- */
977 #ifdef CONFIG_SYS_INIT_DCACHE_CS
979 mtdcr EBC0_CFGADDR, r4
980 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
981 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
982 mtdcr EBC0_CFGDATA, r4
985 mtdcr EBC0_CFGADDR, r4
986 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
987 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
988 mtdcr EBC0_CFGDATA, r4
991 * Enable the data cache for the 128MB storage access control region
992 * at CONFIG_SYS_INIT_RAM_ADDR.
995 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
996 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
1000 * Preallocate data cache lines to be used to avoid a subsequent
1001 * cache miss and an ensuing machine check exception when exceptions
1006 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1007 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
1009 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
1010 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
1013 * Convert the size, in bytes, to the number of cache lines/blocks
1016 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
1017 srwi r5, r4, L1_CACHE_SHIFT
1023 /* Preallocate the computed number of cache blocks. */
1024 ..alloc_dcache_block:
1026 addi r3, r3, L1_CACHE_BYTES
1027 bdnz ..alloc_dcache_block
1031 * Load the initial stack pointer and data area and convert the size,
1032 * in bytes, to the number of words to initialize to a known value.
1034 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
1035 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
1037 lis r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@h
1038 ori r4, r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@l
1041 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
1042 ori r2, r2, CONFIG_SYS_INIT_RAM_SIZE@l
1044 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1045 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
1052 * Make room for stack frame header and clear final stack frame so
1053 * that stack backtraces terminate cleanly.
1059 * Set up a dummy frame to store reset vector as return address.
1060 * this causes stack underflow to reset board.
1062 stwu r1, -8(r1) /* Save back chain and move SP */
1063 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1064 ori r0, r0, RESET_VECTOR@l
1065 stwu r1, -8(r1) /* Save back chain and move SP */
1066 stw r0, +12(r1) /* Save return addr (underflow vect) */
1068 #elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1069 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
1074 /* Set up Stack at top of OCM */
1075 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1076 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
1078 /* Set up a zeroized stack frame so that backtrace works right */
1084 * Set up a dummy frame to store reset vector as return address.
1085 * this causes stack underflow to reset board.
1087 stwu r1, -8(r1) /* Save back chain and move SP */
1088 lis r0, RESET_VECTOR@h /* Address of reset vector */
1089 ori r0, r0, RESET_VECTOR@l
1090 stwu r1, -8(r1) /* Save back chain and move SP */
1091 stw r0, +12(r1) /* Save return addr (underflow vect) */
1092 #endif /* CONFIG_SYS_INIT_DCACHE_CS */
1094 #ifdef CONFIG_NAND_SPL
1095 bl nand_boot_common /* will not return */
1097 GET_GOT /* initialize GOT access */
1099 bl cpu_init_f /* run low-level CPU init code (from Flash) */
1101 bl board_init_f /* run first part of init code (from Flash) */
1102 /* NOTREACHED - board_init_f() does not return */
1104 #endif /* CONFIG_NAND_SPL */
1106 #endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
1107 /*----------------------------------------------------------------------- */
1110 #if !defined(CONFIG_NAND_SPL) && !defined(CONFIG_SPL_BUILD)
1112 * This code finishes saving the registers to the exception frame
1113 * and jumps to the appropriate handler for the exception.
1114 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1116 .globl transfer_to_handler
1117 transfer_to_handler:
1127 andi. r24,r23,0x3f00 /* get vector offset */
1131 mtspr SPRG2,r22 /* r1 is now kernel sp */
1132 lwz r24,0(r23) /* virtual address of handler */
1133 lwz r23,4(r23) /* where to go when done */
1138 rfi /* jump to handler, enable MMU */
1141 mfmsr r28 /* Disable interrupts */
1145 SYNC /* Some chip revs need this... */
1160 lwz r2,_NIP(r1) /* Restore environment */
1171 mfmsr r28 /* Disable interrupts */
1175 SYNC /* Some chip revs need this... */
1190 lwz r2,_NIP(r1) /* Restore environment */
1202 mfmsr r28 /* Disable interrupts */
1206 SYNC /* Some chip revs need this... */
1221 lwz r2,_NIP(r1) /* Restore environment */
1223 mtspr SPRN_MCSRR0,r2
1224 mtspr SPRN_MCSRR1,r0
1230 #endif /* CONFIG_440 */
1238 /*------------------------------------------------------------------------------- */
1239 /* Function: out16 */
1240 /* Description: Output 16 bits */
1241 /*------------------------------------------------------------------------------- */
1247 /*------------------------------------------------------------------------------- */
1248 /* Function: out16r */
1249 /* Description: Byte reverse and output 16 bits */
1250 /*------------------------------------------------------------------------------- */
1256 /*------------------------------------------------------------------------------- */
1257 /* Function: out32r */
1258 /* Description: Byte reverse and output 32 bits */
1259 /*------------------------------------------------------------------------------- */
1265 /*------------------------------------------------------------------------------- */
1266 /* Function: in16 */
1267 /* Description: Input 16 bits */
1268 /*------------------------------------------------------------------------------- */
1274 /*------------------------------------------------------------------------------- */
1275 /* Function: in16r */
1276 /* Description: Input 16 bits and byte reverse */
1277 /*------------------------------------------------------------------------------- */
1283 /*------------------------------------------------------------------------------- */
1284 /* Function: in32r */
1285 /* Description: Input 32 bits and byte reverse */
1286 /*------------------------------------------------------------------------------- */
1292 #if !defined(CONFIG_SPL_BUILD)
1294 * void relocate_code (addr_sp, gd, addr_moni)
1296 * This "function" does not return, instead it continues in RAM
1297 * after relocating the monitor code.
1299 * r3 = Relocated stack pointer
1300 * r4 = Relocated global data pointer
1301 * r5 = Relocated text pointer
1303 .globl relocate_code
1305 #if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
1307 * We need to flush the initial global data (gd_t) and bd_info
1308 * before the dcache will be invalidated.
1311 /* Save registers */
1317 * Flush complete dcache, this is faster than flushing the
1318 * ranges for global_data and bd_info instead.
1322 #if defined(CONFIG_SYS_INIT_DCACHE_CS)
1324 * Undo the earlier data cache set-up for the primordial stack and
1325 * data area. First, invalidate the data cache and then disable data
1326 * cacheability for that area. Finally, restore the EBC values, if
1330 /* Invalidate the primordial stack and data area in cache */
1331 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1332 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
1334 lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
1335 ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
1338 bl invalidate_dcache_range
1340 /* Disable cacheability for the region */
1342 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1343 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
1347 /* Restore the EBC parameters */
1349 mtdcr EBC0_CFGADDR, r3
1351 ori r3, r3, PBxAP_VAL@l
1352 mtdcr EBC0_CFGDATA, r3
1355 mtdcr EBC0_CFGADDR, r3
1357 ori r3, r3, PBxCR_VAL@l
1358 mtdcr EBC0_CFGDATA, r3
1359 #endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
1361 /* Restore registers */
1365 #endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
1367 #ifdef CONFIG_SYS_INIT_RAM_DCACHE
1369 * Unlock the previously locked d-cache
1373 /* set TFLOOR/NFLOOR to 0 again */
1390 /* Invalidate data cache, now no longer our stack */
1394 #endif /* CONFIG_SYS_INIT_RAM_DCACHE */
1397 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1398 * to speed up the boot process. Now this cache needs to be disabled.
1400 #if defined(CONFIG_440)
1401 /* Clear all potential pending exceptions */
1404 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
1405 tlbre r0,r1,0x0002 /* Read contents */
1406 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
1407 tlbwe r0,r1,0x0002 /* Save it out */
1410 #endif /* defined(CONFIG_440) */
1411 mr r1, r3 /* Set new stack pointer */
1412 mr r9, r4 /* Save copy of Init Data pointer */
1413 mr r10, r5 /* Save copy of Destination Address */
1416 mr r3, r5 /* Destination Address */
1417 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1418 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
1419 lwz r5, GOT(__init_end)
1421 li r6, L1_CACHE_BYTES /* Cache Line Size */
1426 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
1432 /* First our own GOT */
1434 /* then the one used by the C code */
1444 beq cr1,4f /* In place copy is not necessary */
1445 beq 7f /* Protect against 0 count */
1464 * Now flush the cache: note that we must start from a cache aligned
1465 * address. Otherwise we might miss one cache line.
1469 beq 7f /* Always flush prefetch queue in any case */
1477 sync /* Wait for all dcbst to complete on bus */
1483 7: sync /* Wait for all icbi to complete on bus */
1487 * We are done. Do not return, instead branch to second part of board
1488 * initialization, now running from RAM.
1491 addi r0, r10, in_ram - _start + _START_OFFSET
1493 blr /* NEVER RETURNS! */
1498 * Relocation Function, r12 point to got2+0x8000
1500 * Adjust got2 pointers, no need to check for 0, this code
1501 * already puts a few entries in the table.
1503 li r0,__got2_entries@sectoff@l
1504 la r3,GOT(_GOT2_TABLE_)
1505 lwz r11,GOT(_GOT2_TABLE_)
1517 * Now adjust the fixups and the pointers to the fixups
1518 * in case we need to move ourselves again.
1520 li r0,__fixup_entries@sectoff@l
1521 lwz r3,GOT(_FIXUP_TABLE_)
1537 * Now clear BSS segment
1539 lwz r3,GOT(__bss_start)
1540 lwz r4,GOT(__bss_end)
1562 mr r3, r9 /* Init Data pointer */
1563 mr r4, r10 /* Destination Address */
1567 * Copy exception vector code to low memory
1570 * r7: source address, r8: end address, r9: target address
1574 mflr r4 /* save link register */
1576 lwz r7, GOT(_start_of_vectors)
1577 lwz r8, GOT(_end_of_vectors)
1579 li r9, 0x100 /* reset vector always at 0x100 */
1582 bgelr /* return if r7>=r8 - just in case */
1592 * relocate `hdlr' and `int_return' entries
1594 li r7, .L_MachineCheck - _start + _START_OFFSET
1595 li r8, Alignment - _start + _START_OFFSET
1598 addi r7, r7, 0x100 /* next exception vector */
1602 li r7, .L_Alignment - _start + _START_OFFSET
1605 li r7, .L_ProgramCheck - _start + _START_OFFSET
1609 li r7, .L_FPUnavailable - _start + _START_OFFSET
1612 li r7, .L_Decrementer - _start + _START_OFFSET
1615 li r7, .L_APU - _start + _START_OFFSET
1618 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1621 li r7, .L_DataTLBError - _start + _START_OFFSET
1623 #else /* CONFIG_440 */
1624 li r7, .L_PIT - _start + _START_OFFSET
1627 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
1630 li r7, .L_DataTLBMiss - _start + _START_OFFSET
1632 #endif /* CONFIG_440 */
1634 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1637 #if !defined(CONFIG_440)
1638 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1639 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1640 mtmsr r7 /* change MSR */
1643 b __440_msr_continue
1646 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1647 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1655 mtlr r4 /* restore link register */
1657 #endif /* CONFIG_SPL_BUILD */
1659 #if defined(CONFIG_440)
1660 /*----------------------------------------------------------------------------+
1662 +----------------------------------------------------------------------------*/
1663 function_prolog(dcbz_area)
1664 rlwinm. r5,r4,0,27,31
1665 rlwinm r5,r4,27,5,31
1674 function_epilog(dcbz_area)
1675 #endif /* CONFIG_440 */
1676 #endif /* CONFIG_NAND_SPL */
1678 /*------------------------------------------------------------------------------- */
1680 /* Description: Input 8 bits */
1681 /*------------------------------------------------------------------------------- */
1687 /*------------------------------------------------------------------------------- */
1688 /* Function: out8 */
1689 /* Description: Output 8 bits */
1690 /*------------------------------------------------------------------------------- */
1696 /*------------------------------------------------------------------------------- */
1697 /* Function: out32 */
1698 /* Description: Output 32 bits */
1699 /*------------------------------------------------------------------------------- */
1705 /*------------------------------------------------------------------------------- */
1706 /* Function: in32 */
1707 /* Description: Input 32 bits */
1708 /*------------------------------------------------------------------------------- */
1714 /**************************************************************************/
1715 /* PPC405EP specific stuff */
1716 /**************************************************************************/
1720 #ifdef CONFIG_BUBINGA
1722 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1723 * function) to support FPGA and NVRAM accesses below.
1726 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1727 ori r3,r3,GPIO0_OSRH@l
1728 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1729 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
1732 ori r3,r3,GPIO0_OSRL@l
1733 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1734 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
1737 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1738 ori r3,r3,GPIO0_ISR1H@l
1739 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1740 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
1742 lis r3,GPIO0_ISR1L@h
1743 ori r3,r3,GPIO0_ISR1L@l
1744 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1745 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
1748 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1749 ori r3,r3,GPIO0_TSRH@l
1750 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1751 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
1754 ori r3,r3,GPIO0_TSRL@l
1755 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1756 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
1759 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1760 ori r3,r3,GPIO0_TCR@l
1761 lis r4,CONFIG_SYS_GPIO0_TCR@h
1762 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
1765 li r3,PB1AP /* program EBC bank 1 for RTC access */
1766 mtdcr EBC0_CFGADDR,r3
1767 lis r3,CONFIG_SYS_EBC_PB1AP@h
1768 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
1769 mtdcr EBC0_CFGDATA,r3
1771 mtdcr EBC0_CFGADDR,r3
1772 lis r3,CONFIG_SYS_EBC_PB1CR@h
1773 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
1774 mtdcr EBC0_CFGDATA,r3
1776 li r3,PB1AP /* program EBC bank 1 for RTC access */
1777 mtdcr EBC0_CFGADDR,r3
1778 lis r3,CONFIG_SYS_EBC_PB1AP@h
1779 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
1780 mtdcr EBC0_CFGDATA,r3
1782 mtdcr EBC0_CFGADDR,r3
1783 lis r3,CONFIG_SYS_EBC_PB1CR@h
1784 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
1785 mtdcr EBC0_CFGDATA,r3
1787 li r3,PB4AP /* program EBC bank 4 for FPGA access */
1788 mtdcr EBC0_CFGADDR,r3
1789 lis r3,CONFIG_SYS_EBC_PB4AP@h
1790 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
1791 mtdcr EBC0_CFGDATA,r3
1793 mtdcr EBC0_CFGADDR,r3
1794 lis r3,CONFIG_SYS_EBC_PB4CR@h
1795 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
1796 mtdcr EBC0_CFGDATA,r3
1800 !-----------------------------------------------------------------------
1801 ! Check to see if chip is in bypass mode.
1802 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1803 ! CPU reset Otherwise, skip this step and keep going.
1804 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1805 ! will not be fast enough for the SDRAM (min 66MHz)
1806 !-----------------------------------------------------------------------
1808 mfdcr r5, CPC0_PLLMR1
1809 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
1812 beq pll_done /* if SSCS =b'1' then PLL has */
1813 /* already been set */
1814 /* and CPU has been reset */
1815 /* so skip to next section */
1817 #ifdef CONFIG_BUBINGA
1819 !-----------------------------------------------------------------------
1820 ! Read NVRAM to get value to write in PLLMR.
1821 ! If value has not been correctly saved, write default value
1822 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1823 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1825 ! WARNING: This code assumes the first three words in the nvram_t
1826 ! structure in openbios.h. Changing the beginning of
1827 ! the structure will break this code.
1829 !-----------------------------------------------------------------------
1831 addis r3,0,NVRAM_BASE@h
1832 addi r3,r3,NVRAM_BASE@l
1835 addis r5,0,NVRVFY1@h
1836 addi r5,r5,NVRVFY1@l
1837 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
1841 addis r5,0,NVRVFY2@h
1842 addi r5,r5,NVRVFY2@l
1843 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
1845 addi r3,r3,8 /* Skip over conf_size */
1846 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1847 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1848 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1849 cmpi cr0,0,r5,1 /* See if PLL is locked */
1852 #endif /* CONFIG_BUBINGA */
1856 andi. r5, r4, CPC0_BOOT_SEP@l
1857 bne strap_1 /* serial eeprom present */
1858 addis r5,0,CPLD_REG0_ADDR@h
1859 ori r5,r5,CPLD_REG0_ADDR@l
1862 #endif /* CONFIG_TAIHU */
1864 #if defined(CONFIG_ZEUS)
1866 andi. r5, r4, CPC0_BOOT_SEP@l
1867 bne strap_1 /* serial eeprom present */
1874 mfdcr r3, CPC0_PLLMR0
1875 mfdcr r4, CPC0_PLLMR1
1879 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1880 ori r3,r3,PLLMR0_DEFAULT@l /* */
1881 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1882 ori r4,r4,PLLMR1_DEFAULT@l /* */
1887 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1888 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1889 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1890 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1893 mfdcr r3, CPC0_PLLMR0
1894 mfdcr r4, CPC0_PLLMR1
1895 #endif /* CONFIG_TAIHU */
1898 b pll_write /* Write the CPC0_PLLMR with new value */
1902 !-----------------------------------------------------------------------
1903 ! Clear Soft Reset Register
1904 ! This is needed to enable PCI if not booting from serial EPROM
1905 !-----------------------------------------------------------------------
1915 blr /* return to main code */
1918 !-----------------------------------------------------------------------------
1919 ! Function: pll_write
1920 ! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1922 ! 1. Pll is first disabled (de-activated by putting in bypass mode)
1924 ! 3. Clock dividers are set while PLL is held in reset and bypassed
1925 ! 4. PLL Reset is cleared
1926 ! 5. Wait 100us for PLL to lock
1927 ! 6. A core reset is performed
1928 ! Input: r3 = Value to write to CPC0_PLLMR0
1929 ! Input: r4 = Value to write to CPC0_PLLMR1
1931 !-----------------------------------------------------------------------------
1937 ori r5,r5,0x0101 /* Stop the UART clocks */
1938 mtdcr CPC0_UCR,r5 /* Before changing PLL */
1940 mfdcr r5, CPC0_PLLMR1
1941 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
1942 mtdcr CPC0_PLLMR1,r5
1943 oris r5,r5,0x4000 /* Set PLL Reset */
1944 mtdcr CPC0_PLLMR1,r5
1946 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
1947 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
1948 oris r5,r5,0x4000 /* Set PLL Reset */
1949 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
1950 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
1951 mtdcr CPC0_PLLMR1,r5
1954 ! Wait min of 100us for PLL to lock.
1955 ! See CMOS 27E databook for more info.
1956 ! At 200MHz, that means waiting 20,000 instructions
1958 addi r3,0,20000 /* 2000 = 0x4e20 */
1963 oris r5,r5,0x8000 /* Enable PLL */
1964 mtdcr CPC0_PLLMR1,r5 /* Engage */
1967 * Reset CPU to guarantee timings are OK
1968 * Not sure if this is needed...
1971 mtspr SPRN_DBCR0,r3 /* This will cause a CPU core reset, and */
1972 /* execution will continue from the poweron */
1973 /* vector of 0xfffffffc */
1974 #endif /* CONFIG_405EP */
1976 #if defined(CONFIG_440)
1977 /*----------------------------------------------------------------------------+
1979 +----------------------------------------------------------------------------*/
1980 function_prolog(mttlb3)
1983 function_epilog(mttlb3)
1985 /*----------------------------------------------------------------------------+
1987 +----------------------------------------------------------------------------*/
1988 function_prolog(mftlb3)
1991 function_epilog(mftlb3)
1993 /*----------------------------------------------------------------------------+
1995 +----------------------------------------------------------------------------*/
1996 function_prolog(mttlb2)
1999 function_epilog(mttlb2)
2001 /*----------------------------------------------------------------------------+
2003 +----------------------------------------------------------------------------*/
2004 function_prolog(mftlb2)
2007 function_epilog(mftlb2)
2009 /*----------------------------------------------------------------------------+
2011 +----------------------------------------------------------------------------*/
2012 function_prolog(mttlb1)
2015 function_epilog(mttlb1)
2017 /*----------------------------------------------------------------------------+
2019 +----------------------------------------------------------------------------*/
2020 function_prolog(mftlb1)
2023 function_epilog(mftlb1)
2024 #endif /* CONFIG_440 */
2026 #if defined(CONFIG_NAND_SPL)
2028 * void nand_boot_relocate(dst, src, bytes)
2030 * r3 = Destination address to copy code to (in SDRAM)
2031 * r4 = Source address to copy code from
2032 * r5 = size to copy in bytes
2040 * Copy SPL from icache into SDRAM
2052 * Calculate "corrected" link register, so that we "continue"
2053 * in execution in destination range
2055 sub r3,r7,r6 /* r3 = src - dst */
2056 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2062 * First initialize SDRAM. It has to be available *before* calling
2065 lis r3,CONFIG_SYS_SDRAM_BASE@h
2066 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
2070 * Now copy the 4k SPL code into SDRAM and continue execution
2073 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2074 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2075 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2076 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2077 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2078 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
2079 bl nand_boot_relocate
2082 * We're running from SDRAM now!!!
2084 * It is necessary for 4xx systems to relocate from running at
2085 * the original location (0xfffffxxx) to somewhere else (SDRAM
2086 * preferably). This is because CS0 needs to be reconfigured for
2087 * NAND access. And we can't reconfigure this CS when currently
2088 * "running" from it.
2092 * Finally call nand_boot() to load main NAND U-Boot image from
2093 * NAND and jump to it.
2095 bl nand_boot /* will not return */
2096 #endif /* CONFIG_NAND_SPL */