xref: /illumos-gate/usr/src/uts/sun4v/os/cpc_subr.c (revision 5a469116)
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 /*
221f10d449SChristopher Baumbauer - Oracle America - San Diego United States  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23c21bd51dSDan McDonald  * Copyright 2021 Joyent, Inc.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * sun4u common CPC subroutines.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/time.h>
327c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
337c478bd9Sstevel@tonic-gate #include <sys/thread.h>
347c478bd9Sstevel@tonic-gate #include <sys/regset.h>
357c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
367c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
377c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h>
387c478bd9Sstevel@tonic-gate #include <sys/cpc_ultra.h>
397c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
407c478bd9Sstevel@tonic-gate #include <sys/intr.h>
417c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
427c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
437c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
447c478bd9Sstevel@tonic-gate #include <sys/machcpuvar.h>
457c478bd9Sstevel@tonic-gate #include <sys/cpc_pcbe.h>
467c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
477c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
487c478bd9Sstevel@tonic-gate 
491f10d449SChristopher Baumbauer - Oracle America - San Diego United States uint64_t	cpc_level15_inum = 0;	/* used in interrupt.s */
50b9e93c10SJonathan Haslam 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
kcpc_hw_init(void)597c478bd9Sstevel@tonic-gate kcpc_hw_init(void)
607c478bd9Sstevel@tonic-gate {
611f10d449SChristopher 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
kcpc_hw_startup_cpu(ushort_t cpflags)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 
97*5a469116SPatrick Mooney 	kcpc_idle_ctxop_install(t, cp);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * Examine the processor and load an appropriate PCBE.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate int
kcpc_hw_load_pcbe(void)1047c478bd9Sstevel@tonic-gate kcpc_hw_load_pcbe(void)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	char		modname[MODMAXNAMELEN+1];
1077c478bd9Sstevel@tonic-gate 	char		*p, *q;
1087c478bd9Sstevel@tonic-gate 	int		len, stat;
1097c478bd9Sstevel@tonic-gate 	extern char	*boot_cpu_compatible_list;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	for (stat = -1, p = boot_cpu_compatible_list; p != NULL; p = q) {
1127c478bd9Sstevel@tonic-gate 		/*
1137c478bd9Sstevel@tonic-gate 		 * Get next CPU module name from boot_cpu_compatible_list
1147c478bd9Sstevel@tonic-gate 		 */
1157c478bd9Sstevel@tonic-gate 		q = strchr(p, ':');
1167c478bd9Sstevel@tonic-gate 		len = (q) ? (q - p) : strlen(p);
1177c478bd9Sstevel@tonic-gate 		if (len < sizeof (modname)) {
1187c478bd9Sstevel@tonic-gate 			(void) strncpy(modname, p, len);
1197c478bd9Sstevel@tonic-gate 			modname[len] = '\0';
1207c478bd9Sstevel@tonic-gate 			stat = kcpc_pcbe_tryload(modname, 0, 0, 0);
1217c478bd9Sstevel@tonic-gate 			if (stat == 0)
1227c478bd9Sstevel@tonic-gate 				break;
1237c478bd9Sstevel@tonic-gate 		}
1247c478bd9Sstevel@tonic-gate 		if (q)
1257c478bd9Sstevel@tonic-gate 			q++;			/* skip over ':' */
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate 	return (stat);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1327c478bd9Sstevel@tonic-gate int
kcpc_hw_cpu_hook(processorid_t cpuid,ulong_t * kcpc_cpumap)1337c478bd9Sstevel@tonic-gate kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate 	return (0);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate int
kcpc_hw_lwp_hook(void)1397c478bd9Sstevel@tonic-gate kcpc_hw_lwp_hook(void)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	return (0);
1427c478bd9Sstevel@tonic-gate }
143