xref: /illumos-gate/usr/src/uts/common/io/options.c (revision 3d393ee6c37fa10ac512ed6d36109ad616dc7c1a)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #include <sys/types.h>
29 #include <sys/errno.h>
30 #include <sys/conf.h>
31 #include <sys/ddi.h>
32 #include <sys/sunddi.h>
33 
34 /*
35  * Configuration information
36  */
37 
38 static int options_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
39 		void **result);
40 static int options_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
41 static int options_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
42 static dev_info_t *options_devi;
43 
44 struct dev_ops	options_ops = {
45 
46 	DEVO_REV,		/* devo_rev, */
47 	0,			/* refcnt  */
48 	options_info,		/* info */
49 	nulldev,		/* identify */
50 	nulldev,		/* probe */
51 	options_attach,		/* attach */
52 	options_detach,		/* detach */
53 	nodev,			/* reset */
54 	(struct cb_ops *)0,	/* driver operations */
55 	(struct bus_ops *)0,	/* bus operations */
56 	nulldev,		/* power */
57 	ddi_quiesce_not_needed,		/* quiesce */
58 
59 };
60 
61 /*
62  * Autoload Data and Autoload Entry
63  */
64 
65 #include <sys/modctl.h>
66 
67 extern struct mod_ops mod_driverops;
68 static struct modldrv modldrv = {
69 	&mod_driverops,	/* Type of module. This one is a driver */
70 	"options driver",	/* Name of the module. */
71 	&options_ops,	/* driver ops */
72 };
73 
74 static struct modlinkage modlinkage = {
75 	MODREV_1, (void *)&modldrv
76 };
77 
78 /*
79  * This is the driver initialization routine.
80  */
81 
82 int
83 _init()
84 {
85 	return (mod_install(&modlinkage));
86 }
87 
88 int
89 _fini()
90 {
91 	return (EBUSY);
92 }
93 
94 int
95 _info(modinfop)
96 	struct modinfo *modinfop;
97 {
98 	return (mod_info(&modlinkage, modinfop));
99 }
100 
101 /* ARGSUSED */
102 static int
103 options_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
104 {
105 	register int error;
106 
107 	switch (infocmd) {
108 	case DDI_INFO_DEVT2DEVINFO:
109 		if (options_devi == NULL) {
110 			error = DDI_FAILURE;
111 		} else {
112 			*result = (void *) options_devi;
113 			error = DDI_SUCCESS;
114 		}
115 		break;
116 	case DDI_INFO_DEVT2INSTANCE:
117 		*result = (void *)0;
118 		error = DDI_SUCCESS;
119 		break;
120 	default:
121 		error = DDI_FAILURE;
122 	}
123 	return (error);
124 }
125 
126 static int
127 options_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
128 {
129 	switch (cmd) {
130 	case DDI_ATTACH:
131 		options_devi = devi;
132 		return (DDI_SUCCESS);
133 
134 	case DDI_RESUME:
135 		return (DDI_SUCCESS);
136 
137 	default:
138 		return (DDI_FAILURE);
139 	}
140 }
141 
142 /*ARGSUSED*/
143 static int
144 options_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
145 {
146 	switch (cmd) {
147 	case DDI_SUSPEND:
148 		return (DDI_SUCCESS);
149 
150 	case DDI_DETACH:
151 	default:
152 		return (DDI_FAILURE);
153 	}
154 }
155