xref: /titanic_50/usr/src/uts/sun4v/os/cpc_subr.c (revision a24e89c4a1eec8361718d94a6275e6720643284e)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * sun4u common CPC subroutines.
28  */
29 
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/atomic.h>
33 #include <sys/thread.h>
34 #include <sys/regset.h>
35 #include <sys/archsystm.h>
36 #include <sys/machsystm.h>
37 #include <sys/cpc_impl.h>
38 #include <sys/cpc_ultra.h>
39 #include <sys/sunddi.h>
40 #include <sys/intr.h>
41 #include <sys/ivintr.h>
42 #include <sys/x_call.h>
43 #include <sys/cpuvar.h>
44 #include <sys/machcpuvar.h>
45 #include <sys/cpc_pcbe.h>
46 #include <sys/modctl.h>
47 #include <sys/sdt.h>
48 
49 uint64_t	cpc_level15_inum;	/* used in interrupt.s */
50 int		cpc_has_overflow_intr;	/* set in cheetah.c */
51 
52 extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
53 extern int kcpc_counts_include_idle;
54 
55 /*
56  * Called on the boot CPU during startup.
57  */
58 void
59 kcpc_hw_init(void)
60 {
61 	if (cpc_has_overflow_intr) {
62 		cpc_level15_inum = add_softintr(PIL_15,
63 		    kcpc_hw_overflow_intr, NULL, SOFTINT_MT);
64 	}
65 
66 	/*
67 	 * Make sure the boot CPU gets set up.
68 	 */
69 	kcpc_hw_startup_cpu(CPU->cpu_flags);
70 }
71 
72 /*
73  * Prepare for CPC interrupts and install an idle thread CPC context.
74  */
75 void
76 kcpc_hw_startup_cpu(ushort_t cpflags)
77 {
78 	cpu_t		*cp = CPU;
79 	kthread_t	*t = cp->cpu_idle_thread;
80 
81 	ASSERT(t->t_bound_cpu == cp);
82 
83 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
84 		int pstate_save = disable_vec_intr();
85 
86 		ASSERT(cpc_level15_inum != 0);
87 
88 		intr_enqueue_req(PIL_15, cpc_level15_inum);
89 		enable_vec_intr(pstate_save);
90 	}
91 
92 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
93 
94 	if (kcpc_counts_include_idle)
95 		return;
96 
97 	installctx(t, cp, kcpc_idle_save, kcpc_idle_restore, NULL, NULL,
98 	    NULL, NULL);
99 }
100 
101 /*
102  * Examine the processor and load an appropriate PCBE.
103  */
104 int
105 kcpc_hw_load_pcbe(void)
106 {
107 	char		modname[MODMAXNAMELEN+1];
108 	char		*p, *q;
109 	int		len, stat;
110 	extern char	*boot_cpu_compatible_list;
111 
112 	for (stat = -1, p = boot_cpu_compatible_list; p != NULL; p = q) {
113 		/*
114 		 * Get next CPU module name from boot_cpu_compatible_list
115 		 */
116 		q = strchr(p, ':');
117 		len = (q) ? (q - p) : strlen(p);
118 		if (len < sizeof (modname)) {
119 			(void) strncpy(modname, p, len);
120 			modname[len] = '\0';
121 			stat = kcpc_pcbe_tryload(modname, 0, 0, 0);
122 			if (stat == 0)
123 				break;
124 		}
125 		if (q)
126 			q++;			/* skip over ':' */
127 	}
128 	return (stat);
129 
130 }
131 
132 /*ARGSUSED*/
133 static void
134 kcpc_remotestop_func(uint64_t arg1, uint64_t arg2)
135 {
136 	ASSERT(CPU->cpu_cpc_ctx != NULL);
137 	pcbe_ops->pcbe_allstop();
138 	atomic_or_uint(&CPU->cpu_cpc_ctx->kc_flags, KCPC_CTX_INVALID_STOPPED);
139 }
140 
141 /*
142  * Ensure the counters are stopped on the given processor.
143  *
144  * Callers must ensure kernel preemption is disabled.
145  */
146 void
147 kcpc_remote_stop(cpu_t *cp)
148 {
149 	xc_one(cp->cpu_id, kcpc_remotestop_func, 0, 0);
150 }
151 
152 /*ARGSUSED*/
153 int
154 kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
155 {
156 	return (0);
157 }
158 
159 int
160 kcpc_hw_lwp_hook(void)
161 {
162 	return (0);
163 }
164 
165 /*ARGSUSED*/
166 static void
167 kcpc_remoteprogram_func(uint64_t arg1, uint64_t arg2)
168 {
169 	ASSERT(CPU->cpu_cpc_ctx != NULL);
170 
171 	pcbe_ops->pcbe_program(CPU->cpu_cpc_ctx);
172 }
173 
174 /*
175  * Ensure counters are enabled on the given processor.
176  */
177 void
178 kcpc_remote_program(cpu_t *cp)
179 {
180 	xc_one(cp->cpu_id, kcpc_remoteprogram_func, 0, 0);
181 }
182