xref: /onnv-gate/usr/src/uts/sun4u/cpu/us3_cheetah.c (revision 8906:e559381f1e2b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52414Saguzovsk  * Common Development and Distribution License (the "License").
62414Saguzovsk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
228803SJonathan.Haslam@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/systm.h>
280Sstevel@tonic-gate #include <sys/ddi.h>
290Sstevel@tonic-gate #include <sys/sysmacros.h>
300Sstevel@tonic-gate #include <sys/archsystm.h>
310Sstevel@tonic-gate #include <sys/vmsystm.h>
320Sstevel@tonic-gate #include <sys/machparam.h>
330Sstevel@tonic-gate #include <sys/machsystm.h>
340Sstevel@tonic-gate #include <sys/machthread.h>
350Sstevel@tonic-gate #include <sys/cpu.h>
360Sstevel@tonic-gate #include <sys/cmp.h>
370Sstevel@tonic-gate #include <sys/elf_SPARC.h>
380Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
390Sstevel@tonic-gate #include <vm/seg_kmem.h>
400Sstevel@tonic-gate #include <sys/cpuvar.h>
410Sstevel@tonic-gate #include <sys/cheetahregs.h>
420Sstevel@tonic-gate #include <sys/us3_module.h>
430Sstevel@tonic-gate #include <sys/async.h>
440Sstevel@tonic-gate #include <sys/cmn_err.h>
450Sstevel@tonic-gate #include <sys/debug.h>
460Sstevel@tonic-gate #include <sys/dditypes.h>
470Sstevel@tonic-gate #include <sys/prom_debug.h>
480Sstevel@tonic-gate #include <sys/prom_plat.h>
490Sstevel@tonic-gate #include <sys/cpu_module.h>
500Sstevel@tonic-gate #include <sys/sysmacros.h>
510Sstevel@tonic-gate #include <sys/intreg.h>
520Sstevel@tonic-gate #include <sys/clock.h>
530Sstevel@tonic-gate #include <sys/platform_module.h>
540Sstevel@tonic-gate #include <sys/machtrap.h>
550Sstevel@tonic-gate #include <sys/ontrap.h>
560Sstevel@tonic-gate #include <sys/panic.h>
570Sstevel@tonic-gate #include <sys/memlist.h>
580Sstevel@tonic-gate #include <sys/bootconf.h>
590Sstevel@tonic-gate #include <sys/ivintr.h>
600Sstevel@tonic-gate #include <sys/atomic.h>
610Sstevel@tonic-gate #include <sys/fm/protocol.h>
620Sstevel@tonic-gate #include <sys/fm/cpu/UltraSPARC-III.h>
630Sstevel@tonic-gate #include <vm/vm_dep.h>
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #ifdef	CHEETAHPLUS_ERRATUM_25
660Sstevel@tonic-gate #include <sys/cyclic.h>
670Sstevel@tonic-gate #endif	/* CHEETAHPLUS_ERRATUM_25 */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
702991Ssusans  * Note that 'Cheetah PRM' refers to:
712991Ssusans  *   SPARC V9 JPS1 Implementation Supplement: Sun UltraSPARC-III
722991Ssusans  */
732991Ssusans 
742991Ssusans /*
750Sstevel@tonic-gate  * Setup trap handlers.
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate void
cpu_init_trap(void)780Sstevel@tonic-gate cpu_init_trap(void)
790Sstevel@tonic-gate {
808803SJonathan.Haslam@Sun.COM 	CH_SET_TRAP(pil15_epilogue, ch_pil15_interrupt_instr);
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	CH_SET_TRAP(tt0_fecc, fecc_err_instr);
830Sstevel@tonic-gate 	CH_SET_TRAP(tt1_fecc, fecc_err_tl1_instr);
840Sstevel@tonic-gate 	CH_SET_TRAP(tt1_swtrap0, fecc_err_tl1_cont_instr);
850Sstevel@tonic-gate }
860Sstevel@tonic-gate 
870Sstevel@tonic-gate static int
getintprop(pnode_t node,char * name,int deflt)88789Sahrens getintprop(pnode_t node, char *name, int deflt)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	int	value;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	switch (prom_getproplen(node, name)) {
930Sstevel@tonic-gate 	case sizeof (int):
940Sstevel@tonic-gate 		(void) prom_getprop(node, name, (caddr_t)&value);
950Sstevel@tonic-gate 		break;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	default:
980Sstevel@tonic-gate 		value = deflt;
990Sstevel@tonic-gate 		break;
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	return (value);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * Set the magic constants of the implementation.
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate /*ARGSUSED*/
1090Sstevel@tonic-gate void
cpu_fiximp(pnode_t dnode)110789Sahrens cpu_fiximp(pnode_t dnode)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	int i, a;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	static struct {
1150Sstevel@tonic-gate 		char	*name;
1160Sstevel@tonic-gate 		int	*var;
1170Sstevel@tonic-gate 		int	defval;
1180Sstevel@tonic-gate 	} prop[] = {
1190Sstevel@tonic-gate 		"dcache-size", &dcache_size, CH_DCACHE_SIZE,
1200Sstevel@tonic-gate 		"dcache-line-size", &dcache_linesize, CH_DCACHE_LSIZE,
1210Sstevel@tonic-gate 		"icache-size", &icache_size, CH_ICACHE_SIZE,
1220Sstevel@tonic-gate 		"icache-line-size", &icache_linesize, CH_ICACHE_LSIZE,
1230Sstevel@tonic-gate 		"ecache-size", &ecache_size, CH_ECACHE_MAX_SIZE,
1240Sstevel@tonic-gate 		"ecache-line-size", &ecache_alignsize, CH_ECACHE_MAX_LSIZE,
1250Sstevel@tonic-gate 		"ecache-associativity", &ecache_associativity, CH_ECACHE_NWAY
1260Sstevel@tonic-gate 	};
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	for (i = 0; i < sizeof (prop) / sizeof (prop[0]); i++)
1290Sstevel@tonic-gate 		*prop[i].var = getintprop(dnode, prop[i].name, prop[i].defval);
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	ecache_setsize = ecache_size / ecache_associativity;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	vac_size = CH_VAC_SIZE;
1340Sstevel@tonic-gate 	vac_mask = MMU_PAGEMASK & (vac_size - 1);
1350Sstevel@tonic-gate 	i = 0; a = vac_size;
1360Sstevel@tonic-gate 	while (a >>= 1)
1370Sstevel@tonic-gate 		++i;
1380Sstevel@tonic-gate 	vac_shift = i;
1390Sstevel@tonic-gate 	shm_alignment = vac_size;
1400Sstevel@tonic-gate 	vac = 1;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * Cheetah's large page support has problems with large numbers of
1440Sstevel@tonic-gate 	 * large pages, so just disable large pages out-of-the-box.
1452991Ssusans 	 * Note that the other defaults are set in sun4u/vm/mach_vm_dep.c.
1460Sstevel@tonic-gate 	 */
1472991Ssusans 	max_uheap_lpsize = MMU_PAGESIZE;
1482991Ssusans 	max_ustack_lpsize = MMU_PAGESIZE;
1492991Ssusans 	max_privmap_lpsize = MMU_PAGESIZE;
1502991Ssusans 	max_utext_lpsize = MMU_PAGESIZE;
1512414Saguzovsk 	max_shm_lpsize = MMU_PAGESIZE;
1523764Sdp78419 	max_bootlp_tteszc = TTE8K;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate void
send_mondo_set(cpuset_t set)1560Sstevel@tonic-gate send_mondo_set(cpuset_t set)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate 	int lo, busy, nack, shipped = 0;
1590Sstevel@tonic-gate 	uint16_t i, cpuids[IDSR_BN_SETS];
1600Sstevel@tonic-gate 	uint64_t idsr, nackmask = 0, busymask, curnack, curbusy;
1610Sstevel@tonic-gate 	uint64_t starttick, endtick, tick, lasttick;
1620Sstevel@tonic-gate #if (NCPU > IDSR_BN_SETS)
1630Sstevel@tonic-gate 	int index = 0;
1640Sstevel@tonic-gate 	int ncpuids = 0;
1650Sstevel@tonic-gate #endif
1660Sstevel@tonic-gate #ifdef	CHEETAHPLUS_ERRATUM_25
1670Sstevel@tonic-gate 	int recovered = 0;
1680Sstevel@tonic-gate 	int cpuid;
1690Sstevel@tonic-gate #endif
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	ASSERT(!CPUSET_ISNULL(set));
1720Sstevel@tonic-gate 	starttick = lasttick = gettick();
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #if (NCPU <= IDSR_BN_SETS)
1750Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++)
1760Sstevel@tonic-gate 		if (CPU_IN_SET(set, i)) {
1770Sstevel@tonic-gate 			shipit(i, shipped);
1780Sstevel@tonic-gate 			nackmask |= IDSR_NACK_BIT(shipped);
1790Sstevel@tonic-gate 			cpuids[shipped++] = i;
1800Sstevel@tonic-gate 			CPUSET_DEL(set, i);
1810Sstevel@tonic-gate 			if (CPUSET_ISNULL(set))
1820Sstevel@tonic-gate 				break;
1830Sstevel@tonic-gate 		}
1840Sstevel@tonic-gate 	CPU_STATS_ADDQ(CPU, sys, xcalls, shipped);
1850Sstevel@tonic-gate #else
1860Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++)
1870Sstevel@tonic-gate 		if (CPU_IN_SET(set, i)) {
1880Sstevel@tonic-gate 			ncpuids++;
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 			/*
1910Sstevel@tonic-gate 			 * Ship only to the first (IDSR_BN_SETS) CPUs.  If we
1920Sstevel@tonic-gate 			 * find we have shipped to more than (IDSR_BN_SETS)
1930Sstevel@tonic-gate 			 * CPUs, set "index" to the highest numbered CPU in
1940Sstevel@tonic-gate 			 * the set so we can ship to other CPUs a bit later on.
1950Sstevel@tonic-gate 			 */
1960Sstevel@tonic-gate 			if (shipped < IDSR_BN_SETS) {
1970Sstevel@tonic-gate 				shipit(i, shipped);
1980Sstevel@tonic-gate 				nackmask |= IDSR_NACK_BIT(shipped);
1990Sstevel@tonic-gate 				cpuids[shipped++] = i;
2000Sstevel@tonic-gate 				CPUSET_DEL(set, i);
2010Sstevel@tonic-gate 				if (CPUSET_ISNULL(set))
2020Sstevel@tonic-gate 					break;
2030Sstevel@tonic-gate 			} else
2040Sstevel@tonic-gate 				index = (int)i;
2050Sstevel@tonic-gate 		}
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	CPU_STATS_ADDQ(CPU, sys, xcalls, ncpuids);
2080Sstevel@tonic-gate #endif
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	busymask = IDSR_NACK_TO_BUSY(nackmask);
2110Sstevel@tonic-gate 	busy = nack = 0;
2120Sstevel@tonic-gate 	endtick = starttick + xc_tick_limit;
2130Sstevel@tonic-gate 	for (;;) {
2140Sstevel@tonic-gate 		idsr = getidsr();
2150Sstevel@tonic-gate #if (NCPU <= IDSR_BN_SETS)
2160Sstevel@tonic-gate 		if (idsr == 0)
2170Sstevel@tonic-gate 			break;
2180Sstevel@tonic-gate #else
2190Sstevel@tonic-gate 		if (idsr == 0 && shipped == ncpuids)
2200Sstevel@tonic-gate 			break;
2210Sstevel@tonic-gate #endif
2220Sstevel@tonic-gate 		tick = gettick();
2230Sstevel@tonic-gate 		/*
2240Sstevel@tonic-gate 		 * If there is a big jump between the current tick
2250Sstevel@tonic-gate 		 * count and lasttick, we have probably hit a break
2260Sstevel@tonic-gate 		 * point.  Adjust endtick accordingly to avoid panic.
2270Sstevel@tonic-gate 		 */
2280Sstevel@tonic-gate 		if (tick > (lasttick + xc_tick_jump_limit))
2290Sstevel@tonic-gate 			endtick += (tick - lasttick);
2300Sstevel@tonic-gate 		lasttick = tick;
2310Sstevel@tonic-gate 		if (tick > endtick) {
2320Sstevel@tonic-gate 			if (panic_quiesce)
2330Sstevel@tonic-gate 				return;
2340Sstevel@tonic-gate #ifdef	CHEETAHPLUS_ERRATUM_25
2350Sstevel@tonic-gate 			cpuid = -1;
2360Sstevel@tonic-gate 			for (i = 0; i < IDSR_BN_SETS; i++) {
2370Sstevel@tonic-gate 				if (idsr & (IDSR_NACK_BIT(i) |
2380Sstevel@tonic-gate 				    IDSR_BUSY_BIT(i))) {
2390Sstevel@tonic-gate 					cpuid = cpuids[i];
2400Sstevel@tonic-gate 					break;
2410Sstevel@tonic-gate 				}
2420Sstevel@tonic-gate 			}
2430Sstevel@tonic-gate 			if (cheetah_sendmondo_recover && cpuid != -1 &&
2440Sstevel@tonic-gate 			    recovered == 0) {
2450Sstevel@tonic-gate 				if (mondo_recover(cpuid, i)) {
2460Sstevel@tonic-gate 					/*
2470Sstevel@tonic-gate 					 * We claimed the whole memory or
2480Sstevel@tonic-gate 					 * full scan is disabled.
2490Sstevel@tonic-gate 					 */
2500Sstevel@tonic-gate 					recovered++;
2510Sstevel@tonic-gate 				}
2520Sstevel@tonic-gate 				tick = gettick();
2530Sstevel@tonic-gate 				endtick = tick + xc_tick_limit;
2540Sstevel@tonic-gate 				lasttick = tick;
2550Sstevel@tonic-gate 				/*
2560Sstevel@tonic-gate 				 * Recheck idsr
2570Sstevel@tonic-gate 				 */
2580Sstevel@tonic-gate 				continue;
2590Sstevel@tonic-gate 			} else
2600Sstevel@tonic-gate #endif	/* CHEETAHPLUS_ERRATUM_25 */
2610Sstevel@tonic-gate 			{
2620Sstevel@tonic-gate 				cmn_err(CE_CONT, "send mondo timeout "
2630Sstevel@tonic-gate 				    "[%d NACK %d BUSY]\nIDSR 0x%"
2640Sstevel@tonic-gate 				    "" PRIx64 "  cpuids:", nack, busy, idsr);
2650Sstevel@tonic-gate 				for (i = 0; i < IDSR_BN_SETS; i++) {
2660Sstevel@tonic-gate 					if (idsr & (IDSR_NACK_BIT(i) |
2670Sstevel@tonic-gate 					    IDSR_BUSY_BIT(i))) {
2680Sstevel@tonic-gate 						cmn_err(CE_CONT, " 0x%x",
2690Sstevel@tonic-gate 						    cpuids[i]);
2700Sstevel@tonic-gate 					}
2710Sstevel@tonic-gate 				}
2720Sstevel@tonic-gate 				cmn_err(CE_CONT, "\n");
2730Sstevel@tonic-gate 				cmn_err(CE_PANIC, "send_mondo_set: timeout");
2740Sstevel@tonic-gate 			}
2750Sstevel@tonic-gate 		}
2760Sstevel@tonic-gate 		curnack = idsr & nackmask;
2770Sstevel@tonic-gate 		curbusy = idsr & busymask;
2780Sstevel@tonic-gate #if (NCPU > IDSR_BN_SETS)
2790Sstevel@tonic-gate 		if (shipped < ncpuids) {
2800Sstevel@tonic-gate 			uint64_t cpus_left;
2810Sstevel@tonic-gate 			uint16_t next = (uint16_t)index;
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 			cpus_left = ~(IDSR_NACK_TO_BUSY(curnack) | curbusy) &
2844718Smh27603 			    busymask;
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate 			if (cpus_left) {
2870Sstevel@tonic-gate 				do {
2880Sstevel@tonic-gate 					/*
2890Sstevel@tonic-gate 					 * Sequence through and ship to the
2900Sstevel@tonic-gate 					 * remainder of the CPUs in the system
2910Sstevel@tonic-gate 					 * (e.g. other than the first
2920Sstevel@tonic-gate 					 * (IDSR_BN_SETS)) in reverse order.
2930Sstevel@tonic-gate 					 */
2940Sstevel@tonic-gate 					lo = lowbit(cpus_left) - 1;
2950Sstevel@tonic-gate 					i = IDSR_BUSY_IDX(lo);
2960Sstevel@tonic-gate 					shipit(next, i);
2970Sstevel@tonic-gate 					shipped++;
2980Sstevel@tonic-gate 					cpuids[i] = next;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 					/*
3010Sstevel@tonic-gate 					 * If we've processed all the CPUs,
3020Sstevel@tonic-gate 					 * exit the loop now and save
3030Sstevel@tonic-gate 					 * instructions.
3040Sstevel@tonic-gate 					 */
3050Sstevel@tonic-gate 					if (shipped == ncpuids)
3060Sstevel@tonic-gate 						break;
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 					for ((index = ((int)next - 1));
3090Sstevel@tonic-gate 					    index >= 0; index--)
3100Sstevel@tonic-gate 						if (CPU_IN_SET(set, index)) {
3110Sstevel@tonic-gate 							next = (uint16_t)index;
3120Sstevel@tonic-gate 							break;
3130Sstevel@tonic-gate 						}
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 					cpus_left &= ~(1ull << lo);
3160Sstevel@tonic-gate 				} while (cpus_left);
3170Sstevel@tonic-gate #ifdef	CHEETAHPLUS_ERRATUM_25
3180Sstevel@tonic-gate 				/*
3190Sstevel@tonic-gate 				 * Clear recovered because we are sending to
3200Sstevel@tonic-gate 				 * a new set of targets.
3210Sstevel@tonic-gate 				 */
3220Sstevel@tonic-gate 				recovered = 0;
3230Sstevel@tonic-gate #endif
3240Sstevel@tonic-gate 				continue;
3250Sstevel@tonic-gate 			}
3260Sstevel@tonic-gate 		}
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate 		if (curbusy) {
3290Sstevel@tonic-gate 			busy++;
3300Sstevel@tonic-gate 			continue;
3310Sstevel@tonic-gate 		}
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate #ifdef SEND_MONDO_STATS
3340Sstevel@tonic-gate 		{
3350Sstevel@tonic-gate 			int n = gettick() - starttick;
3360Sstevel@tonic-gate 			if (n < 8192)
3370Sstevel@tonic-gate 				x_nack_stimes[n >> 7]++;
3380Sstevel@tonic-gate 		}
3390Sstevel@tonic-gate #endif
3400Sstevel@tonic-gate 		while (gettick() < (tick + sys_clock_mhz))
3410Sstevel@tonic-gate 			;
3420Sstevel@tonic-gate 		do {
3430Sstevel@tonic-gate 			lo = lowbit(curnack) - 1;
3440Sstevel@tonic-gate 			i = IDSR_NACK_IDX(lo);
3450Sstevel@tonic-gate 			shipit(cpuids[i], i);
3460Sstevel@tonic-gate 			curnack &= ~(1ull << lo);
3470Sstevel@tonic-gate 		} while (curnack);
3480Sstevel@tonic-gate 		nack++;
3490Sstevel@tonic-gate 		busy = 0;
3500Sstevel@tonic-gate 	}
3510Sstevel@tonic-gate #ifdef SEND_MONDO_STATS
3520Sstevel@tonic-gate 	{
3530Sstevel@tonic-gate 		int n = gettick() - starttick;
3540Sstevel@tonic-gate 		if (n < 8192)
3550Sstevel@tonic-gate 			x_set_stimes[n >> 7]++;
3560Sstevel@tonic-gate 		else
3570Sstevel@tonic-gate 			x_set_ltimes[(n >> 13) & 0xf]++;
3580Sstevel@tonic-gate 	}
3590Sstevel@tonic-gate 	x_set_cpus[shipped]++;
3600Sstevel@tonic-gate #endif
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate /*
3640Sstevel@tonic-gate  * Handles error logging for implementation specific error types.
3650Sstevel@tonic-gate  */
3660Sstevel@tonic-gate /*ARGSUSED*/
3670Sstevel@tonic-gate int
cpu_impl_async_log_err(void * flt,errorq_elem_t * eqep)3680Sstevel@tonic-gate cpu_impl_async_log_err(void *flt, errorq_elem_t *eqep)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate 	/* There aren't any error types which are specific to cheetah only */
3710Sstevel@tonic-gate 	return (CH_ASYNC_LOG_UNKNOWN);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate /*
3750Sstevel@tonic-gate  * Figure out if Ecache is direct-mapped (Cheetah or Cheetah+ with Ecache
3760Sstevel@tonic-gate  * control ECCR_ASSOC bit off or 2-way (Cheetah+ with ECCR_ASSOC on).
3770Sstevel@tonic-gate  * We need to do this on the fly because we may have mixed Cheetah+'s with
3780Sstevel@tonic-gate  * both direct and 2-way Ecaches.
3790Sstevel@tonic-gate  */
3800Sstevel@tonic-gate int
cpu_ecache_nway(void)3810Sstevel@tonic-gate cpu_ecache_nway(void)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate 	return (CH_ECACHE_NWAY);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate /*
3870Sstevel@tonic-gate  * Note that these are entered into the table: Fatal Errors (PERR, IERR,
3880Sstevel@tonic-gate  * ISAP, EMU) first, orphaned UCU/UCC, AFAR Overwrite policy, finally IVU, IVC.
3890Sstevel@tonic-gate  * Afar overwrite policy is:
3900Sstevel@tonic-gate  *   UCU,UCC > UE,EDU,WDU,CPU > CE,EDC,EMC,WDC,CPC > TO,BERR
3910Sstevel@tonic-gate  */
3920Sstevel@tonic-gate ecc_type_to_info_t ecc_type_to_info[] = {
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	/* Fatal Errors */
3950Sstevel@tonic-gate 	C_AFSR_PERR,	"PERR ",	ECC_ALL_TRAPS,	CPU_FATAL,
3960Sstevel@tonic-gate 		"PERR Fatal",
3970Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_SYSTEM2,
3980Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_PERR,
3990Sstevel@tonic-gate 	C_AFSR_IERR,	"IERR ", 	ECC_ALL_TRAPS,	CPU_FATAL,
4000Sstevel@tonic-gate 		"IERR Fatal",
4010Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_SYSTEM2,
4020Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_IERR,
4030Sstevel@tonic-gate 	C_AFSR_ISAP,	"ISAP ",	ECC_ALL_TRAPS,	CPU_FATAL,
4040Sstevel@tonic-gate 		"ISAP Fatal",
4050Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_SYSTEM1,
4060Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_ISAP,
4070Sstevel@tonic-gate 	C_AFSR_EMU,	"EMU ",		ECC_ASYNC_TRAPS, CPU_FATAL,
4080Sstevel@tonic-gate 		"EMU Fatal",
4090Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_MEMORY,
4100Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_EMU,
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 	/* Orphaned UCC/UCU Errors */
4130Sstevel@tonic-gate 	C_AFSR_UCU,	"OUCU ",	ECC_ORPH_TRAPS, CPU_ORPH,
4140Sstevel@tonic-gate 		"Orphaned UCU",
4150Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4160Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UCU,
4170Sstevel@tonic-gate 	C_AFSR_UCC,	"OUCC ",	ECC_ORPH_TRAPS, CPU_ORPH,
4180Sstevel@tonic-gate 		"Orphaned UCC",
4190Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4200Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UCC,
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 	/* UCU, UCC */
4230Sstevel@tonic-gate 	C_AFSR_UCU,	"UCU ",		ECC_F_TRAP,	CPU_UE_ECACHE,
4240Sstevel@tonic-gate 		"UCU",
4250Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4260Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UCU,
4270Sstevel@tonic-gate 	C_AFSR_UCC,	"UCC ",		ECC_F_TRAP,	CPU_CE_ECACHE,
4280Sstevel@tonic-gate 		"UCC",
4290Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4300Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UCC,
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 	/* UE, EDU:ST, EDU:BLD, WDU, CPU */
4330Sstevel@tonic-gate 	C_AFSR_UE,	"UE ",		ECC_ASYNC_TRAPS, CPU_UE,
4340Sstevel@tonic-gate 		"Uncorrectable system bus (UE)",
4350Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_MEMORY,
4360Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UE,
4370Sstevel@tonic-gate 	C_AFSR_EDU,	"EDU ",		ECC_C_TRAP,	CPU_UE_ECACHE_RETIRE,
4380Sstevel@tonic-gate 		"EDU:ST",
4390Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4400Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_EDUST,
4410Sstevel@tonic-gate 	C_AFSR_EDU,	"EDU ",		ECC_D_TRAP,	CPU_UE_ECACHE_RETIRE,
4420Sstevel@tonic-gate 		"EDU:BLD",
4430Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4440Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_EDUBL,
4450Sstevel@tonic-gate 	C_AFSR_WDU,	"WDU ",		ECC_C_TRAP,	CPU_UE_ECACHE_RETIRE,
4460Sstevel@tonic-gate 		"WDU",
4470Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4480Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_WDU,
4490Sstevel@tonic-gate 	C_AFSR_CPU,	"CPU ",		ECC_C_TRAP,	CPU_UE_ECACHE,
4500Sstevel@tonic-gate 		"CPU",
4510Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4520Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_CPU,
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	/* CE, EDC, EMC, WDC, CPC */
4550Sstevel@tonic-gate 	C_AFSR_CE,	"CE ",		ECC_C_TRAP,	CPU_CE,
4560Sstevel@tonic-gate 		"Corrected system bus (CE)",
4570Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_MEMORY,
4580Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_CE,
4590Sstevel@tonic-gate 	C_AFSR_EDC,	"EDC ",		ECC_C_TRAP,	CPU_CE_ECACHE,
4600Sstevel@tonic-gate 		"EDC",
4610Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4620Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_EDC,
4630Sstevel@tonic-gate 	C_AFSR_EMC,	"EMC ",		ECC_C_TRAP,	CPU_EMC,
4640Sstevel@tonic-gate 		"EMC",
4650Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_MEMORY,
4660Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_EMC,
4670Sstevel@tonic-gate 	C_AFSR_WDC,	"WDC ",		ECC_C_TRAP,	CPU_CE_ECACHE,
4680Sstevel@tonic-gate 		"WDC",
4690Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4700Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_WDC,
4710Sstevel@tonic-gate 	C_AFSR_CPC,	"CPC ",		ECC_C_TRAP,	CPU_CE_ECACHE,
4720Sstevel@tonic-gate 		"CPC",
4730Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_L2_DATA,
4740Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_CPC,
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate 	/* TO, BERR */
4770Sstevel@tonic-gate 	C_AFSR_TO,	"TO ",		ECC_ASYNC_TRAPS, CPU_TO,
4780Sstevel@tonic-gate 		"Timeout (TO)",
4790Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_IO,
4800Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_TO,
4810Sstevel@tonic-gate 	C_AFSR_BERR,	"BERR ",	ECC_ASYNC_TRAPS, CPU_BERR,
4820Sstevel@tonic-gate 		"Bus Error (BERR)",
4830Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_IO,
4840Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_BERR,
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 	/* IVU, IVC */
4870Sstevel@tonic-gate 	C_AFSR_IVU,	"IVU ",		ECC_C_TRAP,	CPU_IV,
4880Sstevel@tonic-gate 		"IVU",
4890Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_SYSTEM1,
4900Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_IVU,
4910Sstevel@tonic-gate 	C_AFSR_IVC,	"IVC ",		ECC_C_TRAP,	CPU_IV,
4920Sstevel@tonic-gate 		"IVC",
4930Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_SYSTEM1,
4940Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_IVC,
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate 	0,		NULL,		0,		0,
4970Sstevel@tonic-gate 		NULL,
4980Sstevel@tonic-gate 		FM_EREPORT_PAYLOAD_UNKNOWN,
4990Sstevel@tonic-gate 		FM_EREPORT_CPU_USIII_UNKNOWN,
5000Sstevel@tonic-gate };
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate  * Prioritized list of Error bits for AFAR overwrite.
5040Sstevel@tonic-gate  * See Cheetah PRM P.6.1
5050Sstevel@tonic-gate  *   Class 4:  UCC, UCU
5060Sstevel@tonic-gate  *   Class 3:  UE, EDU, EMU, WDU, CPU
5070Sstevel@tonic-gate  *   Class 2:  CE, EDC, EMC, WDC, CPC
5080Sstevel@tonic-gate  *   Class 1:  TO, BERR
5090Sstevel@tonic-gate  */
5100Sstevel@tonic-gate uint64_t afar_overwrite[] = {
5110Sstevel@tonic-gate 	C_AFSR_UCC | C_AFSR_UCU,
5120Sstevel@tonic-gate 	C_AFSR_UE | C_AFSR_EDU | C_AFSR_EMU | C_AFSR_WDU | C_AFSR_CPU,
5130Sstevel@tonic-gate 	C_AFSR_CE | C_AFSR_EDC | C_AFSR_EMC | C_AFSR_WDC | C_AFSR_CPC,
5140Sstevel@tonic-gate 	C_AFSR_TO | C_AFSR_BERR,
5150Sstevel@tonic-gate 	0
5160Sstevel@tonic-gate };
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate /*
5190Sstevel@tonic-gate  * Prioritized list of Error bits for ESYND overwrite.
5200Sstevel@tonic-gate  * See Cheetah PRM P.6.2
5210Sstevel@tonic-gate  *   Class 2:  UE, IVU, EDU, WDU, UCU, CPU
5220Sstevel@tonic-gate  *   Class 1:  CE, IVC, EDC, WDC, UCC, CPC
5230Sstevel@tonic-gate  */
5240Sstevel@tonic-gate uint64_t esynd_overwrite[] = {
5250Sstevel@tonic-gate 	C_AFSR_UE | C_AFSR_IVU | C_AFSR_EDU | C_AFSR_WDU | C_AFSR_UCU |
5260Sstevel@tonic-gate 	    C_AFSR_CPU,
5270Sstevel@tonic-gate 	C_AFSR_CE | C_AFSR_IVC | C_AFSR_EDC | C_AFSR_WDC | C_AFSR_UCC |
5280Sstevel@tonic-gate 	    C_AFSR_CPC,
5290Sstevel@tonic-gate 	0
5300Sstevel@tonic-gate };
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate /*
5330Sstevel@tonic-gate  * Prioritized list of Error bits for MSYND overwrite.
5340Sstevel@tonic-gate  * See Cheetah PRM P.6.3
5350Sstevel@tonic-gate  *   Class 2:  EMU
5360Sstevel@tonic-gate  *   Class 1:  EMC
5370Sstevel@tonic-gate  */
5380Sstevel@tonic-gate uint64_t msynd_overwrite[] = {
5390Sstevel@tonic-gate 	C_AFSR_EMU,
5400Sstevel@tonic-gate 	C_AFSR_EMC,
5410Sstevel@tonic-gate 	0
5420Sstevel@tonic-gate };
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate /*
5450Sstevel@tonic-gate  * change cpu speed bits -- new speed will be normal-speed/divisor.
5460Sstevel@tonic-gate  *
5470Sstevel@tonic-gate  * The Jalapeno memory controllers are required to drain outstanding
5480Sstevel@tonic-gate  * memory transactions within 32 JBus clocks in order to be ready
5490Sstevel@tonic-gate  * to enter Estar mode.  In some corner cases however, that time
5500Sstevel@tonic-gate  * fell short.
5510Sstevel@tonic-gate  *
5520Sstevel@tonic-gate  * A safe software solution is to force MCU to act like in Estar mode,
5530Sstevel@tonic-gate  * then delay 1us (in ppm code) prior to assert J_CHNG_L signal.
5540Sstevel@tonic-gate  * To reverse the effect, upon exiting Estar, software restores the
5550Sstevel@tonic-gate  * MCU to its original state.
5560Sstevel@tonic-gate  */
5570Sstevel@tonic-gate /* ARGSUSED1 */
5580Sstevel@tonic-gate void
cpu_change_speed(uint64_t divisor,uint64_t arg2)5590Sstevel@tonic-gate cpu_change_speed(uint64_t divisor, uint64_t arg2)
5600Sstevel@tonic-gate {
5614667Smh27603 	bus_config_eclk_t	*bceclk;
5620Sstevel@tonic-gate 	uint64_t		reg;
5634667Smh27603 	processor_info_t	*pi = &(CPU->cpu_type_info);
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate 	for (bceclk = bus_config_eclk; bceclk->divisor; bceclk++) {
5660Sstevel@tonic-gate 		if (bceclk->divisor != divisor)
5670Sstevel@tonic-gate 			continue;
5680Sstevel@tonic-gate 		reg = get_safari_config();
5690Sstevel@tonic-gate 		reg &= ~SAFARI_CONFIG_ECLK_MASK;
5700Sstevel@tonic-gate 		reg |= bceclk->mask;
5710Sstevel@tonic-gate 		set_safari_config(reg);
5720Sstevel@tonic-gate 		CPU->cpu_m.divisor = (uchar_t)divisor;
573*8906SEric.Saxe@Sun.COM 		cpu_set_curr_clock(((uint64_t)pi->pi_clock * 1000000) /
574*8906SEric.Saxe@Sun.COM 		    divisor);
5750Sstevel@tonic-gate 		return;
5760Sstevel@tonic-gate 	}
5770Sstevel@tonic-gate 	/*
5780Sstevel@tonic-gate 	 * We will reach here only if OBP and kernel don't agree on
5790Sstevel@tonic-gate 	 * the speeds supported by the CPU.
5800Sstevel@tonic-gate 	 */
5810Sstevel@tonic-gate 	cmn_err(CE_WARN, "cpu_change_speed: bad divisor %" PRIu64, divisor);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate /*
5850Sstevel@tonic-gate  * Cpu private initialization.  This includes allocating the cpu_private
5860Sstevel@tonic-gate  * data structure, initializing it, and initializing the scrubber for this
5870Sstevel@tonic-gate  * cpu.  This function calls cpu_init_ecache_scrub_dr to init the scrubber.
5880Sstevel@tonic-gate  * We use kmem_cache_create for the cheetah private data structure because
5890Sstevel@tonic-gate  * it needs to be allocated on a PAGESIZE (8192) byte boundary.
5900Sstevel@tonic-gate  */
5910Sstevel@tonic-gate void
cpu_init_private(struct cpu * cp)5920Sstevel@tonic-gate cpu_init_private(struct cpu *cp)
5930Sstevel@tonic-gate {
5940Sstevel@tonic-gate 	cheetah_private_t *chprp;
5950Sstevel@tonic-gate 	int i;
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate 	ASSERT(CPU_PRIVATE(cp) == NULL);
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate 	/* LINTED: E_TRUE_LOGICAL_EXPR */
6000Sstevel@tonic-gate 	ASSERT((offsetof(cheetah_private_t, chpr_tl1_err_data) +
6010Sstevel@tonic-gate 	    sizeof (ch_err_tl1_data_t) * CH_ERR_TL1_TLMAX) <= PAGESIZE);
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate 	/*
6040Sstevel@tonic-gate 	 * Running with a Cheetah+, Jaguar, or Panther on a Cheetah CPU
6050Sstevel@tonic-gate 	 * machine is not a supported configuration. Attempting to do so
6060Sstevel@tonic-gate 	 * may result in unpredictable failures (e.g. running Cheetah+
6070Sstevel@tonic-gate 	 * CPUs with Cheetah E$ disp flush) so don't allow it.
6080Sstevel@tonic-gate 	 *
6090Sstevel@tonic-gate 	 * This is just defensive code since this configuration mismatch
6100Sstevel@tonic-gate 	 * should have been caught prior to OS execution.
6110Sstevel@tonic-gate 	 */
6120Sstevel@tonic-gate 	if (!IS_CHEETAH(cpunodes[cp->cpu_id].implementation)) {
6130Sstevel@tonic-gate 		cmn_err(CE_PANIC, "CPU%d: UltraSPARC-III+/IV/IV+ not"
6140Sstevel@tonic-gate 		    " supported on UltraSPARC-III code\n", cp->cpu_id);
6150Sstevel@tonic-gate 	}
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate 	/*
6180Sstevel@tonic-gate 	 * If the ch_private_cache has not been created, create it.
6190Sstevel@tonic-gate 	 */
6200Sstevel@tonic-gate 	if (ch_private_cache == NULL) {
6210Sstevel@tonic-gate 		ch_private_cache = kmem_cache_create("ch_private_cache",
6220Sstevel@tonic-gate 		    sizeof (cheetah_private_t), PAGESIZE, NULL, NULL,
6230Sstevel@tonic-gate 		    NULL, NULL, static_arena, 0);
6240Sstevel@tonic-gate 	}
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	chprp = CPU_PRIVATE(cp) = kmem_cache_alloc(ch_private_cache, KM_SLEEP);
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate 	bzero(chprp, sizeof (cheetah_private_t));
6290Sstevel@tonic-gate 	chprp->chpr_fecctl0_logout.clo_data.chd_afar = LOGOUT_INVALID;
6300Sstevel@tonic-gate 	chprp->chpr_cecc_logout.clo_data.chd_afar = LOGOUT_INVALID;
6310Sstevel@tonic-gate 	chprp->chpr_async_logout.clo_data.chd_afar = LOGOUT_INVALID;
6320Sstevel@tonic-gate 	for (i = 0; i < CH_ERR_TL1_TLMAX; i++)
6330Sstevel@tonic-gate 		chprp->chpr_tl1_err_data[i].ch_err_tl1_logout.clo_data.chd_afar
6340Sstevel@tonic-gate 		    = LOGOUT_INVALID;
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	chprp->chpr_icache_size = CH_ICACHE_SIZE;
6370Sstevel@tonic-gate 	chprp->chpr_icache_linesize = CH_ICACHE_LSIZE;
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate 	cpu_init_ecache_scrub_dr(cp);
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate 	chprp->chpr_ec_set_size = cpunodes[cp->cpu_id].ecache_size /
6420Sstevel@tonic-gate 	    cpu_ecache_nway();
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	adjust_hw_copy_limits(cpunodes[cp->cpu_id].ecache_size);
6450Sstevel@tonic-gate 	ch_err_tl1_paddrs[cp->cpu_id] = va_to_pa(chprp);
6460Sstevel@tonic-gate 	ASSERT(ch_err_tl1_paddrs[cp->cpu_id] != -1);
6470Sstevel@tonic-gate }
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate /*
6500Sstevel@tonic-gate  * Clear the error state registers for this CPU.
6510Sstevel@tonic-gate  * For Cheetah, just clear the AFSR
6520Sstevel@tonic-gate  */
6530Sstevel@tonic-gate void
set_cpu_error_state(ch_cpu_errors_t * cpu_error_regs)6540Sstevel@tonic-gate set_cpu_error_state(ch_cpu_errors_t *cpu_error_regs)
6550Sstevel@tonic-gate {
6560Sstevel@tonic-gate 	set_asyncflt(cpu_error_regs->afsr & ~C_AFSR_FATAL_ERRS);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate /*
6600Sstevel@tonic-gate  * For Cheetah, the error recovery code uses an alternate flush area in the
6610Sstevel@tonic-gate  * TL>0 fast ECC handler.  ecache_tl1_flushaddr is the physical address of
6620Sstevel@tonic-gate  * this exclusive displacement flush area.
6630Sstevel@tonic-gate  */
6640Sstevel@tonic-gate uint64_t ecache_tl1_flushaddr = (uint64_t)-1; /* physaddr for E$ flushing */
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate /*
6670Sstevel@tonic-gate  * Allocate and initialize the exclusive displacement flush area.
6680Sstevel@tonic-gate  */
6690Sstevel@tonic-gate caddr_t
ecache_init_scrub_flush_area(caddr_t alloc_base)6700Sstevel@tonic-gate ecache_init_scrub_flush_area(caddr_t alloc_base)
6710Sstevel@tonic-gate {
6725648Ssetje 	unsigned size = 2 * CH_ECACHE_8M_SIZE;
6735648Ssetje 	caddr_t tmp_alloc_base = alloc_base;
6745648Ssetje 	caddr_t flush_alloc_base =
6755648Ssetje 	    (caddr_t)roundup((uintptr_t)alloc_base, size);
6765648Ssetje 	caddr_t ecache_tl1_virtaddr;
6770Sstevel@tonic-gate 
6785648Ssetje 	/*
6795648Ssetje 	 * Allocate the physical memory for the exclusive flush area
6805648Ssetje 	 *
6815648Ssetje 	 * Need to allocate an exclusive flush area that is twice the
6825648Ssetje 	 * largest supported E$ size, physically contiguous, and
6835648Ssetje 	 * aligned on twice the largest E$ size boundary.
6845648Ssetje 	 *
6855648Ssetje 	 * Memory allocated via prom_alloc is included in the "cage"
6865648Ssetje 	 * from the DR perspective and due to this, its physical
6875648Ssetje 	 * address will never change and the memory will not be
6885648Ssetje 	 * removed.
6895648Ssetje 	 *
6905648Ssetje 	 * prom_alloc takes 3 arguments: bootops, virtual address hint,
6915648Ssetje 	 * size of the area to allocate, and alignment of the area to
6925648Ssetje 	 * allocate. It returns zero if the allocation fails, or the
6935648Ssetje 	 * virtual address for a successful allocation. Memory prom_alloc'd
6945648Ssetje 	 * is physically contiguous.
6955648Ssetje 	 */
6965648Ssetje 	if ((ecache_tl1_virtaddr =
6975648Ssetje 	    prom_alloc(flush_alloc_base, size, size)) != NULL) {
6985648Ssetje 
6995648Ssetje 		tmp_alloc_base =
7005648Ssetje 		    (caddr_t)roundup((uintptr_t)(ecache_tl1_virtaddr + size),
7015648Ssetje 		    ecache_alignsize);
7025648Ssetje 
7033764Sdp78419 		/*
7045648Ssetje 		 * get the physical address of the exclusive flush area
7053764Sdp78419 		 */
7065648Ssetje 		ecache_tl1_flushaddr = va_to_pa(ecache_tl1_virtaddr);
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 	} else {
7095648Ssetje 		ecache_tl1_virtaddr = (caddr_t)-1;
7105648Ssetje 		cmn_err(CE_NOTE, "!ecache_init_scrub_flush_area failed\n");
7110Sstevel@tonic-gate 	}
7120Sstevel@tonic-gate 
7135648Ssetje 	return (tmp_alloc_base);
7140Sstevel@tonic-gate }
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate /*
7170Sstevel@tonic-gate  * Update cpu_offline_set so the scrubber knows which cpus are offline
7180Sstevel@tonic-gate  */
7190Sstevel@tonic-gate /*ARGSUSED*/
7200Sstevel@tonic-gate int
cpu_scrub_cpu_setup(cpu_setup_t what,int cpuid,void * arg)7210Sstevel@tonic-gate cpu_scrub_cpu_setup(cpu_setup_t what, int cpuid, void *arg)
7220Sstevel@tonic-gate {
7230Sstevel@tonic-gate 	switch (what) {
7240Sstevel@tonic-gate 	case CPU_ON:
7250Sstevel@tonic-gate 	case CPU_INIT:
7260Sstevel@tonic-gate 		CPUSET_DEL(cpu_offline_set, cpuid);
7270Sstevel@tonic-gate 		break;
7280Sstevel@tonic-gate 	case CPU_OFF:
7290Sstevel@tonic-gate 		CPUSET_ADD(cpu_offline_set, cpuid);
7300Sstevel@tonic-gate 		break;
7310Sstevel@tonic-gate 	default:
7320Sstevel@tonic-gate 		break;
7330Sstevel@tonic-gate 	}
7340Sstevel@tonic-gate 	return (0);
7350Sstevel@tonic-gate }
736