xref: /openbmc/u-boot/arch/powerpc/cpu/mpc85xx/start.S (revision 0c3b301f79fcad081c8509ee4cb06e7b0478c8c1)
183d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */
2a47a12beSStefan Roese/*
3a4107f86SPrabhakar Kushwaha * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc.
4a47a12beSStefan Roese * Copyright (C) 2003  Motorola,Inc.
5a47a12beSStefan Roese */
6a47a12beSStefan Roese
7a47a12beSStefan Roese/* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
8a47a12beSStefan Roese *
9a47a12beSStefan Roese * The processor starts at 0xfffffffc and the code is first executed in the
10a47a12beSStefan Roese * last 4K page(0xfffff000-0xffffffff) in flash/rom.
11a47a12beSStefan Roese *
12a47a12beSStefan Roese */
13a47a12beSStefan Roese
1425ddd1fbSWolfgang Denk#include <asm-offsets.h>
15a47a12beSStefan Roese#include <config.h>
16a47a12beSStefan Roese#include <mpc85xx.h>
17a47a12beSStefan Roese#include <version.h>
18a47a12beSStefan Roese
19a47a12beSStefan Roese#include <ppc_asm.tmpl>
20a47a12beSStefan Roese#include <ppc_defs.h>
21a47a12beSStefan Roese
22a47a12beSStefan Roese#include <asm/cache.h>
23a47a12beSStefan Roese#include <asm/mmu.h>
24a47a12beSStefan Roese
25a47a12beSStefan Roese#undef	MSR_KERNEL
26a47a12beSStefan Roese#define MSR_KERNEL ( MSR_ME )	/* Machine Check */
27a47a12beSStefan Roese
28b26df185SPrabhakar Kushwaha#define LAW_EN		0x80000000
29b26df185SPrabhakar Kushwaha
304b919725SScott Wood#if defined(CONFIG_NAND_SPL) || \
314b919725SScott Wood	(defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
324b919725SScott Wood#define MINIMAL_SPL
334b919725SScott Wood#endif
344b919725SScott Wood
3517b86147SLiu Gang#if !defined(CONFIG_SPL) && !defined(CONFIG_SYS_RAMBOOT) && \
3617b86147SLiu Gang	!defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SRIO_PCIE_BOOT_SLAVE)
374b919725SScott Wood#define NOR_BOOT
384b919725SScott Wood#endif
394b919725SScott Wood
40a47a12beSStefan Roese/*
41a47a12beSStefan Roese * Set up GOT: Global Offset Table
42a47a12beSStefan Roese *
43a47a12beSStefan Roese * Use r12 to access the GOT
44a47a12beSStefan Roese */
45a47a12beSStefan Roese	START_GOT
46a47a12beSStefan Roese	GOT_ENTRY(_GOT2_TABLE_)
47a47a12beSStefan Roese	GOT_ENTRY(_FIXUP_TABLE_)
48a47a12beSStefan Roese
494b919725SScott Wood#ifndef MINIMAL_SPL
50a47a12beSStefan Roese	GOT_ENTRY(_start)
51a47a12beSStefan Roese	GOT_ENTRY(_start_of_vectors)
52a47a12beSStefan Roese	GOT_ENTRY(_end_of_vectors)
53a47a12beSStefan Roese	GOT_ENTRY(transfer_to_handler)
54a47a12beSStefan Roese#endif
55a47a12beSStefan Roese
56a47a12beSStefan Roese	GOT_ENTRY(__init_end)
573929fb0aSSimon Glass	GOT_ENTRY(__bss_end)
58a47a12beSStefan Roese	GOT_ENTRY(__bss_start)
59a47a12beSStefan Roese	END_GOT
60a47a12beSStefan Roese
61a47a12beSStefan Roese/*
62a47a12beSStefan Roese * e500 Startup -- after reset only the last 4KB of the effective
63a47a12beSStefan Roese * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
64a47a12beSStefan Roese * section is located at THIS LAST page and basically does three
65a47a12beSStefan Roese * things: clear some registers, set up exception tables and
66a47a12beSStefan Roese * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
67a47a12beSStefan Roese * continue the boot procedure.
68a47a12beSStefan Roese
69a47a12beSStefan Roese * Once the boot rom is mapped by TLB entries we can proceed
70a47a12beSStefan Roese * with normal startup.
71a47a12beSStefan Roese *
72a47a12beSStefan Roese */
73a47a12beSStefan Roese
74a47a12beSStefan Roese	.section .bootpg,"ax"
75a47a12beSStefan Roese	.globl _start_e500
76a47a12beSStefan Roese
77a47a12beSStefan Roese_start_e500:
785344f7a2SPrabhakar Kushwaha/* Enable debug exception */
795344f7a2SPrabhakar Kushwaha	li	r1,MSR_DE
805344f7a2SPrabhakar Kushwaha	mtmsr 	r1
81a47a12beSStefan Roese
82fa08d395SAlexander Graf	/*
83fa08d395SAlexander Graf	 * If we got an ePAPR device tree pointer passed in as r3, we need that
84fa08d395SAlexander Graf	 * later in cpu_init_early_f(). Save it to a safe register before we
85fa08d395SAlexander Graf	 * clobber it so that we can fetch it from there later.
86fa08d395SAlexander Graf	 */
87fa08d395SAlexander Graf	mr	r24, r3
88fa08d395SAlexander Graf
8933eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
9033eee330SScott Wood	mfspr	r3,SPRN_SVR
9133eee330SScott Wood	rlwinm	r3,r3,0,0xff
9233eee330SScott Wood	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
9333eee330SScott Wood	cmpw	r3,r4
9433eee330SScott Wood	beq	1f
9533eee330SScott Wood
9633eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
9733eee330SScott Wood	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
9833eee330SScott Wood	cmpw	r3,r4
9933eee330SScott Wood	beq	1f
10033eee330SScott Wood#endif
10133eee330SScott Wood
10233eee330SScott Wood	/* Not a supported revision affected by erratum */
10333eee330SScott Wood	li	r27,0
10433eee330SScott Wood	b	2f
10533eee330SScott Wood
10633eee330SScott Wood1:	li	r27,1	/* Remember for later that we have the erratum */
10733eee330SScott Wood	/* Erratum says set bits 55:60 to 001001 */
10833eee330SScott Wood	msync
10933eee330SScott Wood	isync
110cd7ad629SAndy Fleming	mfspr	r3,SPRN_HDBCR0
11133eee330SScott Wood	li	r4,0x48
11233eee330SScott Wood	rlwimi	r3,r4,0,0x1f8
113cd7ad629SAndy Fleming	mtspr	SPRN_HDBCR0,r3
11433eee330SScott Wood	isync
11533eee330SScott Wood2:
11633eee330SScott Wood#endif
117954a1a47SYork Sun#ifdef CONFIG_SYS_FSL_ERRATUM_A005125
118954a1a47SYork Sun	msync
119954a1a47SYork Sun	isync
120954a1a47SYork Sun	mfspr	r3, SPRN_HDBCR0
121954a1a47SYork Sun	oris	r3, r3, 0x0080
122954a1a47SYork Sun	mtspr	SPRN_HDBCR0, r3
123954a1a47SYork Sun#endif
124954a1a47SYork Sun
12533eee330SScott Wood
126fb4a2409SAneesh Bansal#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC) && \
127fb4a2409SAneesh Bansal	!defined(CONFIG_E6500)
1287065b7d4SRuchika Gupta	/* ISBC uses L2 as stack.
1297065b7d4SRuchika Gupta	 * Disable L2 cache here so that u-boot can enable it later
1307065b7d4SRuchika Gupta	 * as part of it's normal flow
1317065b7d4SRuchika Gupta	*/
1327065b7d4SRuchika Gupta
1337065b7d4SRuchika Gupta	/* Check if L2 is enabled */
1347065b7d4SRuchika Gupta	mfspr	r3, SPRN_L2CSR0
1357065b7d4SRuchika Gupta	lis	r2, L2CSR0_L2E@h
1367065b7d4SRuchika Gupta	ori	r2, r2, L2CSR0_L2E@l
1377065b7d4SRuchika Gupta	and.	r4, r3, r2
1387065b7d4SRuchika Gupta	beq	l2_disabled
1397065b7d4SRuchika Gupta
1407065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1417065b7d4SRuchika Gupta	/* Flush L2 cache */
1427065b7d4SRuchika Gupta	lis     r2,(L2CSR0_L2FL)@h
1437065b7d4SRuchika Gupta	ori     r2, r2, (L2CSR0_L2FL)@l
1447065b7d4SRuchika Gupta	or      r3, r2, r3
1457065b7d4SRuchika Gupta	sync
1467065b7d4SRuchika Gupta	isync
1477065b7d4SRuchika Gupta	mtspr   SPRN_L2CSR0,r3
1487065b7d4SRuchika Gupta	isync
1497065b7d4SRuchika Gupta1:
1507065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1517065b7d4SRuchika Gupta	and. r1, r3, r2
1527065b7d4SRuchika Gupta	bne 1b
1537065b7d4SRuchika Gupta
1547065b7d4SRuchika Gupta	mfspr r3, SPRN_L2CSR0
1557065b7d4SRuchika Gupta	lis r2, L2CSR0_L2E@h
1567065b7d4SRuchika Gupta	ori r2, r2, L2CSR0_L2E@l
1577065b7d4SRuchika Gupta	andc r4, r3, r2
1587065b7d4SRuchika Gupta	sync
1597065b7d4SRuchika Gupta	isync
1607065b7d4SRuchika Gupta	mtspr SPRN_L2CSR0,r4
1617065b7d4SRuchika Gupta	isync
1627065b7d4SRuchika Gupta
1637065b7d4SRuchika Guptal2_disabled:
1647065b7d4SRuchika Gupta#endif
1657065b7d4SRuchika Gupta
166a47a12beSStefan Roese/* clear registers/arrays not reset by hardware */
167a47a12beSStefan Roese
168a47a12beSStefan Roese	/* L1 */
169a47a12beSStefan Roese	li	r0,2
170a47a12beSStefan Roese	mtspr	L1CSR0,r0	/* invalidate d-cache */
171a47a12beSStefan Roese	mtspr	L1CSR1,r0	/* invalidate i-cache */
172a47a12beSStefan Roese
173a47a12beSStefan Roese	mfspr	r1,DBSR
174a47a12beSStefan Roese	mtspr	DBSR,r1		/* Clear all valid bits */
175a47a12beSStefan Roese
176a47a12beSStefan Roese
17769c78267SYork Sun	.macro	create_tlb1_entry esel ts tsize epn wimg rpn perm phy_high scratch
17869c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
17969c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
18069c78267SYork Sun	mtspr	MAS0, \scratch
18169c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@h
18269c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@l
18369c78267SYork Sun	mtspr	MAS1, \scratch
18469c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
18569c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
18669c78267SYork Sun	mtspr	MAS2, \scratch
18769c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
18869c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
18969c78267SYork Sun	mtspr	MAS3, \scratch
19069c78267SYork Sun	lis	\scratch, \phy_high@h
19169c78267SYork Sun	ori	\scratch, \scratch, \phy_high@l
19269c78267SYork Sun	mtspr	MAS7, \scratch
19369c78267SYork Sun	isync
19469c78267SYork Sun	msync
19569c78267SYork Sun	tlbwe
19669c78267SYork Sun	isync
19769c78267SYork Sun	.endm
19869c78267SYork Sun
19969c78267SYork Sun	.macro	create_tlb0_entry esel ts tsize epn wimg rpn perm phy_high scratch
20069c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
20169c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
20269c78267SYork Sun	mtspr	MAS0, \scratch
20369c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@h
20469c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@l
20569c78267SYork Sun	mtspr	MAS1, \scratch
20669c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
20769c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
20869c78267SYork Sun	mtspr	MAS2, \scratch
20969c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
21069c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
21169c78267SYork Sun	mtspr	MAS3, \scratch
21269c78267SYork Sun	lis	\scratch, \phy_high@h
21369c78267SYork Sun	ori	\scratch, \scratch, \phy_high@l
21469c78267SYork Sun	mtspr	MAS7, \scratch
21569c78267SYork Sun	isync
21669c78267SYork Sun	msync
21769c78267SYork Sun	tlbwe
21869c78267SYork Sun	isync
21969c78267SYork Sun	.endm
22069c78267SYork Sun
22169c78267SYork Sun	.macro	delete_tlb1_entry esel scratch
22269c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
22369c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
22469c78267SYork Sun	mtspr	MAS0, \scratch
22569c78267SYork Sun	li	\scratch, 0
22669c78267SYork Sun	mtspr	MAS1, \scratch
22769c78267SYork Sun	isync
22869c78267SYork Sun	msync
22969c78267SYork Sun	tlbwe
23069c78267SYork Sun	isync
23169c78267SYork Sun	.endm
23269c78267SYork Sun
23369c78267SYork Sun	.macro	delete_tlb0_entry esel epn wimg scratch
23469c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
23569c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
23669c78267SYork Sun	mtspr	MAS0, \scratch
23769c78267SYork Sun	li	\scratch, 0
23869c78267SYork Sun	mtspr	MAS1, \scratch
23969c78267SYork Sun	lis	\scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
24069c78267SYork Sun	ori	\scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
24169c78267SYork Sun	mtspr	MAS2, \scratch
24269c78267SYork Sun	isync
24369c78267SYork Sun	msync
24469c78267SYork Sun	tlbwe
24569c78267SYork Sun	isync
24669c78267SYork Sun	.endm
24769c78267SYork Sun
2484b919725SScott Wood/* Interrupt vectors do not fit in minimal SPL. */
2494b919725SScott Wood#if !defined(MINIMAL_SPL)
250a47a12beSStefan Roese	/* Setup interrupt vectors */
2510635b09cSHaiying Wang	lis	r1,CONFIG_SYS_MONITOR_BASE@h
252a47a12beSStefan Roese	mtspr	IVPR,r1
253a47a12beSStefan Roese
25496d2bb95SScott Wood	li	r4,CriticalInput@l
255a4107f86SPrabhakar Kushwaha	mtspr	IVOR0,r4	/* 0: Critical input */
25696d2bb95SScott Wood	li	r4,MachineCheck@l
257a4107f86SPrabhakar Kushwaha	mtspr	IVOR1,r4	/* 1: Machine check */
25896d2bb95SScott Wood	li	r4,DataStorage@l
259a4107f86SPrabhakar Kushwaha	mtspr	IVOR2,r4	/* 2: Data storage */
26096d2bb95SScott Wood	li	r4,InstStorage@l
261a4107f86SPrabhakar Kushwaha	mtspr	IVOR3,r4	/* 3: Instruction storage */
26296d2bb95SScott Wood	li	r4,ExtInterrupt@l
263a4107f86SPrabhakar Kushwaha	mtspr	IVOR4,r4	/* 4: External interrupt */
26496d2bb95SScott Wood	li	r4,Alignment@l
265a4107f86SPrabhakar Kushwaha	mtspr	IVOR5,r4	/* 5: Alignment */
26696d2bb95SScott Wood	li	r4,ProgramCheck@l
267a4107f86SPrabhakar Kushwaha	mtspr	IVOR6,r4	/* 6: Program check */
26896d2bb95SScott Wood	li	r4,FPUnavailable@l
269a4107f86SPrabhakar Kushwaha	mtspr	IVOR7,r4	/* 7: floating point unavailable */
27096d2bb95SScott Wood	li	r4,SystemCall@l
271a4107f86SPrabhakar Kushwaha	mtspr	IVOR8,r4	/* 8: System call */
272a47a12beSStefan Roese	/* 9: Auxiliary processor unavailable(unsupported) */
27396d2bb95SScott Wood	li	r4,Decrementer@l
274a4107f86SPrabhakar Kushwaha	mtspr	IVOR10,r4	/* 10: Decrementer */
27596d2bb95SScott Wood	li	r4,IntervalTimer@l
276a4107f86SPrabhakar Kushwaha	mtspr	IVOR11,r4	/* 11: Interval timer */
27796d2bb95SScott Wood	li	r4,WatchdogTimer@l
278a4107f86SPrabhakar Kushwaha	mtspr	IVOR12,r4	/* 12: Watchdog timer */
27996d2bb95SScott Wood	li	r4,DataTLBError@l
280a4107f86SPrabhakar Kushwaha	mtspr	IVOR13,r4	/* 13: Data TLB error */
28196d2bb95SScott Wood	li	r4,InstructionTLBError@l
282a4107f86SPrabhakar Kushwaha	mtspr	IVOR14,r4	/* 14: Instruction TLB error */
28396d2bb95SScott Wood	li	r4,DebugBreakpoint@l
284a4107f86SPrabhakar Kushwaha	mtspr	IVOR15,r4	/* 15: Debug */
285119a55f9SPrabhakar Kushwaha#endif
286a47a12beSStefan Roese
287a47a12beSStefan Roese	/* Clear and set up some registers. */
288a47a12beSStefan Roese	li      r0,0x0000
289a47a12beSStefan Roese	lis	r1,0xffff
290a47a12beSStefan Roese	mtspr	DEC,r0			/* prevent dec exceptions */
291a47a12beSStefan Roese	mttbl	r0			/* prevent fit & wdt exceptions */
292a47a12beSStefan Roese	mttbu	r0
293a47a12beSStefan Roese	mtspr	TSR,r1			/* clear all timer exception status */
294a47a12beSStefan Roese	mtspr	TCR,r0			/* disable all */
295a47a12beSStefan Roese	mtspr	ESR,r0			/* clear exception syndrome register */
296a47a12beSStefan Roese	mtspr	MCSR,r0			/* machine check syndrome register */
297a47a12beSStefan Roese	mtxer	r0			/* clear integer exception register */
298a47a12beSStefan Roese
299a47a12beSStefan Roese#ifdef CONFIG_SYS_BOOK3E_HV
300a47a12beSStefan Roese	mtspr	MAS8,r0			/* make sure MAS8 is clear */
301a47a12beSStefan Roese#endif
302a47a12beSStefan Roese
303a47a12beSStefan Roese	/* Enable Time Base and Select Time Base Clock */
304a47a12beSStefan Roese	lis	r0,HID0_EMCP@h		/* Enable machine check */
305a47a12beSStefan Roese#if defined(CONFIG_ENABLE_36BIT_PHYS)
306a47a12beSStefan Roese	ori	r0,r0,HID0_ENMAS7@l	/* Enable MAS7 */
307a47a12beSStefan Roese#endif
308a47a12beSStefan Roese#ifndef CONFIG_E500MC
309a47a12beSStefan Roese	ori	r0,r0,HID0_TBEN@l	/* Enable Timebase */
310a47a12beSStefan Roese#endif
311a47a12beSStefan Roese	mtspr	HID0,r0
312a47a12beSStefan Roese
31310343403SYork Sun#if !defined(CONFIG_E500MC) && !defined(CONFIG_ARCH_QEMU_E500)
314a47a12beSStefan Roese	li	r0,(HID1_ASTME|HID1_ABE)@l	/* Addr streaming & broadcast */
315a47a12beSStefan Roese	mfspr	r3,PVR
316a47a12beSStefan Roese	andi.	r3,r3, 0xff
317a47a12beSStefan Roese	cmpwi	r3,0x50@l	/* if we are rev 5.0 or greater set MBDD */
318a47a12beSStefan Roese	blt 1f
319a47a12beSStefan Roese	/* Set MBDD bit also */
320a47a12beSStefan Roese	ori r0, r0, HID1_MBDD@l
321a47a12beSStefan Roese1:
322a47a12beSStefan Roese	mtspr	HID1,r0
323a47a12beSStefan Roese#endif
324a47a12beSStefan Roese
32543f082bbSKumar Gala#ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
326cd7ad629SAndy Fleming	mfspr	r3,SPRN_HDBCR1
32743f082bbSKumar Gala	oris	r3,r3,0x0100
328cd7ad629SAndy Fleming	mtspr	SPRN_HDBCR1,r3
32943f082bbSKumar Gala#endif
33043f082bbSKumar Gala
331a47a12beSStefan Roese	/* Enable Branch Prediction */
332a47a12beSStefan Roese#if defined(CONFIG_BTB)
333a47a12beSStefan Roese	lis	r0,BUCSR_ENABLE@h
334a47a12beSStefan Roese	ori	r0,r0,BUCSR_ENABLE@l
335a47a12beSStefan Roese	mtspr	SPRN_BUCSR,r0
336a47a12beSStefan Roese#endif
337a47a12beSStefan Roese
338a47a12beSStefan Roese#if defined(CONFIG_SYS_INIT_DBCR)
339a47a12beSStefan Roese	lis	r1,0xffff
340a47a12beSStefan Roese	ori	r1,r1,0xffff
341a47a12beSStefan Roese	mtspr	DBSR,r1			/* Clear all status bits */
342a47a12beSStefan Roese	lis	r0,CONFIG_SYS_INIT_DBCR@h	/* DBCR0[IDM] must be set */
343a47a12beSStefan Roese	ori	r0,r0,CONFIG_SYS_INIT_DBCR@l
344a47a12beSStefan Roese	mtspr	DBCR0,r0
345a47a12beSStefan Roese#endif
346a47a12beSStefan Roese
34723b36a7dSYork Sun#ifdef CONFIG_ARCH_MPC8569
348a47a12beSStefan Roese#define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
349a47a12beSStefan Roese#define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
350a47a12beSStefan Roese
351a47a12beSStefan Roese	/* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
352a47a12beSStefan Roese	 * use address space which is more than 12bits, and it must be done in
353a47a12beSStefan Roese	 * the 4K boot page. So we set this bit here.
354a47a12beSStefan Roese	 */
355a47a12beSStefan Roese
356a47a12beSStefan Roese	/* create a temp mapping TLB0[0] for LBCR  */
35769c78267SYork Sun	create_tlb0_entry 0, \
35869c78267SYork Sun		0, BOOKE_PAGESZ_4K, \
35969c78267SYork Sun		CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G, \
36069c78267SYork Sun		CONFIG_SYS_LBC_ADDR, MAS3_SW|MAS3_SR, \
36169c78267SYork Sun		0, r6
362a47a12beSStefan Roese
363a47a12beSStefan Roese	/* Set LBCR register */
364a47a12beSStefan Roese	lis     r4,CONFIG_SYS_LBCR_ADDR@h
365a47a12beSStefan Roese	ori     r4,r4,CONFIG_SYS_LBCR_ADDR@l
366a47a12beSStefan Roese
367a47a12beSStefan Roese	lis     r5,CONFIG_SYS_LBC_LBCR@h
368a47a12beSStefan Roese	ori     r5,r5,CONFIG_SYS_LBC_LBCR@l
369a47a12beSStefan Roese	stw     r5,0(r4)
370a47a12beSStefan Roese	isync
371a47a12beSStefan Roese
372a47a12beSStefan Roese	/* invalidate this temp TLB */
373a47a12beSStefan Roese	lis	r4,CONFIG_SYS_LBC_ADDR@h
374a47a12beSStefan Roese	ori	r4,r4,CONFIG_SYS_LBC_ADDR@l
375a47a12beSStefan Roese	tlbivax	0,r4
376a47a12beSStefan Roese	isync
377a47a12beSStefan Roese
37823b36a7dSYork Sun#endif /* CONFIG_ARCH_MPC8569 */
379a47a12beSStefan Roese
3806ca88b09STimur Tabi/*
38172243c01STimur Tabi * Search for the TLB that covers the code we're executing, and shrink it
38272243c01STimur Tabi * so that it covers only this 4K page.  That will ensure that any other
38372243c01STimur Tabi * TLB we create won't interfere with it.  We assume that the TLB exists,
3843ea21536SScott Wood * which is why we don't check the Valid bit of MAS1.  We also assume
3853ea21536SScott Wood * it is in TLB1.
38672243c01STimur Tabi *
38772243c01STimur Tabi * This is necessary, for example, when booting from the on-chip ROM,
38872243c01STimur Tabi * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
38972243c01STimur Tabi */
39072243c01STimur Tabi	bl	nexti		/* Find our address */
39172243c01STimur Tabinexti:	mflr	r1		/* R1 = our PC */
39272243c01STimur Tabi	li	r2, 0
39372243c01STimur Tabi	mtspr	MAS6, r2	/* Assume the current PID and AS are 0 */
39472243c01STimur Tabi	isync
39572243c01STimur Tabi	msync
39672243c01STimur Tabi	tlbsx	0, r1		/* This must succeed */
39772243c01STimur Tabi
3983ea21536SScott Wood	mfspr	r14, MAS0	/* Save ESEL for later */
3993ea21536SScott Wood	rlwinm	r14, r14, 16, 0xfff
4003ea21536SScott Wood
40172243c01STimur Tabi	/* Set the size of the TLB to 4KB */
40272243c01STimur Tabi	mfspr	r3, MAS1
40331d084ddSScott Wood	li	r2, 0xF80
40472243c01STimur Tabi	andc	r3, r3, r2	/* Clear the TSIZE bits */
40572243c01STimur Tabi	ori	r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
4063ea21536SScott Wood	oris	r3, r3, MAS1_IPROT@h
40772243c01STimur Tabi	mtspr	MAS1, r3
40872243c01STimur Tabi
40972243c01STimur Tabi	/*
41072243c01STimur Tabi	 * Set the base address of the TLB to our PC.  We assume that
41172243c01STimur Tabi	 * virtual == physical.  We also assume that MAS2_EPN == MAS3_RPN.
41272243c01STimur Tabi	 */
41372243c01STimur Tabi	lis	r3, MAS2_EPN@h
41472243c01STimur Tabi	ori	r3, r3, MAS2_EPN@l	/* R3 = MAS2_EPN */
41572243c01STimur Tabi
41672243c01STimur Tabi	and	r1, r1, r3	/* Our PC, rounded down to the nearest page */
41772243c01STimur Tabi
41872243c01STimur Tabi	mfspr	r2, MAS2
41972243c01STimur Tabi	andc	r2, r2, r3
42072243c01STimur Tabi	or	r2, r2, r1
42133eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
42233eee330SScott Wood	cmpwi	r27,0
42333eee330SScott Wood	beq	1f
42433eee330SScott Wood	andi.	r15, r2, MAS2_I|MAS2_G /* save the old I/G for later */
42533eee330SScott Wood	rlwinm	r2, r2, 0, ~MAS2_I
42633eee330SScott Wood	ori	r2, r2, MAS2_G
42733eee330SScott Wood1:
42833eee330SScott Wood#endif
42972243c01STimur Tabi	mtspr	MAS2, r2	/* Set the EPN to our PC base address */
43072243c01STimur Tabi
43172243c01STimur Tabi	mfspr	r2, MAS3
43272243c01STimur Tabi	andc	r2, r2, r3
43372243c01STimur Tabi	or	r2, r2, r1
43472243c01STimur Tabi	mtspr	MAS3, r2	/* Set the RPN to our PC base address */
43572243c01STimur Tabi
43672243c01STimur Tabi	isync
43772243c01STimur Tabi	msync
43872243c01STimur Tabi	tlbwe
43972243c01STimur Tabi
44072243c01STimur Tabi/*
4413ea21536SScott Wood * Clear out any other TLB entries that may exist, to avoid conflicts.
4423ea21536SScott Wood * Our TLB entry is in r14.
4433ea21536SScott Wood */
4443ea21536SScott Wood	li	r0, TLBIVAX_ALL | TLBIVAX_TLB0
4453ea21536SScott Wood	tlbivax 0, r0
4463ea21536SScott Wood	tlbsync
4473ea21536SScott Wood
4483ea21536SScott Wood	mfspr	r4, SPRN_TLB1CFG
4493ea21536SScott Wood	rlwinm	r4, r4, 0, TLBnCFG_NENTRY_MASK
4503ea21536SScott Wood
4513ea21536SScott Wood	li	r3, 0
4523ea21536SScott Wood	mtspr	MAS1, r3
4533ea21536SScott Wood1:	cmpw	r3, r14
4543ea21536SScott Wood	rlwinm	r5, r3, 16, MAS0_ESEL_MSK
4553ea21536SScott Wood	addi	r3, r3, 1
4563ea21536SScott Wood	beq	2f		/* skip the entry we're executing from */
4573ea21536SScott Wood
4583ea21536SScott Wood	oris	r5, r5, MAS0_TLBSEL(1)@h
4593ea21536SScott Wood	mtspr	MAS0, r5
4603ea21536SScott Wood
4613ea21536SScott Wood	isync
4623ea21536SScott Wood	tlbwe
4633ea21536SScott Wood	isync
4643ea21536SScott Wood	msync
4653ea21536SScott Wood
4663ea21536SScott Wood2:	cmpw	r3, r4
4673ea21536SScott Wood	blt	1b
4683ea21536SScott Wood
469f978f7c2SAneesh Bansal#if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && !defined(MINIMAL_SPL) && \
470f978f7c2SAneesh Bansal	!defined(CONFIG_SECURE_BOOT)
471f545d300SScott Wood/*
472f545d300SScott Wood * TLB entry for debuggging in AS1
473f545d300SScott Wood * Create temporary TLB entry in AS0 to handle debug exception
474f545d300SScott Wood * As on debug exception MSR is cleared i.e. Address space is changed
475f545d300SScott Wood * to 0. A TLB entry (in AS0) is required to handle debug exception generated
476f545d300SScott Wood * in AS1.
477f545d300SScott Wood */
478f545d300SScott Wood
4794b919725SScott Wood#ifdef NOR_BOOT
480f545d300SScott Wood/*
481f545d300SScott Wood * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
482f545d300SScott Wood * bacause flash's virtual address maps to 0xff800000 - 0xffffffff.
483f545d300SScott Wood * and this window is outside of 4K boot window.
484f545d300SScott Wood */
485f545d300SScott Wood	create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
486f545d300SScott Wood		0, BOOKE_PAGESZ_4M, \
487f545d300SScott Wood		CONFIG_SYS_MONITOR_BASE & 0xffc00000,  MAS2_I|MAS2_G, \
488f545d300SScott Wood		0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
489f545d300SScott Wood		0, r6
490f545d300SScott Wood
491f545d300SScott Wood#else
492f545d300SScott Wood/*
493f545d300SScott Wood * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
494f545d300SScott Wood * because "nexti" will resize TLB to 4K
495f545d300SScott Wood */
496f545d300SScott Wood	create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
497f545d300SScott Wood		0, BOOKE_PAGESZ_256K, \
498f545d300SScott Wood		CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS2_I, \
499f545d300SScott Wood		CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS3_SX|MAS3_SW|MAS3_SR, \
500f545d300SScott Wood		0, r6
501f545d300SScott Wood#endif
502f545d300SScott Wood#endif
503f545d300SScott Wood
5043ea21536SScott Wood/*
5056ca88b09STimur Tabi * Relocate CCSR, if necessary.  We relocate CCSR if (obviously) the default
5066ca88b09STimur Tabi * location is not where we want it.  This typically happens on a 36-bit
5076ca88b09STimur Tabi * system, where we want to move CCSR to near the top of 36-bit address space.
5086ca88b09STimur Tabi *
5096ca88b09STimur Tabi * To move CCSR, we create two temporary TLBs, one for the old location, and
5106ca88b09STimur Tabi * another for the new location.  On CoreNet systems, we also need to create
5116ca88b09STimur Tabi * a special, temporary LAW.
5126ca88b09STimur Tabi *
5136ca88b09STimur Tabi * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
5146ca88b09STimur Tabi * long-term TLBs, so we use TLB0 here.
5156ca88b09STimur Tabi */
5166ca88b09STimur Tabi#if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
5176ca88b09STimur Tabi
5186ca88b09STimur Tabi#if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
5196ca88b09STimur Tabi#error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
5206ca88b09STimur Tabi#endif
5216ca88b09STimur Tabi
5226ca88b09STimur Tabicreate_ccsr_new_tlb:
5236ca88b09STimur Tabi	/*
5246ca88b09STimur Tabi	 * Create a TLB for the new location of CCSR.  Register R8 is reserved
5256ca88b09STimur Tabi	 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
5266ca88b09STimur Tabi	 */
5273ea21536SScott Wood	lis	r8, CONFIG_SYS_CCSRBAR@h
5283ea21536SScott Wood	ori	r8, r8, CONFIG_SYS_CCSRBAR@l
5293ea21536SScott Wood	lis	r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
5303ea21536SScott Wood	ori	r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
53169c78267SYork Sun	create_tlb0_entry 0, \
53269c78267SYork Sun		0, BOOKE_PAGESZ_4K, \
53369c78267SYork Sun		CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, \
53469c78267SYork Sun		CONFIG_SYS_CCSRBAR_PHYS_LOW, MAS3_SW|MAS3_SR, \
53569c78267SYork Sun		CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
5366ca88b09STimur Tabi	/*
537c2efa0aaSTimur Tabi	 * Create a TLB for the current location of CCSR.  Register R9 is reserved
5386ca88b09STimur Tabi	 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
5396ca88b09STimur Tabi	 */
5406ca88b09STimur Tabicreate_ccsr_old_tlb:
54169c78267SYork Sun	create_tlb0_entry 1, \
54269c78267SYork Sun		0, BOOKE_PAGESZ_4K, \
54369c78267SYork Sun		CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, \
54469c78267SYork Sun		CONFIG_SYS_CCSRBAR_DEFAULT, MAS3_SW|MAS3_SR, \
54569c78267SYork Sun		0, r3 /* The default CCSR address is always a 32-bit number */
54669c78267SYork Sun
5476ca88b09STimur Tabi
54819e43841STimur Tabi	/*
54919e43841STimur Tabi	 * We have a TLB for what we think is the current (old) CCSR.  Let's
55019e43841STimur Tabi	 * verify that, otherwise we won't be able to move it.
55119e43841STimur Tabi	 * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
55219e43841STimur Tabi	 * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
55319e43841STimur Tabi	 */
55419e43841STimur Tabiverify_old_ccsr:
55519e43841STimur Tabi	lis     r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
55619e43841STimur Tabi	ori     r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
55719e43841STimur Tabi#ifdef CONFIG_FSL_CORENET
55819e43841STimur Tabi	lwz	r1, 4(r9)		/* CCSRBARL */
55919e43841STimur Tabi#else
56019e43841STimur Tabi	lwz	r1, 0(r9)		/* CCSRBAR, shifted right by 12 */
56119e43841STimur Tabi	slwi	r1, r1, 12
56219e43841STimur Tabi#endif
56319e43841STimur Tabi
56419e43841STimur Tabi	cmpl	0, r0, r1
56519e43841STimur Tabi
56619e43841STimur Tabi	/*
56719e43841STimur Tabi	 * If the value we read from CCSRBARL is not what we expect, then
56819e43841STimur Tabi	 * enter an infinite loop.  This will at least allow a debugger to
56919e43841STimur Tabi	 * halt execution and examine TLBs, etc.  There's no point in going
57019e43841STimur Tabi	 * on.
57119e43841STimur Tabi	 */
57219e43841STimur Tabiinfinite_debug_loop:
57319e43841STimur Tabi	bne	infinite_debug_loop
57419e43841STimur Tabi
5756ca88b09STimur Tabi#ifdef CONFIG_FSL_CORENET
5766ca88b09STimur Tabi
5776ca88b09STimur Tabi#define CCSR_LAWBARH0	(CONFIG_SYS_CCSRBAR + 0x1000)
5786ca88b09STimur Tabi#define LAW_SIZE_4K	0xb
5796ca88b09STimur Tabi#define CCSRBAR_LAWAR	(LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
5806ca88b09STimur Tabi#define CCSRAR_C	0x80000000	/* Commit */
5816ca88b09STimur Tabi
5826ca88b09STimur Tabicreate_temp_law:
5836ca88b09STimur Tabi	/*
5846ca88b09STimur Tabi	 * On CoreNet systems, we create the temporary LAW using a special LAW
5856ca88b09STimur Tabi	 * target ID of 0x1e.  LAWBARH is at offset 0xc00 in CCSR.
5866ca88b09STimur Tabi	 */
5876ca88b09STimur Tabi	lis     r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
5886ca88b09STimur Tabi	ori     r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
5896ca88b09STimur Tabi	lis     r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
5906ca88b09STimur Tabi	ori     r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
5916ca88b09STimur Tabi	lis     r2, CCSRBAR_LAWAR@h
5926ca88b09STimur Tabi	ori     r2, r2, CCSRBAR_LAWAR@l
5936ca88b09STimur Tabi
5946ca88b09STimur Tabi	stw     r0, 0xc00(r9)	/* LAWBARH0 */
5956ca88b09STimur Tabi	stw     r1, 0xc04(r9)	/* LAWBARL0 */
5966ca88b09STimur Tabi	sync
5976ca88b09STimur Tabi	stw     r2, 0xc08(r9)	/* LAWAR0 */
5986ca88b09STimur Tabi
5996ca88b09STimur Tabi	/*
6006ca88b09STimur Tabi	 * Read back from LAWAR to ensure the update is complete.  e500mc
6016ca88b09STimur Tabi	 * cores also require an isync.
6026ca88b09STimur Tabi	 */
6036ca88b09STimur Tabi	lwz	r0, 0xc08(r9)	/* LAWAR0 */
6046ca88b09STimur Tabi	isync
6056ca88b09STimur Tabi
6066ca88b09STimur Tabi	/*
6076ca88b09STimur Tabi	 * Read the current CCSRBARH and CCSRBARL using load word instructions.
6086ca88b09STimur Tabi	 * Follow this with an isync instruction. This forces any outstanding
6096ca88b09STimur Tabi	 * accesses to configuration space to completion.
6106ca88b09STimur Tabi	 */
6116ca88b09STimur Tabiread_old_ccsrbar:
6126ca88b09STimur Tabi	lwz	r0, 0(r9)	/* CCSRBARH */
613c2efa0aaSTimur Tabi	lwz	r0, 4(r9)	/* CCSRBARL */
6146ca88b09STimur Tabi	isync
6156ca88b09STimur Tabi
6166ca88b09STimur Tabi	/*
6176ca88b09STimur Tabi	 * Write the new values for CCSRBARH and CCSRBARL to their old
6186ca88b09STimur Tabi	 * locations.  The CCSRBARH has a shadow register. When the CCSRBARH
6196ca88b09STimur Tabi	 * has a new value written it loads a CCSRBARH shadow register. When
6206ca88b09STimur Tabi	 * the CCSRBARL is written, the CCSRBARH shadow register contents
6216ca88b09STimur Tabi	 * along with the CCSRBARL value are loaded into the CCSRBARH and
6226ca88b09STimur Tabi	 * CCSRBARL registers, respectively.  Follow this with a sync
6236ca88b09STimur Tabi	 * instruction.
6246ca88b09STimur Tabi	 */
6256ca88b09STimur Tabiwrite_new_ccsrbar:
6266ca88b09STimur Tabi	lis	r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
6276ca88b09STimur Tabi	ori	r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
6286ca88b09STimur Tabi	lis	r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
6296ca88b09STimur Tabi	ori	r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
6306ca88b09STimur Tabi	lis	r2, CCSRAR_C@h
6316ca88b09STimur Tabi	ori	r2, r2, CCSRAR_C@l
6326ca88b09STimur Tabi
6336ca88b09STimur Tabi	stw	r0, 0(r9)	/* Write to CCSRBARH */
6346ca88b09STimur Tabi	sync			/* Make sure we write to CCSRBARH first */
6356ca88b09STimur Tabi	stw	r1, 4(r9)	/* Write to CCSRBARL */
6366ca88b09STimur Tabi	sync
6376ca88b09STimur Tabi
6386ca88b09STimur Tabi	/*
6396ca88b09STimur Tabi	 * Write a 1 to the commit bit (C) of CCSRAR at the old location.
6406ca88b09STimur Tabi	 * Follow this with a sync instruction.
6416ca88b09STimur Tabi	 */
6426ca88b09STimur Tabi	stw	r2, 8(r9)
6436ca88b09STimur Tabi	sync
6446ca88b09STimur Tabi
6456ca88b09STimur Tabi	/* Delete the temporary LAW */
6466ca88b09STimur Tabidelete_temp_law:
6476ca88b09STimur Tabi	li	r1, 0
6486ca88b09STimur Tabi	stw	r1, 0xc08(r8)
6496ca88b09STimur Tabi	sync
6506ca88b09STimur Tabi	stw	r1, 0xc00(r8)
6516ca88b09STimur Tabi	stw	r1, 0xc04(r8)
6526ca88b09STimur Tabi	sync
6536ca88b09STimur Tabi
6546ca88b09STimur Tabi#else /* #ifdef CONFIG_FSL_CORENET */
6556ca88b09STimur Tabi
6566ca88b09STimur Tabiwrite_new_ccsrbar:
6576ca88b09STimur Tabi	/*
6586ca88b09STimur Tabi	 * Read the current value of CCSRBAR using a load word instruction
6596ca88b09STimur Tabi	 * followed by an isync. This forces all accesses to configuration
6606ca88b09STimur Tabi	 * space to complete.
6616ca88b09STimur Tabi	 */
6626ca88b09STimur Tabi	sync
6636ca88b09STimur Tabi	lwz	r0, 0(r9)
6646ca88b09STimur Tabi	isync
6656ca88b09STimur Tabi
6666ca88b09STimur Tabi/* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
6676ca88b09STimur Tabi#define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
6686ca88b09STimur Tabi			   (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
6696ca88b09STimur Tabi
6706ca88b09STimur Tabi	/* Write the new value to CCSRBAR. */
6716ca88b09STimur Tabi	lis	r0, CCSRBAR_PHYS_RS12@h
6726ca88b09STimur Tabi	ori	r0, r0, CCSRBAR_PHYS_RS12@l
6736ca88b09STimur Tabi	stw	r0, 0(r9)
6746ca88b09STimur Tabi	sync
6756ca88b09STimur Tabi
6766ca88b09STimur Tabi	/*
6776ca88b09STimur Tabi	 * The manual says to perform a load of an address that does not
6786ca88b09STimur Tabi	 * access configuration space or the on-chip SRAM using an existing TLB,
6796ca88b09STimur Tabi	 * but that doesn't appear to be necessary.  We will do the isync,
6806ca88b09STimur Tabi	 * though.
6816ca88b09STimur Tabi	 */
6826ca88b09STimur Tabi	isync
6836ca88b09STimur Tabi
6846ca88b09STimur Tabi	/*
6856ca88b09STimur Tabi	 * Read the contents of CCSRBAR from its new location, followed by
6866ca88b09STimur Tabi	 * another isync.
6876ca88b09STimur Tabi	 */
6886ca88b09STimur Tabi	lwz	r0, 0(r8)
6896ca88b09STimur Tabi	isync
6906ca88b09STimur Tabi
6916ca88b09STimur Tabi#endif  /* #ifdef CONFIG_FSL_CORENET */
6926ca88b09STimur Tabi
6936ca88b09STimur Tabi	/* Delete the temporary TLBs */
6946ca88b09STimur Tabidelete_temp_tlbs:
69569c78267SYork Sun	delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, r3
69669c78267SYork Sun	delete_tlb0_entry 1, CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, r3
6976ca88b09STimur Tabi
6986ca88b09STimur Tabi#endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
6996ca88b09STimur Tabi
700e9827468SPrabhakar Kushwaha#if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
7016d2b9da1SYork Suncreate_ccsr_l2_tlb:
7026d2b9da1SYork Sun	/*
7036d2b9da1SYork Sun	 * Create a TLB for the MMR location of CCSR
7046d2b9da1SYork Sun	 * to access L2CSR0 register
7056d2b9da1SYork Sun	 */
7066d2b9da1SYork Sun	create_tlb0_entry 0, \
7076d2b9da1SYork Sun		0, BOOKE_PAGESZ_4K, \
7086d2b9da1SYork Sun		CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, \
7096d2b9da1SYork Sun		CONFIG_SYS_CCSRBAR_PHYS_LOW + 0xC20000, MAS3_SW|MAS3_SR, \
7106d2b9da1SYork Sun		CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
7116d2b9da1SYork Sun
7126d2b9da1SYork Sunenable_l2_cluster_l2:
7136d2b9da1SYork Sun	/* enable L2 cache */
7146d2b9da1SYork Sun	lis	r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@h
7156d2b9da1SYork Sun	ori	r3, r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@l
7166d2b9da1SYork Sun	li	r4, 33	/* stash id */
7176d2b9da1SYork Sun	stw	r4, 4(r3)
7186d2b9da1SYork Sun	lis	r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@h
7196d2b9da1SYork Sun	ori	r4, r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@l
7206d2b9da1SYork Sun	sync
7216d2b9da1SYork Sun	stw	r4, 0(r3)	/* invalidate L2 */
72282eda684SAneesh Bansal	/* Poll till the bits are cleared */
7236d2b9da1SYork Sun1:	sync
7246d2b9da1SYork Sun	lwz	r0, 0(r3)
7256d2b9da1SYork Sun	twi	0, r0, 0
7266d2b9da1SYork Sun	isync
7276d2b9da1SYork Sun	and.	r1, r0, r4
7286d2b9da1SYork Sun	bne	1b
72982eda684SAneesh Bansal
73082eda684SAneesh Bansal	/* L2PE must be set before L2 cache is enabled */
73182eda684SAneesh Bansal	lis	r4, (L2CSR0_L2PE)@h
73282eda684SAneesh Bansal	ori	r4, r4, (L2CSR0_L2PE)@l
73382eda684SAneesh Bansal	sync
73482eda684SAneesh Bansal	stw	r4, 0(r3)	/* enable L2 parity/ECC error checking */
73582eda684SAneesh Bansal	/* Poll till the bit is set */
73682eda684SAneesh Bansal1:	sync
73782eda684SAneesh Bansal	lwz	r0, 0(r3)
73882eda684SAneesh Bansal	twi	0, r0, 0
73982eda684SAneesh Bansal	isync
74082eda684SAneesh Bansal	and.	r1, r0, r4
74182eda684SAneesh Bansal	beq	1b
74282eda684SAneesh Bansal
743c416faf8SJames Yang	lis	r4, (L2CSR0_L2E|L2CSR0_L2PE)@h
7449cd95ac7SJames Yang	ori	r4, r4, (L2CSR0_L2REP_MODE)@l
7456d2b9da1SYork Sun	sync
7463e4c3137SAndy Fleming	stw	r4, 0(r3)	/* enable L2 */
74782eda684SAneesh Bansal	/* Poll till the bit is set */
74882eda684SAneesh Bansal1:	sync
74982eda684SAneesh Bansal	lwz	r0, 0(r3)
75082eda684SAneesh Bansal	twi	0, r0, 0
75182eda684SAneesh Bansal	isync
75282eda684SAneesh Bansal	and.	r1, r0, r4
75382eda684SAneesh Bansal	beq	1b
75482eda684SAneesh Bansal
7556d2b9da1SYork Sundelete_ccsr_l2_tlb:
7566d2b9da1SYork Sun	delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, r3
7576d2b9da1SYork Sun#endif
7586d2b9da1SYork Sun
7593e4c3137SAndy Fleming	/*
7603e4c3137SAndy Fleming	 * Enable the L1. On e6500, this has to be done
7613e4c3137SAndy Fleming	 * after the L2 is up.
7623e4c3137SAndy Fleming	 */
7633e4c3137SAndy Fleming
7643e4c3137SAndy Fleming#ifdef CONFIG_SYS_CACHE_STASHING
7653e4c3137SAndy Fleming	/* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
7663e4c3137SAndy Fleming	li	r2,(32 + 0)
7673e4c3137SAndy Fleming	mtspr	L1CSR2,r2
7683e4c3137SAndy Fleming#endif
7693e4c3137SAndy Fleming
7703e4c3137SAndy Fleming	/* Enable/invalidate the I-Cache */
7713e4c3137SAndy Fleming	lis	r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
7723e4c3137SAndy Fleming	ori	r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
7733e4c3137SAndy Fleming	mtspr	SPRN_L1CSR1,r2
7743e4c3137SAndy Fleming1:
7753e4c3137SAndy Fleming	mfspr	r3,SPRN_L1CSR1
7763e4c3137SAndy Fleming	and.	r1,r3,r2
7773e4c3137SAndy Fleming	bne	1b
7783e4c3137SAndy Fleming
7793e4c3137SAndy Fleming	lis	r3,(L1CSR1_CPE|L1CSR1_ICE)@h
7803e4c3137SAndy Fleming	ori	r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
7813e4c3137SAndy Fleming	mtspr	SPRN_L1CSR1,r3
7823e4c3137SAndy Fleming	isync
7833e4c3137SAndy Fleming2:
7843e4c3137SAndy Fleming	mfspr	r3,SPRN_L1CSR1
7853e4c3137SAndy Fleming	andi.	r1,r3,L1CSR1_ICE@l
7863e4c3137SAndy Fleming	beq	2b
7873e4c3137SAndy Fleming
7883e4c3137SAndy Fleming	/* Enable/invalidate the D-Cache */
7893e4c3137SAndy Fleming	lis	r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
7903e4c3137SAndy Fleming	ori	r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
7913e4c3137SAndy Fleming	mtspr	SPRN_L1CSR0,r2
7923e4c3137SAndy Fleming1:
7933e4c3137SAndy Fleming	mfspr	r3,SPRN_L1CSR0
7943e4c3137SAndy Fleming	and.	r1,r3,r2
7953e4c3137SAndy Fleming	bne	1b
7963e4c3137SAndy Fleming
7973e4c3137SAndy Fleming	lis	r3,(L1CSR0_CPE|L1CSR0_DCE)@h
7983e4c3137SAndy Fleming	ori	r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
7993e4c3137SAndy Fleming	mtspr	SPRN_L1CSR0,r3
8003e4c3137SAndy Fleming	isync
8013e4c3137SAndy Fleming2:
8023e4c3137SAndy Fleming	mfspr	r3,SPRN_L1CSR0
8033e4c3137SAndy Fleming	andi.	r1,r3,L1CSR0_DCE@l
8043e4c3137SAndy Fleming	beq	2b
80533eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
80633eee330SScott Wood#define DCSR_LAWBARH0	(CONFIG_SYS_CCSRBAR + 0x1000)
80733eee330SScott Wood#define LAW_SIZE_1M	0x13
80833eee330SScott Wood#define DCSRBAR_LAWAR	(LAW_EN | (0x1d << 20) | LAW_SIZE_1M)
80933eee330SScott Wood
81033eee330SScott Wood	cmpwi	r27,0
81133eee330SScott Wood	beq	9f
81233eee330SScott Wood
81333eee330SScott Wood	/*
81433eee330SScott Wood	 * Create a TLB entry for CCSR
81533eee330SScott Wood	 *
81633eee330SScott Wood	 * We're executing out of TLB1 entry in r14, and that's the only
81733eee330SScott Wood	 * TLB entry that exists.  To allocate some TLB entries for our
81833eee330SScott Wood	 * own use, flip a bit high enough that we won't flip it again
81933eee330SScott Wood	 * via incrementing.
82033eee330SScott Wood	 */
82133eee330SScott Wood
82233eee330SScott Wood	xori	r8, r14, 32
82333eee330SScott Wood	lis	r0, MAS0_TLBSEL(1)@h
82433eee330SScott Wood	rlwimi	r0, r8, 16, MAS0_ESEL_MSK
82533eee330SScott Wood	lis	r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@h
82633eee330SScott Wood	ori	r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@l
82733eee330SScott Wood	lis	r7, CONFIG_SYS_CCSRBAR@h
82833eee330SScott Wood	ori	r7, r7, CONFIG_SYS_CCSRBAR@l
82933eee330SScott Wood	ori	r2, r7, MAS2_I|MAS2_G
83033eee330SScott Wood	lis	r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
83133eee330SScott Wood	ori	r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
83233eee330SScott Wood	lis	r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
83333eee330SScott Wood	ori	r4, r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
83433eee330SScott Wood	mtspr	MAS0, r0
83533eee330SScott Wood	mtspr	MAS1, r1
83633eee330SScott Wood	mtspr	MAS2, r2
83733eee330SScott Wood	mtspr	MAS3, r3
83833eee330SScott Wood	mtspr	MAS7, r4
83933eee330SScott Wood	isync
84033eee330SScott Wood	tlbwe
84133eee330SScott Wood	isync
84233eee330SScott Wood	msync
84333eee330SScott Wood
84433eee330SScott Wood	/* Map DCSR temporarily to physical address zero */
84533eee330SScott Wood	li	r0, 0
84633eee330SScott Wood	lis	r3, DCSRBAR_LAWAR@h
84733eee330SScott Wood	ori	r3, r3, DCSRBAR_LAWAR@l
84833eee330SScott Wood
84933eee330SScott Wood	stw	r0, 0xc00(r7)	/* LAWBARH0 */
85033eee330SScott Wood	stw	r0, 0xc04(r7)	/* LAWBARL0 */
85133eee330SScott Wood	sync
85233eee330SScott Wood	stw	r3, 0xc08(r7)	/* LAWAR0 */
85333eee330SScott Wood
85433eee330SScott Wood	/* Read back from LAWAR to ensure the update is complete. */
85533eee330SScott Wood	lwz	r3, 0xc08(r7)	/* LAWAR0 */
85633eee330SScott Wood	isync
85733eee330SScott Wood
85833eee330SScott Wood	/* Create a TLB entry for DCSR at zero */
85933eee330SScott Wood
86033eee330SScott Wood	addi	r9, r8, 1
86133eee330SScott Wood	lis	r0, MAS0_TLBSEL(1)@h
86233eee330SScott Wood	rlwimi	r0, r9, 16, MAS0_ESEL_MSK
86333eee330SScott Wood	lis	r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@h
86433eee330SScott Wood	ori	r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@l
86533eee330SScott Wood	li	r6, 0	/* DCSR effective address */
86633eee330SScott Wood	ori	r2, r6, MAS2_I|MAS2_G
86733eee330SScott Wood	li	r3, MAS3_SW|MAS3_SR
86833eee330SScott Wood	li	r4, 0
86933eee330SScott Wood	mtspr	MAS0, r0
87033eee330SScott Wood	mtspr	MAS1, r1
87133eee330SScott Wood	mtspr	MAS2, r2
87233eee330SScott Wood	mtspr	MAS3, r3
87333eee330SScott Wood	mtspr	MAS7, r4
87433eee330SScott Wood	isync
87533eee330SScott Wood	tlbwe
87633eee330SScott Wood	isync
87733eee330SScott Wood	msync
87833eee330SScott Wood
87933eee330SScott Wood	/* enable the timebase */
88033eee330SScott Wood#define CTBENR	0xe2084
88133eee330SScott Wood	li	r3, 1
88233eee330SScott Wood	addis	r4, r7, CTBENR@ha
88333eee330SScott Wood	stw	r3, CTBENR@l(r4)
88433eee330SScott Wood	lwz	r3, CTBENR@l(r4)
88533eee330SScott Wood	twi	0,r3,0
88633eee330SScott Wood	isync
88733eee330SScott Wood
88833eee330SScott Wood	.macro	erratum_set_ccsr offset value
88933eee330SScott Wood	addis	r3, r7, \offset@ha
89033eee330SScott Wood	lis	r4, \value@h
89133eee330SScott Wood	addi	r3, r3, \offset@l
89233eee330SScott Wood	ori	r4, r4, \value@l
89333eee330SScott Wood	bl	erratum_set_value
89433eee330SScott Wood	.endm
89533eee330SScott Wood
89633eee330SScott Wood	.macro	erratum_set_dcsr offset value
89733eee330SScott Wood	addis	r3, r6, \offset@ha
89833eee330SScott Wood	lis	r4, \value@h
89933eee330SScott Wood	addi	r3, r3, \offset@l
90033eee330SScott Wood	ori	r4, r4, \value@l
90133eee330SScott Wood	bl	erratum_set_value
90233eee330SScott Wood	.endm
90333eee330SScott Wood
90433eee330SScott Wood	erratum_set_dcsr 0xb0e08 0xe0201800
90533eee330SScott Wood	erratum_set_dcsr 0xb0e18 0xe0201800
90633eee330SScott Wood	erratum_set_dcsr 0xb0e38 0xe0400000
90733eee330SScott Wood	erratum_set_dcsr 0xb0008 0x00900000
90833eee330SScott Wood	erratum_set_dcsr 0xb0e40 0xe00a0000
90933eee330SScott Wood	erratum_set_ccsr 0x18600 CONFIG_SYS_FSL_CORENET_SNOOPVEC_COREONLY
91024936ed1SDave Liu#ifdef  CONFIG_RAMBOOT_PBL
91124936ed1SDave Liu	erratum_set_ccsr 0x10f00 0x495e5000
91224936ed1SDave Liu#else
91333eee330SScott Wood	erratum_set_ccsr 0x10f00 0x415e5000
91424936ed1SDave Liu#endif
91533eee330SScott Wood	erratum_set_ccsr 0x11f00 0x415e5000
91633eee330SScott Wood
91733eee330SScott Wood	/* Make temp mapping uncacheable again, if it was initially */
91833eee330SScott Wood	bl	2f
91933eee330SScott Wood2:	mflr	r3
92033eee330SScott Wood	tlbsx	0, r3
92133eee330SScott Wood	mfspr	r4, MAS2
92233eee330SScott Wood	rlwimi	r4, r15, 0, MAS2_I
92333eee330SScott Wood	rlwimi	r4, r15, 0, MAS2_G
92433eee330SScott Wood	mtspr	MAS2, r4
92533eee330SScott Wood	isync
92633eee330SScott Wood	tlbwe
92733eee330SScott Wood	isync
92833eee330SScott Wood	msync
92933eee330SScott Wood
93033eee330SScott Wood	/* Clear the cache */
93133eee330SScott Wood	lis	r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
93233eee330SScott Wood	ori	r3,r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
93333eee330SScott Wood	sync
93433eee330SScott Wood	isync
93533eee330SScott Wood	mtspr	SPRN_L1CSR1,r3
93633eee330SScott Wood	isync
93733eee330SScott Wood2:	sync
93833eee330SScott Wood	mfspr	r4,SPRN_L1CSR1
93933eee330SScott Wood	and.	r4,r4,r3
94033eee330SScott Wood	bne	2b
94133eee330SScott Wood
94233eee330SScott Wood	lis	r3,(L1CSR1_CPE|L1CSR1_ICE)@h
94333eee330SScott Wood	ori	r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
94433eee330SScott Wood	sync
94533eee330SScott Wood	isync
94633eee330SScott Wood	mtspr	SPRN_L1CSR1,r3
94733eee330SScott Wood	isync
94833eee330SScott Wood2:	sync
94933eee330SScott Wood	mfspr	r4,SPRN_L1CSR1
95033eee330SScott Wood	and.	r4,r4,r3
95133eee330SScott Wood	beq	2b
95233eee330SScott Wood
95333eee330SScott Wood	/* Remove temporary mappings */
95433eee330SScott Wood	lis	r0, MAS0_TLBSEL(1)@h
95533eee330SScott Wood	rlwimi	r0, r9, 16, MAS0_ESEL_MSK
95633eee330SScott Wood	li	r3, 0
95733eee330SScott Wood	mtspr	MAS0, r0
95833eee330SScott Wood	mtspr	MAS1, r3
95933eee330SScott Wood	isync
96033eee330SScott Wood	tlbwe
96133eee330SScott Wood	isync
96233eee330SScott Wood	msync
96333eee330SScott Wood
96433eee330SScott Wood	li	r3, 0
96533eee330SScott Wood	stw	r3, 0xc08(r7)	/* LAWAR0 */
96633eee330SScott Wood	lwz	r3, 0xc08(r7)
96733eee330SScott Wood	isync
96833eee330SScott Wood
96933eee330SScott Wood	lis	r0, MAS0_TLBSEL(1)@h
97033eee330SScott Wood	rlwimi	r0, r8, 16, MAS0_ESEL_MSK
97133eee330SScott Wood	li	r3, 0
97233eee330SScott Wood	mtspr	MAS0, r0
97333eee330SScott Wood	mtspr	MAS1, r3
97433eee330SScott Wood	isync
97533eee330SScott Wood	tlbwe
97633eee330SScott Wood	isync
97733eee330SScott Wood	msync
97833eee330SScott Wood
97933eee330SScott Wood	b	9f
98033eee330SScott Wood
98133eee330SScott Wood	/* r3 = addr, r4 = value, clobbers r5, r11, r12 */
98233eee330SScott Wooderratum_set_value:
98333eee330SScott Wood	/* Lock two cache lines into I-Cache */
98433eee330SScott Wood	sync
98533eee330SScott Wood	mfspr	r11, SPRN_L1CSR1
98633eee330SScott Wood	rlwinm	r11, r11, 0, ~L1CSR1_ICUL
98733eee330SScott Wood	sync
98833eee330SScott Wood	isync
98933eee330SScott Wood	mtspr	SPRN_L1CSR1, r11
99033eee330SScott Wood	isync
99133eee330SScott Wood
99233eee330SScott Wood	mflr	r12
99333eee330SScott Wood	bl	5f
99433eee330SScott Wood5:	mflr	r5
99533eee330SScott Wood	addi	r5, r5, 2f - 5b
99633eee330SScott Wood	icbtls	0, 0, r5
99733eee330SScott Wood	addi	r5, r5, 64
99833eee330SScott Wood
99933eee330SScott Wood	sync
100033eee330SScott Wood	mfspr	r11, SPRN_L1CSR1
100133eee330SScott Wood3:	andi.	r11, r11, L1CSR1_ICUL
100233eee330SScott Wood	bne	3b
100333eee330SScott Wood
100433eee330SScott Wood	icbtls	0, 0, r5
100533eee330SScott Wood	addi	r5, r5, 64
100633eee330SScott Wood
100733eee330SScott Wood	sync
100833eee330SScott Wood	mfspr	r11, SPRN_L1CSR1
100933eee330SScott Wood3:	andi.	r11, r11, L1CSR1_ICUL
101033eee330SScott Wood	bne	3b
101133eee330SScott Wood
101233eee330SScott Wood	b	2f
101333eee330SScott Wood	.align	6
101433eee330SScott Wood	/* Inside a locked cacheline, wait a while, write, then wait a while */
101533eee330SScott Wood2:	sync
101633eee330SScott Wood
101733eee330SScott Wood	mfspr	r5, SPRN_TBRL
101833eee330SScott Wood	addis	r11, r5, 0x10000@h /* wait 65536 timebase ticks */
101933eee330SScott Wood4:	mfspr	r5, SPRN_TBRL
102033eee330SScott Wood	subf.	r5, r5, r11
102133eee330SScott Wood	bgt	4b
102233eee330SScott Wood
102333eee330SScott Wood	stw	r4, 0(r3)
102433eee330SScott Wood
102533eee330SScott Wood	mfspr	r5, SPRN_TBRL
102633eee330SScott Wood	addis	r11, r5, 0x10000@h /* wait 65536 timebase ticks */
102733eee330SScott Wood4:	mfspr	r5, SPRN_TBRL
102833eee330SScott Wood	subf.	r5, r5, r11
102933eee330SScott Wood	bgt	4b
103033eee330SScott Wood
103133eee330SScott Wood	sync
103233eee330SScott Wood
103333eee330SScott Wood	/*
103433eee330SScott Wood	 * Fill out the rest of this cache line and the next with nops,
103533eee330SScott Wood	 * to ensure that nothing outside the locked area will be
103633eee330SScott Wood	 * fetched due to a branch.
103733eee330SScott Wood	 */
103833eee330SScott Wood	.rept 19
103933eee330SScott Wood	nop
104033eee330SScott Wood	.endr
104133eee330SScott Wood
104233eee330SScott Wood	sync
104333eee330SScott Wood	mfspr	r11, SPRN_L1CSR1
104433eee330SScott Wood	rlwinm	r11, r11, 0, ~L1CSR1_ICUL
104533eee330SScott Wood	sync
104633eee330SScott Wood	isync
104733eee330SScott Wood	mtspr	SPRN_L1CSR1, r11
104833eee330SScott Wood	isync
104933eee330SScott Wood
105033eee330SScott Wood	mtlr	r12
105133eee330SScott Wood	blr
105233eee330SScott Wood
105333eee330SScott Wood9:
105433eee330SScott Wood#endif
105533eee330SScott Wood
10566ca88b09STimur Tabicreate_init_ram_area:
1057a47a12beSStefan Roese	lis     r6,FSL_BOOKE_MAS0(1, 15, 0)@h
1058a47a12beSStefan Roese	ori     r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
1059a47a12beSStefan Roese
10604b919725SScott Wood#ifdef NOR_BOOT
1061a47a12beSStefan Roese	/* create a temp mapping in AS=1 to the 4M boot window */
106269c78267SYork Sun	create_tlb1_entry 15, \
106369c78267SYork Sun		1, BOOKE_PAGESZ_4M, \
106469c78267SYork Sun		CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
106569c78267SYork Sun		0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
106669c78267SYork Sun		0, r6
1067a47a12beSStefan Roese
10687065b7d4SRuchika Gupta#elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
10697065b7d4SRuchika Gupta	/* create a temp mapping in AS = 1 for Flash mapping
10707065b7d4SRuchika Gupta	 * created by PBL for ISBC code
10717065b7d4SRuchika Gupta	 */
107269c78267SYork Sun	create_tlb1_entry 15, \
107369c78267SYork Sun		1, BOOKE_PAGESZ_1M, \
10747f0a22ffSScott Wood		CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
10757f0a22ffSScott Wood		CONFIG_SYS_PBI_FLASH_WINDOW & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
107669c78267SYork Sun		0, r6
1077467a40dfSAneesh Bansal
1078aa36c84eSSumit Garg/*
1079aa36c84eSSumit Garg * For Targets without CONFIG_SPL like P3, P5
1080aa36c84eSSumit Garg * and for targets with CONFIG_SPL like T1, T2, T4, only for
1081aa36c84eSSumit Garg * u-boot-spl i.e. CONFIG_SPL_BUILD
1082aa36c84eSSumit Garg */
1083aa36c84eSSumit Garg#elif defined(CONFIG_RAMBOOT_PBL) && defined(CONFIG_SECURE_BOOT) && \
1084aa36c84eSSumit Garg	(!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
1085467a40dfSAneesh Bansal	/* create a temp mapping in AS = 1 for mapping CONFIG_SYS_MONITOR_BASE
1086467a40dfSAneesh Bansal	 * to L3 Address configured by PBL for ISBC code
1087467a40dfSAneesh Bansal	 */
1088467a40dfSAneesh Bansal	create_tlb1_entry 15, \
1089467a40dfSAneesh Bansal		1, BOOKE_PAGESZ_1M, \
1090467a40dfSAneesh Bansal		CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
1091467a40dfSAneesh Bansal		CONFIG_SYS_INIT_L3_ADDR & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
1092467a40dfSAneesh Bansal		0, r6
1093467a40dfSAneesh Bansal
1094a47a12beSStefan Roese#else
1095a47a12beSStefan Roese	/*
10960635b09cSHaiying Wang	 * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
10970635b09cSHaiying Wang	 * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
1098a47a12beSStefan Roese	 */
109969c78267SYork Sun	create_tlb1_entry 15, \
110069c78267SYork Sun		1, BOOKE_PAGESZ_1M, \
11017f0a22ffSScott Wood		CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
11027f0a22ffSScott Wood		CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
110369c78267SYork Sun		0, r6
1104a47a12beSStefan Roese#endif
1105a47a12beSStefan Roese
1106a47a12beSStefan Roese	/* create a temp mapping in AS=1 to the stack */
1107a3f18529Syork#if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
1108a3f18529Syork    defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
110969c78267SYork Sun	create_tlb1_entry 14, \
111069c78267SYork Sun		1, BOOKE_PAGESZ_16K, \
111169c78267SYork Sun		CONFIG_SYS_INIT_RAM_ADDR, 0, \
111269c78267SYork Sun		CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, MAS3_SX|MAS3_SW|MAS3_SR, \
111369c78267SYork Sun		CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH, r6
1114a47a12beSStefan Roese
111569c78267SYork Sun#else
111669c78267SYork Sun	create_tlb1_entry 14, \
111769c78267SYork Sun		1, BOOKE_PAGESZ_16K, \
111869c78267SYork Sun		CONFIG_SYS_INIT_RAM_ADDR, 0, \
111969c78267SYork Sun		CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, \
112069c78267SYork Sun		0, r6
112169c78267SYork Sun#endif
1122a47a12beSStefan Roese
11235344f7a2SPrabhakar Kushwaha	lis	r6,MSR_IS|MSR_DS|MSR_DE@h
11245344f7a2SPrabhakar Kushwaha	ori	r6,r6,MSR_IS|MSR_DS|MSR_DE@l
1125a47a12beSStefan Roese	lis	r7,switch_as@h
1126a47a12beSStefan Roese	ori	r7,r7,switch_as@l
1127a47a12beSStefan Roese
1128a47a12beSStefan Roese	mtspr	SPRN_SRR0,r7
1129a47a12beSStefan Roese	mtspr	SPRN_SRR1,r6
1130a47a12beSStefan Roese	rfi
1131a47a12beSStefan Roese
1132a47a12beSStefan Roeseswitch_as:
1133a47a12beSStefan Roese/* L1 DCache is used for initial RAM */
1134a47a12beSStefan Roese
1135a47a12beSStefan Roese	/* Allocate Initial RAM in data cache.
1136a47a12beSStefan Roese	 */
1137a47a12beSStefan Roese	lis	r3,CONFIG_SYS_INIT_RAM_ADDR@h
1138a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
1139a47a12beSStefan Roese	mfspr	r2, L1CFG0
1140a47a12beSStefan Roese	andi.	r2, r2, 0x1ff
1141a47a12beSStefan Roese	/* cache size * 1024 / (2 * L1 line size) */
1142a47a12beSStefan Roese	slwi	r2, r2, (10 - 1 - L1_CACHE_SHIFT)
1143a47a12beSStefan Roese	mtctr	r2
1144a47a12beSStefan Roese	li	r0,0
1145a47a12beSStefan Roese1:
1146a47a12beSStefan Roese	dcbz	r0,r3
1147668ec87fSRuchika Gupta#ifdef CONFIG_E6500	/* Lock/unlock L2 cache long with L1 */
11482becdc6fSYork Sun	dcbtls	2, r0, r3
1149668ec87fSRuchika Gupta	dcbtls	0, r0, r3
11502becdc6fSYork Sun#else
1151a47a12beSStefan Roese	dcbtls	0, r0, r3
11522becdc6fSYork Sun#endif
1153a47a12beSStefan Roese	addi	r3,r3,CONFIG_SYS_CACHELINE_SIZE
1154a47a12beSStefan Roese	bdnz	1b
1155a47a12beSStefan Roese
1156a47a12beSStefan Roese	/* Jump out the last 4K page and continue to 'normal' start */
11574b919725SScott Wood#if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)
11584b919725SScott Wood	/* We assume that we're already running at the address we're linked at */
1159a47a12beSStefan Roese	b	_start_cont
1160a47a12beSStefan Roese#else
1161a47a12beSStefan Roese	/* Calculate absolute address in FLASH and jump there		*/
1162a47a12beSStefan Roese	/*--------------------------------------------------------------*/
1163a47a12beSStefan Roese	lis	r3,CONFIG_SYS_MONITOR_BASE@h
1164a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_MONITOR_BASE@l
116596d2bb95SScott Wood	addi	r3,r3,_start_cont - _start
1166a47a12beSStefan Roese	mtlr	r3
1167a47a12beSStefan Roese	blr
1168a47a12beSStefan Roese#endif
1169a47a12beSStefan Roese
1170a47a12beSStefan Roese	.text
1171a47a12beSStefan Roese	.globl	_start
1172a47a12beSStefan Roese_start:
1173a47a12beSStefan Roese	.long	0x27051956		/* U-BOOT Magic Number */
1174a47a12beSStefan Roese	.globl	version_string
1175a47a12beSStefan Roeseversion_string:
117609c2e90cSAndreas Bießmann	.ascii U_BOOT_VERSION_STRING, "\0"
1177a47a12beSStefan Roese
1178a47a12beSStefan Roese	.align	4
1179a47a12beSStefan Roese	.globl	_start_cont
1180a47a12beSStefan Roese_start_cont:
1181a47a12beSStefan Roese	/* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
118289f42899SJoakim Tjernlund	lis	r3,(CONFIG_SYS_INIT_RAM_ADDR)@h
118389f42899SJoakim Tjernlund	ori	r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
118450689461Smario.six@gdsys.cc
11852b71d098SAndy Yan#if CONFIG_VAL(SYS_MALLOC_F_LEN)
11862b71d098SAndy Yan#if CONFIG_VAL(SYS_MALLOC_F_LEN) + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
11872b71d098SAndy Yan#error "SYS_MALLOC_F_LEN too large to fit into initial RAM."
118850689461Smario.six@gdsys.cc#endif
118950689461Smario.six@gdsys.cc
119050689461Smario.six@gdsys.cc	/* Leave 16+ byte for back chain termination and NULL return address */
11912b71d098SAndy Yan	subi	r3,r3,((CONFIG_VAL(SYS_MALLOC_F_LEN)+16+15)&~0xf)
119250689461Smario.six@gdsys.cc#endif
119350689461Smario.six@gdsys.cc
119450689461Smario.six@gdsys.cc	/* End of RAM */
119550689461Smario.six@gdsys.cc	lis	r4,(CONFIG_SYS_INIT_RAM_ADDR)@h
119650689461Smario.six@gdsys.cc	ori	r4,r4,(CONFIG_SYS_INIT_RAM_SIZE)@l
119750689461Smario.six@gdsys.cc
119850689461Smario.six@gdsys.cc	li	r0,0
119950689461Smario.six@gdsys.cc
120050689461Smario.six@gdsys.cc1: 	subi 	r4,r4,4
120150689461Smario.six@gdsys.cc	stw 	r0,0(r4)
120250689461Smario.six@gdsys.cc	cmplw 	r4,r3
120350689461Smario.six@gdsys.cc	bne	1b
120450689461Smario.six@gdsys.cc
12052b71d098SAndy Yan#if CONFIG_VAL(SYS_MALLOC_F_LEN)
120650689461Smario.six@gdsys.cc	lis	r4,(CONFIG_SYS_INIT_RAM_ADDR)@h
120750689461Smario.six@gdsys.cc	ori	r4,r4,(CONFIG_SYS_GBL_DATA_OFFSET)@l
120850689461Smario.six@gdsys.cc
120950689461Smario.six@gdsys.cc	addi	r3,r3,16	/* Pre-relocation malloc area */
121050689461Smario.six@gdsys.cc	stw	r3,GD_MALLOC_BASE(r4)
121150689461Smario.six@gdsys.cc	subi	r3,r3,16
121250689461Smario.six@gdsys.cc#endif
1213a47a12beSStefan Roese	li	r0,0
121489f42899SJoakim Tjernlund	stw	r0,0(r3)	/* Terminate Back Chain */
121589f42899SJoakim Tjernlund	stw	r0,+4(r3)	/* NULL return address. */
121689f42899SJoakim Tjernlund	mr	r1,r3		/* Transfer to SP(r1) */
1217a47a12beSStefan Roese
1218a47a12beSStefan Roese	GET_GOT
1219*45e81f9aSJoakim Tjernlund	/* Needed for -msingle-pic-base */
1220*45e81f9aSJoakim Tjernlund	bl	_GLOBAL_OFFSET_TABLE_@local-4
1221*45e81f9aSJoakim Tjernlund	mflr	r30
1222fa08d395SAlexander Graf
1223fa08d395SAlexander Graf	/* Pass our potential ePAPR device tree pointer to cpu_init_early_f */
1224fa08d395SAlexander Graf	mr	r3, r24
1225fa08d395SAlexander Graf
1226a47a12beSStefan Roese	bl	cpu_init_early_f
1227a47a12beSStefan Roese
1228a47a12beSStefan Roese	/* switch back to AS = 0 */
1229a47a12beSStefan Roese	lis	r3,(MSR_CE|MSR_ME|MSR_DE)@h
1230a47a12beSStefan Roese	ori	r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
1231a47a12beSStefan Roese	mtmsr	r3
1232a47a12beSStefan Roese	isync
1233a47a12beSStefan Roese
1234701e6401SYork Sun	bl	cpu_init_f	/* return boot_flag for calling board_init_f */
1235a47a12beSStefan Roese	bl	board_init_f
1236a47a12beSStefan Roese	isync
1237a47a12beSStefan Roese
123852ebd9c1SPeter Tyser	/* NOTREACHED - board_init_f() does not return */
123952ebd9c1SPeter Tyser
12404b919725SScott Wood#ifndef MINIMAL_SPL
1241a47a12beSStefan Roese	.globl	_start_of_vectors
1242a47a12beSStefan Roese_start_of_vectors:
1243a47a12beSStefan Roese
1244a47a12beSStefan Roese/* Critical input. */
1245a47a12beSStefan Roese	CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
1246a47a12beSStefan Roese
1247a47a12beSStefan Roese/* Machine check */
1248a47a12beSStefan Roese	MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
1249a47a12beSStefan Roese
1250a47a12beSStefan Roese/* Data Storage exception. */
1251a47a12beSStefan Roese	STD_EXCEPTION(0x0300, DataStorage, UnknownException)
1252a47a12beSStefan Roese
1253a47a12beSStefan Roese/* Instruction Storage exception. */
1254a47a12beSStefan Roese	STD_EXCEPTION(0x0400, InstStorage, UnknownException)
1255a47a12beSStefan Roese
1256a47a12beSStefan Roese/* External Interrupt exception. */
1257a47a12beSStefan Roese	STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
1258a47a12beSStefan Roese
1259a47a12beSStefan Roese/* Alignment exception. */
1260a47a12beSStefan RoeseAlignment:
1261a47a12beSStefan Roese	EXCEPTION_PROLOG(SRR0, SRR1)
1262a47a12beSStefan Roese	mfspr	r4,DAR
1263a47a12beSStefan Roese	stw	r4,_DAR(r21)
1264a47a12beSStefan Roese	mfspr	r5,DSISR
1265a47a12beSStefan Roese	stw	r5,_DSISR(r21)
1266a47a12beSStefan Roese	addi	r3,r1,STACK_FRAME_OVERHEAD
126796d2bb95SScott Wood	EXC_XFER_TEMPLATE(0x600, Alignment, AlignmentException,
126896d2bb95SScott Wood		MSR_KERNEL, COPY_EE)
1269a47a12beSStefan Roese
1270a47a12beSStefan Roese/* Program check exception */
1271a47a12beSStefan RoeseProgramCheck:
1272a47a12beSStefan Roese	EXCEPTION_PROLOG(SRR0, SRR1)
1273a47a12beSStefan Roese	addi	r3,r1,STACK_FRAME_OVERHEAD
127496d2bb95SScott Wood	EXC_XFER_TEMPLATE(0x700, ProgramCheck, ProgramCheckException,
1275a47a12beSStefan Roese		MSR_KERNEL, COPY_EE)
1276a47a12beSStefan Roese
1277a47a12beSStefan Roese	/* No FPU on MPC85xx.  This exception is not supposed to happen.
1278a47a12beSStefan Roese	*/
1279a47a12beSStefan Roese	STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
1280d87a2ad1SScott Wood	STD_EXCEPTION(0x0900, SystemCall, UnknownException)
1281a47a12beSStefan Roese	STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
1282a47a12beSStefan Roese	STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
1283a47a12beSStefan Roese	STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
1284a47a12beSStefan Roese
1285a47a12beSStefan Roese	STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
1286a47a12beSStefan Roese	STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
1287a47a12beSStefan Roese
1288a47a12beSStefan Roese	CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
1289a47a12beSStefan Roese
1290a47a12beSStefan Roese	.globl	_end_of_vectors
1291a47a12beSStefan Roese_end_of_vectors:
1292a47a12beSStefan Roese
1293a47a12beSStefan Roese
1294a47a12beSStefan Roese	. = . + (0x100 - ( . & 0xff ))	/* align for debug */
1295a47a12beSStefan Roese
1296a47a12beSStefan Roese/*
1297a47a12beSStefan Roese * This code finishes saving the registers to the exception frame
1298a47a12beSStefan Roese * and jumps to the appropriate handler for the exception.
1299a47a12beSStefan Roese * Register r21 is pointer into trap frame, r1 has new stack pointer.
130096d2bb95SScott Wood * r23 is the address of the handler.
1301a47a12beSStefan Roese */
1302a47a12beSStefan Roese	.globl	transfer_to_handler
1303a47a12beSStefan Roesetransfer_to_handler:
1304a47a12beSStefan Roese	SAVE_GPR(7, r21)
1305a47a12beSStefan Roese	SAVE_4GPRS(8, r21)
1306a47a12beSStefan Roese	SAVE_8GPRS(12, r21)
1307a47a12beSStefan Roese	SAVE_8GPRS(24, r21)
1308a47a12beSStefan Roese
1309a47a12beSStefan Roese	li	r22,0
1310a47a12beSStefan Roese	stw	r22,RESULT(r21)
1311a47a12beSStefan Roese	mtspr	SPRG2,r22		/* r1 is now kernel sp */
1312a47a12beSStefan Roese
131396d2bb95SScott Wood	mtctr	r23			/* virtual address of handler */
131496d2bb95SScott Wood	mtmsr	r20
131596d2bb95SScott Wood	bctrl
1316a47a12beSStefan Roese
1317a47a12beSStefan Roeseint_return:
1318a47a12beSStefan Roese	mfmsr	r28		/* Disable interrupts */
1319a47a12beSStefan Roese	li	r4,0
1320a47a12beSStefan Roese	ori	r4,r4,MSR_EE
1321a47a12beSStefan Roese	andc	r28,r28,r4
1322a47a12beSStefan Roese	SYNC			/* Some chip revs need this... */
1323a47a12beSStefan Roese	mtmsr	r28
1324a47a12beSStefan Roese	SYNC
1325a47a12beSStefan Roese	lwz	r2,_CTR(r1)
1326a47a12beSStefan Roese	lwz	r0,_LINK(r1)
1327a47a12beSStefan Roese	mtctr	r2
1328a47a12beSStefan Roese	mtlr	r0
1329a47a12beSStefan Roese	lwz	r2,_XER(r1)
1330a47a12beSStefan Roese	lwz	r0,_CCR(r1)
1331a47a12beSStefan Roese	mtspr	XER,r2
1332a47a12beSStefan Roese	mtcrf	0xFF,r0
1333a47a12beSStefan Roese	REST_10GPRS(3, r1)
1334a47a12beSStefan Roese	REST_10GPRS(13, r1)
1335a47a12beSStefan Roese	REST_8GPRS(23, r1)
1336a47a12beSStefan Roese	REST_GPR(31, r1)
1337a47a12beSStefan Roese	lwz	r2,_NIP(r1)	/* Restore environment */
1338a47a12beSStefan Roese	lwz	r0,_MSR(r1)
1339a47a12beSStefan Roese	mtspr	SRR0,r2
1340a47a12beSStefan Roese	mtspr	SRR1,r0
1341a47a12beSStefan Roese	lwz	r0,GPR0(r1)
1342a47a12beSStefan Roese	lwz	r2,GPR2(r1)
1343a47a12beSStefan Roese	lwz	r1,GPR1(r1)
1344a47a12beSStefan Roese	SYNC
1345a47a12beSStefan Roese	rfi
1346a47a12beSStefan Roese
1347a47a12beSStefan Roese/* Cache functions.
1348a47a12beSStefan Roese*/
13490a9fe8eeSMatthew McClintock.globl flush_icache
13500a9fe8eeSMatthew McClintockflush_icache:
1351a47a12beSStefan Roese.globl invalidate_icache
1352a47a12beSStefan Roeseinvalidate_icache:
1353a47a12beSStefan Roese	mfspr	r0,L1CSR1
1354a47a12beSStefan Roese	ori	r0,r0,L1CSR1_ICFI
1355a47a12beSStefan Roese	msync
1356a47a12beSStefan Roese	isync
1357a47a12beSStefan Roese	mtspr	L1CSR1,r0
1358a47a12beSStefan Roese	isync
1359a47a12beSStefan Roese	blr				/* entire I cache */
1360a47a12beSStefan Roese
1361a47a12beSStefan Roese.globl invalidate_dcache
1362a47a12beSStefan Roeseinvalidate_dcache:
1363a47a12beSStefan Roese	mfspr	r0,L1CSR0
1364a47a12beSStefan Roese	ori	r0,r0,L1CSR0_DCFI
1365a47a12beSStefan Roese	msync
1366a47a12beSStefan Roese	isync
1367a47a12beSStefan Roese	mtspr	L1CSR0,r0
1368a47a12beSStefan Roese	isync
1369a47a12beSStefan Roese	blr
1370a47a12beSStefan Roese
1371a47a12beSStefan Roese	.globl	icache_enable
1372a47a12beSStefan Roeseicache_enable:
1373a47a12beSStefan Roese	mflr	r8
1374a47a12beSStefan Roese	bl	invalidate_icache
1375a47a12beSStefan Roese	mtlr	r8
1376a47a12beSStefan Roese	isync
1377a47a12beSStefan Roese	mfspr	r4,L1CSR1
13782ec70961SMark Marshall	ori	r4,r4,(L1CSR1_CPE | L1CSR1_ICE)@l
13792ec70961SMark Marshall	oris	r4,r4,(L1CSR1_CPE | L1CSR1_ICE)@h
1380a47a12beSStefan Roese	mtspr	L1CSR1,r4
1381a47a12beSStefan Roese	isync
1382a47a12beSStefan Roese	blr
1383a47a12beSStefan Roese
1384a47a12beSStefan Roese	.globl	icache_disable
1385a47a12beSStefan Roeseicache_disable:
1386a47a12beSStefan Roese	mfspr	r0,L1CSR1
1387a47a12beSStefan Roese	lis	r3,0
1388a47a12beSStefan Roese	ori	r3,r3,L1CSR1_ICE
1389a47a12beSStefan Roese	andc	r0,r0,r3
1390a47a12beSStefan Roese	mtspr	L1CSR1,r0
1391a47a12beSStefan Roese	isync
1392a47a12beSStefan Roese	blr
1393a47a12beSStefan Roese
1394a47a12beSStefan Roese	.globl	icache_status
1395a47a12beSStefan Roeseicache_status:
1396a47a12beSStefan Roese	mfspr	r3,L1CSR1
1397a47a12beSStefan Roese	andi.	r3,r3,L1CSR1_ICE
1398a47a12beSStefan Roese	blr
1399a47a12beSStefan Roese
1400a47a12beSStefan Roese	.globl	dcache_enable
1401a47a12beSStefan Roesedcache_enable:
1402a47a12beSStefan Roese	mflr	r8
1403a47a12beSStefan Roese	bl	invalidate_dcache
1404a47a12beSStefan Roese	mtlr	r8
1405a47a12beSStefan Roese	isync
1406a47a12beSStefan Roese	mfspr	r0,L1CSR0
14072ec70961SMark Marshall	ori	r0,r0,(L1CSR0_CPE |  L1CSR0_DCE)@l
14082ec70961SMark Marshall	oris	r0,r0,(L1CSR0_CPE |  L1CSR0_DCE)@h
1409a47a12beSStefan Roese	msync
1410a47a12beSStefan Roese	isync
1411a47a12beSStefan Roese	mtspr	L1CSR0,r0
1412a47a12beSStefan Roese	isync
1413a47a12beSStefan Roese	blr
1414a47a12beSStefan Roese
1415a47a12beSStefan Roese	.globl	dcache_disable
1416a47a12beSStefan Roesedcache_disable:
1417a47a12beSStefan Roese	mfspr	r3,L1CSR0
1418a47a12beSStefan Roese	lis	r4,0
1419a47a12beSStefan Roese	ori	r4,r4,L1CSR0_DCE
1420a47a12beSStefan Roese	andc	r3,r3,r4
142145a68135SKumar Gala	mtspr	L1CSR0,r3
1422a47a12beSStefan Roese	isync
1423a47a12beSStefan Roese	blr
1424a47a12beSStefan Roese
1425a47a12beSStefan Roese	.globl	dcache_status
1426a47a12beSStefan Roesedcache_status:
1427a47a12beSStefan Roese	mfspr	r3,L1CSR0
1428a47a12beSStefan Roese	andi.	r3,r3,L1CSR0_DCE
1429a47a12beSStefan Roese	blr
1430a47a12beSStefan Roese
1431a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1432a47a12beSStefan Roese/* Function:	 in8 */
1433a47a12beSStefan Roese/* Description:	 Input 8 bits */
1434a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1435a47a12beSStefan Roese	.globl	in8
1436a47a12beSStefan Roesein8:
1437a47a12beSStefan Roese	lbz	r3,0x0000(r3)
1438a47a12beSStefan Roese	blr
1439a47a12beSStefan Roese
1440a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1441a47a12beSStefan Roese/* Function:	 out8 */
1442a47a12beSStefan Roese/* Description:	 Output 8 bits */
1443a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1444a47a12beSStefan Roese	.globl	out8
1445a47a12beSStefan Roeseout8:
1446a47a12beSStefan Roese	stb	r4,0x0000(r3)
1447a47a12beSStefan Roese	sync
1448a47a12beSStefan Roese	blr
1449a47a12beSStefan Roese
1450a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1451a47a12beSStefan Roese/* Function:	 out16 */
1452a47a12beSStefan Roese/* Description:	 Output 16 bits */
1453a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1454a47a12beSStefan Roese	.globl	out16
1455a47a12beSStefan Roeseout16:
1456a47a12beSStefan Roese	sth	r4,0x0000(r3)
1457a47a12beSStefan Roese	sync
1458a47a12beSStefan Roese	blr
1459a47a12beSStefan Roese
1460a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1461a47a12beSStefan Roese/* Function:	 out16r */
1462a47a12beSStefan Roese/* Description:	 Byte reverse and output 16 bits */
1463a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1464a47a12beSStefan Roese	.globl	out16r
1465a47a12beSStefan Roeseout16r:
1466a47a12beSStefan Roese	sthbrx	r4,r0,r3
1467a47a12beSStefan Roese	sync
1468a47a12beSStefan Roese	blr
1469a47a12beSStefan Roese
1470a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1471a47a12beSStefan Roese/* Function:	 out32 */
1472a47a12beSStefan Roese/* Description:	 Output 32 bits */
1473a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1474a47a12beSStefan Roese	.globl	out32
1475a47a12beSStefan Roeseout32:
1476a47a12beSStefan Roese	stw	r4,0x0000(r3)
1477a47a12beSStefan Roese	sync
1478a47a12beSStefan Roese	blr
1479a47a12beSStefan Roese
1480a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1481a47a12beSStefan Roese/* Function:	 out32r */
1482a47a12beSStefan Roese/* Description:	 Byte reverse and output 32 bits */
1483a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1484a47a12beSStefan Roese	.globl	out32r
1485a47a12beSStefan Roeseout32r:
1486a47a12beSStefan Roese	stwbrx	r4,r0,r3
1487a47a12beSStefan Roese	sync
1488a47a12beSStefan Roese	blr
1489a47a12beSStefan Roese
1490a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1491a47a12beSStefan Roese/* Function:	 in16 */
1492a47a12beSStefan Roese/* Description:	 Input 16 bits */
1493a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1494a47a12beSStefan Roese	.globl	in16
1495a47a12beSStefan Roesein16:
1496a47a12beSStefan Roese	lhz	r3,0x0000(r3)
1497a47a12beSStefan Roese	blr
1498a47a12beSStefan Roese
1499a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1500a47a12beSStefan Roese/* Function:	 in16r */
1501a47a12beSStefan Roese/* Description:	 Input 16 bits and byte reverse */
1502a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1503a47a12beSStefan Roese	.globl	in16r
1504a47a12beSStefan Roesein16r:
1505a47a12beSStefan Roese	lhbrx	r3,r0,r3
1506a47a12beSStefan Roese	blr
1507a47a12beSStefan Roese
1508a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1509a47a12beSStefan Roese/* Function:	 in32 */
1510a47a12beSStefan Roese/* Description:	 Input 32 bits */
1511a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1512a47a12beSStefan Roese	.globl	in32
1513a47a12beSStefan Roesein32:
1514a47a12beSStefan Roese	lwz	3,0x0000(3)
1515a47a12beSStefan Roese	blr
1516a47a12beSStefan Roese
1517a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1518a47a12beSStefan Roese/* Function:	 in32r */
1519a47a12beSStefan Roese/* Description:	 Input 32 bits and byte reverse */
1520a47a12beSStefan Roese/*------------------------------------------------------------------------------- */
1521a47a12beSStefan Roese	.globl	in32r
1522a47a12beSStefan Roesein32r:
1523a47a12beSStefan Roese	lwbrx	r3,r0,r3
1524a47a12beSStefan Roese	blr
15254b919725SScott Wood#endif  /* !MINIMAL_SPL */
1526a47a12beSStefan Roese
1527a47a12beSStefan Roese/*------------------------------------------------------------------------------*/
1528a47a12beSStefan Roese
1529a47a12beSStefan Roese/*
1530a47a12beSStefan Roese * void write_tlb(mas0, mas1, mas2, mas3, mas7)
1531a47a12beSStefan Roese */
1532a47a12beSStefan Roese	.globl	write_tlb
1533a47a12beSStefan Roesewrite_tlb:
1534a47a12beSStefan Roese	mtspr	MAS0,r3
1535a47a12beSStefan Roese	mtspr	MAS1,r4
1536a47a12beSStefan Roese	mtspr	MAS2,r5
1537a47a12beSStefan Roese	mtspr	MAS3,r6
1538a47a12beSStefan Roese#ifdef CONFIG_ENABLE_36BIT_PHYS
1539a47a12beSStefan Roese	mtspr	MAS7,r7
1540a47a12beSStefan Roese#endif
1541a47a12beSStefan Roese	li	r3,0
1542a47a12beSStefan Roese#ifdef CONFIG_SYS_BOOK3E_HV
1543a47a12beSStefan Roese	mtspr	MAS8,r3
1544a47a12beSStefan Roese#endif
1545a47a12beSStefan Roese	isync
1546a47a12beSStefan Roese	tlbwe
1547a47a12beSStefan Roese	msync
1548a47a12beSStefan Roese	isync
1549a47a12beSStefan Roese	blr
1550a47a12beSStefan Roese
1551a47a12beSStefan Roese/*
1552a47a12beSStefan Roese * void relocate_code (addr_sp, gd, addr_moni)
1553a47a12beSStefan Roese *
1554a47a12beSStefan Roese * This "function" does not return, instead it continues in RAM
1555a47a12beSStefan Roese * after relocating the monitor code.
1556a47a12beSStefan Roese *
1557a47a12beSStefan Roese * r3 = dest
1558a47a12beSStefan Roese * r4 = src
1559a47a12beSStefan Roese * r5 = length in bytes
1560a47a12beSStefan Roese * r6 = cachelinesize
1561a47a12beSStefan Roese */
1562a47a12beSStefan Roese	.globl	relocate_code
1563a47a12beSStefan Roeserelocate_code:
1564a47a12beSStefan Roese	mr	r1,r3		/* Set new stack pointer		*/
1565a47a12beSStefan Roese	mr	r9,r4		/* Save copy of Init Data pointer	*/
1566a47a12beSStefan Roese	mr	r10,r5		/* Save copy of Destination Address	*/
1567a47a12beSStefan Roese
1568a47a12beSStefan Roese	GET_GOT
1569651fcf60SPrabhakar Kushwaha#ifndef CONFIG_SPL_SKIP_RELOCATE
1570a47a12beSStefan Roese	mr	r3,r5				/* Destination Address	*/
1571a47a12beSStefan Roese	lis	r4,CONFIG_SYS_MONITOR_BASE@h		/* Source      Address	*/
1572a47a12beSStefan Roese	ori	r4,r4,CONFIG_SYS_MONITOR_BASE@l
1573a47a12beSStefan Roese	lwz	r5,GOT(__init_end)
1574a47a12beSStefan Roese	sub	r5,r5,r4
1575a47a12beSStefan Roese	li	r6,CONFIG_SYS_CACHELINE_SIZE		/* Cache Line Size	*/
1576a47a12beSStefan Roese
1577a47a12beSStefan Roese	/*
1578a47a12beSStefan Roese	 * Fix GOT pointer:
1579a47a12beSStefan Roese	 *
1580a47a12beSStefan Roese	 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
1581a47a12beSStefan Roese	 *
1582a47a12beSStefan Roese	 * Offset:
1583a47a12beSStefan Roese	 */
1584a47a12beSStefan Roese	sub	r15,r10,r4
1585a47a12beSStefan Roese
1586a47a12beSStefan Roese	/* First our own GOT */
1587a47a12beSStefan Roese	add	r12,r12,r15
1588a47a12beSStefan Roese	/* the the one used by the C code */
1589a47a12beSStefan Roese	add	r30,r30,r15
1590a47a12beSStefan Roese
1591a47a12beSStefan Roese	/*
1592a47a12beSStefan Roese	 * Now relocate code
1593a47a12beSStefan Roese	 */
1594a47a12beSStefan Roese
1595a47a12beSStefan Roese	cmplw	cr1,r3,r4
1596a47a12beSStefan Roese	addi	r0,r5,3
1597a47a12beSStefan Roese	srwi.	r0,r0,2
1598a47a12beSStefan Roese	beq	cr1,4f		/* In place copy is not necessary	*/
1599a47a12beSStefan Roese	beq	7f		/* Protect against 0 count		*/
1600a47a12beSStefan Roese	mtctr	r0
1601a47a12beSStefan Roese	bge	cr1,2f
1602a47a12beSStefan Roese
1603a47a12beSStefan Roese	la	r8,-4(r4)
1604a47a12beSStefan Roese	la	r7,-4(r3)
1605a47a12beSStefan Roese1:	lwzu	r0,4(r8)
1606a47a12beSStefan Roese	stwu	r0,4(r7)
1607a47a12beSStefan Roese	bdnz	1b
1608a47a12beSStefan Roese	b	4f
1609a47a12beSStefan Roese
1610a47a12beSStefan Roese2:	slwi	r0,r0,2
1611a47a12beSStefan Roese	add	r8,r4,r0
1612a47a12beSStefan Roese	add	r7,r3,r0
1613a47a12beSStefan Roese3:	lwzu	r0,-4(r8)
1614a47a12beSStefan Roese	stwu	r0,-4(r7)
1615a47a12beSStefan Roese	bdnz	3b
1616a47a12beSStefan Roese
1617a47a12beSStefan Roese/*
1618a47a12beSStefan Roese * Now flush the cache: note that we must start from a cache aligned
1619a47a12beSStefan Roese * address. Otherwise we might miss one cache line.
1620a47a12beSStefan Roese */
1621a47a12beSStefan Roese4:	cmpwi	r6,0
1622a47a12beSStefan Roese	add	r5,r3,r5
1623a47a12beSStefan Roese	beq	7f		/* Always flush prefetch queue in any case */
1624a47a12beSStefan Roese	subi	r0,r6,1
1625a47a12beSStefan Roese	andc	r3,r3,r0
1626a47a12beSStefan Roese	mr	r4,r3
1627a47a12beSStefan Roese5:	dcbst	0,r4
1628a47a12beSStefan Roese	add	r4,r4,r6
1629a47a12beSStefan Roese	cmplw	r4,r5
1630a47a12beSStefan Roese	blt	5b
1631a47a12beSStefan Roese	sync			/* Wait for all dcbst to complete on bus */
1632a47a12beSStefan Roese	mr	r4,r3
1633a47a12beSStefan Roese6:	icbi	0,r4
1634a47a12beSStefan Roese	add	r4,r4,r6
1635a47a12beSStefan Roese	cmplw	r4,r5
1636a47a12beSStefan Roese	blt	6b
1637a47a12beSStefan Roese7:	sync			/* Wait for all icbi to complete on bus */
1638a47a12beSStefan Roese	isync
1639a47a12beSStefan Roese
1640a47a12beSStefan Roese/*
1641a47a12beSStefan Roese * We are done. Do not return, instead branch to second part of board
1642a47a12beSStefan Roese * initialization, now running from RAM.
1643a47a12beSStefan Roese */
1644a47a12beSStefan Roese
164596d2bb95SScott Wood	addi	r0,r10,in_ram - _start
1646689f00fcSPrabhakar Kushwaha
1647689f00fcSPrabhakar Kushwaha	/*
1648689f00fcSPrabhakar Kushwaha	 * As IVPR is going to point RAM address,
1649689f00fcSPrabhakar Kushwaha	 * Make sure IVOR15 has valid opcode to support debugger
1650689f00fcSPrabhakar Kushwaha	 */
1651689f00fcSPrabhakar Kushwaha	mtspr	IVOR15,r0
1652689f00fcSPrabhakar Kushwaha
1653689f00fcSPrabhakar Kushwaha	/*
1654689f00fcSPrabhakar Kushwaha	 * Re-point the IVPR at RAM
1655689f00fcSPrabhakar Kushwaha	 */
1656689f00fcSPrabhakar Kushwaha	mtspr	IVPR,r10
1657689f00fcSPrabhakar Kushwaha
1658a47a12beSStefan Roese	mtlr	r0
1659a47a12beSStefan Roese	blr				/* NEVER RETURNS! */
1660651fcf60SPrabhakar Kushwaha#endif
1661a47a12beSStefan Roese	.globl	in_ram
1662a47a12beSStefan Roesein_ram:
1663a47a12beSStefan Roese
1664a47a12beSStefan Roese	/*
1665a47a12beSStefan Roese	 * Relocation Function, r12 point to got2+0x8000
1666a47a12beSStefan Roese	 *
1667a47a12beSStefan Roese	 * Adjust got2 pointers, no need to check for 0, this code
1668a47a12beSStefan Roese	 * already puts a few entries in the table.
1669a47a12beSStefan Roese	 */
1670a47a12beSStefan Roese	li	r0,__got2_entries@sectoff@l
1671a47a12beSStefan Roese	la	r3,GOT(_GOT2_TABLE_)
1672a47a12beSStefan Roese	lwz	r11,GOT(_GOT2_TABLE_)
1673a47a12beSStefan Roese	mtctr	r0
1674a47a12beSStefan Roese	sub	r11,r3,r11
1675a47a12beSStefan Roese	addi	r3,r3,-4
1676a47a12beSStefan Roese1:	lwzu	r0,4(r3)
1677a47a12beSStefan Roese	cmpwi	r0,0
1678a47a12beSStefan Roese	beq-	2f
1679a47a12beSStefan Roese	add	r0,r0,r11
1680a47a12beSStefan Roese	stw	r0,0(r3)
1681a47a12beSStefan Roese2:	bdnz	1b
1682a47a12beSStefan Roese
1683a47a12beSStefan Roese	/*
1684a47a12beSStefan Roese	 * Now adjust the fixups and the pointers to the fixups
1685a47a12beSStefan Roese	 * in case we need to move ourselves again.
1686a47a12beSStefan Roese	 */
1687a47a12beSStefan Roese	li	r0,__fixup_entries@sectoff@l
1688a47a12beSStefan Roese	lwz	r3,GOT(_FIXUP_TABLE_)
1689a47a12beSStefan Roese	cmpwi	r0,0
1690a47a12beSStefan Roese	mtctr	r0
1691a47a12beSStefan Roese	addi	r3,r3,-4
1692a47a12beSStefan Roese	beq	4f
1693a47a12beSStefan Roese3:	lwzu	r4,4(r3)
1694a47a12beSStefan Roese	lwzux	r0,r4,r11
1695d1e0b10aSJoakim Tjernlund	cmpwi	r0,0
1696a47a12beSStefan Roese	add	r0,r0,r11
169734bbf618SJoakim Tjernlund	stw	r4,0(r3)
1698d1e0b10aSJoakim Tjernlund	beq-	5f
1699a47a12beSStefan Roese	stw	r0,0(r4)
1700d1e0b10aSJoakim Tjernlund5:	bdnz	3b
1701a47a12beSStefan Roese4:
1702a47a12beSStefan Roeseclear_bss:
1703a47a12beSStefan Roese	/*
1704a47a12beSStefan Roese	 * Now clear BSS segment
1705a47a12beSStefan Roese	 */
1706a47a12beSStefan Roese	lwz	r3,GOT(__bss_start)
17073929fb0aSSimon Glass	lwz	r4,GOT(__bss_end)
1708a47a12beSStefan Roese
1709a47a12beSStefan Roese	cmplw	0,r3,r4
1710a47a12beSStefan Roese	beq	6f
1711a47a12beSStefan Roese
1712a47a12beSStefan Roese	li	r0,0
1713a47a12beSStefan Roese5:
1714a47a12beSStefan Roese	stw	r0,0(r3)
1715a47a12beSStefan Roese	addi	r3,r3,4
1716a47a12beSStefan Roese	cmplw	0,r3,r4
171767ad0d52SYing Zhang	blt	5b
1718a47a12beSStefan Roese6:
1719a47a12beSStefan Roese
1720a47a12beSStefan Roese	mr	r3,r9		/* Init Data pointer		*/
1721a47a12beSStefan Roese	mr	r4,r10		/* Destination Address		*/
1722a47a12beSStefan Roese	bl	board_init_r
1723a47a12beSStefan Roese
17244b919725SScott Wood#ifndef MINIMAL_SPL
1725a47a12beSStefan Roese	/*
1726a47a12beSStefan Roese	 * Copy exception vector code to low memory
1727a47a12beSStefan Roese	 *
1728a47a12beSStefan Roese	 * r3: dest_addr
1729a47a12beSStefan Roese	 * r7: source address, r8: end address, r9: target address
1730a47a12beSStefan Roese	 */
1731a47a12beSStefan Roese	.globl	trap_init
1732a47a12beSStefan Roesetrap_init:
1733e1bfd1c6SScott Wood	mflr	r11
1734e1bfd1c6SScott Wood	bl	_GLOBAL_OFFSET_TABLE_-4
1735e1bfd1c6SScott Wood	mflr	r12
1736e1bfd1c6SScott Wood
173796d2bb95SScott Wood	/* Update IVORs as per relocation */
173896d2bb95SScott Wood	mtspr	IVPR,r3
1739a47a12beSStefan Roese
1740e1bfd1c6SScott Wood	lwz	r4,CriticalInput@got(r12)
174196d2bb95SScott Wood	mtspr	IVOR0,r4	/* 0: Critical input */
1742e1bfd1c6SScott Wood	lwz	r4,MachineCheck@got(r12)
174396d2bb95SScott Wood	mtspr	IVOR1,r4	/* 1: Machine check */
1744e1bfd1c6SScott Wood	lwz	r4,DataStorage@got(r12)
174596d2bb95SScott Wood	mtspr	IVOR2,r4	/* 2: Data storage */
1746e1bfd1c6SScott Wood	lwz	r4,InstStorage@got(r12)
174796d2bb95SScott Wood	mtspr	IVOR3,r4	/* 3: Instruction storage */
1748e1bfd1c6SScott Wood	lwz	r4,ExtInterrupt@got(r12)
174996d2bb95SScott Wood	mtspr	IVOR4,r4	/* 4: External interrupt */
1750e1bfd1c6SScott Wood	lwz	r4,Alignment@got(r12)
175196d2bb95SScott Wood	mtspr	IVOR5,r4	/* 5: Alignment */
1752e1bfd1c6SScott Wood	lwz	r4,ProgramCheck@got(r12)
175396d2bb95SScott Wood	mtspr	IVOR6,r4	/* 6: Program check */
1754e1bfd1c6SScott Wood	lwz	r4,FPUnavailable@got(r12)
175596d2bb95SScott Wood	mtspr	IVOR7,r4	/* 7: floating point unavailable */
1756e1bfd1c6SScott Wood	lwz	r4,SystemCall@got(r12)
175796d2bb95SScott Wood	mtspr	IVOR8,r4	/* 8: System call */
175864829bafSPrabhakar Kushwaha	/* 9: Auxiliary processor unavailable(unsupported) */
1759e1bfd1c6SScott Wood	lwz	r4,Decrementer@got(r12)
176096d2bb95SScott Wood	mtspr	IVOR10,r4	/* 10: Decrementer */
1761e1bfd1c6SScott Wood	lwz	r4,IntervalTimer@got(r12)
176296d2bb95SScott Wood	mtspr	IVOR11,r4	/* 11: Interval timer */
1763e1bfd1c6SScott Wood	lwz	r4,WatchdogTimer@got(r12)
176496d2bb95SScott Wood	mtspr	IVOR12,r4	/* 12: Watchdog timer */
1765e1bfd1c6SScott Wood	lwz	r4,DataTLBError@got(r12)
176696d2bb95SScott Wood	mtspr	IVOR13,r4	/* 13: Data TLB error */
1767e1bfd1c6SScott Wood	lwz	r4,InstructionTLBError@got(r12)
176896d2bb95SScott Wood	mtspr	IVOR14,r4	/* 14: Instruction TLB error */
1769e1bfd1c6SScott Wood	lwz	r4,DebugBreakpoint@got(r12)
177096d2bb95SScott Wood	mtspr	IVOR15,r4	/* 15: Debug */
177164829bafSPrabhakar Kushwaha
1772e1bfd1c6SScott Wood	mtlr	r11
1773a47a12beSStefan Roese	blr
1774a47a12beSStefan Roese
1775a47a12beSStefan Roese.globl unlock_ram_in_cache
1776a47a12beSStefan Roeseunlock_ram_in_cache:
1777a47a12beSStefan Roese	/* invalidate the INIT_RAM section */
1778a47a12beSStefan Roese	lis	r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
1779a47a12beSStefan Roese	ori	r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
1780a47a12beSStefan Roese	mfspr	r4,L1CFG0
1781a47a12beSStefan Roese	andi.	r4,r4,0x1ff
1782a47a12beSStefan Roese	slwi	r4,r4,(10 - 1 - L1_CACHE_SHIFT)
1783a47a12beSStefan Roese	mtctr	r4
1784a47a12beSStefan Roese1:	dcbi	r0,r3
1785668ec87fSRuchika Gupta#ifdef CONFIG_E6500	/* lock/unlock L2 cache long with L1 */
17862becdc6fSYork Sun	dcblc	2, r0, r3
1787668ec87fSRuchika Gupta	dcblc	0, r0, r3
17882becdc6fSYork Sun#else
1789a71d45d7SYork Sun	dcblc	r0,r3
17902becdc6fSYork Sun#endif
1791a47a12beSStefan Roese	addi	r3,r3,CONFIG_SYS_CACHELINE_SIZE
1792a47a12beSStefan Roese	bdnz	1b
1793a47a12beSStefan Roese	sync
1794a47a12beSStefan Roese
1795a47a12beSStefan Roese	/* Invalidate the TLB entries for the cache */
1796a47a12beSStefan Roese	lis	r3,CONFIG_SYS_INIT_RAM_ADDR@h
1797a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
1798a47a12beSStefan Roese	tlbivax	0,r3
1799a47a12beSStefan Roese	addi	r3,r3,0x1000
1800a47a12beSStefan Roese	tlbivax	0,r3
1801a47a12beSStefan Roese	addi	r3,r3,0x1000
1802a47a12beSStefan Roese	tlbivax	0,r3
1803a47a12beSStefan Roese	addi	r3,r3,0x1000
1804a47a12beSStefan Roese	tlbivax	0,r3
1805a47a12beSStefan Roese	isync
1806a47a12beSStefan Roese	blr
1807a47a12beSStefan Roese
1808a47a12beSStefan Roese.globl flush_dcache
1809a47a12beSStefan Roeseflush_dcache:
1810a47a12beSStefan Roese	mfspr	r3,SPRN_L1CFG0
1811a47a12beSStefan Roese
1812a47a12beSStefan Roese	rlwinm	r5,r3,9,3	/* Extract cache block size */
1813a47a12beSStefan Roese	twlgti	r5,1		/* Only 32 and 64 byte cache blocks
1814a47a12beSStefan Roese				 * are currently defined.
1815a47a12beSStefan Roese				 */
1816a47a12beSStefan Roese	li	r4,32
1817a47a12beSStefan Roese	subfic	r6,r5,2		/* r6 = log2(1KiB / cache block size) -
1818a47a12beSStefan Roese				 *      log2(number of ways)
1819a47a12beSStefan Roese				 */
1820a47a12beSStefan Roese	slw	r5,r4,r5	/* r5 = cache block size */
1821a47a12beSStefan Roese
1822a47a12beSStefan Roese	rlwinm	r7,r3,0,0xff	/* Extract number of KiB in the cache */
1823a47a12beSStefan Roese	mulli	r7,r7,13	/* An 8-way cache will require 13
1824a47a12beSStefan Roese				 * loads per set.
1825a47a12beSStefan Roese				 */
1826a47a12beSStefan Roese	slw	r7,r7,r6
1827a47a12beSStefan Roese
1828a47a12beSStefan Roese	/* save off HID0 and set DCFA */
1829a47a12beSStefan Roese	mfspr	r8,SPRN_HID0
1830a47a12beSStefan Roese	ori	r9,r8,HID0_DCFA@l
1831a47a12beSStefan Roese	mtspr	SPRN_HID0,r9
1832a47a12beSStefan Roese	isync
1833a47a12beSStefan Roese
1834a47a12beSStefan Roese	lis	r4,0
1835a47a12beSStefan Roese	mtctr	r7
1836a47a12beSStefan Roese
1837a47a12beSStefan Roese1:	lwz	r3,0(r4)	/* Load... */
1838a47a12beSStefan Roese	add	r4,r4,r5
1839a47a12beSStefan Roese	bdnz	1b
1840a47a12beSStefan Roese
1841a47a12beSStefan Roese	msync
1842a47a12beSStefan Roese	lis	r4,0
1843a47a12beSStefan Roese	mtctr	r7
1844a47a12beSStefan Roese
1845a47a12beSStefan Roese1:	dcbf	0,r4		/* ...and flush. */
1846a47a12beSStefan Roese	add	r4,r4,r5
1847a47a12beSStefan Roese	bdnz	1b
1848a47a12beSStefan Roese
1849a47a12beSStefan Roese	/* restore HID0 */
1850a47a12beSStefan Roese	mtspr	SPRN_HID0,r8
1851a47a12beSStefan Roese	isync
1852a47a12beSStefan Roese
1853a47a12beSStefan Roese	blr
18544b919725SScott Wood#endif /* !MINIMAL_SPL */
1855