xref: /illumos-gate/usr/src/uts/sun4u/cpu/opl_olympus.c (revision c9d93b53)
125cf1a30Sjl /*
225cf1a30Sjl  * CDDL HEADER START
325cf1a30Sjl  *
425cf1a30Sjl  * The contents of this file are subject to the terms of the
525cf1a30Sjl  * Common Development and Distribution License (the "License").
625cf1a30Sjl  * You may not use this file except in compliance with the License.
725cf1a30Sjl  *
825cf1a30Sjl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925cf1a30Sjl  * or http://www.opensolaris.org/os/licensing.
1025cf1a30Sjl  * See the License for the specific language governing permissions
1125cf1a30Sjl  * and limitations under the License.
1225cf1a30Sjl  *
1325cf1a30Sjl  * When distributing Covered Code, include this CDDL HEADER in each
1425cf1a30Sjl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525cf1a30Sjl  * If applicable, add the following below this CDDL HEADER, with the
1625cf1a30Sjl  * fields enclosed by brackets "[]" replaced with your own identifying
1725cf1a30Sjl  * information: Portions Copyright [yyyy] [name of copyright owner]
1825cf1a30Sjl  *
1925cf1a30Sjl  * CDDL HEADER END
2025cf1a30Sjl  */
2125cf1a30Sjl /*
22*c9d93b53SJames Anderson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2325cf1a30Sjl  * Use is subject to license terms.
2425cf1a30Sjl  */
2525cf1a30Sjl 
26e98fafb9Sjl /*
27e98fafb9Sjl  * Support for Olympus-C (SPARC64-VI) and Jupiter (SPARC64-VII).
28e98fafb9Sjl  */
29e98fafb9Sjl 
3025cf1a30Sjl #include <sys/types.h>
3125cf1a30Sjl #include <sys/systm.h>
3225cf1a30Sjl #include <sys/ddi.h>
3325cf1a30Sjl #include <sys/sysmacros.h>
3425cf1a30Sjl #include <sys/archsystm.h>
3525cf1a30Sjl #include <sys/vmsystm.h>
3625cf1a30Sjl #include <sys/machparam.h>
3725cf1a30Sjl #include <sys/machsystm.h>
3825cf1a30Sjl #include <sys/machthread.h>
3925cf1a30Sjl #include <sys/cpu.h>
4025cf1a30Sjl #include <sys/cmp.h>
4125cf1a30Sjl #include <sys/elf_SPARC.h>
4225cf1a30Sjl #include <vm/vm_dep.h>
4325cf1a30Sjl #include <vm/hat_sfmmu.h>
4425cf1a30Sjl #include <vm/seg_kpm.h>
453cbfd4cfSjimand #include <vm/seg_kmem.h>
4625cf1a30Sjl #include <sys/cpuvar.h>
4725cf1a30Sjl #include <sys/opl_olympus_regs.h>
4825cf1a30Sjl #include <sys/opl_module.h>
4925cf1a30Sjl #include <sys/async.h>
5025cf1a30Sjl #include <sys/cmn_err.h>
5125cf1a30Sjl #include <sys/debug.h>
5225cf1a30Sjl #include <sys/dditypes.h>
5325cf1a30Sjl #include <sys/cpu_module.h>
5425cf1a30Sjl #include <sys/sysmacros.h>
5525cf1a30Sjl #include <sys/intreg.h>
5625cf1a30Sjl #include <sys/clock.h>
5725cf1a30Sjl #include <sys/platform_module.h>
5825cf1a30Sjl #include <sys/ontrap.h>
5925cf1a30Sjl #include <sys/panic.h>
6025cf1a30Sjl #include <sys/memlist.h>
6125cf1a30Sjl #include <sys/ndifm.h>
6225cf1a30Sjl #include <sys/ddifm.h>
6325cf1a30Sjl #include <sys/fm/protocol.h>
6425cf1a30Sjl #include <sys/fm/util.h>
6525cf1a30Sjl #include <sys/fm/cpu/SPARC64-VI.h>
6625cf1a30Sjl #include <sys/dtrace.h>
6725cf1a30Sjl #include <sys/watchpoint.h>
6825cf1a30Sjl #include <sys/promif.h>
6925cf1a30Sjl 
7025cf1a30Sjl /*
7125cf1a30Sjl  * Internal functions.
7225cf1a30Sjl  */
7325cf1a30Sjl static int cpu_sync_log_err(void *flt);
7425cf1a30Sjl static void cpu_payload_add_aflt(struct async_flt *, nvlist_t *, nvlist_t *);
7525cf1a30Sjl static void opl_cpu_sync_error(struct regs *, ulong_t, ulong_t, uint_t, uint_t);
7625cf1a30Sjl static int  cpu_flt_in_memory(opl_async_flt_t *, uint64_t);
771ba18ff1Sjimand static int prom_SPARC64VII_support_enabled(void);
7850eff769Smb static void opl_ta3();
79febcc4a5Sjimand static int plat_prom_preserve_kctx_is_supported(void);
8025cf1a30Sjl 
8125cf1a30Sjl /*
8225cf1a30Sjl  * Error counters resetting interval.
8325cf1a30Sjl  */
8425cf1a30Sjl static int opl_async_check_interval = 60;		/* 1 min */
8525cf1a30Sjl 
861e2e7a75Shuah uint_t cpu_impl_dual_pgsz = 1;
8725cf1a30Sjl 
8825cf1a30Sjl /*
8925cf1a30Sjl  * PA[22:0] represent Displacement in Jupiter
9025cf1a30Sjl  * configuration space.
9125cf1a30Sjl  */
9225cf1a30Sjl uint_t	root_phys_addr_lo_mask = 0x7fffffu;
9325cf1a30Sjl 
9425cf1a30Sjl /*
9525cf1a30Sjl  * set in /etc/system to control logging of user BERR/TO's
9625cf1a30Sjl  */
9725cf1a30Sjl int cpu_berr_to_verbose = 0;
9825cf1a30Sjl 
99e98fafb9Sjl /*
100e98fafb9Sjl  * Set to 1 if booted with all Jupiter cpus (all-Jupiter features enabled).
101e98fafb9Sjl  */
102e98fafb9Sjl int cpu_alljupiter = 0;
103e98fafb9Sjl 
1041426d65aSsm /*
1051426d65aSsm  * The sfmmu_cext field to be used by processes in a shared context domain.
1061426d65aSsm  */
1071426d65aSsm static uchar_t shctx_cext = TAGACCEXT_MKSZPAIR(DEFAULT_ISM_PAGESZC, TTE8K);
1081426d65aSsm 
10925cf1a30Sjl static int min_ecache_size;
11025cf1a30Sjl static uint_t priv_hcl_1;
11125cf1a30Sjl static uint_t priv_hcl_2;
11225cf1a30Sjl static uint_t priv_hcl_4;
11325cf1a30Sjl static uint_t priv_hcl_8;
11425cf1a30Sjl 
11525cf1a30Sjl /*
11625cf1a30Sjl  * Olympus error log
11725cf1a30Sjl  */
11825cf1a30Sjl static opl_errlog_t	*opl_err_log;
119b9a675d4Smb static int		opl_cpu0_log_setup;
12025cf1a30Sjl 
12150eff769Smb /*
12250eff769Smb  * OPL ta 3 save area.
12350eff769Smb  */
12450eff769Smb char	*opl_ta3_save;
12550eff769Smb 
12625cf1a30Sjl /*
12725cf1a30Sjl  * UE is classified into four classes (MEM, CHANNEL, CPU, PATH).
12825cf1a30Sjl  * No any other ecc_type_info insertion is allowed in between the following
12925cf1a30Sjl  * four UE classess.
13025cf1a30Sjl  */
13125cf1a30Sjl ecc_type_to_info_t ecc_type_to_info[] = {
13225cf1a30Sjl 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
13325cf1a30Sjl 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
13425cf1a30Sjl 	FM_EREPORT_CPU_UE_MEM,
13525cf1a30Sjl 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
13625cf1a30Sjl 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
13725cf1a30Sjl 	FM_EREPORT_CPU_UE_CHANNEL,
13825cf1a30Sjl 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
13925cf1a30Sjl 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
14025cf1a30Sjl 	FM_EREPORT_CPU_UE_CPU,
14125cf1a30Sjl 	SFSR_UE,	"UE ",	(OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_UE,
14225cf1a30Sjl 	"Uncorrectable ECC",  FM_EREPORT_PAYLOAD_SYNC,
14325cf1a30Sjl 	FM_EREPORT_CPU_UE_PATH,
14425cf1a30Sjl 	SFSR_BERR, "BERR ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
14525cf1a30Sjl 	"Bus Error",  FM_EREPORT_PAYLOAD_SYNC,
14625cf1a30Sjl 	FM_EREPORT_CPU_BERR,
14725cf1a30Sjl 	SFSR_TO, "TO ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
14825cf1a30Sjl 	"Bus Timeout",  FM_EREPORT_PAYLOAD_SYNC,
14925cf1a30Sjl 	FM_EREPORT_CPU_BTO,
15025cf1a30Sjl 	SFSR_TLB_MUL, "TLB_MUL ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
15125cf1a30Sjl 	"TLB MultiHit",  FM_EREPORT_PAYLOAD_SYNC,
15225cf1a30Sjl 	FM_EREPORT_CPU_MTLB,
15325cf1a30Sjl 	SFSR_TLB_PRT, "TLB_PRT ", (OPL_ECC_SYNC_TRAP), OPL_CPU_SYNC_OTHERS,
15425cf1a30Sjl 	"TLB Parity",  FM_EREPORT_PAYLOAD_SYNC,
15525cf1a30Sjl 	FM_EREPORT_CPU_TLBP,
15625cf1a30Sjl 
15725cf1a30Sjl 	UGESR_IAUG_CRE, "IAUG_CRE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
15825cf1a30Sjl 	"IAUG CRE",  FM_EREPORT_PAYLOAD_URGENT,
15925cf1a30Sjl 	FM_EREPORT_CPU_CRE,
16025cf1a30Sjl 	UGESR_IAUG_TSBCTXT, "IAUG_TSBCTXT",
16125cf1a30Sjl 	OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
16225cf1a30Sjl 	"IAUG TSBCTXT",  FM_EREPORT_PAYLOAD_URGENT,
16325cf1a30Sjl 	FM_EREPORT_CPU_TSBCTX,
16425cf1a30Sjl 	UGESR_IUG_TSBP, "IUG_TSBP", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
16525cf1a30Sjl 	"IUG TSBP",  FM_EREPORT_PAYLOAD_URGENT,
16625cf1a30Sjl 	FM_EREPORT_CPU_TSBP,
16725cf1a30Sjl 	UGESR_IUG_PSTATE, "IUG_PSTATE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
16825cf1a30Sjl 	"IUG PSTATE",  FM_EREPORT_PAYLOAD_URGENT,
16925cf1a30Sjl 	FM_EREPORT_CPU_PSTATE,
17025cf1a30Sjl 	UGESR_IUG_TSTATE, "IUG_TSTATE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
17125cf1a30Sjl 	"IUG TSTATE",  FM_EREPORT_PAYLOAD_URGENT,
17225cf1a30Sjl 	FM_EREPORT_CPU_TSTATE,
17325cf1a30Sjl 	UGESR_IUG_F, "IUG_F", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
17425cf1a30Sjl 	"IUG FREG",  FM_EREPORT_PAYLOAD_URGENT,
17525cf1a30Sjl 	FM_EREPORT_CPU_IUG_F,
17625cf1a30Sjl 	UGESR_IUG_R, "IUG_R", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
17725cf1a30Sjl 	"IUG RREG",  FM_EREPORT_PAYLOAD_URGENT,
17825cf1a30Sjl 	FM_EREPORT_CPU_IUG_R,
17925cf1a30Sjl 	UGESR_AUG_SDC, "AUG_SDC", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
18025cf1a30Sjl 	"AUG SDC",  FM_EREPORT_PAYLOAD_URGENT,
18125cf1a30Sjl 	FM_EREPORT_CPU_SDC,
18225cf1a30Sjl 	UGESR_IUG_WDT, "IUG_WDT", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
18325cf1a30Sjl 	"IUG WDT",  FM_EREPORT_PAYLOAD_URGENT,
18425cf1a30Sjl 	FM_EREPORT_CPU_WDT,
18525cf1a30Sjl 	UGESR_IUG_DTLB, "IUG_DTLB", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
18625cf1a30Sjl 	"IUG DTLB",  FM_EREPORT_PAYLOAD_URGENT,
18725cf1a30Sjl 	FM_EREPORT_CPU_DTLB,
18825cf1a30Sjl 	UGESR_IUG_ITLB, "IUG_ITLB", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
18925cf1a30Sjl 	"IUG ITLB",  FM_EREPORT_PAYLOAD_URGENT,
19025cf1a30Sjl 	FM_EREPORT_CPU_ITLB,
19125cf1a30Sjl 	UGESR_IUG_COREERR, "IUG_COREERR",
19225cf1a30Sjl 	OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
19325cf1a30Sjl 	"IUG COREERR",  FM_EREPORT_PAYLOAD_URGENT,
19425cf1a30Sjl 	FM_EREPORT_CPU_CORE,
19525cf1a30Sjl 	UGESR_MULTI_DAE, "MULTI_DAE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
19625cf1a30Sjl 	"MULTI DAE",  FM_EREPORT_PAYLOAD_URGENT,
19725cf1a30Sjl 	FM_EREPORT_CPU_DAE,
19825cf1a30Sjl 	UGESR_MULTI_IAE, "MULTI_IAE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
19925cf1a30Sjl 	"MULTI IAE",  FM_EREPORT_PAYLOAD_URGENT,
20025cf1a30Sjl 	FM_EREPORT_CPU_IAE,
20125cf1a30Sjl 	UGESR_MULTI_UGE, "MULTI_UGE", OPL_ECC_URGENT_TRAP, OPL_CPU_URGENT,
20225cf1a30Sjl 	"MULTI UGE",  FM_EREPORT_PAYLOAD_URGENT,
20325cf1a30Sjl 	FM_EREPORT_CPU_UGE,
20425cf1a30Sjl 	0,		NULL,		0,		0,
20525cf1a30Sjl 	NULL,  0,	   0,
20625cf1a30Sjl };
20725cf1a30Sjl 
20825cf1a30Sjl int (*p2get_mem_info)(int synd_code, uint64_t paddr,
20925cf1a30Sjl 		uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
21025cf1a30Sjl 		int *segsp, int *banksp, int *mcidp);
21125cf1a30Sjl 
21225cf1a30Sjl 
21325cf1a30Sjl /*
21450eff769Smb  * Setup trap handlers for 0xA, 0x32, 0x40 trap types
21550eff769Smb  * and "ta 3" and "ta 4".
21625cf1a30Sjl  */
21725cf1a30Sjl void
cpu_init_trap(void)21825cf1a30Sjl cpu_init_trap(void)
21925cf1a30Sjl {
22025cf1a30Sjl 	OPL_SET_TRAP(tt0_iae, opl_serr_instr);
22125cf1a30Sjl 	OPL_SET_TRAP(tt1_iae, opl_serr_instr);
22225cf1a30Sjl 	OPL_SET_TRAP(tt0_dae, opl_serr_instr);
22325cf1a30Sjl 	OPL_SET_TRAP(tt1_dae, opl_serr_instr);
22425cf1a30Sjl 	OPL_SET_TRAP(tt0_asdat, opl_ugerr_instr);
22525cf1a30Sjl 	OPL_SET_TRAP(tt1_asdat, opl_ugerr_instr);
22650eff769Smb 	OPL_SET_TRAP(tt0_flushw, opl_ta3_instr);
22750eff769Smb 	OPL_PATCH_28(opl_cleanw_patch, opl_ta4_instr);
22825cf1a30Sjl }
22925cf1a30Sjl 
23025cf1a30Sjl static int
getintprop(pnode_t node,char * name,int deflt)23125cf1a30Sjl getintprop(pnode_t node, char *name, int deflt)
23225cf1a30Sjl {
23325cf1a30Sjl 	int	value;
23425cf1a30Sjl 
23525cf1a30Sjl 	switch (prom_getproplen(node, name)) {
23625cf1a30Sjl 	case sizeof (int):
23725cf1a30Sjl 		(void) prom_getprop(node, name, (caddr_t)&value);
23825cf1a30Sjl 		break;
23925cf1a30Sjl 
24025cf1a30Sjl 	default:
24125cf1a30Sjl 		value = deflt;
24225cf1a30Sjl 		break;
24325cf1a30Sjl 	}
24425cf1a30Sjl 
24525cf1a30Sjl 	return (value);
24625cf1a30Sjl }
24725cf1a30Sjl 
24825cf1a30Sjl /*
24925cf1a30Sjl  * Set the magic constants of the implementation.
25025cf1a30Sjl  */
25125cf1a30Sjl /*ARGSUSED*/
25225cf1a30Sjl void
cpu_fiximp(pnode_t dnode)25325cf1a30Sjl cpu_fiximp(pnode_t dnode)
25425cf1a30Sjl {
25525cf1a30Sjl 	int i, a;
25625cf1a30Sjl 	extern int vac_size, vac_shift;
25725cf1a30Sjl 	extern uint_t vac_mask;
25825cf1a30Sjl 
25925cf1a30Sjl 	static struct {
26025cf1a30Sjl 		char	*name;
26125cf1a30Sjl 		int	*var;
26225cf1a30Sjl 		int	defval;
26325cf1a30Sjl 	} prop[] = {
26425cf1a30Sjl 		"l1-dcache-size", &dcache_size, OPL_DCACHE_SIZE,
26525cf1a30Sjl 		"l1-dcache-line-size", &dcache_linesize, OPL_DCACHE_LSIZE,
26625cf1a30Sjl 		"l1-icache-size", &icache_size, OPL_ICACHE_SIZE,
26725cf1a30Sjl 		"l1-icache-line-size", &icache_linesize, OPL_ICACHE_LSIZE,
26825cf1a30Sjl 		"l2-cache-size", &ecache_size, OPL_ECACHE_SIZE,
26925cf1a30Sjl 		"l2-cache-line-size", &ecache_alignsize, OPL_ECACHE_LSIZE,
27025cf1a30Sjl 		"l2-cache-associativity", &ecache_associativity, OPL_ECACHE_NWAY
27125cf1a30Sjl 	};
27225cf1a30Sjl 
27325cf1a30Sjl 	for (i = 0; i < sizeof (prop) / sizeof (prop[0]); i++)
27425cf1a30Sjl 		*prop[i].var = getintprop(dnode, prop[i].name, prop[i].defval);
27525cf1a30Sjl 
27625cf1a30Sjl 	ecache_setsize = ecache_size / ecache_associativity;
27725cf1a30Sjl 
27825cf1a30Sjl 	vac_size = OPL_VAC_SIZE;
27925cf1a30Sjl 	vac_mask = MMU_PAGEMASK & (vac_size - 1);
28025cf1a30Sjl 	i = 0; a = vac_size;
28125cf1a30Sjl 	while (a >>= 1)
28225cf1a30Sjl 		++i;
28325cf1a30Sjl 	vac_shift = i;
28425cf1a30Sjl 	shm_alignment = vac_size;
28525cf1a30Sjl 	vac = 1;
28625cf1a30Sjl }
28725cf1a30Sjl 
288e98fafb9Sjl /*
289e98fafb9Sjl  * Enable features for Jupiter-only domains.
290e98fafb9Sjl  */
291e98fafb9Sjl void
cpu_fix_alljupiter(void)292e98fafb9Sjl cpu_fix_alljupiter(void)
293e98fafb9Sjl {
2941ba18ff1Sjimand 	if (!prom_SPARC64VII_support_enabled()) {
2951ba18ff1Sjimand 		/*
2961ba18ff1Sjimand 		 * Do not enable all-Jupiter features and do not turn on
2971ba18ff1Sjimand 		 * the cpu_alljupiter flag.
2981ba18ff1Sjimand 		 */
2991ba18ff1Sjimand 		return;
3001ba18ff1Sjimand 	}
3011ba18ff1Sjimand 
302e98fafb9Sjl 	cpu_alljupiter = 1;
303e98fafb9Sjl 
304e98fafb9Sjl 	/*
305e98fafb9Sjl 	 * Enable ima hwcap for Jupiter-only domains.  DR will prevent
306e98fafb9Sjl 	 * addition of Olympus-C to all-Jupiter domains to preserve ima
307e98fafb9Sjl 	 * hwcap semantics.
308e98fafb9Sjl 	 */
309e98fafb9Sjl 	cpu_hwcap_flags |= AV_SPARC_IMA;
3101426d65aSsm 
3111426d65aSsm 	/*
31220064263SSean McEnroe 	 * Enable shared context support.
3131426d65aSsm 	 */
31420064263SSean McEnroe 	shctx_on = 1;
315e98fafb9Sjl }
316e98fafb9Sjl 
31751f7a915Shyw #ifdef	OLYMPUS_C_REV_B_ERRATA_XCALL
31851f7a915Shyw /*
31951f7a915Shyw  * Quick and dirty way to redefine locally in
32051f7a915Shyw  * OPL the value of IDSR_BN_SETS to 31 instead
32151f7a915Shyw  * of the standard 32 value. This is to workaround
32251f7a915Shyw  * REV_B of Olympus_c processor's problem in handling
32351f7a915Shyw  * more than 31 xcall broadcast.
32451f7a915Shyw  */
32551f7a915Shyw #undef	IDSR_BN_SETS
32651f7a915Shyw #define	IDSR_BN_SETS    31
32751f7a915Shyw #endif	/* OLYMPUS_C_REV_B_ERRATA_XCALL */
32851f7a915Shyw 
32925cf1a30Sjl void
send_mondo_set(cpuset_t set)33025cf1a30Sjl send_mondo_set(cpuset_t set)
33125cf1a30Sjl {
33225cf1a30Sjl 	int lo, busy, nack, shipped = 0;
33325cf1a30Sjl 	uint16_t i, cpuids[IDSR_BN_SETS];
33425cf1a30Sjl 	uint64_t idsr, nackmask = 0, busymask, curnack, curbusy;
33525cf1a30Sjl 	uint64_t starttick, endtick, tick, lasttick;
33625cf1a30Sjl #if (NCPU > IDSR_BN_SETS)
33725cf1a30Sjl 	int index = 0;
33825cf1a30Sjl 	int ncpuids = 0;
33925cf1a30Sjl #endif
340227649d1Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
34125cf1a30Sjl 	int bn_sets = IDSR_BN_SETS;
34225cf1a30Sjl 	uint64_t ver;
34325cf1a30Sjl 
34425cf1a30Sjl 	ASSERT(NCPU > bn_sets);
34525cf1a30Sjl #endif
34625cf1a30Sjl 
34725cf1a30Sjl 	ASSERT(!CPUSET_ISNULL(set));
34825cf1a30Sjl 	starttick = lasttick = gettick();
34925cf1a30Sjl 
350227649d1Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
35125cf1a30Sjl 	ver = ultra_getver();
35225cf1a30Sjl 	if (((ULTRA_VER_IMPL(ver)) == OLYMPUS_C_IMPL) &&
353e98fafb9Sjl 	    ((OLYMPUS_REV_MASK(ver)) == OLYMPUS_C_A))
35425cf1a30Sjl 		bn_sets = 1;
35525cf1a30Sjl #endif
35625cf1a30Sjl 
35725cf1a30Sjl #if (NCPU <= IDSR_BN_SETS)
35825cf1a30Sjl 	for (i = 0; i < NCPU; i++)
35925cf1a30Sjl 		if (CPU_IN_SET(set, i)) {
36025cf1a30Sjl 			shipit(i, shipped);
36125cf1a30Sjl 			nackmask |= IDSR_NACK_BIT(shipped);
36225cf1a30Sjl 			cpuids[shipped++] = i;
36325cf1a30Sjl 			CPUSET_DEL(set, i);
36425cf1a30Sjl 			if (CPUSET_ISNULL(set))
36525cf1a30Sjl 				break;
36625cf1a30Sjl 		}
36725cf1a30Sjl 	CPU_STATS_ADDQ(CPU, sys, xcalls, shipped);
36825cf1a30Sjl #else
36925cf1a30Sjl 	for (i = 0; i < NCPU; i++)
37025cf1a30Sjl 		if (CPU_IN_SET(set, i)) {
37125cf1a30Sjl 			ncpuids++;
37225cf1a30Sjl 
37325cf1a30Sjl 			/*
37425cf1a30Sjl 			 * Ship only to the first (IDSR_BN_SETS) CPUs.  If we
37525cf1a30Sjl 			 * find we have shipped to more than (IDSR_BN_SETS)
37625cf1a30Sjl 			 * CPUs, set "index" to the highest numbered CPU in
37725cf1a30Sjl 			 * the set so we can ship to other CPUs a bit later on.
37825cf1a30Sjl 			 */
379227649d1Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
38025cf1a30Sjl 			if (shipped < bn_sets) {
38125cf1a30Sjl #else
38225cf1a30Sjl 			if (shipped < IDSR_BN_SETS) {
38325cf1a30Sjl #endif
38425cf1a30Sjl 				shipit(i, shipped);
38525cf1a30Sjl 				nackmask |= IDSR_NACK_BIT(shipped);
38625cf1a30Sjl 				cpuids[shipped++] = i;
38725cf1a30Sjl 				CPUSET_DEL(set, i);
38825cf1a30Sjl 				if (CPUSET_ISNULL(set))
38925cf1a30Sjl 					break;
39025cf1a30Sjl 			} else
39125cf1a30Sjl 				index = (int)i;
39225cf1a30Sjl 		}
39325cf1a30Sjl 
39425cf1a30Sjl 	CPU_STATS_ADDQ(CPU, sys, xcalls, ncpuids);
39525cf1a30Sjl #endif
39625cf1a30Sjl 
39725cf1a30Sjl 	busymask = IDSR_NACK_TO_BUSY(nackmask);
39825cf1a30Sjl 	busy = nack = 0;
39925cf1a30Sjl 	endtick = starttick + xc_tick_limit;
40025cf1a30Sjl 	for (;;) {
40125cf1a30Sjl 		idsr = getidsr();
40225cf1a30Sjl #if (NCPU <= IDSR_BN_SETS)
40325cf1a30Sjl 		if (idsr == 0)
40425cf1a30Sjl 			break;
40525cf1a30Sjl #else
40625cf1a30Sjl 		if (idsr == 0 && shipped == ncpuids)
40725cf1a30Sjl 			break;
40825cf1a30Sjl #endif
40925cf1a30Sjl 		tick = gettick();
41025cf1a30Sjl 		/*
41125cf1a30Sjl 		 * If there is a big jump between the current tick
41225cf1a30Sjl 		 * count and lasttick, we have probably hit a break
41325cf1a30Sjl 		 * point.  Adjust endtick accordingly to avoid panic.
41425cf1a30Sjl 		 */
41525cf1a30Sjl 		if (tick > (lasttick + xc_tick_jump_limit))
41625cf1a30Sjl 			endtick += (tick - lasttick);
41725cf1a30Sjl 		lasttick = tick;
41825cf1a30Sjl 		if (tick > endtick) {
41925cf1a30Sjl 			if (panic_quiesce)
42025cf1a30Sjl 				return;
421e98fafb9Sjl 			cmn_err(CE_CONT, "send mondo timeout [%d NACK %d "
422e98fafb9Sjl 			    "BUSY]\nIDSR 0x%" PRIx64 "  cpuids:",
423e98fafb9Sjl 			    nack, busy, idsr);
424227649d1Shyw #ifdef	OLYMPUS_C_REV_A_ERRATA_XCALL
42525cf1a30Sjl 			for (i = 0; i < bn_sets; i++) {
42625cf1a30Sjl #else
42725cf1a30Sjl 			for (i = 0; i < IDSR_BN_SETS; i++) {
42825cf1a30Sjl #endif
42925cf1a30Sjl 				if (idsr & (IDSR_NACK_BIT(i) |
43025cf1a30Sjl 				    IDSR_BUSY_BIT(i))) {
431e98fafb9Sjl 					cmn_err(CE_CONT, " 0x%x", cpuids[i]);
43225cf1a30Sjl 				}
43325cf1a30Sjl 			}
43425cf1a30Sjl 			cmn_err(CE_CONT, "\n");
43525cf1a30Sjl 			cmn_err(CE_PANIC, "send_mondo_set: timeout");
43625cf1a30Sjl 		}
43725cf1a30Sjl 		curnack = idsr & nackmask;
43825cf1a30Sjl 		curbusy = idsr & busymask;
439227649d1Shyw 
440227649d1Shyw #ifdef OLYMPUS_C_REV_B_ERRATA_XCALL
441227649d1Shyw 		/*
442227649d1Shyw 		 * Only proceed to send more xcalls if all the
443227649d1Shyw 		 * cpus in the previous IDSR_BN_SETS were completed.
444227649d1Shyw 		 */
445227649d1Shyw 		if (curbusy) {
446227649d1Shyw 			busy++;
447227649d1Shyw 			continue;
448227649d1Shyw 		}
449227649d1Shyw #endif /* OLYMPUS_C_REV_B_ERRATA_XCALL */
450227649d1Shyw 
45125cf1a30Sjl #if (NCPU > IDSR_BN_SETS)
45225cf1a30Sjl 		if (shipped < ncpuids) {
45325cf1a30Sjl 			uint64_t cpus_left;
45425cf1a30Sjl 			uint16_t next = (uint16_t)index;
45525cf1a30Sjl 
45625cf1a30Sjl 			cpus_left = ~(IDSR_NACK_TO_BUSY(curnack) | curbusy) &
45725cf1a30Sjl 			    busymask;
45825cf1a30Sjl 
45925cf1a30Sjl 			if (cpus_left) {
46025cf1a30Sjl 				do {
46125cf1a30Sjl 					/*
46225cf1a30Sjl 					 * Sequence through and ship to the
46325cf1a30Sjl 					 * remainder of the CPUs in the system
46425cf1a30Sjl 					 * (e.g. other than the first
46525cf1a30Sjl 					 * (IDSR_BN_SETS)) in reverse order.
46625cf1a30Sjl 					 */
46725cf1a30Sjl 					lo = lowbit(cpus_left) - 1;
46825cf1a30Sjl 					i = IDSR_BUSY_IDX(lo);
46925cf1a30Sjl 					shipit(next, i);
47025cf1a30Sjl 					shipped++;
47125cf1a30Sjl 					cpuids[i] = next;
47225cf1a30Sjl 
47325cf1a30Sjl 					/*
47425cf1a30Sjl 					 * If we've processed all the CPUs,
47525cf1a30Sjl 					 * exit the loop now and save
47625cf1a30Sjl 					 * instructions.
47725cf1a30Sjl 					 */
47825cf1a30Sjl 					if (shipped == ncpuids)
47925cf1a30Sjl 						break;
48025cf1a30Sjl 
48125cf1a30Sjl 					for ((index = ((int)next - 1));
482e98fafb9Sjl 					    index >= 0; index--)
48325cf1a30Sjl 						if (CPU_IN_SET(set, index)) {
48425cf1a30Sjl 							next = (uint16_t)index;
48525cf1a30Sjl 							break;
48625cf1a30Sjl 						}
48725cf1a30Sjl 
48825cf1a30Sjl 					cpus_left &= ~(1ull << lo);
48925cf1a30Sjl 				} while (cpus_left);
49025cf1a30Sjl 				continue;
49125cf1a30Sjl 			}
49225cf1a30Sjl 		}
49325cf1a30Sjl #endif
494227649d1Shyw #ifndef	OLYMPUS_C_REV_B_ERRATA_XCALL
49525cf1a30Sjl 		if (curbusy) {
49625cf1a30Sjl 			busy++;
49725cf1a30Sjl 			continue;
49825cf1a30Sjl 		}
499227649d1Shyw #endif	/* OLYMPUS_C_REV_B_ERRATA_XCALL */
50025cf1a30Sjl #ifdef SEND_MONDO_STATS
50125cf1a30Sjl 		{
50225cf1a30Sjl 			int n = gettick() - starttick;
50325cf1a30Sjl 			if (n < 8192)
50425cf1a30Sjl 				x_nack_stimes[n >> 7]++;
50525cf1a30Sjl 		}
50625cf1a30Sjl #endif
50725cf1a30Sjl 		while (gettick() < (tick + sys_clock_mhz))
50825cf1a30Sjl 			;
50925cf1a30Sjl 		do {
51025cf1a30Sjl 			lo = lowbit(curnack) - 1;
51125cf1a30Sjl 			i = IDSR_NACK_IDX(lo);
51225cf1a30Sjl 			shipit(cpuids[i], i);
51325cf1a30Sjl 			curnack &= ~(1ull << lo);
51425cf1a30Sjl 		} while (curnack);
51525cf1a30Sjl 		nack++;
51625cf1a30Sjl 		busy = 0;
51725cf1a30Sjl 	}
51825cf1a30Sjl #ifdef SEND_MONDO_STATS
51925cf1a30Sjl 	{
52025cf1a30Sjl 		int n = gettick() - starttick;
52125cf1a30Sjl 		if (n < 8192)
52225cf1a30Sjl 			x_set_stimes[n >> 7]++;
52325cf1a30Sjl 		else
52425cf1a30Sjl 			x_set_ltimes[(n >> 13) & 0xf]++;
52525cf1a30Sjl 	}
52625cf1a30Sjl 	x_set_cpus[shipped]++;
52725cf1a30Sjl #endif
52825cf1a30Sjl }
52925cf1a30Sjl 
53025cf1a30Sjl /*
53125cf1a30Sjl  * Cpu private initialization.
53225cf1a30Sjl  */
53325cf1a30Sjl void
53425cf1a30Sjl cpu_init_private(struct cpu *cp)
53525cf1a30Sjl {
536e98fafb9Sjl 	if (!((IS_OLYMPUS_C(cpunodes[cp->cpu_id].implementation)) ||
537e98fafb9Sjl 	    (IS_JUPITER(cpunodes[cp->cpu_id].implementation)))) {
538e98fafb9Sjl 		cmn_err(CE_PANIC, "CPU%d Impl %d: Only SPARC64-VI(I) is "
539e98fafb9Sjl 		    "supported", cp->cpu_id,
540e98fafb9Sjl 		    cpunodes[cp->cpu_id].implementation);
54125cf1a30Sjl 	}
54225cf1a30Sjl 
54325cf1a30Sjl 	adjust_hw_copy_limits(cpunodes[cp->cpu_id].ecache_size);
54425cf1a30Sjl }
54525cf1a30Sjl 
54625cf1a30Sjl void
54725cf1a30Sjl cpu_setup(void)
54825cf1a30Sjl {
54925cf1a30Sjl 	extern int at_flags;
55025cf1a30Sjl 	extern int cpc_has_overflow_intr;
55125cf1a30Sjl 	uint64_t cpu0_log;
55225cf1a30Sjl 	extern	 uint64_t opl_cpu0_err_log;
55325cf1a30Sjl 
55425cf1a30Sjl 	/*
55525cf1a30Sjl 	 * Initialize Error log Scratch register for error handling.
55625cf1a30Sjl 	 */
55725cf1a30Sjl 
55825cf1a30Sjl 	cpu0_log = va_to_pa(&opl_cpu0_err_log);
55925cf1a30Sjl 	opl_error_setup(cpu0_log);
560b9a675d4Smb 	opl_cpu0_log_setup = 1;
56125cf1a30Sjl 
56225cf1a30Sjl 	/*
56325cf1a30Sjl 	 * Enable MMU translating multiple page sizes for
56425cf1a30Sjl 	 * sITLB and sDTLB.
56525cf1a30Sjl 	 */
566*c9d93b53SJames Anderson 	cpu_early_feature_init();
56725cf1a30Sjl 
56825cf1a30Sjl 	/*
56925cf1a30Sjl 	 * Setup chip-specific trap handlers.
57025cf1a30Sjl 	 */
57125cf1a30Sjl 	cpu_init_trap();
57225cf1a30Sjl 
57325cf1a30Sjl 	cache |= (CACHE_VAC | CACHE_PTAG | CACHE_IOCOHERENT);
57425cf1a30Sjl 
57525cf1a30Sjl 	at_flags = EF_SPARC_32PLUS | EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3;
57625cf1a30Sjl 
57725cf1a30Sjl 	/*
57825cf1a30Sjl 	 * Due to the number of entries in the fully-associative tlb
57925cf1a30Sjl 	 * this may have to be tuned lower than in spitfire.
58025cf1a30Sjl 	 */
58125cf1a30Sjl 	pp_slots = MIN(8, MAXPP_SLOTS);
58225cf1a30Sjl 
58325cf1a30Sjl 	/*
58425cf1a30Sjl 	 * Block stores do not invalidate all pages of the d$, pagecopy
58525cf1a30Sjl 	 * et. al. need virtual translations with virtual coloring taken
58625cf1a30Sjl 	 * into consideration.  prefetch/ldd will pollute the d$ on the
58725cf1a30Sjl 	 * load side.
58825cf1a30Sjl 	 */
58925cf1a30Sjl 	pp_consistent_coloring = PPAGE_STORE_VCOLORING | PPAGE_LOADS_POLLUTE;
59025cf1a30Sjl 
59125cf1a30Sjl 	if (use_page_coloring) {
59225cf1a30Sjl 		do_pg_coloring = 1;
59325cf1a30Sjl 	}
59425cf1a30Sjl 
59525cf1a30Sjl 	isa_list =
59625cf1a30Sjl 	    "sparcv9+vis2 sparcv9+vis sparcv9 "
59725cf1a30Sjl 	    "sparcv8plus+vis2 sparcv8plus+vis sparcv8plus "
59825cf1a30Sjl 	    "sparcv8 sparcv8-fsmuld sparcv7 sparc";
59925cf1a30Sjl 
6001820c2cdShyw 	cpu_hwcap_flags = AV_SPARC_VIS | AV_SPARC_VIS2 |
6011820c2cdShyw 	    AV_SPARC_POPC | AV_SPARC_FMAF;
60225cf1a30Sjl 
60325cf1a30Sjl 	/*
60425cf1a30Sjl 	 * On SPARC64-VI, there's no hole in the virtual address space
60525cf1a30Sjl 	 */
60625cf1a30Sjl 	hole_start = hole_end = 0;
60725cf1a30Sjl 
60825cf1a30Sjl 	/*
60925cf1a30Sjl 	 * The kpm mapping window.
61025cf1a30Sjl 	 * kpm_size:
61125cf1a30Sjl 	 *	The size of a single kpm range.
61225cf1a30Sjl 	 *	The overall size will be: kpm_size * vac_colors.
61325cf1a30Sjl 	 * kpm_vbase:
61425cf1a30Sjl 	 *	The virtual start address of the kpm range within the kernel
61525cf1a30Sjl 	 *	virtual address space. kpm_vbase has to be kpm_size aligned.
61625cf1a30Sjl 	 */
61725cf1a30Sjl 	kpm_size = (size_t)(128ull * 1024 * 1024 * 1024 * 1024); /* 128TB */
61825cf1a30Sjl 	kpm_size_shift = 47;
61925cf1a30Sjl 	kpm_vbase = (caddr_t)0x8000000000000000ull; /* 8EB */
62025cf1a30Sjl 	kpm_smallpages = 1;
62125cf1a30Sjl 
62225cf1a30Sjl 	/*
62325cf1a30Sjl 	 * The traptrace code uses either %tick or %stick for
62425cf1a30Sjl 	 * timestamping.  We have %stick so we can use it.
62525cf1a30Sjl 	 */
62625cf1a30Sjl 	traptrace_use_stick = 1;
62725cf1a30Sjl 
62825cf1a30Sjl 	/*
62925cf1a30Sjl 	 * SPARC64-VI has a performance counter overflow interrupt
63025cf1a30Sjl 	 */
63125cf1a30Sjl 	cpc_has_overflow_intr = 1;
63225cf1a30Sjl 
63325cf1a30Sjl 	/*
63425cf1a30Sjl 	 * Declare that this architecture/cpu combination does not support
63525cf1a30Sjl 	 * fpRAS.
63625cf1a30Sjl 	 */
63725cf1a30Sjl 	fpras_implemented = 0;
63825cf1a30Sjl }
63925cf1a30Sjl 
64025cf1a30Sjl /*
64125cf1a30Sjl  * Called by setcpudelay
64225cf1a30Sjl  */
64325cf1a30Sjl void
64425cf1a30Sjl cpu_init_tick_freq(void)
64525cf1a30Sjl {
64625cf1a30Sjl 	/*
64725cf1a30Sjl 	 * For SPARC64-VI we want to use the system clock rate as
64825cf1a30Sjl 	 * the basis for low level timing, due to support of mixed
64925cf1a30Sjl 	 * speed CPUs and power managment.
65025cf1a30Sjl 	 */
65125cf1a30Sjl 	if (system_clock_freq == 0)
65225cf1a30Sjl 		cmn_err(CE_PANIC, "setcpudelay: invalid system_clock_freq");
65325cf1a30Sjl 
65425cf1a30Sjl 	sys_tick_freq = system_clock_freq;
65525cf1a30Sjl }
65625cf1a30Sjl 
65725cf1a30Sjl #ifdef SEND_MONDO_STATS
65825cf1a30Sjl uint32_t x_one_stimes[64];
65925cf1a30Sjl uint32_t x_one_ltimes[16];
66025cf1a30Sjl uint32_t x_set_stimes[64];
66125cf1a30Sjl uint32_t x_set_ltimes[16];
66225cf1a30Sjl uint32_t x_set_cpus[NCPU];
66325cf1a30Sjl uint32_t x_nack_stimes[64];
66425cf1a30Sjl #endif
66525cf1a30Sjl 
66625cf1a30Sjl /*
66725cf1a30Sjl  * Note: A version of this function is used by the debugger via the KDI,
66825cf1a30Sjl  * and must be kept in sync with this version.  Any changes made to this
66925cf1a30Sjl  * function to support new chips or to accomodate errata must also be included
67025cf1a30Sjl  * in the KDI-specific version.  See us3_kdi.c.
67125cf1a30Sjl  */
67225cf1a30Sjl void
67325cf1a30Sjl send_one_mondo(int cpuid)
67425cf1a30Sjl {
67525cf1a30Sjl 	int busy, nack;
67625cf1a30Sjl 	uint64_t idsr, starttick, endtick, tick, lasttick;
67725cf1a30Sjl 	uint64_t busymask;
67825cf1a30Sjl 
67925cf1a30Sjl 	CPU_STATS_ADDQ(CPU, sys, xcalls, 1);
68025cf1a30Sjl 	starttick = lasttick = gettick();
68125cf1a30Sjl 	shipit(cpuid, 0);
68225cf1a30Sjl 	endtick = starttick + xc_tick_limit;
68325cf1a30Sjl 	busy = nack = 0;
68425cf1a30Sjl 	busymask = IDSR_BUSY;
68525cf1a30Sjl 	for (;;) {
68625cf1a30Sjl 		idsr = getidsr();
68725cf1a30Sjl 		if (idsr == 0)
68825cf1a30Sjl 			break;
68925cf1a30Sjl 
69025cf1a30Sjl 		tick = gettick();
69125cf1a30Sjl 		/*
69225cf1a30Sjl 		 * If there is a big jump between the current tick
69325cf1a30Sjl 		 * count and lasttick, we have probably hit a break
69425cf1a30Sjl 		 * point.  Adjust endtick accordingly to avoid panic.
69525cf1a30Sjl 		 */
69625cf1a30Sjl 		if (tick > (lasttick + xc_tick_jump_limit))
69725cf1a30Sjl 			endtick += (tick - lasttick);
69825cf1a30Sjl 		lasttick = tick;
69925cf1a30Sjl 		if (tick > endtick) {
70025cf1a30Sjl 			if (panic_quiesce)
70125cf1a30Sjl 				return;
702e98fafb9Sjl 			cmn_err(CE_PANIC, "send mondo timeout (target 0x%x) "
703e98fafb9Sjl 			    "[%d NACK %d BUSY]", cpuid, nack, busy);
70425cf1a30Sjl 		}
70525cf1a30Sjl 
70625cf1a30Sjl 		if (idsr & busymask) {
70725cf1a30Sjl 			busy++;
70825cf1a30Sjl 			continue;
70925cf1a30Sjl 		}
71025cf1a30Sjl 		drv_usecwait(1);
71125cf1a30Sjl 		shipit(cpuid, 0);
71225cf1a30Sjl 		nack++;
71325cf1a30Sjl 		busy = 0;
71425cf1a30Sjl 	}
71525cf1a30Sjl #ifdef SEND_MONDO_STATS
71625cf1a30Sjl 	{
71725cf1a30Sjl 		int n = gettick() - starttick;
71825cf1a30Sjl 		if (n < 8192)
71925cf1a30Sjl 			x_one_stimes[n >> 7]++;
72025cf1a30Sjl 		else
72125cf1a30Sjl 			x_one_ltimes[(n >> 13) & 0xf]++;
72225cf1a30Sjl 	}
72325cf1a30Sjl #endif
72425cf1a30Sjl }
72525cf1a30Sjl 
72625cf1a30Sjl /*
72725cf1a30Sjl  * init_mmu_page_sizes is set to one after the bootup time initialization
72825cf1a30Sjl  * via mmu_init_mmu_page_sizes, to indicate that mmu_page_sizes has a
72925cf1a30Sjl  * valid value.
73025cf1a30Sjl  *
73125cf1a30Sjl  * mmu_disable_ism_large_pages and mmu_disable_large_pages are the mmu-specific
73225cf1a30Sjl  * versions of disable_ism_large_pages and disable_large_pages, and feed back
73325cf1a30Sjl  * into those two hat variables at hat initialization time.
73425cf1a30Sjl  *
73525cf1a30Sjl  */
73625cf1a30Sjl int init_mmu_page_sizes = 0;
737ec25b48fSsusans 
738ec25b48fSsusans static uint_t mmu_disable_large_pages = 0;
739ec25b48fSsusans static uint_t mmu_disable_ism_large_pages = ((1 << TTE64K) |
740e12a8a13Ssusans 	(1 << TTE512K) | (1 << TTE32M) | (1 << TTE256M));
741ec25b48fSsusans static uint_t mmu_disable_auto_data_large_pages = ((1 << TTE64K) |
742e12a8a13Ssusans 	(1 << TTE512K) | (1 << TTE32M) | (1 << TTE256M));
743ec25b48fSsusans static uint_t mmu_disable_auto_text_large_pages = ((1 << TTE64K) |
744ec25b48fSsusans 	(1 << TTE512K));
74525cf1a30Sjl 
74625cf1a30Sjl /*
74725cf1a30Sjl  * Re-initialize mmu_page_sizes and friends, for SPARC64-VI mmu support.
74825cf1a30Sjl  * Called during very early bootup from check_cpus_set().
74925cf1a30Sjl  * Can be called to verify that mmu_page_sizes are set up correctly.
75025cf1a30Sjl  *
75125cf1a30Sjl  * Set Olympus defaults. We do not use the function parameter.
75225cf1a30Sjl  */
75320064263SSean McEnroe /*ARGSUSED*/
75420064263SSean McEnroe void
75520064263SSean McEnroe mmu_init_scd(sf_scd_t *scdp)
75620064263SSean McEnroe {
75720064263SSean McEnroe 	scdp->scd_sfmmup->sfmmu_cext = shctx_cext;
75820064263SSean McEnroe }
75920064263SSean McEnroe 
76025cf1a30Sjl /*ARGSUSED*/
76125cf1a30Sjl int
76225cf1a30Sjl mmu_init_mmu_page_sizes(int32_t not_used)
76325cf1a30Sjl {
76425cf1a30Sjl 	if (!init_mmu_page_sizes) {
76525cf1a30Sjl 		mmu_page_sizes = MMU_PAGE_SIZES;
76625cf1a30Sjl 		mmu_hashcnt = MAX_HASHCNT;
767e12a8a13Ssusans 		mmu_ism_pagesize = DEFAULT_ISM_PAGESIZE;
76825cf1a30Sjl 		mmu_exported_pagesize_mask = (1 << TTE8K) |
76925cf1a30Sjl 		    (1 << TTE64K) | (1 << TTE512K) | (1 << TTE4M) |
77025cf1a30Sjl 		    (1 << TTE32M) | (1 << TTE256M);
77125cf1a30Sjl 		init_mmu_page_sizes = 1;
77225cf1a30Sjl 		return (0);
77325cf1a30Sjl 	}
77425cf1a30Sjl 	return (1);
77525cf1a30Sjl }
77625cf1a30Sjl 
77725cf1a30Sjl /* SPARC64-VI worst case DTLB parameters */
77825cf1a30Sjl #ifndef	LOCKED_DTLB_ENTRIES
77925cf1a30Sjl #define	LOCKED_DTLB_ENTRIES	5	/* 2 user TSBs, 2 nucleus, + OBP */
78025cf1a30Sjl #endif
78125cf1a30Sjl #define	TOTAL_DTLB_ENTRIES	32
78225cf1a30Sjl #define	AVAIL_32M_ENTRIES	0
78325cf1a30Sjl #define	AVAIL_256M_ENTRIES	0
78425cf1a30Sjl #define	AVAIL_DTLB_ENTRIES	(TOTAL_DTLB_ENTRIES - LOCKED_DTLB_ENTRIES)
78525cf1a30Sjl static uint64_t ttecnt_threshold[MMU_PAGE_SIZES] = {
78625cf1a30Sjl 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES,
78725cf1a30Sjl 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES,
78825cf1a30Sjl 	AVAIL_DTLB_ENTRIES, AVAIL_DTLB_ENTRIES};
78925cf1a30Sjl 
79025cf1a30Sjl /*
79125cf1a30Sjl  * The function returns the mmu-specific values for the
792582cbfcbSjimand  * hat's disable_large_pages, disable_ism_large_pages, and
793ec25b48fSsusans  * disable_auto_data_large_pages and
794ec25b48fSsusans  * disable_text_data_large_pages variables.
79525cf1a30Sjl  */
796ec25b48fSsusans uint_t
79725cf1a30Sjl mmu_large_pages_disabled(uint_t flag)
79825cf1a30Sjl {
799ec25b48fSsusans 	uint_t pages_disable = 0;
800ec25b48fSsusans 	extern int use_text_pgsz64K;
801ec25b48fSsusans 	extern int use_text_pgsz512K;
80225cf1a30Sjl 
80325cf1a30Sjl 	if (flag == HAT_LOAD) {
80425cf1a30Sjl 		pages_disable =  mmu_disable_large_pages;
80525cf1a30Sjl 	} else if (flag == HAT_LOAD_SHARE) {
80625cf1a30Sjl 		pages_disable = mmu_disable_ism_large_pages;
807ec25b48fSsusans 	} else if (flag == HAT_AUTO_DATA) {
808ec25b48fSsusans 		pages_disable = mmu_disable_auto_data_large_pages;
809ec25b48fSsusans 	} else if (flag == HAT_AUTO_TEXT) {
810ec25b48fSsusans 		pages_disable = mmu_disable_auto_text_large_pages;
811ec25b48fSsusans 		if (use_text_pgsz512K) {
812ec25b48fSsusans 			pages_disable &= ~(1 << TTE512K);
813ec25b48fSsusans 		}
814ec25b48fSsusans 		if (use_text_pgsz64K) {
815ec25b48fSsusans 			pages_disable &= ~(1 << TTE64K);
816ec25b48fSsusans 		}
81725cf1a30Sjl 	}
81825cf1a30Sjl 	return (pages_disable);
81925cf1a30Sjl }
82025cf1a30Sjl 
82125cf1a30Sjl /*
82225cf1a30Sjl  * mmu_init_large_pages is called with the desired ism_pagesize parameter.
8231426d65aSsm  * It may be called from set_platform_defaults, if some value other than 4M
82425cf1a30Sjl  * is desired.  mmu_ism_pagesize is the tunable.  If it has a bad value,
82525cf1a30Sjl  * then only warn, since it would be bad form to panic due to a user typo.
82625cf1a30Sjl  *
82725cf1a30Sjl  * The function re-initializes the mmu_disable_ism_large_pages variable.
82825cf1a30Sjl  */
82925cf1a30Sjl void
83025cf1a30Sjl mmu_init_large_pages(size_t ism_pagesize)
83125cf1a30Sjl {
8321426d65aSsm 
83325cf1a30Sjl 	switch (ism_pagesize) {
83425cf1a30Sjl 	case MMU_PAGESIZE4M:
83525cf1a30Sjl 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
83625cf1a30Sjl 		    (1 << TTE512K) | (1 << TTE32M) | (1 << TTE256M));
837ec25b48fSsusans 		mmu_disable_auto_data_large_pages = ((1 << TTE64K) |
838582cbfcbSjimand 		    (1 << TTE512K) | (1 << TTE32M) | (1 << TTE256M));
8391426d65aSsm 		shctx_cext = TAGACCEXT_MKSZPAIR(TTE4M, TTE8K);
84025cf1a30Sjl 		break;
84125cf1a30Sjl 	case MMU_PAGESIZE32M:
84225cf1a30Sjl 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
84325cf1a30Sjl 		    (1 << TTE512K) | (1 << TTE256M));
844ec25b48fSsusans 		mmu_disable_auto_data_large_pages = ((1 << TTE64K) |
845582cbfcbSjimand 		    (1 << TTE512K) | (1 << TTE4M) | (1 << TTE256M));
846ec25b48fSsusans 		adjust_data_maxlpsize(ism_pagesize);
8471426d65aSsm 		shctx_cext = TAGACCEXT_MKSZPAIR(TTE32M, TTE8K);
84825cf1a30Sjl 		break;
84925cf1a30Sjl 	case MMU_PAGESIZE256M:
85025cf1a30Sjl 		mmu_disable_ism_large_pages = ((1 << TTE64K) |
85125cf1a30Sjl 		    (1 << TTE512K) | (1 << TTE32M));
852ec25b48fSsusans 		mmu_disable_auto_data_large_pages = ((1 << TTE64K) |
853582cbfcbSjimand 		    (1 << TTE512K) | (1 << TTE4M) | (1 << TTE32M));
854ec25b48fSsusans 		adjust_data_maxlpsize(ism_pagesize);
8551426d65aSsm 		shctx_cext = TAGACCEXT_MKSZPAIR(TTE256M, TTE8K);
85625cf1a30Sjl 		break;
85725cf1a30Sjl 	default:
85825cf1a30Sjl 		cmn_err(CE_WARN, "Unrecognized mmu_ism_pagesize value 0x%lx",
85925cf1a30Sjl 		    ism_pagesize);
86025cf1a30Sjl 		break;
86125cf1a30Sjl 	}
86225cf1a30Sjl }
86325cf1a30Sjl 
86425cf1a30Sjl /*
86525cf1a30Sjl  * Function to reprogram the TLBs when page sizes used
86625cf1a30Sjl  * by a process change significantly.
86725cf1a30Sjl  */
8681426d65aSsm static void
86922a594afSjimand mmu_setup_page_sizes(struct hat *hat, uint64_t *ttecnt, uint8_t *tmp_pgsz)
87025cf1a30Sjl {
87125cf1a30Sjl 	uint8_t pgsz0, pgsz1;
87225cf1a30Sjl 
87325cf1a30Sjl 	/*
87425cf1a30Sjl 	 * Don't program 2nd dtlb for kernel and ism hat
87525cf1a30Sjl 	 */
87622a594afSjimand 	ASSERT(hat->sfmmu_ismhat == NULL);
87722a594afSjimand 	ASSERT(hat != ksfmmup);
87825cf1a30Sjl 
87925cf1a30Sjl 	/*
88025cf1a30Sjl 	 * hat->sfmmu_pgsz[] is an array whose elements
88125cf1a30Sjl 	 * contain a sorted order of page sizes.  Element
88225cf1a30Sjl 	 * 0 is the most commonly used page size, followed
88325cf1a30Sjl 	 * by element 1, and so on.
88425cf1a30Sjl 	 *
88525cf1a30Sjl 	 * ttecnt[] is an array of per-page-size page counts
88625cf1a30Sjl 	 * mapped into the process.
88725cf1a30Sjl 	 *
88825cf1a30Sjl 	 * If the HAT's choice for page sizes is unsuitable,
88925cf1a30Sjl 	 * we can override it here.  The new values written
89025cf1a30Sjl 	 * to the array will be handed back to us later to
89125cf1a30Sjl 	 * do the actual programming of the TLB hardware.
89225cf1a30Sjl 	 *
89325cf1a30Sjl 	 */
89422a594afSjimand 	pgsz0 = (uint8_t)MIN(tmp_pgsz[0], tmp_pgsz[1]);
89522a594afSjimand 	pgsz1 = (uint8_t)MAX(tmp_pgsz[0], tmp_pgsz[1]);
89625cf1a30Sjl 
89725cf1a30Sjl 	/*
89825cf1a30Sjl 	 * This implements PAGESIZE programming of the sTLB
89925cf1a30Sjl 	 * if large TTE counts don't exceed the thresholds.
90025cf1a30Sjl 	 */
90125cf1a30Sjl 	if (ttecnt[pgsz0] < ttecnt_threshold[pgsz0])
90225cf1a30Sjl 		pgsz0 = page_szc(MMU_PAGESIZE);
90325cf1a30Sjl 	if (ttecnt[pgsz1] < ttecnt_threshold[pgsz1])
90425cf1a30Sjl 		pgsz1 = page_szc(MMU_PAGESIZE);
90522a594afSjimand 	tmp_pgsz[0] = pgsz0;
90622a594afSjimand 	tmp_pgsz[1] = pgsz1;
90725cf1a30Sjl 	/* otherwise, accept what the HAT chose for us */
90825cf1a30Sjl }
90925cf1a30Sjl 
91025cf1a30Sjl /*
91125cf1a30Sjl  * The HAT calls this function when an MMU context is allocated so that we
91225cf1a30Sjl  * can reprogram the large TLBs appropriately for the new process using
91325cf1a30Sjl  * the context.
91425cf1a30Sjl  *
91525cf1a30Sjl  * The caller must hold the HAT lock.
91625cf1a30Sjl  */
91725cf1a30Sjl void
91825cf1a30Sjl mmu_set_ctx_page_sizes(struct hat *hat)
91925cf1a30Sjl {
92025cf1a30Sjl 	uint8_t pgsz0, pgsz1;
92125cf1a30Sjl 	uint8_t new_cext;
92225cf1a30Sjl 
92325cf1a30Sjl 	ASSERT(sfmmu_hat_lock_held(hat));
92425cf1a30Sjl 	/*
92525cf1a30Sjl 	 * Don't program 2nd dtlb for kernel and ism hat
92625cf1a30Sjl 	 */
92725cf1a30Sjl 	if (hat->sfmmu_ismhat || hat == ksfmmup)
92825cf1a30Sjl 		return;
92925cf1a30Sjl 
93025cf1a30Sjl 	/*
93125cf1a30Sjl 	 * If supported, reprogram the TLBs to a larger pagesize.
93225cf1a30Sjl 	 */
9331426d65aSsm 	if (hat->sfmmu_scdp != NULL) {
93420064263SSean McEnroe 		new_cext = hat->sfmmu_scdp->scd_sfmmup->sfmmu_cext;
93520064263SSean McEnroe 		ASSERT(new_cext == shctx_cext);
9361426d65aSsm 	} else {
9371426d65aSsm 		pgsz0 = hat->sfmmu_pgsz[0];
9381426d65aSsm 		pgsz1 = hat->sfmmu_pgsz[1];
9391426d65aSsm 		ASSERT(pgsz0 < mmu_page_sizes);
9401426d65aSsm 		ASSERT(pgsz1 < mmu_page_sizes);
9411426d65aSsm 		new_cext = TAGACCEXT_MKSZPAIR(pgsz1, pgsz0);
9421426d65aSsm 	}
94325cf1a30Sjl 	if (hat->sfmmu_cext != new_cext) {
9441e2e7a75Shuah #ifdef DEBUG
9451e2e7a75Shuah 		int i;
9461e2e7a75Shuah 		/*
9471e2e7a75Shuah 		 * assert cnum should be invalid, this is because pagesize
9481e2e7a75Shuah 		 * can only be changed after a proc's ctxs are invalidated.
9491e2e7a75Shuah 		 */
9501e2e7a75Shuah 		for (i = 0; i < max_mmu_ctxdoms; i++) {
9511e2e7a75Shuah 			ASSERT(hat->sfmmu_ctxs[i].cnum == INVALID_CONTEXT);
9521e2e7a75Shuah 		}
9531e2e7a75Shuah #endif /* DEBUG */
95425cf1a30Sjl 		hat->sfmmu_cext = new_cext;
95525cf1a30Sjl 	}
95625cf1a30Sjl 	/*
95725cf1a30Sjl 	 * sfmmu_setctx_sec() will take care of the
95825cf1a30Sjl 	 * rest of the dirty work for us.
95925cf1a30Sjl 	 */
96025cf1a30Sjl }
96125cf1a30Sjl 
96222a594afSjimand /*
96322a594afSjimand  * This function assumes that there are either four or six supported page
96422a594afSjimand  * sizes and at most two programmable TLBs, so we need to decide which
96522a594afSjimand  * page sizes are most important and then adjust the TLB page sizes
96622a594afSjimand  * accordingly (if supported).
96722a594afSjimand  *
96822a594afSjimand  * If these assumptions change, this function will need to be
96922a594afSjimand  * updated to support whatever the new limits are.
97022a594afSjimand  */
97122a594afSjimand void
97222a594afSjimand mmu_check_page_sizes(sfmmu_t *sfmmup, uint64_t *ttecnt)
97322a594afSjimand {
97422a594afSjimand 	uint64_t sortcnt[MMU_PAGE_SIZES];
97522a594afSjimand 	uint8_t tmp_pgsz[MMU_PAGE_SIZES];
97622a594afSjimand 	uint8_t i, j, max;
97722a594afSjimand 	uint16_t oldval, newval;
97822a594afSjimand 
97922a594afSjimand 	/*
98022a594afSjimand 	 * We only consider reprogramming the TLBs if one or more of
98122a594afSjimand 	 * the two most used page sizes changes and we're using
98222a594afSjimand 	 * large pages in this process.
98322a594afSjimand 	 */
98405d3dc4bSpaulsan 	if (SFMMU_LGPGS_INUSE(sfmmup)) {
98522a594afSjimand 		/* Sort page sizes. */
98622a594afSjimand 		for (i = 0; i < mmu_page_sizes; i++) {
98722a594afSjimand 			sortcnt[i] = ttecnt[i];
98822a594afSjimand 		}
98922a594afSjimand 		for (j = 0; j < mmu_page_sizes; j++) {
99022a594afSjimand 			for (i = mmu_page_sizes - 1, max = 0; i > 0; i--) {
99122a594afSjimand 				if (sortcnt[i] > sortcnt[max])
99222a594afSjimand 					max = i;
99322a594afSjimand 			}
99422a594afSjimand 			tmp_pgsz[j] = max;
99522a594afSjimand 			sortcnt[max] = 0;
99622a594afSjimand 		}
99722a594afSjimand 
99822a594afSjimand 		oldval = sfmmup->sfmmu_pgsz[0] << 8 | sfmmup->sfmmu_pgsz[1];
99922a594afSjimand 
100022a594afSjimand 		mmu_setup_page_sizes(sfmmup, ttecnt, tmp_pgsz);
100122a594afSjimand 
100222a594afSjimand 		/* Check 2 largest values after the sort. */
100322a594afSjimand 		newval = tmp_pgsz[0] << 8 | tmp_pgsz[1];
100422a594afSjimand 		if (newval != oldval) {
100522a594afSjimand 			sfmmu_reprog_pgsz_arr(sfmmup, tmp_pgsz);
100622a594afSjimand 		}
100722a594afSjimand 	}
100822a594afSjimand }
100922a594afSjimand 
101025cf1a30Sjl /*
101125cf1a30Sjl  * Return processor specific async error structure
101225cf1a30Sjl  * size used.
101325cf1a30Sjl  */
101425cf1a30Sjl int
101525cf1a30Sjl cpu_aflt_size(void)
101625cf1a30Sjl {
101725cf1a30Sjl 	return (sizeof (opl_async_flt_t));
101825cf1a30Sjl }
101925cf1a30Sjl 
102025cf1a30Sjl /*
102125cf1a30Sjl  * The cpu_sync_log_err() function is called via the [uc]e_drain() function to
102225cf1a30Sjl  * post-process CPU events that are dequeued.  As such, it can be invoked
102325cf1a30Sjl  * from softint context, from AST processing in the trap() flow, or from the
102425cf1a30Sjl  * panic flow.  We decode the CPU-specific data, and take appropriate actions.
102525cf1a30Sjl  * Historically this entry point was used to log the actual cmn_err(9F) text;
102625cf1a30Sjl  * now with FMA it is used to prepare 'flt' to be converted into an ereport.
102725cf1a30Sjl  * With FMA this function now also returns a flag which indicates to the
102825cf1a30Sjl  * caller whether the ereport should be posted (1) or suppressed (0).
102925cf1a30Sjl  */
103025cf1a30Sjl /*ARGSUSED*/
103125cf1a30Sjl static int
103225cf1a30Sjl cpu_sync_log_err(void *flt)
103325cf1a30Sjl {
103425cf1a30Sjl 	opl_async_flt_t *opl_flt = (opl_async_flt_t *)flt;
103525cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)flt;
103625cf1a30Sjl 
103725cf1a30Sjl 	/*
103825cf1a30Sjl 	 * No extra processing of urgent error events.
103925cf1a30Sjl 	 * Always generate ereports for these events.
104025cf1a30Sjl 	 */
104125cf1a30Sjl 	if (aflt->flt_status == OPL_ECC_URGENT_TRAP)
104225cf1a30Sjl 		return (1);
104325cf1a30Sjl 
104425cf1a30Sjl 	/*
104525cf1a30Sjl 	 * Additional processing for synchronous errors.
104625cf1a30Sjl 	 */
104725cf1a30Sjl 	switch (opl_flt->flt_type) {
104825cf1a30Sjl 	case OPL_CPU_INV_SFSR:
104925cf1a30Sjl 		return (1);
105025cf1a30Sjl 
105125cf1a30Sjl 	case OPL_CPU_SYNC_UE:
105225cf1a30Sjl 		/*
105325cf1a30Sjl 		 * The validity: SFSR_MK_UE bit has been checked
105425cf1a30Sjl 		 * in opl_cpu_sync_error()
105525cf1a30Sjl 		 * No more check is required.
105625cf1a30Sjl 		 *
105725cf1a30Sjl 		 * opl_flt->flt_eid_mod and flt_eid_sid have been set by H/W,
105825cf1a30Sjl 		 * and they have been retrieved in cpu_queue_events()
105925cf1a30Sjl 		 */
106025cf1a30Sjl 
106125cf1a30Sjl 		if (opl_flt->flt_eid_mod == OPL_ERRID_MEM) {
106225cf1a30Sjl 			ASSERT(aflt->flt_in_memory);
106325cf1a30Sjl 			/*
106425cf1a30Sjl 			 * We want to skip logging only if ALL the following
106525cf1a30Sjl 			 * conditions are true:
106625cf1a30Sjl 			 *
106725cf1a30Sjl 			 *	1. We are not panicing already.
106825cf1a30Sjl 			 *	2. The error is a memory error.
106925cf1a30Sjl 			 *	3. There is only one error.
107025cf1a30Sjl 			 *	4. The error is on a retired page.
107125cf1a30Sjl 			 *	5. The error occurred under on_trap
107225cf1a30Sjl 			 *	protection AFLT_PROT_EC
107325cf1a30Sjl 			 */
107425cf1a30Sjl 			if (!panicstr && aflt->flt_prot == AFLT_PROT_EC &&
107525cf1a30Sjl 			    page_retire_check(aflt->flt_addr, NULL) == 0) {
107625cf1a30Sjl 				/*
107725cf1a30Sjl 				 * Do not log an error from
107825cf1a30Sjl 				 * the retired page
107925cf1a30Sjl 				 */
108025cf1a30Sjl 				softcall(ecc_page_zero, (void *)aflt->flt_addr);
108125cf1a30Sjl 				return (0);
108225cf1a30Sjl 			}
108325cf1a30Sjl 			if (!panicstr)
108425cf1a30Sjl 				cpu_page_retire(opl_flt);
108525cf1a30Sjl 		}
108625cf1a30Sjl 		return (1);
108725cf1a30Sjl 
108825cf1a30Sjl 	case OPL_CPU_SYNC_OTHERS:
108925cf1a30Sjl 		/*
109025cf1a30Sjl 		 * For the following error cases, the processor HW does
109125cf1a30Sjl 		 * not set the flt_eid_mod/flt_eid_sid. Instead, SW will attempt
109225cf1a30Sjl 		 * to assign appropriate values here to reflect what we
109325cf1a30Sjl 		 * think is the most likely cause of the problem w.r.t to
109425cf1a30Sjl 		 * the particular error event.  For Buserr and timeout
109525cf1a30Sjl 		 * error event, we will assign OPL_ERRID_CHANNEL as the
109625cf1a30Sjl 		 * most likely reason.  For TLB parity or multiple hit
109725cf1a30Sjl 		 * error events, we will assign the reason as
109825cf1a30Sjl 		 * OPL_ERRID_CPU (cpu related problem) and set the
109925cf1a30Sjl 		 * flt_eid_sid to point to the cpuid.
110025cf1a30Sjl 		 */
110125cf1a30Sjl 
110225cf1a30Sjl 		if (opl_flt->flt_bit & (SFSR_BERR|SFSR_TO)) {
110325cf1a30Sjl 			/*
110425cf1a30Sjl 			 * flt_eid_sid will not be used for this case.
110525cf1a30Sjl 			 */
110625cf1a30Sjl 			opl_flt->flt_eid_mod = OPL_ERRID_CHANNEL;
110725cf1a30Sjl 		}
110825cf1a30Sjl 		if (opl_flt->flt_bit & (SFSR_TLB_MUL|SFSR_TLB_PRT)) {
1109e98fafb9Sjl 			opl_flt->flt_eid_mod = OPL_ERRID_CPU;
1110e98fafb9Sjl 			opl_flt->flt_eid_sid = aflt->flt_inst;
111125cf1a30Sjl 		}
111225cf1a30Sjl 
111325cf1a30Sjl 		/*
111425cf1a30Sjl 		 * In case of no effective error bit
111525cf1a30Sjl 		 */
111625cf1a30Sjl 		if ((opl_flt->flt_bit & SFSR_ERRS) == 0) {
1117e98fafb9Sjl 			opl_flt->flt_eid_mod = OPL_ERRID_CPU;
1118e98fafb9Sjl 			opl_flt->flt_eid_sid = aflt->flt_inst;
111925cf1a30Sjl 		}
112025cf1a30Sjl 		break;
112125cf1a30Sjl 
112225cf1a30Sjl 		default:
112325cf1a30Sjl 			return (1);
112425cf1a30Sjl 	}
112525cf1a30Sjl 	return (1);
112625cf1a30Sjl }
112725cf1a30Sjl 
112825cf1a30Sjl /*
112925cf1a30Sjl  * Retire the bad page that may contain the flushed error.
113025cf1a30Sjl  */
113125cf1a30Sjl void
113225cf1a30Sjl cpu_page_retire(opl_async_flt_t *opl_flt)
113325cf1a30Sjl {
113425cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)opl_flt;
113525cf1a30Sjl 	(void) page_retire(aflt->flt_addr, PR_UE);
113625cf1a30Sjl }
113725cf1a30Sjl 
113825cf1a30Sjl /*
113925cf1a30Sjl  * Invoked by error_init() early in startup and therefore before
114025cf1a30Sjl  * startup_errorq() is called to drain any error Q -
114125cf1a30Sjl  *
114225cf1a30Sjl  * startup()
114325cf1a30Sjl  *   startup_end()
114425cf1a30Sjl  *     error_init()
114525cf1a30Sjl  *       cpu_error_init()
114625cf1a30Sjl  * errorq_init()
114725cf1a30Sjl  *   errorq_drain()
114825cf1a30Sjl  * start_other_cpus()
114925cf1a30Sjl  *
115025cf1a30Sjl  * The purpose of this routine is to create error-related taskqs.  Taskqs
115125cf1a30Sjl  * are used for this purpose because cpu_lock can't be grabbed from interrupt
115225cf1a30Sjl  * context.
115325cf1a30Sjl  *
115425cf1a30Sjl  */
115525cf1a30Sjl /*ARGSUSED*/
115625cf1a30Sjl void
115725cf1a30Sjl cpu_error_init(int items)
115825cf1a30Sjl {
115925cf1a30Sjl 	opl_err_log = (opl_errlog_t *)
116025cf1a30Sjl 	    kmem_alloc(ERRLOG_ALLOC_SZ, KM_SLEEP);
116125cf1a30Sjl 	if ((uint64_t)opl_err_log & MMU_PAGEOFFSET)
116225cf1a30Sjl 		cmn_err(CE_PANIC, "The base address of the error log "
116325cf1a30Sjl 		    "is not page aligned");
116425cf1a30Sjl }
116525cf1a30Sjl 
116625cf1a30Sjl /*
116725cf1a30Sjl  * We route all errors through a single switch statement.
116825cf1a30Sjl  */
116925cf1a30Sjl void
117025cf1a30Sjl cpu_ue_log_err(struct async_flt *aflt)
117125cf1a30Sjl {
117225cf1a30Sjl 	switch (aflt->flt_class) {
117325cf1a30Sjl 	case CPU_FAULT:
117425cf1a30Sjl 		if (cpu_sync_log_err(aflt))
117525cf1a30Sjl 			cpu_ereport_post(aflt);
117625cf1a30Sjl 		break;
117725cf1a30Sjl 
117825cf1a30Sjl 	case BUS_FAULT:
117925cf1a30Sjl 		bus_async_log_err(aflt);
118025cf1a30Sjl 		break;
118125cf1a30Sjl 
118225cf1a30Sjl 	default:
118325cf1a30Sjl 		cmn_err(CE_WARN, "discarding async error %p with invalid "
118425cf1a30Sjl 		    "fault class (0x%x)", (void *)aflt, aflt->flt_class);
118525cf1a30Sjl 		return;
118625cf1a30Sjl 	}
118725cf1a30Sjl }
118825cf1a30Sjl 
118925cf1a30Sjl /*
119025cf1a30Sjl  * Routine for panic hook callback from panic_idle().
119125cf1a30Sjl  *
119225cf1a30Sjl  * Nothing to do here.
119325cf1a30Sjl  */
119425cf1a30Sjl void
119525cf1a30Sjl cpu_async_panic_callb(void)
119625cf1a30Sjl {
119725cf1a30Sjl }
119825cf1a30Sjl 
119925cf1a30Sjl /*
120025cf1a30Sjl  * Routine to return a string identifying the physical name
120125cf1a30Sjl  * associated with a memory/cache error.
120225cf1a30Sjl  */
120325cf1a30Sjl /*ARGSUSED*/
120425cf1a30Sjl int
120525cf1a30Sjl cpu_get_mem_unum(int synd_status, ushort_t flt_synd, uint64_t flt_stat,
120625cf1a30Sjl     uint64_t flt_addr, int flt_bus_id, int flt_in_memory,
120725cf1a30Sjl     ushort_t flt_status, char *buf, int buflen, int *lenp)
120825cf1a30Sjl {
120925cf1a30Sjl 	int synd_code;
121025cf1a30Sjl 	int ret;
121125cf1a30Sjl 
121225cf1a30Sjl 	/*
121325cf1a30Sjl 	 * An AFSR of -1 defaults to a memory syndrome.
121425cf1a30Sjl 	 */
121525cf1a30Sjl 	synd_code = (int)flt_synd;
121625cf1a30Sjl 
121725cf1a30Sjl 	if (&plat_get_mem_unum) {
121825cf1a30Sjl 		if ((ret = plat_get_mem_unum(synd_code, flt_addr, flt_bus_id,
1219e98fafb9Sjl 		    flt_in_memory, flt_status, buf, buflen, lenp)) != 0) {
122025cf1a30Sjl 			buf[0] = '\0';
122125cf1a30Sjl 			*lenp = 0;
122225cf1a30Sjl 		}
122325cf1a30Sjl 		return (ret);
122425cf1a30Sjl 	}
122525cf1a30Sjl 	buf[0] = '\0';
122625cf1a30Sjl 	*lenp = 0;
122725cf1a30Sjl 	return (ENOTSUP);
122825cf1a30Sjl }
122925cf1a30Sjl 
123025cf1a30Sjl /*
123125cf1a30Sjl  * Wrapper for cpu_get_mem_unum() routine that takes an
123225cf1a30Sjl  * async_flt struct rather than explicit arguments.
123325cf1a30Sjl  */
123425cf1a30Sjl int
123525cf1a30Sjl cpu_get_mem_unum_aflt(int synd_status, struct async_flt *aflt,
123625cf1a30Sjl     char *buf, int buflen, int *lenp)
123725cf1a30Sjl {
123825cf1a30Sjl 	/*
123925cf1a30Sjl 	 * We always pass -1 so that cpu_get_mem_unum will interpret this as a
124025cf1a30Sjl 	 * memory error.
124125cf1a30Sjl 	 */
124225cf1a30Sjl 	return (cpu_get_mem_unum(synd_status, aflt->flt_synd,
124325cf1a30Sjl 	    (uint64_t)-1,
124425cf1a30Sjl 	    aflt->flt_addr, aflt->flt_bus_id, aflt->flt_in_memory,
124525cf1a30Sjl 	    aflt->flt_status, buf, buflen, lenp));
124625cf1a30Sjl }
124725cf1a30Sjl 
124825cf1a30Sjl /*
124925cf1a30Sjl  * This routine is a more generic interface to cpu_get_mem_unum()
125025cf1a30Sjl  * that may be used by other modules (e.g. mm).
125125cf1a30Sjl  */
125225cf1a30Sjl /*ARGSUSED*/
125325cf1a30Sjl int
125425cf1a30Sjl cpu_get_mem_name(uint64_t synd, uint64_t *afsr, uint64_t afar,
125525cf1a30Sjl     char *buf, int buflen, int *lenp)
125625cf1a30Sjl {
125725cf1a30Sjl 	int synd_status, flt_in_memory, ret;
125825cf1a30Sjl 	ushort_t flt_status = 0;
125925cf1a30Sjl 	char unum[UNUM_NAMLEN];
126025cf1a30Sjl 
126125cf1a30Sjl 	/*
126225cf1a30Sjl 	 * Check for an invalid address.
126325cf1a30Sjl 	 */
126425cf1a30Sjl 	if (afar == (uint64_t)-1)
126525cf1a30Sjl 		return (ENXIO);
126625cf1a30Sjl 
126725cf1a30Sjl 	if (synd == (uint64_t)-1)
126825cf1a30Sjl 		synd_status = AFLT_STAT_INVALID;
126925cf1a30Sjl 	else
127025cf1a30Sjl 		synd_status = AFLT_STAT_VALID;
127125cf1a30Sjl 
127225cf1a30Sjl 	flt_in_memory = (*afsr & SFSR_MEMORY) &&
1273e98fafb9Sjl 	    pf_is_memory(afar >> MMU_PAGESHIFT);
127425cf1a30Sjl 
127525cf1a30Sjl 	ret = cpu_get_mem_unum(synd_status, (ushort_t)synd, *afsr, afar,
1276e98fafb9Sjl 	    CPU->cpu_id, flt_in_memory, flt_status, unum, UNUM_NAMLEN, lenp);
127725cf1a30Sjl 	if (ret != 0)
127825cf1a30Sjl 		return (ret);
127925cf1a30Sjl 
128025cf1a30Sjl 	if (*lenp >= buflen)
128125cf1a30Sjl 		return (ENAMETOOLONG);
128225cf1a30Sjl 
128325cf1a30Sjl 	(void) strncpy(buf, unum, buflen);
128425cf1a30Sjl 
128525cf1a30Sjl 	return (0);
128625cf1a30Sjl }
128725cf1a30Sjl 
128825cf1a30Sjl /*
128925cf1a30Sjl  * Routine to return memory information associated
129025cf1a30Sjl  * with a physical address and syndrome.
129125cf1a30Sjl  */
129225cf1a30Sjl /*ARGSUSED*/
129325cf1a30Sjl int
129425cf1a30Sjl cpu_get_mem_info(uint64_t synd, uint64_t afar,
129525cf1a30Sjl     uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
129625cf1a30Sjl     int *segsp, int *banksp, int *mcidp)
129725cf1a30Sjl {
129825cf1a30Sjl 	int synd_code = (int)synd;
129925cf1a30Sjl 
130025cf1a30Sjl 	if (afar == (uint64_t)-1)
130125cf1a30Sjl 		return (ENXIO);
130225cf1a30Sjl 
130325cf1a30Sjl 	if (p2get_mem_info != NULL)
1304e98fafb9Sjl 		return ((p2get_mem_info)(synd_code, afar, mem_sizep, seg_sizep,
1305e98fafb9Sjl 		    bank_sizep, segsp, banksp, mcidp));
130625cf1a30Sjl 	else
130725cf1a30Sjl 		return (ENOTSUP);
130825cf1a30Sjl }
130925cf1a30Sjl 
131025cf1a30Sjl /*
131125cf1a30Sjl  * Routine to return a string identifying the physical
131225cf1a30Sjl  * name associated with a cpuid.
131325cf1a30Sjl  */
131425cf1a30Sjl int
131525cf1a30Sjl cpu_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
131625cf1a30Sjl {
131725cf1a30Sjl 	int ret;
131825cf1a30Sjl 	char unum[UNUM_NAMLEN];
131925cf1a30Sjl 
132025cf1a30Sjl 	if (&plat_get_cpu_unum) {
1321e98fafb9Sjl 		if ((ret = plat_get_cpu_unum(cpuid, unum, UNUM_NAMLEN,
1322e98fafb9Sjl 		    lenp)) != 0)
132325cf1a30Sjl 			return (ret);
132425cf1a30Sjl 	} else {
132525cf1a30Sjl 		return (ENOTSUP);
132625cf1a30Sjl 	}
132725cf1a30Sjl 
132825cf1a30Sjl 	if (*lenp >= buflen)
132925cf1a30Sjl 		return (ENAMETOOLONG);
133025cf1a30Sjl 
133125cf1a30Sjl 	(void) strncpy(buf, unum, *lenp);
133225cf1a30Sjl 
133325cf1a30Sjl 	return (0);
133425cf1a30Sjl }
133525cf1a30Sjl 
133625cf1a30Sjl /*
133725cf1a30Sjl  * This routine exports the name buffer size.
133825cf1a30Sjl  */
133925cf1a30Sjl size_t
134025cf1a30Sjl cpu_get_name_bufsize()
134125cf1a30Sjl {
134225cf1a30Sjl 	return (UNUM_NAMLEN);
134325cf1a30Sjl }
134425cf1a30Sjl 
134525cf1a30Sjl /*
134625cf1a30Sjl  * Flush the entire ecache by ASI_L2_CNTL.U2_FLUSH
134725cf1a30Sjl  */
134825cf1a30Sjl void
134925cf1a30Sjl cpu_flush_ecache(void)
135025cf1a30Sjl {
135125cf1a30Sjl 	flush_ecache(ecache_flushaddr, cpunodes[CPU->cpu_id].ecache_size,
135225cf1a30Sjl 	    cpunodes[CPU->cpu_id].ecache_linesize);
135325cf1a30Sjl }
135425cf1a30Sjl 
135525cf1a30Sjl static uint8_t
135625cf1a30Sjl flt_to_trap_type(struct async_flt *aflt)
135725cf1a30Sjl {
135825cf1a30Sjl 	if (aflt->flt_status & OPL_ECC_ISYNC_TRAP)
135925cf1a30Sjl 		return (TRAP_TYPE_ECC_I);
136025cf1a30Sjl 	if (aflt->flt_status & OPL_ECC_DSYNC_TRAP)
136125cf1a30Sjl 		return (TRAP_TYPE_ECC_D);
136225cf1a30Sjl 	if (aflt->flt_status & OPL_ECC_URGENT_TRAP)
136325cf1a30Sjl 		return (TRAP_TYPE_URGENT);
136495400b06Sjimand 	return (TRAP_TYPE_UNKNOWN);
136525cf1a30Sjl }
136625cf1a30Sjl 
136725cf1a30Sjl /*
136825cf1a30Sjl  * Encode the data saved in the opl_async_flt_t struct into
136925cf1a30Sjl  * the FM ereport payload.
137025cf1a30Sjl  */
137125cf1a30Sjl /* ARGSUSED */
137225cf1a30Sjl static void
137325cf1a30Sjl cpu_payload_add_aflt(struct async_flt *aflt, nvlist_t *payload,
137425cf1a30Sjl 		nvlist_t *resource)
137525cf1a30Sjl {
137625cf1a30Sjl 	opl_async_flt_t *opl_flt = (opl_async_flt_t *)aflt;
137725cf1a30Sjl 	char unum[UNUM_NAMLEN];
137825cf1a30Sjl 	char sbuf[21]; /* sizeof (UINT64_MAX) + '\0' */
137925cf1a30Sjl 	int len;
138025cf1a30Sjl 
138125cf1a30Sjl 
138225cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_SFSR) {
138325cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_SFSR,
1384e98fafb9Sjl 		    DATA_TYPE_UINT64, aflt->flt_stat, NULL);
138525cf1a30Sjl 	}
138625cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_SFAR) {
138725cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_SFAR,
1388e98fafb9Sjl 		    DATA_TYPE_UINT64, aflt->flt_addr, NULL);
138925cf1a30Sjl 	}
139025cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_UGESR) {
139125cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_UGESR,
1392e98fafb9Sjl 		    DATA_TYPE_UINT64, aflt->flt_stat, NULL);
139325cf1a30Sjl 	}
139425cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_PC) {
139525cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_PC,
139625cf1a30Sjl 		    DATA_TYPE_UINT64, (uint64_t)aflt->flt_pc, NULL);
139725cf1a30Sjl 	}
139825cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_TL) {
139925cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_TL,
140025cf1a30Sjl 		    DATA_TYPE_UINT8, (uint8_t)aflt->flt_tl, NULL);
140125cf1a30Sjl 	}
140225cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_TT) {
140325cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_TT,
140425cf1a30Sjl 		    DATA_TYPE_UINT8, flt_to_trap_type(aflt), NULL);
140525cf1a30Sjl 	}
140625cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_PRIV) {
140725cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_PRIV,
140825cf1a30Sjl 		    DATA_TYPE_BOOLEAN_VALUE,
140925cf1a30Sjl 		    (aflt->flt_priv ? B_TRUE : B_FALSE), NULL);
141025cf1a30Sjl 	}
141125cf1a30Sjl 	if (aflt->flt_payload & FM_EREPORT_PAYLOAD_FLAG_FLT_STATUS) {
141225cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_FLT_STATUS,
1413e98fafb9Sjl 		    DATA_TYPE_UINT64, (uint64_t)aflt->flt_status, NULL);
141425cf1a30Sjl 	}
141525cf1a30Sjl 
141625cf1a30Sjl 	switch (opl_flt->flt_eid_mod) {
141725cf1a30Sjl 	case OPL_ERRID_CPU:
141825cf1a30Sjl 		(void) snprintf(sbuf, sizeof (sbuf), "%llX",
1419e98fafb9Sjl 		    (u_longlong_t)cpunodes[opl_flt->flt_eid_sid].device_id);
142025cf1a30Sjl 		(void) fm_fmri_cpu_set(resource, FM_CPU_SCHEME_VERSION,
1421e98fafb9Sjl 		    NULL, opl_flt->flt_eid_sid,
1422e98fafb9Sjl 		    (uint8_t *)&cpunodes[opl_flt->flt_eid_sid].version, sbuf);
1423e98fafb9Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_RESOURCE,
1424e98fafb9Sjl 		    DATA_TYPE_NVLIST, resource, NULL);
142525cf1a30Sjl 		break;
142625cf1a30Sjl 
142725cf1a30Sjl 	case OPL_ERRID_CHANNEL:
142825cf1a30Sjl 		/*
142925cf1a30Sjl 		 * No resource is created but the cpumem DE will find
143025cf1a30Sjl 		 * the defective path by retreiving EID from SFSR which is
143125cf1a30Sjl 		 * included in the payload.
143225cf1a30Sjl 		 */
143325cf1a30Sjl 		break;
143425cf1a30Sjl 
143525cf1a30Sjl 	case OPL_ERRID_MEM:
143625cf1a30Sjl 		(void) cpu_get_mem_unum_aflt(0, aflt, unum, UNUM_NAMLEN, &len);
1437e98fafb9Sjl 		(void) fm_fmri_mem_set(resource, FM_MEM_SCHEME_VERSION, NULL,
1438e98fafb9Sjl 		    unum, NULL, (uint64_t)-1);
143925cf1a30Sjl 		fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_RESOURCE,
1440e98fafb9Sjl 		    DATA_TYPE_NVLIST, resource, NULL);
144125cf1a30Sjl 		break;
144225cf1a30Sjl 
144325cf1a30Sjl 	case OPL_ERRID_PATH:
144425cf1a30Sjl 		/*
144525cf1a30Sjl 		 * No resource is created but the cpumem DE will find
144625cf1a30Sjl 		 * the defective path by retreiving EID from SFSR which is
144725cf1a30Sjl 		 * included in the payload.
144825cf1a30Sjl 		 */
144925cf1a30Sjl 		break;
145025cf1a30Sjl 	}
145125cf1a30Sjl }
145225cf1a30Sjl 
145325cf1a30Sjl /*
145425cf1a30Sjl  * Returns whether fault address is valid for this error bit and
145525cf1a30Sjl  * whether the address is "in memory" (i.e. pf_is_memory returns 1).
145625cf1a30Sjl  */
145725cf1a30Sjl /*ARGSUSED*/
145825cf1a30Sjl static int
145925cf1a30Sjl cpu_flt_in_memory(opl_async_flt_t *opl_flt, uint64_t t_afsr_bit)
146025cf1a30Sjl {
146125cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)opl_flt;
146225cf1a30Sjl 
146325cf1a30Sjl 	if (aflt->flt_status & (OPL_ECC_SYNC_TRAP)) {
146425cf1a30Sjl 		return ((t_afsr_bit & SFSR_MEMORY) &&
146525cf1a30Sjl 		    pf_is_memory(aflt->flt_addr >> MMU_PAGESHIFT));
146625cf1a30Sjl 	}
146725cf1a30Sjl 	return (0);
146825cf1a30Sjl }
146925cf1a30Sjl 
147025cf1a30Sjl /*
147125cf1a30Sjl  * In OPL SCF does the stick synchronization.
147225cf1a30Sjl  */
147325cf1a30Sjl void
147425cf1a30Sjl sticksync_slave(void)
147525cf1a30Sjl {
147625cf1a30Sjl }
147725cf1a30Sjl 
147825cf1a30Sjl /*
147925cf1a30Sjl  * In OPL SCF does the stick synchronization.
148025cf1a30Sjl  */
148125cf1a30Sjl void
148225cf1a30Sjl sticksync_master(void)
148325cf1a30Sjl {
148425cf1a30Sjl }
148525cf1a30Sjl 
148625cf1a30Sjl /*
148725cf1a30Sjl  * Cpu private unitialization.  OPL cpus do not use the private area.
148825cf1a30Sjl  */
148925cf1a30Sjl void
149025cf1a30Sjl cpu_uninit_private(struct cpu *cp)
149125cf1a30Sjl {
149225cf1a30Sjl 	cmp_delete_cpu(cp->cpu_id);
149325cf1a30Sjl }
149425cf1a30Sjl 
149525cf1a30Sjl /*
149625cf1a30Sjl  * Always flush an entire cache.
149725cf1a30Sjl  */
149825cf1a30Sjl void
149925cf1a30Sjl cpu_error_ecache_flush(void)
150025cf1a30Sjl {
150125cf1a30Sjl 	cpu_flush_ecache();
150225cf1a30Sjl }
150325cf1a30Sjl 
150425cf1a30Sjl void
150525cf1a30Sjl cpu_ereport_post(struct async_flt *aflt)
150625cf1a30Sjl {
150725cf1a30Sjl 	char *cpu_type, buf[FM_MAX_CLASS];
150825cf1a30Sjl 	nv_alloc_t *nva = NULL;
150925cf1a30Sjl 	nvlist_t *ereport, *detector, *resource;
151025cf1a30Sjl 	errorq_elem_t *eqep;
151125cf1a30Sjl 	char sbuf[21]; /* sizeof (UINT64_MAX) + '\0' */
151225cf1a30Sjl 
151325cf1a30Sjl 	if (aflt->flt_panic || panicstr) {
151425cf1a30Sjl 		eqep = errorq_reserve(ereport_errorq);
151525cf1a30Sjl 		if (eqep == NULL)
151625cf1a30Sjl 			return;
151725cf1a30Sjl 		ereport = errorq_elem_nvl(ereport_errorq, eqep);
151825cf1a30Sjl 		nva = errorq_elem_nva(ereport_errorq, eqep);
151925cf1a30Sjl 	} else {
152025cf1a30Sjl 		ereport = fm_nvlist_create(nva);
152125cf1a30Sjl 	}
152225cf1a30Sjl 
152325cf1a30Sjl 	/*
152425cf1a30Sjl 	 * Create the scheme "cpu" FMRI.
152525cf1a30Sjl 	 */
152625cf1a30Sjl 	detector = fm_nvlist_create(nva);
152725cf1a30Sjl 	resource = fm_nvlist_create(nva);
152825cf1a30Sjl 	switch (cpunodes[aflt->flt_inst].implementation) {
152925cf1a30Sjl 	case OLYMPUS_C_IMPL:
153025cf1a30Sjl 		cpu_type = FM_EREPORT_CPU_SPARC64_VI;
153125cf1a30Sjl 		break;
1532e98fafb9Sjl 	case JUPITER_IMPL:
1533e98fafb9Sjl 		cpu_type = FM_EREPORT_CPU_SPARC64_VII;
1534e98fafb9Sjl 		break;
153525cf1a30Sjl 	default:
153625cf1a30Sjl 		cpu_type = FM_EREPORT_CPU_UNSUPPORTED;
153725cf1a30Sjl 		break;
153825cf1a30Sjl 	}
153925cf1a30Sjl 	(void) snprintf(sbuf, sizeof (sbuf), "%llX",
154025cf1a30Sjl 	    (u_longlong_t)cpunodes[aflt->flt_inst].device_id);
154125cf1a30Sjl 	(void) fm_fmri_cpu_set(detector, FM_CPU_SCHEME_VERSION, NULL,
154225cf1a30Sjl 	    aflt->flt_inst, (uint8_t *)&cpunodes[aflt->flt_inst].version,
154325cf1a30Sjl 	    sbuf);
154425cf1a30Sjl 
154525cf1a30Sjl 	/*
154625cf1a30Sjl 	 * Encode all the common data into the ereport.
154725cf1a30Sjl 	 */
154825cf1a30Sjl 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s.%s",
154925cf1a30Sjl 	    FM_ERROR_CPU, cpu_type, aflt->flt_erpt_class);
155025cf1a30Sjl 
155125cf1a30Sjl 	fm_ereport_set(ereport, FM_EREPORT_VERSION, buf,
155225cf1a30Sjl 	    fm_ena_generate(aflt->flt_id, FM_ENA_FMT1), detector, NULL);
155325cf1a30Sjl 
155425cf1a30Sjl 	/*
155525cf1a30Sjl 	 * Encode the error specific data that was saved in
155625cf1a30Sjl 	 * the async_flt structure into the ereport.
155725cf1a30Sjl 	 */
155825cf1a30Sjl 	cpu_payload_add_aflt(aflt, ereport, resource);
155925cf1a30Sjl 
156025cf1a30Sjl 	if (aflt->flt_panic || panicstr) {
156125cf1a30Sjl 		errorq_commit(ereport_errorq, eqep, ERRORQ_SYNC);
156225cf1a30Sjl 	} else {
156325cf1a30Sjl 		(void) fm_ereport_post(ereport, EVCH_TRYHARD);
156425cf1a30Sjl 		fm_nvlist_destroy(ereport, FM_NVA_FREE);
156525cf1a30Sjl 		fm_nvlist_destroy(detector, FM_NVA_FREE);
156625cf1a30Sjl 		fm_nvlist_destroy(resource, FM_NVA_FREE);
156725cf1a30Sjl 	}
156825cf1a30Sjl }
156925cf1a30Sjl 
157025cf1a30Sjl void
157125cf1a30Sjl cpu_run_bus_error_handlers(struct async_flt *aflt, int expected)
157225cf1a30Sjl {
157325cf1a30Sjl 	int status;
157425cf1a30Sjl 	ddi_fm_error_t de;
157525cf1a30Sjl 
157625cf1a30Sjl 	bzero(&de, sizeof (ddi_fm_error_t));
157725cf1a30Sjl 
157825cf1a30Sjl 	de.fme_version = DDI_FME_VERSION;
157925cf1a30Sjl 	de.fme_ena = fm_ena_generate(aflt->flt_id, FM_ENA_FMT1);
158025cf1a30Sjl 	de.fme_flag = expected;
158125cf1a30Sjl 	de.fme_bus_specific = (void *)aflt->flt_addr;
158225cf1a30Sjl 	status = ndi_fm_handler_dispatch(ddi_root_node(), NULL, &de);
158325cf1a30Sjl 	if ((aflt->flt_prot == AFLT_PROT_NONE) && (status == DDI_FM_FATAL))
158425cf1a30Sjl 		aflt->flt_panic = 1;
158525cf1a30Sjl }
158625cf1a30Sjl 
158725cf1a30Sjl void
158825cf1a30Sjl cpu_errorq_dispatch(char *error_class, void *payload, size_t payload_sz,
158925cf1a30Sjl     errorq_t *eqp, uint_t flag)
159025cf1a30Sjl {
159125cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)payload;
159225cf1a30Sjl 
159325cf1a30Sjl 	aflt->flt_erpt_class = error_class;
159425cf1a30Sjl 	errorq_dispatch(eqp, payload, payload_sz, flag);
159525cf1a30Sjl }
159625cf1a30Sjl 
159725cf1a30Sjl void
159825cf1a30Sjl adjust_hw_copy_limits(int ecache_size)
159925cf1a30Sjl {
160025cf1a30Sjl 	/*
160125cf1a30Sjl 	 * Set hw copy limits.
160225cf1a30Sjl 	 *
160325cf1a30Sjl 	 * /etc/system will be parsed later and can override one or more
160425cf1a30Sjl 	 * of these settings.
160525cf1a30Sjl 	 *
160625cf1a30Sjl 	 * At this time, ecache size seems only mildly relevant.
160725cf1a30Sjl 	 * We seem to run into issues with the d-cache and stalls
160825cf1a30Sjl 	 * we see on misses.
160925cf1a30Sjl 	 *
161025cf1a30Sjl 	 * Cycle measurement indicates that 2 byte aligned copies fare
161125cf1a30Sjl 	 * little better than doing things with VIS at around 512 bytes.
161225cf1a30Sjl 	 * 4 byte aligned shows promise until around 1024 bytes. 8 Byte
161325cf1a30Sjl 	 * aligned is faster whenever the source and destination data
161425cf1a30Sjl 	 * in cache and the total size is less than 2 Kbytes.  The 2K
161525cf1a30Sjl 	 * limit seems to be driven by the 2K write cache.
161625cf1a30Sjl 	 * When more than 2K of copies are done in non-VIS mode, stores
161725cf1a30Sjl 	 * backup in the write cache.  In VIS mode, the write cache is
161825cf1a30Sjl 	 * bypassed, allowing faster cache-line writes aligned on cache
161925cf1a30Sjl 	 * boundaries.
162025cf1a30Sjl 	 *
162125cf1a30Sjl 	 * In addition, in non-VIS mode, there is no prefetching, so
162225cf1a30Sjl 	 * for larger copies, the advantage of prefetching to avoid even
162325cf1a30Sjl 	 * occasional cache misses is enough to justify using the VIS code.
162425cf1a30Sjl 	 *
162525cf1a30Sjl 	 * During testing, it was discovered that netbench ran 3% slower
162625cf1a30Sjl 	 * when hw_copy_limit_8 was 2K or larger.  Apparently for server
162725cf1a30Sjl 	 * applications, data is only used once (copied to the output
162825cf1a30Sjl 	 * buffer, then copied by the network device off the system).  Using
162925cf1a30Sjl 	 * the VIS copy saves more L2 cache state.  Network copies are
163025cf1a30Sjl 	 * around 1.3K to 1.5K in size for historical reasons.
163125cf1a30Sjl 	 *
163225cf1a30Sjl 	 * Therefore, a limit of 1K bytes will be used for the 8 byte
163325cf1a30Sjl 	 * aligned copy even for large caches and 8 MB ecache.  The
163425cf1a30Sjl 	 * infrastructure to allow different limits for different sized
163525cf1a30Sjl 	 * caches is kept to allow further tuning in later releases.
163625cf1a30Sjl 	 */
163725cf1a30Sjl 
163825cf1a30Sjl 	if (min_ecache_size == 0 && use_hw_bcopy) {
163925cf1a30Sjl 		/*
164025cf1a30Sjl 		 * First time through - should be before /etc/system
164125cf1a30Sjl 		 * is read.
164225cf1a30Sjl 		 * Could skip the checks for zero but this lets us
164325cf1a30Sjl 		 * preserve any debugger rewrites.
164425cf1a30Sjl 		 */
164525cf1a30Sjl 		if (hw_copy_limit_1 == 0) {
164625cf1a30Sjl 			hw_copy_limit_1 = VIS_COPY_THRESHOLD;
164725cf1a30Sjl 			priv_hcl_1 = hw_copy_limit_1;
164825cf1a30Sjl 		}
164925cf1a30Sjl 		if (hw_copy_limit_2 == 0) {
165025cf1a30Sjl 			hw_copy_limit_2 = 2 * VIS_COPY_THRESHOLD;
165125cf1a30Sjl 			priv_hcl_2 = hw_copy_limit_2;
165225cf1a30Sjl 		}
165325cf1a30Sjl 		if (hw_copy_limit_4 == 0) {
165425cf1a30Sjl 			hw_copy_limit_4 = 4 * VIS_COPY_THRESHOLD;
165525cf1a30Sjl 			priv_hcl_4 = hw_copy_limit_4;
165625cf1a30Sjl 		}
165725cf1a30Sjl 		if (hw_copy_limit_8 == 0) {
165825cf1a30Sjl 			hw_copy_limit_8 = 4 * VIS_COPY_THRESHOLD;
165925cf1a30Sjl 			priv_hcl_8 = hw_copy_limit_8;
166025cf1a30Sjl 		}
166125cf1a30Sjl 		min_ecache_size = ecache_size;
166225cf1a30Sjl 	} else {
166325cf1a30Sjl 		/*
166425cf1a30Sjl 		 * MP initialization. Called *after* /etc/system has
166525cf1a30Sjl 		 * been parsed. One CPU has already been initialized.
166625cf1a30Sjl 		 * Need to cater for /etc/system having scragged one
166725cf1a30Sjl 		 * of our values.
166825cf1a30Sjl 		 */
166925cf1a30Sjl 		if (ecache_size == min_ecache_size) {
167025cf1a30Sjl 			/*
167125cf1a30Sjl 			 * Same size ecache. We do nothing unless we
167225cf1a30Sjl 			 * have a pessimistic ecache setting. In that
167325cf1a30Sjl 			 * case we become more optimistic (if the cache is
167425cf1a30Sjl 			 * large enough).
167525cf1a30Sjl 			 */
167625cf1a30Sjl 			if (hw_copy_limit_8 == 4 * VIS_COPY_THRESHOLD) {
167725cf1a30Sjl 				/*
167825cf1a30Sjl 				 * Need to adjust hw_copy_limit* from our
167925cf1a30Sjl 				 * pessimistic uniprocessor value to a more
168025cf1a30Sjl 				 * optimistic UP value *iff* it hasn't been
168125cf1a30Sjl 				 * reset.
168225cf1a30Sjl 				 */
168325cf1a30Sjl 				if ((ecache_size > 1048576) &&
168425cf1a30Sjl 				    (priv_hcl_8 == hw_copy_limit_8)) {
168525cf1a30Sjl 					if (ecache_size <= 2097152)
168625cf1a30Sjl 						hw_copy_limit_8 = 4 *
168725cf1a30Sjl 						    VIS_COPY_THRESHOLD;
168825cf1a30Sjl 					else if (ecache_size <= 4194304)
168925cf1a30Sjl 						hw_copy_limit_8 = 4 *
169025cf1a30Sjl 						    VIS_COPY_THRESHOLD;
169125cf1a30Sjl 					else
169225cf1a30Sjl 						hw_copy_limit_8 = 4 *
169325cf1a30Sjl 						    VIS_COPY_THRESHOLD;
169425cf1a30Sjl 					priv_hcl_8 = hw_copy_limit_8;
169525cf1a30Sjl 				}
169625cf1a30Sjl 			}
169725cf1a30Sjl 		} else if (ecache_size < min_ecache_size) {
169825cf1a30Sjl 			/*
169925cf1a30Sjl 			 * A different ecache size. Can this even happen?
170025cf1a30Sjl 			 */
170125cf1a30Sjl 			if (priv_hcl_8 == hw_copy_limit_8) {
170225cf1a30Sjl 				/*
170325cf1a30Sjl 				 * The previous value that we set
170425cf1a30Sjl 				 * is unchanged (i.e., it hasn't been
170525cf1a30Sjl 				 * scragged by /etc/system). Rewrite it.
170625cf1a30Sjl 				 */
170725cf1a30Sjl 				if (ecache_size <= 1048576)
170825cf1a30Sjl 					hw_copy_limit_8 = 8 *
170925cf1a30Sjl 					    VIS_COPY_THRESHOLD;
171025cf1a30Sjl 				else if (ecache_size <= 2097152)
171125cf1a30Sjl 					hw_copy_limit_8 = 8 *
171225cf1a30Sjl 					    VIS_COPY_THRESHOLD;
171325cf1a30Sjl 				else if (ecache_size <= 4194304)
171425cf1a30Sjl 					hw_copy_limit_8 = 8 *
171525cf1a30Sjl 					    VIS_COPY_THRESHOLD;
171625cf1a30Sjl 				else
171725cf1a30Sjl 					hw_copy_limit_8 = 10 *
171825cf1a30Sjl 					    VIS_COPY_THRESHOLD;
171925cf1a30Sjl 				priv_hcl_8 = hw_copy_limit_8;
172025cf1a30Sjl 				min_ecache_size = ecache_size;
172125cf1a30Sjl 			}
172225cf1a30Sjl 		}
172325cf1a30Sjl 	}
172425cf1a30Sjl }
172525cf1a30Sjl 
172625cf1a30Sjl #define	VIS_BLOCKSIZE		64
172725cf1a30Sjl 
172825cf1a30Sjl int
172925cf1a30Sjl dtrace_blksuword32_err(uintptr_t addr, uint32_t *data)
173025cf1a30Sjl {
173125cf1a30Sjl 	int ret, watched;
173225cf1a30Sjl 
173325cf1a30Sjl 	watched = watch_disable_addr((void *)addr, VIS_BLOCKSIZE, S_WRITE);
173425cf1a30Sjl 	ret = dtrace_blksuword32(addr, data, 0);
173525cf1a30Sjl 	if (watched)
173625cf1a30Sjl 		watch_enable_addr((void *)addr, VIS_BLOCKSIZE, S_WRITE);
173725cf1a30Sjl 
173825cf1a30Sjl 	return (ret);
173925cf1a30Sjl }
174025cf1a30Sjl 
174125cf1a30Sjl void
174225cf1a30Sjl opl_cpu_reg_init()
174325cf1a30Sjl {
174425cf1a30Sjl 	uint64_t	this_cpu_log;
174525cf1a30Sjl 
1746b9a675d4Smb 	if (cpu[getprocessorid()] == &cpu0 && opl_cpu0_log_setup == 1) {
174750eff769Smb 		/*
174850eff769Smb 		 * Support for "ta 3"
174950eff769Smb 		 */
175050eff769Smb 		opl_ta3();
1751b9a675d4Smb 
1752b9a675d4Smb 		/*
1753b9a675d4Smb 		 * If we are being called at boot time on cpu0 the error
1754b9a675d4Smb 		 * log is already set up in cpu_setup. Clear the
1755b9a675d4Smb 		 * opl_cpu0_log_setup flag so that a subsequent DR of cpu0 will
1756b9a675d4Smb 		 * do the proper initialization.
1757b9a675d4Smb 		 */
1758b9a675d4Smb 		opl_cpu0_log_setup = 0;
175925cf1a30Sjl 		return;
176050eff769Smb 	}
176125cf1a30Sjl 
176225cf1a30Sjl 	/*
176325cf1a30Sjl 	 * Initialize Error log Scratch register for error handling.
176425cf1a30Sjl 	 */
176525cf1a30Sjl 
176625cf1a30Sjl 	this_cpu_log = va_to_pa((void*)(((uint64_t)opl_err_log) +
1767e98fafb9Sjl 	    ERRLOG_BUFSZ * (getprocessorid())));
176825cf1a30Sjl 	opl_error_setup(this_cpu_log);
176925cf1a30Sjl }
177025cf1a30Sjl 
177125cf1a30Sjl /*
177225cf1a30Sjl  * Queue one event in ue_queue based on ecc_type_to_info entry.
177325cf1a30Sjl  */
177425cf1a30Sjl static void
177525cf1a30Sjl cpu_queue_one_event(opl_async_flt_t *opl_flt, char *reason,
177625cf1a30Sjl     ecc_type_to_info_t *eccp)
177725cf1a30Sjl {
177825cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)opl_flt;
177925cf1a30Sjl 
178025cf1a30Sjl 	if (reason &&
178125cf1a30Sjl 	    strlen(reason) + strlen(eccp->ec_reason) < MAX_REASON_STRING) {
178225cf1a30Sjl 		(void) strcat(reason, eccp->ec_reason);
178325cf1a30Sjl 	}
178425cf1a30Sjl 
178525cf1a30Sjl 	opl_flt->flt_bit = eccp->ec_afsr_bit;
178625cf1a30Sjl 	opl_flt->flt_type = eccp->ec_flt_type;
178725cf1a30Sjl 	aflt->flt_in_memory = cpu_flt_in_memory(opl_flt, opl_flt->flt_bit);
178825cf1a30Sjl 	aflt->flt_payload = eccp->ec_err_payload;
178925cf1a30Sjl 
179025cf1a30Sjl 	ASSERT(aflt->flt_status & (OPL_ECC_SYNC_TRAP|OPL_ECC_URGENT_TRAP));
1791e98fafb9Sjl 	cpu_errorq_dispatch(eccp->ec_err_class, (void *)opl_flt,
1792e98fafb9Sjl 	    sizeof (opl_async_flt_t), ue_queue, aflt->flt_panic);
179325cf1a30Sjl }
179425cf1a30Sjl 
179525cf1a30Sjl /*
179625cf1a30Sjl  * Queue events on async event queue one event per error bit.
179725cf1a30Sjl  * Return number of events queued.
179825cf1a30Sjl  */
179925cf1a30Sjl int
180025cf1a30Sjl cpu_queue_events(opl_async_flt_t *opl_flt, char *reason, uint64_t t_afsr_errs)
180125cf1a30Sjl {
180225cf1a30Sjl 	struct async_flt *aflt = (struct async_flt *)opl_flt;
180325cf1a30Sjl 	ecc_type_to_info_t *eccp;
180425cf1a30Sjl 	int nevents = 0;
180525cf1a30Sjl 
180625cf1a30Sjl 	/*
180725cf1a30Sjl 	 * Queue expected errors, error bit and fault type must must match
180825cf1a30Sjl 	 * in the ecc_type_to_info table.
180925cf1a30Sjl 	 */
181025cf1a30Sjl 	for (eccp = ecc_type_to_info; t_afsr_errs != 0 && eccp->ec_desc != NULL;
1811e98fafb9Sjl 	    eccp++) {
181225cf1a30Sjl 		if ((eccp->ec_afsr_bit & t_afsr_errs) != 0 &&
181325cf1a30Sjl 		    (eccp->ec_flags & aflt->flt_status) != 0) {
181425cf1a30Sjl 			/*
181525cf1a30Sjl 			 * UE error event can be further
181625cf1a30Sjl 			 * classified/breakdown into finer granularity
181725cf1a30Sjl 			 * based on the flt_eid_mod value set by HW.  We do
181825cf1a30Sjl 			 * special handling here so that we can report UE
181925cf1a30Sjl 			 * error in finer granularity as ue_mem,
182025cf1a30Sjl 			 * ue_channel, ue_cpu or ue_path.
182125cf1a30Sjl 			 */
182225cf1a30Sjl 			if (eccp->ec_flt_type == OPL_CPU_SYNC_UE) {
1823e98fafb9Sjl 				opl_flt->flt_eid_mod = (aflt->flt_stat &
1824e98fafb9Sjl 				    SFSR_EID_MOD) >> SFSR_EID_MOD_SHIFT;
1825e98fafb9Sjl 				opl_flt->flt_eid_sid = (aflt->flt_stat &
1826e98fafb9Sjl 				    SFSR_EID_SID) >> SFSR_EID_SID_SHIFT;
182725cf1a30Sjl 				/*
182825cf1a30Sjl 				 * Need to advance eccp pointer by flt_eid_mod
182925cf1a30Sjl 				 * so that we get an appropriate ecc pointer
183025cf1a30Sjl 				 *
183125cf1a30Sjl 				 * EID			# of advances
183225cf1a30Sjl 				 * ----------------------------------
183325cf1a30Sjl 				 * OPL_ERRID_MEM	0
183425cf1a30Sjl 				 * OPL_ERRID_CHANNEL	1
183525cf1a30Sjl 				 * OPL_ERRID_CPU	2
183625cf1a30Sjl 				 * OPL_ERRID_PATH	3
183725cf1a30Sjl 				 */
183825cf1a30Sjl 				eccp += opl_flt->flt_eid_mod;
183925cf1a30Sjl 			}
184025cf1a30Sjl 			cpu_queue_one_event(opl_flt, reason, eccp);
184125cf1a30Sjl 			t_afsr_errs &= ~eccp->ec_afsr_bit;
184225cf1a30Sjl 			nevents++;
184325cf1a30Sjl 		}
184425cf1a30Sjl 	}
184525cf1a30Sjl 
184625cf1a30Sjl 	return (nevents);
184725cf1a30Sjl }
184825cf1a30Sjl 
184925cf1a30Sjl /*
185025cf1a30Sjl  * Sync. error wrapper functions.
185125cf1a30Sjl  * We use these functions in order to transfer here from the
185225cf1a30Sjl  * nucleus trap handler information about trap type (data or
185325cf1a30Sjl  * instruction) and trap level (0 or above 0). This way we
185425cf1a30Sjl  * get rid of using SFSR's reserved bits.
185525cf1a30Sjl  */
185625cf1a30Sjl 
185725cf1a30Sjl #define	OPL_SYNC_TL0	0
185825cf1a30Sjl #define	OPL_SYNC_TL1	1
185925cf1a30Sjl #define	OPL_ISYNC_ERR	0
186025cf1a30Sjl #define	OPL_DSYNC_ERR	1
186125cf1a30Sjl 
186225cf1a30Sjl void
186325cf1a30Sjl opl_cpu_isync_tl0_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
186425cf1a30Sjl {
186525cf1a30Sjl 	uint64_t t_sfar = p_sfar;
186625cf1a30Sjl 	uint64_t t_sfsr = p_sfsr;
186725cf1a30Sjl 
186825cf1a30Sjl 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
186925cf1a30Sjl 	    OPL_SYNC_TL0, OPL_ISYNC_ERR);
187025cf1a30Sjl }
187125cf1a30Sjl 
187225cf1a30Sjl void
187325cf1a30Sjl opl_cpu_isync_tl1_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
187425cf1a30Sjl {
187525cf1a30Sjl 	uint64_t t_sfar = p_sfar;
187625cf1a30Sjl 	uint64_t t_sfsr = p_sfsr;
187725cf1a30Sjl 
187825cf1a30Sjl 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
187925cf1a30Sjl 	    OPL_SYNC_TL1, OPL_ISYNC_ERR);
188025cf1a30Sjl }
188125cf1a30Sjl 
188225cf1a30Sjl void
188325cf1a30Sjl opl_cpu_dsync_tl0_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
188425cf1a30Sjl {
188525cf1a30Sjl 	uint64_t t_sfar = p_sfar;
188625cf1a30Sjl 	uint64_t t_sfsr = p_sfsr;
188725cf1a30Sjl 
188825cf1a30Sjl 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
188925cf1a30Sjl 	    OPL_SYNC_TL0, OPL_DSYNC_ERR);
189025cf1a30Sjl }
189125cf1a30Sjl 
189225cf1a30Sjl void
189325cf1a30Sjl opl_cpu_dsync_tl1_error(struct regs *rp, ulong_t p_sfar, ulong_t p_sfsr)
189425cf1a30Sjl {
189525cf1a30Sjl 	uint64_t t_sfar = p_sfar;
189625cf1a30Sjl 	uint64_t t_sfsr = p_sfsr;
189725cf1a30Sjl 
189825cf1a30Sjl 	opl_cpu_sync_error(rp, t_sfar, t_sfsr,
189925cf1a30Sjl 	    OPL_SYNC_TL1, OPL_DSYNC_ERR);
190025cf1a30Sjl }
190125cf1a30Sjl 
190225cf1a30Sjl /*
190325cf1a30Sjl  * The fj sync err handler transfers control here for UE, BERR, TO, TLB_MUL
190425cf1a30Sjl  * and TLB_PRT.
190525cf1a30Sjl  * This function is designed based on cpu_deferred_error().
190625cf1a30Sjl  */
190725cf1a30Sjl 
190825cf1a30Sjl static void
190925cf1a30Sjl opl_cpu_sync_error(struct regs *rp, ulong_t t_sfar, ulong_t t_sfsr,
191025cf1a30Sjl     uint_t tl, uint_t derr)
191125cf1a30Sjl {
191225cf1a30Sjl 	opl_async_flt_t opl_flt;
191325cf1a30Sjl 	struct async_flt *aflt;
191425cf1a30Sjl 	int trampolined = 0;
191525cf1a30Sjl 	char pr_reason[MAX_REASON_STRING];
191625cf1a30Sjl 	uint64_t log_sfsr;
191725cf1a30Sjl 	int expected = DDI_FM_ERR_UNEXPECTED;
191825cf1a30Sjl 	ddi_acc_hdl_t *hp;
191925cf1a30Sjl 
192025cf1a30Sjl 	/*
192125cf1a30Sjl 	 * We need to look at p_flag to determine if the thread detected an
192225cf1a30Sjl 	 * error while dumping core.  We can't grab p_lock here, but it's ok
192325cf1a30Sjl 	 * because we just need a consistent snapshot and we know that everyone
192425cf1a30Sjl 	 * else will store a consistent set of bits while holding p_lock.  We
192525cf1a30Sjl 	 * don't have to worry about a race because SDOCORE is set once prior
192625cf1a30Sjl 	 * to doing i/o from the process's address space and is never cleared.
192725cf1a30Sjl 	 */
192825cf1a30Sjl 	uint_t pflag = ttoproc(curthread)->p_flag;
192925cf1a30Sjl 
193025cf1a30Sjl 	pr_reason[0] = '\0';
193125cf1a30Sjl 
193225cf1a30Sjl 	/*
193325cf1a30Sjl 	 * handle the specific error
193425cf1a30Sjl 	 */
193525cf1a30Sjl 	bzero(&opl_flt, sizeof (opl_async_flt_t));
193625cf1a30Sjl 	aflt = (struct async_flt *)&opl_flt;
193725cf1a30Sjl 	aflt->flt_id = gethrtime_waitfree();
193825cf1a30Sjl 	aflt->flt_bus_id = getprocessorid();
193925cf1a30Sjl 	aflt->flt_inst = CPU->cpu_id;
194025cf1a30Sjl 	aflt->flt_stat = t_sfsr;
194125cf1a30Sjl 	aflt->flt_addr = t_sfar;
194225cf1a30Sjl 	aflt->flt_pc = (caddr_t)rp->r_pc;
194325cf1a30Sjl 	aflt->flt_prot = (uchar_t)AFLT_PROT_NONE;
194425cf1a30Sjl 	aflt->flt_class = (uchar_t)CPU_FAULT;
1945e98fafb9Sjl 	aflt->flt_priv = (uchar_t)(tl == 1 ? 1 : ((rp->r_tstate &
1946e98fafb9Sjl 	    TSTATE_PRIV) ? 1 : 0));
194725cf1a30Sjl 	aflt->flt_tl = (uchar_t)tl;
194825cf1a30Sjl 	aflt->flt_panic = (uchar_t)(tl != 0 || aft_testfatal != 0 ||
194925cf1a30Sjl 	    (t_sfsr & (SFSR_TLB_MUL|SFSR_TLB_PRT)) != 0);
195025cf1a30Sjl 	aflt->flt_core = (pflag & SDOCORE) ? 1 : 0;
195125cf1a30Sjl 	aflt->flt_status = (derr) ? OPL_ECC_DSYNC_TRAP : OPL_ECC_ISYNC_TRAP;
195225cf1a30Sjl 
195325cf1a30Sjl 	/*
195425cf1a30Sjl 	 * If SFSR.FV is not set, both SFSR and SFAR/SFPAR values are uncertain.
195525cf1a30Sjl 	 * So, clear all error bits to avoid mis-handling and force the system
195625cf1a30Sjl 	 * panicked.
195725cf1a30Sjl 	 * We skip all the procedures below down to the panic message call.
195825cf1a30Sjl 	 */
195925cf1a30Sjl 	if (!(t_sfsr & SFSR_FV)) {
196025cf1a30Sjl 		opl_flt.flt_type = OPL_CPU_INV_SFSR;
196125cf1a30Sjl 		aflt->flt_panic = 1;
196225cf1a30Sjl 		aflt->flt_payload = FM_EREPORT_PAYLOAD_SYNC;
1963e98fafb9Sjl 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_SFSR, (void *)&opl_flt,
1964e98fafb9Sjl 		    sizeof (opl_async_flt_t), ue_queue, aflt->flt_panic);
196525cf1a30Sjl 		fm_panic("%sErrors(s)", "invalid SFSR");
196625cf1a30Sjl 	}
196725cf1a30Sjl 
196825cf1a30Sjl 	/*
196925cf1a30Sjl 	 * If either UE and MK bit is off, this is not valid UE error.
197025cf1a30Sjl 	 * If it is not valid UE error, clear UE & MK_UE bits to prevent
197125cf1a30Sjl 	 * mis-handling below.
197225cf1a30Sjl 	 * aflt->flt_stat keeps the original bits as a reference.
197325cf1a30Sjl 	 */
197425cf1a30Sjl 	if ((t_sfsr & (SFSR_MK_UE|SFSR_UE)) !=
197525cf1a30Sjl 	    (SFSR_MK_UE|SFSR_UE)) {
197625cf1a30Sjl 		t_sfsr &= ~(SFSR_MK_UE|SFSR_UE);
197725cf1a30Sjl 	}
197825cf1a30Sjl 
197925cf1a30Sjl 	/*
198025cf1a30Sjl 	 * If the trap occurred in privileged mode at TL=0, we need to check to
198125cf1a30Sjl 	 * see if we were executing in the kernel under on_trap() or t_lofault
198225cf1a30Sjl 	 * protection.  If so, modify the saved registers so that we return
198325cf1a30Sjl 	 * from the trap to the appropriate trampoline routine.
198425cf1a30Sjl 	 */
198525cf1a30Sjl 	if (!aflt->flt_panic && aflt->flt_priv && tl == 0) {
198625cf1a30Sjl 		if (curthread->t_ontrap != NULL) {
198725cf1a30Sjl 			on_trap_data_t *otp = curthread->t_ontrap;
198825cf1a30Sjl 
198925cf1a30Sjl 			if (otp->ot_prot & OT_DATA_EC) {
199025cf1a30Sjl 				aflt->flt_prot = (uchar_t)AFLT_PROT_EC;
199125cf1a30Sjl 				otp->ot_trap |= (ushort_t)OT_DATA_EC;
199225cf1a30Sjl 				rp->r_pc = otp->ot_trampoline;
199325cf1a30Sjl 				rp->r_npc = rp->r_pc + 4;
199425cf1a30Sjl 				trampolined = 1;
199525cf1a30Sjl 			}
199625cf1a30Sjl 
199725cf1a30Sjl 			if ((t_sfsr & (SFSR_TO | SFSR_BERR)) &&
199825cf1a30Sjl 			    (otp->ot_prot & OT_DATA_ACCESS)) {
199925cf1a30Sjl 				aflt->flt_prot = (uchar_t)AFLT_PROT_ACCESS;
200025cf1a30Sjl 				otp->ot_trap |= (ushort_t)OT_DATA_ACCESS;
200125cf1a30Sjl 				rp->r_pc = otp->ot_trampoline;
200225cf1a30Sjl 				rp->r_npc = rp->r_pc + 4;
200325cf1a30Sjl 				trampolined = 1;
200425cf1a30Sjl 				/*
200525cf1a30Sjl 				 * for peeks and caut_gets errors are expected
200625cf1a30Sjl 				 */
200725cf1a30Sjl 				hp = (ddi_acc_hdl_t *)otp->ot_handle;
200825cf1a30Sjl 				if (!hp)
200925cf1a30Sjl 					expected = DDI_FM_ERR_PEEK;
201025cf1a30Sjl 				else if (hp->ah_acc.devacc_attr_access ==
201125cf1a30Sjl 				    DDI_CAUTIOUS_ACC)
201225cf1a30Sjl 					expected = DDI_FM_ERR_EXPECTED;
201325cf1a30Sjl 			}
201425cf1a30Sjl 
201525cf1a30Sjl 		} else if (curthread->t_lofault) {
201625cf1a30Sjl 			aflt->flt_prot = AFLT_PROT_COPY;
201725cf1a30Sjl 			rp->r_g1 = EFAULT;
201825cf1a30Sjl 			rp->r_pc = curthread->t_lofault;
201925cf1a30Sjl 			rp->r_npc = rp->r_pc + 4;
202025cf1a30Sjl 			trampolined = 1;
202125cf1a30Sjl 		}
202225cf1a30Sjl 	}
202325cf1a30Sjl 
202425cf1a30Sjl 	/*
202525cf1a30Sjl 	 * If we're in user mode or we're doing a protected copy, we either
202625cf1a30Sjl 	 * want the ASTON code below to send a signal to the user process
202725cf1a30Sjl 	 * or we want to panic if aft_panic is set.
202825cf1a30Sjl 	 *
202925cf1a30Sjl 	 * If we're in privileged mode and we're not doing a copy, then we
203025cf1a30Sjl 	 * need to check if we've trampolined.  If we haven't trampolined,
203125cf1a30Sjl 	 * we should panic.
203225cf1a30Sjl 	 */
203325cf1a30Sjl 	if (!aflt->flt_priv || aflt->flt_prot == AFLT_PROT_COPY) {
203425cf1a30Sjl 		if (t_sfsr & (SFSR_ERRS & ~(SFSR_BERR | SFSR_TO)))
203525cf1a30Sjl 			aflt->flt_panic |= aft_panic;
203625cf1a30Sjl 	} else if (!trampolined) {
203725cf1a30Sjl 		aflt->flt_panic = 1;
203825cf1a30Sjl 	}
203925cf1a30Sjl 
204025cf1a30Sjl 	/*
204125cf1a30Sjl 	 * If we've trampolined due to a privileged TO or BERR, or if an
204225cf1a30Sjl 	 * unprivileged TO or BERR occurred, we don't want to enqueue an
204325cf1a30Sjl 	 * event for that TO or BERR.  Queue all other events (if any) besides
204425cf1a30Sjl 	 * the TO/BERR.
204525cf1a30Sjl 	 */
204625cf1a30Sjl 	log_sfsr = t_sfsr;
204725cf1a30Sjl 	if (trampolined) {
204825cf1a30Sjl 		log_sfsr &= ~(SFSR_TO | SFSR_BERR);
204925cf1a30Sjl 	} else if (!aflt->flt_priv) {
205025cf1a30Sjl 		/*
205125cf1a30Sjl 		 * User mode, suppress messages if
205225cf1a30Sjl 		 * cpu_berr_to_verbose is not set.
205325cf1a30Sjl 		 */
205425cf1a30Sjl 		if (!cpu_berr_to_verbose)
205525cf1a30Sjl 			log_sfsr &= ~(SFSR_TO | SFSR_BERR);
205625cf1a30Sjl 	}
205725cf1a30Sjl 
2058e98fafb9Sjl 	if (((log_sfsr & SFSR_ERRS) && (cpu_queue_events(&opl_flt, pr_reason,
2059e98fafb9Sjl 	    t_sfsr) == 0)) || ((t_sfsr & SFSR_ERRS) == 0)) {
206025cf1a30Sjl 		opl_flt.flt_type = OPL_CPU_INV_SFSR;
206125cf1a30Sjl 		aflt->flt_payload = FM_EREPORT_PAYLOAD_SYNC;
2062e98fafb9Sjl 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_SFSR, (void *)&opl_flt,
2063e98fafb9Sjl 		    sizeof (opl_async_flt_t), ue_queue, aflt->flt_panic);
206425cf1a30Sjl 	}
206525cf1a30Sjl 
206625cf1a30Sjl 	if (t_sfsr & (SFSR_UE|SFSR_TO|SFSR_BERR)) {
206725cf1a30Sjl 		cpu_run_bus_error_handlers(aflt, expected);
206825cf1a30Sjl 	}
206925cf1a30Sjl 
207025cf1a30Sjl 	/*
207125cf1a30Sjl 	 * Panic here if aflt->flt_panic has been set.  Enqueued errors will
207225cf1a30Sjl 	 * be logged as part of the panic flow.
207325cf1a30Sjl 	 */
207425cf1a30Sjl 	if (aflt->flt_panic) {
207525cf1a30Sjl 		if (pr_reason[0] == 0)
207625cf1a30Sjl 			strcpy(pr_reason, "invalid SFSR ");
207725cf1a30Sjl 
207825cf1a30Sjl 		fm_panic("%sErrors(s)", pr_reason);
207925cf1a30Sjl 	}
208025cf1a30Sjl 
208125cf1a30Sjl 	/*
208225cf1a30Sjl 	 * If we queued an error and we are going to return from the trap and
208325cf1a30Sjl 	 * the error was in user mode or inside of a copy routine, set AST flag
208425cf1a30Sjl 	 * so the queue will be drained before returning to user mode.  The
208525cf1a30Sjl 	 * AST processing will also act on our failure policy.
208625cf1a30Sjl 	 */
208725cf1a30Sjl 	if (!aflt->flt_priv || aflt->flt_prot == AFLT_PROT_COPY) {
208825cf1a30Sjl 		int pcb_flag = 0;
208925cf1a30Sjl 
2090e98fafb9Sjl 		if (t_sfsr & (SFSR_ERRS & ~(SFSR_BERR | SFSR_TO)))
209125cf1a30Sjl 			pcb_flag |= ASYNC_HWERR;
209225cf1a30Sjl 
209325cf1a30Sjl 		if (t_sfsr & SFSR_BERR)
209425cf1a30Sjl 			pcb_flag |= ASYNC_BERR;
209525cf1a30Sjl 
209625cf1a30Sjl 		if (t_sfsr & SFSR_TO)
209725cf1a30Sjl 			pcb_flag |= ASYNC_BTO;
209825cf1a30Sjl 
209925cf1a30Sjl 		ttolwp(curthread)->lwp_pcb.pcb_flags |= pcb_flag;
210025cf1a30Sjl 		aston(curthread);
210125cf1a30Sjl 	}
210225cf1a30Sjl }
210325cf1a30Sjl 
210425cf1a30Sjl /*ARGSUSED*/
210525cf1a30Sjl void
210625cf1a30Sjl opl_cpu_urgent_error(struct regs *rp, ulong_t p_ugesr, ulong_t tl)
210725cf1a30Sjl {
210825cf1a30Sjl 	opl_async_flt_t opl_flt;
210925cf1a30Sjl 	struct async_flt *aflt;
211025cf1a30Sjl 	char pr_reason[MAX_REASON_STRING];
211125cf1a30Sjl 
211225cf1a30Sjl 	/* normalize tl */
211325cf1a30Sjl 	tl = (tl >= 2 ? 1 : 0);
211425cf1a30Sjl 	pr_reason[0] = '\0';
211525cf1a30Sjl 
211625cf1a30Sjl 	bzero(&opl_flt, sizeof (opl_async_flt_t));
211725cf1a30Sjl 	aflt = (struct async_flt *)&opl_flt;
211825cf1a30Sjl 	aflt->flt_id = gethrtime_waitfree();
211925cf1a30Sjl 	aflt->flt_bus_id = getprocessorid();
212025cf1a30Sjl 	aflt->flt_inst = CPU->cpu_id;
212125cf1a30Sjl 	aflt->flt_stat = p_ugesr;
212225cf1a30Sjl 	aflt->flt_pc = (caddr_t)rp->r_pc;
212325cf1a30Sjl 	aflt->flt_class = (uchar_t)CPU_FAULT;
212425cf1a30Sjl 	aflt->flt_tl = tl;
2125e98fafb9Sjl 	aflt->flt_priv = (uchar_t)(tl == 1 ? 1 : ((rp->r_tstate & TSTATE_PRIV) ?
2126e98fafb9Sjl 	    1 : 0));
212725cf1a30Sjl 	aflt->flt_status = OPL_ECC_URGENT_TRAP;
212825cf1a30Sjl 	aflt->flt_panic = 1;
212925cf1a30Sjl 	/*
213025cf1a30Sjl 	 * HW does not set mod/sid in case of urgent error.
213125cf1a30Sjl 	 * So we have to set it here.
213225cf1a30Sjl 	 */
213325cf1a30Sjl 	opl_flt.flt_eid_mod = OPL_ERRID_CPU;
213425cf1a30Sjl 	opl_flt.flt_eid_sid = aflt->flt_inst;
213525cf1a30Sjl 
213625cf1a30Sjl 	if (cpu_queue_events(&opl_flt, pr_reason, p_ugesr) == 0) {
213725cf1a30Sjl 		opl_flt.flt_type = OPL_CPU_INV_UGESR;
213825cf1a30Sjl 		aflt->flt_payload = FM_EREPORT_PAYLOAD_URGENT;
2139e98fafb9Sjl 		cpu_errorq_dispatch(FM_EREPORT_CPU_INV_URG, (void *)&opl_flt,
2140e98fafb9Sjl 		    sizeof (opl_async_flt_t), ue_queue, aflt->flt_panic);
214125cf1a30Sjl 	}
214225cf1a30Sjl 
214325cf1a30Sjl 	fm_panic("Urgent Error");
214425cf1a30Sjl }
214525cf1a30Sjl 
214625cf1a30Sjl /*
214725cf1a30Sjl  * Initialization error counters resetting.
214825cf1a30Sjl  */
214925cf1a30Sjl /* ARGSUSED */
215025cf1a30Sjl static void
215125cf1a30Sjl opl_ras_online(void *arg, cpu_t *cp, cyc_handler_t *hdlr, cyc_time_t *when)
215225cf1a30Sjl {
215325cf1a30Sjl 	hdlr->cyh_func = (cyc_func_t)ras_cntr_reset;
215425cf1a30Sjl 	hdlr->cyh_level = CY_LOW_LEVEL;
215525cf1a30Sjl 	hdlr->cyh_arg = (void *)(uintptr_t)cp->cpu_id;
215625cf1a30Sjl 
215725cf1a30Sjl 	when->cyt_when = cp->cpu_id * (((hrtime_t)NANOSEC * 10)/ NCPU);
215825cf1a30Sjl 	when->cyt_interval = (hrtime_t)NANOSEC * opl_async_check_interval;
215925cf1a30Sjl }
216025cf1a30Sjl 
216125cf1a30Sjl void
216225cf1a30Sjl cpu_mp_init(void)
216325cf1a30Sjl {
216425cf1a30Sjl 	cyc_omni_handler_t hdlr;
216525cf1a30Sjl 
216625cf1a30Sjl 	hdlr.cyo_online = opl_ras_online;
216725cf1a30Sjl 	hdlr.cyo_offline = NULL;
216825cf1a30Sjl 	hdlr.cyo_arg = NULL;
216925cf1a30Sjl 	mutex_enter(&cpu_lock);
217025cf1a30Sjl 	(void) cyclic_add_omni(&hdlr);
217125cf1a30Sjl 	mutex_exit(&cpu_lock);
217225cf1a30Sjl }
217325cf1a30Sjl 
2174ca1293cbSjimand int heaplp_use_stlb = 0;
21753cbfd4cfSjimand 
217625cf1a30Sjl void
217725cf1a30Sjl mmu_init_kernel_pgsz(struct hat *hat)
217825cf1a30Sjl {
21793cbfd4cfSjimand 	uint_t tte = page_szc(segkmem_lpsize);
21803cbfd4cfSjimand 	uchar_t new_cext_primary, new_cext_nucleus;
21813cbfd4cfSjimand 
21823cbfd4cfSjimand 	if (heaplp_use_stlb == 0) {
21833cbfd4cfSjimand 		/* do not reprogram stlb */
21843cbfd4cfSjimand 		tte = TTE8K;
2185febcc4a5Sjimand 	} else if (!plat_prom_preserve_kctx_is_supported()) {
2186febcc4a5Sjimand 		/* OBP does not support non-zero primary context */
2187febcc4a5Sjimand 		tte = TTE8K;
2188febcc4a5Sjimand 		heaplp_use_stlb = 0;
21893cbfd4cfSjimand 	}
21903cbfd4cfSjimand 
21913cbfd4cfSjimand 	new_cext_nucleus = TAGACCEXT_MKSZPAIR(tte, TTE8K);
21923cbfd4cfSjimand 	new_cext_primary = TAGACCEXT_MKSZPAIR(TTE8K, tte);
21933cbfd4cfSjimand 
21943cbfd4cfSjimand 	hat->sfmmu_cext = new_cext_primary;
21953cbfd4cfSjimand 	kcontextreg = ((uint64_t)new_cext_nucleus << CTXREG_NEXT_SHIFT) |
2196e98fafb9Sjl 	    ((uint64_t)new_cext_primary << CTXREG_EXT_SHIFT);
219725cf1a30Sjl }
219825cf1a30Sjl 
219925cf1a30Sjl size_t
220025cf1a30Sjl mmu_get_kernel_lpsize(size_t lpsize)
220125cf1a30Sjl {
220225cf1a30Sjl 	uint_t tte;
220325cf1a30Sjl 
220425cf1a30Sjl 	if (lpsize == 0) {
220525cf1a30Sjl 		/* no setting for segkmem_lpsize in /etc/system: use default */
220625cf1a30Sjl 		return (MMU_PAGESIZE4M);
220725cf1a30Sjl 	}
220825cf1a30Sjl 
220925cf1a30Sjl 	for (tte = TTE8K; tte <= TTE4M; tte++) {
221025cf1a30Sjl 		if (lpsize == TTEBYTES(tte))
221125cf1a30Sjl 			return (lpsize);
221225cf1a30Sjl 	}
221325cf1a30Sjl 
221425cf1a30Sjl 	return (TTEBYTES(TTE8K));
221525cf1a30Sjl }
221625cf1a30Sjl 
221750eff769Smb /*
221850eff769Smb  * Support for ta 3.
221950eff769Smb  * We allocate here a buffer for each cpu
222050eff769Smb  * for saving the current register window.
222150eff769Smb  */
222250eff769Smb typedef struct win_regs {
222350eff769Smb 	uint64_t l[8];
222450eff769Smb 	uint64_t i[8];
222550eff769Smb } win_regs_t;
222650eff769Smb static void
222750eff769Smb opl_ta3(void)
222850eff769Smb {
2229b9a675d4Smb 	/*
2230b9a675d4Smb 	 * opl_ta3 should only be called once at boot time.
2231b9a675d4Smb 	 */
2232b9a675d4Smb 	if (opl_ta3_save == NULL)
2233b9a675d4Smb 		opl_ta3_save = (char *)kmem_alloc(NCPU * sizeof (win_regs_t),
2234b9a675d4Smb 		    KM_SLEEP);
223550eff769Smb }
223650eff769Smb 
223725cf1a30Sjl /*
223825cf1a30Sjl  * The following are functions that are unused in
223925cf1a30Sjl  * OPL cpu module. They are defined here to resolve
224025cf1a30Sjl  * dependencies in the "unix" module.
224125cf1a30Sjl  * Unused functions that should never be called in
224225cf1a30Sjl  * OPL are coded with ASSERT(0).
224325cf1a30Sjl  */
224425cf1a30Sjl 
224525cf1a30Sjl void
224625cf1a30Sjl cpu_disable_errors(void)
224725cf1a30Sjl {}
224825cf1a30Sjl 
224925cf1a30Sjl void
225025cf1a30Sjl cpu_enable_errors(void)
225125cf1a30Sjl { ASSERT(0); }
225225cf1a30Sjl 
225325cf1a30Sjl /*ARGSUSED*/
225425cf1a30Sjl void
225525cf1a30Sjl cpu_ce_scrub_mem_err(struct async_flt *ecc, boolean_t t)
225625cf1a30Sjl { ASSERT(0); }
225725cf1a30Sjl 
225825cf1a30Sjl /*ARGSUSED*/
225925cf1a30Sjl void
226025cf1a30Sjl cpu_faulted_enter(struct cpu *cp)
226125cf1a30Sjl {}
226225cf1a30Sjl 
226325cf1a30Sjl /*ARGSUSED*/
226425cf1a30Sjl void
226525cf1a30Sjl cpu_faulted_exit(struct cpu *cp)
226625cf1a30Sjl {}
226725cf1a30Sjl 
226825cf1a30Sjl /*ARGSUSED*/
226925cf1a30Sjl void
227025cf1a30Sjl cpu_check_allcpus(struct async_flt *aflt)
227125cf1a30Sjl {}
227225cf1a30Sjl 
227325cf1a30Sjl /*ARGSUSED*/
227425cf1a30Sjl void
227525cf1a30Sjl cpu_ce_log_err(struct async_flt *aflt, errorq_elem_t *t)
227625cf1a30Sjl { ASSERT(0); }
227725cf1a30Sjl 
227825cf1a30Sjl /*ARGSUSED*/
227925cf1a30Sjl void
228025cf1a30Sjl cpu_check_ce(int flag, uint64_t pa, caddr_t va, uint_t psz)
228125cf1a30Sjl { ASSERT(0); }
228225cf1a30Sjl 
228325cf1a30Sjl /*ARGSUSED*/
228425cf1a30Sjl void
228525cf1a30Sjl cpu_ce_count_unum(struct async_flt *ecc, int len, char *unum)
228625cf1a30Sjl { ASSERT(0); }
228725cf1a30Sjl 
228825cf1a30Sjl /*ARGSUSED*/
228925cf1a30Sjl void
229025cf1a30Sjl cpu_busy_ecache_scrub(struct cpu *cp)
229125cf1a30Sjl {}
229225cf1a30Sjl 
229325cf1a30Sjl /*ARGSUSED*/
229425cf1a30Sjl void
229525cf1a30Sjl cpu_idle_ecache_scrub(struct cpu *cp)
229625cf1a30Sjl {}
229725cf1a30Sjl 
229825cf1a30Sjl /* ARGSUSED */
229925cf1a30Sjl void
230025cf1a30Sjl cpu_change_speed(uint64_t divisor, uint64_t arg2)
230125cf1a30Sjl { ASSERT(0); }
230225cf1a30Sjl 
230325cf1a30Sjl void
230425cf1a30Sjl cpu_init_cache_scrub(void)
230525cf1a30Sjl {}
230625cf1a30Sjl 
230725cf1a30Sjl /* ARGSUSED */
230825cf1a30Sjl int
230925cf1a30Sjl cpu_get_mem_sid(char *unum, char *buf, int buflen, int *lenp)
231025cf1a30Sjl {
23110cc8ae86Sav 	if (&plat_get_mem_sid) {
23120cc8ae86Sav 		return (plat_get_mem_sid(unum, buf, buflen, lenp));
23130cc8ae86Sav 	} else {
23140cc8ae86Sav 		return (ENOTSUP);
23150cc8ae86Sav 	}
231625cf1a30Sjl }
231725cf1a30Sjl 
231825cf1a30Sjl /* ARGSUSED */
231925cf1a30Sjl int
232025cf1a30Sjl cpu_get_mem_addr(char *unum, char *sid, uint64_t offset, uint64_t *addrp)
232125cf1a30Sjl {
23220cc8ae86Sav 	if (&plat_get_mem_addr) {
23230cc8ae86Sav 		return (plat_get_mem_addr(unum, sid, offset, addrp));
23240cc8ae86Sav 	} else {
23250cc8ae86Sav 		return (ENOTSUP);
23260cc8ae86Sav 	}
232725cf1a30Sjl }
232825cf1a30Sjl 
232925cf1a30Sjl /* ARGSUSED */
233025cf1a30Sjl int
233125cf1a30Sjl cpu_get_mem_offset(uint64_t flt_addr, uint64_t *offp)
233225cf1a30Sjl {
23330cc8ae86Sav 	if (&plat_get_mem_offset) {
23340cc8ae86Sav 		return (plat_get_mem_offset(flt_addr, offp));
23350cc8ae86Sav 	} else {
23360cc8ae86Sav 		return (ENOTSUP);
23370cc8ae86Sav 	}
233825cf1a30Sjl }
233925cf1a30Sjl 
234025cf1a30Sjl /*ARGSUSED*/
234125cf1a30Sjl void
234225cf1a30Sjl itlb_rd_entry(uint_t entry, tte_t *tte, uint64_t *va_tag)
234325cf1a30Sjl { ASSERT(0); }
234425cf1a30Sjl 
234525cf1a30Sjl /*ARGSUSED*/
234625cf1a30Sjl void
234725cf1a30Sjl dtlb_rd_entry(uint_t entry, tte_t *tte, uint64_t *va_tag)
234825cf1a30Sjl { ASSERT(0); }
2349f4b0f0a6Shyw 
2350f4b0f0a6Shyw /*ARGSUSED*/
2351f4b0f0a6Shyw void
2352f4b0f0a6Shyw read_ecc_data(struct async_flt *aflt, short verbose, short ce_err)
2353f4b0f0a6Shyw { ASSERT(0); }
2354f4b0f0a6Shyw 
2355f4b0f0a6Shyw /*ARGSUSED*/
2356f4b0f0a6Shyw int
2357f4b0f0a6Shyw ce_scrub_xdiag_recirc(struct async_flt *aflt, errorq_t *eqp,
2358f4b0f0a6Shyw     errorq_elem_t *eqep, size_t afltoffset)
2359f4b0f0a6Shyw {
2360f4b0f0a6Shyw 	ASSERT(0);
2361f4b0f0a6Shyw 	return (0);
2362f4b0f0a6Shyw }
2363f4b0f0a6Shyw 
2364f4b0f0a6Shyw /*ARGSUSED*/
2365f4b0f0a6Shyw char *
2366f4b0f0a6Shyw flt_to_error_type(struct async_flt *aflt)
2367f4b0f0a6Shyw {
2368f4b0f0a6Shyw 	ASSERT(0);
2369f4b0f0a6Shyw 	return (NULL);
2370f4b0f0a6Shyw }
23711ba18ff1Sjimand 
23721ba18ff1Sjimand #define	PROM_SPARC64VII_MODE_PROPNAME	"SPARC64-VII-mode"
23731ba18ff1Sjimand 
23741ba18ff1Sjimand /*
23751ba18ff1Sjimand  * Check for existence of OPL OBP property that indicates
23761ba18ff1Sjimand  * SPARC64-VII support. By default, only enable Jupiter
23771ba18ff1Sjimand  * features if the property is present.   It will be
23781ba18ff1Sjimand  * present in all-Jupiter domains by OBP if the domain has
23791ba18ff1Sjimand  * been selected by the user on the system controller to
23801ba18ff1Sjimand  * run in Jupiter mode.  Basically, this OBP property must
23811ba18ff1Sjimand  * be present to turn on the cpu_alljupiter flag.
23821ba18ff1Sjimand  */
23831ba18ff1Sjimand static int
23841ba18ff1Sjimand prom_SPARC64VII_support_enabled(void)
23851ba18ff1Sjimand {
23861ba18ff1Sjimand 	int val;
23871ba18ff1Sjimand 
23881ba18ff1Sjimand 	return ((prom_getprop(prom_rootnode(), PROM_SPARC64VII_MODE_PROPNAME,
23891ba18ff1Sjimand 	    (caddr_t)&val) == 0) ? 1 : 0);
23901ba18ff1Sjimand }
2391febcc4a5Sjimand 
2392febcc4a5Sjimand #define	PROM_KCTX_PRESERVED_PROPNAME	"context0-page-size-preserved"
2393febcc4a5Sjimand 
2394febcc4a5Sjimand /*
2395febcc4a5Sjimand  * Check for existence of OPL OBP property that indicates support for
2396febcc4a5Sjimand  * preserving Solaris kernel page sizes when entering OBP.  We need to
2397febcc4a5Sjimand  * check the prom tree since the ddi tree is not yet built when the
2398febcc4a5Sjimand  * platform startup sequence is called.
2399febcc4a5Sjimand  */
2400febcc4a5Sjimand static int
2401febcc4a5Sjimand plat_prom_preserve_kctx_is_supported(void)
2402febcc4a5Sjimand {
2403febcc4a5Sjimand 	pnode_t		pnode;
2404febcc4a5Sjimand 	int		val;
2405febcc4a5Sjimand 
2406febcc4a5Sjimand 	/*
2407febcc4a5Sjimand 	 * Check for existence of context0-page-size-preserved property
2408febcc4a5Sjimand 	 * in virtual-memory prom node.
2409febcc4a5Sjimand 	 */
2410febcc4a5Sjimand 	pnode = (pnode_t)prom_getphandle(prom_mmu_ihandle());
2411febcc4a5Sjimand 	return ((prom_getprop(pnode, PROM_KCTX_PRESERVED_PROPNAME,
2412febcc4a5Sjimand 	    (caddr_t)&val) == 0) ? 1 : 0);
2413febcc4a5Sjimand }
2414