xref: /onnv-gate/usr/src/uts/common/io/nulldriver.c (revision 8011:9406cd6ea18e)
1*8011SChris.Horne@Sun.COM /*
2*8011SChris.Horne@Sun.COM  * CDDL HEADER START
3*8011SChris.Horne@Sun.COM  *
4*8011SChris.Horne@Sun.COM  * The contents of this file are subject to the terms of the
5*8011SChris.Horne@Sun.COM  * Common Development and Distribution License (the "License").
6*8011SChris.Horne@Sun.COM  * You may not use this file except in compliance with the License.
7*8011SChris.Horne@Sun.COM  *
8*8011SChris.Horne@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*8011SChris.Horne@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*8011SChris.Horne@Sun.COM  * See the License for the specific language governing permissions
11*8011SChris.Horne@Sun.COM  * and limitations under the License.
12*8011SChris.Horne@Sun.COM  *
13*8011SChris.Horne@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*8011SChris.Horne@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*8011SChris.Horne@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*8011SChris.Horne@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*8011SChris.Horne@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*8011SChris.Horne@Sun.COM  *
19*8011SChris.Horne@Sun.COM  * CDDL HEADER END
20*8011SChris.Horne@Sun.COM  */
21*8011SChris.Horne@Sun.COM /*
22*8011SChris.Horne@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*8011SChris.Horne@Sun.COM  * Use is subject to license terms.
24*8011SChris.Horne@Sun.COM  */
25*8011SChris.Horne@Sun.COM 
26*8011SChris.Horne@Sun.COM /*
27*8011SChris.Horne@Sun.COM  * nulldriver - null device driver
28*8011SChris.Horne@Sun.COM  *
29*8011SChris.Horne@Sun.COM  * The nulldriver is used to associate a solaris driver with a specific
30*8011SChris.Horne@Sun.COM  * device without enabling external device access.
31*8011SChris.Horne@Sun.COM  *
32*8011SChris.Horne@Sun.COM  * The driver can be used to:
33*8011SChris.Horne@Sun.COM  *
34*8011SChris.Horne@Sun.COM  * o Prevent external access to specific devices/hardware by associating a
35*8011SChris.Horne@Sun.COM  *   high-precedence 'compatible' binding, including a path-oriented alias,
36*8011SChris.Horne@Sun.COM  *   with nulldriver.
37*8011SChris.Horne@Sun.COM  *
38*8011SChris.Horne@Sun.COM  * o Enable a nexus bus_config implementation to perform dynamic child
39*8011SChris.Horne@Sun.COM  *   discovery by creating a child 'probe' devinfo node, bound to
40*8011SChris.Horne@Sun.COM  *   nulldriver, at the specific child @unit-addresses associated with
41*8011SChris.Horne@Sun.COM  *   discovery.  With a nulldriver bound 'probe' node, nexus driver
42*8011SChris.Horne@Sun.COM  *   bus_config discovery code can use the same devinfo node oriented
43*8011SChris.Horne@Sun.COM  *   transport services for both discovery and normal-operation: which
44*8011SChris.Horne@Sun.COM  *   is a significant simplification.  While nulldriver prevents external
45*8011SChris.Horne@Sun.COM  *   device access, a nexus driver can still internally use the transport
46*8011SChris.Horne@Sun.COM  *   services.
47*8011SChris.Horne@Sun.COM  *
48*8011SChris.Horne@Sun.COM  *   A scsi(4) example of this type of use is SCSA enumeration services
49*8011SChris.Horne@Sun.COM  *   issuing a scsi REPORT_LUN command to a lun-0 'probe' node bound to
50*8011SChris.Horne@Sun.COM  *   nulldriver in order to discover all luns supported by a target.
51*8011SChris.Horne@Sun.COM  */
52*8011SChris.Horne@Sun.COM 
53*8011SChris.Horne@Sun.COM #include <sys/modctl.h>
54*8011SChris.Horne@Sun.COM #include <sys/conf.h>
55*8011SChris.Horne@Sun.COM #include <sys/ddi.h>
56*8011SChris.Horne@Sun.COM #include <sys/sunddi.h>
57*8011SChris.Horne@Sun.COM #include <sys/cmn_err.h>
58*8011SChris.Horne@Sun.COM 
59*8011SChris.Horne@Sun.COM static int nulldriver_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
60*8011SChris.Horne@Sun.COM static int nulldriver_probe(dev_info_t *);
61*8011SChris.Horne@Sun.COM static int nulldriver_attach(dev_info_t *, ddi_attach_cmd_t);
62*8011SChris.Horne@Sun.COM static int nulldriver_detach(dev_info_t *, ddi_detach_cmd_t);
63*8011SChris.Horne@Sun.COM 
64*8011SChris.Horne@Sun.COM static struct cb_ops nulldriver_cb_ops = {
65*8011SChris.Horne@Sun.COM 	nodev,				/* open */
66*8011SChris.Horne@Sun.COM 	nodev,				/* close */
67*8011SChris.Horne@Sun.COM 	nodev,				/* strategy */
68*8011SChris.Horne@Sun.COM 	nodev,				/* print */
69*8011SChris.Horne@Sun.COM 	nodev,				/* dump */
70*8011SChris.Horne@Sun.COM 	nodev,				/* read */
71*8011SChris.Horne@Sun.COM 	nodev,				/* write */
72*8011SChris.Horne@Sun.COM 	nodev,				/* ioctl */
73*8011SChris.Horne@Sun.COM 	nodev,				/* devmap */
74*8011SChris.Horne@Sun.COM 	nodev,				/* mmap */
75*8011SChris.Horne@Sun.COM 	nodev,				/* segmap */
76*8011SChris.Horne@Sun.COM 	nochpoll,			/* poll */
77*8011SChris.Horne@Sun.COM 	ddi_prop_op,			/* cb_prop_op */
78*8011SChris.Horne@Sun.COM 	0,				/* streamtab  */
79*8011SChris.Horne@Sun.COM 	D_MP | D_NEW | D_HOTPLUG	/* Driver compatibility flag */
80*8011SChris.Horne@Sun.COM };
81*8011SChris.Horne@Sun.COM 
82*8011SChris.Horne@Sun.COM static struct dev_ops nulldriver_dev_ops = {
83*8011SChris.Horne@Sun.COM 	DEVO_REV,			/* devo_rev, */
84*8011SChris.Horne@Sun.COM 	0,				/* refcnt  */
85*8011SChris.Horne@Sun.COM 	nulldriver_getinfo,		/* info */
86*8011SChris.Horne@Sun.COM 	nodev,				/* identify */
87*8011SChris.Horne@Sun.COM 	nulldriver_probe,		/* probe */
88*8011SChris.Horne@Sun.COM 	nulldriver_attach,		/* attach */
89*8011SChris.Horne@Sun.COM 	nulldriver_detach,		/* detach */
90*8011SChris.Horne@Sun.COM 	nodev,				/* reset */
91*8011SChris.Horne@Sun.COM 	&nulldriver_cb_ops,		/* driver operations */
92*8011SChris.Horne@Sun.COM 	(struct bus_ops *)0,		/* bus operations */
93*8011SChris.Horne@Sun.COM 	NULL,				/* power */
94*8011SChris.Horne@Sun.COM 	ddi_quiesce_not_needed,		/* quiesce */
95*8011SChris.Horne@Sun.COM };
96*8011SChris.Horne@Sun.COM 
97*8011SChris.Horne@Sun.COM static struct modldrv modldrv = {
98*8011SChris.Horne@Sun.COM 	&mod_driverops, "nulldriver 1.1", &nulldriver_dev_ops
99*8011SChris.Horne@Sun.COM };
100*8011SChris.Horne@Sun.COM 
101*8011SChris.Horne@Sun.COM static struct modlinkage modlinkage = {
102*8011SChris.Horne@Sun.COM 	MODREV_1, &modldrv, NULL
103*8011SChris.Horne@Sun.COM };
104*8011SChris.Horne@Sun.COM 
105*8011SChris.Horne@Sun.COM int
_init(void)106*8011SChris.Horne@Sun.COM _init(void)
107*8011SChris.Horne@Sun.COM {
108*8011SChris.Horne@Sun.COM 	return (mod_install(&modlinkage));
109*8011SChris.Horne@Sun.COM }
110*8011SChris.Horne@Sun.COM 
111*8011SChris.Horne@Sun.COM int
_fini(void)112*8011SChris.Horne@Sun.COM _fini(void)
113*8011SChris.Horne@Sun.COM {
114*8011SChris.Horne@Sun.COM 	return (mod_remove(&modlinkage));
115*8011SChris.Horne@Sun.COM }
116*8011SChris.Horne@Sun.COM 
117*8011SChris.Horne@Sun.COM int
_info(struct modinfo * modinfop)118*8011SChris.Horne@Sun.COM _info(struct modinfo *modinfop)
119*8011SChris.Horne@Sun.COM {
120*8011SChris.Horne@Sun.COM 	return (mod_info(&modlinkage, modinfop));
121*8011SChris.Horne@Sun.COM }
122*8011SChris.Horne@Sun.COM 
123*8011SChris.Horne@Sun.COM /*ARGSUSED*/
124*8011SChris.Horne@Sun.COM static int
nulldriver_getinfo(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)125*8011SChris.Horne@Sun.COM nulldriver_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd,
126*8011SChris.Horne@Sun.COM     void *arg, void **result)
127*8011SChris.Horne@Sun.COM {
128*8011SChris.Horne@Sun.COM 	return (DDI_FAILURE);
129*8011SChris.Horne@Sun.COM }
130*8011SChris.Horne@Sun.COM 
131*8011SChris.Horne@Sun.COM /*ARGSUSED*/
132*8011SChris.Horne@Sun.COM static int
nulldriver_probe(dev_info_t * dip)133*8011SChris.Horne@Sun.COM nulldriver_probe(dev_info_t *dip)
134*8011SChris.Horne@Sun.COM {
135*8011SChris.Horne@Sun.COM 	/*
136*8011SChris.Horne@Sun.COM 	 * We want to succeed probe so that the node gets assigned a unit
137*8011SChris.Horne@Sun.COM 	 * address "@addr".
138*8011SChris.Horne@Sun.COM 	 */
139*8011SChris.Horne@Sun.COM 	if (ddi_dev_is_sid(dip) == DDI_SUCCESS)
140*8011SChris.Horne@Sun.COM 		return (DDI_PROBE_DONTCARE);
141*8011SChris.Horne@Sun.COM 	return (DDI_PROBE_DONTCARE);
142*8011SChris.Horne@Sun.COM }
143*8011SChris.Horne@Sun.COM 
144*8011SChris.Horne@Sun.COM /*
145*8011SChris.Horne@Sun.COM  * nulldriver_attach()
146*8011SChris.Horne@Sun.COM  *	attach(9e) entrypoint.
147*8011SChris.Horne@Sun.COM  */
148*8011SChris.Horne@Sun.COM /* ARGSUSED */
149*8011SChris.Horne@Sun.COM static int
nulldriver_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)150*8011SChris.Horne@Sun.COM nulldriver_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
151*8011SChris.Horne@Sun.COM {
152*8011SChris.Horne@Sun.COM 	switch (cmd) {
153*8011SChris.Horne@Sun.COM 	case DDI_ATTACH:
154*8011SChris.Horne@Sun.COM 	case DDI_RESUME:
155*8011SChris.Horne@Sun.COM 		return (DDI_SUCCESS);
156*8011SChris.Horne@Sun.COM 
157*8011SChris.Horne@Sun.COM 	case DDI_PM_RESUME:
158*8011SChris.Horne@Sun.COM 	default:
159*8011SChris.Horne@Sun.COM 		return (DDI_FAILURE);
160*8011SChris.Horne@Sun.COM 	}
161*8011SChris.Horne@Sun.COM }
162*8011SChris.Horne@Sun.COM 
163*8011SChris.Horne@Sun.COM /*
164*8011SChris.Horne@Sun.COM  * nulldriver_detach()
165*8011SChris.Horne@Sun.COM  *	detach(9E) entrypoint
166*8011SChris.Horne@Sun.COM  */
167*8011SChris.Horne@Sun.COM /* ARGSUSED */
168*8011SChris.Horne@Sun.COM static int
nulldriver_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)169*8011SChris.Horne@Sun.COM nulldriver_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
170*8011SChris.Horne@Sun.COM {
171*8011SChris.Horne@Sun.COM 	switch (cmd) {
172*8011SChris.Horne@Sun.COM 	case DDI_DETACH:
173*8011SChris.Horne@Sun.COM 	case DDI_SUSPEND:
174*8011SChris.Horne@Sun.COM 		return (DDI_SUCCESS);
175*8011SChris.Horne@Sun.COM 
176*8011SChris.Horne@Sun.COM 	case DDI_PM_SUSPEND:
177*8011SChris.Horne@Sun.COM 	default:
178*8011SChris.Horne@Sun.COM 		return (DDI_FAILURE);
179*8011SChris.Horne@Sun.COM 	}
180*8011SChris.Horne@Sun.COM }
181