xref: /onnv-gate/usr/src/uts/sun4v/cpu/niagara.c (revision 5834:66e26b3fbcc7)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51592Sgirish  * Common Development and Distribution License (the "License").
61592Sgirish  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
214203Srsmaeda 
220Sstevel@tonic-gate /*
23*5834Spt157919  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/systm.h>
310Sstevel@tonic-gate #include <sys/archsystm.h>
320Sstevel@tonic-gate #include <sys/machparam.h>
330Sstevel@tonic-gate #include <sys/machsystm.h>
340Sstevel@tonic-gate #include <sys/cpu.h>
350Sstevel@tonic-gate #include <sys/elf_SPARC.h>
360Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
370Sstevel@tonic-gate #include <vm/page.h>
380Sstevel@tonic-gate #include <sys/cpuvar.h>
390Sstevel@tonic-gate #include <sys/async.h>
400Sstevel@tonic-gate #include <sys/cmn_err.h>
410Sstevel@tonic-gate #include <sys/debug.h>
420Sstevel@tonic-gate #include <sys/dditypes.h>
430Sstevel@tonic-gate #include <sys/sunddi.h>
440Sstevel@tonic-gate #include <sys/cpu_module.h>
450Sstevel@tonic-gate #include <sys/prom_debug.h>
460Sstevel@tonic-gate #include <sys/vmsystm.h>
470Sstevel@tonic-gate #include <sys/prom_plat.h>
480Sstevel@tonic-gate #include <sys/sysmacros.h>
490Sstevel@tonic-gate #include <sys/intreg.h>
500Sstevel@tonic-gate #include <sys/machtrap.h>
510Sstevel@tonic-gate #include <sys/ontrap.h>
520Sstevel@tonic-gate #include <sys/ivintr.h>
530Sstevel@tonic-gate #include <sys/atomic.h>
540Sstevel@tonic-gate #include <sys/panic.h>
550Sstevel@tonic-gate #include <sys/dtrace.h>
560Sstevel@tonic-gate #include <sys/simulate.h>
570Sstevel@tonic-gate #include <sys/fault.h>
581050Sgirish #include <sys/niagararegs.h>
591050Sgirish #include <sys/trapstat.h>
601592Sgirish #include <sys/hsvc.h>
61*5834Spt157919 #include <sys/mutex_impl.h>
620Sstevel@tonic-gate 
631991Sheppo #define	NI_MMU_PAGESIZE_MASK	((1 << TTE8K) | (1 << TTE64K) | (1 << TTE4M) \
641991Sheppo 				    | (1 << TTE256M))
650Sstevel@tonic-gate 
660Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU;
671050Sgirish static niagara_mmustat_t *cpu_tstat_va;		/* VA of mmustat buffer */
681050Sgirish static uint64_t cpu_tstat_pa;			/* PA of mmustat buffer */
691592Sgirish char cpu_module_name[] = "SUNW,UltraSPARC-T1";
700Sstevel@tonic-gate 
711592Sgirish /*
721592Sgirish  * Hypervisor services information for the NIAGARA CPU module
731592Sgirish  */
741592Sgirish static boolean_t niagara_hsvc_available = B_TRUE;
751592Sgirish static uint64_t niagara_sup_minor;		/* Supported minor number */
761592Sgirish static hsvc_info_t niagara_hsvc = {
771592Sgirish 	HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA_CPU, 1, 0, cpu_module_name
781592Sgirish };
790Sstevel@tonic-gate 
800Sstevel@tonic-gate void
cpu_setup(void)810Sstevel@tonic-gate cpu_setup(void)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	extern int mmu_exported_pagesize_mask;
840Sstevel@tonic-gate 	extern int cpc_has_overflow_intr;
851592Sgirish 	int status;
861991Sheppo 	char *ni_isa_set[] = {
871991Sheppo 	    "sparcv9+vis",
881991Sheppo 	    "sparcv9+vis2",
891991Sheppo 	    "sparcv8plus+vis",
901991Sheppo 	    "sparcv8plus+vis2",
911991Sheppo 	    NULL
921991Sheppo 	};
931592Sgirish 
941592Sgirish 	/*
951592Sgirish 	 * Negotiate the API version for Niagara specific hypervisor
961592Sgirish 	 * services.
971592Sgirish 	 */
981592Sgirish 	status = hsvc_register(&niagara_hsvc, &niagara_sup_minor);
991592Sgirish 	if (status != 0) {
1001592Sgirish 		cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
1011717Swesolows 		    "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d\n",
1021592Sgirish 		    niagara_hsvc.hsvc_modname, niagara_hsvc.hsvc_group,
1031592Sgirish 		    niagara_hsvc.hsvc_major, niagara_hsvc.hsvc_minor, status);
1041592Sgirish 		niagara_hsvc_available = B_FALSE;
1051592Sgirish 	}
1060Sstevel@tonic-gate 
1071991Sheppo 	/*
1081991Sheppo 	 * The setup common to all CPU modules is done in cpu_setup_common
1091991Sheppo 	 * routine.
1101991Sheppo 	 */
1111991Sheppo 	cpu_setup_common(ni_isa_set);
1121991Sheppo 
1130Sstevel@tonic-gate 	cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
1140Sstevel@tonic-gate 
1151991Sheppo 	if (broken_md_flag) {
1161991Sheppo 		/*
1171991Sheppo 		 * Turn on the missing bits supported by Niagara CPU in
1181991Sheppo 		 * MMU pagesize mask returned by MD.
1191991Sheppo 		 */
1201991Sheppo 		mmu_exported_pagesize_mask |= NI_MMU_PAGESIZE_MASK;
1211991Sheppo 	} else {
1221991Sheppo 		if ((mmu_exported_pagesize_mask &
1231991Sheppo 		    DEFAULT_SUN4V_MMU_PAGESIZE_MASK) !=
1241991Sheppo 		    DEFAULT_SUN4V_MMU_PAGESIZE_MASK)
1251991Sheppo 			cmn_err(CE_PANIC, "machine description"
1261991Sheppo 			    " does not have required sun4v page sizes"
1271991Sheppo 			    " 8K, 64K and 4M: MD mask is 0x%x",
1281991Sheppo 			    mmu_exported_pagesize_mask);
1290Sstevel@tonic-gate 	}
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	cpu_hwcap_flags |= AV_SPARC_ASI_BLK_INIT;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	/*
134303Sgirish 	 * Niagara supports a 48-bit subset of the full 64-bit virtual
135303Sgirish 	 * address space. Virtual addresses between 0x0000800000000000
136303Sgirish 	 * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
137303Sgirish 	 * and must never be mapped. In addition, software must not use
138303Sgirish 	 * pages within 4GB of the VA hole as instruction pages to
139303Sgirish 	 * avoid problems with prefetching into the VA hole.
1400Sstevel@tonic-gate 	 */
1411991Sheppo 	hole_start = (caddr_t)((1ull << (va_bits - 1)) - (1ull << 32));
1421991Sheppo 	hole_end = (caddr_t)((0ull - (1ull << (va_bits - 1))) + (1ull << 32));
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	/*
1450Sstevel@tonic-gate 	 * Niagara has a performance counter overflow interrupt
1460Sstevel@tonic-gate 	 */
1470Sstevel@tonic-gate 	cpc_has_overflow_intr = 1;
1484528Spaulsan 
1494528Spaulsan 	shctx_on = 0;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
1521991Sheppo #define	MB(n)	((n) * 1024 * 1024)
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Set the magic constants of the implementation.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate void
cpu_fiximp(struct cpu_node * cpunode)1570Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate 	/*
1601991Sheppo 	 * The Cache node is optional in MD. Therefore in case "Cache"
1611991Sheppo 	 * node does not exists in MD, set the default L2 cache associativity,
1621991Sheppo 	 * size, linesize.
1630Sstevel@tonic-gate 	 */
1640Sstevel@tonic-gate 	if (cpunode->ecache_size == 0)
1651991Sheppo 		cpunode->ecache_size = MB(3);
1660Sstevel@tonic-gate 	if (cpunode->ecache_linesize == 0)
1670Sstevel@tonic-gate 		cpunode->ecache_linesize = 64;
1680Sstevel@tonic-gate 	if (cpunode->ecache_associativity == 0)
1690Sstevel@tonic-gate 		cpunode->ecache_associativity = 12;
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate void
cpu_map_exec_units(struct cpu * cp)1734203Srsmaeda cpu_map_exec_units(struct cpu *cp)
1740Sstevel@tonic-gate {
1754203Srsmaeda 	ASSERT(MUTEX_HELD(&cpu_lock));
1760Sstevel@tonic-gate 
177220Sesaxe 	/*
1783434Sesaxe 	 * The cpu_ipipe and cpu_fpu fields are initialized based on
1794203Srsmaeda 	 * the execution unit sharing information from the MD. They
1804203Srsmaeda 	 * default to the CPU id in the absence of such information.
181220Sesaxe 	 */
1821991Sheppo 	cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping;
1831991Sheppo 	if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND)
1841991Sheppo 		cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
185220Sesaxe 
1863434Sesaxe 	cp->cpu_m.cpu_fpu = cpunodes[cp->cpu_id].fpu_mapping;
1873434Sesaxe 	if (cp->cpu_m.cpu_fpu == NO_EU_MAPPING_FOUND)
1883434Sesaxe 		cp->cpu_m.cpu_fpu = (id_t)(cp->cpu_id);
1893434Sesaxe 
1903434Sesaxe 	/*
1913434Sesaxe 	 * Niagara defines the the core to be at the ipipe level
1923434Sesaxe 	 */
1933434Sesaxe 	cp->cpu_m.cpu_core = cp->cpu_m.cpu_ipipe;
1944732Sdavemq 
1954732Sdavemq 	/*
1964732Sdavemq 	 * Niagara systems just have one chip. Therefore, the chip id
1974769Sdp78419 	 * mpipe id are always 0.
1984732Sdavemq 	 */
1994732Sdavemq 	cp->cpu_m.cpu_chip = 0;
2004769Sdp78419 	cp->cpu_m.cpu_mpipe = 0;
2014203Srsmaeda }
2024203Srsmaeda 
203*5834Spt157919 void
cpu_mutex_delay(void)204*5834Spt157919 cpu_mutex_delay(void)
205*5834Spt157919 {
206*5834Spt157919 	/*
207*5834Spt157919 	 * Dummy is the thread-private target of the cas.  If multiple strands
208*5834Spt157919 	 * have the same kernel call stack, dummy could fall at the same VA and
209*5834Spt157919 	 * hence the same L2 cache bank.  To avoid this, create multiple dummy
210*5834Spt157919 	 * words spread across several cache lines.
211*5834Spt157919 	 */
212*5834Spt157919 	struct {
213*5834Spt157919 		long val;
214*5834Spt157919 		long pad[7];
215*5834Spt157919 	} dummy[4];
216*5834Spt157919 
217*5834Spt157919 	long *ptr = &(dummy[CPU->cpu_seqid & 0x03].val);
218*5834Spt157919 	cas_delay(ptr);
219*5834Spt157919 }
220*5834Spt157919 
2214203Srsmaeda static int niagara_cpucnt;
2224203Srsmaeda 
2234203Srsmaeda void
cpu_init_private(struct cpu * cp)2244203Srsmaeda cpu_init_private(struct cpu *cp)
2254203Srsmaeda {
2264203Srsmaeda 	extern void niagara_kstat_init(void);
2273434Sesaxe 
2280Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2294203Srsmaeda 
2304203Srsmaeda 	cpu_map_exec_units(cp);
2314203Srsmaeda 
2324203Srsmaeda 	if ((niagara_cpucnt++ == 0) && (niagara_hsvc_available == B_TRUE))
2334203Srsmaeda 		niagara_kstat_init();
234*5834Spt157919 
235*5834Spt157919 	mutex_delay = cpu_mutex_delay;
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate 
2384203Srsmaeda /*ARGSUSED*/
2390Sstevel@tonic-gate void
cpu_uninit_private(struct cpu * cp)2400Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp)
2410Sstevel@tonic-gate {
2424203Srsmaeda 	extern void niagara_kstat_fini(void);
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2454203Srsmaeda 
2464203Srsmaeda 	if ((--niagara_cpucnt == 0) && (niagara_hsvc_available == B_TRUE))
2474203Srsmaeda 		niagara_kstat_fini();
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate  * On Niagara, any flush will cause all preceding stores to be
2520Sstevel@tonic-gate  * synchronized wrt the i$, regardless of address or ASI.  In fact,
2530Sstevel@tonic-gate  * the address is ignored, so we always flush address 0.
2540Sstevel@tonic-gate  */
2555352Ssvemuri /*ARGSUSED*/
2560Sstevel@tonic-gate void
dtrace_flush_sec(uintptr_t addr)2570Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate 	doflush(0);
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #define	IS_FLOAT(i) (((i) & 0x1000000) != 0)
2630Sstevel@tonic-gate #define	IS_IBIT_SET(x)	(x & 0x2000)
2640Sstevel@tonic-gate #define	IS_VIS1(op, op3)(op == 2 && op3 == 0x36)
2650Sstevel@tonic-gate #define	IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi)		\
2660Sstevel@tonic-gate 		(op == 3 && (op3 == IOP_V8_LDDFA ||		\
2670Sstevel@tonic-gate 		op3 == IOP_V8_STDFA) &&	asi > ASI_SNFL)
2680Sstevel@tonic-gate int
vis1_partial_support(struct regs * rp,k_siginfo_t * siginfo,uint_t * fault)2690Sstevel@tonic-gate vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate 	char *badaddr;
2720Sstevel@tonic-gate 	int instr;
2730Sstevel@tonic-gate 	uint_t	optype, op3, asi;
2745352Ssvemuri 	uint_t	ignor;
2750Sstevel@tonic-gate 
276526Sarao 	if (!USERMODE(rp->r_tstate))
277526Sarao 		return (-1);
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 	instr = fetch_user_instr((caddr_t)rp->r_pc);
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	optype = (instr >> 30) & 0x3;
2820Sstevel@tonic-gate 	op3 = (instr >> 19) & 0x3f;
2830Sstevel@tonic-gate 	ignor = (instr >> 5) & 0xff;
2840Sstevel@tonic-gate 	if (IS_IBIT_SET(instr)) {
2850Sstevel@tonic-gate 		asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) &
2860Sstevel@tonic-gate 		    TSTATE_ASI_MASK);
2870Sstevel@tonic-gate 	} else {
2880Sstevel@tonic-gate 		asi = ignor;
2890Sstevel@tonic-gate 	}
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 	if (!IS_VIS1(optype, op3) &&
2920Sstevel@tonic-gate 	    !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) {
2930Sstevel@tonic-gate 		return (-1);
2940Sstevel@tonic-gate 	}
2950Sstevel@tonic-gate 	switch (simulate_unimp(rp, &badaddr)) {
2960Sstevel@tonic-gate 	case SIMU_RETRY:
2970Sstevel@tonic-gate 		break;	/* regs are already set up */
2980Sstevel@tonic-gate 		/*NOTREACHED*/
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	case SIMU_SUCCESS:
3010Sstevel@tonic-gate 		/*
3020Sstevel@tonic-gate 		 * skip the successfully
3030Sstevel@tonic-gate 		 * simulated instruction
3040Sstevel@tonic-gate 		 */
3050Sstevel@tonic-gate 		rp->r_pc = rp->r_npc;
3060Sstevel@tonic-gate 		rp->r_npc += 4;
3070Sstevel@tonic-gate 		break;
3080Sstevel@tonic-gate 		/*NOTREACHED*/
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	case SIMU_FAULT:
3110Sstevel@tonic-gate 		siginfo->si_signo = SIGSEGV;
3120Sstevel@tonic-gate 		siginfo->si_code = SEGV_MAPERR;
3130Sstevel@tonic-gate 		siginfo->si_addr = badaddr;
3140Sstevel@tonic-gate 		*fault = FLTBOUNDS;
3150Sstevel@tonic-gate 		break;
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 	case SIMU_DZERO:
3180Sstevel@tonic-gate 		siginfo->si_signo = SIGFPE;
3190Sstevel@tonic-gate 		siginfo->si_code = FPE_INTDIV;
3200Sstevel@tonic-gate 		siginfo->si_addr = (caddr_t)rp->r_pc;
3210Sstevel@tonic-gate 		*fault = FLTIZDIV;
3220Sstevel@tonic-gate 		break;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 	case SIMU_UNALIGN:
3250Sstevel@tonic-gate 		siginfo->si_signo = SIGBUS;
3260Sstevel@tonic-gate 		siginfo->si_code = BUS_ADRALN;
3270Sstevel@tonic-gate 		siginfo->si_addr = badaddr;
3280Sstevel@tonic-gate 		*fault = FLTACCESS;
3290Sstevel@tonic-gate 		break;
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	case SIMU_ILLEGAL:
3320Sstevel@tonic-gate 	default:
3330Sstevel@tonic-gate 		siginfo->si_signo = SIGILL;
3340Sstevel@tonic-gate 		op3 = (instr >> 19) & 0x3F;
3350Sstevel@tonic-gate 		if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) ||
3360Sstevel@tonic-gate 		    (op3 == IOP_V8_STDFA)))
3370Sstevel@tonic-gate 			siginfo->si_code = ILL_ILLADR;
3380Sstevel@tonic-gate 		else
3390Sstevel@tonic-gate 			siginfo->si_code = ILL_ILLOPC;
3400Sstevel@tonic-gate 		siginfo->si_addr = (caddr_t)rp->r_pc;
3410Sstevel@tonic-gate 		*fault = FLTILL;
3420Sstevel@tonic-gate 		break;
3430Sstevel@tonic-gate 	}
3440Sstevel@tonic-gate 	return (0);
3450Sstevel@tonic-gate }
3461050Sgirish 
3471050Sgirish /*
3481050Sgirish  * Trapstat support for Niagara processor
3491050Sgirish  */
3501050Sgirish int
cpu_trapstat_conf(int cmd)3511050Sgirish cpu_trapstat_conf(int cmd)
3521050Sgirish {
3531050Sgirish 	size_t len;
3541050Sgirish 	uint64_t mmustat_pa, hvret;
3551050Sgirish 	int status = 0;
3561050Sgirish 
3571592Sgirish 	if (niagara_hsvc_available == B_FALSE)
3581592Sgirish 		return (ENOTSUP);
3591592Sgirish 
3601050Sgirish 	switch (cmd) {
3611050Sgirish 	case CPU_TSTATCONF_INIT:
3621050Sgirish 		ASSERT(cpu_tstat_va == NULL);
3631050Sgirish 		len = (NCPU+1) * sizeof (niagara_mmustat_t);
3641050Sgirish 		cpu_tstat_va = contig_mem_alloc_align(len,
3651050Sgirish 		    sizeof (niagara_mmustat_t));
3661050Sgirish 		if (cpu_tstat_va == NULL)
3671050Sgirish 			status = EAGAIN;
3681050Sgirish 		else {
3691050Sgirish 			bzero(cpu_tstat_va, len);
3701050Sgirish 			cpu_tstat_pa = va_to_pa(cpu_tstat_va);
3711050Sgirish 		}
3721050Sgirish 		break;
3731050Sgirish 
3741050Sgirish 	case CPU_TSTATCONF_FINI:
3751050Sgirish 		if (cpu_tstat_va) {
3761050Sgirish 			len = (NCPU+1) * sizeof (niagara_mmustat_t);
3771050Sgirish 			contig_mem_free(cpu_tstat_va, len);
3781050Sgirish 			cpu_tstat_va = NULL;
3791050Sgirish 			cpu_tstat_pa = 0;
3801050Sgirish 		}
3811050Sgirish 		break;
3821050Sgirish 
3831050Sgirish 	case CPU_TSTATCONF_ENABLE:
3841050Sgirish 		hvret = hv_niagara_mmustat_conf((cpu_tstat_pa +
3851050Sgirish 		    (CPU->cpu_id+1) * sizeof (niagara_mmustat_t)),
3861050Sgirish 		    (uint64_t *)&mmustat_pa);
3871050Sgirish 		if (hvret != H_EOK)
3881050Sgirish 			status = EINVAL;
3891050Sgirish 		break;
3901050Sgirish 
3911050Sgirish 	case CPU_TSTATCONF_DISABLE:
3921050Sgirish 		hvret = hv_niagara_mmustat_conf(0, (uint64_t *)&mmustat_pa);
3931050Sgirish 		if (hvret != H_EOK)
3941050Sgirish 			status = EINVAL;
3951050Sgirish 		break;
3961050Sgirish 
3971050Sgirish 	default:
3981050Sgirish 		status = EINVAL;
3991050Sgirish 		break;
4001050Sgirish 	}
4011050Sgirish 	return (status);
4021050Sgirish }
4031050Sgirish 
4041050Sgirish void
cpu_trapstat_data(void * buf,uint_t tstat_pgszs)4051050Sgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
4061050Sgirish {
4071050Sgirish 	niagara_mmustat_t	*mmustatp;
4081050Sgirish 	tstat_pgszdata_t	*tstatp = (tstat_pgszdata_t *)buf;
4095352Ssvemuri 	int	i;
4101050Sgirish 
4111050Sgirish 	if (cpu_tstat_va == NULL)
4121050Sgirish 		return;
4131050Sgirish 
4141050Sgirish 	mmustatp = &((niagara_mmustat_t *)cpu_tstat_va)[CPU->cpu_id+1];
4151050Sgirish 	if (tstat_pgszs > NIAGARA_MMUSTAT_PGSZS)
4161050Sgirish 		tstat_pgszs = NIAGARA_MMUSTAT_PGSZS;
4171050Sgirish 
4181050Sgirish 	for (i = 0; i < tstat_pgszs; i++, tstatp++) {
4191050Sgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count =
4201050Sgirish 		    mmustatp->kitsb[i].tsbhit_count;
4211050Sgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time =
4221050Sgirish 		    mmustatp->kitsb[i].tsbhit_time;
4231050Sgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count =
4241050Sgirish 		    mmustatp->uitsb[i].tsbhit_count;
4251050Sgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time =
4261050Sgirish 		    mmustatp->uitsb[i].tsbhit_time;
4271050Sgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count =
4281050Sgirish 		    mmustatp->kdtsb[i].tsbhit_count;
4291050Sgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time =
4301050Sgirish 		    mmustatp->kdtsb[i].tsbhit_time;
4311050Sgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count =
4321050Sgirish 		    mmustatp->udtsb[i].tsbhit_count;
4331050Sgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time =
4341050Sgirish 		    mmustatp->udtsb[i].tsbhit_time;
4351050Sgirish 	}
4361050Sgirish }
437