xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/release.S (revision d217a9ad01ee6557a0c47cfc745eef6890507bbb)
1a47a12beSStefan Roese/*
2709389b6SYork Sun * Copyright 2008-2012 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese * Kumar Gala <kumar.gala@freescale.com>
4a47a12beSStefan Roese *
51a459660SWolfgang Denk * SPDX-License-Identifier:	GPL-2.0+
6a47a12beSStefan Roese */
7a47a12beSStefan Roese
825ddd1fbSWolfgang Denk#include <asm-offsets.h>
9a47a12beSStefan Roese#include <config.h>
10a47a12beSStefan Roese#include <mpc85xx.h>
11a47a12beSStefan Roese#include <version.h>
12a47a12beSStefan Roese
13a47a12beSStefan Roese#define _LINUX_CONFIG_H 1	/* avoid reading Linux autoconf.h file	*/
14a47a12beSStefan Roese
15a47a12beSStefan Roese#include <ppc_asm.tmpl>
16a47a12beSStefan Roese#include <ppc_defs.h>
17a47a12beSStefan Roese
18a47a12beSStefan Roese#include <asm/cache.h>
19a47a12beSStefan Roese#include <asm/mmu.h>
20a47a12beSStefan Roese
21a47a12beSStefan Roese/* To boot secondary cpus, we need a place for them to start up.
22a47a12beSStefan Roese * Normally, they start at 0xfffffffc, but that's usually the
23a47a12beSStefan Roese * firmware, and we don't want to have to run the firmware again.
24a47a12beSStefan Roese * Instead, the primary cpu will set the BPTR to point here to
25a47a12beSStefan Roese * this page.  We then set up the core, and head to
26a47a12beSStefan Roese * start_secondary.  Note that this means that the code below
27a47a12beSStefan Roese * must never exceed 1023 instructions (the branch at the end
28a47a12beSStefan Roese * would then be the 1024th).
29a47a12beSStefan Roese */
30a47a12beSStefan Roese	.globl	__secondary_start_page
31a47a12beSStefan Roese	.align	12
32a47a12beSStefan Roese__secondary_start_page:
33a47a12beSStefan Roese/* First do some preliminary setup */
34a47a12beSStefan Roese	lis	r3, HID0_EMCP@h		/* enable machine check */
35a47a12beSStefan Roese#ifndef CONFIG_E500MC
36a47a12beSStefan Roese	ori	r3,r3,HID0_TBEN@l	/* enable Timebase */
37a47a12beSStefan Roese#endif
38a47a12beSStefan Roese#ifdef CONFIG_PHYS_64BIT
39a47a12beSStefan Roese	ori	r3,r3,HID0_ENMAS7@l	/* enable MAS7 updates */
40a47a12beSStefan Roese#endif
41a47a12beSStefan Roese	mtspr	SPRN_HID0,r3
42a47a12beSStefan Roese
43a47a12beSStefan Roese#ifndef CONFIG_E500MC
44a47a12beSStefan Roese	li	r3,(HID1_ASTME|HID1_ABE)@l	/* Addr streaming & broadcast */
45a47a12beSStefan Roese	mfspr   r0,PVR
46a47a12beSStefan Roese	andi.	r0,r0,0xff
47a47a12beSStefan Roese	cmpwi	r0,0x50@l	/* if we are rev 5.0 or greater set MBDD */
48a47a12beSStefan Roese	blt 1f
49a47a12beSStefan Roese	/* Set MBDD bit also */
50a47a12beSStefan Roese	ori r3, r3, HID1_MBDD@l
51a47a12beSStefan Roese1:
52a47a12beSStefan Roese	mtspr	SPRN_HID1,r3
53a47a12beSStefan Roese#endif
54a47a12beSStefan Roese
5543f082bbSKumar Gala#ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
56cd7ad629SAndy Fleming	mfspr	r3,SPRN_HDBCR1
5743f082bbSKumar Gala	oris	r3,r3,0x0100
58cd7ad629SAndy Fleming	mtspr	SPRN_HDBCR1,r3
5943f082bbSKumar Gala#endif
6043f082bbSKumar Gala
6133eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
6233eee330SScott Wood	mfspr	r3,SPRN_SVR
6333eee330SScott Wood	rlwinm	r3,r3,0,0xff
6433eee330SScott Wood	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
6533eee330SScott Wood	cmpw	r3,r4
6633eee330SScott Wood	beq	1f
6733eee330SScott Wood
6833eee330SScott Wood#ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
6933eee330SScott Wood	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
7033eee330SScott Wood	cmpw	r3,r4
7133eee330SScott Wood	beq	1f
7233eee330SScott Wood#endif
7333eee330SScott Wood
7433eee330SScott Wood	/* Not a supported revision affected by erratum */
7533eee330SScott Wood	b	2f
7633eee330SScott Wood
7733eee330SScott Wood1:	/* Erratum says set bits 55:60 to 001001 */
7833eee330SScott Wood	msync
7933eee330SScott Wood	isync
80cd7ad629SAndy Fleming	mfspr	r3,SPRN_HDBCR0
8133eee330SScott Wood	li	r4,0x48
8233eee330SScott Wood	rlwimi	r3,r4,0,0x1f8
83cd7ad629SAndy Fleming	mtspr	SPRN_HDBCR0,r3
8433eee330SScott Wood	isync
8533eee330SScott Wood2:
8633eee330SScott Wood#endif
8733eee330SScott Wood
88a47a12beSStefan Roese	/* Enable branch prediction */
89a47a12beSStefan Roese	lis	r3,BUCSR_ENABLE@h
90a47a12beSStefan Roese	ori	r3,r3,BUCSR_ENABLE@l
91a47a12beSStefan Roese	mtspr	SPRN_BUCSR,r3
92a47a12beSStefan Roese
93a47a12beSStefan Roese	/* Ensure TB is 0 */
94a47a12beSStefan Roese	li	r3,0
95a47a12beSStefan Roese	mttbl	r3
96a47a12beSStefan Roese	mttbu	r3
97a47a12beSStefan Roese
98a47a12beSStefan Roese	/* Enable/invalidate the I-Cache */
99a47a12beSStefan Roese	lis	r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
100a47a12beSStefan Roese	ori	r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
101a47a12beSStefan Roese	mtspr	SPRN_L1CSR1,r2
102a47a12beSStefan Roese1:
103a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR1
104a47a12beSStefan Roese	and.	r1,r3,r2
105a47a12beSStefan Roese	bne	1b
106a47a12beSStefan Roese
107a47a12beSStefan Roese	lis	r3,(L1CSR1_CPE|L1CSR1_ICE)@h
108a47a12beSStefan Roese	ori	r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
109a47a12beSStefan Roese	mtspr	SPRN_L1CSR1,r3
110a47a12beSStefan Roese	isync
111a47a12beSStefan Roese2:
112a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR1
113a47a12beSStefan Roese	andi.	r1,r3,L1CSR1_ICE@l
114a47a12beSStefan Roese	beq	2b
115a47a12beSStefan Roese
116a47a12beSStefan Roese	/* Enable/invalidate the D-Cache */
117a47a12beSStefan Roese	lis	r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
118a47a12beSStefan Roese	ori	r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
119a47a12beSStefan Roese	mtspr	SPRN_L1CSR0,r2
120a47a12beSStefan Roese1:
121a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR0
122a47a12beSStefan Roese	and.	r1,r3,r2
123a47a12beSStefan Roese	bne	1b
124a47a12beSStefan Roese
125a47a12beSStefan Roese	lis	r3,(L1CSR0_CPE|L1CSR0_DCE)@h
126a47a12beSStefan Roese	ori	r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
127a47a12beSStefan Roese	mtspr	SPRN_L1CSR0,r3
128a47a12beSStefan Roese	isync
129a47a12beSStefan Roese2:
130a47a12beSStefan Roese	mfspr	r3,SPRN_L1CSR0
131a47a12beSStefan Roese	andi.	r1,r3,L1CSR0_DCE@l
132a47a12beSStefan Roese	beq	2b
133a47a12beSStefan Roese
134a47a12beSStefan Roese#define toreset(x) (x - __secondary_start_page + 0xfffff000)
135a47a12beSStefan Roese
136a47a12beSStefan Roese	/* get our PIR to figure out our table entry */
137ffd06e02SYork Sun	lis	r3,toreset(__spin_table_addr)@h
138ffd06e02SYork Sun	ori	r3,r3,toreset(__spin_table_addr)@l
139ffd06e02SYork Sun	lwz	r3,0(r3)
140a47a12beSStefan Roese
141a47a12beSStefan Roese	mfspr	r0,SPRN_PIR
142615f0cbaSYork Sun#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
143709389b6SYork Sun/*
144615f0cbaSYork Sun * PIR definition for Chassis 2
145709389b6SYork Sun * 0-17 Reserved (logic 0s)
146f6981439SYork Sun * 18-19 CHIP_ID,    2'b00      - SoC 1
147709389b6SYork Sun *                  all others - reserved
1480c7e65f3STimur Tabi * 20-24 CLUSTER_ID 5'b00000   - CCM 1
149709389b6SYork Sun *                  all others - reserved
1500c7e65f3STimur Tabi * 25-26 CORE_CLUSTER_ID 2'b00 - cluster 1
1510c7e65f3STimur Tabi *                       2'b01 - cluster 2
1520c7e65f3STimur Tabi *                       2'b10 - cluster 3
1530c7e65f3STimur Tabi *                       2'b11 - cluster 4
1540c7e65f3STimur Tabi * 27-28 CORE_ID         2'b00 - core 0
1550c7e65f3STimur Tabi *                       2'b01 - core 1
1560c7e65f3STimur Tabi *                       2'b10 - core 2
1570c7e65f3STimur Tabi *                       2'b11 - core 3
1580c7e65f3STimur Tabi * 29-31 THREAD_ID       3'b000 - thread 0
1590c7e65f3STimur Tabi *                       3'b001 - thread 1
160f6981439SYork Sun *
161f6981439SYork Sun * Power-on PIR increments threads by 0x01, cores within a cluster by 0x08
162f6981439SYork Sun * and clusters by 0x20.
163f6981439SYork Sun *
164f6981439SYork Sun * We renumber PIR so that all threads in the system are consecutive.
165709389b6SYork Sun */
166f6981439SYork Sun
167f6981439SYork Sun	rlwinm	r8,r0,29,0x03	/* r8 = core within cluster */
168f6981439SYork Sun	srwi	r10,r0,5	/* r10 = cluster */
169f6981439SYork Sun
170f6981439SYork Sun	mulli	r5,r10,CONFIG_SYS_FSL_CORES_PER_CLUSTER
171f6981439SYork Sun	add	r5,r5,r8	/* for spin table index */
172f6981439SYork Sun	mulli	r4,r5,CONFIG_SYS_FSL_THREADS_PER_CORE	/* for PIR */
173709389b6SYork Sun#elif	defined(CONFIG_E500MC)
174a47a12beSStefan Roese	rlwinm	r4,r0,27,27,31
175f6981439SYork Sun	mr	r5,r4
176a47a12beSStefan Roese#else
177a47a12beSStefan Roese	mr	r4,r0
178f6981439SYork Sun	mr	r5,r4
179a47a12beSStefan Roese#endif
180a47a12beSStefan Roese
181709389b6SYork Sun	/*
182f6981439SYork Sun	 * r10 has the base address for the entry.
183f6981439SYork Sun	 * we cannot access it yet before setting up a new TLB
184709389b6SYork Sun	 */
185f6981439SYork Sun	slwi	r8,r5,6	/* spin table is padded to 64 byte */
186f6981439SYork Sun	add	r10,r3,r8
187709389b6SYork Sun
188709389b6SYork Sun	mtspr	SPRN_PIR,r4	/* write to PIR register */
189709389b6SYork Sun
1906d2b9da1SYork Sun#ifdef CONFIG_SYS_CACHE_STASHING
1916d2b9da1SYork Sun	/* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
1926d2b9da1SYork Sun	slwi	r8,r4,1
1936d2b9da1SYork Sun	addi	r8,r8,32
1946d2b9da1SYork Sun	mtspr	L1CSR2,r8
1956d2b9da1SYork Sun#endif
1966d2b9da1SYork Sun
1975e23ab0aSYork Sun#if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
1985e23ab0aSYork Sun	defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
1995e23ab0aSYork Sun	/*
2005e23ab0aSYork Sun	 * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
2015e23ab0aSYork Sun	 * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
2025e23ab0aSYork Sun	 * also appleis to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1
2035e23ab0aSYork Sun	 */
2041e9ea85fSYork Sun	mfspr   r3,SPRN_SVR
2055e23ab0aSYork Sun	rlwinm	r6,r3,24,~0x800		/* clear E bit */
2061e9ea85fSYork Sun
2075e23ab0aSYork Sun	lis	r5,SVR_P4080@h
2085e23ab0aSYork Sun	ori	r5,r5,SVR_P4080@l
2095e23ab0aSYork Sun	cmpw	r6,r5
2105e23ab0aSYork Sun	bne	1f
2115e23ab0aSYork Sun
2125e23ab0aSYork Sun	rlwinm  r3,r3,0,0xf0
2135e23ab0aSYork Sun	li      r5,0x30
2145e23ab0aSYork Sun	cmpw    r3,r5
2155e23ab0aSYork Sun	bge     2f
2165e23ab0aSYork Sun1:
21757125f22SYork Sun#ifdef	CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011
21857125f22SYork Sun	lis	r3,toreset(enable_cpu_a011_workaround)@ha
21957125f22SYork Sun	lwz	r3,toreset(enable_cpu_a011_workaround)@l(r3)
22057125f22SYork Sun	cmpwi	r3,0
22157125f22SYork Sun	beq	2f
22257125f22SYork Sun#endif
2235e23ab0aSYork Sun	mfspr	r3,L1CSR2
2245e23ab0aSYork Sun	oris	r3,r3,(L1CSR2_DCWS)@h
2255e23ab0aSYork Sun	mtspr	L1CSR2,r3
2261e9ea85fSYork Sun2:
227fd3c9befSKumar Gala#endif
228fd3c9befSKumar Gala
229*d217a9adSYork Sun#ifdef CONFIG_SYS_FSL_ERRATUM_A005812
230*d217a9adSYork Sun	/*
231*d217a9adSYork Sun	 * A-005812 workaround sets bit 32 of SPR 976 for SoCs running in
232*d217a9adSYork Sun	 * write shadow mode. This code should run after other code setting
233*d217a9adSYork Sun	 * DCWS.
234*d217a9adSYork Sun	 */
235*d217a9adSYork Sun	mfspr	r3,L1CSR2
236*d217a9adSYork Sun	andis.	r3,r3,(L1CSR2_DCWS)@h
237*d217a9adSYork Sun	beq	1f
238*d217a9adSYork Sun	mfspr	r3, SPRN_HDBCR0
239*d217a9adSYork Sun	oris	r3, r3, 0x8000
240*d217a9adSYork Sun	mtspr	SPRN_HDBCR0, r3
241*d217a9adSYork Sun1:
242*d217a9adSYork Sun#endif
243*d217a9adSYork Sun
244a47a12beSStefan Roese#ifdef CONFIG_BACKSIDE_L2_CACHE
245acf3f8daSKumar Gala	/* skip L2 setup on P2040/P2040E as they have no L2 */
246feae3424SYork Sun	mfspr	r3,SPRN_SVR
247feae3424SYork Sun	rlwinm	r6,r3,24,~0x800		/* clear E bit of SVR */
248feae3424SYork Sun
249acf3f8daSKumar Gala	lis	r3,SVR_P2040@h
250acf3f8daSKumar Gala	ori	r3,r3,SVR_P2040@l
251feae3424SYork Sun	cmpw	r6,r3
252acf3f8daSKumar Gala	beq 3f
253acf3f8daSKumar Gala
254a47a12beSStefan Roese	/* Enable/invalidate the L2 cache */
255a47a12beSStefan Roese	msync
256a47a12beSStefan Roese	lis	r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h
257a47a12beSStefan Roese	ori	r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l
258a47a12beSStefan Roese	mtspr	SPRN_L2CSR0,r2
259a47a12beSStefan Roese1:
260a47a12beSStefan Roese	mfspr	r3,SPRN_L2CSR0
261a47a12beSStefan Roese	and.	r1,r3,r2
262a47a12beSStefan Roese	bne	1b
263a47a12beSStefan Roese
264a47a12beSStefan Roese#ifdef CONFIG_SYS_CACHE_STASHING
265a47a12beSStefan Roese	/* set stash id to (coreID) * 2 + 32 + L2 (1) */
266a47a12beSStefan Roese	addi	r3,r8,1
267a47a12beSStefan Roese	mtspr	SPRN_L2CSR1,r3
268a47a12beSStefan Roese#endif
269a47a12beSStefan Roese
270a47a12beSStefan Roese	lis	r3,CONFIG_SYS_INIT_L2CSR0@h
271a47a12beSStefan Roese	ori	r3,r3,CONFIG_SYS_INIT_L2CSR0@l
272a47a12beSStefan Roese	mtspr	SPRN_L2CSR0,r3
273a47a12beSStefan Roese	isync
274a47a12beSStefan Roese2:
275a47a12beSStefan Roese	mfspr	r3,SPRN_L2CSR0
276a47a12beSStefan Roese	andis.	r1,r3,L2CSR0_L2E@h
277a47a12beSStefan Roese	beq	2b
278a47a12beSStefan Roese#endif
279acf3f8daSKumar Gala3:
280ffd06e02SYork Sun	/* setup mapping for the spin table, WIMGE=0b00100 */
281ffd06e02SYork Sun	lis	r13,toreset(__spin_table_addr)@h
282ffd06e02SYork Sun	ori	r13,r13,toreset(__spin_table_addr)@l
283ffd06e02SYork Sun	lwz	r13,0(r13)
284ffd06e02SYork Sun	/* mask by 4K */
285ffd06e02SYork Sun	rlwinm	r13,r13,0,0,19
286a47a12beSStefan Roese
287ffd06e02SYork Sun	lis	r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h
288ffd06e02SYork Sun	mtspr	SPRN_MAS0,r11
289ffd06e02SYork Sun	lis	r11,(MAS1_VALID|MAS1_IPROT)@h
290ffd06e02SYork Sun	ori	r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
291ffd06e02SYork Sun	mtspr	SPRN_MAS1,r11
292ffd06e02SYork Sun	oris	r11,r13,(MAS2_M|MAS2_G)@h
293ffd06e02SYork Sun	ori	r11,r13,(MAS2_M|MAS2_G)@l
294ffd06e02SYork Sun	mtspr	SPRN_MAS2,r11
295ffd06e02SYork Sun	oris	r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h
296ffd06e02SYork Sun	ori	r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l
297ffd06e02SYork Sun	mtspr	SPRN_MAS3,r11
298ffd06e02SYork Sun	li	r11,0
299ffd06e02SYork Sun	mtspr	SPRN_MAS7,r11
300ffd06e02SYork Sun	tlbwe
301ffd06e02SYork Sun
302ffd06e02SYork Sun	/*
303ffd06e02SYork Sun	 * __bootpg_addr has the address of __second_half_boot_page
304ffd06e02SYork Sun	 * jump there in AS=1 space with cache enabled
305ffd06e02SYork Sun	 */
306ffd06e02SYork Sun	lis	r13,toreset(__bootpg_addr)@h
307ffd06e02SYork Sun	ori	r13,r13,toreset(__bootpg_addr)@l
308ffd06e02SYork Sun	lwz	r11,0(r13)
309ffd06e02SYork Sun	mtspr	SPRN_SRR0,r11
310ffd06e02SYork Sun	mfmsr	r13
311ffd06e02SYork Sun	ori	r12,r13,MSR_IS|MSR_DS@l
312ffd06e02SYork Sun	mtspr	SPRN_SRR1,r12
313ffd06e02SYork Sun	rfi
314ffd06e02SYork Sun
315ffd06e02SYork Sun	/*
316ffd06e02SYork Sun	 * Allocate some space for the SDRAM address of the bootpg.
317ffd06e02SYork Sun	 * This variable has to be in the boot page so that it can
318ffd06e02SYork Sun	 * be accessed by secondary cores when they come out of reset.
319ffd06e02SYork Sun	 */
320ffd06e02SYork Sun	.align L1_CACHE_SHIFT
321ffd06e02SYork Sun	.globl __bootpg_addr
322ffd06e02SYork Sun__bootpg_addr:
323ffd06e02SYork Sun	.long	0
324ffd06e02SYork Sun
325ffd06e02SYork Sun	.global __spin_table_addr
326ffd06e02SYork Sun__spin_table_addr:
327ffd06e02SYork Sun	.long	0
328ffd06e02SYork Sun
329ffd06e02SYork Sun	/*
330ffd06e02SYork Sun	 * This variable is set by cpu_init_r() after parsing hwconfig
331ffd06e02SYork Sun	 * to enable workaround for erratum NMG_CPU_A011.
332ffd06e02SYork Sun	 */
333ffd06e02SYork Sun	.align L1_CACHE_SHIFT
334ffd06e02SYork Sun	.global enable_cpu_a011_workaround
335ffd06e02SYork Sunenable_cpu_a011_workaround:
336ffd06e02SYork Sun	.long	1
337ffd06e02SYork Sun
338ffd06e02SYork Sun	/* Fill in the empty space.  The actual reset vector is
339ffd06e02SYork Sun	 * the last word of the page */
340ffd06e02SYork Sun__secondary_start_code_end:
341ffd06e02SYork Sun	.space 4092 - (__secondary_start_code_end - __secondary_start_page)
342ffd06e02SYork Sun__secondary_reset_vector:
343ffd06e02SYork Sun	b	__secondary_start_page
344ffd06e02SYork Sun
345ffd06e02SYork Sun
346ffd06e02SYork Sun/* this is a separated page for the spin table and cacheable boot code */
347ffd06e02SYork Sun	.align L1_CACHE_SHIFT
348ffd06e02SYork Sun	.global __second_half_boot_page
349ffd06e02SYork Sun__second_half_boot_page:
3502a5fcb83SYork Sun#ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
3512a5fcb83SYork Sun	lis	r3,(spin_table_compat - __second_half_boot_page)@h
3522a5fcb83SYork Sun	ori	r3,r3,(spin_table_compat - __second_half_boot_page)@l
3532a5fcb83SYork Sun	add	r3,r3,r11 /* r11 has the address of __second_half_boot_page */
3542a5fcb83SYork Sun	lwz	r14,0(r3)
3552a5fcb83SYork Sun#endif
3562a5fcb83SYork Sun
357a47a12beSStefan Roese#define ENTRY_ADDR_UPPER	0
358a47a12beSStefan Roese#define ENTRY_ADDR_LOWER	4
359a47a12beSStefan Roese#define ENTRY_R3_UPPER		8
360a47a12beSStefan Roese#define ENTRY_R3_LOWER		12
361a47a12beSStefan Roese#define ENTRY_RESV		16
362a47a12beSStefan Roese#define ENTRY_PIR		20
363ffd06e02SYork Sun#define ENTRY_SIZE		64
364ffd06e02SYork Sun	/*
365ffd06e02SYork Sun	 * setup the entry
366ffd06e02SYork Sun	 * r10 has the base address of the spin table.
367ffd06e02SYork Sun	 * spin table is defined as
368ffd06e02SYork Sun	 * struct {
369ffd06e02SYork Sun	 *	uint64_t entry_addr;
370ffd06e02SYork Sun	 *	uint64_t r3;
371ffd06e02SYork Sun	 *	uint32_t rsvd1;
372ffd06e02SYork Sun	 *	uint32_t pir;
373ffd06e02SYork Sun	 * };
374ffd06e02SYork Sun	 * we pad this struct to 64 bytes so each entry is in its own cacheline
375ffd06e02SYork Sun	 */
376a47a12beSStefan Roese	li	r3,0
377a47a12beSStefan Roese	li	r8,1
378ffd06e02SYork Sun	mfspr	r4,SPRN_PIR
379a47a12beSStefan Roese	stw	r3,ENTRY_ADDR_UPPER(r10)
380a47a12beSStefan Roese	stw	r3,ENTRY_R3_UPPER(r10)
381a47a12beSStefan Roese	stw	r4,ENTRY_R3_LOWER(r10)
382ffd06e02SYork Sun	stw	r3,ENTRY_RESV(r10)
383ffd06e02SYork Sun	stw	r4,ENTRY_PIR(r10)
384ffd06e02SYork Sun	msync
385ffd06e02SYork Sun	stw	r8,ENTRY_ADDR_LOWER(r10)
386a47a12beSStefan Roese
387a47a12beSStefan Roese	/* spin waiting for addr */
3882a5fcb83SYork Sun3:
3892a5fcb83SYork Sun/*
3902a5fcb83SYork Sun * To comply with ePAPR 1.1, the spin table has been moved to cache-enabled
3912a5fcb83SYork Sun * memory. Old OS may not work with this change. A patch is waiting to be
3922a5fcb83SYork Sun * accepted for Linux kernel. Other OS needs similar fix to spin table.
3932a5fcb83SYork Sun * For OSes with old spin table code, we can enable this temporary fix by
3942a5fcb83SYork Sun * setting environmental variable "spin_table_compat". For new OSes, set
3952a5fcb83SYork Sun * "spin_table_compat=no". After Linux is fixed, we can remove this macro
3962a5fcb83SYork Sun * and related code. For now, it is enabled by default.
3972a5fcb83SYork Sun */
3982a5fcb83SYork Sun#ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
3992a5fcb83SYork Sun	cmpwi   r14,0
4002a5fcb83SYork Sun	beq     4f
4012a5fcb83SYork Sun	dcbf    0, r10
4022a5fcb83SYork Sun	sync
4032a5fcb83SYork Sun4:
4042a5fcb83SYork Sun#endif
4052a5fcb83SYork Sun	lwz	r4,ENTRY_ADDR_LOWER(r10)
406a47a12beSStefan Roese	andi.	r11,r4,1
407ffd06e02SYork Sun	bne	3b
408a47a12beSStefan Roese	isync
409a47a12beSStefan Roese
410a47a12beSStefan Roese	/* setup IVORs to match fixed offsets */
411a47a12beSStefan Roese#include "fixed_ivor.S"
412a47a12beSStefan Roese
413a47a12beSStefan Roese	/* get the upper bits of the addr */
414a47a12beSStefan Roese	lwz	r11,ENTRY_ADDR_UPPER(r10)
415a47a12beSStefan Roese
416a47a12beSStefan Roese	/* setup branch addr */
417a47a12beSStefan Roese	mtspr	SPRN_SRR0,r4
418a47a12beSStefan Roese
419a47a12beSStefan Roese	/* mark the entry as released */
420a47a12beSStefan Roese	li	r8,3
421a47a12beSStefan Roese	stw	r8,ENTRY_ADDR_LOWER(r10)
422a47a12beSStefan Roese
423a47a12beSStefan Roese	/* mask by ~64M to setup our tlb we will jump to */
424a47a12beSStefan Roese	rlwinm	r12,r4,0,0,5
425a47a12beSStefan Roese
426ffd06e02SYork Sun	/*
427ffd06e02SYork Sun	 * setup r3, r4, r5, r6, r7, r8, r9
428ffd06e02SYork Sun	 * r3 contains the value to put in the r3 register at secondary cpu
429ffd06e02SYork Sun	 * entry. The high 32-bits are ignored on 32-bit chip implementations.
430ffd06e02SYork Sun	 * 64-bit chip implementations however shall load all 64-bits
431ffd06e02SYork Sun	 */
432ffd06e02SYork Sun#ifdef CONFIG_SYS_PPC64
433ffd06e02SYork Sun	ld	r3,ENTRY_R3_UPPER(r10)
434ffd06e02SYork Sun#else
435a47a12beSStefan Roese	lwz	r3,ENTRY_R3_LOWER(r10)
436ffd06e02SYork Sun#endif
437a47a12beSStefan Roese	li	r4,0
438a47a12beSStefan Roese	li	r5,0
4393f0997b3SYork Sun	li	r6,0
440a47a12beSStefan Roese	lis	r7,(64*1024*1024)@h
441a47a12beSStefan Roese	li	r8,0
442a47a12beSStefan Roese	li	r9,0
443a47a12beSStefan Roese
444a47a12beSStefan Roese	/* load up the pir */
445a47a12beSStefan Roese	lwz	r0,ENTRY_PIR(r10)
446a47a12beSStefan Roese	mtspr	SPRN_PIR,r0
447a47a12beSStefan Roese	mfspr	r0,SPRN_PIR
448a47a12beSStefan Roese	stw	r0,ENTRY_PIR(r10)
449a47a12beSStefan Roese
450a47a12beSStefan Roese	mtspr	IVPR,r12
451a47a12beSStefan Roese/*
452a47a12beSStefan Roese * Coming here, we know the cpu has one TLB mapping in TLB1[0]
453a47a12beSStefan Roese * which maps 0xfffff000-0xffffffff one-to-one.  We set up a
454a47a12beSStefan Roese * second mapping that maps addr 1:1 for 64M, and then we jump to
455a47a12beSStefan Roese * addr
456a47a12beSStefan Roese */
457a47a12beSStefan Roese	lis	r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h
458a47a12beSStefan Roese	mtspr	SPRN_MAS0,r10
459a47a12beSStefan Roese	lis	r10,(MAS1_VALID|MAS1_IPROT)@h
460a47a12beSStefan Roese	ori	r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
461a47a12beSStefan Roese	mtspr	SPRN_MAS1,r10
462a47a12beSStefan Roese	/* WIMGE = 0b00000 for now */
463a47a12beSStefan Roese	mtspr	SPRN_MAS2,r12
464a47a12beSStefan Roese	ori	r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR)
465a47a12beSStefan Roese	mtspr	SPRN_MAS3,r12
466a47a12beSStefan Roese#ifdef CONFIG_ENABLE_36BIT_PHYS
467a47a12beSStefan Roese	mtspr	SPRN_MAS7,r11
468a47a12beSStefan Roese#endif
469a47a12beSStefan Roese	tlbwe
470a47a12beSStefan Roese
471a47a12beSStefan Roese/* Now we have another mapping for this page, so we jump to that
472a47a12beSStefan Roese * mapping
473a47a12beSStefan Roese */
474a47a12beSStefan Roese	mtspr	SPRN_SRR1,r13
475a47a12beSStefan Roese	rfi
476a47a12beSStefan Roese
477a47a12beSStefan Roese
478ffd06e02SYork Sun	.align 6
479a47a12beSStefan Roese	.globl __spin_table
480a47a12beSStefan Roese__spin_table:
481a47a12beSStefan Roese	.space CONFIG_MAX_CPUS*ENTRY_SIZE
4822a5fcb83SYork Sun
4832a5fcb83SYork Sun#ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
4842a5fcb83SYork Sun	.align L1_CACHE_SHIFT
4852a5fcb83SYork Sun	.global spin_table_compat
4862a5fcb83SYork Sunspin_table_compat:
4872a5fcb83SYork Sun	.long	1
4882a5fcb83SYork Sun
4892a5fcb83SYork Sun#endif
4902a5fcb83SYork Sun
491ffd06e02SYork Sun__spin_table_end:
492ffd06e02SYork Sun	.space 4096 - (__spin_table_end - __spin_table)
493