xref: /titanic_51/usr/src/uts/sun4u/os/cpc_subr.c (revision 1f10d449561c68a9cd8fbba556489f89a1138415)
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
5b0fc0e77Sgovinda  * Common Development and Distribution License (the "License").
6b0fc0e77Sgovinda  * 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 /*
22*1f10d449SChristopher Baumbauer - Oracle America - San Diego United States  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * sun4u common CPC subroutines.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/time.h>
317c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
327c478bd9Sstevel@tonic-gate #include <sys/thread.h>
337c478bd9Sstevel@tonic-gate #include <sys/regset.h>
347c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
357c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
367c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h>
377c478bd9Sstevel@tonic-gate #include <sys/cpc_ultra.h>
387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
397c478bd9Sstevel@tonic-gate #include <sys/intr.h>
407c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
417c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
427c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
437c478bd9Sstevel@tonic-gate #include <sys/machcpuvar.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpc_pcbe.h>
457c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
467c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
47b885580bSAlexander Kolbasov #include <sys/kcpc.h>
487c478bd9Sstevel@tonic-gate 
49*1f10d449SChristopher Baumbauer - Oracle America - San Diego United States uint64_t	cpc_level15_inum = 0;	/* used in interrupt.s */
507c478bd9Sstevel@tonic-gate int		cpc_has_overflow_intr;	/* set in cheetah.c */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
537c478bd9Sstevel@tonic-gate extern int kcpc_counts_include_idle;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Called on the boot CPU during startup.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate void
597c478bd9Sstevel@tonic-gate kcpc_hw_init(void)
607c478bd9Sstevel@tonic-gate {
61*1f10d449SChristopher Baumbauer - Oracle America - San Diego United States 	if ((cpc_has_overflow_intr) && (cpc_level15_inum == 0)) {
627c478bd9Sstevel@tonic-gate 		cpc_level15_inum = add_softintr(PIL_15,
63b0fc0e77Sgovinda 		    kcpc_hw_overflow_intr, NULL, SOFTINT_MT);
647c478bd9Sstevel@tonic-gate 	}
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/*
677c478bd9Sstevel@tonic-gate 	 * Make sure the boot CPU gets set up.
687c478bd9Sstevel@tonic-gate 	 */
697c478bd9Sstevel@tonic-gate 	kcpc_hw_startup_cpu(CPU->cpu_flags);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Prepare for CPC interrupts and install an idle thread CPC context.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate void
767c478bd9Sstevel@tonic-gate kcpc_hw_startup_cpu(ushort_t cpflags)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	cpu_t		*cp = CPU;
797c478bd9Sstevel@tonic-gate 	kthread_t	*t = cp->cpu_idle_thread;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	ASSERT(t->t_bound_cpu == cp);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
847c478bd9Sstevel@tonic-gate 		int pstate_save = disable_vec_intr();
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 		ASSERT(cpc_level15_inum != 0);
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 		intr_enqueue_req(PIL_15, cpc_level15_inum);
897c478bd9Sstevel@tonic-gate 		enable_vec_intr(pstate_save);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	if (kcpc_counts_include_idle)
957c478bd9Sstevel@tonic-gate 		return;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	installctx(t, cp, kcpc_idle_save, kcpc_idle_restore, NULL, NULL,
987c478bd9Sstevel@tonic-gate 	    NULL, NULL);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * Examine the processor and load an appropriate PCBE.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate int
1057c478bd9Sstevel@tonic-gate kcpc_hw_load_pcbe(void)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	uint64_t	ver = ultra_getver();
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	return (kcpc_pcbe_tryload(NULL, ULTRA_VER_MANUF(ver),
1107c478bd9Sstevel@tonic-gate 	    ULTRA_VER_IMPL(ver), ULTRA_VER_MASK(ver)));
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1147c478bd9Sstevel@tonic-gate int
1157c478bd9Sstevel@tonic-gate kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate 	return (0);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate int
1217c478bd9Sstevel@tonic-gate kcpc_hw_lwp_hook(void)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	return (0);
1247c478bd9Sstevel@tonic-gate }
125