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