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