xref: /illumos-gate/usr/src/uts/sun4u/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) 1999, 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>
48b885580bSAlexander Kolbasov #include <sys/kcpc.h>
497c478bd9Sstevel@tonic-gate 
501f10d449SChristopher Baumbauer - Oracle America - San Diego United States uint64_t	cpc_level15_inum = 0;	/* used in interrupt.s */
51b9e93c10SJonathan Haslam int		cpc_has_overflow_intr;	/* set in cheetah.c */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
547c478bd9Sstevel@tonic-gate extern int kcpc_counts_include_idle;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * Called on the boot CPU during startup.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate void
kcpc_hw_init(void)607c478bd9Sstevel@tonic-gate kcpc_hw_init(void)
617c478bd9Sstevel@tonic-gate {
621f10d449SChristopher Baumbauer - Oracle America - San Diego United States 	if ((cpc_has_overflow_intr) && (cpc_level15_inum == 0)) {
637c478bd9Sstevel@tonic-gate 		cpc_level15_inum = add_softintr(PIL_15,
64b0fc0e77Sgovinda 		    kcpc_hw_overflow_intr, NULL, SOFTINT_MT);
657c478bd9Sstevel@tonic-gate 	}
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/*
687c478bd9Sstevel@tonic-gate 	 * Make sure the boot CPU gets set up.
697c478bd9Sstevel@tonic-gate 	 */
707c478bd9Sstevel@tonic-gate 	kcpc_hw_startup_cpu(CPU->cpu_flags);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Prepare for CPC interrupts and install an idle thread CPC context.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate void
kcpc_hw_startup_cpu(ushort_t cpflags)777c478bd9Sstevel@tonic-gate kcpc_hw_startup_cpu(ushort_t cpflags)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate 	cpu_t		*cp = CPU;
807c478bd9Sstevel@tonic-gate 	kthread_t	*t = cp->cpu_idle_thread;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	ASSERT(t->t_bound_cpu == cp);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
857c478bd9Sstevel@tonic-gate 		int pstate_save = disable_vec_intr();
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 		ASSERT(cpc_level15_inum != 0);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 		intr_enqueue_req(PIL_15, cpc_level15_inum);
907c478bd9Sstevel@tonic-gate 		enable_vec_intr(pstate_save);
917c478bd9Sstevel@tonic-gate 	}
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	if (kcpc_counts_include_idle)
967c478bd9Sstevel@tonic-gate 		return;
977c478bd9Sstevel@tonic-gate 
98*5a469116SPatrick Mooney 	kcpc_idle_ctxop_install(t, cp);
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
kcpc_hw_load_pcbe(void)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
kcpc_hw_cpu_hook(processorid_t cpuid,ulong_t * kcpc_cpumap)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
kcpc_hw_lwp_hook(void)1217c478bd9Sstevel@tonic-gate kcpc_hw_lwp_hook(void)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	return (0);
1247c478bd9Sstevel@tonic-gate }
125