xref: /onnv-gate/usr/src/uts/sun4u/cpu/opl_olympus.c (revision 1888:3586ab197d6d)
11772Sjl139090 /*
21772Sjl139090  * CDDL HEADER START
31772Sjl139090  *
41772Sjl139090  * The contents of this file are subject to the terms of the
51772Sjl139090  * Common Development and Distribution License (the "License").
61772Sjl139090  * You may not use this file except in compliance with the License.
71772Sjl139090  *
81772Sjl139090  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91772Sjl139090  * or http://www.opensolaris.org/os/licensing.
101772Sjl139090  * See the License for the specific language governing permissions
111772Sjl139090  * and limitations under the License.
121772Sjl139090  *
131772Sjl139090  * When distributing Covered Code, include this CDDL HEADER in each
141772Sjl139090  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151772Sjl139090  * If applicable, add the following below this CDDL HEADER, with the
161772Sjl139090  * fields enclosed by brackets "[]" replaced with your own identifying
171772Sjl139090  * information: Portions Copyright [yyyy] [name of copyright owner]
181772Sjl139090  *
191772Sjl139090  * CDDL HEADER END
201772Sjl139090  */
211772Sjl139090 /*
221772Sjl139090  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
231772Sjl139090  * Use is subject to license terms.
241772Sjl139090  */
251772Sjl139090 
261772Sjl139090 #pragma ident	"%Z%%M%	%I%	%E% SMI"
271772Sjl139090 
281772Sjl139090 #include <sys/types.h>
291772Sjl139090 #include <sys/systm.h>
301772Sjl139090 #include <sys/ddi.h>
311772Sjl139090 #include <sys/sysmacros.h>
321772Sjl139090 #include <sys/archsystm.h>
331772Sjl139090 #include <sys/vmsystm.h>
341772Sjl139090 #include <sys/machparam.h>
351772Sjl139090 #include <sys/machsystm.h>
361772Sjl139090 #include <sys/machthread.h>
371772Sjl139090 #include <sys/cpu.h>
381772Sjl139090 #include <sys/cmp.h>
391772Sjl139090 #include <sys/elf_SPARC.h>
401772Sjl139090 #include <vm/vm_dep.h>
411772Sjl139090 #include <vm/hat_sfmmu.h>
421772Sjl139090 #include <vm/seg_kpm.h>
431772Sjl139090 #include <sys/cpuvar.h>
441772Sjl139090 #include <sys/opl_olympus_regs.h>
451772Sjl139090 #include <sys/opl_module.h>
461772Sjl139090 #include <sys/async.h>
471772Sjl139090 #include <sys/cmn_err.h>
481772Sjl139090 #include <sys/debug.h>
491772Sjl139090 #include <sys/dditypes.h>
501772Sjl139090 #include <sys/cpu_module.h>
511772Sjl139090 #include <sys/sysmacros.h>
521772Sjl139090 #include <sys/intreg.h>
531772Sjl139090 #include <sys/clock.h>
541772Sjl139090 #include <sys/platform_module.h>
551772Sjl139090 #include <sys/ontrap.h>
561772Sjl139090 #include <sys/panic.h>
571772Sjl139090 #include <sys/memlist.h>
581772Sjl139090 #include <sys/ndifm.h>
591772Sjl139090 #include <sys/ddifm.h>
601772Sjl139090 #include <sys/fm/protocol.h>
611772Sjl139090 #include <sys/fm/util.h>
621772Sjl139090 #include <sys/fm/cpu/SPARC64-VI.h>
631772Sjl139090 #include <sys/dtrace.h>
641772Sjl139090 #include <sys/watchpoint.h>
651772Sjl139090 #include <sys/promif.h>
661772Sjl139090 
671772Sjl139090 /*
681772Sjl139090  * Internal functions.
691772Sjl139090  */
701772Sjl139090 static int cpu_sync_log_err(void *flt);
711772Sjl139090 static void cpu_payload_add_aflt(struct async_flt *, nvlist_t *, nvlist_t *);
721772Sjl139090 static void opl_cpu_sync_error(struct regs *, ulong_t, ulong_t, uint_t, uint_t);
731772Sjl139090 static int  cpu_flt_in_memory(opl_async_flt_t *, uint64_t);
741772Sjl139090 
751772Sjl139090 /*
761772Sjl139090  * Error counters resetting interval.
771772Sjl139090  */
781772Sjl139090 static int opl_async_check_interval = 60;		/* 1 min */
791772Sjl139090 
801772Sjl139090 /*
811772Sjl139090  * Maximum number of contexts for Olympus-C.
821772Sjl139090  */
831772Sjl139090 #define	MAX_NCTXS	(1 << 13)
841772Sjl139090 
851772Sjl139090 /* Will be set !NULL for SPARC64-VI and derivatives. */
861772Sjl139090 static uchar_t ctx_pgsz_arr[MAX_NCTXS];
871772Sjl139090 uchar_t *ctx_pgsz_array = ctx_pgsz_arr;
881772Sjl139090 
891772Sjl139090 /*
901772Sjl139090  * PA[22:0] represent Displacement in Jupiter
911772Sjl139090  * configuration space.
921772Sjl139090  */
931772Sjl139090 uint_t	root_phys_addr_lo_mask = 0x7fffffu;
941772Sjl139090 
951772Sjl139090 /*
961772Sjl139090  * set in /etc/system to control logging of user BERR/TO's
971772Sjl139090  */
981772Sjl139090 int cpu_berr_to_verbose = 0;
991772Sjl139090 
1001772Sjl139090 static int min_ecache_size;
1011772Sjl139090 static uint_t priv_hcl_1;
1021772Sjl139090 static uint_t priv_hcl_2;
1031772Sjl139090 static uint_t priv_hcl_4;
1041772Sjl139090 static uint_t priv_hcl_8;
1051772Sjl139090 
1061772Sjl139090 /*
1071772Sjl139090  * Olympus error log
1081772Sjl139090  */
1091772Sjl139090 static opl_errlog_t	*opl_err_log;
1101772Sjl139090 
1111772Sjl139090 /*
1121772Sjl139090  * UE is classified into four classes (MEM, CHANNEL, CPU, PATH).
1131772Sjl139090  * No any other ecc_type_info insertion is allowed in between the following
1141772Sjl139090  * four UE classess.
1151772Sjl139090  */
1161772Sjl139090 ecc_type_to_info_t ecc_type_to_info[] = {
1171772Sjl139090 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
1181772Sjl139090 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
1191772Sjl139090 	FM_EREPORT_CPU_UE_MEM,
1201772Sjl139090 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
1211772Sjl139090 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
1221772Sjl139090 	FM_EREPORT_CPU_UE_CHANNEL,
1231772Sjl139090 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
1241772Sjl139090 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
1251772Sjl139090 	FM_EREPORT_CPU_UE_CPU,
1261772Sjl139090 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
1271772Sjl139090 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
1281772Sjl139090 	FM_EREPORT_CPU_UE_PATH,
1291772Sjl139090 	SFSR_BERR, "BERR ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
1301772Sjl139090 	"Bus Error",  FM_EREPORT_PAYLOAD_SYNC,
1311772Sjl139090 	FM_EREPORT_CPU_BERR,
1321772Sjl139090 	SFSR_TO, "TO ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
1331772Sjl139090 	"Bus Timeout",  FM_EREPORT_PAYLOAD_SYNC,
1341772Sjl139090 	FM_EREPORT_CPU_BTO,
1351772Sjl139090 	SFSR_TLB_MUL, "TLB_MUL ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
1361772Sjl139090 	"TLB MultiHit",  FM_EREPORT_PAYLOAD_SYNC,
1371772Sjl139090 	FM_EREPORT_CPU_MTLB,
1381772Sjl139090 	SFSR_TLB_PRT, "TLB_PRT ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
1391772Sjl139090 	"TLB Parity",  FM_EREPORT_PAYLOAD_SYNC,
1401772Sjl139090 	FM_EREPORT_CPU_TLBP,
1411772Sjl139090 
1421772Sjl139090 	UGESR_IAUG_CRE, "IAUG_CRE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1431772Sjl139090 	"IAUG CRE",  FM_EREPORT_PAYLOAD_URGENT,
1441772Sjl139090 	FM_EREPORT_CPU_CRE,
1451772Sjl139090 	UGESR_IAUG_TSBCTXT, "IAUG_TSBCTXT",
1461772Sjl139090 	OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1471772Sjl139090 	"IAUG TSBCTXT",  FM_EREPORT_PAYLOAD_URGENT,
1481772Sjl139090 	FM_EREPORT_CPU_TSBCTX,
1491772Sjl139090 	UGESR_IUG_TSBP, "IUG_TSBP", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1501772Sjl139090 	"IUG TSBP",  FM_EREPORT_PAYLOAD_URGENT,
1511772Sjl139090 	FM_EREPORT_CPU_TSBP,
1521772Sjl139090 	UGESR_IUG_PSTATE, "IUG_PSTATE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1531772Sjl139090 	"IUG PSTATE",  FM_EREPORT_PAYLOAD_URGENT,
1541772Sjl139090 	FM_EREPORT_CPU_PSTATE,
1551772Sjl139090 	UGESR_IUG_TSTATE, "IUG_TSTATE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1561772Sjl139090 	"IUG TSTATE",  FM_EREPORT_PAYLOAD_URGENT,
1571772Sjl139090 	FM_EREPORT_CPU_TSTATE,
1581772Sjl139090 	UGESR_IUG_F, "IUG_F", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1591772Sjl139090 	"IUG FREG",  FM_EREPORT_PAYLOAD_URGENT,
1601772Sjl139090 	FM_EREPORT_CPU_IUG_F,
1611772Sjl139090 	UGESR_IUG_R, "IUG_R", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1621772Sjl139090 	"IUG RREG",  FM_EREPORT_PAYLOAD_URGENT,
1631772Sjl139090 	FM_EREPORT_CPU_IUG_R,
1641772Sjl139090 	UGESR_AUG_SDC, "AUG_SDC", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1651772Sjl139090 	"AUG SDC",  FM_EREPORT_PAYLOAD_URGENT,
1661772Sjl139090 	FM_EREPORT_CPU_SDC,
1671772Sjl139090 	UGESR_IUG_WDT, "IUG_WDT", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1681772Sjl139090 	"IUG WDT",  FM_EREPORT_PAYLOAD_URGENT,
1691772Sjl139090 	FM_EREPORT_CPU_WDT,
1701772Sjl139090 	UGESR_IUG_DTLB, "IUG_DTLB", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1711772Sjl139090 	"IUG DTLB",  FM_EREPORT_PAYLOAD_URGENT,
1721772Sjl139090 	FM_EREPORT_CPU_DTLB,
1731772Sjl139090 	UGESR_IUG_ITLB, "IUG_ITLB", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1741772Sjl139090 	"IUG ITLB",  FM_EREPORT_PAYLOAD_URGENT,
1751772Sjl139090 	FM_EREPORT_CPU_ITLB,
1761772Sjl139090 	UGESR_IUG_COREERR, "IUG_COREERR",
1771772Sjl139090 	OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1781772Sjl139090 	"IUG COREERR",  FM_EREPORT_PAYLOAD_URGENT,
1791772Sjl139090 	FM_EREPORT_CPU_CORE,
1801772Sjl139090 	UGESR_MULTI_DAE, "MULTI_DAE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1811772Sjl139090 	"MULTI DAE",  FM_EREPORT_PAYLOAD_URGENT,
1821772Sjl139090 	FM_EREPORT_CPU_DAE,
1831772Sjl139090 	UGESR_MULTI_IAE, "MULTI_IAE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1841772Sjl139090 	"MULTI IAE",  FM_EREPORT_PAYLOAD_URGENT,
1851772Sjl139090 	FM_EREPORT_CPU_IAE,
1861772Sjl139090 	UGESR_MULTI_UGE, "MULTI_UGE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
1871772Sjl139090 	"MULTI UGE",  FM_EREPORT_PAYLOAD_URGENT,
1881772Sjl139090 	FM_EREPORT_CPU_UGE,
1891772Sjl139090 	0,		NULL,		0,		0,
1901772Sjl139090 	NULL,  0,	   0,
1911772Sjl139090 };
1921772Sjl139090 
1931772Sjl139090 int (*p2get_mem_info)(int synd_code, uint64_t paddr,
1941772Sjl139090 		uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
1951772Sjl139090 		int *segsp, int *banksp, int *mcidp);
1961772Sjl139090 
1971772Sjl139090 
1981772Sjl139090 /*
1991772Sjl139090  * Setup trap handlers for 0xA, 0x32, 0x40 trap types.
2001772Sjl139090  */
2011772Sjl139090 void
2021772Sjl139090 cpu_init_trap(void)
2031772Sjl139090 {
2041772Sjl139090 	OPL_SET_TRAP(tt0_iae, opl_serr_instr);
2051772Sjl139090 	OPL_SET_TRAP(tt1_iae, opl_serr_instr);
2061772Sjl139090 	OPL_SET_TRAP(tt0_dae, opl_serr_instr);
2071772Sjl139090 	OPL_SET_TRAP(tt1_dae, opl_serr_instr);
2081772Sjl139090 	OPL_SET_TRAP(tt0_asdat, opl_ugerr_instr);
2091772Sjl139090 	OPL_SET_TRAP(tt1_asdat, opl_ugerr_instr);
2101772Sjl139090 }
2111772Sjl139090 
2121772Sjl139090 static int
2131772Sjl139090 getintprop(pnode_t node, char *name, int deflt)
2141772Sjl139090 {
2151772Sjl139090 	int	value;
2161772Sjl139090 
2171772Sjl139090 	switch (prom_getproplen(node, name)) {
2181772Sjl139090 	case sizeof (int):
2191772Sjl139090 		(void) prom_getprop(node, name, (caddr_t)&value);
2201772Sjl139090 		break;
2211772Sjl139090 
2221772Sjl139090 	default:
2231772Sjl139090 		value = deflt;
2241772Sjl139090 		break;
2251772Sjl139090 	}
2261772Sjl139090 
2271772Sjl139090 	return (value);
2281772Sjl139090 }
2291772Sjl139090 
2301772Sjl139090 /*
2311772Sjl139090  * Set the magic constants of the implementation.
2321772Sjl139090  */
2331772Sjl139090 /*ARGSUSED*/
2341772Sjl139090 void
2351772Sjl139090 cpu_fiximp(pnode_t dnode)
2361772Sjl139090 {
2371772Sjl139090 	int i, a;
2381772Sjl139090 	extern int vac_size, vac_shift;
2391772Sjl139090 	extern uint_t vac_mask;
2401772Sjl139090 
2411772Sjl139090 	static struct {
2421772Sjl139090 		char	*name;
2431772Sjl139090 		int	*var;
2441772Sjl139090 		int	defval;
2451772Sjl139090 	} prop[] = {
2461772Sjl139090 		"l1-dcache-size", &dcache_size, OPL_DCACHE_SIZE,
2471772Sjl139090 		"l1-dcache-line-size", &dcache_linesize, OPL_DCACHE_LSIZE,
2481772Sjl139090 		"l1-icache-size", &icache_size, OPL_ICACHE_SIZE,
2491772Sjl139090 		"l1-icache-line-size", &icache_linesize, OPL_ICACHE_LSIZE,
2501772Sjl139090 		"l2-cache-size", &ecache_size, OPL_ECACHE_SIZE,
2511772Sjl139090 		"l2-cache-line-size", &ecache_alignsize, OPL_ECACHE_LSIZE,
2521772Sjl139090 		"l2-cache-associativity", &ecache_associativity, OPL_ECACHE_NWAY
2531772Sjl139090 	};
2541772Sjl139090 
2551772Sjl139090 	for (i = 0; i < sizeof (prop) / sizeof (prop[0]); i++)
2561772Sjl139090 		*prop[i].var = getintprop(dnode, prop[i].name, prop[i].defval);
2571772Sjl139090 
2581772Sjl139090 	ecache_setsize = ecache_size / ecache_associativity;
2591772Sjl139090 
2601772Sjl139090 	vac_size = OPL_VAC_SIZE;
2611772Sjl139090 	vac_mask = MMU_PAGEMASK & (vac_size - 1);
2621772Sjl139090 	i = 0; a = vac_size;
2631772Sjl139090 	while (a >>= 1)
2641772Sjl139090 		++i;
2651772Sjl139090 	vac_shift = i;
2661772Sjl139090 	shm_alignment = vac_size;
2671772Sjl139090 	vac = 1;
2681772Sjl139090 }
2691772Sjl139090 
2701772Sjl139090 void
2711772Sjl139090 send_mondo_set(cpuset_t set)
2721772Sjl139090 {
2731772Sjl139090 	int lo, busy, nack, shipped = 0;
2741772Sjl139090 	uint16_t i, cpuids[IDSR_BN_SETS];
2751772Sjl139090 	uint64_t idsr, nackmask = 0, busymask, curnack, curbusy;
2761772Sjl139090 	uint64_t starttick, endtick, tick, lasttick;
2771772Sjl139090 #if (NCPU > IDSR_BN_SETS)
2781772Sjl139090 	int index = 0;
2791772Sjl139090 	int ncpuids = 0;
2801772Sjl139090 #endif
281*1888Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
2821772Sjl139090 	int bn_sets = IDSR_BN_SETS;
2831772Sjl139090 	uint64_t ver;
2841772Sjl139090 
2851772Sjl139090 	ASSERT(NCPU > bn_sets);
2861772Sjl139090 #endif
2871772Sjl139090 
2881772Sjl139090 	ASSERT(!CPUSET_ISNULL(set));
2891772Sjl139090 	starttick = lasttick = gettick();
2901772Sjl139090 
291*1888Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
2921772Sjl139090 	ver = ultra_getver();
2931772Sjl139090 	if (((ULTRA_VER_IMPL(ver)) == OLYMPUS_C_IMPL) &&
2941772Sjl139090 		((OLYMPUS_REV_MASK(ver)) == OLYMPUS_C_A))
2951772Sjl139090 		bn_sets = 1;
2961772Sjl139090 #endif
2971772Sjl139090 
2981772Sjl139090 #if (NCPU <= IDSR_BN_SETS)
2991772Sjl139090 	for (i = 0; i < NCPU; i++)
3001772Sjl139090 		if (CPU_IN_SET(set, i)) {
3011772Sjl139090 			shipit(i, shipped);
3021772Sjl139090 			nackmask |= IDSR_NACK_BIT(shipped);
3031772Sjl139090 			cpuids[shipped++] = i;
3041772Sjl139090 			CPUSET_DEL(set, i);
3051772Sjl139090 			if (CPUSET_ISNULL(set))
3061772Sjl139090 				break;
3071772Sjl139090 		}
3081772Sjl139090 	CPU_STATS_ADDQ(CPU, sys, xcalls, shipped);
3091772Sjl139090 #else
3101772Sjl139090 	for (i = 0; i < NCPU; i++)
3111772Sjl139090 		if (CPU_IN_SET(set, i)) {
3121772Sjl139090 			ncpuids++;
3131772Sjl139090 
3141772Sjl139090 			/*
3151772Sjl139090 			 * Ship only to the first (IDSR_BN_SETS) CPUs.  If we
3161772Sjl139090 			 * find we have shipped to more than (IDSR_BN_SETS)
3171772Sjl139090 			 * CPUs, set "index" to the highest numbered CPU in
3181772Sjl139090 			 * the set so we can ship to other CPUs a bit later on.
3191772Sjl139090 			 */
320*1888Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
3211772Sjl139090 			if (shipped < bn_sets) {
3221772Sjl139090 #else
3231772Sjl139090 			if (shipped < IDSR_BN_SETS) {
3241772Sjl139090 #endif
3251772Sjl139090 				shipit(i, shipped);
3261772Sjl139090 				nackmask |= IDSR_NACK_BIT(shipped);
3271772Sjl139090 				cpuids[shipped++] = i;
3281772Sjl139090 				CPUSET_DEL(set, i);
3291772Sjl139090 				if (CPUSET_ISNULL(set))
3301772Sjl139090 					break;
3311772Sjl139090 			} else
3321772Sjl139090 				index = (int)i;
3331772Sjl139090 		}
3341772Sjl139090 
3351772Sjl139090 	CPU_STATS_ADDQ(CPU, sys, xcalls, ncpuids);
3361772Sjl139090 #endif
3371772Sjl139090 
3381772Sjl139090 	busymask = IDSR_NACK_TO_BUSY(nackmask);
3391772Sjl139090 	busy = nack = 0;
3401772Sjl139090 	endtick = starttick + xc_tick_limit;
3411772Sjl139090 	for (;;) {
3421772Sjl139090 		idsr = getidsr();
3431772Sjl139090 #if (NCPU <= IDSR_BN_SETS)
3441772Sjl139090 		if (idsr == 0)
3451772Sjl139090 			break;
3461772Sjl139090 #else
3471772Sjl139090 		if (idsr == 0 && shipped == ncpuids)
3481772Sjl139090 			break;
3491772Sjl139090 #endif
3501772Sjl139090 		tick = gettick();
3511772Sjl139090 		/*
3521772Sjl139090 		 * If there is a big jump between the current tick
3531772Sjl139090 		 * count and lasttick, we have probably hit a break
3541772Sjl139090 		 * point.  Adjust endtick accordingly to avoid panic.
3551772Sjl139090 		 */
3561772Sjl139090 		if (tick > (lasttick + xc_tick_jump_limit))
3571772Sjl139090 			endtick += (tick - lasttick);
3581772Sjl139090 		lasttick = tick;
3591772Sjl139090 		if (tick > endtick) {
3601772Sjl139090 			if (panic_quiesce)
3611772Sjl139090 				return;
3621772Sjl139090 			cmn_err(CE_CONT, "send mondo timeout "
3631772Sjl139090 				"[%d NACK %d BUSY]\nIDSR 0x%"
3641772Sjl139090 				"" PRIx64 "  cpuids:", nack, busy, idsr);
365*1888Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
3661772Sjl139090 			for (i = 0; i < bn_sets; i++) {
3671772Sjl139090 #else
3681772Sjl139090 			for (i = 0; i < IDSR_BN_SETS; i++) {
3691772Sjl139090 #endif
3701772Sjl139090 				if (idsr & (IDSR_NACK_BIT(i) |
3711772Sjl139090 				    IDSR_BUSY_BIT(i))) {
3721772Sjl139090 					cmn_err(CE_CONT, " 0x%x",
3731772Sjl139090 						cpuids[i]);
3741772Sjl139090 				}
3751772Sjl139090 			}
3761772Sjl139090 			cmn_err(CE_CONT, "\n");
3771772Sjl139090 			cmn_err(CE_PANIC, "send_mondo_set: timeout");
3781772Sjl139090 		}
3791772Sjl139090 		curnack = idsr & nackmask;
3801772Sjl139090 		curbusy = idsr & busymask;
381*1888Shyw 
382*1888Shyw #ifdef OLYMPUS_C_REV_B_ERRATA_XCALL
383*1888Shyw 		/*
384*1888Shyw 		 * Only proceed to send more xcalls if all the
385*1888Shyw 		 * cpus in the previous IDSR_BN_SETS were completed.
386*1888Shyw 		 */
387*1888Shyw 		if (curbusy) {
388*1888Shyw 			busy++;
389*1888Shyw 			continue;
390*1888Shyw 		}
391*1888Shyw #endif /* OLYMPUS_C_REV_B_ERRATA_XCALL */
392*1888Shyw 
3931772Sjl139090 #if (NCPU > IDSR_BN_SETS)
3941772Sjl139090 		if (shipped < ncpuids) {
3951772Sjl139090 			uint64_t cpus_left;
3961772Sjl139090 			uint16_t next = (uint16_t)index;
3971772Sjl139090 
3981772Sjl139090 			cpus_left = ~(IDSR_NACK_TO_BUSY(curnack) | curbusy) &
3991772Sjl139090 			    busymask;
4001772Sjl139090 
4011772Sjl139090 			if (cpus_left) {
4021772Sjl139090 				do {
4031772Sjl139090 					/*
4041772Sjl139090 					 * Sequence through and ship to the
4051772Sjl139090 					 * remainder of the CPUs in the system
4061772Sjl139090 					 * (e.g. other than the first
4071772Sjl139090 					 * (IDSR_BN_SETS)) in reverse order.
4081772Sjl139090 					 */
4091772Sjl139090 					lo = lowbit(cpus_left) - 1;
4101772Sjl139090 					i = IDSR_BUSY_IDX(lo);
4111772Sjl139090 					shipit(next, i);
4121772Sjl139090 					shipped++;
4131772Sjl139090 					cpuids[i] = next;
4141772Sjl139090 
4151772Sjl139090 					/*
4161772Sjl139090 					 * If we've processed all the CPUs,
4171772Sjl139090 					 * exit the loop now and save
4181772Sjl139090 					 * instructions.
4191772Sjl139090 					 */
4201772Sjl139090 					if (shipped == ncpuids)
4211772Sjl139090 						break;
4221772Sjl139090 
4231772Sjl139090 					for ((index = ((int)next - 1));
4241772Sjl139090 						index >= 0; index--)
4251772Sjl139090 						if (CPU_IN_SET(set, index)) {
4261772Sjl139090 							next = (uint16_t)index;
4271772Sjl139090 							break;
4281772Sjl139090 						}
4291772Sjl139090 
4301772Sjl139090 					cpus_left &= ~(1ull << lo);
4311772Sjl139090 				} while (cpus_left);
4321772Sjl139090 				continue;
4331772Sjl139090 			}
4341772Sjl139090 		}
4351772Sjl139090 #endif
436*1888Shyw #ifndef	OLYMPUS_C_REV_B_ERRATA_XCALL
4371772Sjl139090 		if (curbusy) {
4381772Sjl139090 			busy++;
4391772Sjl139090 			continue;
4401772Sjl139090 		}
441*1888Shyw #endif	/* OLYMPUS_C_REV_B_ERRATA_XCALL */
4421772Sjl139090 #ifdef SEND_MONDO_STATS
4431772Sjl139090 		{
4441772Sjl139090 			int n = gettick() - starttick;
4451772Sjl139090 			if (n < 8192)
4461772Sjl139090 				x_nack_stimes[n >> 7]++;
4471772Sjl139090 		}
4481772Sjl139090 #endif
4491772Sjl139090 		while (gettick() < (tick + sys_clock_mhz))
4501772Sjl139090 			;
4511772Sjl139090 		do {
4521772Sjl139090 			lo = lowbit(curnack) - 1;
4531772Sjl139090 			i = IDSR_NACK_IDX(lo);
4541772Sjl139090 			shipit(cpuids[i], i);
4551772Sjl139090 			curnack &= ~(1ull << lo);
4561772Sjl139090 		} while (curnack);
4571772Sjl139090 		nack++;
4581772Sjl139090 		busy = 0;
4591772Sjl139090 	}
4601772Sjl139090 #ifdef SEND_MONDO_STATS
4611772Sjl139090 	{
4621772Sjl139090 		int n = gettick() - starttick;
4631772Sjl139090 		if (n < 8192)
4641772Sjl139090 			x_set_stimes[n >> 7]++;
4651772Sjl139090 		else
4661772Sjl139090 			x_set_ltimes[(n >> 13) & 0xf]++;
4671772Sjl139090 	}
4681772Sjl139090 	x_set_cpus[shipped]++;
4691772Sjl139090 #endif
4701772Sjl139090 }
4711772Sjl139090 
4721772Sjl139090 /*
4731772Sjl139090  * Cpu private initialization.
4741772Sjl139090  */
4751772Sjl139090 void
4761772Sjl139090 cpu_init_private(struct cpu *cp)
4771772Sjl139090 {
4781772Sjl139090 	if (!(IS_OLYMPUS_C(cpunodes[cp->cpu_id].implementation))) {
4791772Sjl139090 		cmn_err(CE_PANIC, "CPU%d Impl %d: Only SPARC64-VI is supported",
4801772Sjl139090 			cp->cpu_id, cpunodes[cp->cpu_id].implementation);
4811772Sjl139090 	}
4821772Sjl139090 
4831772Sjl139090 	adjust_hw_copy_limits(cpunodes[cp->cpu_id].ecache_size);
4841772Sjl139090 }
4851772Sjl139090 
4861772Sjl139090 void
4871772Sjl139090 cpu_setup(void)
4881772Sjl139090 {
4891772Sjl139090 	extern int at_flags;
4901772Sjl139090 	extern int disable_delay_tlb_flush, delay_tlb_flush;
4911772Sjl139090 	extern int cpc_has_overflow_intr;
4921772Sjl139090 	extern int disable_text_largepages;
4931772Sjl139090 	extern int use_text_pgsz4m;
4941772Sjl139090 	uint64_t cpu0_log;
4951772Sjl139090 	extern	 uint64_t opl_cpu0_err_log;
4961772Sjl139090 
4971772Sjl139090 	/*
4981772Sjl139090 	 * Initialize Error log Scratch register for error handling.
4991772Sjl139090 	 */
5001772Sjl139090 
5011772Sjl139090 	cpu0_log = va_to_pa(&opl_cpu0_err_log);
5021772Sjl139090 	opl_error_setup(cpu0_log);
5031772Sjl139090 
5041772Sjl139090 	/*
5051772Sjl139090 	 * Enable MMU translating multiple page sizes for
5061772Sjl139090 	 * sITLB and sDTLB.
5071772Sjl139090 	 */
5081772Sjl139090 	opl_mpg_enable();
5091772Sjl139090 
5101772Sjl139090 	/*
5111772Sjl139090 	 * Setup chip-specific trap handlers.
5121772Sjl139090 	 */
5131772Sjl139090 	cpu_init_trap();
5141772Sjl139090 
5151772Sjl139090 	cache |= (CACHE_VAC | CACHE_PTAG | CACHE_IOCOHERENT);
5161772Sjl139090 
5171772Sjl139090 	at_flags = EF_SPARC_32PLUS | EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3;
5181772Sjl139090 
5191772Sjl139090 	/*
5201772Sjl139090 	 * Use the maximum number of contexts available for SPARC64-VI
5211772Sjl139090 	 * unless it has been tuned for debugging.
5221772Sjl139090 	 * We are checking against 0 here since this value can be patched
5231772Sjl139090 	 * while booting.  It can not be patched via /etc/system since it
5241772Sjl139090 	 * will be patched too late and thus cause the system to panic.
5251772Sjl139090 	 */
5261772Sjl139090 	if (nctxs == 0)
5271772Sjl139090 		nctxs = MAX_NCTXS;
5281772Sjl139090 
5291772Sjl139090 	/*
5301772Sjl139090 	 * Due to the number of entries in the fully-associative tlb
5311772Sjl139090 	 * this may have to be tuned lower than in spitfire.
5321772Sjl139090 	 */
5331772Sjl139090 	pp_slots = MIN(8, MAXPP_SLOTS);
5341772Sjl139090 
5351772Sjl139090 	/*
5361772Sjl139090 	 * Block stores do not invalidate all pages of the d$, pagecopy
5371772Sjl139090 	 * et. al. need virtual translations with virtual coloring taken
5381772Sjl139090 	 * into consideration.  prefetch/ldd will pollute the d$ on the
5391772Sjl139090 	 * load side.
5401772Sjl139090 	 */
5411772Sjl139090 	pp_consistent_coloring = PPAGE_STORE_VCOLORING | PPAGE_LOADS_POLLUTE;
5421772Sjl139090 
5431772Sjl139090 	if (use_page_coloring) {
5441772Sjl139090 		do_pg_coloring = 1;
5451772Sjl139090 		if (use_virtual_coloring)
5461772Sjl139090 			do_virtual_coloring = 1;
5471772Sjl139090 	}
5481772Sjl139090 
5491772Sjl139090 	isa_list =
5501772Sjl139090 	    "sparcv9+vis2 sparcv9+vis sparcv9 "
5511772Sjl139090 	    "sparcv8plus+vis2 sparcv8plus+vis sparcv8plus "
5521772Sjl139090 	    "sparcv8 sparcv8-fsmuld sparcv7 sparc";
5531772Sjl139090 
5541772Sjl139090 	cpu_hwcap_flags = AV_SPARC_VIS | AV_SPARC_VIS2;
5551772Sjl139090 
5561772Sjl139090 	/*
5571772Sjl139090 	 * On SPARC64-VI, there's no hole in the virtual address space
5581772Sjl139090 	 */
5591772Sjl139090 	hole_start = hole_end = 0;
5601772Sjl139090 
5611772Sjl139090 	/*
5621772Sjl139090 	 * The kpm mapping window.
5631772Sjl139090 	 * kpm_size:
5641772Sjl139090 	 *	The size of a single kpm range.
5651772Sjl139090 	 *	The overall size will be: kpm_size * vac_colors.
5661772Sjl139090 	 * kpm_vbase:
5671772Sjl139090 	 *	The virtual start address of the kpm range within the kernel
5681772Sjl139090 	 *	virtual address space. kpm_vbase has to be kpm_size aligned.
5691772Sjl139090 	 */
5701772Sjl139090 	kpm_size = (size_t)(128ull * 1024 * 1024 * 1024 * 1024); /* 128TB */
5711772Sjl139090 	kpm_size_shift = 47;
5721772Sjl139090 	kpm_vbase = (caddr_t)0x8000000000000000ull; /* 8EB */
5731772Sjl139090 	kpm_smallpages = 1;
5741772Sjl139090 
5751772Sjl139090 	/*
5761772Sjl139090 	 * The traptrace code uses either %tick or %stick for
5771772Sjl139090 	 * timestamping.  We have %stick so we can use it.
5781772Sjl139090 	 */
5791772Sjl139090 	traptrace_use_stick = 1;
5801772Sjl139090 
5811772Sjl139090 	/*
5821772Sjl139090 	 * SPARC64-VI has a performance counter overflow interrupt
5831772Sjl139090 	 */
5841772Sjl139090 	cpc_has_overflow_intr = 1;
5851772Sjl139090 
5861772Sjl139090 	/*
5871772Sjl139090 	 * Use SPARC64-VI flush-all support
5881772Sjl139090 	 */
5891772Sjl139090 	if (!disable_delay_tlb_flush)
5901772Sjl139090 		delay_tlb_flush = 1;
5911772Sjl139090 
5921772Sjl139090 	/*
5931772Sjl139090 	 * Declare that this architecture/cpu combination does not support
5941772Sjl139090 	 * fpRAS.
5951772Sjl139090 	 */
5961772Sjl139090 	fpras_implemented = 0;
5971772Sjl139090 
5981772Sjl139090 	/*
5991772Sjl139090 	 * Enable 4M pages to be used for mapping user text by default.  Don't
6001772Sjl139090 	 * use large pages for initialized data segments since we may not know
6011772Sjl139090 	 * at exec() time what should be the preferred large page size for DTLB
6021772Sjl139090 	 * programming.
6031772Sjl139090 	 */
6041772Sjl139090 	use_text_pgsz4m = 1;
6051772Sjl139090 	disable_text_largepages = (1 << TTE64K) | (1 << TTE512K) |
6061772Sjl139090 	    (1 << TTE32M) | (1 << TTE256M);
6071772Sjl139090 }
6081772Sjl139090 
6091772Sjl139090 /*
6101772Sjl139090  * Called by setcpudelay
6111772Sjl139090  */
6121772Sjl139090 void
6131772Sjl139090 cpu_init_tick_freq(void)
6141772Sjl139090 {
6151772Sjl139090 	/*
6161772Sjl139090 	 * For SPARC64-VI we want to use the system clock rate as
6171772Sjl139090 	 * the basis for low level timing, due to support of mixed
6181772Sjl139090 	 * speed CPUs and power managment.
6191772Sjl139090 	 */
6201772Sjl139090 	if (system_clock_freq == 0)
6211772Sjl139090 		cmn_err(CE_PANIC, "setcpudelay: invalid system_clock_freq");
6221772Sjl139090 
6231772Sjl139090 	sys_tick_freq = system_clock_freq;
6241772Sjl139090 }
6251772Sjl139090 
6261772Sjl139090 #ifdef SEND_MONDO_STATS
6271772Sjl139090 uint32_t x_one_stimes[64];
6281772Sjl139090 uint32_t x_one_ltimes[16];
6291772Sjl139090 uint32_t x_set_stimes[64];
6301772Sjl139090 uint32_t x_set_ltimes[16];
6311772Sjl139090 uint32_t x_set_cpus[NCPU];
6321772Sjl139090 uint32_t x_nack_stimes[64];
6331772Sjl139090 #endif
6341772Sjl139090 
6351772Sjl139090 /*
6361772Sjl139090  * Note: A version of this function is used by the debugger via the KDI,
6371772Sjl139090  * and must be kept in sync with this version.  Any changes made to this
6381772Sjl139090  * function to support new chips or to accomodate errata must also be included
6391772Sjl139090  * in the KDI-specific version.  See us3_kdi.c.
6401772Sjl139090  */
6411772Sjl139090 void
6421772Sjl139090 send_one_mondo(int cpuid)
6431772Sjl139090 {
6441772Sjl139090 	int busy, nack;
6451772Sjl139090 	uint64_t idsr, starttick, endtick, tick, lasttick;
6461772Sjl139090 	uint64_t busymask;
6471772Sjl139090 
6481772Sjl139090 	CPU_STATS_ADDQ(CPU, sys, xcalls, 1);
6491772Sjl139090 	starttick = lasttick = gettick();
6501772Sjl139090 	shipit(cpuid, 0);
6511772Sjl139090 	endtick = starttick + xc_tick_limit;
6521772Sjl139090 	busy = nack = 0;
6531772Sjl139090 	busymask = IDSR_BUSY;
6541772Sjl139090 	for (;;) {
6551772Sjl139090 		idsr = getidsr();
6561772Sjl139090 		if (idsr == 0)
6571772Sjl139090 			break;
6581772Sjl139090 
6591772Sjl139090 		tick = gettick();
6601772Sjl139090 		/*
6611772Sjl139090 		 * If there is a big jump between the current tick
6621772Sjl139090 		 * count and lasttick, we have probably hit a break
6631772Sjl139090 		 * point.  Adjust endtick accordingly to avoid panic.
6641772Sjl139090 		 */
6651772Sjl139090 		if (tick > (lasttick + xc_tick_jump_limit))
6661772Sjl139090 			endtick += (tick - lasttick);
6671772Sjl139090 		lasttick = tick;
6681772Sjl139090 		if (tick > endtick) {
6691772Sjl139090 			if (panic_quiesce)
6701772Sjl139090 				return;
6711772Sjl139090 			cmn_err(CE_PANIC, "send mondo timeout "
6721772Sjl139090 				"(target 0x%x) [%d NACK %d BUSY]",
6731772Sjl139090 					cpuid, nack, busy);
6741772Sjl139090 		}
6751772Sjl139090 
6761772Sjl139090 		if (idsr & busymask) {
6771772Sjl139090 			busy++;
6781772Sjl139090 			continue;
6791772Sjl139090 		}
6801772Sjl139090 		drv_usecwait(1);
6811772Sjl139090 		shipit(cpuid, 0);
6821772Sjl139090 		nack++;
6831772Sjl139090 		busy = 0;
6841772Sjl139090 	}
6851772Sjl139090 #ifdef SEND_MONDO_STATS
6861772Sjl139090 	{
6871772Sjl139090 		int n = gettick() - starttick;
6881772Sjl139090 		if (n < 8192)
6891772Sjl139090 			x_one_stimes[n >> 7]++;
6901772Sjl139090 		else
6911772Sjl139090 			x_one_ltimes[(n >> 13) & 0xf]++;
6921772Sjl139090 	}
6931772Sjl139090 #endif
6941772Sjl139090 }
6951772Sjl139090 
6961772Sjl139090 /*
6971772Sjl139090  * init_mmu_page_sizes is set to one after the bootup time initialization
6981772Sjl139090  * via mmu_init_mmu_page_sizes, to indicate that mmu_page_sizes has a
6991772Sjl139090  * valid value.
7001772Sjl139090  *
7011772Sjl139090  * mmu_disable_ism_large_pages and mmu_disable_large_pages are the mmu-specific
7021772Sjl139090  * versions of disable_ism_large_pages and disable_large_pages, and feed back
7031772Sjl139090  * into those two hat variables at hat initialization time.
7041772Sjl139090  *
7051772Sjl139090  */
7061772Sjl139090 int init_mmu_page_sizes = 0;
7071772Sjl139090 static int mmu_disable_ism_large_pages = ((1 << TTE64K) |
7081772Sjl139090 	(1 << TTE512K) | (1 << TTE256M));
7091772Sjl139090 static int mmu_disable_large_pages = 0;
7101772Sjl139090 
7111772Sjl139090 /*
7121772Sjl139090  * Re-initialize mmu_page_sizes and friends, for SPARC64-VI mmu support.
7131772Sjl139090  * Called during very early bootup from check_cpus_set().
7141772Sjl139090  * Can be called to verify that mmu_page_sizes are set up correctly.
7151772Sjl139090  *
7161772Sjl139090  * Set Olympus defaults. We do not use the function parameter.
7171772Sjl139090  */
7181772Sjl139090 /*ARGSUSED*/
7191772Sjl139090 int
7201772Sjl139090 mmu_init_mmu_page_sizes(int32_t not_used)
7211772Sjl139090 {
7221772Sjl139090 	if (!init_mmu_page_sizes) {
7231772Sjl139090 		mmu_page_sizes = MMU_PAGE_SIZES;
7241772Sjl139090 		mmu_hashcnt = MAX_HASHCNT;
7251772Sjl139090 		mmu_ism_pagesize = MMU_PAGESIZE32M;
7261772Sjl139090 		mmu_exported_pagesize_mask = (1 << TTE8K) |
7271772Sjl139090 		    (1 << TTE64K) | (1 << TTE512K) | (1 << TTE4M) |
7281772Sjl139090 		    (1 << TTE32M) | (1 << TTE256M);
7291772Sjl139090 		init_mmu_page_sizes = 1;
7301772Sjl139090 		return (0);
7311772Sjl139090 	}
7321772Sjl139090 	return (1);
7331772Sjl139090 }
7341772Sjl139090 
7351772Sjl139090 /* SPARC64-VI worst case DTLB parameters */
7361772Sjl139090 #ifndef	LOCKED_DTLB_ENTRIES
7371772Sjl139090 #define	LOCKED_DTLB_ENTRIES	5	/* 2 user TSBs, 2 nucleus, + OBP */
7381772Sjl139090 #endif
7391772Sjl139090 #define	TOTAL_DTLB_ENTRIES	32
7401772Sjl139090 #define	AVAIL_32M_ENTRIES	0
7411772Sjl139090 #define	AVAIL_256M_ENTRIES	0
7421772Sjl139090 #define	AVAIL_DTLB_ENTRIES	(TOTAL_DTLB_ENTRIES - LOCKED_DTLB_ENTRIES)
7431772Sjl139090 static uint64_t ttecnt_threshold[MMU_PAGE_SIZES] = {
7441772Sjl139090 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES,
7451772Sjl139090 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES,
7461772Sjl139090 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES};
7471772Sjl139090 
7481772Sjl139090 size_t
7491772Sjl139090 mmu_map_pgsz(size_t pgsize)
7501772Sjl139090 {
7511772Sjl139090 	struct proc *p = curproc;
7521772Sjl139090 	struct as *as = p->p_as;
7531772Sjl139090 	struct hat *hat = as->a_hat;
7541772Sjl139090 	uint_t pgsz0, pgsz1;
7551772Sjl139090 	size_t size0, size1;
7561772Sjl139090 
7571772Sjl139090 	ASSERT(mmu_page_sizes == max_mmu_page_sizes);
7581772Sjl139090 	pgsz0 = hat->sfmmu_pgsz[0];
7591772Sjl139090 	pgsz1 = hat->sfmmu_pgsz[1];
7601772Sjl139090 	size0 = hw_page_array[pgsz0].hp_size;
7611772Sjl139090 	size1 = hw_page_array[pgsz1].hp_size;
7621772Sjl139090 	/* Allow use of a larger pagesize if neither TLB is reprogrammed. */
7631772Sjl139090 	if ((pgsz0 == TTE8K) && (pgsz1 == TTE8K)) {
7641772Sjl139090 		return (pgsize);
7651772Sjl139090 	/* Allow use of requested pagesize if TLB is reprogrammed to it. */
7661772Sjl139090 	} else if ((pgsize == size0) || (pgsize == size1)) {
7671772Sjl139090 		return (pgsize);
7681772Sjl139090 	/* Use larger reprogrammed TLB size if pgsize is atleast that big. */
7691772Sjl139090 	} else if (pgsz1 > pgsz0) {
7701772Sjl139090 		if (pgsize >= size1)
7711772Sjl139090 			return (size1);
7721772Sjl139090 	/* Use smaller reprogrammed TLB size if pgsize is atleast that big. */
7731772Sjl139090 	} else {
7741772Sjl139090 		if (pgsize >= size0)
7751772Sjl139090 			return (size0);
7761772Sjl139090 	}
7771772Sjl139090 	return (pgsize);
7781772Sjl139090 }
7791772Sjl139090 
7801772Sjl139090 /*
7811772Sjl139090  * The function returns the mmu-specific values for the
7821772Sjl139090  * hat's disable_large_pages and disable_ism_large_pages variables.
7831772Sjl139090  */
7841772Sjl139090 int
7851772Sjl139090 mmu_large_pages_disabled(uint_t flag)
7861772Sjl139090 {
7871772Sjl139090 	int pages_disable = 0;
7881772Sjl139090 
7891772Sjl139090 	if (flag == HAT_LOAD) {
7901772Sjl139090 		pages_disable =  mmu_disable_large_pages;
7911772Sjl139090 	} else if (flag == HAT_LOAD_SHARE) {
7921772Sjl139090 		pages_disable = mmu_disable_ism_large_pages;
7931772Sjl139090 	}
7941772Sjl139090 	return (pages_disable);
7951772Sjl139090 }
7961772Sjl139090 
7971772Sjl139090 /*
7981772Sjl139090  * mmu_init_large_pages is called with the desired ism_pagesize parameter.
7991772Sjl139090  * It may be called from set_platform_defaults, if some value other than 32M
8001772Sjl139090  * is desired.  mmu_ism_pagesize is the tunable.  If it has a bad value,
8011772Sjl139090  * then only warn, since it would be bad form to panic due to a user typo.
8021772Sjl139090  *
8031772Sjl139090  * The function re-initializes the mmu_disable_ism_large_pages variable.
8041772Sjl139090  */
8051772Sjl139090 void
8061772Sjl139090 mmu_init_large_pages(size_t ism_pagesize)
8071772Sjl139090 {
8081772Sjl139090 	switch (ism_pagesize) {
8091772Sjl139090 	case MMU_PAGESIZE4M:
8101772Sjl139090 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
8111772Sjl139090 		    (1 << TTE512K) | (1 << TTE32M) | (1 << TTE256M));
8121772Sjl139090 		break;
8131772Sjl139090 	case MMU_PAGESIZE32M:
8141772Sjl139090 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
8151772Sjl139090 		    (1 << TTE512K) | (1 << TTE256M));
8161772Sjl139090 		break;
8171772Sjl139090 	case MMU_PAGESIZE256M:
8181772Sjl139090 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
8191772Sjl139090 		    (1 << TTE512K) | (1 << TTE32M));
8201772Sjl139090 		break;
8211772Sjl139090 	default:
8221772Sjl139090 		cmn_err(CE_WARN, "Unrecognized mmu_ism_pagesize value 0x%lx",
8231772Sjl139090 		    ism_pagesize);
8241772Sjl139090 		break;
8251772Sjl139090 	}
8261772Sjl139090 }
8271772Sjl139090 
8281772Sjl139090 /*ARGSUSED*/
8291772Sjl139090 uint_t
8301772Sjl139090 mmu_preferred_pgsz(struct hat *hat, caddr_t addr, size_t len)
8311772Sjl139090 {
8321772Sjl139090 	sfmmu_t *sfmmup = (sfmmu_t *)hat;
8331772Sjl139090 	uint_t pgsz0, pgsz1;
8341772Sjl139090 	uint_t szc, maxszc = mmu_page_sizes - 1;
8351772Sjl139090 	size_t pgsz;
8361772Sjl139090 	extern int disable_large_pages;
8371772Sjl139090 
8381772Sjl139090 	pgsz0 = (uint_t)sfmmup->sfmmu_pgsz[0];
8391772Sjl139090 	pgsz1 = (uint_t)sfmmup->sfmmu_pgsz[1];
8401772Sjl139090 
8411772Sjl139090 	/*
8421772Sjl139090 	 * If either of the TLBs are reprogrammed, choose
8431772Sjl139090 	 * the largest mapping size as the preferred size,
8441772Sjl139090 	 * if it fits the size and alignment constraints.
8451772Sjl139090 	 * Else return the largest mapping size that fits,
8461772Sjl139090 	 * if neither TLB is reprogrammed.
8471772Sjl139090 	 */
8481772Sjl139090 	if (pgsz0 > TTE8K || pgsz1 > TTE8K) {
8491772Sjl139090 		if (pgsz1 > pgsz0) {	/* First try pgsz1 */
8501772Sjl139090 			pgsz = hw_page_array[pgsz1].hp_size;
8511772Sjl139090 			if ((len >= pgsz) && IS_P2ALIGNED(addr, pgsz))
8521772Sjl139090 				return (pgsz1);
8531772Sjl139090 		}
8541772Sjl139090 		if (pgsz0 > TTE8K) {	/* Then try pgsz0, if !TTE8K */
8551772Sjl139090 			pgsz = hw_page_array[pgsz0].hp_size;
8561772Sjl139090 			if ((len >= pgsz) && IS_P2ALIGNED(addr, pgsz))
8571772Sjl139090 				return (pgsz0);
8581772Sjl139090 		}
8591772Sjl139090 	} else { /* Otherwise pick best fit if neither TLB is reprogrammed. */
8601772Sjl139090 		for (szc = maxszc; szc > TTE8K; szc--) {
8611772Sjl139090 			if (disable_large_pages & (1 << szc))
8621772Sjl139090 				continue;
8631772Sjl139090 
8641772Sjl139090 			pgsz = hw_page_array[szc].hp_size;
8651772Sjl139090 			if ((len >= pgsz) && IS_P2ALIGNED(addr, pgsz))
8661772Sjl139090 				return (szc);
8671772Sjl139090 		}
8681772Sjl139090 	}
8691772Sjl139090 	return (TTE8K);
8701772Sjl139090 }
8711772Sjl139090 
8721772Sjl139090 /*
8731772Sjl139090  * Function to reprogram the TLBs when page sizes used
8741772Sjl139090  * by a process change significantly.
8751772Sjl139090  */
8761772Sjl139090 void
8771772Sjl139090 mmu_setup_page_sizes(struct hat *hat, uint64_t *ttecnt)
8781772Sjl139090 {
8791772Sjl139090 	extern int page_szc(size_t);
8801772Sjl139090 	uint8_t pgsz0, pgsz1;
8811772Sjl139090 
8821772Sjl139090 	/*
8831772Sjl139090 	 * Don't program 2nd dtlb for kernel and ism hat
8841772Sjl139090 	 */
8851772Sjl139090 	if (hat->sfmmu_ismhat || hat == ksfmmup)
8861772Sjl139090 		return;
8871772Sjl139090 
8881772Sjl139090 	/*
8891772Sjl139090 	 * hat->sfmmu_pgsz[] is an array whose elements
8901772Sjl139090 	 * contain a sorted order of page sizes.  Element
8911772Sjl139090 	 * 0 is the most commonly used page size, followed
8921772Sjl139090 	 * by element 1, and so on.
8931772Sjl139090 	 *
8941772Sjl139090 	 * ttecnt[] is an array of per-page-size page counts
8951772Sjl139090 	 * mapped into the process.
8961772Sjl139090 	 *
8971772Sjl139090 	 * If the HAT's choice for page sizes is unsuitable,
8981772Sjl139090 	 * we can override it here.  The new values written
8991772Sjl139090 	 * to the array will be handed back to us later to
9001772Sjl139090 	 * do the actual programming of the TLB hardware.
9011772Sjl139090 	 *
9021772Sjl139090 	 */
9031772Sjl139090 	pgsz0 = (uint8_t)MIN(hat->sfmmu_pgsz[0], hat->sfmmu_pgsz[1]);
9041772Sjl139090 	pgsz1 = (uint8_t)MAX(hat->sfmmu_pgsz[0], hat->sfmmu_pgsz[1]);
9051772Sjl139090 
9061772Sjl139090 	/*
9071772Sjl139090 	 * This implements PAGESIZE programming of the sTLB
9081772Sjl139090 	 * if large TTE counts don't exceed the thresholds.
9091772Sjl139090 	 */
9101772Sjl139090 	if (ttecnt[pgsz0] < ttecnt_threshold[pgsz0])
9111772Sjl139090 		pgsz0 = page_szc(MMU_PAGESIZE);
9121772Sjl139090 	if (ttecnt[pgsz1] < ttecnt_threshold[pgsz1])
9131772Sjl139090 		pgsz1 = page_szc(MMU_PAGESIZE);
9141772Sjl139090 	hat->sfmmu_pgsz[0] = pgsz0;
9151772Sjl139090 	hat->sfmmu_pgsz[1] = pgsz1;
9161772Sjl139090 	/* otherwise, accept what the HAT chose for us */
9171772Sjl139090 }
9181772Sjl139090 
9191772Sjl139090 /*
9201772Sjl139090  * The HAT calls this function when an MMU context is allocated so that we
9211772Sjl139090  * can reprogram the large TLBs appropriately for the new process using
9221772Sjl139090  * the context.
9231772Sjl139090  *
9241772Sjl139090  * The caller must hold the HAT lock.
9251772Sjl139090  */
9261772Sjl139090 void
9271772Sjl139090 mmu_set_ctx_page_sizes(struct hat *hat)
9281772Sjl139090 {
9291772Sjl139090 	uint8_t pgsz0, pgsz1;
9301772Sjl139090 	uint8_t new_cext;
9311772Sjl139090 
9321772Sjl139090 	ASSERT(sfmmu_hat_lock_held(hat));
9331772Sjl139090 	/*
9341772Sjl139090 	 * Don't program 2nd dtlb for kernel and ism hat
9351772Sjl139090 	 */
9361772Sjl139090 	if (hat->sfmmu_ismhat || hat == ksfmmup)
9371772Sjl139090 		return;
9381772Sjl139090 
9391772Sjl139090 	/*
9401772Sjl139090 	 * If supported, reprogram the TLBs to a larger pagesize.
9411772Sjl139090 	 */
9421772Sjl139090 	pgsz0 = hat->sfmmu_pgsz[0];
9431772Sjl139090 	pgsz1 = hat->sfmmu_pgsz[1];
9441772Sjl139090 	ASSERT(pgsz0 < mmu_page_sizes);
9451772Sjl139090 	ASSERT(pgsz1 < mmu_page_sizes);
9461772Sjl139090 	new_cext = TAGACCEXT_MKSZPAIR(pgsz1, pgsz0);
9471772Sjl139090 	if (hat->sfmmu_cext != new_cext) {
9481772Sjl139090 		hat->sfmmu_cext = new_cext;
9491772Sjl139090 	}
9501772Sjl139090 	ctx_pgsz_array[hat->sfmmu_cnum] = hat->sfmmu_cext;
9511772Sjl139090 	/*
9521772Sjl139090 	 * sfmmu_setctx_sec() will take care of the
9531772Sjl139090 	 * rest of the dirty work for us.
9541772Sjl139090 	 */
9551772Sjl139090 }
9561772Sjl139090 
9571772Sjl139090 /*
9581772Sjl139090  * Return processor specific async error structure
9591772Sjl139090  * size used.
9601772Sjl139090  */
9611772Sjl139090 int
9621772Sjl139090 cpu_aflt_size(void)
9631772Sjl139090 {
9641772Sjl139090 	return (sizeof (opl_async_flt_t));
9651772Sjl139090 }
9661772Sjl139090 
9671772Sjl139090 /*
9681772Sjl139090  * The cpu_sync_log_err() function is called via the [uc]e_drain() function to
9691772Sjl139090  * post-process CPU events that are dequeued.  As such, it can be invoked
9701772Sjl139090  * from softint context, from AST processing in the trap() flow, or from the
9711772Sjl139090  * panic flow.  We decode the CPU-specific data, and take appropriate actions.
9721772Sjl139090  * Historically this entry point was used to log the actual cmn_err(9F) text;
9731772Sjl139090  * now with FMA it is used to prepare 'flt' to be converted into an ereport.
9741772Sjl139090  * With FMA this function now also returns a flag which indicates to the
9751772Sjl139090  * caller whether the ereport should be posted (1) or suppressed (0).
9761772Sjl139090  */
9771772Sjl139090 /*ARGSUSED*/
9781772Sjl139090 static int
9791772Sjl139090 cpu_sync_log_err(void *flt)
9801772Sjl139090 {
9811772Sjl139090 	opl_async_flt_t *opl_flt = (opl_async_flt_t *)flt;
9821772Sjl139090 	struct async_flt *aflt = (struct async_flt *)flt;
9831772Sjl139090 
9841772Sjl139090 	/*
9851772Sjl139090 	 * No extra processing of urgent error events.
9861772Sjl139090 	 * Always generate ereports for these events.
9871772Sjl139090 	 */
9881772Sjl139090 	if (aflt->flt_status == OPL_ECC_URGENT_TRAP)
9891772Sjl139090 		return (1);
9901772Sjl139090 
9911772Sjl139090 	/*
9921772Sjl139090 	 * Additional processing for synchronous errors.
9931772Sjl139090 	 */
9941772Sjl139090 	switch (opl_flt->flt_type) {
9951772Sjl139090 	case OPL_CPU_INV_SFSR:
9961772Sjl139090 		return (1);
9971772Sjl139090 
9981772Sjl139090 	case OPL_CPU_SYNC_UE:
9991772Sjl139090 		/*
10001772Sjl139090 		 * The validity: SFSR_MK_UE bit has been checked
10011772Sjl139090 		 * in opl_cpu_sync_error()
10021772Sjl139090 		 * No more check is required.
10031772Sjl139090 		 *
10041772Sjl139090 		 * opl_flt->flt_eid_mod and flt_eid_sid have been set by H/W,
10051772Sjl139090 		 * and they have been retrieved in cpu_queue_events()
10061772Sjl139090 		 */
10071772Sjl139090 
10081772Sjl139090 		if (opl_flt->flt_eid_mod == OPL_ERRID_MEM) {
10091772Sjl139090 			ASSERT(aflt->flt_in_memory);
10101772Sjl139090 			/*
10111772Sjl139090 			 * We want to skip logging only if ALL the following
10121772Sjl139090 			 * conditions are true:
10131772Sjl139090 			 *
10141772Sjl139090 			 *	1. We are not panicing already.
10151772Sjl139090 			 *	2. The error is a memory error.
10161772Sjl139090 			 *	3. There is only one error.
10171772Sjl139090 			 *	4. The error is on a retired page.
10181772Sjl139090 			 *	5. The error occurred under on_trap
10191772Sjl139090 			 *	protection AFLT_PROT_EC
10201772Sjl139090 			 */
10211772Sjl139090 			if (!panicstr && aflt->flt_prot == AFLT_PROT_EC &&
10221772Sjl139090 			    page_retire_check(aflt->flt_addr, NULL) == 0) {
10231772Sjl139090 				/*
10241772Sjl139090 				 * Do not log an error from
10251772Sjl139090 				 * the retired page
10261772Sjl139090 				 */
10271772Sjl139090 				softcall(ecc_page_zero, (void *)aflt->flt_addr);
10281772Sjl139090 				return (0);
10291772Sjl139090 			}
10301772Sjl139090 			if (!panicstr)
10311772Sjl139090 				cpu_page_retire(opl_flt);
10321772Sjl139090 		}
10331772Sjl139090 		return (1);
10341772Sjl139090 
10351772Sjl139090 	case OPL_CPU_SYNC_OTHERS:
10361772Sjl139090 		/*
10371772Sjl139090 		 * For the following error cases, the processor HW does
10381772Sjl139090 		 * not set the flt_eid_mod/flt_eid_sid. Instead, SW will attempt
10391772Sjl139090 		 * to assign appropriate values here to reflect what we
10401772Sjl139090 		 * think is the most likely cause of the problem w.r.t to
10411772Sjl139090 		 * the particular error event.  For Buserr and timeout
10421772Sjl139090 		 * error event, we will assign OPL_ERRID_CHANNEL as the
10431772Sjl139090 		 * most likely reason.  For TLB parity or multiple hit
10441772Sjl139090 		 * error events, we will assign the reason as
10451772Sjl139090 		 * OPL_ERRID_CPU (cpu related problem) and set the
10461772Sjl139090 		 * flt_eid_sid to point to the cpuid.
10471772Sjl139090 		 */
10481772Sjl139090 
10491772Sjl139090 		if (opl_flt->flt_bit & (SFSR_BERR|SFSR_TO)) {
10501772Sjl139090 			/*
10511772Sjl139090 			 * flt_eid_sid will not be used for this case.
10521772Sjl139090 			 */
10531772Sjl139090 			opl_flt->flt_eid_mod = OPL_ERRID_CHANNEL;
10541772Sjl139090 		}
10551772Sjl139090 		if (opl_flt->flt_bit & (SFSR_TLB_MUL|SFSR_TLB_PRT)) {
10561772Sjl139090 			    opl_flt->flt_eid_mod = OPL_ERRID_CPU;
10571772Sjl139090 			    opl_flt->flt_eid_sid = aflt->flt_inst;
10581772Sjl139090 		}
10591772Sjl139090 
10601772Sjl139090 		/*
10611772Sjl139090 		 * In case of no effective error bit
10621772Sjl139090 		 */
10631772Sjl139090 		if ((opl_flt->flt_bit & SFSR_ERRS) == 0) {
10641772Sjl139090 			    opl_flt->flt_eid_mod = OPL_ERRID_CPU;
10651772Sjl139090 			    opl_flt->flt_eid_sid = aflt->flt_inst;
10661772Sjl139090 		}
10671772Sjl139090 		break;
10681772Sjl139090 
10691772Sjl139090 		default:
10701772Sjl139090 			return (1);
10711772Sjl139090 	}
10721772Sjl139090 	return (1);
10731772Sjl139090 }
10741772Sjl139090 
10751772Sjl139090 /*
10761772Sjl139090  * Retire the bad page that may contain the flushed error.
10771772Sjl139090  */
10781772Sjl139090 void
10791772Sjl139090 cpu_page_retire(opl_async_flt_t *opl_flt)
10801772Sjl139090 {
10811772Sjl139090 	struct async_flt *aflt = (struct async_flt *)opl_flt;
10821772Sjl139090 	(void) page_retire(aflt->flt_addr, PR_UE);
10831772Sjl139090 }
10841772Sjl139090 
10851772Sjl139090 /*
10861772Sjl139090  * Invoked by error_init() early in startup and therefore before
10871772Sjl139090  * startup_errorq() is called to drain any error Q -
10881772Sjl139090  *
10891772Sjl139090  * startup()
10901772Sjl139090  *   startup_end()
10911772Sjl139090  *     error_init()
10921772Sjl139090  *       cpu_error_init()
10931772Sjl139090  * errorq_init()
10941772Sjl139090  *   errorq_drain()
10951772Sjl139090  * start_other_cpus()
10961772Sjl139090  *
10971772Sjl139090  * The purpose of this routine is to create error-related taskqs.  Taskqs
10981772Sjl139090  * are used for this purpose because cpu_lock can't be grabbed from interrupt
10991772Sjl139090  * context.
11001772Sjl139090  *
11011772Sjl139090  */
11021772Sjl139090 /*ARGSUSED*/
11031772Sjl139090 void
11041772Sjl139090 cpu_error_init(int items)
11051772Sjl139090 {
11061772Sjl139090 	opl_err_log = (opl_errlog_t *)
11071772Sjl139090 	    kmem_alloc(ERRLOG_ALLOC_SZ, KM_SLEEP);
11081772Sjl139090 	if ((uint64_t)opl_err_log & MMU_PAGEOFFSET)
11091772Sjl139090 		cmn_err(CE_PANIC, "The base address of the error log "
11101772Sjl139090 		    "is not page aligned");
11111772Sjl139090 }
11121772Sjl139090 
11131772Sjl139090 /*
11141772Sjl139090  * We route all errors through a single switch statement.
11151772Sjl139090  */
11161772Sjl139090 void
11171772Sjl139090 cpu_ue_log_err(struct async_flt *aflt)
11181772Sjl139090 {
11191772Sjl139090 	switch (aflt->flt_class) {
11201772Sjl139090 	case CPU_FAULT:
11211772Sjl139090 		if (cpu_sync_log_err(aflt))
11221772Sjl139090 			cpu_ereport_post(aflt);
11231772Sjl139090 		break;
11241772Sjl139090 
11251772Sjl139090 	case BUS_FAULT:
11261772Sjl139090 		bus_async_log_err(aflt);
11271772Sjl139090 		break;
11281772Sjl139090 
11291772Sjl139090 	default:
11301772Sjl139090 		cmn_err(CE_WARN, "discarding async error %p with invalid "
11311772Sjl139090 		    "fault class (0x%x)", (void *)aflt, aflt->flt_class);
11321772Sjl139090 		return;
11331772Sjl139090 	}
11341772Sjl139090 }
11351772Sjl139090 
11361772Sjl139090 /*
11371772Sjl139090  * Routine for panic hook callback from panic_idle().
11381772Sjl139090  *
11391772Sjl139090  * Nothing to do here.
11401772Sjl139090  */
11411772Sjl139090 void
11421772Sjl139090 cpu_async_panic_callb(void)
11431772Sjl139090 {
11441772Sjl139090 }
11451772Sjl139090 
11461772Sjl139090 /*
11471772Sjl139090  * Routine to return a string identifying the physical name
11481772Sjl139090  * associated with a memory/cache error.
11491772Sjl139090  */
11501772Sjl139090 /*ARGSUSED*/
11511772Sjl139090 int
11521772Sjl139090 cpu_get_mem_unum(int synd_status, ushort_t flt_synd, uint64_t flt_stat,
11531772Sjl139090     uint64_t flt_addr, int flt_bus_id, int flt_in_memory,
11541772Sjl139090     ushort_t flt_status, char *buf, int buflen, int *lenp)
11551772Sjl139090 {
11561772Sjl139090 	int synd_code;
11571772Sjl139090 	int ret;
11581772Sjl139090 
11591772Sjl139090 	/*
11601772Sjl139090 	 * An AFSR of -1 defaults to a memory syndrome.
11611772Sjl139090 	 */
11621772Sjl139090 	synd_code = (int)flt_synd;
11631772Sjl139090 
11641772Sjl139090 	if (&plat_get_mem_unum) {
11651772Sjl139090 		if ((ret = plat_get_mem_unum(synd_code, flt_addr, flt_bus_id,
11661772Sjl139090 			flt_in_memory, flt_status, buf, buflen, lenp)) != 0) {
11671772Sjl139090 			buf[0] = '\0';
11681772Sjl139090 			*lenp = 0;
11691772Sjl139090 		}
11701772Sjl139090 		return (ret);
11711772Sjl139090 	}
11721772Sjl139090 	buf[0] = '\0';
11731772Sjl139090 	*lenp = 0;
11741772Sjl139090 	return (ENOTSUP);
11751772Sjl139090 }
11761772Sjl139090 
11771772Sjl139090 /*
11781772Sjl139090  * Wrapper for cpu_get_mem_unum() routine that takes an
11791772Sjl139090  * async_flt struct rather than explicit arguments.
11801772Sjl139090  */
11811772Sjl139090 int
11821772Sjl139090 cpu_get_mem_unum_aflt(int synd_status, struct async_flt *aflt,
11831772Sjl139090     char *buf, int buflen, int *lenp)
11841772Sjl139090 {
11851772Sjl139090 	/*
11861772Sjl139090 	 * We always pass -1 so that cpu_get_mem_unum will interpret this as a
11871772Sjl139090 	 * memory error.
11881772Sjl139090 	 */
11891772Sjl139090 	return (cpu_get_mem_unum(synd_status, aflt->flt_synd,
11901772Sjl139090 	    (uint64_t)-1,
11911772Sjl139090 	    aflt->flt_addr, aflt->flt_bus_id, aflt->flt_in_memory,
11921772Sjl139090 	    aflt->flt_status, buf, buflen, lenp));
11931772Sjl139090 }
11941772Sjl139090 
11951772Sjl139090 /*
11961772Sjl139090  * This routine is a more generic interface to cpu_get_mem_unum()
11971772Sjl139090  * that may be used by other modules (e.g. mm).
11981772Sjl139090  */
11991772Sjl139090 /*ARGSUSED*/
12001772Sjl139090 int
12011772Sjl139090 cpu_get_mem_name(uint64_t synd, uint64_t *afsr, uint64_t afar,
12021772Sjl139090     char *buf, int buflen, int *lenp)
12031772Sjl139090 {
12041772Sjl139090 	int synd_status, flt_in_memory, ret;
12051772Sjl139090 	ushort_t flt_status = 0;
12061772Sjl139090 	char unum[UNUM_NAMLEN];
12071772Sjl139090 
12081772Sjl139090 	/*
12091772Sjl139090 	 * Check for an invalid address.
12101772Sjl139090 	 */
12111772Sjl139090 	if (afar == (uint64_t)-1)
12121772Sjl139090 		return (ENXIO);
12131772Sjl139090 
12141772Sjl139090 	if (synd == (uint64_t)-1)
12151772Sjl139090 		synd_status = AFLT_STAT_INVALID;
12161772Sjl139090 	else
12171772Sjl139090 		synd_status = AFLT_STAT_VALID;
12181772Sjl139090 
12191772Sjl139090 	flt_in_memory = (*afsr & SFSR_MEMORY) &&
12201772Sjl139090 		pf_is_memory(afar >> MMU_PAGESHIFT);
12211772Sjl139090 
12221772Sjl139090 	ret = cpu_get_mem_unum(synd_status, (ushort_t)synd, *afsr, afar,
12231772Sjl139090 		CPU->cpu_id, flt_in_memory, flt_status, unum,
12241772Sjl139090 		UNUM_NAMLEN, lenp);
12251772Sjl139090 	if (ret != 0)
12261772Sjl139090 		return (ret);
12271772Sjl139090 
12281772Sjl139090 	if (*lenp >= buflen)
12291772Sjl139090 		return (ENAMETOOLONG);
12301772Sjl139090 
12311772Sjl139090 	(void) strncpy(buf, unum, buflen);
12321772Sjl139090 
12331772Sjl139090 	return (0);
12341772Sjl139090 }
12351772Sjl139090 
12361772Sjl139090 /*
12371772Sjl139090  * Routine to return memory information associated
12381772Sjl139090  * with a physical address and syndrome.
12391772Sjl139090  */
12401772Sjl139090 /*ARGSUSED*/
12411772Sjl139090 int
12421772Sjl139090 cpu_get_mem_info(uint64_t synd, uint64_t afar,
12431772Sjl139090     uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
12441772Sjl139090     int *segsp, int *banksp, int *mcidp)
12451772Sjl139090 {
12461772Sjl139090 	int synd_code = (int)synd;
12471772Sjl139090 
12481772Sjl139090 	if (afar == (uint64_t)-1)
12491772Sjl139090 		return (ENXIO);
12501772Sjl139090 
12511772Sjl139090 	if (p2get_mem_info != NULL)
12521772Sjl139090 		return ((p2get_mem_info)(synd_code, afar,
12531772Sjl139090 			mem_sizep, seg_sizep, bank_sizep,
12541772Sjl139090 			segsp, banksp, mcidp));
12551772Sjl139090 	else
12561772Sjl139090 		return (ENOTSUP);
12571772Sjl139090 }
12581772Sjl139090 
12591772Sjl139090 /*
12601772Sjl139090  * Routine to return a string identifying the physical
12611772Sjl139090  * name associated with a cpuid.
12621772Sjl139090  */
12631772Sjl139090 int
12641772Sjl139090 cpu_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
12651772Sjl139090 {
12661772Sjl139090 	int ret;
12671772Sjl139090 	char unum[UNUM_NAMLEN];
12681772Sjl139090 
12691772Sjl139090 	if (&plat_get_cpu_unum) {
12701772Sjl139090 		if ((ret = plat_get_cpu_unum(cpuid, unum, UNUM_NAMLEN, lenp))
12711772Sjl139090 			!= 0)
12721772Sjl139090 			return (ret);
12731772Sjl139090 	} else {
12741772Sjl139090 		return (ENOTSUP);
12751772Sjl139090 	}
12761772Sjl139090 
12771772Sjl139090 	if (*lenp >= buflen)
12781772Sjl139090 		return (ENAMETOOLONG);
12791772Sjl139090 
12801772Sjl139090 	(void) strncpy(buf, unum, *lenp);
12811772Sjl139090 
12821772Sjl139090 	return (0);
12831772Sjl139090 }
12841772Sjl139090 
12851772Sjl139090 /*
12861772Sjl139090  * This routine exports the name buffer size.
12871772Sjl139090  */
12881772Sjl139090 size_t
12891772Sjl139090 cpu_get_name_bufsize()
12901772Sjl139090 {
12911772Sjl139090 	return (UNUM_NAMLEN);
12921772Sjl139090 }
12931772Sjl139090 
12941772Sjl139090 /*
12951772Sjl139090  * Flush the entire ecache by ASI_L2_CNTL.U2_FLUSH
12961772Sjl139090  */
12971772Sjl139090 void
12981772Sjl139090 cpu_flush_ecache(void)
12991772Sjl139090 {
13001772Sjl139090 	flush_ecache(ecache_flushaddr, cpunodes[CPU->cpu_id].ecache_size,
13011772Sjl139090 	    cpunodes[CPU->cpu_id].ecache_linesize);
13021772Sjl139090 }
13031772Sjl139090 
13041772Sjl139090 static uint8_t
13051772Sjl139090 flt_to_trap_type(struct async_flt *aflt)
13061772Sjl139090 {
13071772Sjl139090 	if (aflt->flt_status & OPL_ECC_ISYNC_TRAP)
13081772Sjl139090 		return (TRAP_TYPE_ECC_I);
13091772Sjl139090 	if (aflt->flt_status & OPL_ECC_DSYNC_TRAP)
13101772Sjl139090 		return (TRAP_TYPE_ECC_D);
13111772Sjl139090 	if (aflt->flt_status & OPL_ECC_URGENT_TRAP)
13121772Sjl139090 		return (TRAP_TYPE_URGENT);
13131772Sjl139090 	return (-1);
13141772Sjl139090 }
13151772Sjl139090 
13161772Sjl139090 /*
13171772Sjl139090  * Encode the data saved in the opl_async_flt_t struct into
13181772Sjl139090  * the FM ereport payload.
13191772Sjl139090  */
13201772Sjl139090 /* ARGSUSED */
13211772Sjl139090 static void
13221772Sjl139090 cpu_payload_add_aflt(struct async_flt *aflt, nvlist_t *payload,
13231772Sjl139090 		nvlist_t *resource)
13241772Sjl139090 {
13251772Sjl139090 	opl_async_flt_t *opl_flt = (opl_async_flt_t *)aflt;
13261772Sjl139090 	char unum[UNUM_NAMLEN];
13271772Sjl139090 	char sbuf[21]; /* sizeof (UINT64_MAX) + '\0' */
13281772Sjl139090 	int len;
13291772Sjl139090 
13301772Sjl139090 
13311772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_SFSR) {
13321772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_SFSR,
13331772Sjl139090 			DATA_TYPE_UINT64, aflt->flt_stat, NULL);
13341772Sjl139090 	}
13351772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_SFAR) {
13361772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_SFAR,
13371772Sjl139090 			DATA_TYPE_UINT64, aflt->flt_addr, NULL);
13381772Sjl139090 	}
13391772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_UGESR) {
13401772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_UGESR,
13411772Sjl139090 			DATA_TYPE_UINT64, aflt->flt_stat, NULL);
13421772Sjl139090 	}
13431772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_PC) {
13441772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_PC,
13451772Sjl139090 		    DATA_TYPE_UINT64, (uint64_t)aflt->flt_pc, NULL);
13461772Sjl139090 	}
13471772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_TL) {
13481772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_TL,
13491772Sjl139090 		    DATA_TYPE_UINT8, (uint8_t)aflt->flt_tl, NULL);
13501772Sjl139090 	}
13511772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_TT) {
13521772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_TT,
13531772Sjl139090 		    DATA_TYPE_UINT8, flt_to_trap_type(aflt), NULL);
13541772Sjl139090 	}
13551772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_PRIV) {
13561772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_PRIV,
13571772Sjl139090 		    DATA_TYPE_BOOLEAN_VALUE,
13581772Sjl139090 		    (aflt->flt_priv ? B_TRUE : B_FALSE), NULL);
13591772Sjl139090 	}
13601772Sjl139090 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_FLT_STATUS) {
13611772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_FLT_STATUS,
13621772Sjl139090 			DATA_TYPE_UINT64, (uint64_t)aflt->flt_status, NULL);
13631772Sjl139090 	}
13641772Sjl139090 
13651772Sjl139090 	switch (opl_flt->flt_eid_mod) {
13661772Sjl139090 	case OPL_ERRID_CPU:
13671772Sjl139090 		(void) snprintf(sbuf, sizeof (sbuf), "%llX",
13681772Sjl139090 			(u_longlong_t)cpunodes[opl_flt->flt_eid_sid].device_id);
13691772Sjl139090 		(void) fm_fmri_cpu_set(resource, FM_CPU_SCHEME_VERSION,
13701772Sjl139090 			NULL, opl_flt->flt_eid_sid,
13711772Sjl139090 			(uint8_t *)&cpunodes[opl_flt->flt_eid_sid].version,
13721772Sjl139090 			sbuf);
13731772Sjl139090 		fm_payload_set(payload,
13741772Sjl139090 			FM_EREPORT_PAYLOAD_NAME_RESOURCE,
13751772Sjl139090 			DATA_TYPE_NVLIST, resource, NULL);
13761772Sjl139090 		break;
13771772Sjl139090 
13781772Sjl139090 	case OPL_ERRID_CHANNEL:
13791772Sjl139090 		/*
13801772Sjl139090 		 * No resource is created but the cpumem DE will find
13811772Sjl139090 		 * the defective path by retreiving EID from SFSR which is
13821772Sjl139090 		 * included in the payload.
13831772Sjl139090 		 */
13841772Sjl139090 		break;
13851772Sjl139090 
13861772Sjl139090 	case OPL_ERRID_MEM:
13871772Sjl139090 		(void) cpu_get_mem_unum_aflt(0, aflt, unum, UNUM_NAMLEN, &len);
13881772Sjl139090 		(void) fm_fmri_mem_set(resource, FM_MEM_SCHEME_VERSION,
13891772Sjl139090 			NULL, unum, NULL, (uint64_t)-1);
13901772Sjl139090 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_RESOURCE,
13911772Sjl139090 			DATA_TYPE_NVLIST, resource, NULL);
13921772Sjl139090 		break;
13931772Sjl139090 
13941772Sjl139090 	case OPL_ERRID_PATH:
13951772Sjl139090 		/*
13961772Sjl139090 		 * No resource is created but the cpumem DE will find
13971772Sjl139090 		 * the defective path by retreiving EID from SFSR which is
13981772Sjl139090 		 * included in the payload.
13991772Sjl139090 		 */
14001772Sjl139090 		break;
14011772Sjl139090 	}
14021772Sjl139090 }
14031772Sjl139090 
14041772Sjl139090 /*
14051772Sjl139090  * Returns whether fault address is valid for this error bit and
14061772Sjl139090  * whether the address is "in memory" (i.e. pf_is_memory returns 1).
14071772Sjl139090  */
14081772Sjl139090 /*ARGSUSED*/
14091772Sjl139090 static int
14101772Sjl139090 cpu_flt_in_memory(opl_async_flt_t *opl_flt, uint64_t t_afsr_bit)
14111772Sjl139090 {
14121772Sjl139090 	struct async_flt *aflt = (struct async_flt *)opl_flt;
14131772Sjl139090 
14141772Sjl139090 	if (aflt->flt_status & (OPL_ECC_SYNC_TRAP)) {
14151772Sjl139090 		return ((t_afsr_bit & SFSR_MEMORY) &&
14161772Sjl139090 		    pf_is_memory(aflt->flt_addr >> MMU_PAGESHIFT));
14171772Sjl139090 	}
14181772Sjl139090 	return (0);
14191772Sjl139090 }
14201772Sjl139090 
14211772Sjl139090 /*
14221772Sjl139090  * In OPL SCF does the stick synchronization.
14231772Sjl139090  */
14241772Sjl139090 void
14251772Sjl139090 sticksync_slave(void)
14261772Sjl139090 {
14271772Sjl139090 }
14281772Sjl139090 
14291772Sjl139090 /*
14301772Sjl139090  * In OPL SCF does the stick synchronization.
14311772Sjl139090  */
14321772Sjl139090 void
14331772Sjl139090 sticksync_master(void)
14341772Sjl139090 {
14351772Sjl139090 }
14361772Sjl139090 
14371772Sjl139090 /*
14381772Sjl139090  * Cpu private unitialization.  OPL cpus do not use the private area.
14391772Sjl139090  */
14401772Sjl139090 void
14411772Sjl139090 cpu_uninit_private(struct cpu *cp)
14421772Sjl139090 {
14431772Sjl139090 	cmp_delete_cpu(cp->cpu_id);
14441772Sjl139090 }
14451772Sjl139090 
14461772Sjl139090 /*
14471772Sjl139090  * Always flush an entire cache.
14481772Sjl139090  */
14491772Sjl139090 void
14501772Sjl139090 cpu_error_ecache_flush(void)
14511772Sjl139090 {
14521772Sjl139090 	cpu_flush_ecache();
14531772Sjl139090 }
14541772Sjl139090 
14551772Sjl139090 void
14561772Sjl139090 cpu_ereport_post(struct async_flt *aflt)
14571772Sjl139090 {
14581772Sjl139090 	char *cpu_type, buf[FM_MAX_CLASS];
14591772Sjl139090 	nv_alloc_t *nva = NULL;
14601772Sjl139090 	nvlist_t *ereport, *detector, *resource;
14611772Sjl139090 	errorq_elem_t *eqep;
14621772Sjl139090 	char sbuf[21]; /* sizeof (UINT64_MAX) + '\0' */
14631772Sjl139090 
14641772Sjl139090 	if (aflt->flt_panic || panicstr) {
14651772Sjl139090 		eqep = errorq_reserve(ereport_errorq);
14661772Sjl139090 		if (eqep == NULL)
14671772Sjl139090 			return;
14681772Sjl139090 		ereport = errorq_elem_nvl(ereport_errorq, eqep);
14691772Sjl139090 		nva = errorq_elem_nva(ereport_errorq, eqep);
14701772Sjl139090 	} else {
14711772Sjl139090 		ereport = fm_nvlist_create(nva);
14721772Sjl139090 	}
14731772Sjl139090 
14741772Sjl139090 	/*
14751772Sjl139090 	 * Create the scheme "cpu" FMRI.
14761772Sjl139090 	 */
14771772Sjl139090 	detector = fm_nvlist_create(nva);
14781772Sjl139090 	resource = fm_nvlist_create(nva);
14791772Sjl139090 	switch (cpunodes[aflt->flt_inst].implementation) {
14801772Sjl139090 	case OLYMPUS_C_IMPL:
14811772Sjl139090 		cpu_type = FM_EREPORT_CPU_SPARC64_VI;
14821772Sjl139090 		break;
14831772Sjl139090 	default:
14841772Sjl139090 		cpu_type = FM_EREPORT_CPU_UNSUPPORTED;
14851772Sjl139090 		break;
14861772Sjl139090 	}
14871772Sjl139090 	(void) snprintf(sbuf, sizeof (sbuf), "%llX",
14881772Sjl139090 	    (u_longlong_t)cpunodes[aflt->flt_inst].device_id);
14891772Sjl139090 	(void) fm_fmri_cpu_set(detector, FM_CPU_SCHEME_VERSION, NULL,
14901772Sjl139090 	    aflt->flt_inst, (uint8_t *)&cpunodes[aflt->flt_inst].version,
14911772Sjl139090 	    sbuf);
14921772Sjl139090 
14931772Sjl139090 	/*
14941772Sjl139090 	 * Encode all the common data into the ereport.
14951772Sjl139090 	 */
14961772Sjl139090 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s.%s",
14971772Sjl139090 	    FM_ERROR_CPU, cpu_type, aflt->flt_erpt_class);
14981772Sjl139090 
14991772Sjl139090 	fm_ereport_set(ereport, FM_EREPORT_VERSION, buf,
15001772Sjl139090 	    fm_ena_generate(aflt->flt_id, FM_ENA_FMT1), detector, NULL);
15011772Sjl139090 
15021772Sjl139090 	/*
15031772Sjl139090 	 * Encode the error specific data that was saved in
15041772Sjl139090 	 * the async_flt structure into the ereport.
15051772Sjl139090 	 */
15061772Sjl139090 	cpu_payload_add_aflt(aflt, ereport, resource);
15071772Sjl139090 
15081772Sjl139090 	if (aflt->flt_panic || panicstr) {
15091772Sjl139090 		errorq_commit(ereport_errorq, eqep, ERRORQ_SYNC);
15101772Sjl139090 	} else {
15111772Sjl139090 		(void) fm_ereport_post(ereport, EVCH_TRYHARD);
15121772Sjl139090 		fm_nvlist_destroy(ereport, FM_NVA_FREE);
15131772Sjl139090 		fm_nvlist_destroy(detector, FM_NVA_FREE);
15141772Sjl139090 		fm_nvlist_destroy(resource, FM_NVA_FREE);
15151772Sjl139090 	}
15161772Sjl139090 }
15171772Sjl139090 
15181772Sjl139090 void
15191772Sjl139090 cpu_run_bus_error_handlers(struct async_flt *aflt, int expected)
15201772Sjl139090 {
15211772Sjl139090 	int status;
15221772Sjl139090 	ddi_fm_error_t de;
15231772Sjl139090 
15241772Sjl139090 	bzero(&de, sizeof (ddi_fm_error_t));
15251772Sjl139090 
15261772Sjl139090 	de.fme_version = DDI_FME_VERSION;
15271772Sjl139090 	de.fme_ena = fm_ena_generate(aflt->flt_id, FM_ENA_FMT1);
15281772Sjl139090 	de.fme_flag = expected;
15291772Sjl139090 	de.fme_bus_specific = (void *)aflt->flt_addr;
15301772Sjl139090 	status = ndi_fm_handler_dispatch(ddi_root_node(), NULL, &de);
15311772Sjl139090 	if ((aflt->flt_prot == AFLT_PROT_NONE) && (status == DDI_FM_FATAL))
15321772Sjl139090 		aflt->flt_panic = 1;
15331772Sjl139090 }
15341772Sjl139090 
15351772Sjl139090 void
15361772Sjl139090 cpu_errorq_dispatch(char *error_class, void *payload, size_t payload_sz,
15371772Sjl139090     errorq_t *eqp, uint_t flag)
15381772Sjl139090 {
15391772Sjl139090 	struct async_flt *aflt = (struct async_flt *)payload;
15401772Sjl139090 
15411772Sjl139090 	aflt->flt_erpt_class = error_class;
15421772Sjl139090 	errorq_dispatch(eqp, payload, payload_sz, flag);
15431772Sjl139090 }
15441772Sjl139090 
15451772Sjl139090 void
15461772Sjl139090 adjust_hw_copy_limits(int ecache_size)
15471772Sjl139090 {
15481772Sjl139090 	/*
15491772Sjl139090 	 * Set hw copy limits.
15501772Sjl139090 	 *
15511772Sjl139090 	 * /etc/system will be parsed later and can override one or more
15521772Sjl139090 	 * of these settings.
15531772Sjl139090 	 *
15541772Sjl139090 	 * At this time, ecache size seems only mildly relevant.
15551772Sjl139090 	 * We seem to run into issues with the d-cache and stalls
15561772Sjl139090 	 * we see on misses.
15571772Sjl139090 	 *
15581772Sjl139090 	 * Cycle measurement indicates that 2 byte aligned copies fare
15591772Sjl139090 	 * little better than doing things with VIS at around 512 bytes.
15601772Sjl139090 	 * 4 byte aligned shows promise until around 1024 bytes. 8 Byte
15611772Sjl139090 	 * aligned is faster whenever the source and destination data
15621772Sjl139090 	 * in cache and the total size is less than 2 Kbytes.  The 2K
15631772Sjl139090 	 * limit seems to be driven by the 2K write cache.
15641772Sjl139090 	 * When more than 2K of copies are done in non-VIS mode, stores
15651772Sjl139090 	 * backup in the write cache.  In VIS mode, the write cache is
15661772Sjl139090 	 * bypassed, allowing faster cache-line writes aligned on cache
15671772Sjl139090 	 * boundaries.
15681772Sjl139090 	 *
15691772Sjl139090 	 * In addition, in non-VIS mode, there is no prefetching, so
15701772Sjl139090 	 * for larger copies, the advantage of prefetching to avoid even
15711772Sjl139090 	 * occasional cache misses is enough to justify using the VIS code.
15721772Sjl139090 	 *
15731772Sjl139090 	 * During testing, it was discovered that netbench ran 3% slower
15741772Sjl139090 	 * when hw_copy_limit_8 was 2K or larger.  Apparently for server
15751772Sjl139090 	 * applications, data is only used once (copied to the output
15761772Sjl139090 	 * buffer, then copied by the network device off the system).  Using
15771772Sjl139090 	 * the VIS copy saves more L2 cache state.  Network copies are
15781772Sjl139090 	 * around 1.3K to 1.5K in size for historical reasons.
15791772Sjl139090 	 *
15801772Sjl139090 	 * Therefore, a limit of 1K bytes will be used for the 8 byte
15811772Sjl139090 	 * aligned copy even for large caches and 8 MB ecache.  The
15821772Sjl139090 	 * infrastructure to allow different limits for different sized
15831772Sjl139090 	 * caches is kept to allow further tuning in later releases.
15841772Sjl139090 	 */
15851772Sjl139090 
15861772Sjl139090 	if (min_ecache_size == 0 && use_hw_bcopy) {
15871772Sjl139090 		/*
15881772Sjl139090 		 * First time through - should be before /etc/system
15891772Sjl139090 		 * is read.
15901772Sjl139090 		 * Could skip the checks for zero but this lets us
15911772Sjl139090 		 * preserve any debugger rewrites.
15921772Sjl139090 		 */
15931772Sjl139090 		if (hw_copy_limit_1 == 0) {
15941772Sjl139090 			hw_copy_limit_1 = VIS_COPY_THRESHOLD;
15951772Sjl139090 			priv_hcl_1 = hw_copy_limit_1;
15961772Sjl139090 		}
15971772Sjl139090 		if (hw_copy_limit_2 == 0) {
15981772Sjl139090 			hw_copy_limit_2 = 2 * VIS_COPY_THRESHOLD;
15991772Sjl139090 			priv_hcl_2 = hw_copy_limit_2;
16001772Sjl139090 		}
16011772Sjl139090 		if (hw_copy_limit_4 == 0) {
16021772Sjl139090 			hw_copy_limit_4 = 4 * VIS_COPY_THRESHOLD;
16031772Sjl139090 			priv_hcl_4 = hw_copy_limit_4;
16041772Sjl139090 		}
16051772Sjl139090 		if (hw_copy_limit_8 == 0) {
16061772Sjl139090 			hw_copy_limit_8 = 4 * VIS_COPY_THRESHOLD;
16071772Sjl139090 			priv_hcl_8 = hw_copy_limit_8;
16081772Sjl139090 		}
16091772Sjl139090 		min_ecache_size = ecache_size;
16101772Sjl139090 	} else {
16111772Sjl139090 		/*
16121772Sjl139090 		 * MP initialization. Called *after* /etc/system has
16131772Sjl139090 		 * been parsed. One CPU has already been initialized.
16141772Sjl139090 		 * Need to cater for /etc/system having scragged one
16151772Sjl139090 		 * of our values.
16161772Sjl139090 		 */
16171772Sjl139090 		if (ecache_size == min_ecache_size) {
16181772Sjl139090 			/*
16191772Sjl139090 			 * Same size ecache. We do nothing unless we
16201772Sjl139090 			 * have a pessimistic ecache setting. In that
16211772Sjl139090 			 * case we become more optimistic (if the cache is
16221772Sjl139090 			 * large enough).
16231772Sjl139090 			 */
16241772Sjl139090 			if (hw_copy_limit_8 == 4 * VIS_COPY_THRESHOLD) {
16251772Sjl139090 				/*
16261772Sjl139090 				 * Need to adjust hw_copy_limit* from our
16271772Sjl139090 				 * pessimistic uniprocessor value to a more
16281772Sjl139090 				 * optimistic UP value *iff* it hasn't been
16291772Sjl139090 				 * reset.
16301772Sjl139090 				 */
16311772Sjl139090 				if ((ecache_size > 1048576) &&
16321772Sjl139090 				    (priv_hcl_8 == hw_copy_limit_8)) {
16331772Sjl139090 					if (ecache_size <= 2097152)
16341772Sjl139090 						hw_copy_limit_8 = 4 *
16351772Sjl139090 						    VIS_COPY_THRESHOLD;
16361772Sjl139090 					else if (ecache_size <= 4194304)
16371772Sjl139090 						hw_copy_limit_8 = 4 *
16381772Sjl139090 						    VIS_COPY_THRESHOLD;
16391772Sjl139090 					else
16401772Sjl139090 						hw_copy_limit_8 = 4 *
16411772Sjl139090 						    VIS_COPY_THRESHOLD;
16421772Sjl139090 					priv_hcl_8 = hw_copy_limit_8;
16431772Sjl139090 				}
16441772Sjl139090 			}
16451772Sjl139090 		} else if (ecache_size < min_ecache_size) {
16461772Sjl139090 			/*
16471772Sjl139090 			 * A different ecache size. Can this even happen?
16481772Sjl139090 			 */
16491772Sjl139090 			if (priv_hcl_8 == hw_copy_limit_8) {
16501772Sjl139090 				/*
16511772Sjl139090 				 * The previous value that we set
16521772Sjl139090 				 * is unchanged (i.e., it hasn't been
16531772Sjl139090 				 * scragged by /etc/system). Rewrite it.
16541772Sjl139090 				 */
16551772Sjl139090 				if (ecache_size <= 1048576)
16561772Sjl139090 					hw_copy_limit_8 = 8 *
16571772Sjl139090 					    VIS_COPY_THRESHOLD;
16581772Sjl139090 				else if (ecache_size <= 2097152)
16591772Sjl139090 					hw_copy_limit_8 = 8 *
16601772Sjl139090 					    VIS_COPY_THRESHOLD;
16611772Sjl139090 				else if (ecache_size <= 4194304)
16621772Sjl139090 					hw_copy_limit_8 = 8 *
16631772Sjl139090 					    VIS_COPY_THRESHOLD;
16641772Sjl139090 				else
16651772Sjl139090 					hw_copy_limit_8 = 10 *
16661772Sjl139090 					    VIS_COPY_THRESHOLD;
16671772Sjl139090 				priv_hcl_8 = hw_copy_limit_8;
16681772Sjl139090 				min_ecache_size = ecache_size;
16691772Sjl139090 			}
16701772Sjl139090 		}
16711772Sjl139090 	}
16721772Sjl139090 }
16731772Sjl139090 
16741772Sjl139090 #define	VIS_BLOCKSIZE		64
16751772Sjl139090 
16761772Sjl139090 int
16771772Sjl139090 dtrace_blksuword32_err(uintptr_t addr, uint32_t *data)
16781772Sjl139090 {
16791772Sjl139090 	int ret, watched;
16801772Sjl139090 
16811772Sjl139090 	watched = watch_disable_addr((void *)addr, VIS_BLOCKSIZE, S_WRITE);
16821772Sjl139090 	ret = dtrace_blksuword32(addr, data, 0);
16831772Sjl139090 	if (watched)
16841772Sjl139090 		watch_enable_addr((void *)addr, VIS_BLOCKSIZE, S_WRITE);
16851772Sjl139090 
16861772Sjl139090 	return (ret);
16871772Sjl139090 }
16881772Sjl139090 
16891772Sjl139090 void
16901772Sjl139090 opl_cpu_reg_init()
16911772Sjl139090 {
16921772Sjl139090 	uint64_t	this_cpu_log;
16931772Sjl139090 
16941772Sjl139090 	/*
16951772Sjl139090 	 * We do not need to re-initialize cpu0 registers.
16961772Sjl139090 	 */
16971772Sjl139090 	if (cpu[getprocessorid()] == &cpu0)
16981772Sjl139090 		return;
16991772Sjl139090 
17001772Sjl139090 	/*
17011772Sjl139090 	 * Initialize Error log Scratch register for error handling.
17021772Sjl139090 	 */
17031772Sjl139090 
17041772Sjl139090 	this_cpu_log = va_to_pa((void*)(((uint64_t)opl_err_log) +
17051772Sjl139090 		ERRLOG_BUFSZ * (getprocessorid())));
17061772Sjl139090 	opl_error_setup(this_cpu_log);
17071772Sjl139090 
17081772Sjl139090 	/*
17091772Sjl139090 	 * Enable MMU translating multiple page sizes for
17101772Sjl139090 	 * sITLB and sDTLB.
17111772Sjl139090 	 */
17121772Sjl139090 	opl_mpg_enable();
17131772Sjl139090 }
17141772Sjl139090 
17151772Sjl139090 /*
17161772Sjl139090  * Queue one event in ue_queue based on ecc_type_to_info entry.
17171772Sjl139090  */
17181772Sjl139090 static void
17191772Sjl139090 cpu_queue_one_event(opl_async_flt_t *opl_flt, char *reason,
17201772Sjl139090     ecc_type_to_info_t *eccp)
17211772Sjl139090 {
17221772Sjl139090 	struct async_flt *aflt = (struct async_flt *)opl_flt;
17231772Sjl139090 
17241772Sjl139090 	if (reason &&
17251772Sjl139090 	    strlen(reason) + strlen(eccp->ec_reason) < MAX_REASON_STRING) {
17261772Sjl139090 		(void) strcat(reason, eccp->ec_reason);
17271772Sjl139090 	}
17281772Sjl139090 
17291772Sjl139090 	opl_flt->flt_bit = eccp->ec_afsr_bit;
17301772Sjl139090 	opl_flt->flt_type = eccp->ec_flt_type;
17311772Sjl139090 	aflt->flt_in_memory = cpu_flt_in_memory(opl_flt, opl_flt->flt_bit);
17321772Sjl139090 	aflt->flt_payload = eccp->ec_err_payload;
17331772Sjl139090 
17341772Sjl139090 	ASSERT(aflt->flt_status & (OPL_ECC_SYNC_TRAP|OPL_ECC_URGENT_TRAP));
17351772Sjl139090 	cpu_errorq_dispatch(eccp->ec_err_class,
17361772Sjl139090 		(void *)opl_flt, sizeof (opl_async_flt_t),
17371772Sjl139090 		ue_queue,
17381772Sjl139090 		aflt->flt_panic);
17391772Sjl139090 }
17401772Sjl139090 
17411772Sjl139090 /*
17421772Sjl139090  * Queue events on async event queue one event per error bit.
17431772Sjl139090  * Return number of events queued.
17441772Sjl139090  */
17451772Sjl139090 int
17461772Sjl139090 cpu_queue_events(opl_async_flt_t *opl_flt, char *reason, uint64_t t_afsr_errs)
17471772Sjl139090 {
17481772Sjl139090 	struct async_flt *aflt = (struct async_flt *)opl_flt;
17491772Sjl139090 	ecc_type_to_info_t *eccp;
17501772Sjl139090 	int nevents = 0;
17511772Sjl139090 
17521772Sjl139090 	/*
17531772Sjl139090 	 * Queue expected errors, error bit and fault type must must match
17541772Sjl139090 	 * in the ecc_type_to_info table.
17551772Sjl139090 	 */
17561772Sjl139090 	for (eccp = ecc_type_to_info; t_afsr_errs != 0 && eccp->ec_desc != NULL;
17571772Sjl139090 		eccp++) {
17581772Sjl139090 		if ((eccp->ec_afsr_bit & t_afsr_errs) != 0 &&
17591772Sjl139090 		    (eccp->ec_flags & aflt->flt_status) != 0) {
17601772Sjl139090 			/*
17611772Sjl139090 			 * UE error event can be further
17621772Sjl139090 			 * classified/breakdown into finer granularity
17631772Sjl139090 			 * based on the flt_eid_mod value set by HW.  We do
17641772Sjl139090 			 * special handling here so that we can report UE
17651772Sjl139090 			 * error in finer granularity as ue_mem,
17661772Sjl139090 			 * ue_channel, ue_cpu or ue_path.
17671772Sjl139090 			 */
17681772Sjl139090 			if (eccp->ec_flt_type == OPL_CPU_SYNC_UE) {
17691772Sjl139090 				opl_flt->flt_eid_mod =
17701772Sjl139090 					(aflt->flt_stat & SFSR_EID_MOD)
17711772Sjl139090 					>> SFSR_EID_MOD_SHIFT;
17721772Sjl139090 				opl_flt->flt_eid_sid =
17731772Sjl139090 					(aflt->flt_stat & SFSR_EID_SID)
17741772Sjl139090 					>> SFSR_EID_SID_SHIFT;
17751772Sjl139090 				/*
17761772Sjl139090 				 * Need to advance eccp pointer by flt_eid_mod
17771772Sjl139090 				 * so that we get an appropriate ecc pointer
17781772Sjl139090 				 *
17791772Sjl139090 				 * EID			# of advances
17801772Sjl139090 				 * ----------------------------------
17811772Sjl139090 				 * OPL_ERRID_MEM	0
17821772Sjl139090 				 * OPL_ERRID_CHANNEL	1
17831772Sjl139090 				 * OPL_ERRID_CPU	2
17841772Sjl139090 				 * OPL_ERRID_PATH	3
17851772Sjl139090 				 */
17861772Sjl139090 				eccp += opl_flt->flt_eid_mod;
17871772Sjl139090 			}
17881772Sjl139090 			cpu_queue_one_event(opl_flt, reason, eccp);
17891772Sjl139090 			t_afsr_errs &= ~eccp->ec_afsr_bit;
17901772Sjl139090 			nevents++;
17911772Sjl139090 		}
17921772Sjl139090 	}
17931772Sjl139090 
17941772Sjl139090 	return (nevents);
17951772Sjl139090 }
17961772Sjl139090 
17971772Sjl139090 /*
17981772Sjl139090  * Sync. error wrapper functions.
17991772Sjl139090  * We use these functions in order to transfer here from the
18001772Sjl139090  * nucleus trap handler information about trap type (data or
18011772Sjl139090  * instruction) and trap level (0 or above 0). This way we
18021772Sjl139090  * get rid of using SFSR's reserved bits.
18031772Sjl139090  */
18041772Sjl139090 
18051772Sjl139090 #define	OPL_SYNC_TL0	0
18061772Sjl139090 #define	OPL_SYNC_TL1	1
18071772Sjl139090 #define	OPL_ISYNC_ERR	0
18081772Sjl139090 #define	OPL_DSYNC_ERR	1
18091772Sjl139090 
18101772Sjl139090 void
18111772Sjl139090 opl_cpu_isync_tl0_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
18121772Sjl139090 {
18131772Sjl139090 	uint64_t t_sfar = p_sfar;
18141772Sjl139090 	uint64_t t_sfsr = p_sfsr;
18151772Sjl139090 
18161772Sjl139090 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
18171772Sjl139090 	    OPL_SYNC_TL0, OPL_ISYNC_ERR);
18181772Sjl139090 }
18191772Sjl139090 
18201772Sjl139090 void
18211772Sjl139090 opl_cpu_isync_tl1_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
18221772Sjl139090 {
18231772Sjl139090 	uint64_t t_sfar = p_sfar;
18241772Sjl139090 	uint64_t t_sfsr = p_sfsr;
18251772Sjl139090 
18261772Sjl139090 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
18271772Sjl139090 	    OPL_SYNC_TL1, OPL_ISYNC_ERR);
18281772Sjl139090 }
18291772Sjl139090 
18301772Sjl139090 void
18311772Sjl139090 opl_cpu_dsync_tl0_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
18321772Sjl139090 {
18331772Sjl139090 	uint64_t t_sfar = p_sfar;
18341772Sjl139090 	uint64_t t_sfsr = p_sfsr;
18351772Sjl139090 
18361772Sjl139090 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
18371772Sjl139090 	    OPL_SYNC_TL0, OPL_DSYNC_ERR);
18381772Sjl139090 }
18391772Sjl139090 
18401772Sjl139090 void
18411772Sjl139090 opl_cpu_dsync_tl1_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
18421772Sjl139090 {
18431772Sjl139090 	uint64_t t_sfar = p_sfar;
18441772Sjl139090 	uint64_t t_sfsr = p_sfsr;
18451772Sjl139090 
18461772Sjl139090 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
18471772Sjl139090 	    OPL_SYNC_TL1, OPL_DSYNC_ERR);
18481772Sjl139090 }
18491772Sjl139090 
18501772Sjl139090 /*
18511772Sjl139090  * The fj sync err handler transfers control here for UE, BERR, TO, TLB_MUL
18521772Sjl139090  * and TLB_PRT.
18531772Sjl139090  * This function is designed based on cpu_deferred_error().
18541772Sjl139090  */
18551772Sjl139090 
18561772Sjl139090 static void
18571772Sjl139090 opl_cpu_sync_error(struct regs *rp, ulong_t t_sfar, ulong_t t_sfsr,
18581772Sjl139090     uint_t tl, uint_t derr)
18591772Sjl139090 {
18601772Sjl139090 	opl_async_flt_t opl_flt;
18611772Sjl139090 	struct async_flt *aflt;
18621772Sjl139090 	int trampolined = 0;
18631772Sjl139090 	char pr_reason[MAX_REASON_STRING];
18641772Sjl139090 	uint64_t log_sfsr;
18651772Sjl139090 	int expected = DDI_FM_ERR_UNEXPECTED;
18661772Sjl139090 	ddi_acc_hdl_t *hp;
18671772Sjl139090 
18681772Sjl139090 	/*
18691772Sjl139090 	 * We need to look at p_flag to determine if the thread detected an
18701772Sjl139090 	 * error while dumping core.  We can't grab p_lock here, but it's ok
18711772Sjl139090 	 * because we just need a consistent snapshot and we know that everyone
18721772Sjl139090 	 * else will store a consistent set of bits while holding p_lock.  We
18731772Sjl139090 	 * don't have to worry about a race because SDOCORE is set once prior
18741772Sjl139090 	 * to doing i/o from the process's address space and is never cleared.
18751772Sjl139090 	 */
18761772Sjl139090 	uint_t pflag = ttoproc(curthread)->p_flag;
18771772Sjl139090 
18781772Sjl139090 	pr_reason[0] = '\0';
18791772Sjl139090 
18801772Sjl139090 	/*
18811772Sjl139090 	 * handle the specific error
18821772Sjl139090 	 */
18831772Sjl139090 	bzero(&opl_flt, sizeof (opl_async_flt_t));
18841772Sjl139090 	aflt = (struct async_flt *)&opl_flt;
18851772Sjl139090 	aflt->flt_id = gethrtime_waitfree();
18861772Sjl139090 	aflt->flt_bus_id = getprocessorid();
18871772Sjl139090 	aflt->flt_inst = CPU->cpu_id;
18881772Sjl139090 	aflt->flt_stat = t_sfsr;
18891772Sjl139090 	aflt->flt_addr = t_sfar;
18901772Sjl139090 	aflt->flt_pc = (caddr_t)rp->r_pc;
18911772Sjl139090 	aflt->flt_prot = (uchar_t)AFLT_PROT_NONE;
18921772Sjl139090 	aflt->flt_class = (uchar_t)CPU_FAULT;
18931772Sjl139090 	aflt->flt_priv = (uchar_t)
18941772Sjl139090 		(tl == 1 ? 1 : ((rp->r_tstate & TSTATE_PRIV) ?  1 : 0));
18951772Sjl139090 	aflt->flt_tl = (uchar_t)tl;
18961772Sjl139090 	aflt->flt_panic = (uchar_t)(tl != 0 || aft_testfatal != 0 ||
18971772Sjl139090 	    (t_sfsr & (SFSR_TLB_MUL|SFSR_TLB_PRT)) != 0);
18981772Sjl139090 	aflt->flt_core = (pflag & SDOCORE) ? 1 : 0;
18991772Sjl139090 	aflt->flt_status = (derr) ? OPL_ECC_DSYNC_TRAP : OPL_ECC_ISYNC_TRAP;
19001772Sjl139090 
19011772Sjl139090 	/*
19021772Sjl139090 	 * If SFSR.FV is not set, both SFSR and SFAR/SFPAR values are uncertain.
19031772Sjl139090 	 * So, clear all error bits to avoid mis-handling and force the system
19041772Sjl139090 	 * panicked.
19051772Sjl139090 	 * We skip all the procedures below down to the panic message call.
19061772Sjl139090 	 */
19071772Sjl139090 	if (!(t_sfsr & SFSR_FV)) {
19081772Sjl139090 		opl_flt.flt_type = OPL_CPU_INV_SFSR;
19091772Sjl139090 		aflt->flt_panic = 1;
19101772Sjl139090 		aflt->flt_payload = FM_EREPORT_PAYLOAD_SYNC;
19111772Sjl139090 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_SFSR,
19121772Sjl139090 			(void *)&opl_flt, sizeof (opl_async_flt_t), ue_queue,
19131772Sjl139090 			aflt->flt_panic);
19141772Sjl139090 		fm_panic("%sErrors(s)", "invalid SFSR");
19151772Sjl139090 	}
19161772Sjl139090 
19171772Sjl139090 	/*
19181772Sjl139090 	 * If either UE and MK bit is off, this is not valid UE error.
19191772Sjl139090 	 * If it is not valid UE error, clear UE & MK_UE bits to prevent
19201772Sjl139090 	 * mis-handling below.
19211772Sjl139090 	 * aflt->flt_stat keeps the original bits as a reference.
19221772Sjl139090 	 */
19231772Sjl139090 	if ((t_sfsr & (SFSR_MK_UE|SFSR_UE)) !=
19241772Sjl139090 	    (SFSR_MK_UE|SFSR_UE)) {
19251772Sjl139090 		t_sfsr &= ~(SFSR_MK_UE|SFSR_UE);
19261772Sjl139090 	}
19271772Sjl139090 
19281772Sjl139090 	/*
19291772Sjl139090 	 * If the trap occurred in privileged mode at TL=0, we need to check to
19301772Sjl139090 	 * see if we were executing in the kernel under on_trap() or t_lofault
19311772Sjl139090 	 * protection.  If so, modify the saved registers so that we return
19321772Sjl139090 	 * from the trap to the appropriate trampoline routine.
19331772Sjl139090 	 */
19341772Sjl139090 	if (!aflt->flt_panic && aflt->flt_priv && tl == 0) {
19351772Sjl139090 		if (curthread->t_ontrap != NULL) {
19361772Sjl139090 			on_trap_data_t *otp = curthread->t_ontrap;
19371772Sjl139090 
19381772Sjl139090 			if (otp->ot_prot & OT_DATA_EC) {
19391772Sjl139090 				aflt->flt_prot = (uchar_t)AFLT_PROT_EC;
19401772Sjl139090 				otp->ot_trap |= (ushort_t)OT_DATA_EC;
19411772Sjl139090 				rp->r_pc = otp->ot_trampoline;
19421772Sjl139090 				rp->r_npc = rp->r_pc + 4;
19431772Sjl139090 				trampolined = 1;
19441772Sjl139090 			}
19451772Sjl139090 
19461772Sjl139090 			if ((t_sfsr & (SFSR_TO | SFSR_BERR)) &&
19471772Sjl139090 			    (otp->ot_prot & OT_DATA_ACCESS)) {
19481772Sjl139090 				aflt->flt_prot = (uchar_t)AFLT_PROT_ACCESS;
19491772Sjl139090 				otp->ot_trap |= (ushort_t)OT_DATA_ACCESS;
19501772Sjl139090 				rp->r_pc = otp->ot_trampoline;
19511772Sjl139090 				rp->r_npc = rp->r_pc + 4;
19521772Sjl139090 				trampolined = 1;
19531772Sjl139090 				/*
19541772Sjl139090 				 * for peeks and caut_gets errors are expected
19551772Sjl139090 				 */
19561772Sjl139090 				hp = (ddi_acc_hdl_t *)otp->ot_handle;
19571772Sjl139090 				if (!hp)
19581772Sjl139090 					expected = DDI_FM_ERR_PEEK;
19591772Sjl139090 				else if (hp->ah_acc.devacc_attr_access ==
19601772Sjl139090 				    DDI_CAUTIOUS_ACC)
19611772Sjl139090 					expected = DDI_FM_ERR_EXPECTED;
19621772Sjl139090 			}
19631772Sjl139090 
19641772Sjl139090 		} else if (curthread->t_lofault) {
19651772Sjl139090 			aflt->flt_prot = AFLT_PROT_COPY;
19661772Sjl139090 			rp->r_g1 = EFAULT;
19671772Sjl139090 			rp->r_pc = curthread->t_lofault;
19681772Sjl139090 			rp->r_npc = rp->r_pc + 4;
19691772Sjl139090 			trampolined = 1;
19701772Sjl139090 		}
19711772Sjl139090 	}
19721772Sjl139090 
19731772Sjl139090 	/*
19741772Sjl139090 	 * If we're in user mode or we're doing a protected copy, we either
19751772Sjl139090 	 * want the ASTON code below to send a signal to the user process
19761772Sjl139090 	 * or we want to panic if aft_panic is set.
19771772Sjl139090 	 *
19781772Sjl139090 	 * If we're in privileged mode and we're not doing a copy, then we
19791772Sjl139090 	 * need to check if we've trampolined.  If we haven't trampolined,
19801772Sjl139090 	 * we should panic.
19811772Sjl139090 	 */
19821772Sjl139090 	if (!aflt->flt_priv || aflt->flt_prot == AFLT_PROT_COPY) {
19831772Sjl139090 		if (t_sfsr & (SFSR_ERRS & ~(SFSR_BERR | SFSR_TO)))
19841772Sjl139090 			aflt->flt_panic |= aft_panic;
19851772Sjl139090 	} else if (!trampolined) {
19861772Sjl139090 		aflt->flt_panic = 1;
19871772Sjl139090 	}
19881772Sjl139090 
19891772Sjl139090 	/*
19901772Sjl139090 	 * If we've trampolined due to a privileged TO or BERR, or if an
19911772Sjl139090 	 * unprivileged TO or BERR occurred, we don't want to enqueue an
19921772Sjl139090 	 * event for that TO or BERR.  Queue all other events (if any) besides
19931772Sjl139090 	 * the TO/BERR.
19941772Sjl139090 	 */
19951772Sjl139090 	log_sfsr = t_sfsr;
19961772Sjl139090 	if (trampolined) {
19971772Sjl139090 		log_sfsr &= ~(SFSR_TO | SFSR_BERR);
19981772Sjl139090 	} else if (!aflt->flt_priv) {
19991772Sjl139090 		/*
20001772Sjl139090 		 * User mode, suppress messages if
20011772Sjl139090 		 * cpu_berr_to_verbose is not set.
20021772Sjl139090 		 */
20031772Sjl139090 		if (!cpu_berr_to_verbose)
20041772Sjl139090 			log_sfsr &= ~(SFSR_TO | SFSR_BERR);
20051772Sjl139090 	}
20061772Sjl139090 
20071772Sjl139090 	if (((log_sfsr & SFSR_ERRS) &&
20081772Sjl139090 		(cpu_queue_events(&opl_flt, pr_reason, t_sfsr) == 0)) ||
20091772Sjl139090 	    ((t_sfsr & SFSR_ERRS) == 0)) {
20101772Sjl139090 		opl_flt.flt_type = OPL_CPU_INV_SFSR;
20111772Sjl139090 		aflt->flt_payload = FM_EREPORT_PAYLOAD_SYNC;
20121772Sjl139090 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_SFSR,
20131772Sjl139090 			(void *)&opl_flt, sizeof (opl_async_flt_t), ue_queue,
20141772Sjl139090 			aflt->flt_panic);
20151772Sjl139090 	}
20161772Sjl139090 
20171772Sjl139090 	if (t_sfsr & (SFSR_UE|SFSR_TO|SFSR_BERR)) {
20181772Sjl139090 		cpu_run_bus_error_handlers(aflt, expected);
20191772Sjl139090 	}
20201772Sjl139090 
20211772Sjl139090 	/*
20221772Sjl139090 	 * Panic here if aflt->flt_panic has been set.  Enqueued errors will
20231772Sjl139090 	 * be logged as part of the panic flow.
20241772Sjl139090 	 */
20251772Sjl139090 	if (aflt->flt_panic) {
20261772Sjl139090 		if (pr_reason[0] == 0)
20271772Sjl139090 			strcpy(pr_reason, "invalid SFSR ");
20281772Sjl139090 
20291772Sjl139090 		fm_panic("%sErrors(s)", pr_reason);
20301772Sjl139090 	}
20311772Sjl139090 
20321772Sjl139090 	/*
20331772Sjl139090 	 * If we queued an error and we are going to return from the trap and
20341772Sjl139090 	 * the error was in user mode or inside of a copy routine, set AST flag
20351772Sjl139090 	 * so the queue will be drained before returning to user mode.  The
20361772Sjl139090 	 * AST processing will also act on our failure policy.
20371772Sjl139090 	 */
20381772Sjl139090 	if (!aflt->flt_priv || aflt->flt_prot == AFLT_PROT_COPY) {
20391772Sjl139090 		int pcb_flag = 0;
20401772Sjl139090 
20411772Sjl139090 		if (t_sfsr & (SFSR_ERRS &
20421772Sjl139090 			~(SFSR_BERR | SFSR_TO)))
20431772Sjl139090 			pcb_flag |= ASYNC_HWERR;
20441772Sjl139090 
20451772Sjl139090 		if (t_sfsr & SFSR_BERR)
20461772Sjl139090 			pcb_flag |= ASYNC_BERR;
20471772Sjl139090 
20481772Sjl139090 		if (t_sfsr & SFSR_TO)
20491772Sjl139090 			pcb_flag |= ASYNC_BTO;
20501772Sjl139090 
20511772Sjl139090 		ttolwp(curthread)->lwp_pcb.pcb_flags |= pcb_flag;
20521772Sjl139090 		aston(curthread);
20531772Sjl139090 	}
20541772Sjl139090 }
20551772Sjl139090 
20561772Sjl139090 /*ARGSUSED*/
20571772Sjl139090 void
20581772Sjl139090 opl_cpu_urgent_error(struct regs *rp, ulong_t p_ugesr, ulong_t tl)
20591772Sjl139090 {
20601772Sjl139090 	opl_async_flt_t opl_flt;
20611772Sjl139090 	struct async_flt *aflt;
20621772Sjl139090 	char pr_reason[MAX_REASON_STRING];
20631772Sjl139090 
20641772Sjl139090 	/* normalize tl */
20651772Sjl139090 	tl = (tl >= 2 ? 1 : 0);
20661772Sjl139090 	pr_reason[0] = '\0';
20671772Sjl139090 
20681772Sjl139090 	bzero(&opl_flt, sizeof (opl_async_flt_t));
20691772Sjl139090 	aflt = (struct async_flt *)&opl_flt;
20701772Sjl139090 	aflt->flt_id = gethrtime_waitfree();
20711772Sjl139090 	aflt->flt_bus_id = getprocessorid();
20721772Sjl139090 	aflt->flt_inst = CPU->cpu_id;
20731772Sjl139090 	aflt->flt_stat = p_ugesr;
20741772Sjl139090 	aflt->flt_pc = (caddr_t)rp->r_pc;
20751772Sjl139090 	aflt->flt_class = (uchar_t)CPU_FAULT;
20761772Sjl139090 	aflt->flt_tl = tl;
20771772Sjl139090 	aflt->flt_priv = (uchar_t)
20781772Sjl139090 		(tl == 1 ? 1 : ((rp->r_tstate & TSTATE_PRIV) ?  1 : 0));
20791772Sjl139090 	aflt->flt_status = OPL_ECC_URGENT_TRAP;
20801772Sjl139090 	aflt->flt_panic = 1;
20811772Sjl139090 	/*
20821772Sjl139090 	 * HW does not set mod/sid in case of urgent error.
20831772Sjl139090 	 * So we have to set it here.
20841772Sjl139090 	 */
20851772Sjl139090 	opl_flt.flt_eid_mod = OPL_ERRID_CPU;
20861772Sjl139090 	opl_flt.flt_eid_sid = aflt->flt_inst;
20871772Sjl139090 
20881772Sjl139090 	if (cpu_queue_events(&opl_flt, pr_reason, p_ugesr) == 0) {
20891772Sjl139090 		opl_flt.flt_type = OPL_CPU_INV_UGESR;
20901772Sjl139090 		aflt->flt_payload = FM_EREPORT_PAYLOAD_URGENT;
20911772Sjl139090 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_URG,
20921772Sjl139090 			(void *)&opl_flt, sizeof (opl_async_flt_t),
20931772Sjl139090 			ue_queue, aflt->flt_panic);
20941772Sjl139090 	}
20951772Sjl139090 
20961772Sjl139090 	fm_panic("Urgent Error");
20971772Sjl139090 }
20981772Sjl139090 
20991772Sjl139090 /*
21001772Sjl139090  * Initialization error counters resetting.
21011772Sjl139090  */
21021772Sjl139090 /* ARGSUSED */
21031772Sjl139090 static void
21041772Sjl139090 opl_ras_online(void *arg, cpu_t *cp, cyc_handler_t *hdlr, cyc_time_t *when)
21051772Sjl139090 {
21061772Sjl139090 	hdlr->cyh_func = (cyc_func_t)ras_cntr_reset;
21071772Sjl139090 	hdlr->cyh_level = CY_LOW_LEVEL;
21081772Sjl139090 	hdlr->cyh_arg = (void *)(uintptr_t)cp->cpu_id;
21091772Sjl139090 
21101772Sjl139090 	when->cyt_when = cp->cpu_id * (((hrtime_t)NANOSEC * 10)/ NCPU);
21111772Sjl139090 	when->cyt_interval = (hrtime_t)NANOSEC * opl_async_check_interval;
21121772Sjl139090 }
21131772Sjl139090 
21141772Sjl139090 void
21151772Sjl139090 cpu_mp_init(void)
21161772Sjl139090 {
21171772Sjl139090 	cyc_omni_handler_t hdlr;
21181772Sjl139090 
21191772Sjl139090 	hdlr.cyo_online = opl_ras_online;
21201772Sjl139090 	hdlr.cyo_offline = NULL;
21211772Sjl139090 	hdlr.cyo_arg = NULL;
21221772Sjl139090 	mutex_enter(&cpu_lock);
21231772Sjl139090 	(void) cyclic_add_omni(&hdlr);
21241772Sjl139090 	mutex_exit(&cpu_lock);
21251772Sjl139090 }
21261772Sjl139090 
21271772Sjl139090 /*ARGSUSED*/
21281772Sjl139090 void
21291772Sjl139090 mmu_init_kernel_pgsz(struct hat *hat)
21301772Sjl139090 {
21311772Sjl139090 }
21321772Sjl139090 
21331772Sjl139090 size_t
21341772Sjl139090 mmu_get_kernel_lpsize(size_t lpsize)
21351772Sjl139090 {
21361772Sjl139090 	uint_t tte;
21371772Sjl139090 
21381772Sjl139090 	if (lpsize == 0) {
21391772Sjl139090 		/* no setting for segkmem_lpsize in /etc/system: use default */
21401772Sjl139090 		return (MMU_PAGESIZE4M);
21411772Sjl139090 	}
21421772Sjl139090 
21431772Sjl139090 	for (tte = TTE8K; tte <= TTE4M; tte++) {
21441772Sjl139090 		if (lpsize == TTEBYTES(tte))
21451772Sjl139090 			return (lpsize);
21461772Sjl139090 	}
21471772Sjl139090 
21481772Sjl139090 	return (TTEBYTES(TTE8K));
21491772Sjl139090 }
21501772Sjl139090 
21511772Sjl139090 /*
21521772Sjl139090  * The following are functions that are unused in
21531772Sjl139090  * OPL cpu module. They are defined here to resolve
21541772Sjl139090  * dependencies in the "unix" module.
21551772Sjl139090  * Unused functions that should never be called in
21561772Sjl139090  * OPL are coded with ASSERT(0).
21571772Sjl139090  */
21581772Sjl139090 
21591772Sjl139090 void
21601772Sjl139090 cpu_disable_errors(void)
21611772Sjl139090 {}
21621772Sjl139090 
21631772Sjl139090 void
21641772Sjl139090 cpu_enable_errors(void)
21651772Sjl139090 { ASSERT(0); }
21661772Sjl139090 
21671772Sjl139090 /*ARGSUSED*/
21681772Sjl139090 void
21691772Sjl139090 cpu_ce_scrub_mem_err(struct async_flt *ecc, boolean_t t)
21701772Sjl139090 { ASSERT(0); }
21711772Sjl139090 
21721772Sjl139090 /*ARGSUSED*/
21731772Sjl139090 void
21741772Sjl139090 cpu_faulted_enter(struct cpu *cp)
21751772Sjl139090 {}
21761772Sjl139090 
21771772Sjl139090 /*ARGSUSED*/
21781772Sjl139090 void
21791772Sjl139090 cpu_faulted_exit(struct cpu *cp)
21801772Sjl139090 {}
21811772Sjl139090 
21821772Sjl139090 /*ARGSUSED*/
21831772Sjl139090 void
21841772Sjl139090 cpu_check_allcpus(struct async_flt *aflt)
21851772Sjl139090 {}
21861772Sjl139090 
21871772Sjl139090 /*ARGSUSED*/
21881772Sjl139090 void
21891772Sjl139090 cpu_ce_log_err(struct async_flt *aflt, errorq_elem_t *t)
21901772Sjl139090 { ASSERT(0); }
21911772Sjl139090 
21921772Sjl139090 /*ARGSUSED*/
21931772Sjl139090 void
21941772Sjl139090 cpu_check_ce(int flag, uint64_t pa, caddr_t va, uint_t psz)
21951772Sjl139090 { ASSERT(0); }
21961772Sjl139090 
21971772Sjl139090 /*ARGSUSED*/
21981772Sjl139090 void
21991772Sjl139090 cpu_ce_count_unum(struct async_flt *ecc, int len, char *unum)
22001772Sjl139090 { ASSERT(0); }
22011772Sjl139090 
22021772Sjl139090 /*ARGSUSED*/
22031772Sjl139090 void
22041772Sjl139090 cpu_busy_ecache_scrub(struct cpu *cp)
22051772Sjl139090 {}
22061772Sjl139090 
22071772Sjl139090 /*ARGSUSED*/
22081772Sjl139090 void
22091772Sjl139090 cpu_idle_ecache_scrub(struct cpu *cp)
22101772Sjl139090 {}
22111772Sjl139090 
22121772Sjl139090 /* ARGSUSED */
22131772Sjl139090 void
22141772Sjl139090 cpu_change_speed(uint64_t divisor, uint64_t arg2)
22151772Sjl139090 { ASSERT(0); }
22161772Sjl139090 
22171772Sjl139090 void
22181772Sjl139090 cpu_init_cache_scrub(void)
22191772Sjl139090 {}
22201772Sjl139090 
22211772Sjl139090 /* ARGSUSED */
22221772Sjl139090 int
22231772Sjl139090 cpu_get_mem_sid(char *unum, char *buf, int buflen, int *lenp)
22241772Sjl139090 {
22251772Sjl139090 	return (ENOTSUP);
22261772Sjl139090 }
22271772Sjl139090 
22281772Sjl139090 /* ARGSUSED */
22291772Sjl139090 int
22301772Sjl139090 cpu_get_mem_addr(char *unum, char *sid, uint64_t offset, uint64_t *addrp)
22311772Sjl139090 {
22321772Sjl139090 	return (ENOTSUP);
22331772Sjl139090 }
22341772Sjl139090 
22351772Sjl139090 /* ARGSUSED */
22361772Sjl139090 int
22371772Sjl139090 cpu_get_mem_offset(uint64_t flt_addr, uint64_t *offp)
22381772Sjl139090 {
22391772Sjl139090 	return (ENOTSUP);
22401772Sjl139090 }
22411772Sjl139090 
22421772Sjl139090 /*ARGSUSED*/
22431772Sjl139090 void
22441772Sjl139090 itlb_rd_entry(uint_t entry, tte_t *tte, uint64_t *va_tag)
22451772Sjl139090 { ASSERT(0); }
22461772Sjl139090 
22471772Sjl139090 /*ARGSUSED*/
22481772Sjl139090 void
22491772Sjl139090 dtlb_rd_entry(uint_t entry, tte_t *tte, uint64_t *va_tag)
22501772Sjl139090 { ASSERT(0); }
2251