xref: /onnv-gate/usr/src/uts/common/os/dacf_clnt.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 (c) 1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
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 /*
30*0Sstevel@tonic-gate  * DACF (Device Autoconfiguration Framework) client code.
31*0Sstevel@tonic-gate  *
32*0Sstevel@tonic-gate  * DACF has two clients. the first is dacf modules which implement
33*0Sstevel@tonic-gate  * configuration operations; the second is the set of hooks in the kernel
34*0Sstevel@tonic-gate  * which do rule matching and invoke configuration operations.
35*0Sstevel@tonic-gate  *
36*0Sstevel@tonic-gate  * This file implements the second part, the kernel hooks.
37*0Sstevel@tonic-gate  *
38*0Sstevel@tonic-gate  * Currently implemented are post-attach and pre-detach handlers, and the hook
39*0Sstevel@tonic-gate  * for ddi_create_minor_common() which sets up post-attach and pre-detach
40*0Sstevel@tonic-gate  * reservations.
41*0Sstevel@tonic-gate  *
42*0Sstevel@tonic-gate  * This code depends on the core dacf code (in dacf.c) but the converse should
43*0Sstevel@tonic-gate  * never be true.
44*0Sstevel@tonic-gate  *
45*0Sstevel@tonic-gate  * This file also implements '__kernel', the kernel-supplied dacf module.
46*0Sstevel@tonic-gate  * For now, this is pretty much empty, except under DEBUG, in which case it
47*0Sstevel@tonic-gate  * contains some debugging code.
48*0Sstevel@tonic-gate  */
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #include <sys/param.h>
51*0Sstevel@tonic-gate #include <sys/modctl.h>
52*0Sstevel@tonic-gate #include <sys/sysmacros.h>
53*0Sstevel@tonic-gate #include <sys/kmem.h>
54*0Sstevel@tonic-gate #include <sys/cmn_err.h>
55*0Sstevel@tonic-gate #include <sys/pathname.h>
56*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
57*0Sstevel@tonic-gate #include <sys/sunddi.h>
58*0Sstevel@tonic-gate #include <sys/autoconf.h>
59*0Sstevel@tonic-gate #include <sys/modhash.h>
60*0Sstevel@tonic-gate #include <sys/dacf_impl.h>
61*0Sstevel@tonic-gate #include <sys/systm.h>
62*0Sstevel@tonic-gate #include <sys/debug.h>
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /*
65*0Sstevel@tonic-gate  * dacfc_match_create_minor()
66*0Sstevel@tonic-gate  * 	Check to see if this minor node creation sequence matches a dacf
67*0Sstevel@tonic-gate  * 	(device autoconfiguration framework) rule.  If so make a reservation
68*0Sstevel@tonic-gate  * 	for the operation to be invoked at post-attach and/or pre-detach time.
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate void
71*0Sstevel@tonic-gate dacfc_match_create_minor(char *name, char *node_type, dev_info_t *dip,
72*0Sstevel@tonic-gate     struct ddi_minor_data *dmdp, int flag)
73*0Sstevel@tonic-gate {
74*0Sstevel@tonic-gate 	dacf_rule_t *r;
75*0Sstevel@tonic-gate 	char *dev_path, *dev_pathp, *drv_mname = NULL;
76*0Sstevel@tonic-gate 	dacf_rsrvlist_t *pa_rsrv, *pd_rsrv;
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate 	if (flag & CLONE_DEV) {
79*0Sstevel@tonic-gate 		return;
80*0Sstevel@tonic-gate 	}
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate 	/*
83*0Sstevel@tonic-gate 	 * Because dacf currently only implements post-attach and pre-detach
84*0Sstevel@tonic-gate 	 * processing, we only care about minor nodes created during attach.
85*0Sstevel@tonic-gate 	 * However, there is no restriction on drivers about when to create
86*0Sstevel@tonic-gate 	 * minor nodes.
87*0Sstevel@tonic-gate 	 */
88*0Sstevel@tonic-gate 	if (!DEVI_IS_ATTACHING(dmdp->dip)) {
89*0Sstevel@tonic-gate 		return;
90*0Sstevel@tonic-gate 	}
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	dev_path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
93*0Sstevel@tonic-gate 	dev_pathp = ddi_pathname(dip, dev_path);
94*0Sstevel@tonic-gate 	pa_rsrv = kmem_alloc(sizeof (dacf_rsrvlist_t), KM_SLEEP);
95*0Sstevel@tonic-gate 	pd_rsrv = kmem_alloc(sizeof (dacf_rsrvlist_t), KM_SLEEP);
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate 	if (name) {
98*0Sstevel@tonic-gate 		const char *drv_name = ddi_driver_name(dip);
99*0Sstevel@tonic-gate 		if (drv_name == NULL)
100*0Sstevel@tonic-gate 			drv_name = "???";
101*0Sstevel@tonic-gate 		drv_mname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
102*0Sstevel@tonic-gate 		(void) snprintf(drv_mname, MAXPATHLEN, "%s:%s", drv_name, name);
103*0Sstevel@tonic-gate 	}
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 	mutex_enter(&dacf_lock);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	/*
108*0Sstevel@tonic-gate 	 * Ensure that we don't wind up in a 'matching loop' against a devinfo
109*0Sstevel@tonic-gate 	 * node, which could cause deadlock.  This could happen as follows:
110*0Sstevel@tonic-gate 	 *
111*0Sstevel@tonic-gate 	 * 	We match (just below)
112*0Sstevel@tonic-gate 	 * 	We invoke a task (later, at the end of devi_attach)
113*0Sstevel@tonic-gate 	 *	   this means we have taken the per-devinfo lock
114*0Sstevel@tonic-gate 	 * 	The task invoke winds up causing the same driver (that has
115*0Sstevel@tonic-gate 	 *	   just finished attaching) to create another minor node.
116*0Sstevel@tonic-gate 	 * 	We try to re-acquire the per-devinfo list lock again in the
117*0Sstevel@tonic-gate 	 *	   process of making another reservation
118*0Sstevel@tonic-gate 	 */
119*0Sstevel@tonic-gate 	mutex_enter(&(DEVI(dip)->devi_lock));
120*0Sstevel@tonic-gate 	if (DEVI_IS_INVOKING_DACF(dip)) {
121*0Sstevel@tonic-gate 		mutex_exit(&(DEVI(dip)->devi_lock));
122*0Sstevel@tonic-gate 		cmn_err(CE_WARN,
123*0Sstevel@tonic-gate 		    "!dacf detected deadlock, aborting matching procedure\n");
124*0Sstevel@tonic-gate 		mutex_exit(&dacf_lock);
125*0Sstevel@tonic-gate 		kmem_free(pa_rsrv, sizeof (dacf_rsrvlist_t));
126*0Sstevel@tonic-gate 		kmem_free(pd_rsrv, sizeof (dacf_rsrvlist_t));
127*0Sstevel@tonic-gate 		kmem_free(dev_path, MAXPATHLEN);
128*0Sstevel@tonic-gate 		if (drv_mname) {
129*0Sstevel@tonic-gate 			kmem_free(drv_mname, MAXPATHLEN);
130*0Sstevel@tonic-gate 		}
131*0Sstevel@tonic-gate 		return;
132*0Sstevel@tonic-gate 	}
133*0Sstevel@tonic-gate 	mutex_exit(&(DEVI(dip)->devi_lock));
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	/*
136*0Sstevel@tonic-gate 	 * Do rule matching.  It's possible to construct two rules that would
137*0Sstevel@tonic-gate 	 * match against the same minor node, so we match from most to least
138*0Sstevel@tonic-gate 	 * specific:
139*0Sstevel@tonic-gate 	 * 	device path
140*0Sstevel@tonic-gate 	 * 	minor node name (concatenation of drv_name:name
141*0Sstevel@tonic-gate 	 * 	node type
142*0Sstevel@tonic-gate 	 *
143*0Sstevel@tonic-gate 	 * Future additions to the set of device-specifiers should be
144*0Sstevel@tonic-gate 	 * sensitive to this ordering.
145*0Sstevel@tonic-gate 	 */
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	/*
148*0Sstevel@tonic-gate 	 * post-attach matching
149*0Sstevel@tonic-gate 	 */
150*0Sstevel@tonic-gate 	r = NULL;
151*0Sstevel@tonic-gate 	if (dev_pathp) {
152*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_DEV_PATH,
153*0Sstevel@tonic-gate 		    dev_pathp);
154*0Sstevel@tonic-gate 	}
155*0Sstevel@tonic-gate 	if (!r && drv_mname) {
156*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_DRV_MNAME,
157*0Sstevel@tonic-gate 		    drv_mname);
158*0Sstevel@tonic-gate 	}
159*0Sstevel@tonic-gate 	if (!r && node_type) {
160*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_MIN_NT, node_type);
161*0Sstevel@tonic-gate 	}
162*0Sstevel@tonic-gate 	if (r) {
163*0Sstevel@tonic-gate 		dacf_rsrv_make(pa_rsrv, r, dmdp, &(DEVI(dip)->devi_dacf_tasks));
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_MSGS)
166*0Sstevel@tonic-gate 			printf("dacf: made 'post-attach' reservation for "
167*0Sstevel@tonic-gate 			    "%s, %s, %s\n", name, node_type, dev_pathp);
168*0Sstevel@tonic-gate 	} else {
169*0Sstevel@tonic-gate 		kmem_free(pa_rsrv, sizeof (dacf_rsrvlist_t));
170*0Sstevel@tonic-gate 	}
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 	/*
173*0Sstevel@tonic-gate 	 * pre-detach matching
174*0Sstevel@tonic-gate 	 */
175*0Sstevel@tonic-gate 	r = NULL;
176*0Sstevel@tonic-gate 	if (dev_pathp) {
177*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_DEV_PATH,
178*0Sstevel@tonic-gate 		    dev_pathp);
179*0Sstevel@tonic-gate 	}
180*0Sstevel@tonic-gate 	if (!r && drv_mname) {
181*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_DRV_MNAME,
182*0Sstevel@tonic-gate 		    drv_mname);
183*0Sstevel@tonic-gate 	}
184*0Sstevel@tonic-gate 	if (!r && node_type) {
185*0Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_MIN_NT, node_type);
186*0Sstevel@tonic-gate 	}
187*0Sstevel@tonic-gate 	if (r) {
188*0Sstevel@tonic-gate 		dacf_rsrv_make(pd_rsrv, r, dmdp, &(DEVI(dip)->devi_dacf_tasks));
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_MSGS) {
191*0Sstevel@tonic-gate 			printf("dacf: made 'pre-detach' reservation for "
192*0Sstevel@tonic-gate 			    "%s, %s, %s\n", name, node_type, dev_pathp);
193*0Sstevel@tonic-gate 		}
194*0Sstevel@tonic-gate 	} else {
195*0Sstevel@tonic-gate 		kmem_free(pd_rsrv, sizeof (dacf_rsrvlist_t));
196*0Sstevel@tonic-gate 	}
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate 	mutex_exit(&dacf_lock);
199*0Sstevel@tonic-gate 	kmem_free(dev_path, MAXPATHLEN);
200*0Sstevel@tonic-gate 	if (drv_mname) {
201*0Sstevel@tonic-gate 		kmem_free(drv_mname, MAXPATHLEN);
202*0Sstevel@tonic-gate 	}
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate /*
206*0Sstevel@tonic-gate  * dacfc_postattach()
207*0Sstevel@tonic-gate  * 	autoconfiguration for post-attach events.
208*0Sstevel@tonic-gate  *
209*0Sstevel@tonic-gate  * 	strategy: try to configure.  If some of the configuration operations
210*0Sstevel@tonic-gate  * 	fail, emit a warning.
211*0Sstevel@tonic-gate  */
212*0Sstevel@tonic-gate int
213*0Sstevel@tonic-gate dacfc_postattach(dev_info_t *devi)
214*0Sstevel@tonic-gate {
215*0Sstevel@tonic-gate 	int err = DACF_SUCCESS;
216*0Sstevel@tonic-gate 	char *path, *pathp;
217*0Sstevel@tonic-gate 	dacf_rsrvlist_t **opsp, *op;
218*0Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&dacf_lock));
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 	/*
221*0Sstevel@tonic-gate 	 * Instruct dacf_process_rsrvs() to invoke each POSTATTACH op.
222*0Sstevel@tonic-gate 	 */
223*0Sstevel@tonic-gate 	opsp = &DEVI(devi)->devi_dacf_tasks;
224*0Sstevel@tonic-gate 	dacf_process_rsrvs(opsp, DACF_OPID_POSTATTACH, DACF_PROC_INVOKE);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	/*
227*0Sstevel@tonic-gate 	 * Check to see that all POSTATTACH's succeeded.
228*0Sstevel@tonic-gate 	 */
229*0Sstevel@tonic-gate 	for (op = *opsp; op != NULL; op = op->rsrv_next) {
230*0Sstevel@tonic-gate 		if (op->rsrv_rule->r_opid != DACF_OPID_POSTATTACH)
231*0Sstevel@tonic-gate 			continue;
232*0Sstevel@tonic-gate 		if (op->rsrv_result == DACF_SUCCESS)
233*0Sstevel@tonic-gate 			continue;
234*0Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
235*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "op failed, err = %d\n",
236*0Sstevel@tonic-gate 			    op->rsrv_result);
237*0Sstevel@tonic-gate 		}
238*0Sstevel@tonic-gate 		err = DACF_FAILURE;
239*0Sstevel@tonic-gate 		break;
240*0Sstevel@tonic-gate 	}
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	/*
243*0Sstevel@tonic-gate 	 * If one or more postattach's failed, give up.
244*0Sstevel@tonic-gate 	 */
245*0Sstevel@tonic-gate 	if ((err == DACF_FAILURE) && (dacfdebug & DACF_DBG_DEVI)) {
246*0Sstevel@tonic-gate 		path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
247*0Sstevel@tonic-gate 		if ((pathp = ddi_pathname(devi, path)) == NULL)
248*0Sstevel@tonic-gate 			pathp = "<unknown>";
249*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s attached, but failed to auto-configure",
250*0Sstevel@tonic-gate 		    pathp);
251*0Sstevel@tonic-gate 		kmem_free(path, MAXPATHLEN);
252*0Sstevel@tonic-gate 	}
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 	return (err);
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate /*
258*0Sstevel@tonic-gate  * dacfc_predetach()
259*0Sstevel@tonic-gate  * 	auto-unconfiguration for pre-detach events.
260*0Sstevel@tonic-gate  *
261*0Sstevel@tonic-gate  * 	strategy: call the pre-detach operation for all matching reservations.
262*0Sstevel@tonic-gate  * 	If any of these fail, make (one) attempt to reconfigure things back
263*0Sstevel@tonic-gate  * 	into a sane state.  if that fails, our state is uncertain.
264*0Sstevel@tonic-gate  */
265*0Sstevel@tonic-gate int
266*0Sstevel@tonic-gate dacfc_predetach(dev_info_t *devi)
267*0Sstevel@tonic-gate {
268*0Sstevel@tonic-gate 	int err = DDI_SUCCESS;
269*0Sstevel@tonic-gate 	char *path, *pathp;
270*0Sstevel@tonic-gate 	dacf_rsrvlist_t **opsp, *op;
271*0Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&dacf_lock));
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate 	/*
274*0Sstevel@tonic-gate 	 * Instruct dacf_process_rsrvs() to invoke each PREDETACH op.
275*0Sstevel@tonic-gate 	 */
276*0Sstevel@tonic-gate 	opsp = &DEVI(devi)->devi_dacf_tasks;
277*0Sstevel@tonic-gate 	dacf_process_rsrvs(opsp, DACF_OPID_PREDETACH, DACF_PROC_INVOKE);
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 	/*
280*0Sstevel@tonic-gate 	 * Check to see that all PREDETACH's succeeded.
281*0Sstevel@tonic-gate 	 */
282*0Sstevel@tonic-gate 	for (op = *opsp; op != NULL; op = op->rsrv_next) {
283*0Sstevel@tonic-gate 		if (op->rsrv_rule->r_opid != DACF_OPID_PREDETACH)
284*0Sstevel@tonic-gate 			continue;
285*0Sstevel@tonic-gate 		if (op->rsrv_result == 0)
286*0Sstevel@tonic-gate 			continue;
287*0Sstevel@tonic-gate 		err = DDI_FAILURE;
288*0Sstevel@tonic-gate 		break;
289*0Sstevel@tonic-gate 	}
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate 	/*
292*0Sstevel@tonic-gate 	 * If one or more predetach's failed, make one attempt to fix things
293*0Sstevel@tonic-gate 	 * by re-running all of the POST-ATTACH operations.  If any of those
294*0Sstevel@tonic-gate 	 * fail, give up.
295*0Sstevel@tonic-gate 	 */
296*0Sstevel@tonic-gate 	if (err == DDI_FAILURE) {
297*0Sstevel@tonic-gate 		int pa_err;
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
300*0Sstevel@tonic-gate 			path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
301*0Sstevel@tonic-gate 			if ((pathp = ddi_pathname(devi, path)) == NULL)
302*0Sstevel@tonic-gate 				pathp = "<unknown>";
303*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s failed to auto-unconfigure, "
304*0Sstevel@tonic-gate 			    "attempting to reconfigure...", pathp);
305*0Sstevel@tonic-gate 			kmem_free(path, MAXPATHLEN);
306*0Sstevel@tonic-gate 		}
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 		pa_err = dacfc_postattach(devi);
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
311*0Sstevel@tonic-gate 			path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
312*0Sstevel@tonic-gate 			if ((pathp = ddi_pathname(devi, path)) == NULL)
313*0Sstevel@tonic-gate 				pathp = "<unknown>";
314*0Sstevel@tonic-gate 
315*0Sstevel@tonic-gate 			if (pa_err == DDI_FAILURE) {
316*0Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s failed to "
317*0Sstevel@tonic-gate 				    "auto-unconfigure, and could not be "
318*0Sstevel@tonic-gate 				    "re-autoconfigured.", pathp);
319*0Sstevel@tonic-gate 			} else {
320*0Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s failed to "
321*0Sstevel@tonic-gate 				    "auto-unconfigure, but was successfully "
322*0Sstevel@tonic-gate 				    "re-autoconfigured.", pathp);
323*0Sstevel@tonic-gate 			}
324*0Sstevel@tonic-gate 			kmem_free(path, MAXPATHLEN);
325*0Sstevel@tonic-gate 		}
326*0Sstevel@tonic-gate 	}
327*0Sstevel@tonic-gate 
328*0Sstevel@tonic-gate 	return (err);
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate /*
332*0Sstevel@tonic-gate  * kmod_dacfsw:
333*0Sstevel@tonic-gate  * 	This is the declaration for the kernel-supplied '__kernel' dacf module.
334*0Sstevel@tonic-gate  * 	DACF supplies a framework based around loadable modules.  However, it
335*0Sstevel@tonic-gate  * 	may be convenient (in the future) to have a module provided by the
336*0Sstevel@tonic-gate  * 	kernel.  This is useful in cases when a module can't be loaded (early in
337*0Sstevel@tonic-gate  * 	boot), or for code that would never get unloaded anyway.
338*0Sstevel@tonic-gate  */
339*0Sstevel@tonic-gate #ifdef DEBUG
340*0Sstevel@tonic-gate /*ARGSUSED*/
341*0Sstevel@tonic-gate static int
342*0Sstevel@tonic-gate kmod_test_postattach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
343*0Sstevel@tonic-gate {
344*0Sstevel@tonic-gate 	const char *verbose = dacf_get_arg(arg_hdl, "verbose");
345*0Sstevel@tonic-gate 	if (verbose && (strcmp(verbose, "true") == 0)) {
346*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "got kmod_test_postattach\n");
347*0Sstevel@tonic-gate 	}
348*0Sstevel@tonic-gate 	return (0);
349*0Sstevel@tonic-gate }
350*0Sstevel@tonic-gate #endif
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate static dacf_op_t kmod_op_test[] = {
353*0Sstevel@tonic-gate #ifdef DEBUG
354*0Sstevel@tonic-gate 	{ DACF_OPID_POSTATTACH, kmod_test_postattach },
355*0Sstevel@tonic-gate #endif
356*0Sstevel@tonic-gate 	{ DACF_OPID_END,	NULL },
357*0Sstevel@tonic-gate };
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate static dacf_opset_t kmod_opsets[] = {
360*0Sstevel@tonic-gate #ifdef DEBUG
361*0Sstevel@tonic-gate 	{ "kmod_test",		kmod_op_test },
362*0Sstevel@tonic-gate #endif
363*0Sstevel@tonic-gate 	{ NULL,			NULL },
364*0Sstevel@tonic-gate };
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate struct dacfsw kmod_dacfsw = {
367*0Sstevel@tonic-gate 	DACF_MODREV_1, kmod_opsets
368*0Sstevel@tonic-gate };
369