xref: /titanic_50/usr/src/uts/sun4v/cpu/niagara.c (revision 80ab886d233f514d54c2a6bdeb9fdfd951bd6881)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5c56c1e58Sgirish  * Common Development and Distribution License (the "License").
6c56c1e58Sgirish  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22c56c1e58Sgirish  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/systm.h>
307c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
317c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
327c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
337c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
347c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h>
357c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
367c478bd9Sstevel@tonic-gate #include <vm/page.h>
377c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
387c478bd9Sstevel@tonic-gate #include <sys/async.h>
397c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
407c478bd9Sstevel@tonic-gate #include <sys/debug.h>
417c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
427c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
437c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
447c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h>
457c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
467c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
477c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
487c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
497c478bd9Sstevel@tonic-gate #include <sys/machtrap.h>
507c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
517c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
527c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
537c478bd9Sstevel@tonic-gate #include <sys/panic.h>
547c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
557c478bd9Sstevel@tonic-gate #include <sys/simulate.h>
567c478bd9Sstevel@tonic-gate #include <sys/fault.h>
57ce0352ebSgirish #include <sys/niagararegs.h>
58ce0352ebSgirish #include <sys/trapstat.h>
59c56c1e58Sgirish #include <sys/hsvc.h>
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	S_VAC_SIZE	MMU_PAGESIZE /* XXXQ? */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Maximum number of contexts
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate #define	MAX_NCTXS	(1 << 13)
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU;
69ce0352ebSgirish static niagara_mmustat_t *cpu_tstat_va;		/* VA of mmustat buffer */
70ce0352ebSgirish static uint64_t cpu_tstat_pa;			/* PA of mmustat buffer */
71c56c1e58Sgirish char cpu_module_name[] = "SUNW,UltraSPARC-T1";
727c478bd9Sstevel@tonic-gate 
73c56c1e58Sgirish /*
74c56c1e58Sgirish  * Hypervisor services information for the NIAGARA CPU module
75c56c1e58Sgirish  */
76c56c1e58Sgirish static boolean_t niagara_hsvc_available = B_TRUE;
77c56c1e58Sgirish static uint64_t niagara_sup_minor;		/* Supported minor number */
78c56c1e58Sgirish static hsvc_info_t niagara_hsvc = {
79c56c1e58Sgirish 	HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA_CPU, 1, 0, cpu_module_name
80c56c1e58Sgirish };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate void
837c478bd9Sstevel@tonic-gate cpu_setup(void)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	extern int at_flags;
867c478bd9Sstevel@tonic-gate 	extern int disable_delay_tlb_flush, delay_tlb_flush;
877c478bd9Sstevel@tonic-gate 	extern int mmu_exported_pagesize_mask;
887c478bd9Sstevel@tonic-gate 	extern int get_cpu_pagesizes(void);
897c478bd9Sstevel@tonic-gate 	extern int cpc_has_overflow_intr;
90c56c1e58Sgirish 	int status;
91c56c1e58Sgirish 
92c56c1e58Sgirish 	/*
93c56c1e58Sgirish 	 * Negotiate the API version for Niagara specific hypervisor
94c56c1e58Sgirish 	 * services.
95c56c1e58Sgirish 	 */
96c56c1e58Sgirish 	status = hsvc_register(&niagara_hsvc, &niagara_sup_minor);
97c56c1e58Sgirish 	if (status != 0) {
98c56c1e58Sgirish 		cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
99*80ab886dSwesolows 		    "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d\n",
100c56c1e58Sgirish 		    niagara_hsvc.hsvc_modname, niagara_hsvc.hsvc_group,
101c56c1e58Sgirish 		    niagara_hsvc.hsvc_major, niagara_hsvc.hsvc_minor, status);
102c56c1e58Sgirish 		niagara_hsvc_available = B_FALSE;
103c56c1e58Sgirish 	}
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
1067c478bd9Sstevel@tonic-gate 	at_flags = EF_SPARC_SUN_US3 | EF_SPARC_32PLUS | EF_SPARC_SUN_US1;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * Use the maximum number of contexts available for Spitfire unless
1107c478bd9Sstevel@tonic-gate 	 * it has been tuned for debugging.
1117c478bd9Sstevel@tonic-gate 	 * We are checking against 0 here since this value can be patched
1127c478bd9Sstevel@tonic-gate 	 * while booting.  It can not be patched via /etc/system since it
1137c478bd9Sstevel@tonic-gate 	 * will be patched too late and thus cause the system to panic.
1147c478bd9Sstevel@tonic-gate 	 */
1157c478bd9Sstevel@tonic-gate 	if (nctxs == 0)
1167c478bd9Sstevel@tonic-gate 		nctxs = MAX_NCTXS;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	if (use_page_coloring) {
1197c478bd9Sstevel@tonic-gate 		do_pg_coloring = 1;
1207c478bd9Sstevel@tonic-gate 		if (use_virtual_coloring)
1217c478bd9Sstevel@tonic-gate 			do_virtual_coloring = 1;
1227c478bd9Sstevel@tonic-gate 	}
1237c478bd9Sstevel@tonic-gate 	/*
1247c478bd9Sstevel@tonic-gate 	 * Initalize supported page sizes information before the PD.
1257c478bd9Sstevel@tonic-gate 	 * If no information is available, then initialize the
1267c478bd9Sstevel@tonic-gate 	 * mmu_exported_pagesize_mask to a reasonable value for that processor.
1277c478bd9Sstevel@tonic-gate 	 */
1287c478bd9Sstevel@tonic-gate 	mmu_exported_pagesize_mask = get_cpu_pagesizes();
1297c478bd9Sstevel@tonic-gate 	if (mmu_exported_pagesize_mask <= 0) {
1307c478bd9Sstevel@tonic-gate 		mmu_exported_pagesize_mask = (1 << TTE8K) | (1 << TTE64K) |
1317c478bd9Sstevel@tonic-gate 		    (1 << TTE4M) | (1 << TTE256M);
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * Tune pp_slots to use up to 1/8th of the tlb entries.
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	pp_slots = MIN(8, MAXPP_SLOTS);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	/*
1407c478bd9Sstevel@tonic-gate 	 * Block stores invalidate all pages of the d$ so pagecopy
1417c478bd9Sstevel@tonic-gate 	 * et. al. do not need virtual translations with virtual
1427c478bd9Sstevel@tonic-gate 	 * coloring taken into consideration.
1437c478bd9Sstevel@tonic-gate 	 */
1447c478bd9Sstevel@tonic-gate 	pp_consistent_coloring = 0;
1457c478bd9Sstevel@tonic-gate 	isa_list =
1467c478bd9Sstevel@tonic-gate 	    "sparcv9 sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 "
1477c478bd9Sstevel@tonic-gate 	    "sparc sparcv9+vis sparcv9+vis2 sparcv8plus+vis sparcv8plus+vis2";
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	cpu_hwcap_flags |= AV_SPARC_ASI_BLK_INIT;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	/*
15207e2e5e8Sgirish 	 * Niagara supports a 48-bit subset of the full 64-bit virtual
15307e2e5e8Sgirish 	 * address space. Virtual addresses between 0x0000800000000000
15407e2e5e8Sgirish 	 * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
15507e2e5e8Sgirish 	 * and must never be mapped. In addition, software must not use
15607e2e5e8Sgirish 	 * pages within 4GB of the VA hole as instruction pages to
15707e2e5e8Sgirish 	 * avoid problems with prefetching into the VA hole.
1587c478bd9Sstevel@tonic-gate 	 *
15907e2e5e8Sgirish 	 * VA hole information should be obtained from the machine
16007e2e5e8Sgirish 	 * description.
1617c478bd9Sstevel@tonic-gate 	 */
16207e2e5e8Sgirish 	hole_start = (caddr_t)(0x800000000000ul - (1ul << 32));
16307e2e5e8Sgirish 	hole_end = (caddr_t)(0xffff800000000000ul + (1ul << 32));
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/*
1667c478bd9Sstevel@tonic-gate 	 * The kpm mapping window.
1677c478bd9Sstevel@tonic-gate 	 * kpm_size:
1687c478bd9Sstevel@tonic-gate 	 *	The size of a single kpm range.
1697c478bd9Sstevel@tonic-gate 	 *	The overall size will be: kpm_size * vac_colors.
1707c478bd9Sstevel@tonic-gate 	 * kpm_vbase:
1717c478bd9Sstevel@tonic-gate 	 *	The virtual start address of the kpm range within the kernel
1727c478bd9Sstevel@tonic-gate 	 *	virtual address space. kpm_vbase has to be kpm_size aligned.
1737c478bd9Sstevel@tonic-gate 	 */
1747c478bd9Sstevel@tonic-gate 	kpm_size = (size_t)(2ull * 1024 * 1024 * 1024 * 1024); /* 2TB */
1757c478bd9Sstevel@tonic-gate 	kpm_size_shift = 41;
1767c478bd9Sstevel@tonic-gate 	kpm_vbase = (caddr_t)0xfffffa0000000000ull; /* 16EB - 6TB */
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	/*
1797c478bd9Sstevel@tonic-gate 	 * The traptrace code uses either %tick or %stick for
1807c478bd9Sstevel@tonic-gate 	 * timestamping.  We have %stick so we can use it.
1817c478bd9Sstevel@tonic-gate 	 */
1827c478bd9Sstevel@tonic-gate 	traptrace_use_stick = 1;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	/*
1857c478bd9Sstevel@tonic-gate 	 * sun4v provides demap_all
1867c478bd9Sstevel@tonic-gate 	 */
1877c478bd9Sstevel@tonic-gate 	if (!disable_delay_tlb_flush)
1887c478bd9Sstevel@tonic-gate 		delay_tlb_flush = 1;
1897c478bd9Sstevel@tonic-gate 	/*
1907c478bd9Sstevel@tonic-gate 	 * Niagara has a performance counter overflow interrupt
1917c478bd9Sstevel@tonic-gate 	 */
1927c478bd9Sstevel@tonic-gate 	cpc_has_overflow_intr = 1;
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #define	MB	 * 1024 * 1024
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Set the magic constants of the implementation.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate void
2007c478bd9Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate 	extern int vac_size, vac_shift;
2037c478bd9Sstevel@tonic-gate 	extern uint_t vac_mask;
2047c478bd9Sstevel@tonic-gate 	int i, a;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	/*
2077c478bd9Sstevel@tonic-gate 	 * The assumption here is that fillsysinfo will eventually
2087c478bd9Sstevel@tonic-gate 	 * have code to fill this info in from the PD.
2097c478bd9Sstevel@tonic-gate 	 * We hard code this for niagara now.
2107c478bd9Sstevel@tonic-gate 	 * Once the PD access library is done this code
2117c478bd9Sstevel@tonic-gate 	 * might need to be changed to get the info from the PD
2127c478bd9Sstevel@tonic-gate 	 */
2137c478bd9Sstevel@tonic-gate 	if (cpunode->ecache_size == 0)
2147c478bd9Sstevel@tonic-gate 		cpunode->ecache_size = 3 MB;
2157c478bd9Sstevel@tonic-gate 	if (cpunode->ecache_linesize == 0)
2167c478bd9Sstevel@tonic-gate 		cpunode->ecache_linesize = 64;
2177c478bd9Sstevel@tonic-gate 	if (cpunode->ecache_associativity == 0)
2187c478bd9Sstevel@tonic-gate 		cpunode->ecache_associativity = 12;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	cpunode->ecache_setsize =
2217c478bd9Sstevel@tonic-gate 	    cpunode->ecache_size / cpunode->ecache_associativity;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	if (ecache_setsize == 0)
2247c478bd9Sstevel@tonic-gate 		ecache_setsize = cpunode->ecache_setsize;
2257c478bd9Sstevel@tonic-gate 	if (ecache_alignsize == 0)
2267c478bd9Sstevel@tonic-gate 		ecache_alignsize = cpunode->ecache_linesize;
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	vac_size = S_VAC_SIZE;
2297c478bd9Sstevel@tonic-gate 	vac_mask = MMU_PAGEMASK & (vac_size - 1);
2307c478bd9Sstevel@tonic-gate 	i = 0; a = vac_size;
2317c478bd9Sstevel@tonic-gate 	while (a >>= 1)
2327c478bd9Sstevel@tonic-gate 		++i;
2337c478bd9Sstevel@tonic-gate 	vac_shift = i;
2347c478bd9Sstevel@tonic-gate 	shm_alignment = vac_size;
2357c478bd9Sstevel@tonic-gate 	vac = 0;
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate static int niagara_cpucnt;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate void
2417c478bd9Sstevel@tonic-gate cpu_init_private(struct cpu *cp)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate 	extern int niagara_kstat_init(void);
2447c478bd9Sstevel@tonic-gate 
24570f54eadSesaxe 	/*
24670f54eadSesaxe 	 * This code change assumes that the virtual cpu ids are identical
24770f54eadSesaxe 	 * to the physical cpu ids which is true for ontario but not for
24870f54eadSesaxe 	 * niagara in general.
24970f54eadSesaxe 	 * This is a temporary fix which will later be modified to obtain
25070f54eadSesaxe 	 * the execution unit sharing information from MD table.
25170f54eadSesaxe 	 */
25270f54eadSesaxe 	cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id / 4);
25370f54eadSesaxe 
2547c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
255c56c1e58Sgirish 	if (niagara_cpucnt++ == 0 && niagara_hsvc_available == B_TRUE) {
2567c478bd9Sstevel@tonic-gate 		(void) niagara_kstat_init();
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate void
2617c478bd9Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp)
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate 	extern int niagara_kstat_fini(void);
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
266c56c1e58Sgirish 	if (--niagara_cpucnt == 0 && niagara_hsvc_available == B_TRUE) {
2677c478bd9Sstevel@tonic-gate 		(void) niagara_kstat_fini();
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate  * On Niagara, any flush will cause all preceding stores to be
2737c478bd9Sstevel@tonic-gate  * synchronized wrt the i$, regardless of address or ASI.  In fact,
2747c478bd9Sstevel@tonic-gate  * the address is ignored, so we always flush address 0.
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate void
2777c478bd9Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	doflush(0);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate #define	IS_FLOAT(i) (((i) & 0x1000000) != 0)
2837c478bd9Sstevel@tonic-gate #define	IS_IBIT_SET(x)	(x & 0x2000)
2847c478bd9Sstevel@tonic-gate #define	IS_VIS1(op, op3)(op == 2 && op3 == 0x36)
2857c478bd9Sstevel@tonic-gate #define	IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi)		\
2867c478bd9Sstevel@tonic-gate 		(op == 3 && (op3 == IOP_V8_LDDFA ||		\
2877c478bd9Sstevel@tonic-gate 		op3 == IOP_V8_STDFA) &&	asi > ASI_SNFL)
2887c478bd9Sstevel@tonic-gate int
2897c478bd9Sstevel@tonic-gate vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault)
2907c478bd9Sstevel@tonic-gate {
2917c478bd9Sstevel@tonic-gate 	char *badaddr;
2927c478bd9Sstevel@tonic-gate 	int instr;
2937c478bd9Sstevel@tonic-gate 	uint_t	optype, op3, asi;
2947c478bd9Sstevel@tonic-gate 	uint_t	rd, ignor;
2957c478bd9Sstevel@tonic-gate 
296efaef81fSarao 	if (!USERMODE(rp->r_tstate))
297efaef81fSarao 		return (-1);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	instr = fetch_user_instr((caddr_t)rp->r_pc);
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	rd = (instr >> 25) & 0x1f;
3027c478bd9Sstevel@tonic-gate 	optype = (instr >> 30) & 0x3;
3037c478bd9Sstevel@tonic-gate 	op3 = (instr >> 19) & 0x3f;
3047c478bd9Sstevel@tonic-gate 	ignor = (instr >> 5) & 0xff;
3057c478bd9Sstevel@tonic-gate 	if (IS_IBIT_SET(instr)) {
3067c478bd9Sstevel@tonic-gate 		asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) &
3077c478bd9Sstevel@tonic-gate 		    TSTATE_ASI_MASK);
3087c478bd9Sstevel@tonic-gate 	} else {
3097c478bd9Sstevel@tonic-gate 		asi = ignor;
3107c478bd9Sstevel@tonic-gate 	}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	if (!IS_VIS1(optype, op3) &&
3137c478bd9Sstevel@tonic-gate 	    !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) {
3147c478bd9Sstevel@tonic-gate 		return (-1);
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 	switch (simulate_unimp(rp, &badaddr)) {
3177c478bd9Sstevel@tonic-gate 	case SIMU_RETRY:
3187c478bd9Sstevel@tonic-gate 		break;	/* regs are already set up */
3197c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	case SIMU_SUCCESS:
3227c478bd9Sstevel@tonic-gate 		/*
3237c478bd9Sstevel@tonic-gate 		 * skip the successfully
3247c478bd9Sstevel@tonic-gate 		 * simulated instruction
3257c478bd9Sstevel@tonic-gate 		 */
3267c478bd9Sstevel@tonic-gate 		rp->r_pc = rp->r_npc;
3277c478bd9Sstevel@tonic-gate 		rp->r_npc += 4;
3287c478bd9Sstevel@tonic-gate 		break;
3297c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	case SIMU_FAULT:
3327c478bd9Sstevel@tonic-gate 		siginfo->si_signo = SIGSEGV;
3337c478bd9Sstevel@tonic-gate 		siginfo->si_code = SEGV_MAPERR;
3347c478bd9Sstevel@tonic-gate 		siginfo->si_addr = badaddr;
3357c478bd9Sstevel@tonic-gate 		*fault = FLTBOUNDS;
3367c478bd9Sstevel@tonic-gate 		break;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	case SIMU_DZERO:
3397c478bd9Sstevel@tonic-gate 		siginfo->si_signo = SIGFPE;
3407c478bd9Sstevel@tonic-gate 		siginfo->si_code = FPE_INTDIV;
3417c478bd9Sstevel@tonic-gate 		siginfo->si_addr = (caddr_t)rp->r_pc;
3427c478bd9Sstevel@tonic-gate 		*fault = FLTIZDIV;
3437c478bd9Sstevel@tonic-gate 		break;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	case SIMU_UNALIGN:
3467c478bd9Sstevel@tonic-gate 		siginfo->si_signo = SIGBUS;
3477c478bd9Sstevel@tonic-gate 		siginfo->si_code = BUS_ADRALN;
3487c478bd9Sstevel@tonic-gate 		siginfo->si_addr = badaddr;
3497c478bd9Sstevel@tonic-gate 		*fault = FLTACCESS;
3507c478bd9Sstevel@tonic-gate 		break;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	case SIMU_ILLEGAL:
3537c478bd9Sstevel@tonic-gate 	default:
3547c478bd9Sstevel@tonic-gate 		siginfo->si_signo = SIGILL;
3557c478bd9Sstevel@tonic-gate 		op3 = (instr >> 19) & 0x3F;
3567c478bd9Sstevel@tonic-gate 		if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) ||
3577c478bd9Sstevel@tonic-gate 		    (op3 == IOP_V8_STDFA)))
3587c478bd9Sstevel@tonic-gate 			siginfo->si_code = ILL_ILLADR;
3597c478bd9Sstevel@tonic-gate 		else
3607c478bd9Sstevel@tonic-gate 			siginfo->si_code = ILL_ILLOPC;
3617c478bd9Sstevel@tonic-gate 		siginfo->si_addr = (caddr_t)rp->r_pc;
3627c478bd9Sstevel@tonic-gate 		*fault = FLTILL;
3637c478bd9Sstevel@tonic-gate 		break;
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 	return (0);
3667c478bd9Sstevel@tonic-gate }
367ce0352ebSgirish 
368ce0352ebSgirish /*
369ce0352ebSgirish  * Trapstat support for Niagara processor
370ce0352ebSgirish  */
371ce0352ebSgirish int
372ce0352ebSgirish cpu_trapstat_conf(int cmd)
373ce0352ebSgirish {
374ce0352ebSgirish 	size_t len;
375ce0352ebSgirish 	uint64_t mmustat_pa, hvret;
376ce0352ebSgirish 	int status = 0;
377ce0352ebSgirish 
378c56c1e58Sgirish 	if (niagara_hsvc_available == B_FALSE)
379c56c1e58Sgirish 		return (ENOTSUP);
380c56c1e58Sgirish 
381ce0352ebSgirish 	switch (cmd) {
382ce0352ebSgirish 	case CPU_TSTATCONF_INIT:
383ce0352ebSgirish 		ASSERT(cpu_tstat_va == NULL);
384ce0352ebSgirish 		len = (NCPU+1) * sizeof (niagara_mmustat_t);
385ce0352ebSgirish 		cpu_tstat_va = contig_mem_alloc_align(len,
386ce0352ebSgirish 		    sizeof (niagara_mmustat_t));
387ce0352ebSgirish 		if (cpu_tstat_va == NULL)
388ce0352ebSgirish 			status = EAGAIN;
389ce0352ebSgirish 		else {
390ce0352ebSgirish 			bzero(cpu_tstat_va, len);
391ce0352ebSgirish 			cpu_tstat_pa = va_to_pa(cpu_tstat_va);
392ce0352ebSgirish 		}
393ce0352ebSgirish 		break;
394ce0352ebSgirish 
395ce0352ebSgirish 	case CPU_TSTATCONF_FINI:
396ce0352ebSgirish 		if (cpu_tstat_va) {
397ce0352ebSgirish 			len = (NCPU+1) * sizeof (niagara_mmustat_t);
398ce0352ebSgirish 			contig_mem_free(cpu_tstat_va, len);
399ce0352ebSgirish 			cpu_tstat_va = NULL;
400ce0352ebSgirish 			cpu_tstat_pa = 0;
401ce0352ebSgirish 		}
402ce0352ebSgirish 		break;
403ce0352ebSgirish 
404ce0352ebSgirish 	case CPU_TSTATCONF_ENABLE:
405ce0352ebSgirish 		hvret = hv_niagara_mmustat_conf((cpu_tstat_pa +
406ce0352ebSgirish 		    (CPU->cpu_id+1) * sizeof (niagara_mmustat_t)),
407ce0352ebSgirish 		    (uint64_t *)&mmustat_pa);
408ce0352ebSgirish 		if (hvret != H_EOK)
409ce0352ebSgirish 			status = EINVAL;
410ce0352ebSgirish 		break;
411ce0352ebSgirish 
412ce0352ebSgirish 	case CPU_TSTATCONF_DISABLE:
413ce0352ebSgirish 		hvret = hv_niagara_mmustat_conf(0, (uint64_t *)&mmustat_pa);
414ce0352ebSgirish 		if (hvret != H_EOK)
415ce0352ebSgirish 			status = EINVAL;
416ce0352ebSgirish 		break;
417ce0352ebSgirish 
418ce0352ebSgirish 	default:
419ce0352ebSgirish 		status = EINVAL;
420ce0352ebSgirish 		break;
421ce0352ebSgirish 	}
422ce0352ebSgirish 	return (status);
423ce0352ebSgirish }
424ce0352ebSgirish 
425ce0352ebSgirish void
426ce0352ebSgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
427ce0352ebSgirish {
428ce0352ebSgirish 	niagara_mmustat_t	*mmustatp;
429ce0352ebSgirish 	tstat_pgszdata_t	*tstatp = (tstat_pgszdata_t *)buf;
430ce0352ebSgirish 	int	i, pgcnt;
431ce0352ebSgirish 
432ce0352ebSgirish 	if (cpu_tstat_va == NULL)
433ce0352ebSgirish 		return;
434ce0352ebSgirish 
435ce0352ebSgirish 	mmustatp = &((niagara_mmustat_t *)cpu_tstat_va)[CPU->cpu_id+1];
436ce0352ebSgirish 	if (tstat_pgszs > NIAGARA_MMUSTAT_PGSZS)
437ce0352ebSgirish 		tstat_pgszs = NIAGARA_MMUSTAT_PGSZS;
438ce0352ebSgirish 
439ce0352ebSgirish 	for (i = 0; i < tstat_pgszs; i++, tstatp++) {
440ce0352ebSgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count =
441ce0352ebSgirish 		    mmustatp->kitsb[i].tsbhit_count;
442ce0352ebSgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time =
443ce0352ebSgirish 		    mmustatp->kitsb[i].tsbhit_time;
444ce0352ebSgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count =
445ce0352ebSgirish 		    mmustatp->uitsb[i].tsbhit_count;
446ce0352ebSgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time =
447ce0352ebSgirish 		    mmustatp->uitsb[i].tsbhit_time;
448ce0352ebSgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count =
449ce0352ebSgirish 		    mmustatp->kdtsb[i].tsbhit_count;
450ce0352ebSgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time =
451ce0352ebSgirish 		    mmustatp->kdtsb[i].tsbhit_time;
452ce0352ebSgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count =
453ce0352ebSgirish 		    mmustatp->udtsb[i].tsbhit_count;
454ce0352ebSgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time =
455ce0352ebSgirish 		    mmustatp->udtsb[i].tsbhit_time;
456ce0352ebSgirish 	}
457ce0352ebSgirish }
458