xref: /illumos-gate/usr/src/uts/sun4v/os/cpc_subr.c (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
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 	char		modname[MODMAXNAMELEN+1];
111 	char		*p, *q;
112 	int		len, stat;
113 	extern char	*boot_cpu_compatible_list;
114 
115 	for (stat = -1, p = boot_cpu_compatible_list; p != NULL; p = q) {
116 		/*
117 		 * Get next CPU module name from boot_cpu_compatible_list
118 		 */
119 		q = strchr(p, ':');
120 		len = (q) ? (q - p) : strlen(p);
121 		if (len < sizeof (modname)) {
122 			(void) strncpy(modname, p, len);
123 			modname[len] = '\0';
124 			stat = kcpc_pcbe_tryload(modname, 0, 0, 0);
125 			if (stat == 0)
126 				break;
127 		}
128 		if (q)
129 			q++;			/* skip over ':' */
130 	}
131 	return (stat);
132 
133 }
134 
135 /*ARGSUSED*/
136 static void
137 kcpc_remotestop_func(uint64_t arg1, uint64_t arg2)
138 {
139 	ASSERT(CPU->cpu_cpc_ctx != NULL);
140 	pcbe_ops->pcbe_allstop();
141 	atomic_or_uint(&CPU->cpu_cpc_ctx->kc_flags, KCPC_CTX_INVALID_STOPPED);
142 }
143 
144 /*
145  * Ensure the counters are stopped on the given processor.
146  *
147  * Callers must ensure kernel preemption is disabled.
148  */
149 void
150 kcpc_remote_stop(cpu_t *cp)
151 {
152 	xc_one(cp->cpu_id, kcpc_remotestop_func, 0, 0);
153 }
154 
155 /*ARGSUSED*/
156 int
157 kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
158 {
159 	return (0);
160 }
161 
162 int
163 kcpc_hw_lwp_hook(void)
164 {
165 	return (0);
166 }
167