xref: /onnv-gate/usr/src/uts/sun4v/os/cpc_subr.c (revision 8803:8c01b39012c9)
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
52973Sgovinda  * Common Development and Distribution License (the "License").
62973Sgovinda  * 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  */
210Sstevel@tonic-gate /*
22*8803SJonathan.Haslam@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * sun4u common CPC subroutines.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/time.h>
320Sstevel@tonic-gate #include <sys/atomic.h>
330Sstevel@tonic-gate #include <sys/thread.h>
340Sstevel@tonic-gate #include <sys/regset.h>
350Sstevel@tonic-gate #include <sys/archsystm.h>
360Sstevel@tonic-gate #include <sys/machsystm.h>
370Sstevel@tonic-gate #include <sys/cpc_impl.h>
380Sstevel@tonic-gate #include <sys/cpc_ultra.h>
390Sstevel@tonic-gate #include <sys/sunddi.h>
400Sstevel@tonic-gate #include <sys/intr.h>
410Sstevel@tonic-gate #include <sys/ivintr.h>
420Sstevel@tonic-gate #include <sys/x_call.h>
430Sstevel@tonic-gate #include <sys/cpuvar.h>
440Sstevel@tonic-gate #include <sys/machcpuvar.h>
450Sstevel@tonic-gate #include <sys/cpc_pcbe.h>
460Sstevel@tonic-gate #include <sys/modctl.h>
470Sstevel@tonic-gate #include <sys/sdt.h>
480Sstevel@tonic-gate 
49*8803SJonathan.Haslam@Sun.COM uint64_t	cpc_level15_inum;	/* used in interrupt.s */
50*8803SJonathan.Haslam@Sun.COM int		cpc_has_overflow_intr;	/* set in cheetah.c */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
530Sstevel@tonic-gate extern int kcpc_counts_include_idle;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * Called on the boot CPU during startup.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate void
590Sstevel@tonic-gate kcpc_hw_init(void)
600Sstevel@tonic-gate {
610Sstevel@tonic-gate 	if (cpc_has_overflow_intr) {
620Sstevel@tonic-gate 		cpc_level15_inum = add_softintr(PIL_15,
632973Sgovinda 		    kcpc_hw_overflow_intr, NULL, SOFTINT_MT);
640Sstevel@tonic-gate 	}
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	/*
670Sstevel@tonic-gate 	 * Make sure the boot CPU gets set up.
680Sstevel@tonic-gate 	 */
690Sstevel@tonic-gate 	kcpc_hw_startup_cpu(CPU->cpu_flags);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * Prepare for CPC interrupts and install an idle thread CPC context.
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate void
760Sstevel@tonic-gate kcpc_hw_startup_cpu(ushort_t cpflags)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate 	cpu_t		*cp = CPU;
790Sstevel@tonic-gate 	kthread_t	*t = cp->cpu_idle_thread;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	ASSERT(t->t_bound_cpu == cp);
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
840Sstevel@tonic-gate 		int pstate_save = disable_vec_intr();
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 		ASSERT(cpc_level15_inum != 0);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 		intr_enqueue_req(PIL_15, cpc_level15_inum);
890Sstevel@tonic-gate 		enable_vec_intr(pstate_save);
900Sstevel@tonic-gate 	}
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	if (kcpc_counts_include_idle)
950Sstevel@tonic-gate 		return;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	installctx(t, cp, kcpc_idle_save, kcpc_idle_restore, NULL, NULL,
980Sstevel@tonic-gate 	    NULL, NULL);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * Examine the processor and load an appropriate PCBE.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate int
1050Sstevel@tonic-gate kcpc_hw_load_pcbe(void)
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate 	char		modname[MODMAXNAMELEN+1];
1080Sstevel@tonic-gate 	char		*p, *q;
1090Sstevel@tonic-gate 	int		len, stat;
1100Sstevel@tonic-gate 	extern char	*boot_cpu_compatible_list;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	for (stat = -1, p = boot_cpu_compatible_list; p != NULL; p = q) {
1130Sstevel@tonic-gate 		/*
1140Sstevel@tonic-gate 		 * Get next CPU module name from boot_cpu_compatible_list
1150Sstevel@tonic-gate 		 */
1160Sstevel@tonic-gate 		q = strchr(p, ':');
1170Sstevel@tonic-gate 		len = (q) ? (q - p) : strlen(p);
1180Sstevel@tonic-gate 		if (len < sizeof (modname)) {
1190Sstevel@tonic-gate 			(void) strncpy(modname, p, len);
1200Sstevel@tonic-gate 			modname[len] = '\0';
1210Sstevel@tonic-gate 			stat = kcpc_pcbe_tryload(modname, 0, 0, 0);
1220Sstevel@tonic-gate 			if (stat == 0)
1230Sstevel@tonic-gate 				break;
1240Sstevel@tonic-gate 		}
1250Sstevel@tonic-gate 		if (q)
1260Sstevel@tonic-gate 			q++;			/* skip over ':' */
1270Sstevel@tonic-gate 	}
1280Sstevel@tonic-gate 	return (stat);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate /*ARGSUSED*/
1330Sstevel@tonic-gate static void
1340Sstevel@tonic-gate kcpc_remotestop_func(uint64_t arg1, uint64_t arg2)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate 	ASSERT(CPU->cpu_cpc_ctx != NULL);
1370Sstevel@tonic-gate 	pcbe_ops->pcbe_allstop();
1380Sstevel@tonic-gate 	atomic_or_uint(&CPU->cpu_cpc_ctx->kc_flags, KCPC_CTX_INVALID_STOPPED);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * Ensure the counters are stopped on the given processor.
1430Sstevel@tonic-gate  *
1440Sstevel@tonic-gate  * Callers must ensure kernel preemption is disabled.
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate void
1470Sstevel@tonic-gate kcpc_remote_stop(cpu_t *cp)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate 	xc_one(cp->cpu_id, kcpc_remotestop_func, 0, 0);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*ARGSUSED*/
1530Sstevel@tonic-gate int
1540Sstevel@tonic-gate kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate 	return (0);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate int
1600Sstevel@tonic-gate kcpc_hw_lwp_hook(void)
1610Sstevel@tonic-gate {
1620Sstevel@tonic-gate 	return (0);
1630Sstevel@tonic-gate }
164*8803SJonathan.Haslam@Sun.COM 
165*8803SJonathan.Haslam@Sun.COM /*ARGSUSED*/
166*8803SJonathan.Haslam@Sun.COM static void
167*8803SJonathan.Haslam@Sun.COM kcpc_remoteprogram_func(uint64_t arg1, uint64_t arg2)
168*8803SJonathan.Haslam@Sun.COM {
169*8803SJonathan.Haslam@Sun.COM 	ASSERT(CPU->cpu_cpc_ctx != NULL);
170*8803SJonathan.Haslam@Sun.COM 
171*8803SJonathan.Haslam@Sun.COM 	pcbe_ops->pcbe_program(CPU->cpu_cpc_ctx);
172*8803SJonathan.Haslam@Sun.COM }
173*8803SJonathan.Haslam@Sun.COM 
174*8803SJonathan.Haslam@Sun.COM /*
175*8803SJonathan.Haslam@Sun.COM  * Ensure counters are enabled on the given processor.
176*8803SJonathan.Haslam@Sun.COM  */
177*8803SJonathan.Haslam@Sun.COM void
178*8803SJonathan.Haslam@Sun.COM kcpc_remote_program(cpu_t *cp)
179*8803SJonathan.Haslam@Sun.COM {
180*8803SJonathan.Haslam@Sun.COM 	xc_one(cp->cpu_id, kcpc_remoteprogram_func, 0, 0);
181*8803SJonathan.Haslam@Sun.COM }
182