xref: /freebsd/sys/powerpc/aim/mp_cpudep.c (revision fdafd315)
112640815SMarcel Moolenaar /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
412640815SMarcel Moolenaar  * Copyright (c) 2008 Marcel Moolenaar
512640815SMarcel Moolenaar  * All rights reserved.
612640815SMarcel Moolenaar  *
712640815SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
812640815SMarcel Moolenaar  * modification, are permitted provided that the following conditions
912640815SMarcel Moolenaar  * are met:
1012640815SMarcel Moolenaar  *
1112640815SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
1212640815SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
1312640815SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
1412640815SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
1512640815SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
1612640815SMarcel Moolenaar  *
1712640815SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1812640815SMarcel Moolenaar  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1912640815SMarcel Moolenaar  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2012640815SMarcel Moolenaar  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2112640815SMarcel Moolenaar  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2212640815SMarcel Moolenaar  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312640815SMarcel Moolenaar  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412640815SMarcel Moolenaar  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512640815SMarcel Moolenaar  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2612640815SMarcel Moolenaar  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712640815SMarcel Moolenaar  */
2812640815SMarcel Moolenaar 
2912640815SMarcel Moolenaar #include <sys/param.h>
3012640815SMarcel Moolenaar #include <sys/systm.h>
3112640815SMarcel Moolenaar #include <sys/kernel.h>
3212640815SMarcel Moolenaar #include <sys/bus.h>
3312640815SMarcel Moolenaar #include <sys/pcpu.h>
3412640815SMarcel Moolenaar #include <sys/proc.h>
35589aed00SKyle Evans #include <sys/sched.h>
3612640815SMarcel Moolenaar #include <sys/smp.h>
3712640815SMarcel Moolenaar 
3812640815SMarcel Moolenaar #include <machine/bus.h>
3912640815SMarcel Moolenaar #include <machine/cpu.h>
4012640815SMarcel Moolenaar #include <machine/hid.h>
4112640815SMarcel Moolenaar #include <machine/intr_machdep.h>
4212640815SMarcel Moolenaar #include <machine/pcb.h>
4312640815SMarcel Moolenaar #include <machine/psl.h>
4412640815SMarcel Moolenaar #include <machine/smp.h>
4512640815SMarcel Moolenaar #include <machine/spr.h>
46258dbffeSNathan Whitehorn #include <machine/trap.h>
4712640815SMarcel Moolenaar 
4812640815SMarcel Moolenaar #include <dev/ofw/openfirm.h>
4912640815SMarcel Moolenaar #include <machine/ofw_machdep.h>
5012640815SMarcel Moolenaar 
5112640815SMarcel Moolenaar void *ap_pcpu;
5212640815SMarcel Moolenaar 
53dab90f68SNathan Whitehorn static register_t bsp_state[8] __aligned(8);
54999987e5SNathan Whitehorn 
55999987e5SNathan Whitehorn static void cpudep_save_config(void *dummy);
56999987e5SNathan Whitehorn SYSINIT(cpu_save_config, SI_SUB_CPU, SI_ORDER_ANY, cpudep_save_config, NULL);
57999987e5SNathan Whitehorn 
58c3e289e1SNathan Whitehorn void
cpudep_ap_early_bootstrap(void)59c3e289e1SNathan Whitehorn cpudep_ap_early_bootstrap(void)
60c3e289e1SNathan Whitehorn {
61e5fadf2aSNathan Whitehorn #ifndef __powerpc64__
62c3e289e1SNathan Whitehorn 	register_t reg;
63e5fadf2aSNathan Whitehorn #endif
64c3e289e1SNathan Whitehorn 
65c3e289e1SNathan Whitehorn 	switch (mfpvr() >> 16) {
66c3e289e1SNathan Whitehorn 	case IBM970:
67c3e289e1SNathan Whitehorn 	case IBM970FX:
68c3e289e1SNathan Whitehorn 	case IBM970MP:
69f04019c3SJustin Hibbits 		/* Set HIOR to 0 */
70f04019c3SJustin Hibbits 		__asm __volatile("mtspr 311,%0" :: "r"(0));
71f04019c3SJustin Hibbits 		powerpc_sync();
72f04019c3SJustin Hibbits 
73c3e289e1SNathan Whitehorn 		/* Restore HID4 and HID5, which are necessary for the MMU */
74c3e289e1SNathan Whitehorn 
75e5fadf2aSNathan Whitehorn #ifdef __powerpc64__
76e5fadf2aSNathan Whitehorn 		mtspr(SPR_HID4, bsp_state[2]); powerpc_sync(); isync();
77e5fadf2aSNathan Whitehorn 		mtspr(SPR_HID5, bsp_state[3]); powerpc_sync(); isync();
78e5fadf2aSNathan Whitehorn #else
79c3e289e1SNathan Whitehorn 		__asm __volatile("ld %0, 16(%2); sync; isync;	\
80c3e289e1SNathan Whitehorn 		    mtspr %1, %0; sync; isync;"
8176cbcfdcSAndreas Tobler 		    : "=r"(reg) : "K"(SPR_HID4), "b"(bsp_state));
82c3e289e1SNathan Whitehorn 		__asm __volatile("ld %0, 24(%2); sync; isync;	\
83c3e289e1SNathan Whitehorn 		    mtspr %1, %0; sync; isync;"
8476cbcfdcSAndreas Tobler 		    : "=r"(reg) : "K"(SPR_HID5), "b"(bsp_state));
85e5fadf2aSNathan Whitehorn #endif
86c3e289e1SNathan Whitehorn 		powerpc_sync();
87c3e289e1SNathan Whitehorn 		break;
8870bb600aSWojciech Macek 	case IBMPOWER8:
8970bb600aSWojciech Macek 	case IBMPOWER8E:
90f074eff1SJustin Hibbits 	case IBMPOWER8NVL:
914f4f92c5SJustin Hibbits 	case IBMPOWER9:
92564ac415SNathan Whitehorn #ifdef __powerpc64__
93d32802f0SWojciech Macek 		if (mfmsr() & PSL_HV) {
9470bb600aSWojciech Macek 			isync();
95564ac415SNathan Whitehorn 			/*
96564ac415SNathan Whitehorn 			 * Direct interrupts to SRR instead of HSRR and
97564ac415SNathan Whitehorn 			 * reset LPCR otherwise
98564ac415SNathan Whitehorn 			 */
9970bb600aSWojciech Macek 			mtspr(SPR_LPID, 0);
10070bb600aSWojciech Macek 			isync();
10170bb600aSWojciech Macek 
102ef6da5e5SJustin Hibbits 			mtspr(SPR_LPCR, lpcr);
10370bb600aSWojciech Macek 			isync();
10417b72853SJustin Hibbits 
10517b72853SJustin Hibbits 			/*
10617b72853SJustin Hibbits 			 * Nuke FSCR, to be managed on a per-process basis
10717b72853SJustin Hibbits 			 * later.
10817b72853SJustin Hibbits 			 */
10917b72853SJustin Hibbits 			mtspr(SPR_FSCR, 0);
110d32802f0SWojciech Macek 		}
111564ac415SNathan Whitehorn #endif
11270bb600aSWojciech Macek 		break;
113c3e289e1SNathan Whitehorn 	}
11470bb600aSWojciech Macek 
11570bb600aSWojciech Macek 	__asm __volatile("mtsprg 0, %0" :: "r"(ap_pcpu));
11670bb600aSWojciech Macek 	powerpc_sync();
117c3e289e1SNathan Whitehorn }
118c3e289e1SNathan Whitehorn 
119999987e5SNathan Whitehorn uintptr_t
cpudep_ap_bootstrap(void)120999987e5SNathan Whitehorn cpudep_ap_bootstrap(void)
121999987e5SNathan Whitehorn {
122999987e5SNathan Whitehorn 	register_t msr, sp;
123999987e5SNathan Whitehorn 
12461928298SNathan Whitehorn 	msr = psl_kernset & ~PSL_EE;
125999987e5SNathan Whitehorn 	mtmsr(msr);
126999987e5SNathan Whitehorn 
127a8972989SNathan Whitehorn 	pcpup->pc_curthread = pcpup->pc_idlethread;
128a8972989SNathan Whitehorn #ifdef __powerpc64__
129a8972989SNathan Whitehorn 	__asm __volatile("mr 13,%0" :: "r"(pcpup->pc_curthread));
130a8972989SNathan Whitehorn #else
131a8972989SNathan Whitehorn 	__asm __volatile("mr 2,%0" :: "r"(pcpup->pc_curthread));
132a8972989SNathan Whitehorn #endif
133999987e5SNathan Whitehorn 	pcpup->pc_curpcb = pcpup->pc_curthread->td_pcb;
134999987e5SNathan Whitehorn 	sp = pcpup->pc_curpcb->pcb_sp;
135589aed00SKyle Evans 	schedinit_ap();
136999987e5SNathan Whitehorn 
137999987e5SNathan Whitehorn 	return (sp);
138999987e5SNathan Whitehorn }
139999987e5SNathan Whitehorn 
1406e326900SMarcel Moolenaar static register_t
mpc74xx_l2_enable(register_t l2cr_config)141ed6e65a2SNathan Whitehorn mpc74xx_l2_enable(register_t l2cr_config)
1426e326900SMarcel Moolenaar {
143ed6e65a2SNathan Whitehorn 	register_t ccr, bit;
144ed6e65a2SNathan Whitehorn 	uint16_t	vers;
145ed6e65a2SNathan Whitehorn 
146ed6e65a2SNathan Whitehorn 	vers = mfpvr() >> 16;
147ed6e65a2SNathan Whitehorn 	switch (vers) {
148ed6e65a2SNathan Whitehorn 	case MPC7400:
149ed6e65a2SNathan Whitehorn 	case MPC7410:
150ed6e65a2SNathan Whitehorn 		bit = L2CR_L2IP;
151ed6e65a2SNathan Whitehorn 		break;
152ed6e65a2SNathan Whitehorn 	default:
153ed6e65a2SNathan Whitehorn 		bit = L2CR_L2I;
154ed6e65a2SNathan Whitehorn 		break;
155ed6e65a2SNathan Whitehorn 	}
1566e326900SMarcel Moolenaar 
1576e326900SMarcel Moolenaar 	ccr = mfspr(SPR_L2CR);
1586e326900SMarcel Moolenaar 	if (ccr & L2CR_L2E)
1596e326900SMarcel Moolenaar 		return (ccr);
1606e326900SMarcel Moolenaar 
1616e326900SMarcel Moolenaar 	/* Configure L2 cache. */
1626e326900SMarcel Moolenaar 	ccr = l2cr_config & ~L2CR_L2E;
1636e326900SMarcel Moolenaar 	mtspr(SPR_L2CR, ccr | L2CR_L2I);
1646e326900SMarcel Moolenaar 	do {
1656e326900SMarcel Moolenaar 		ccr = mfspr(SPR_L2CR);
166ed6e65a2SNathan Whitehorn 	} while (ccr & bit);
1676e326900SMarcel Moolenaar 	powerpc_sync();
1686e326900SMarcel Moolenaar 	mtspr(SPR_L2CR, l2cr_config);
1696e326900SMarcel Moolenaar 	powerpc_sync();
1706e326900SMarcel Moolenaar 
1716e326900SMarcel Moolenaar 	return (l2cr_config);
1726e326900SMarcel Moolenaar }
1736e326900SMarcel Moolenaar 
1746e326900SMarcel Moolenaar static register_t
mpc745x_l3_enable(register_t l3cr_config)175999987e5SNathan Whitehorn mpc745x_l3_enable(register_t l3cr_config)
1766e326900SMarcel Moolenaar {
1776e326900SMarcel Moolenaar 	register_t ccr;
1786e326900SMarcel Moolenaar 
1796e326900SMarcel Moolenaar 	ccr = mfspr(SPR_L3CR);
1806e326900SMarcel Moolenaar 	if (ccr & L3CR_L3E)
1816e326900SMarcel Moolenaar 		return (ccr);
1826e326900SMarcel Moolenaar 
1836e326900SMarcel Moolenaar 	/* Configure L3 cache. */
1846e326900SMarcel Moolenaar 	ccr = l3cr_config & ~(L3CR_L3E | L3CR_L3I | L3CR_L3PE | L3CR_L3CLKEN);
1856e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr);
1866e326900SMarcel Moolenaar 	ccr |= 0x4000000;       /* Magic, but documented. */
1876e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr);
1886e326900SMarcel Moolenaar 	ccr |= L3CR_L3CLKEN;
1896e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr);
1906e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr | L3CR_L3I);
1916e326900SMarcel Moolenaar 	while (mfspr(SPR_L3CR) & L3CR_L3I)
1926e326900SMarcel Moolenaar 		;
1936e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr & ~L3CR_L3CLKEN);
1946e326900SMarcel Moolenaar 	powerpc_sync();
1956e326900SMarcel Moolenaar 	DELAY(100);
1966e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr);
1976e326900SMarcel Moolenaar 	powerpc_sync();
1986e326900SMarcel Moolenaar 	DELAY(100);
1996e326900SMarcel Moolenaar 	ccr |= L3CR_L3E;
2006e326900SMarcel Moolenaar 	mtspr(SPR_L3CR, ccr);
2016e326900SMarcel Moolenaar 	powerpc_sync();
2026e326900SMarcel Moolenaar 
2036e326900SMarcel Moolenaar 	return(ccr);
2046e326900SMarcel Moolenaar }
2056e326900SMarcel Moolenaar 
2066e326900SMarcel Moolenaar static register_t
mpc74xx_l1d_enable(void)207ed6e65a2SNathan Whitehorn mpc74xx_l1d_enable(void)
2086e326900SMarcel Moolenaar {
2096e326900SMarcel Moolenaar 	register_t hid;
2106e326900SMarcel Moolenaar 
2116e326900SMarcel Moolenaar 	hid = mfspr(SPR_HID0);
2126e326900SMarcel Moolenaar 	if (hid & HID0_DCE)
2136e326900SMarcel Moolenaar 		return (hid);
2146e326900SMarcel Moolenaar 
2156e326900SMarcel Moolenaar 	/* Enable L1 D-cache */
2166e326900SMarcel Moolenaar 	hid |= HID0_DCE;
2176e326900SMarcel Moolenaar 	powerpc_sync();
2186e326900SMarcel Moolenaar 	mtspr(SPR_HID0, hid | HID0_DCFI);
2196e326900SMarcel Moolenaar 	powerpc_sync();
2206e326900SMarcel Moolenaar 
2216e326900SMarcel Moolenaar 	return (hid);
2226e326900SMarcel Moolenaar }
2236e326900SMarcel Moolenaar 
2246e326900SMarcel Moolenaar static register_t
mpc74xx_l1i_enable(void)225ed6e65a2SNathan Whitehorn mpc74xx_l1i_enable(void)
2266e326900SMarcel Moolenaar {
2276e326900SMarcel Moolenaar 	register_t hid;
2286e326900SMarcel Moolenaar 
2296e326900SMarcel Moolenaar 	hid = mfspr(SPR_HID0);
2306e326900SMarcel Moolenaar 	if (hid & HID0_ICE)
2316e326900SMarcel Moolenaar 		return (hid);
2326e326900SMarcel Moolenaar 
2336e326900SMarcel Moolenaar 	/* Enable L1 I-cache */
2346e326900SMarcel Moolenaar 	hid |= HID0_ICE;
2356e326900SMarcel Moolenaar 	isync();
2366e326900SMarcel Moolenaar 	mtspr(SPR_HID0, hid | HID0_ICFI);
2376e326900SMarcel Moolenaar 	isync();
2386e326900SMarcel Moolenaar 
2396e326900SMarcel Moolenaar 	return (hid);
2406e326900SMarcel Moolenaar }
2416e326900SMarcel Moolenaar 
242999987e5SNathan Whitehorn static void
cpudep_save_config(void * dummy)243999987e5SNathan Whitehorn cpudep_save_config(void *dummy)
24412640815SMarcel Moolenaar {
245999987e5SNathan Whitehorn 	uint16_t	vers;
2466e326900SMarcel Moolenaar 
247999987e5SNathan Whitehorn 	vers = mfpvr() >> 16;
24812640815SMarcel Moolenaar 
249999987e5SNathan Whitehorn 	switch(vers) {
250999987e5SNathan Whitehorn 	case IBM970:
251999987e5SNathan Whitehorn 	case IBM970FX:
252999987e5SNathan Whitehorn 	case IBM970MP:
253c3e289e1SNathan Whitehorn 		#ifdef __powerpc64__
254c3e289e1SNathan Whitehorn 		bsp_state[0] = mfspr(SPR_HID0);
255c3e289e1SNathan Whitehorn 		bsp_state[1] = mfspr(SPR_HID1);
256c3e289e1SNathan Whitehorn 		bsp_state[2] = mfspr(SPR_HID4);
257c3e289e1SNathan Whitehorn 		bsp_state[3] = mfspr(SPR_HID5);
258c3e289e1SNathan Whitehorn 		#else
259999987e5SNathan Whitehorn 		__asm __volatile ("mfspr %0,%2; mr %1,%0; srdi %0,%0,32"
260999987e5SNathan Whitehorn 		    : "=r" (bsp_state[0]),"=r" (bsp_state[1]) : "K" (SPR_HID0));
261999987e5SNathan Whitehorn 		__asm __volatile ("mfspr %0,%2; mr %1,%0; srdi %0,%0,32"
262999987e5SNathan Whitehorn 		    : "=r" (bsp_state[2]),"=r" (bsp_state[3]) : "K" (SPR_HID1));
263999987e5SNathan Whitehorn 		__asm __volatile ("mfspr %0,%2; mr %1,%0; srdi %0,%0,32"
264999987e5SNathan Whitehorn 		    : "=r" (bsp_state[4]),"=r" (bsp_state[5]) : "K" (SPR_HID4));
265999987e5SNathan Whitehorn 		__asm __volatile ("mfspr %0,%2; mr %1,%0; srdi %0,%0,32"
266999987e5SNathan Whitehorn 		    : "=r" (bsp_state[6]),"=r" (bsp_state[7]) : "K" (SPR_HID5));
267c3e289e1SNathan Whitehorn 		#endif
268999987e5SNathan Whitehorn 
269dab90f68SNathan Whitehorn 		powerpc_sync();
270dab90f68SNathan Whitehorn 
271999987e5SNathan Whitehorn 		break;
2722971d3bbSNathan Whitehorn 	case IBMCELLBE:
273cebdaa58SNathan Whitehorn 		#ifdef NOTYET /* Causes problems if in instruction stream on 970 */
2742971d3bbSNathan Whitehorn 		if (mfmsr() & PSL_HV) {
2752971d3bbSNathan Whitehorn 			bsp_state[0] = mfspr(SPR_HID0);
2762971d3bbSNathan Whitehorn 			bsp_state[1] = mfspr(SPR_HID1);
2772971d3bbSNathan Whitehorn 			bsp_state[2] = mfspr(SPR_HID4);
2782971d3bbSNathan Whitehorn 			bsp_state[3] = mfspr(SPR_HID6);
2792971d3bbSNathan Whitehorn 
2802971d3bbSNathan Whitehorn 			bsp_state[4] = mfspr(SPR_CELL_TSCR);
2812971d3bbSNathan Whitehorn 		}
282cebdaa58SNathan Whitehorn 		#endif
2832971d3bbSNathan Whitehorn 
2842971d3bbSNathan Whitehorn 		bsp_state[5] = mfspr(SPR_CELL_TSRL);
2852971d3bbSNathan Whitehorn 
2862971d3bbSNathan Whitehorn 		break;
287999987e5SNathan Whitehorn 	case MPC7450:
288999987e5SNathan Whitehorn 	case MPC7455:
289999987e5SNathan Whitehorn 	case MPC7457:
290999987e5SNathan Whitehorn 		/* Only MPC745x CPUs have an L3 cache. */
291999987e5SNathan Whitehorn 		bsp_state[3] = mfspr(SPR_L3CR);
292999987e5SNathan Whitehorn 
293999987e5SNathan Whitehorn 		/* Fallthrough */
294999987e5SNathan Whitehorn 	case MPC7400:
295999987e5SNathan Whitehorn 	case MPC7410:
296999987e5SNathan Whitehorn 	case MPC7447A:
297999987e5SNathan Whitehorn 	case MPC7448:
298999987e5SNathan Whitehorn 		bsp_state[2] = mfspr(SPR_L2CR);
299999987e5SNathan Whitehorn 		bsp_state[1] = mfspr(SPR_HID1);
300999987e5SNathan Whitehorn 		bsp_state[0] = mfspr(SPR_HID0);
301999987e5SNathan Whitehorn 		break;
302999987e5SNathan Whitehorn 	}
303999987e5SNathan Whitehorn }
304999987e5SNathan Whitehorn 
305999987e5SNathan Whitehorn void
cpudep_ap_setup(void)306429ba161SPiotr Kubaj cpudep_ap_setup(void)
307999987e5SNathan Whitehorn {
3087e7f7b91SJohn Baldwin #ifndef __powerpc64__
309999987e5SNathan Whitehorn 	register_t	reg;
3107e7f7b91SJohn Baldwin #endif
311999987e5SNathan Whitehorn 	uint16_t	vers;
312999987e5SNathan Whitehorn 
313999987e5SNathan Whitehorn 	vers = mfpvr() >> 16;
314999987e5SNathan Whitehorn 
315999987e5SNathan Whitehorn 	switch(vers) {
316999987e5SNathan Whitehorn 	case IBM970:
317999987e5SNathan Whitehorn 	case IBM970FX:
318999987e5SNathan Whitehorn 	case IBM970MP:
319999987e5SNathan Whitehorn 		/*
320999987e5SNathan Whitehorn 		 * The 970 has strange rules about how to update HID registers.
321999987e5SNathan Whitehorn 		 * See Table 2-3, 970MP manual
322e5fadf2aSNathan Whitehorn 		 *
323e5fadf2aSNathan Whitehorn 		 * Note: HID4 and HID5 restored already in
324e5fadf2aSNathan Whitehorn 		 * cpudep_ap_early_bootstrap()
325999987e5SNathan Whitehorn 		 */
326999987e5SNathan Whitehorn 
327dab90f68SNathan Whitehorn 		__asm __volatile("mtasr %0; sync" :: "r"(0));
328e5fadf2aSNathan Whitehorn 	#ifdef __powerpc64__
329e5fadf2aSNathan Whitehorn 		__asm __volatile(" \
330e5fadf2aSNathan Whitehorn 			sync; isync;					\
331e5fadf2aSNathan Whitehorn 			mtspr	%1, %0;					\
332e5fadf2aSNathan Whitehorn 			mfspr	%0, %1;	mfspr	%0, %1;	mfspr	%0, %1;	\
333e5fadf2aSNathan Whitehorn 			mfspr	%0, %1;	mfspr	%0, %1;	mfspr	%0, %1; \
334e5fadf2aSNathan Whitehorn 			sync; isync"
335e5fadf2aSNathan Whitehorn 		    :: "r"(bsp_state[0]), "K"(SPR_HID0));
336e5fadf2aSNathan Whitehorn 		__asm __volatile("sync; isync;	\
337e5fadf2aSNathan Whitehorn 		    mtspr %1, %0; mtspr %1, %0; sync; isync"
338e5fadf2aSNathan Whitehorn 		    :: "r"(bsp_state[1]), "K"(SPR_HID1));
339e5fadf2aSNathan Whitehorn 	#else
340999987e5SNathan Whitehorn 		__asm __volatile(" \
341999987e5SNathan Whitehorn 			ld	%0,0(%2);				\
342dab90f68SNathan Whitehorn 			sync; isync;					\
343999987e5SNathan Whitehorn 			mtspr	%1, %0;					\
344999987e5SNathan Whitehorn 			mfspr	%0, %1;	mfspr	%0, %1;	mfspr	%0, %1;	\
345dab90f68SNathan Whitehorn 			mfspr	%0, %1;	mfspr	%0, %1;	mfspr	%0, %1; \
346dab90f68SNathan Whitehorn 			sync; isync"
34776cbcfdcSAndreas Tobler 		    : "=r"(reg) : "K"(SPR_HID0), "b"(bsp_state));
348dab90f68SNathan Whitehorn 		__asm __volatile("ld %0, 8(%2); sync; isync;	\
349dab90f68SNathan Whitehorn 		    mtspr %1, %0; mtspr %1, %0; sync; isync"
35076cbcfdcSAndreas Tobler 		    : "=r"(reg) : "K"(SPR_HID1), "b"(bsp_state));
351e5fadf2aSNathan Whitehorn 	#endif
352999987e5SNathan Whitehorn 
353999987e5SNathan Whitehorn 		powerpc_sync();
354999987e5SNathan Whitehorn 		break;
3552971d3bbSNathan Whitehorn 	case IBMCELLBE:
356cebdaa58SNathan Whitehorn 		#ifdef NOTYET /* Causes problems if in instruction stream on 970 */
3572971d3bbSNathan Whitehorn 		if (mfmsr() & PSL_HV) {
3582971d3bbSNathan Whitehorn 			mtspr(SPR_HID0, bsp_state[0]);
3592971d3bbSNathan Whitehorn 			mtspr(SPR_HID1, bsp_state[1]);
3602971d3bbSNathan Whitehorn 			mtspr(SPR_HID4, bsp_state[2]);
3612971d3bbSNathan Whitehorn 			mtspr(SPR_HID6, bsp_state[3]);
3622971d3bbSNathan Whitehorn 
3632971d3bbSNathan Whitehorn 			mtspr(SPR_CELL_TSCR, bsp_state[4]);
3642971d3bbSNathan Whitehorn 		}
365cebdaa58SNathan Whitehorn 		#endif
3662971d3bbSNathan Whitehorn 
3672971d3bbSNathan Whitehorn 		mtspr(SPR_CELL_TSRL, bsp_state[5]);
3682971d3bbSNathan Whitehorn 
3692971d3bbSNathan Whitehorn 		break;
370999987e5SNathan Whitehorn 	case MPC7400:
371999987e5SNathan Whitehorn 	case MPC7410:
372999987e5SNathan Whitehorn 	case MPC7447A:
373999987e5SNathan Whitehorn 	case MPC7448:
3744702d987SJustin Hibbits 	case MPC7450:
3754702d987SJustin Hibbits 	case MPC7455:
3764702d987SJustin Hibbits 	case MPC7457:
377999987e5SNathan Whitehorn 		/* XXX: Program the CPU ID into PIR */
3786e326900SMarcel Moolenaar 		__asm __volatile("mtspr 1023,%0" :: "r"(PCPU_GET(cpuid)));
3796e326900SMarcel Moolenaar 
3806e326900SMarcel Moolenaar 		powerpc_sync();
38112640815SMarcel Moolenaar 		isync();
38212640815SMarcel Moolenaar 
383999987e5SNathan Whitehorn 		mtspr(SPR_HID0, bsp_state[0]); isync();
384999987e5SNathan Whitehorn 		mtspr(SPR_HID1, bsp_state[1]); isync();
3856e326900SMarcel Moolenaar 
3864702d987SJustin Hibbits 		/* Now enable the L3 cache. */
3874702d987SJustin Hibbits 		switch (vers) {
3884702d987SJustin Hibbits 		case MPC7450:
3894702d987SJustin Hibbits 		case MPC7455:
3904702d987SJustin Hibbits 		case MPC7457:
3914702d987SJustin Hibbits 			/* Only MPC745x CPUs have an L3 cache. */
3927e7f7b91SJohn Baldwin 			mpc745x_l3_enable(bsp_state[3]);
3934702d987SJustin Hibbits 		default:
3944702d987SJustin Hibbits 			break;
3954702d987SJustin Hibbits 		}
3964702d987SJustin Hibbits 
3977e7f7b91SJohn Baldwin 		mpc74xx_l2_enable(bsp_state[2]);
3987e7f7b91SJohn Baldwin 		mpc74xx_l1d_enable();
3997e7f7b91SJohn Baldwin 		mpc74xx_l1i_enable();
40012640815SMarcel Moolenaar 
401999987e5SNathan Whitehorn 		break;
402cb74659eSNathan Whitehorn 	case IBMPOWER7:
403cb74659eSNathan Whitehorn 	case IBMPOWER7PLUS:
404cb74659eSNathan Whitehorn 	case IBMPOWER8:
405cb74659eSNathan Whitehorn 	case IBMPOWER8E:
406f074eff1SJustin Hibbits 	case IBMPOWER8NVL:
4074f4f92c5SJustin Hibbits 	case IBMPOWER9:
40850d82d6fSNathan Whitehorn #ifdef __powerpc64__
4096d13fd63SWojciech Macek 		if (mfmsr() & PSL_HV) {
410ef6da5e5SJustin Hibbits 			mtspr(SPR_LPCR, mfspr(SPR_LPCR) | lpcr |
4116d13fd63SWojciech Macek 			    LPCR_PECE_WAKESET);
4126d13fd63SWojciech Macek 			isync();
4136d13fd63SWojciech Macek 		}
41450d82d6fSNathan Whitehorn #endif
415cb74659eSNathan Whitehorn 		break;
416999987e5SNathan Whitehorn 	default:
4171dff98d9SNathan Whitehorn #ifdef __powerpc64__
4181dff98d9SNathan Whitehorn 		if (!(mfmsr() & PSL_HV)) /* Rely on HV to have set things up */
4191dff98d9SNathan Whitehorn 			break;
4201dff98d9SNathan Whitehorn #endif
421999987e5SNathan Whitehorn 		printf("WARNING: Unknown CPU type. Cache performace may be "
422999987e5SNathan Whitehorn 		    "suboptimal.\n");
423999987e5SNathan Whitehorn 		break;
424999987e5SNathan Whitehorn 	}
42512640815SMarcel Moolenaar }
426