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 */
21459190a5Srsmaeda
227c478bd9Sstevel@tonic-gate /*
23*575a7426Spt157919 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
327c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
337c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
347c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
357c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h>
367c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
377c478bd9Sstevel@tonic-gate #include <vm/page.h>
387c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
397c478bd9Sstevel@tonic-gate #include <sys/async.h>
407c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
417c478bd9Sstevel@tonic-gate #include <sys/debug.h>
427c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
437c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
457c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h>
467c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
477c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
487c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
497c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
507c478bd9Sstevel@tonic-gate #include <sys/machtrap.h>
517c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
527c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
537c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
547c478bd9Sstevel@tonic-gate #include <sys/panic.h>
557c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
567c478bd9Sstevel@tonic-gate #include <sys/simulate.h>
577c478bd9Sstevel@tonic-gate #include <sys/fault.h>
58ce0352ebSgirish #include <sys/niagararegs.h>
59ce0352ebSgirish #include <sys/trapstat.h>
60c56c1e58Sgirish #include <sys/hsvc.h>
61*575a7426Spt157919 #include <sys/mutex_impl.h>
627c478bd9Sstevel@tonic-gate
631ae08745Sheppo #define NI_MMU_PAGESIZE_MASK ((1 << TTE8K) | (1 << TTE64K) | (1 << TTE4M) \
641ae08745Sheppo | (1 << TTE256M))
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU;
67ce0352ebSgirish static niagara_mmustat_t *cpu_tstat_va; /* VA of mmustat buffer */
68ce0352ebSgirish static uint64_t cpu_tstat_pa; /* PA of mmustat buffer */
69c56c1e58Sgirish char cpu_module_name[] = "SUNW,UltraSPARC-T1";
707c478bd9Sstevel@tonic-gate
71c56c1e58Sgirish /*
72c56c1e58Sgirish * Hypervisor services information for the NIAGARA CPU module
73c56c1e58Sgirish */
74c56c1e58Sgirish static boolean_t niagara_hsvc_available = B_TRUE;
75c56c1e58Sgirish static uint64_t niagara_sup_minor; /* Supported minor number */
76c56c1e58Sgirish static hsvc_info_t niagara_hsvc = {
77c56c1e58Sgirish HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA_CPU, 1, 0, cpu_module_name
78c56c1e58Sgirish };
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate void
cpu_setup(void)817c478bd9Sstevel@tonic-gate cpu_setup(void)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate extern int mmu_exported_pagesize_mask;
847c478bd9Sstevel@tonic-gate extern int cpc_has_overflow_intr;
85c56c1e58Sgirish int status;
861ae08745Sheppo char *ni_isa_set[] = {
871ae08745Sheppo "sparcv9+vis",
881ae08745Sheppo "sparcv9+vis2",
891ae08745Sheppo "sparcv8plus+vis",
901ae08745Sheppo "sparcv8plus+vis2",
911ae08745Sheppo NULL
921ae08745Sheppo };
93c56c1e58Sgirish
94c56c1e58Sgirish /*
95c56c1e58Sgirish * Negotiate the API version for Niagara specific hypervisor
96c56c1e58Sgirish * services.
97c56c1e58Sgirish */
98c56c1e58Sgirish status = hsvc_register(&niagara_hsvc, &niagara_sup_minor);
99c56c1e58Sgirish if (status != 0) {
100c56c1e58Sgirish cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
10180ab886dSwesolows "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d\n",
102c56c1e58Sgirish niagara_hsvc.hsvc_modname, niagara_hsvc.hsvc_group,
103c56c1e58Sgirish niagara_hsvc.hsvc_major, niagara_hsvc.hsvc_minor, status);
104c56c1e58Sgirish niagara_hsvc_available = B_FALSE;
105c56c1e58Sgirish }
1067c478bd9Sstevel@tonic-gate
1071ae08745Sheppo /*
1081ae08745Sheppo * The setup common to all CPU modules is done in cpu_setup_common
1091ae08745Sheppo * routine.
1101ae08745Sheppo */
1111ae08745Sheppo cpu_setup_common(ni_isa_set);
1121ae08745Sheppo
1137c478bd9Sstevel@tonic-gate cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
1147c478bd9Sstevel@tonic-gate
1151ae08745Sheppo if (broken_md_flag) {
1167c478bd9Sstevel@tonic-gate /*
1171ae08745Sheppo * Turn on the missing bits supported by Niagara CPU in
1181ae08745Sheppo * MMU pagesize mask returned by MD.
1197c478bd9Sstevel@tonic-gate */
1201ae08745Sheppo mmu_exported_pagesize_mask |= NI_MMU_PAGESIZE_MASK;
1211ae08745Sheppo } else {
1221ae08745Sheppo if ((mmu_exported_pagesize_mask &
1231ae08745Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK) !=
1241ae08745Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK)
1251ae08745Sheppo cmn_err(CE_PANIC, "machine description"
1261ae08745Sheppo " does not have required sun4v page sizes"
1271ae08745Sheppo " 8K, 64K and 4M: MD mask is 0x%x",
1281ae08745Sheppo mmu_exported_pagesize_mask);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate cpu_hwcap_flags |= AV_SPARC_ASI_BLK_INIT;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /*
13407e2e5e8Sgirish * Niagara supports a 48-bit subset of the full 64-bit virtual
13507e2e5e8Sgirish * address space. Virtual addresses between 0x0000800000000000
13607e2e5e8Sgirish * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
13707e2e5e8Sgirish * and must never be mapped. In addition, software must not use
13807e2e5e8Sgirish * pages within 4GB of the VA hole as instruction pages to
13907e2e5e8Sgirish * avoid problems with prefetching into the VA hole.
1407c478bd9Sstevel@tonic-gate */
1411ae08745Sheppo hole_start = (caddr_t)((1ull << (va_bits - 1)) - (1ull << 32));
1421ae08745Sheppo hole_end = (caddr_t)((0ull - (1ull << (va_bits - 1))) + (1ull << 32));
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * Niagara has a performance counter overflow interrupt
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate cpc_has_overflow_intr = 1;
14805d3dc4bSpaulsan
14905d3dc4bSpaulsan shctx_on = 0;
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate
1521ae08745Sheppo #define MB(n) ((n) * 1024 * 1024)
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * Set the magic constants of the implementation.
1557c478bd9Sstevel@tonic-gate */
1567c478bd9Sstevel@tonic-gate void
cpu_fiximp(struct cpu_node * cpunode)1577c478bd9Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode)
1587c478bd9Sstevel@tonic-gate {
1597c478bd9Sstevel@tonic-gate /*
1601ae08745Sheppo * The Cache node is optional in MD. Therefore in case "Cache"
1611ae08745Sheppo * node does not exists in MD, set the default L2 cache associativity,
1621ae08745Sheppo * size, linesize.
1637c478bd9Sstevel@tonic-gate */
1647c478bd9Sstevel@tonic-gate if (cpunode->ecache_size == 0)
1651ae08745Sheppo cpunode->ecache_size = MB(3);
1667c478bd9Sstevel@tonic-gate if (cpunode->ecache_linesize == 0)
1677c478bd9Sstevel@tonic-gate cpunode->ecache_linesize = 64;
1687c478bd9Sstevel@tonic-gate if (cpunode->ecache_associativity == 0)
1697c478bd9Sstevel@tonic-gate cpunode->ecache_associativity = 12;
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate void
cpu_map_exec_units(struct cpu * cp)173459190a5Srsmaeda cpu_map_exec_units(struct cpu *cp)
1747c478bd9Sstevel@tonic-gate {
175459190a5Srsmaeda ASSERT(MUTEX_HELD(&cpu_lock));
1767c478bd9Sstevel@tonic-gate
17770f54eadSesaxe /*
178fb2f18f8Sesaxe * The cpu_ipipe and cpu_fpu fields are initialized based on
179459190a5Srsmaeda * the execution unit sharing information from the MD. They
180459190a5Srsmaeda * default to the CPU id in the absence of such information.
18170f54eadSesaxe */
1821ae08745Sheppo cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping;
1831ae08745Sheppo if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND)
1841ae08745Sheppo cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
18570f54eadSesaxe
186fb2f18f8Sesaxe cp->cpu_m.cpu_fpu = cpunodes[cp->cpu_id].fpu_mapping;
187fb2f18f8Sesaxe if (cp->cpu_m.cpu_fpu == NO_EU_MAPPING_FOUND)
188fb2f18f8Sesaxe cp->cpu_m.cpu_fpu = (id_t)(cp->cpu_id);
189fb2f18f8Sesaxe
190fb2f18f8Sesaxe /*
191fb2f18f8Sesaxe * Niagara defines the the core to be at the ipipe level
192fb2f18f8Sesaxe */
193fb2f18f8Sesaxe cp->cpu_m.cpu_core = cp->cpu_m.cpu_ipipe;
19459ac0c16Sdavemq
19559ac0c16Sdavemq /*
19659ac0c16Sdavemq * Niagara systems just have one chip. Therefore, the chip id
197ce8eb11aSdp78419 * mpipe id are always 0.
19859ac0c16Sdavemq */
19959ac0c16Sdavemq cp->cpu_m.cpu_chip = 0;
200ce8eb11aSdp78419 cp->cpu_m.cpu_mpipe = 0;
201459190a5Srsmaeda }
202459190a5Srsmaeda
203*575a7426Spt157919 void
cpu_mutex_delay(void)204*575a7426Spt157919 cpu_mutex_delay(void)
205*575a7426Spt157919 {
206*575a7426Spt157919 /*
207*575a7426Spt157919 * Dummy is the thread-private target of the cas. If multiple strands
208*575a7426Spt157919 * have the same kernel call stack, dummy could fall at the same VA and
209*575a7426Spt157919 * hence the same L2 cache bank. To avoid this, create multiple dummy
210*575a7426Spt157919 * words spread across several cache lines.
211*575a7426Spt157919 */
212*575a7426Spt157919 struct {
213*575a7426Spt157919 long val;
214*575a7426Spt157919 long pad[7];
215*575a7426Spt157919 } dummy[4];
216*575a7426Spt157919
217*575a7426Spt157919 long *ptr = &(dummy[CPU->cpu_seqid & 0x03].val);
218*575a7426Spt157919 cas_delay(ptr);
219*575a7426Spt157919 }
220*575a7426Spt157919
221459190a5Srsmaeda static int niagara_cpucnt;
222459190a5Srsmaeda
223459190a5Srsmaeda void
cpu_init_private(struct cpu * cp)224459190a5Srsmaeda cpu_init_private(struct cpu *cp)
225459190a5Srsmaeda {
226459190a5Srsmaeda extern void niagara_kstat_init(void);
227fb2f18f8Sesaxe
2287c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
229459190a5Srsmaeda
230459190a5Srsmaeda cpu_map_exec_units(cp);
231459190a5Srsmaeda
232459190a5Srsmaeda if ((niagara_cpucnt++ == 0) && (niagara_hsvc_available == B_TRUE))
233459190a5Srsmaeda niagara_kstat_init();
234*575a7426Spt157919
235*575a7426Spt157919 mutex_delay = cpu_mutex_delay;
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
238459190a5Srsmaeda /*ARGSUSED*/
2397c478bd9Sstevel@tonic-gate void
cpu_uninit_private(struct cpu * cp)2407c478bd9Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp)
2417c478bd9Sstevel@tonic-gate {
242459190a5Srsmaeda extern void niagara_kstat_fini(void);
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
245459190a5Srsmaeda
246459190a5Srsmaeda if ((--niagara_cpucnt == 0) && (niagara_hsvc_available == B_TRUE))
247459190a5Srsmaeda niagara_kstat_fini();
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate * On Niagara, any flush will cause all preceding stores to be
2527c478bd9Sstevel@tonic-gate * synchronized wrt the i$, regardless of address or ASI. In fact,
2537c478bd9Sstevel@tonic-gate * the address is ignored, so we always flush address 0.
2547c478bd9Sstevel@tonic-gate */
255b02e9a2dSsvemuri /*ARGSUSED*/
2567c478bd9Sstevel@tonic-gate void
dtrace_flush_sec(uintptr_t addr)2577c478bd9Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate doflush(0);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate #define IS_FLOAT(i) (((i) & 0x1000000) != 0)
2637c478bd9Sstevel@tonic-gate #define IS_IBIT_SET(x) (x & 0x2000)
2647c478bd9Sstevel@tonic-gate #define IS_VIS1(op, op3)(op == 2 && op3 == 0x36)
2657c478bd9Sstevel@tonic-gate #define IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi) \
2667c478bd9Sstevel@tonic-gate (op == 3 && (op3 == IOP_V8_LDDFA || \
2677c478bd9Sstevel@tonic-gate op3 == IOP_V8_STDFA) && asi > ASI_SNFL)
2687c478bd9Sstevel@tonic-gate int
vis1_partial_support(struct regs * rp,k_siginfo_t * siginfo,uint_t * fault)2697c478bd9Sstevel@tonic-gate vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault)
2707c478bd9Sstevel@tonic-gate {
2717c478bd9Sstevel@tonic-gate char *badaddr;
2727c478bd9Sstevel@tonic-gate int instr;
2737c478bd9Sstevel@tonic-gate uint_t optype, op3, asi;
274b02e9a2dSsvemuri uint_t ignor;
2757c478bd9Sstevel@tonic-gate
276efaef81fSarao if (!USERMODE(rp->r_tstate))
277efaef81fSarao return (-1);
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate instr = fetch_user_instr((caddr_t)rp->r_pc);
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate optype = (instr >> 30) & 0x3;
2827c478bd9Sstevel@tonic-gate op3 = (instr >> 19) & 0x3f;
2837c478bd9Sstevel@tonic-gate ignor = (instr >> 5) & 0xff;
2847c478bd9Sstevel@tonic-gate if (IS_IBIT_SET(instr)) {
2857c478bd9Sstevel@tonic-gate asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) &
2867c478bd9Sstevel@tonic-gate TSTATE_ASI_MASK);
2877c478bd9Sstevel@tonic-gate } else {
2887c478bd9Sstevel@tonic-gate asi = ignor;
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate if (!IS_VIS1(optype, op3) &&
2927c478bd9Sstevel@tonic-gate !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) {
2937c478bd9Sstevel@tonic-gate return (-1);
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate switch (simulate_unimp(rp, &badaddr)) {
2967c478bd9Sstevel@tonic-gate case SIMU_RETRY:
2977c478bd9Sstevel@tonic-gate break; /* regs are already set up */
2987c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate case SIMU_SUCCESS:
3017c478bd9Sstevel@tonic-gate /*
3027c478bd9Sstevel@tonic-gate * skip the successfully
3037c478bd9Sstevel@tonic-gate * simulated instruction
3047c478bd9Sstevel@tonic-gate */
3057c478bd9Sstevel@tonic-gate rp->r_pc = rp->r_npc;
3067c478bd9Sstevel@tonic-gate rp->r_npc += 4;
3077c478bd9Sstevel@tonic-gate break;
3087c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate case SIMU_FAULT:
3117c478bd9Sstevel@tonic-gate siginfo->si_signo = SIGSEGV;
3127c478bd9Sstevel@tonic-gate siginfo->si_code = SEGV_MAPERR;
3137c478bd9Sstevel@tonic-gate siginfo->si_addr = badaddr;
3147c478bd9Sstevel@tonic-gate *fault = FLTBOUNDS;
3157c478bd9Sstevel@tonic-gate break;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate case SIMU_DZERO:
3187c478bd9Sstevel@tonic-gate siginfo->si_signo = SIGFPE;
3197c478bd9Sstevel@tonic-gate siginfo->si_code = FPE_INTDIV;
3207c478bd9Sstevel@tonic-gate siginfo->si_addr = (caddr_t)rp->r_pc;
3217c478bd9Sstevel@tonic-gate *fault = FLTIZDIV;
3227c478bd9Sstevel@tonic-gate break;
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate case SIMU_UNALIGN:
3257c478bd9Sstevel@tonic-gate siginfo->si_signo = SIGBUS;
3267c478bd9Sstevel@tonic-gate siginfo->si_code = BUS_ADRALN;
3277c478bd9Sstevel@tonic-gate siginfo->si_addr = badaddr;
3287c478bd9Sstevel@tonic-gate *fault = FLTACCESS;
3297c478bd9Sstevel@tonic-gate break;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate case SIMU_ILLEGAL:
3327c478bd9Sstevel@tonic-gate default:
3337c478bd9Sstevel@tonic-gate siginfo->si_signo = SIGILL;
3347c478bd9Sstevel@tonic-gate op3 = (instr >> 19) & 0x3F;
3357c478bd9Sstevel@tonic-gate if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) ||
3367c478bd9Sstevel@tonic-gate (op3 == IOP_V8_STDFA)))
3377c478bd9Sstevel@tonic-gate siginfo->si_code = ILL_ILLADR;
3387c478bd9Sstevel@tonic-gate else
3397c478bd9Sstevel@tonic-gate siginfo->si_code = ILL_ILLOPC;
3407c478bd9Sstevel@tonic-gate siginfo->si_addr = (caddr_t)rp->r_pc;
3417c478bd9Sstevel@tonic-gate *fault = FLTILL;
3427c478bd9Sstevel@tonic-gate break;
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate return (0);
3457c478bd9Sstevel@tonic-gate }
346ce0352ebSgirish
347ce0352ebSgirish /*
348ce0352ebSgirish * Trapstat support for Niagara processor
349ce0352ebSgirish */
350ce0352ebSgirish int
cpu_trapstat_conf(int cmd)351ce0352ebSgirish cpu_trapstat_conf(int cmd)
352ce0352ebSgirish {
353ce0352ebSgirish size_t len;
354ce0352ebSgirish uint64_t mmustat_pa, hvret;
355ce0352ebSgirish int status = 0;
356ce0352ebSgirish
357c56c1e58Sgirish if (niagara_hsvc_available == B_FALSE)
358c56c1e58Sgirish return (ENOTSUP);
359c56c1e58Sgirish
360ce0352ebSgirish switch (cmd) {
361ce0352ebSgirish case CPU_TSTATCONF_INIT:
362ce0352ebSgirish ASSERT(cpu_tstat_va == NULL);
363ce0352ebSgirish len = (NCPU+1) * sizeof (niagara_mmustat_t);
364ce0352ebSgirish cpu_tstat_va = contig_mem_alloc_align(len,
365ce0352ebSgirish sizeof (niagara_mmustat_t));
366ce0352ebSgirish if (cpu_tstat_va == NULL)
367ce0352ebSgirish status = EAGAIN;
368ce0352ebSgirish else {
369ce0352ebSgirish bzero(cpu_tstat_va, len);
370ce0352ebSgirish cpu_tstat_pa = va_to_pa(cpu_tstat_va);
371ce0352ebSgirish }
372ce0352ebSgirish break;
373ce0352ebSgirish
374ce0352ebSgirish case CPU_TSTATCONF_FINI:
375ce0352ebSgirish if (cpu_tstat_va) {
376ce0352ebSgirish len = (NCPU+1) * sizeof (niagara_mmustat_t);
377ce0352ebSgirish contig_mem_free(cpu_tstat_va, len);
378ce0352ebSgirish cpu_tstat_va = NULL;
379ce0352ebSgirish cpu_tstat_pa = 0;
380ce0352ebSgirish }
381ce0352ebSgirish break;
382ce0352ebSgirish
383ce0352ebSgirish case CPU_TSTATCONF_ENABLE:
384ce0352ebSgirish hvret = hv_niagara_mmustat_conf((cpu_tstat_pa +
385ce0352ebSgirish (CPU->cpu_id+1) * sizeof (niagara_mmustat_t)),
386ce0352ebSgirish (uint64_t *)&mmustat_pa);
387ce0352ebSgirish if (hvret != H_EOK)
388ce0352ebSgirish status = EINVAL;
389ce0352ebSgirish break;
390ce0352ebSgirish
391ce0352ebSgirish case CPU_TSTATCONF_DISABLE:
392ce0352ebSgirish hvret = hv_niagara_mmustat_conf(0, (uint64_t *)&mmustat_pa);
393ce0352ebSgirish if (hvret != H_EOK)
394ce0352ebSgirish status = EINVAL;
395ce0352ebSgirish break;
396ce0352ebSgirish
397ce0352ebSgirish default:
398ce0352ebSgirish status = EINVAL;
399ce0352ebSgirish break;
400ce0352ebSgirish }
401ce0352ebSgirish return (status);
402ce0352ebSgirish }
403ce0352ebSgirish
404ce0352ebSgirish void
cpu_trapstat_data(void * buf,uint_t tstat_pgszs)405ce0352ebSgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
406ce0352ebSgirish {
407ce0352ebSgirish niagara_mmustat_t *mmustatp;
408ce0352ebSgirish tstat_pgszdata_t *tstatp = (tstat_pgszdata_t *)buf;
409b02e9a2dSsvemuri int i;
410ce0352ebSgirish
411ce0352ebSgirish if (cpu_tstat_va == NULL)
412ce0352ebSgirish return;
413ce0352ebSgirish
414ce0352ebSgirish mmustatp = &((niagara_mmustat_t *)cpu_tstat_va)[CPU->cpu_id+1];
415ce0352ebSgirish if (tstat_pgszs > NIAGARA_MMUSTAT_PGSZS)
416ce0352ebSgirish tstat_pgszs = NIAGARA_MMUSTAT_PGSZS;
417ce0352ebSgirish
418ce0352ebSgirish for (i = 0; i < tstat_pgszs; i++, tstatp++) {
419ce0352ebSgirish tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count =
420ce0352ebSgirish mmustatp->kitsb[i].tsbhit_count;
421ce0352ebSgirish tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time =
422ce0352ebSgirish mmustatp->kitsb[i].tsbhit_time;
423ce0352ebSgirish tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count =
424ce0352ebSgirish mmustatp->uitsb[i].tsbhit_count;
425ce0352ebSgirish tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time =
426ce0352ebSgirish mmustatp->uitsb[i].tsbhit_time;
427ce0352ebSgirish tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count =
428ce0352ebSgirish mmustatp->kdtsb[i].tsbhit_count;
429ce0352ebSgirish tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time =
430ce0352ebSgirish mmustatp->kdtsb[i].tsbhit_time;
431ce0352ebSgirish tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count =
432ce0352ebSgirish mmustatp->udtsb[i].tsbhit_count;
433ce0352ebSgirish tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time =
434ce0352ebSgirish mmustatp->udtsb[i].tsbhit_time;
435ce0352ebSgirish }
436ce0352ebSgirish }
437