xref: /onnv-gate/usr/src/uts/intel/dtrace/sdt.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/modctl.h>
30*0Sstevel@tonic-gate #include <sys/sunddi.h>
31*0Sstevel@tonic-gate #include <sys/dtrace.h>
32*0Sstevel@tonic-gate #include <sys/kobj.h>
33*0Sstevel@tonic-gate #include <sys/stat.h>
34*0Sstevel@tonic-gate #include <sys/conf.h>
35*0Sstevel@tonic-gate #include <vm/seg_kmem.h>
36*0Sstevel@tonic-gate #include <sys/stack.h>
37*0Sstevel@tonic-gate #include <sys/sdt_impl.h>
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #define	SDT_PATCHVAL	0xf0
40*0Sstevel@tonic-gate #define	SDT_ADDR2NDX(addr)	((((uintptr_t)(addr)) >> 4) & sdt_probetab_mask)
41*0Sstevel@tonic-gate #define	SDT_PROBETAB_SIZE	0x1000		/* 4k entries -- 16K total */
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate static dev_info_t		*sdt_devi;
44*0Sstevel@tonic-gate static int			sdt_verbose = 0;
45*0Sstevel@tonic-gate static sdt_probe_t		**sdt_probetab;
46*0Sstevel@tonic-gate static int			sdt_probetab_size;
47*0Sstevel@tonic-gate static int			sdt_probetab_mask;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*ARGSUSED*/
50*0Sstevel@tonic-gate static int
51*0Sstevel@tonic-gate sdt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t eax)
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate 	uintptr_t stack0, stack1, stack2, stack3, stack4;
54*0Sstevel@tonic-gate 	int i = 0;
55*0Sstevel@tonic-gate 	sdt_probe_t *sdt = sdt_probetab[SDT_ADDR2NDX(addr)];
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #ifdef __amd64
58*0Sstevel@tonic-gate 	/*
59*0Sstevel@tonic-gate 	 * On amd64, stack[0] contains the dereferenced stack pointer,
60*0Sstevel@tonic-gate 	 * stack[1] contains savfp, stack[2] contains savpc.  We want
61*0Sstevel@tonic-gate 	 * to step over these entries.
62*0Sstevel@tonic-gate 	 */
63*0Sstevel@tonic-gate 	i += 3;
64*0Sstevel@tonic-gate #endif
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate 	for (; sdt != NULL; sdt = sdt->sdp_hashnext) {
67*0Sstevel@tonic-gate 		if ((uintptr_t)sdt->sdp_patchpoint == addr) {
68*0Sstevel@tonic-gate 			/*
69*0Sstevel@tonic-gate 			 * When accessing the arguments on the stack, we must
70*0Sstevel@tonic-gate 			 * protect against accessing beyond the stack.  We can
71*0Sstevel@tonic-gate 			 * safely set NOFAULT here -- we know that interrupts
72*0Sstevel@tonic-gate 			 * are already disabled.
73*0Sstevel@tonic-gate 			 */
74*0Sstevel@tonic-gate 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
75*0Sstevel@tonic-gate 			stack0 = stack[i++];
76*0Sstevel@tonic-gate 			stack1 = stack[i++];
77*0Sstevel@tonic-gate 			stack2 = stack[i++];
78*0Sstevel@tonic-gate 			stack3 = stack[i++];
79*0Sstevel@tonic-gate 			stack4 = stack[i++];
80*0Sstevel@tonic-gate 			DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
81*0Sstevel@tonic-gate 			    CPU_DTRACE_BADADDR);
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 			dtrace_probe(sdt->sdp_id, stack0, stack1,
84*0Sstevel@tonic-gate 			    stack2, stack3, stack4);
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 			return (DTRACE_INVOP_NOP);
87*0Sstevel@tonic-gate 		}
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	return (0);
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /*ARGSUSED*/
94*0Sstevel@tonic-gate static void
95*0Sstevel@tonic-gate sdt_provide_module(void *arg, struct modctl *ctl)
96*0Sstevel@tonic-gate {
97*0Sstevel@tonic-gate 	struct module *mp = ctl->mod_mp;
98*0Sstevel@tonic-gate 	char *modname = ctl->mod_modname;
99*0Sstevel@tonic-gate 	sdt_probedesc_t *sdpd;
100*0Sstevel@tonic-gate 	sdt_probe_t *sdp, *old;
101*0Sstevel@tonic-gate 	sdt_provider_t *prov;
102*0Sstevel@tonic-gate 	int len;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	/*
105*0Sstevel@tonic-gate 	 * One for all, and all for one:  if we haven't yet registered all of
106*0Sstevel@tonic-gate 	 * our providers, we'll refuse to provide anything.
107*0Sstevel@tonic-gate 	 */
108*0Sstevel@tonic-gate 	for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
109*0Sstevel@tonic-gate 		if (prov->sdtp_id == DTRACE_PROVNONE)
110*0Sstevel@tonic-gate 			return;
111*0Sstevel@tonic-gate 	}
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	if (mp->sdt_nprobes != 0 || (sdpd = mp->sdt_probes) == NULL)
114*0Sstevel@tonic-gate 		return;
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate 	for (sdpd = mp->sdt_probes; sdpd != NULL; sdpd = sdpd->sdpd_next) {
117*0Sstevel@tonic-gate 		char *name = sdpd->sdpd_name, *func, *nname;
118*0Sstevel@tonic-gate 		int i, j;
119*0Sstevel@tonic-gate 		sdt_provider_t *prov;
120*0Sstevel@tonic-gate 		ulong_t offs;
121*0Sstevel@tonic-gate 		dtrace_id_t id;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 		for (prov = sdt_providers; prov->sdtp_prefix != NULL; prov++) {
124*0Sstevel@tonic-gate 			char *prefix = prov->sdtp_prefix;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 			if (strncmp(name, prefix, strlen(prefix)) == 0) {
127*0Sstevel@tonic-gate 				name += strlen(prefix);
128*0Sstevel@tonic-gate 				break;
129*0Sstevel@tonic-gate 			}
130*0Sstevel@tonic-gate 		}
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 		nname = kmem_alloc(len = strlen(name) + 1, KM_SLEEP);
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 		for (i = 0, j = 0; name[j] != '\0'; i++) {
135*0Sstevel@tonic-gate 			if (name[j] == '_' && name[j + 1] == '_') {
136*0Sstevel@tonic-gate 				nname[i] = '-';
137*0Sstevel@tonic-gate 				j += 2;
138*0Sstevel@tonic-gate 			} else {
139*0Sstevel@tonic-gate 				nname[i] = name[j++];
140*0Sstevel@tonic-gate 			}
141*0Sstevel@tonic-gate 		}
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 		nname[i] = '\0';
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 		sdp = kmem_zalloc(sizeof (sdt_probe_t), KM_SLEEP);
146*0Sstevel@tonic-gate 		sdp->sdp_loadcnt = ctl->mod_loadcnt;
147*0Sstevel@tonic-gate 		sdp->sdp_ctl = ctl;
148*0Sstevel@tonic-gate 		sdp->sdp_name = nname;
149*0Sstevel@tonic-gate 		sdp->sdp_namelen = len;
150*0Sstevel@tonic-gate 		sdp->sdp_provider = prov;
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 		func = kobj_searchsym(mp, sdpd->sdpd_offset, &offs);
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 		if (func == NULL)
155*0Sstevel@tonic-gate 			func = "<unknown>";
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 		/*
158*0Sstevel@tonic-gate 		 * We have our provider.  Now create the probe.
159*0Sstevel@tonic-gate 		 */
160*0Sstevel@tonic-gate 		if ((id = dtrace_probe_lookup(prov->sdtp_id, modname,
161*0Sstevel@tonic-gate 		    func, nname)) != DTRACE_IDNONE) {
162*0Sstevel@tonic-gate 			old = dtrace_probe_arg(prov->sdtp_id, id);
163*0Sstevel@tonic-gate 			ASSERT(old != NULL);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate 			sdp->sdp_next = old->sdp_next;
166*0Sstevel@tonic-gate 			sdp->sdp_id = id;
167*0Sstevel@tonic-gate 			old->sdp_next = sdp;
168*0Sstevel@tonic-gate 		} else {
169*0Sstevel@tonic-gate 			sdp->sdp_id = dtrace_probe_create(prov->sdtp_id,
170*0Sstevel@tonic-gate 			    modname, func, nname, 3, sdp);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 			mp->sdt_nprobes++;
173*0Sstevel@tonic-gate 		}
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 		sdp->sdp_hashnext =
176*0Sstevel@tonic-gate 		    sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)];
177*0Sstevel@tonic-gate 		sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)] = sdp;
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 		sdp->sdp_patchval = SDT_PATCHVAL;
180*0Sstevel@tonic-gate 		sdp->sdp_patchpoint = (uint8_t *)sdpd->sdpd_offset;
181*0Sstevel@tonic-gate 		sdp->sdp_savedval = *sdp->sdp_patchpoint;
182*0Sstevel@tonic-gate 	}
183*0Sstevel@tonic-gate }
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate /*ARGSUSED*/
186*0Sstevel@tonic-gate static void
187*0Sstevel@tonic-gate sdt_destroy(void *arg, dtrace_id_t id, void *parg)
188*0Sstevel@tonic-gate {
189*0Sstevel@tonic-gate 	sdt_probe_t *sdp = parg, *old, *last, *hash;
190*0Sstevel@tonic-gate 	struct modctl *ctl = sdp->sdp_ctl;
191*0Sstevel@tonic-gate 	int ndx;
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate 	if (ctl != NULL && ctl->mod_loadcnt == sdp->sdp_loadcnt) {
194*0Sstevel@tonic-gate 		if ((ctl->mod_loadcnt == sdp->sdp_loadcnt &&
195*0Sstevel@tonic-gate 		    ctl->mod_loaded)) {
196*0Sstevel@tonic-gate 			((struct module *)(ctl->mod_mp))->sdt_nprobes--;
197*0Sstevel@tonic-gate 		}
198*0Sstevel@tonic-gate 	}
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate 	while (sdp != NULL) {
201*0Sstevel@tonic-gate 		old = sdp;
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 		/*
204*0Sstevel@tonic-gate 		 * Now we need to remove this probe from the sdt_probetab.
205*0Sstevel@tonic-gate 		 */
206*0Sstevel@tonic-gate 		ndx = SDT_ADDR2NDX(sdp->sdp_patchpoint);
207*0Sstevel@tonic-gate 		last = NULL;
208*0Sstevel@tonic-gate 		hash = sdt_probetab[ndx];
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 		while (hash != sdp) {
211*0Sstevel@tonic-gate 			ASSERT(hash != NULL);
212*0Sstevel@tonic-gate 			last = hash;
213*0Sstevel@tonic-gate 			hash = hash->sdp_hashnext;
214*0Sstevel@tonic-gate 		}
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate 		if (last != NULL) {
217*0Sstevel@tonic-gate 			last->sdp_hashnext = sdp->sdp_hashnext;
218*0Sstevel@tonic-gate 		} else {
219*0Sstevel@tonic-gate 			sdt_probetab[ndx] = sdp->sdp_hashnext;
220*0Sstevel@tonic-gate 		}
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 		kmem_free(sdp->sdp_name, sdp->sdp_namelen);
223*0Sstevel@tonic-gate 		sdp = sdp->sdp_next;
224*0Sstevel@tonic-gate 		kmem_free(old, sizeof (sdt_probe_t));
225*0Sstevel@tonic-gate 	}
226*0Sstevel@tonic-gate }
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate /*ARGSUSED*/
229*0Sstevel@tonic-gate static void
230*0Sstevel@tonic-gate sdt_enable(void *arg, dtrace_id_t id, void *parg)
231*0Sstevel@tonic-gate {
232*0Sstevel@tonic-gate 	sdt_probe_t *sdp = parg;
233*0Sstevel@tonic-gate 	struct modctl *ctl = sdp->sdp_ctl;
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate 	ctl->mod_nenabled++;
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 	/*
238*0Sstevel@tonic-gate 	 * If this module has disappeared since we discovered its probes,
239*0Sstevel@tonic-gate 	 * refuse to enable it.
240*0Sstevel@tonic-gate 	 */
241*0Sstevel@tonic-gate 	if (!ctl->mod_loaded) {
242*0Sstevel@tonic-gate 		if (sdt_verbose) {
243*0Sstevel@tonic-gate 			cmn_err(CE_NOTE, "sdt is failing for probe %s "
244*0Sstevel@tonic-gate 			    "(module %s unloaded)",
245*0Sstevel@tonic-gate 			    sdp->sdp_name, ctl->mod_modname);
246*0Sstevel@tonic-gate 		}
247*0Sstevel@tonic-gate 		goto err;
248*0Sstevel@tonic-gate 	}
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate 	/*
251*0Sstevel@tonic-gate 	 * Now check that our modctl has the expected load count.  If it
252*0Sstevel@tonic-gate 	 * doesn't, this module must have been unloaded and reloaded -- and
253*0Sstevel@tonic-gate 	 * we're not going to touch it.
254*0Sstevel@tonic-gate 	 */
255*0Sstevel@tonic-gate 	if (ctl->mod_loadcnt != sdp->sdp_loadcnt) {
256*0Sstevel@tonic-gate 		if (sdt_verbose) {
257*0Sstevel@tonic-gate 			cmn_err(CE_NOTE, "sdt is failing for probe %s "
258*0Sstevel@tonic-gate 			    "(module %s reloaded)",
259*0Sstevel@tonic-gate 			    sdp->sdp_name, ctl->mod_modname);
260*0Sstevel@tonic-gate 		}
261*0Sstevel@tonic-gate 		goto err;
262*0Sstevel@tonic-gate 	}
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	while (sdp != NULL) {
265*0Sstevel@tonic-gate 		*sdp->sdp_patchpoint = sdp->sdp_patchval;
266*0Sstevel@tonic-gate 		sdp = sdp->sdp_next;
267*0Sstevel@tonic-gate 	}
268*0Sstevel@tonic-gate err:
269*0Sstevel@tonic-gate 	;
270*0Sstevel@tonic-gate }
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate /*ARGSUSED*/
273*0Sstevel@tonic-gate static void
274*0Sstevel@tonic-gate sdt_disable(void *arg, dtrace_id_t id, void *parg)
275*0Sstevel@tonic-gate {
276*0Sstevel@tonic-gate 	sdt_probe_t *sdp = parg;
277*0Sstevel@tonic-gate 	struct modctl *ctl = sdp->sdp_ctl;
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 	ctl->mod_nenabled--;
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 	if (!ctl->mod_loaded || ctl->mod_loadcnt != sdp->sdp_loadcnt)
282*0Sstevel@tonic-gate 		goto err;
283*0Sstevel@tonic-gate 
284*0Sstevel@tonic-gate 	while (sdp != NULL) {
285*0Sstevel@tonic-gate 		*sdp->sdp_patchpoint = sdp->sdp_savedval;
286*0Sstevel@tonic-gate 		sdp = sdp->sdp_next;
287*0Sstevel@tonic-gate 	}
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate err:
290*0Sstevel@tonic-gate 	;
291*0Sstevel@tonic-gate }
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate static dtrace_pops_t sdt_pops = {
294*0Sstevel@tonic-gate 	NULL,
295*0Sstevel@tonic-gate 	sdt_provide_module,
296*0Sstevel@tonic-gate 	sdt_enable,
297*0Sstevel@tonic-gate 	sdt_disable,
298*0Sstevel@tonic-gate 	NULL,
299*0Sstevel@tonic-gate 	NULL,
300*0Sstevel@tonic-gate 	sdt_getargdesc,
301*0Sstevel@tonic-gate 	NULL,
302*0Sstevel@tonic-gate 	NULL,
303*0Sstevel@tonic-gate 	sdt_destroy
304*0Sstevel@tonic-gate };
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate /*ARGSUSED*/
307*0Sstevel@tonic-gate static int
308*0Sstevel@tonic-gate sdt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
309*0Sstevel@tonic-gate {
310*0Sstevel@tonic-gate 	sdt_provider_t *prov;
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 	if (ddi_create_minor_node(devi, "sdt", S_IFCHR,
313*0Sstevel@tonic-gate 	    0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
314*0Sstevel@tonic-gate 		cmn_err(CE_NOTE, "/dev/sdt couldn't create minor node");
315*0Sstevel@tonic-gate 		ddi_remove_minor_node(devi, NULL);
316*0Sstevel@tonic-gate 		return (DDI_FAILURE);
317*0Sstevel@tonic-gate 	}
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate 	ddi_report_dev(devi);
320*0Sstevel@tonic-gate 	sdt_devi = devi;
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 	if (sdt_probetab_size == 0)
323*0Sstevel@tonic-gate 		sdt_probetab_size = SDT_PROBETAB_SIZE;
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate 	sdt_probetab_mask = sdt_probetab_size - 1;
326*0Sstevel@tonic-gate 	sdt_probetab =
327*0Sstevel@tonic-gate 	    kmem_zalloc(sdt_probetab_size * sizeof (sdt_probe_t *), KM_SLEEP);
328*0Sstevel@tonic-gate 	dtrace_invop_add(sdt_invop);
329*0Sstevel@tonic-gate 
330*0Sstevel@tonic-gate 	for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
331*0Sstevel@tonic-gate 		if (dtrace_register(prov->sdtp_name, prov->sdtp_attr,
332*0Sstevel@tonic-gate 		    DTRACE_PRIV_KERNEL, 0,
333*0Sstevel@tonic-gate 		    &sdt_pops, prov, &prov->sdtp_id) != 0) {
334*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "failed to register sdt provider %s",
335*0Sstevel@tonic-gate 			    prov->sdtp_name);
336*0Sstevel@tonic-gate 		}
337*0Sstevel@tonic-gate 	}
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
340*0Sstevel@tonic-gate }
341*0Sstevel@tonic-gate 
342*0Sstevel@tonic-gate /*ARGSUSED*/
343*0Sstevel@tonic-gate static int
344*0Sstevel@tonic-gate sdt_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
345*0Sstevel@tonic-gate {
346*0Sstevel@tonic-gate 	sdt_provider_t *prov;
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 	switch (cmd) {
349*0Sstevel@tonic-gate 	case DDI_DETACH:
350*0Sstevel@tonic-gate 		break;
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	case DDI_SUSPEND:
353*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 	default:
356*0Sstevel@tonic-gate 		return (DDI_FAILURE);
357*0Sstevel@tonic-gate 	}
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate 	for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
360*0Sstevel@tonic-gate 		if (prov->sdtp_id != DTRACE_PROVNONE) {
361*0Sstevel@tonic-gate 			if (dtrace_unregister(prov->sdtp_id) != 0)
362*0Sstevel@tonic-gate 				return (DDI_FAILURE);
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 			prov->sdtp_id = DTRACE_PROVNONE;
365*0Sstevel@tonic-gate 		}
366*0Sstevel@tonic-gate 	}
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate 	dtrace_invop_remove(sdt_invop);
369*0Sstevel@tonic-gate 	kmem_free(sdt_probetab, sdt_probetab_size * sizeof (sdt_probe_t *));
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
372*0Sstevel@tonic-gate }
373*0Sstevel@tonic-gate 
374*0Sstevel@tonic-gate /*ARGSUSED*/
375*0Sstevel@tonic-gate static int
376*0Sstevel@tonic-gate sdt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
377*0Sstevel@tonic-gate {
378*0Sstevel@tonic-gate 	int error;
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate 	switch (infocmd) {
381*0Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
382*0Sstevel@tonic-gate 		*result = (void *)sdt_devi;
383*0Sstevel@tonic-gate 		error = DDI_SUCCESS;
384*0Sstevel@tonic-gate 		break;
385*0Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
386*0Sstevel@tonic-gate 		*result = (void *)0;
387*0Sstevel@tonic-gate 		error = DDI_SUCCESS;
388*0Sstevel@tonic-gate 		break;
389*0Sstevel@tonic-gate 	default:
390*0Sstevel@tonic-gate 		error = DDI_FAILURE;
391*0Sstevel@tonic-gate 	}
392*0Sstevel@tonic-gate 	return (error);
393*0Sstevel@tonic-gate }
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate /*ARGSUSED*/
396*0Sstevel@tonic-gate static int
397*0Sstevel@tonic-gate sdt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
398*0Sstevel@tonic-gate {
399*0Sstevel@tonic-gate 	return (0);
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate 
402*0Sstevel@tonic-gate static struct cb_ops sdt_cb_ops = {
403*0Sstevel@tonic-gate 	sdt_open,		/* open */
404*0Sstevel@tonic-gate 	nodev,			/* close */
405*0Sstevel@tonic-gate 	nulldev,		/* strategy */
406*0Sstevel@tonic-gate 	nulldev,		/* print */
407*0Sstevel@tonic-gate 	nodev,			/* dump */
408*0Sstevel@tonic-gate 	nodev,			/* read */
409*0Sstevel@tonic-gate 	nodev,			/* write */
410*0Sstevel@tonic-gate 	nodev,			/* ioctl */
411*0Sstevel@tonic-gate 	nodev,			/* devmap */
412*0Sstevel@tonic-gate 	nodev,			/* mmap */
413*0Sstevel@tonic-gate 	nodev,			/* segmap */
414*0Sstevel@tonic-gate 	nochpoll,		/* poll */
415*0Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */
416*0Sstevel@tonic-gate 	0,			/* streamtab  */
417*0Sstevel@tonic-gate 	D_NEW | D_MP		/* Driver compatibility flag */
418*0Sstevel@tonic-gate };
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate static struct dev_ops sdt_ops = {
421*0Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
422*0Sstevel@tonic-gate 	0,			/* refcnt  */
423*0Sstevel@tonic-gate 	sdt_info,		/* get_dev_info */
424*0Sstevel@tonic-gate 	nulldev,		/* identify */
425*0Sstevel@tonic-gate 	nulldev,		/* probe */
426*0Sstevel@tonic-gate 	sdt_attach,		/* attach */
427*0Sstevel@tonic-gate 	sdt_detach,		/* detach */
428*0Sstevel@tonic-gate 	nodev,			/* reset */
429*0Sstevel@tonic-gate 	&sdt_cb_ops,		/* driver operations */
430*0Sstevel@tonic-gate 	NULL,			/* bus operations */
431*0Sstevel@tonic-gate 	nodev			/* dev power */
432*0Sstevel@tonic-gate };
433*0Sstevel@tonic-gate 
434*0Sstevel@tonic-gate /*
435*0Sstevel@tonic-gate  * Module linkage information for the kernel.
436*0Sstevel@tonic-gate  */
437*0Sstevel@tonic-gate static struct modldrv modldrv = {
438*0Sstevel@tonic-gate 	&mod_driverops,		/* module type (this is a pseudo driver) */
439*0Sstevel@tonic-gate 	"Statically Defined Tracing",	/* name of module */
440*0Sstevel@tonic-gate 	&sdt_ops,		/* driver ops */
441*0Sstevel@tonic-gate };
442*0Sstevel@tonic-gate 
443*0Sstevel@tonic-gate static struct modlinkage modlinkage = {
444*0Sstevel@tonic-gate 	MODREV_1,
445*0Sstevel@tonic-gate 	(void *)&modldrv,
446*0Sstevel@tonic-gate 	NULL
447*0Sstevel@tonic-gate };
448*0Sstevel@tonic-gate 
449*0Sstevel@tonic-gate int
450*0Sstevel@tonic-gate _init(void)
451*0Sstevel@tonic-gate {
452*0Sstevel@tonic-gate 	return (mod_install(&modlinkage));
453*0Sstevel@tonic-gate }
454*0Sstevel@tonic-gate 
455*0Sstevel@tonic-gate int
456*0Sstevel@tonic-gate _info(struct modinfo *modinfop)
457*0Sstevel@tonic-gate {
458*0Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
459*0Sstevel@tonic-gate }
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate int
462*0Sstevel@tonic-gate _fini(void)
463*0Sstevel@tonic-gate {
464*0Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
465*0Sstevel@tonic-gate }
466