xref: /openbmc/linux/arch/powerpc/kernel/cpu_setup_6xx.S (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
29b781727SPaul Mackerras/*
39b781727SPaul Mackerras * This file contains low level CPU setup functions.
49b781727SPaul Mackerras *    Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
59b781727SPaul Mackerras */
69b781727SPaul Mackerras
72da37761SChristophe Leroy#include <linux/linkage.h>
82da37761SChristophe Leroy
99b781727SPaul Mackerras#include <asm/processor.h>
109b781727SPaul Mackerras#include <asm/page.h>
119b781727SPaul Mackerras#include <asm/cputable.h>
129b781727SPaul Mackerras#include <asm/ppc_asm.h>
139b781727SPaul Mackerras#include <asm/asm-offsets.h>
149b781727SPaul Mackerras#include <asm/cache.h>
152319f123SKumar Gala#include <asm/mmu.h>
162c86cd18SChristophe Leroy#include <asm/feature-fixups.h>
179b781727SPaul Mackerras
189b781727SPaul Mackerras_GLOBAL(__setup_cpu_603)
191f1936ffSBenjamin Herrenschmidt	mflr	r5
202319f123SKumar GalaBEGIN_MMU_FTR_SECTION
212319f123SKumar Gala	li	r10,0
22ee43eb78SBenjamin Herrenschmidt	mtspr	SPRN_SPRG_603_LRU,r10		/* init SW LRU tracking */
232319f123SKumar GalaEND_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
2493c4a162SChristophe Leroy
25fc215fe7SKumar GalaBEGIN_FTR_SECTION
26fc215fe7SKumar Gala	bl	__init_fpu_registers
27fc215fe7SKumar GalaEND_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
28fc215fe7SKumar Gala	bl	setup_common_caches
29*8631837dSMatthias Schiffer
30*8631837dSMatthias Schiffer	/*
31*8631837dSMatthias Schiffer	 * This assumes that all cores using __setup_cpu_603 with
32*8631837dSMatthias Schiffer	 * MMU_FTR_USE_HIGH_BATS are G2_LE compatible
33*8631837dSMatthias Schiffer	 */
34*8631837dSMatthias SchifferBEGIN_MMU_FTR_SECTION
35*8631837dSMatthias Schiffer	bl      setup_g2_le_hid2
36*8631837dSMatthias SchifferEND_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
37*8631837dSMatthias Schiffer
381f1936ffSBenjamin Herrenschmidt	mtlr	r5
39fc215fe7SKumar Gala	blr
409b781727SPaul Mackerras_GLOBAL(__setup_cpu_604)
411f1936ffSBenjamin Herrenschmidt	mflr	r5
429b781727SPaul Mackerras	bl	setup_common_caches
439b781727SPaul Mackerras	bl	setup_604_hid0
441f1936ffSBenjamin Herrenschmidt	mtlr	r5
459b781727SPaul Mackerras	blr
469b781727SPaul Mackerras_GLOBAL(__setup_cpu_750)
471f1936ffSBenjamin Herrenschmidt	mflr	r5
489b781727SPaul Mackerras	bl	__init_fpu_registers
499b781727SPaul Mackerras	bl	setup_common_caches
509b781727SPaul Mackerras	bl	setup_750_7400_hid0
511f1936ffSBenjamin Herrenschmidt	mtlr	r5
529b781727SPaul Mackerras	blr
539b781727SPaul Mackerras_GLOBAL(__setup_cpu_750cx)
541f1936ffSBenjamin Herrenschmidt	mflr	r5
559b781727SPaul Mackerras	bl	__init_fpu_registers
569b781727SPaul Mackerras	bl	setup_common_caches
579b781727SPaul Mackerras	bl	setup_750_7400_hid0
589b781727SPaul Mackerras	bl	setup_750cx
591f1936ffSBenjamin Herrenschmidt	mtlr	r5
609b781727SPaul Mackerras	blr
619b781727SPaul Mackerras_GLOBAL(__setup_cpu_750fx)
621f1936ffSBenjamin Herrenschmidt	mflr	r5
639b781727SPaul Mackerras	bl	__init_fpu_registers
649b781727SPaul Mackerras	bl	setup_common_caches
659b781727SPaul Mackerras	bl	setup_750_7400_hid0
669b781727SPaul Mackerras	bl	setup_750fx
671f1936ffSBenjamin Herrenschmidt	mtlr	r5
689b781727SPaul Mackerras	blr
699b781727SPaul Mackerras_GLOBAL(__setup_cpu_7400)
701f1936ffSBenjamin Herrenschmidt	mflr	r5
719b781727SPaul Mackerras	bl	__init_fpu_registers
729b781727SPaul Mackerras	bl	setup_7400_workarounds
739b781727SPaul Mackerras	bl	setup_common_caches
749b781727SPaul Mackerras	bl	setup_750_7400_hid0
751f1936ffSBenjamin Herrenschmidt	mtlr	r5
769b781727SPaul Mackerras	blr
779b781727SPaul Mackerras_GLOBAL(__setup_cpu_7410)
781f1936ffSBenjamin Herrenschmidt	mflr	r5
799b781727SPaul Mackerras	bl	__init_fpu_registers
809b781727SPaul Mackerras	bl	setup_7410_workarounds
819b781727SPaul Mackerras	bl	setup_common_caches
829b781727SPaul Mackerras	bl	setup_750_7400_hid0
839b781727SPaul Mackerras	li	r3,0
849b781727SPaul Mackerras	mtspr	SPRN_L2CR2,r3
851f1936ffSBenjamin Herrenschmidt	mtlr	r5
869b781727SPaul Mackerras	blr
879b781727SPaul Mackerras_GLOBAL(__setup_cpu_745x)
881f1936ffSBenjamin Herrenschmidt	mflr	r5
899b781727SPaul Mackerras	bl	setup_common_caches
909b781727SPaul Mackerras	bl	setup_745x_specifics
911f1936ffSBenjamin Herrenschmidt	mtlr	r5
929b781727SPaul Mackerras	blr
939b781727SPaul Mackerras
949b781727SPaul Mackerras/* Enable caches for 603's, 604, 750 & 7400 */
952da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_common_caches)
969b781727SPaul Mackerras	mfspr	r11,SPRN_HID0
979b781727SPaul Mackerras	andi.	r0,r11,HID0_DCE
989b781727SPaul Mackerras	ori	r11,r11,HID0_ICE|HID0_DCE
999b781727SPaul Mackerras	ori	r8,r11,HID0_ICFI
1009b781727SPaul Mackerras	bne	1f			/* don't invalidate the D-cache */
1019b781727SPaul Mackerras	ori	r8,r8,HID0_DCI		/* unless it wasn't enabled */
1029b781727SPaul Mackerras1:	sync
1039b781727SPaul Mackerras	mtspr	SPRN_HID0,r8		/* enable and invalidate caches */
1049b781727SPaul Mackerras	sync
1059b781727SPaul Mackerras	mtspr	SPRN_HID0,r11		/* enable caches */
1069b781727SPaul Mackerras	sync
1079b781727SPaul Mackerras	isync
1089b781727SPaul Mackerras	blr
1092da37761SChristophe LeroySYM_FUNC_END(setup_common_caches)
1109b781727SPaul Mackerras
1119b781727SPaul Mackerras/* 604, 604e, 604ev, ...
1129b781727SPaul Mackerras * Enable superscalar execution & branch history table
1139b781727SPaul Mackerras */
1142da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_604_hid0)
1159b781727SPaul Mackerras	mfspr	r11,SPRN_HID0
1169b781727SPaul Mackerras	ori	r11,r11,HID0_SIED|HID0_BHTE
1179b781727SPaul Mackerras	ori	r8,r11,HID0_BTCD
1189b781727SPaul Mackerras	sync
1199b781727SPaul Mackerras	mtspr	SPRN_HID0,r8	/* flush branch target address cache */
1209b781727SPaul Mackerras	sync			/* on 604e/604r */
1219b781727SPaul Mackerras	mtspr	SPRN_HID0,r11
1229b781727SPaul Mackerras	sync
1239b781727SPaul Mackerras	isync
1249b781727SPaul Mackerras	blr
1252da37761SChristophe LeroySYM_FUNC_END(setup_604_hid0)
1269b781727SPaul Mackerras
127*8631837dSMatthias Schiffer/* Enable high BATs for G2_LE and derivatives like e300cX */
128*8631837dSMatthias SchifferSYM_FUNC_START_LOCAL(setup_g2_le_hid2)
129*8631837dSMatthias Schiffer	mfspr	r11,SPRN_HID2_G2_LE
130*8631837dSMatthias Schiffer	oris	r11,r11,HID2_G2_LE_HBE@h
131*8631837dSMatthias Schiffer	mtspr	SPRN_HID2_G2_LE,r11
132*8631837dSMatthias Schiffer	sync
133*8631837dSMatthias Schiffer	isync
134*8631837dSMatthias Schiffer	blr
135*8631837dSMatthias SchifferSYM_FUNC_END(setup_g2_le_hid2)
136*8631837dSMatthias Schiffer
1379b781727SPaul Mackerras/* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
1389b781727SPaul Mackerras * erratas we work around here.
1399b781727SPaul Mackerras * Moto MPC710CE.pdf describes them, those are errata
1409b781727SPaul Mackerras * #3, #4 and #5
1419b781727SPaul Mackerras * Note that we assume the firmware didn't choose to
1429b781727SPaul Mackerras * apply other workarounds (there are other ones documented
1439b781727SPaul Mackerras * in the .pdf). It appear that Apple firmware only works
1449b781727SPaul Mackerras * around #3 and with the same fix we use. We may want to
1459b781727SPaul Mackerras * check if the CPU is using 60x bus mode in which case
1469b781727SPaul Mackerras * the workaround for errata #4 is useless. Also, we may
147c03983acSJean Delvare * want to explicitly clear HID0_NOPDST as this is not
1489b781727SPaul Mackerras * needed once we have applied workaround #5 (though it's
1499b781727SPaul Mackerras * not set by Apple's firmware at least).
1509b781727SPaul Mackerras */
1512da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_7400_workarounds)
1529b781727SPaul Mackerras	mfpvr	r3
1539b781727SPaul Mackerras	rlwinm	r3,r3,0,20,31
1549b781727SPaul Mackerras	cmpwi	0,r3,0x0207
1559b781727SPaul Mackerras	ble	1f
1569b781727SPaul Mackerras	blr
1572da37761SChristophe LeroySYM_FUNC_END(setup_7400_workarounds)
1582da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_7410_workarounds)
1599b781727SPaul Mackerras	mfpvr	r3
1609b781727SPaul Mackerras	rlwinm	r3,r3,0,20,31
1619b781727SPaul Mackerras	cmpwi	0,r3,0x0100
1629b781727SPaul Mackerras	bnelr
1639b781727SPaul Mackerras1:
1649b781727SPaul Mackerras	mfspr	r11,SPRN_MSSSR0
1659b781727SPaul Mackerras	/* Errata #3: Set L1OPQ_SIZE to 0x10 */
1669b781727SPaul Mackerras	rlwinm	r11,r11,0,9,6
1679b781727SPaul Mackerras	oris	r11,r11,0x0100
1689b781727SPaul Mackerras	/* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
1699b781727SPaul Mackerras	oris	r11,r11,0x0002
1709b781727SPaul Mackerras	/* Errata #5: Set DRLT_SIZE to 0x01 */
1719b781727SPaul Mackerras	rlwinm	r11,r11,0,5,2
1729b781727SPaul Mackerras	oris	r11,r11,0x0800
1739b781727SPaul Mackerras	sync
1749b781727SPaul Mackerras	mtspr	SPRN_MSSSR0,r11
1759b781727SPaul Mackerras	sync
1769b781727SPaul Mackerras	isync
1779b781727SPaul Mackerras	blr
1782da37761SChristophe LeroySYM_FUNC_END(setup_7410_workarounds)
1799b781727SPaul Mackerras
1809b781727SPaul Mackerras/* 740/750/7400/7410
181027dfac6SMichael Ellerman * Enable Store Gathering (SGE), Address Broadcast (ABE),
1829b781727SPaul Mackerras * Branch History Table (BHTE), Branch Target ICache (BTIC)
1839b781727SPaul Mackerras * Dynamic Power Management (DPM), Speculative (SPD)
1849b781727SPaul Mackerras * Clear Instruction cache throttling (ICTC)
1859b781727SPaul Mackerras */
1862da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_750_7400_hid0)
1879b781727SPaul Mackerras	mfspr	r11,SPRN_HID0
1889b781727SPaul Mackerras	ori	r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
1899b781727SPaul Mackerras	oris	r11,r11,HID0_DPM@h
1909b781727SPaul MackerrasBEGIN_FTR_SECTION
1919b781727SPaul Mackerras	xori	r11,r11,HID0_BTIC
1929b781727SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
1939b781727SPaul MackerrasBEGIN_FTR_SECTION
1949b781727SPaul Mackerras	xoris	r11,r11,HID0_DPM@h	/* disable dynamic power mgmt */
1959b781727SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
1969b781727SPaul Mackerras	li	r3,HID0_SPD
1979b781727SPaul Mackerras	andc	r11,r11,r3		/* clear SPD: enable speculative */
1989b781727SPaul Mackerras 	li	r3,0
1999b781727SPaul Mackerras 	mtspr	SPRN_ICTC,r3		/* Instruction Cache Throttling off */
2009b781727SPaul Mackerras	isync
2019b781727SPaul Mackerras	mtspr	SPRN_HID0,r11
2029b781727SPaul Mackerras	sync
2039b781727SPaul Mackerras	isync
2049b781727SPaul Mackerras	blr
2052da37761SChristophe LeroySYM_FUNC_END(setup_750_7400_hid0)
2069b781727SPaul Mackerras
2079b781727SPaul Mackerras/* 750cx specific
2089b781727SPaul Mackerras * Looks like we have to disable NAP feature for some PLL settings...
2099b781727SPaul Mackerras * (waiting for confirmation)
2109b781727SPaul Mackerras */
2112da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_750cx)
2129b781727SPaul Mackerras	mfspr	r10, SPRN_HID1
2139b781727SPaul Mackerras	rlwinm	r10,r10,4,28,31
2149b781727SPaul Mackerras	cmpwi	cr0,r10,7
2159b781727SPaul Mackerras	cmpwi	cr1,r10,9
2169b781727SPaul Mackerras	cmpwi	cr2,r10,11
2179b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr1+eq
2189b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr2+eq
2199b781727SPaul Mackerras	bnelr
2201f1936ffSBenjamin Herrenschmidt	lwz	r6,CPU_SPEC_FEATURES(r4)
2219b781727SPaul Mackerras	li	r7,CPU_FTR_CAN_NAP
2229b781727SPaul Mackerras	andc	r6,r6,r7
2231f1936ffSBenjamin Herrenschmidt	stw	r6,CPU_SPEC_FEATURES(r4)
2249b781727SPaul Mackerras	blr
2252da37761SChristophe LeroySYM_FUNC_END(setup_750cx)
2269b781727SPaul Mackerras
2279b781727SPaul Mackerras/* 750fx specific
2289b781727SPaul Mackerras */
2292da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_750fx)
2309b781727SPaul Mackerras	blr
2312da37761SChristophe LeroySYM_FUNC_END(setup_750fx)
2329b781727SPaul Mackerras
2339b781727SPaul Mackerras/* MPC 745x
2349b781727SPaul Mackerras * Enable Store Gathering (SGE), Branch Folding (FOLD)
2359b781727SPaul Mackerras * Branch History Table (BHTE), Branch Target ICache (BTIC)
2369b781727SPaul Mackerras * Dynamic Power Management (DPM), Speculative (SPD)
2379b781727SPaul Mackerras * Ensure our data cache instructions really operate.
2389b781727SPaul Mackerras * Timebase has to be running or we wouldn't have made it here,
2399b781727SPaul Mackerras * just ensure we don't disable it.
2409b781727SPaul Mackerras * Clear Instruction cache throttling (ICTC)
2419b781727SPaul Mackerras * Enable L2 HW prefetch
2429b781727SPaul Mackerras */
2432da37761SChristophe LeroySYM_FUNC_START_LOCAL(setup_745x_specifics)
2449b781727SPaul Mackerras	/* We check for the presence of an L3 cache setup by
2459b781727SPaul Mackerras	 * the firmware. If any, we disable NAP capability as
2469b781727SPaul Mackerras	 * it's known to be bogus on rev 2.1 and earlier
2479b781727SPaul Mackerras	 */
2482198c070SJon LoeligerBEGIN_FTR_SECTION
2499b781727SPaul Mackerras	mfspr	r11,SPRN_L3CR
2509b781727SPaul Mackerras	andis.	r11,r11,L3CR_L3E@h
2519b781727SPaul Mackerras	beq	1f
2522198c070SJon LoeligerEND_FTR_SECTION_IFSET(CPU_FTR_L3CR)
2531f1936ffSBenjamin Herrenschmidt	lwz	r6,CPU_SPEC_FEATURES(r4)
2549bbf0b57SPaul Mackerras	andis.	r0,r6,CPU_FTR_L3_DISABLE_NAP@h
2559b781727SPaul Mackerras	beq	1f
2569b781727SPaul Mackerras	li	r7,CPU_FTR_CAN_NAP
2579b781727SPaul Mackerras	andc	r6,r6,r7
2581f1936ffSBenjamin Herrenschmidt	stw	r6,CPU_SPEC_FEATURES(r4)
2599b781727SPaul Mackerras1:
2609b781727SPaul Mackerras	mfspr	r11,SPRN_HID0
2619b781727SPaul Mackerras
2629b781727SPaul Mackerras	/* All of the bits we have to set.....
2639b781727SPaul Mackerras	 */
2649b781727SPaul Mackerras	ori	r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
2659b781727SPaul Mackerras	ori	r11,r11,HID0_LRSTK | HID0_BTIC
2669b781727SPaul Mackerras	oris	r11,r11,HID0_DPM@h
267f1f8b494SGerhard PircherBEGIN_MMU_FTR_SECTION
268f1f8b494SGerhard Pircher	oris	r11,r11,HID0_HIGH_BAT@h
269f1f8b494SGerhard PircherEND_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
2709b781727SPaul MackerrasBEGIN_FTR_SECTION
2719b781727SPaul Mackerras	xori	r11,r11,HID0_BTIC
2729b781727SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
2739b781727SPaul MackerrasBEGIN_FTR_SECTION
2749b781727SPaul Mackerras	xoris	r11,r11,HID0_DPM@h	/* disable dynamic power mgmt */
2759b781727SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
2769b781727SPaul Mackerras
2779b781727SPaul Mackerras	/* All of the bits we have to clear....
2789b781727SPaul Mackerras	 */
2799b781727SPaul Mackerras	li	r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
2809b781727SPaul Mackerras	andc	r11,r11,r3		/* clear SPD: enable speculative */
2819b781727SPaul Mackerras 	li	r3,0
2829b781727SPaul Mackerras
2839b781727SPaul Mackerras 	mtspr	SPRN_ICTC,r3		/* Instruction Cache Throttling off */
2849b781727SPaul Mackerras	isync
2859b781727SPaul Mackerras	mtspr	SPRN_HID0,r11
2869b781727SPaul Mackerras	sync
2879b781727SPaul Mackerras	isync
2889b781727SPaul Mackerras
2899b781727SPaul Mackerras	/* Enable L2 HW prefetch, if L2 is enabled
2909b781727SPaul Mackerras	 */
2919b781727SPaul Mackerras	mfspr	r3,SPRN_L2CR
2929b781727SPaul Mackerras	andis.	r3,r3,L2CR_L2E@h
2939b781727SPaul Mackerras	beqlr
2949b781727SPaul Mackerras	mfspr	r3,SPRN_MSSCR0
2959b781727SPaul Mackerras	ori	r3,r3,3
2969b781727SPaul Mackerras	sync
2979b781727SPaul Mackerras	mtspr	SPRN_MSSCR0,r3
2989b781727SPaul Mackerras	sync
2999b781727SPaul Mackerras	isync
3009b781727SPaul Mackerras	blr
3012da37761SChristophe LeroySYM_FUNC_END(setup_745x_specifics)
3029b781727SPaul Mackerras
3039b781727SPaul Mackerras/*
3049b781727SPaul Mackerras * Initialize the FPU registers. This is needed to work around an errata
3059b781727SPaul Mackerras * in some 750 cpus where using a not yet initialized FPU register after
3069b781727SPaul Mackerras * power on reset may hang the CPU
3079b781727SPaul Mackerras */
3089b781727SPaul Mackerras_GLOBAL(__init_fpu_registers)
3099b781727SPaul Mackerras	mfmsr	r10
3109b781727SPaul Mackerras	ori	r11,r10,MSR_FP
3119b781727SPaul Mackerras	mtmsr	r11
3129b781727SPaul Mackerras	isync
3139b781727SPaul Mackerras	addis	r9,r3,empty_zero_page@ha
3149b781727SPaul Mackerras	addi	r9,r9,empty_zero_page@l
3159b781727SPaul Mackerras	REST_32FPRS(0,r9)
3169b781727SPaul Mackerras	sync
3179b781727SPaul Mackerras	mtmsr	r10
3189b781727SPaul Mackerras	isync
3199b781727SPaul Mackerras	blr
3205f32e836SChristophe Leroy_ASM_NOKPROBE_SYMBOL(__init_fpu_registers)
3219b781727SPaul Mackerras
3229b781727SPaul Mackerras
3239b781727SPaul Mackerras/* Definitions for the table use to save CPU states */
3249b781727SPaul Mackerras#define CS_HID0		0
3259b781727SPaul Mackerras#define CS_HID1		4
3269b781727SPaul Mackerras#define CS_HID2		8
3279b781727SPaul Mackerras#define	CS_MSSCR0	12
3289b781727SPaul Mackerras#define CS_MSSSR0	16
3299b781727SPaul Mackerras#define CS_ICTRL	20
3309b781727SPaul Mackerras#define CS_LDSTCR	24
3319b781727SPaul Mackerras#define CS_LDSTDB	28
3329b781727SPaul Mackerras#define CS_SIZE		32
3339b781727SPaul Mackerras
3349b781727SPaul Mackerras	.data
3359b781727SPaul Mackerras	.balign	L1_CACHE_BYTES
3369b781727SPaul Mackerrascpu_state_storage:
3379b781727SPaul Mackerras	.space	CS_SIZE
3389b781727SPaul Mackerras	.balign	L1_CACHE_BYTES,0
3399b781727SPaul Mackerras	.text
3409b781727SPaul Mackerras
3419b781727SPaul Mackerras/* Called in normal context to backup CPU 0 state. This
3429b781727SPaul Mackerras * does not include cache settings. This function is also
3439b781727SPaul Mackerras * called for machine sleep. This does not include the MMU
3449b781727SPaul Mackerras * setup, BATs, etc... but rather the "special" registers
3459b781727SPaul Mackerras * like HID0, HID1, MSSCR0, etc...
3469b781727SPaul Mackerras */
3479b781727SPaul Mackerras_GLOBAL(__save_cpu_setup)
3489b781727SPaul Mackerras	/* Some CR fields are volatile, we back it up all */
3499b781727SPaul Mackerras	mfcr	r7
3509b781727SPaul Mackerras
3519b781727SPaul Mackerras	/* Get storage ptr */
3529b781727SPaul Mackerras	lis	r5,cpu_state_storage@h
3539b781727SPaul Mackerras	ori	r5,r5,cpu_state_storage@l
3549b781727SPaul Mackerras
355d7cceda9SChristophe Leroy	/* Save HID0 (common to all CONFIG_PPC_BOOK3S_32 cpus) */
3569b781727SPaul Mackerras	mfspr	r3,SPRN_HID0
3579b781727SPaul Mackerras	stw	r3,CS_HID0(r5)
3589b781727SPaul Mackerras
3599b781727SPaul Mackerras	/* Now deal with CPU type dependent registers */
3609b781727SPaul Mackerras	mfspr	r3,SPRN_PVR
3619b781727SPaul Mackerras	srwi	r3,r3,16
3629b781727SPaul Mackerras	cmplwi	cr0,r3,0x8000	/* 7450 */
3639b781727SPaul Mackerras	cmplwi	cr1,r3,0x000c	/* 7400 */
3649b781727SPaul Mackerras	cmplwi	cr2,r3,0x800c	/* 7410 */
3659b781727SPaul Mackerras	cmplwi	cr3,r3,0x8001	/* 7455 */
3669b781727SPaul Mackerras	cmplwi	cr4,r3,0x8002	/* 7457 */
3679b781727SPaul Mackerras	cmplwi	cr5,r3,0x8003	/* 7447A */
3689b781727SPaul Mackerras	cmplwi	cr6,r3,0x7000	/* 750FX */
3699b781727SPaul Mackerras	cmplwi	cr7,r3,0x8004	/* 7448 */
3709b781727SPaul Mackerras	/* cr1 is 7400 || 7410 */
3719b781727SPaul Mackerras	cror	4*cr1+eq,4*cr1+eq,4*cr2+eq
3729b781727SPaul Mackerras	/* cr0 is 74xx */
3739b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr3+eq
3749b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr4+eq
3759b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr1+eq
3769b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr5+eq
3779b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr7+eq
3789b781727SPaul Mackerras	bne	1f
3799b781727SPaul Mackerras	/* Backup 74xx specific regs */
3809b781727SPaul Mackerras	mfspr	r4,SPRN_MSSCR0
3819b781727SPaul Mackerras	stw	r4,CS_MSSCR0(r5)
3829b781727SPaul Mackerras	mfspr	r4,SPRN_MSSSR0
3839b781727SPaul Mackerras	stw	r4,CS_MSSSR0(r5)
3849b781727SPaul Mackerras	beq	cr1,1f
3859b781727SPaul Mackerras	/* Backup 745x specific registers */
3869b781727SPaul Mackerras	mfspr	r4,SPRN_HID1
3879b781727SPaul Mackerras	stw	r4,CS_HID1(r5)
3889b781727SPaul Mackerras	mfspr	r4,SPRN_ICTRL
3899b781727SPaul Mackerras	stw	r4,CS_ICTRL(r5)
3909b781727SPaul Mackerras	mfspr	r4,SPRN_LDSTCR
3919b781727SPaul Mackerras	stw	r4,CS_LDSTCR(r5)
3929b781727SPaul Mackerras	mfspr	r4,SPRN_LDSTDB
3939b781727SPaul Mackerras	stw	r4,CS_LDSTDB(r5)
3949b781727SPaul Mackerras1:
3959b781727SPaul Mackerras	bne	cr6,1f
3969b781727SPaul Mackerras	/* Backup 750FX specific registers */
3979b781727SPaul Mackerras	mfspr	r4,SPRN_HID1
3989b781727SPaul Mackerras	stw	r4,CS_HID1(r5)
3999b781727SPaul Mackerras	/* If rev 2.x, backup HID2 */
4009b781727SPaul Mackerras	mfspr	r3,SPRN_PVR
4019b781727SPaul Mackerras	andi.	r3,r3,0xff00
4029b781727SPaul Mackerras	cmpwi	cr0,r3,0x0200
4039b781727SPaul Mackerras	bne	1f
4049b781727SPaul Mackerras	mfspr	r4,SPRN_HID2
4059b781727SPaul Mackerras	stw	r4,CS_HID2(r5)
4069b781727SPaul Mackerras1:
4079b781727SPaul Mackerras	mtcr	r7
4089b781727SPaul Mackerras	blr
4099b781727SPaul Mackerras
4109b781727SPaul Mackerras/* Called with no MMU context (typically MSR:IR/DR off) to
4119b781727SPaul Mackerras * restore CPU state as backed up by the previous
4129b781727SPaul Mackerras * function. This does not include cache setting
4139b781727SPaul Mackerras */
4149b781727SPaul Mackerras_GLOBAL(__restore_cpu_setup)
4159b781727SPaul Mackerras	/* Some CR fields are volatile, we back it up all */
4169b781727SPaul Mackerras	mfcr	r7
4179b781727SPaul Mackerras
4189b781727SPaul Mackerras	/* Get storage ptr */
4199b781727SPaul Mackerras	lis	r5,(cpu_state_storage-KERNELBASE)@h
4209b781727SPaul Mackerras	ori	r5,r5,cpu_state_storage@l
4219b781727SPaul Mackerras
4229b781727SPaul Mackerras	/* Restore HID0 */
4239b781727SPaul Mackerras	lwz	r3,CS_HID0(r5)
4249b781727SPaul Mackerras	sync
4259b781727SPaul Mackerras	isync
4269b781727SPaul Mackerras	mtspr	SPRN_HID0,r3
4279b781727SPaul Mackerras	sync
4289b781727SPaul Mackerras	isync
4299b781727SPaul Mackerras
4309b781727SPaul Mackerras	/* Now deal with CPU type dependent registers */
4319b781727SPaul Mackerras	mfspr	r3,SPRN_PVR
4329b781727SPaul Mackerras	srwi	r3,r3,16
4339b781727SPaul Mackerras	cmplwi	cr0,r3,0x8000	/* 7450 */
4349b781727SPaul Mackerras	cmplwi	cr1,r3,0x000c	/* 7400 */
4359b781727SPaul Mackerras	cmplwi	cr2,r3,0x800c	/* 7410 */
4369b781727SPaul Mackerras	cmplwi	cr3,r3,0x8001	/* 7455 */
4379b781727SPaul Mackerras	cmplwi	cr4,r3,0x8002	/* 7457 */
4389b781727SPaul Mackerras	cmplwi	cr5,r3,0x8003	/* 7447A */
4399b781727SPaul Mackerras	cmplwi	cr6,r3,0x7000	/* 750FX */
4409b781727SPaul Mackerras	cmplwi	cr7,r3,0x8004	/* 7448 */
4419b781727SPaul Mackerras	/* cr1 is 7400 || 7410 */
4429b781727SPaul Mackerras	cror	4*cr1+eq,4*cr1+eq,4*cr2+eq
4439b781727SPaul Mackerras	/* cr0 is 74xx */
4449b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr3+eq
4459b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr4+eq
4469b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr1+eq
4479b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr5+eq
4489b781727SPaul Mackerras	cror	4*cr0+eq,4*cr0+eq,4*cr7+eq
4499b781727SPaul Mackerras	bne	2f
4509b781727SPaul Mackerras	/* Restore 74xx specific regs */
4519b781727SPaul Mackerras	lwz	r4,CS_MSSCR0(r5)
4529b781727SPaul Mackerras	sync
4539b781727SPaul Mackerras	mtspr	SPRN_MSSCR0,r4
4549b781727SPaul Mackerras	sync
4559b781727SPaul Mackerras	isync
4569b781727SPaul Mackerras	lwz	r4,CS_MSSSR0(r5)
4579b781727SPaul Mackerras	sync
4589b781727SPaul Mackerras	mtspr	SPRN_MSSSR0,r4
4599b781727SPaul Mackerras	sync
4609b781727SPaul Mackerras	isync
4619b781727SPaul Mackerras	bne	cr2,1f
4629b781727SPaul Mackerras	/* Clear 7410 L2CR2 */
4639b781727SPaul Mackerras	li	r4,0
4649b781727SPaul Mackerras	mtspr	SPRN_L2CR2,r4
4659b781727SPaul Mackerras1:	beq	cr1,2f
4669b781727SPaul Mackerras	/* Restore 745x specific registers */
4679b781727SPaul Mackerras	lwz	r4,CS_HID1(r5)
4689b781727SPaul Mackerras	sync
4699b781727SPaul Mackerras	mtspr	SPRN_HID1,r4
4709b781727SPaul Mackerras	isync
4719b781727SPaul Mackerras	sync
4729b781727SPaul Mackerras	lwz	r4,CS_ICTRL(r5)
4739b781727SPaul Mackerras	sync
4749b781727SPaul Mackerras	mtspr	SPRN_ICTRL,r4
4759b781727SPaul Mackerras	isync
4769b781727SPaul Mackerras	sync
4779b781727SPaul Mackerras	lwz	r4,CS_LDSTCR(r5)
4789b781727SPaul Mackerras	sync
4799b781727SPaul Mackerras	mtspr	SPRN_LDSTCR,r4
4809b781727SPaul Mackerras	isync
4819b781727SPaul Mackerras	sync
4829b781727SPaul Mackerras	lwz	r4,CS_LDSTDB(r5)
4839b781727SPaul Mackerras	sync
4849b781727SPaul Mackerras	mtspr	SPRN_LDSTDB,r4
4859b781727SPaul Mackerras	isync
4869b781727SPaul Mackerras	sync
4879b781727SPaul Mackerras2:	bne	cr6,1f
4889b781727SPaul Mackerras	/* Restore 750FX specific registers
4899b781727SPaul Mackerras	 * that is restore HID2 on rev 2.x and PLL config & switch
4909b781727SPaul Mackerras	 * to PLL 0 on all
4919b781727SPaul Mackerras	 */
4929b781727SPaul Mackerras	/* If rev 2.x, restore HID2 with low voltage bit cleared */
4939b781727SPaul Mackerras	mfspr	r3,SPRN_PVR
4949b781727SPaul Mackerras	andi.	r3,r3,0xff00
4959b781727SPaul Mackerras	cmpwi	cr0,r3,0x0200
4969b781727SPaul Mackerras	bne	4f
4979b781727SPaul Mackerras	lwz	r4,CS_HID2(r5)
4989b781727SPaul Mackerras	rlwinm	r4,r4,0,19,17
4999b781727SPaul Mackerras	mtspr	SPRN_HID2,r4
5009b781727SPaul Mackerras	sync
5019b781727SPaul Mackerras4:
5029b781727SPaul Mackerras	lwz	r4,CS_HID1(r5)
5039b781727SPaul Mackerras	rlwinm  r5,r4,0,16,14
5049b781727SPaul Mackerras	mtspr	SPRN_HID1,r5
5059b781727SPaul Mackerras		/* Wait for PLL to stabilize */
5069b781727SPaul Mackerras	mftbl	r5
5079b781727SPaul Mackerras3:	mftbl	r6
5089b781727SPaul Mackerras	sub	r6,r6,r5
5099b781727SPaul Mackerras	cmplwi	cr0,r6,10000
5109b781727SPaul Mackerras	ble	3b
5119b781727SPaul Mackerras	/* Setup final PLL */
5129b781727SPaul Mackerras	mtspr	SPRN_HID1,r4
5139b781727SPaul Mackerras1:
5149b781727SPaul Mackerras	mtcr	r7
5159b781727SPaul Mackerras	blr
5165f32e836SChristophe Leroy_ASM_NOKPROBE_SYMBOL(__restore_cpu_setup)
517