release.S 9.01 KB
Newer Older
1
/*
2
 * Copyright 2008-2011 Freescale Semiconductor, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * Kumar Gala <kumar.gala@freescale.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

24
#include <asm-offsets.h>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include <config.h>
#include <mpc85xx.h>
#include <version.h>

#define _LINUX_CONFIG_H 1	/* avoid reading Linux autoconf.h file	*/

#include <ppc_asm.tmpl>
#include <ppc_defs.h>

#include <asm/cache.h>
#include <asm/mmu.h>

/* To boot secondary cpus, we need a place for them to start up.
 * Normally, they start at 0xfffffffc, but that's usually the
 * firmware, and we don't want to have to run the firmware again.
 * Instead, the primary cpu will set the BPTR to point here to
 * this page.  We then set up the core, and head to
 * start_secondary.  Note that this means that the code below
 * must never exceed 1023 instructions (the branch at the end
 * would then be the 1024th).
 */
	.globl	__secondary_start_page
	.align	12
__secondary_start_page:
/* First do some preliminary setup */
	lis	r3, HID0_EMCP@h		/* enable machine check */
51
#ifndef CONFIG_E500MC
52
	ori	r3,r3,HID0_TBEN@l	/* enable Timebase */
53
#endif
54 55 56 57 58
#ifdef CONFIG_PHYS_64BIT
	ori	r3,r3,HID0_ENMAS7@l	/* enable MAS7 updates */
#endif
	mtspr	SPRN_HID0,r3

59
#ifndef CONFIG_E500MC
60
	li	r3,(HID1_ASTME|HID1_ABE)@l	/* Addr streaming & broadcast */
61 62 63 64 65 66 67
	mfspr   r0,PVR
	andi.	r0,r0,0xff
	cmpwi	r0,0x50@l	/* if we are rev 5.0 or greater set MBDD */
	blt 1f
	/* Set MBDD bit also */
	ori r3, r3, HID1_MBDD@l
1:
68
	mtspr	SPRN_HID1,r3
69
#endif
70

71 72 73 74 75 76
#ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
	mfspr	r3,977
	oris	r3,r3,0x0100
	mtspr	977,r3
#endif

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#ifdef CONFIG_SYS_FSL_ERRATUM_A004510
	mfspr	r3,SPRN_SVR
	rlwinm	r3,r3,0,0xff
	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
	cmpw	r3,r4
	beq	1f

#ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
	li	r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
	cmpw	r3,r4
	beq	1f
#endif

	/* Not a supported revision affected by erratum */
	b	2f

1:	/* Erratum says set bits 55:60 to 001001 */
	msync
	isync
	mfspr	r3,976
	li	r4,0x48
	rlwimi	r3,r4,0,0x1f8
	mtspr	976,r3
	isync
2:
#endif

104
	/* Enable branch prediction */
105 106
	lis	r3,BUCSR_ENABLE@h
	ori	r3,r3,BUCSR_ENABLE@l
107 108
	mtspr	SPRN_BUCSR,r3

109 110 111 112 113
	/* Ensure TB is 0 */
	li	r3,0
	mttbl	r3
	mttbu	r3

114
	/* Enable/invalidate the I-Cache */
115 116 117 118 119 120 121 122 123 124 125
	lis	r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
	ori	r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
	mtspr	SPRN_L1CSR1,r2
1:
	mfspr	r3,SPRN_L1CSR1
	and.	r1,r3,r2
	bne	1b

	lis	r3,(L1CSR1_CPE|L1CSR1_ICE)@h
	ori	r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
	mtspr	SPRN_L1CSR1,r3
126
	isync
127 128 129 130
2:
	mfspr	r3,SPRN_L1CSR1
	andi.	r1,r3,L1CSR1_ICE@l
	beq	2b
131 132

	/* Enable/invalidate the D-Cache */
133 134 135 136 137 138 139 140 141 142 143
	lis	r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
	ori	r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
	mtspr	SPRN_L1CSR0,r2
1:
	mfspr	r3,SPRN_L1CSR0
	and.	r1,r3,r2
	bne	1b

	lis	r3,(L1CSR0_CPE|L1CSR0_DCE)@h
	ori	r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
	mtspr	SPRN_L1CSR0,r3
144
	isync
145 146 147 148
2:
	mfspr	r3,SPRN_L1CSR0
	andi.	r1,r3,L1CSR0_DCE@l
	beq	2b
149 150 151 152 153 154 155

#define toreset(x) (x - __secondary_start_page + 0xfffff000)

	/* get our PIR to figure out our table entry */
	lis	r3,toreset(__spin_table)@h
	ori	r3,r3,toreset(__spin_table)@l

156
	/* r10 has the base address for the entry */
157
	mfspr	r0,SPRN_PIR
158 159 160
#ifdef CONFIG_E500MC
	rlwinm	r4,r0,27,27,31
#else
161
	mr	r4,r0
162
#endif
163 164 165
	slwi	r8,r4,5
	add	r10,r3,r8

166 167 168 169 170 171 172
#if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING)
	/* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
	slwi	r8,r4,1
	addi	r8,r8,32
	mtspr	L1CSR2,r8
#endif

173 174 175 176 177 178 179
#if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
	defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
	/*
	 * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
	 * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
	 * also appleis to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1
	 */
180
	mfspr   r3,SPRN_SVR
181 182 183 184 185 186 187
	rlwinm	r6,r3,24,~0x800		/* clear E bit */

	lis	r5,SVR_P4080@h
	ori	r5,r5,SVR_P4080@l
	cmpw	r6,r5
	bne	1f

188
	rlwinm  r3,r3,0,0xf0
189 190
	li      r5,0x30
	cmpw    r3,r5
191
	bge     2f
192
1:
193 194 195 196 197 198
#ifdef	CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011
	lis	r3,toreset(enable_cpu_a011_workaround)@ha
	lwz	r3,toreset(enable_cpu_a011_workaround)@l(r3)
	cmpwi	r3,0
	beq	2f
#endif
199 200 201
	mfspr	r3,L1CSR2
	oris	r3,r3,(L1CSR2_DCWS)@h
	mtspr	L1CSR2,r3
202
2:
203 204
#endif

205
#ifdef CONFIG_BACKSIDE_L2_CACHE
206
	/* skip L2 setup on P2040/P2040E as they have no L2 */
207 208 209
	mfspr	r3,SPRN_SVR
	rlwinm	r6,r3,24,~0x800		/* clear E bit of SVR */

210 211
	lis	r3,SVR_P2040@h
	ori	r3,r3,SVR_P2040@l
212
	cmpw	r6,r3
213 214
	beq 3f

215 216
	/* Enable/invalidate the L2 cache */
	msync
217 218 219
	lis	r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h
	ori	r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l
	mtspr	SPRN_L2CSR0,r2
220 221
1:
	mfspr	r3,SPRN_L2CSR0
222
	and.	r1,r3,r2
223 224
	bne	1b

225 226 227 228 229 230
#ifdef CONFIG_SYS_CACHE_STASHING
	/* set stash id to (coreID) * 2 + 32 + L2 (1) */
	addi	r3,r8,1
	mtspr	SPRN_L2CSR1,r3
#endif

231 232 233 234
	lis	r3,CONFIG_SYS_INIT_L2CSR0@h
	ori	r3,r3,CONFIG_SYS_INIT_L2CSR0@l
	mtspr	SPRN_L2CSR0,r3
	isync
235 236 237 238
2:
	mfspr	r3,SPRN_L2CSR0
	andis.	r1,r3,L2CSR0_L2E@h
	beq	2b
239
#endif
240
3:
241

242 243 244 245 246 247 248 249 250 251
#define EPAPR_MAGIC		(0x45504150)
#define ENTRY_ADDR_UPPER	0
#define ENTRY_ADDR_LOWER	4
#define ENTRY_R3_UPPER		8
#define ENTRY_R3_LOWER		12
#define ENTRY_RESV		16
#define ENTRY_PIR		20
#define ENTRY_R6_UPPER		24
#define ENTRY_R6_LOWER		28
#define ENTRY_SIZE		32
252 253

	/* setup the entry */
254
	li	r3,0
255
	li	r8,1
256 257 258 259 260 261 262 263
	stw	r0,ENTRY_PIR(r10)
	stw	r3,ENTRY_ADDR_UPPER(r10)
	stw	r8,ENTRY_ADDR_LOWER(r10)
	stw	r3,ENTRY_R3_UPPER(r10)
	stw	r4,ENTRY_R3_LOWER(r10)
	stw	r3,ENTRY_R6_UPPER(r10)
	stw	r3,ENTRY_R6_LOWER(r10)

264 265 266 267 268
	/* load r13 with the address of the 'bootpg' in SDRAM */
	lis	r13,toreset(__bootpg_addr)@h
	ori	r13,r13,toreset(__bootpg_addr)@l
	lwz	r13,0(r13)

269 270 271 272 273 274
	/* setup mapping for AS = 1, and jump there */
	lis	r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h
	mtspr	SPRN_MAS0,r11
	lis	r11,(MAS1_VALID|MAS1_IPROT)@h
	ori	r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
	mtspr	SPRN_MAS1,r11
275 276
	oris	r11,r13,(MAS2_I|MAS2_G)@h
	ori	r11,r13,(MAS2_I|MAS2_G)@l
277
	mtspr	SPRN_MAS2,r11
278 279
	oris	r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h
	ori	r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l
280 281 282 283 284
	mtspr	SPRN_MAS3,r11
	tlbwe

	bl	1f
1:	mflr	r11
285 286 287 288 289 290 291 292 293 294 295
	/*
	 * OR in 0xfff to create a mask of the bootpg SDRAM address.  We use
	 * this mask to fixup the cpu spin table and the address that we want
	 * to jump to, eg change them from 0xfffffxxx to 0x7ffffxxx if the
	 * bootpg is at 0x7ffff000 in SDRAM.
	 */
	ori	r13,r13,0xfff
	and	r11, r11, r13
	and	r10, r10, r13

	addi	r11,r11,(2f-1b)
296 297 298 299 300 301
	mfmsr	r13
	ori	r12,r13,MSR_IS|MSR_DS@l

	mtspr	SPRN_SRR0,r11
	mtspr	SPRN_SRR1,r12
	rfi
302 303

	/* spin waiting for addr */
304 305
2:
	lwz	r4,ENTRY_ADDR_LOWER(r10)
306
	andi.	r11,r4,1
307
	bne	2b
308
	isync
309

310 311 312
	/* setup IVORs to match fixed offsets */
#include "fixed_ivor.S"

313 314
	/* get the upper bits of the addr */
	lwz	r11,ENTRY_ADDR_UPPER(r10)
315 316

	/* setup branch addr */
317
	mtspr	SPRN_SRR0,r4
318 319 320

	/* mark the entry as released */
	li	r8,3
321
	stw	r8,ENTRY_ADDR_LOWER(r10)
322 323

	/* mask by ~64M to setup our tlb we will jump to */
324
	rlwinm	r12,r4,0,0,5
325

326 327 328
	/* setup r3, r4, r5, r6, r7, r8, r9 */
	lwz	r3,ENTRY_R3_LOWER(r10)
	li	r4,0
329
	li	r5,0
330 331 332 333
	lwz	r6,ENTRY_R6_LOWER(r10)
	lis	r7,(64*1024*1024)@h
	li	r8,0
	li	r9,0
334 335

	/* load up the pir */
336
	lwz	r0,ENTRY_PIR(r10)
337 338
	mtspr	SPRN_PIR,r0
	mfspr	r0,SPRN_PIR
339
	stw	r0,ENTRY_PIR(r10)
340

341
	mtspr	IVPR,r12
342 343 344 345 346 347
/*
 * Coming here, we know the cpu has one TLB mapping in TLB1[0]
 * which maps 0xfffff000-0xffffffff one-to-one.  We set up a
 * second mapping that maps addr 1:1 for 64M, and then we jump to
 * addr
 */
348 349 350 351 352
	lis	r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h
	mtspr	SPRN_MAS0,r10
	lis	r10,(MAS1_VALID|MAS1_IPROT)@h
	ori	r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
	mtspr	SPRN_MAS1,r10
353
	/* WIMGE = 0b00000 for now */
354 355 356 357 358 359
	mtspr	SPRN_MAS2,r12
	ori	r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR)
	mtspr	SPRN_MAS3,r12
#ifdef CONFIG_ENABLE_36BIT_PHYS
	mtspr	SPRN_MAS7,r11
#endif
360 361 362 363 364
	tlbwe

/* Now we have another mapping for this page, so we jump to that
 * mapping
 */
365 366
	mtspr	SPRN_SRR1,r13
	rfi
367

368 369 370 371 372 373 374 375 376
	/*
	 * Allocate some space for the SDRAM address of the bootpg.
	 * This variable has to be in the boot page so that it can
	 * be accessed by secondary cores when they come out of reset.
	 */
	.globl __bootpg_addr
__bootpg_addr:
	.long	0

377
	.align L1_CACHE_SHIFT
378 379
	.globl __spin_table
__spin_table:
380
	.space CONFIG_MAX_CPUS*ENTRY_SIZE
381

382 383 384 385 386 387 388 389 390
	/*
	 * This variable is set by cpu_init_r() after parsing hwconfig
	 * to enable workaround for erratum NMG_CPU_A011.
	 */
	.align L1_CACHE_SHIFT
	.global enable_cpu_a011_workaround
enable_cpu_a011_workaround:
	.long	1

391 392 393 394 395 396
	/* Fill in the empty space.  The actual reset vector is
	 * the last word of the page */
__secondary_start_code_end:
	.space 4092 - (__secondary_start_code_end - __secondary_start_page)
__secondary_reset_vector:
	b	__secondary_start_page