Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / usb / hubd / hubd.c
blob6c143acd2c88bd2f1990540f6f933952843e7f64
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 * skeleton hub driver, the actual code is in hubdi.c
29 * as it is shared between the root hub and the other hub instances
32 #include <sys/usb/usba/usbai_version.h>
33 #include <sys/usb/usba.h>
34 #include <sys/usb/usba/hubdi.h>
35 #include <sys/usb/hubd/hub.h>
36 #include <sys/usb/hubd/hubdvar.h>
38 static int hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp);
39 static int hubd_close(dev_t dev, int flag, int otyp, cred_t *credp);
40 static int hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
41 cred_t *credp, int *rvalp);
42 static int hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
43 void *arg, void **result);
44 extern int usba_hubdi_power(dev_info_t *dip, int comp, int level);
47 static struct cb_ops hubd_cb_ops = {
48 hubd_open, /* open */
49 hubd_close, /* close */
50 nodev, /* strategy */
51 nodev, /* print */
52 nodev, /* dump */
53 nodev, /* read */
54 nodev, /* write */
55 hubd_ioctl, /* ioctl */
56 nodev, /* devmap */
57 nodev, /* mmap */
58 nodev, /* segmap */
59 nochpoll, /* poll */
60 ddi_prop_op, /* cb_prop_op */
61 NULL, /* streamtab */
62 D_MP /* Driver compatibility flag */
65 static struct dev_ops hubd_ops = {
66 DEVO_REV, /* devo_rev, */
67 0, /* refcnt */
68 hubd_info, /* info */
69 nulldev, /* identify */
70 nulldev, /* probe */
71 usba_hubdi_attach, /* attach */
72 usba_hubdi_detach, /* detach */
73 nodev, /* reset */
74 &hubd_cb_ops, /* driver operations */
75 &usba_hubdi_busops, /* bus operations */
76 usba_hubdi_power, /* power */
77 ddi_quiesce_not_needed, /* quiesce */
80 static struct modldrv modldrv = {
81 &mod_driverops, /* Type of module. This one is a driver */
82 "USB Hub Driver", /* Name of the module. */
83 &hubd_ops, /* driver ops */
86 static struct modlinkage modlinkage = {
87 MODREV_1, (void *)&modldrv, NULL
91 extern void *hubd_statep;
93 int
94 _init(void)
96 int rval;
98 /* Initialize the soft state structures */
99 if ((rval = ddi_soft_state_init(&hubd_statep,
100 sizeof (hubd_t), HUBD_INITIAL_SOFT_SPACE)) != 0) {
101 return (rval);
104 if ((rval = mod_install(&modlinkage)) != 0) {
105 ddi_soft_state_fini(&hubd_statep);
107 return (rval);
110 return (rval);
115 _fini(void)
117 int rval = mod_remove(&modlinkage);
118 if (rval == 0) {
119 ddi_soft_state_fini(&hubd_statep);
122 return (rval);
127 _info(struct modinfo *modinfop)
129 return (mod_info(&modlinkage, modinfop));
133 static dev_info_t *
134 hubd_get_dip(dev_t dev)
136 minor_t minor = getminor(dev);
137 int instance = (int)minor & ~HUBD_IS_ROOT_HUB;
138 hubd_t *hubd = ddi_get_soft_state(hubd_statep, instance);
140 if (hubd) {
141 return (hubd->h_dip);
142 } else {
143 return (NULL);
148 * info handler
150 /*ARGSUSED*/
152 hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
153 void *arg, void **result)
155 dev_t dev;
156 int instance;
157 int error = DDI_FAILURE;
159 switch (infocmd) {
160 case DDI_INFO_DEVT2DEVINFO:
161 *result = (void *)hubd_get_dip((dev_t)arg);
162 if (*result != NULL) {
163 error = DDI_SUCCESS;
165 break;
166 case DDI_INFO_DEVT2INSTANCE:
167 dev = (dev_t)arg;
168 instance = HUBD_UNIT(dev);
169 *result = (void *)(intptr_t)instance;
170 error = DDI_SUCCESS;
171 break;
172 default:
173 break;
175 return (error);
178 static int
179 hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp)
181 dev_info_t *dip = hubd_get_dip(*devp);
183 return (usba_hubdi_open(dip, devp, flags, otyp, credp));
187 static int
188 hubd_close(dev_t dev, int flag, int otyp, cred_t *credp)
190 dev_info_t *dip = hubd_get_dip(dev);
192 return (usba_hubdi_close(dip, dev, flag, otyp, credp));
196 static int
197 hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
198 cred_t *credp, int *rvalp)
200 dev_info_t *dip = hubd_get_dip(dev);
202 return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode,
203 credp, rvalp));