xref: /onnv-gate/usr/src/uts/common/io/usb/hubd/hubd.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 2004 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 /*
30*0Sstevel@tonic-gate  * skeleton hub driver, the actual code is in hubdi.c
31*0Sstevel@tonic-gate  * as it is shared between the root hub and the other hub instances
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate #if defined(lint) && !defined(DEBUG)
34*0Sstevel@tonic-gate #define	DEBUG	1
35*0Sstevel@tonic-gate #endif
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include <sys/usb/usba/usbai_version.h>
38*0Sstevel@tonic-gate #include <sys/usb/usba.h>
39*0Sstevel@tonic-gate #include <sys/usb/usba/hubdi.h>
40*0Sstevel@tonic-gate #include <sys/usb/hubd/hub.h>
41*0Sstevel@tonic-gate #include <sys/usb/hubd/hubdvar.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate static int hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp);
44*0Sstevel@tonic-gate static int hubd_close(dev_t dev, int flag, int otyp, cred_t *credp);
45*0Sstevel@tonic-gate static int hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
46*0Sstevel@tonic-gate 	cred_t *credp, int *rvalp);
47*0Sstevel@tonic-gate static int hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
48*0Sstevel@tonic-gate 	void *arg, void **result);
49*0Sstevel@tonic-gate extern int usba_hubdi_power(dev_info_t *dip, int comp, int level);
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate static struct cb_ops hubd_cb_ops = {
53*0Sstevel@tonic-gate 	hubd_open,			/* open */
54*0Sstevel@tonic-gate 	hubd_close,			/* close */
55*0Sstevel@tonic-gate 	nodev,				/* strategy */
56*0Sstevel@tonic-gate 	nodev,				/* print */
57*0Sstevel@tonic-gate 	nodev,				/* dump */
58*0Sstevel@tonic-gate 	nodev,				/* read */
59*0Sstevel@tonic-gate 	nodev,				/* write */
60*0Sstevel@tonic-gate 	hubd_ioctl,			/* ioctl */
61*0Sstevel@tonic-gate 	nodev,				/* devmap */
62*0Sstevel@tonic-gate 	nodev,				/* mmap */
63*0Sstevel@tonic-gate 	nodev,				/* segmap */
64*0Sstevel@tonic-gate 	nochpoll,			/* poll */
65*0Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
66*0Sstevel@tonic-gate 	NULL,				/* streamtab */
67*0Sstevel@tonic-gate 	D_MP				/* Driver compatibility flag */
68*0Sstevel@tonic-gate };
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate static struct dev_ops hubd_ops = {
71*0Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
72*0Sstevel@tonic-gate 	0,			/* refcnt  */
73*0Sstevel@tonic-gate 	hubd_info,		/* info */
74*0Sstevel@tonic-gate 	nulldev,		/* identify */
75*0Sstevel@tonic-gate 	nulldev,		/* probe */
76*0Sstevel@tonic-gate 	usba_hubdi_attach,	/* attach */
77*0Sstevel@tonic-gate 	usba_hubdi_detach,	/* detach */
78*0Sstevel@tonic-gate 	nodev,			/* reset */
79*0Sstevel@tonic-gate 	&hubd_cb_ops,		/* driver operations */
80*0Sstevel@tonic-gate 	&usba_hubdi_busops,	/* bus operations */
81*0Sstevel@tonic-gate 	usba_hubdi_power	/* power */
82*0Sstevel@tonic-gate };
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate static struct modldrv modldrv = {
85*0Sstevel@tonic-gate 	&mod_driverops, /* Type of module. This one is a driver */
86*0Sstevel@tonic-gate 	"USB Hub Driver %I%", /* Name of the module. */
87*0Sstevel@tonic-gate 	&hubd_ops,	/* driver ops */
88*0Sstevel@tonic-gate };
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate static struct modlinkage modlinkage = {
91*0Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
92*0Sstevel@tonic-gate };
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate extern void *hubd_statep;
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate int
98*0Sstevel@tonic-gate _init(void)
99*0Sstevel@tonic-gate {
100*0Sstevel@tonic-gate 	int rval;
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	/* Initialize the soft state structures */
103*0Sstevel@tonic-gate 	if ((rval = ddi_soft_state_init(&hubd_statep,
104*0Sstevel@tonic-gate 	    sizeof (hubd_t), HUBD_INITIAL_SOFT_SPACE)) != 0) {
105*0Sstevel@tonic-gate 		return (rval);
106*0Sstevel@tonic-gate 	}
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	if ((rval = mod_install(&modlinkage)) != 0) {
109*0Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 		return (rval);
112*0Sstevel@tonic-gate 	}
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate 	return (rval);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate int
119*0Sstevel@tonic-gate _fini(void)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate 	int rval = mod_remove(&modlinkage);
122*0Sstevel@tonic-gate 	if (rval == 0) {
123*0Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
124*0Sstevel@tonic-gate 	}
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	return (rval);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate int
131*0Sstevel@tonic-gate _info(struct modinfo *modinfop)
132*0Sstevel@tonic-gate {
133*0Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate static dev_info_t *
138*0Sstevel@tonic-gate hubd_get_dip(dev_t dev)
139*0Sstevel@tonic-gate {
140*0Sstevel@tonic-gate 	minor_t minor = getminor(dev);
141*0Sstevel@tonic-gate 	int instance = (int)minor & ~HUBD_IS_ROOT_HUB;
142*0Sstevel@tonic-gate 	hubd_t *hubd = ddi_get_soft_state(hubd_statep, instance);
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 	if (hubd) {
145*0Sstevel@tonic-gate 		return (hubd->h_dip);
146*0Sstevel@tonic-gate 	} else {
147*0Sstevel@tonic-gate 		return (NULL);
148*0Sstevel@tonic-gate 	}
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate /*
152*0Sstevel@tonic-gate  * info handler
153*0Sstevel@tonic-gate  */
154*0Sstevel@tonic-gate /*ARGSUSED*/
155*0Sstevel@tonic-gate int
156*0Sstevel@tonic-gate hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
157*0Sstevel@tonic-gate 	void *arg, void **result)
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate 	dev_t dev;
160*0Sstevel@tonic-gate 	int instance;
161*0Sstevel@tonic-gate 	int error = DDI_FAILURE;
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	switch (infocmd) {
164*0Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
165*0Sstevel@tonic-gate 		*result = (void *)hubd_get_dip((dev_t)arg);
166*0Sstevel@tonic-gate 		if (*result != NULL) {
167*0Sstevel@tonic-gate 			error = DDI_SUCCESS;
168*0Sstevel@tonic-gate 		}
169*0Sstevel@tonic-gate 		break;
170*0Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
171*0Sstevel@tonic-gate 		dev = (dev_t)arg;
172*0Sstevel@tonic-gate 		instance = HUBD_UNIT(dev);
173*0Sstevel@tonic-gate 		*result = (void *)(intptr_t)instance;
174*0Sstevel@tonic-gate 		error = DDI_SUCCESS;
175*0Sstevel@tonic-gate 		break;
176*0Sstevel@tonic-gate 	default:
177*0Sstevel@tonic-gate 		break;
178*0Sstevel@tonic-gate 	}
179*0Sstevel@tonic-gate 	return (error);
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate static int
183*0Sstevel@tonic-gate hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp)
184*0Sstevel@tonic-gate {
185*0Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(*devp);
186*0Sstevel@tonic-gate 
187*0Sstevel@tonic-gate 	return (usba_hubdi_open(dip, devp, flags, otyp, credp));
188*0Sstevel@tonic-gate }
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate static int
192*0Sstevel@tonic-gate hubd_close(dev_t dev, int flag, int otyp, cred_t *credp)
193*0Sstevel@tonic-gate {
194*0Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 	return (usba_hubdi_close(dip, dev, flag, otyp, credp));
197*0Sstevel@tonic-gate }
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate static int
201*0Sstevel@tonic-gate hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
202*0Sstevel@tonic-gate 	cred_t *credp, int *rvalp)
203*0Sstevel@tonic-gate {
204*0Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode,
207*0Sstevel@tonic-gate 						credp, rvalp));
208*0Sstevel@tonic-gate }
209