xref: /titanic_44/usr/src/uts/sun4v/os/cpc_subr.c (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * sun4u common CPC subroutines.
30  */
31 
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <sys/atomic.h>
35 #include <sys/thread.h>
36 #include <sys/regset.h>
37 #include <sys/archsystm.h>
38 #include <sys/machsystm.h>
39 #include <sys/cpc_impl.h>
40 #include <sys/cpc_ultra.h>
41 #include <sys/sunddi.h>
42 #include <sys/intr.h>
43 #include <sys/ivintr.h>
44 #include <sys/x_call.h>
45 #include <sys/cpuvar.h>
46 #include <sys/machcpuvar.h>
47 #include <sys/cpc_pcbe.h>
48 #include <sys/modctl.h>
49 #include <sys/sdt.h>
50 
51 uint64_t		cpc_level15_inum;	/* used in interrupt.s */
52 int			cpc_has_overflow_intr;	/* set in cheetah.c */
53 
54 extern kcpc_ctx_t *kcpc_overflow_intr(caddr_t arg, uint64_t bitmap);
55 extern int kcpc_counts_include_idle;
56 
57 /*
58  * Called on the boot CPU during startup.
59  */
60 void
61 kcpc_hw_init(void)
62 {
63 	if (cpc_has_overflow_intr) {
64 		cpc_level15_inum = add_softintr(PIL_15,
65 		    kcpc_hw_overflow_intr, NULL, SOFTINT_MT);
66 	}
67 
68 	/*
69 	 * Make sure the boot CPU gets set up.
70 	 */
71 	kcpc_hw_startup_cpu(CPU->cpu_flags);
72 }
73 
74 /*
75  * Prepare for CPC interrupts and install an idle thread CPC context.
76  */
77 void
78 kcpc_hw_startup_cpu(ushort_t cpflags)
79 {
80 	cpu_t		*cp = CPU;
81 	kthread_t	*t = cp->cpu_idle_thread;
82 
83 	ASSERT(t->t_bound_cpu == cp);
84 
85 	if (cpc_has_overflow_intr && (cpflags & CPU_FROZEN) == 0) {
86 		int pstate_save = disable_vec_intr();
87 
88 		ASSERT(cpc_level15_inum != 0);
89 
90 		intr_enqueue_req(PIL_15, cpc_level15_inum);
91 		enable_vec_intr(pstate_save);
92 	}
93 
94 	mutex_init(&cp->cpu_cpc_ctxlock, "cpu_cpc_ctxlock", MUTEX_DEFAULT, 0);
95 
96 	if (kcpc_counts_include_idle)
97 		return;
98 
99 	installctx(t, cp, kcpc_idle_save, kcpc_idle_restore, NULL, NULL,
100 	    NULL, NULL);
101 }
102 
103 /*
104  * Examine the processor and load an appropriate PCBE.
105  */
106 int
107 kcpc_hw_load_pcbe(void)
108 {
109 	char		modname[MODMAXNAMELEN+1];
110 	char		*p, *q;
111 	int		len, stat;
112 	extern char	*boot_cpu_compatible_list;
113 
114 	for (stat = -1, p = boot_cpu_compatible_list; p != NULL; p = q) {
115 		/*
116 		 * Get next CPU module name from boot_cpu_compatible_list
117 		 */
118 		q = strchr(p, ':');
119 		len = (q) ? (q - p) : strlen(p);
120 		if (len < sizeof (modname)) {
121 			(void) strncpy(modname, p, len);
122 			modname[len] = '\0';
123 			stat = kcpc_pcbe_tryload(modname, 0, 0, 0);
124 			if (stat == 0)
125 				break;
126 		}
127 		if (q)
128 			q++;			/* skip over ':' */
129 	}
130 	return (stat);
131 
132 }
133 
134 /*ARGSUSED*/
135 static void
136 kcpc_remotestop_func(uint64_t arg1, uint64_t arg2)
137 {
138 	ASSERT(CPU->cpu_cpc_ctx != NULL);
139 	pcbe_ops->pcbe_allstop();
140 	atomic_or_uint(&CPU->cpu_cpc_ctx->kc_flags, KCPC_CTX_INVALID_STOPPED);
141 }
142 
143 /*
144  * Ensure the counters are stopped on the given processor.
145  *
146  * Callers must ensure kernel preemption is disabled.
147  */
148 void
149 kcpc_remote_stop(cpu_t *cp)
150 {
151 	xc_one(cp->cpu_id, kcpc_remotestop_func, 0, 0);
152 }
153 
154 /*ARGSUSED*/
155 int
156 kcpc_hw_cpu_hook(processorid_t cpuid, ulong_t *kcpc_cpumap)
157 {
158 	return (0);
159 }
160 
161 int
162 kcpc_hw_lwp_hook(void)
163 {
164 	return (0);
165 }
166