xref: /illumos-gate/usr/src/uts/sun4u/os/cpc_subr.c (revision 7c478bd9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * sun4u common CPC subroutines.
31  */
32 
33 #include <sys/types.h>
34 #include <sys/time.h>
35 #include <sys/atomic.h>
36 #include <sys/thread.h>
37 #include <sys/regset.h>
38 #include <sys/archsystm.h>
39 #include <sys/machsystm.h>
40 #include <sys/cpc_impl.h>
41 #include <sys/cpc_ultra.h>
42 #include <sys/sunddi.h>
43 #include <sys/intr.h>
44 #include <sys/ivintr.h>
45 #include <sys/x_call.h>
46 #include <sys/cpuvar.h>
47 #include <sys/machcpuvar.h>
48 #include <sys/cpc_pcbe.h>
49 #include <sys/modctl.h>
50 #include <sys/sdt.h>
51 
52 uint32_t		cpc_level15_inum;	/* used in interrupt.s */
53 int			cpc_has_overflow_intr;	/* set in cheetah.c */
54 
55 extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
56 extern int kcpc_counts_include_idle;
57 
58 /*
59  * Called on the boot CPU during startup.
60  */
61 void
62 kcpc_hw_init(void)
63 {
64 	if (cpc_has_overflow_intr) {
65 		cpc_level15_inum = add_softintr(PIL_15,
66 		    kcpc_hw_overflow_intr, NULL);
67 	}
68 
69 	/*
70 	 * Make sure the boot CPU gets set up.
71 	 */
72 	kcpc_hw_startup_cpu(CPU->cpu_flags);
73 }
74 
75 /*
76  * Prepare for CPC interrupts and install an idle thread CPC context.
77  */
78 void
79 kcpc_hw_startup_cpu(ushort_t cpflags)
80 {
81 	cpu_t		*cp = CPU;
82 	kthread_t	*t = cp->cpu_idle_thread;
83 
84 	ASSERT(t->t_bound_cpu == cp);
85 
86 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
87 		int pstate_save = disable_vec_intr();
88 
89 		ASSERT(cpc_level15_inum != 0);
90 
91 		intr_enqueue_req(PIL_15, cpc_level15_inum);
92 		enable_vec_intr(pstate_save);
93 	}
94 
95 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
96 
97 	if (kcpc_counts_include_idle)
98 		return;
99 
100 	installctx(t, cp, kcpc_idle_save, kcpc_idle_restore, NULL, NULL,
101 	    NULL, NULL);
102 }
103 
104 /*
105  * Examine the processor and load an appropriate PCBE.
106  */
107 int
108 kcpc_hw_load_pcbe(void)
109 {
110 	uint64_t	ver = ultra_getver();
111 
112 	return (kcpc_pcbe_tryload(NULL, ULTRA_VER_MANUF(ver),
113 	    ULTRA_VER_IMPL(ver), ULTRA_VER_MASK(ver)));
114 }
115 
116 /*ARGSUSED*/
117 static void
118 kcpc_remotestop_func(uint64_t arg1, uint64_t arg2)
119 {
120 	ASSERT(CPU->cpu_cpc_ctx != NULL);
121 	pcbe_ops->pcbe_allstop();
122 	atomic_or_uint(&CPU->cpu_cpc_ctx->kc_flags, KCPC_CTX_INVALID_STOPPED);
123 }
124 
125 /*
126  * Ensure the counters are stopped on the given processor.
127  *
128  * Callers must ensure kernel preemption is disabled.
129  */
130 void
131 kcpc_remote_stop(cpu_t *cp)
132 {
133 	xc_one(cp->cpu_id, kcpc_remotestop_func, 0, 0);
134 }
135 
136 /*ARGSUSED*/
137 int
138 kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
139 {
140 	return (0);
141 }
142 
143 int
144 kcpc_hw_lwp_hook(void)
145 {
146 	return (0);
147 }
148