Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/usb/clients/ugen/ugen.c
+++ new/usr/src/uts/common/io/usb/clients/ugen/ugen.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 *
21 21 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
22 22 * Use is subject to license terms.
23 23 */
24 24
25 25
26 26 /*
27 27 * UGEN: USB Generic Driver
28 28 *
29 29 * The "Universal Generic Driver" (UGEN) for USB devices provides interfaces
30 30 * to talk to USB devices. This is very useful for Point of Sale sale
31 31 * devices and other simple devices like USB scanner, USB palm pilot.
32 32 * The UGEN provides a system call interface to USB devices enabling
33 33 * a USB device vendor to write an application for his
34 34 * device instead of writing a driver. This facilitates the vendor to write
35 35 * device management s/w quickly in userland.
36 36 *
37 37 * UGEN supports read/write/poll entry points. An application can be written
38 38 * using read/write/aioread/aiowrite/poll system calls to communicate
39 39 * with the device.
40 40 */
41 41 #include <sys/usb/usba/usbai_version.h>
42 42 #include <sys/usb/usba.h>
43 43 #include <sys/usb/usba/usba_ugen.h>
44 44 #include <sys/usb/clients/ugen/ugend.h>
45 45
46 46 /* Global variables */
47 47 static void *ugen_skel_statep;
48 48
49 49 /* Prototypes declarations for the entry points */
50 50 static int ugen_skel_getinfo(dev_info_t *, ddi_info_cmd_t,
51 51 void *, void **);
52 52 static int ugen_skel_open(dev_t *, int, int, cred_t *);
53 53 static int ugen_skel_close(dev_t, int, int, cred_t *);
54 54 static int ugen_skel_attach(dev_info_t *, ddi_attach_cmd_t);
55 55 static int ugen_skel_detach(dev_info_t *, ddi_detach_cmd_t);
56 56 static int ugen_skel_power(dev_info_t *, int, int);
57 57 static int ugen_skel_read(dev_t, struct uio *, cred_t *);
58 58 static int ugen_skel_write(dev_t, struct uio *, cred_t *);
59 59 static int ugen_skel_poll(dev_t, short, int, short *,
60 60 struct pollhead **);
61 61
62 62 static int ugen_skel_disconnect_ev_cb(dev_info_t *);
63 63 static int ugen_skel_reconnect_ev_cb(dev_info_t *);
64 64
65 65 /* event support */
66 66 static usb_event_t ugen_skel_events = {
67 67 ugen_skel_disconnect_ev_cb,
68 68 ugen_skel_reconnect_ev_cb,
69 69 NULL, NULL
70 70 };
71 71
72 72 /* Driver cb_ops structure */
73 73 static struct cb_ops ugen_skel_cb_ops = {
74 74 ugen_skel_open, /* open */
75 75 ugen_skel_close, /* close */
76 76 nodev, /* strategy */
77 77 nodev, /* print */
78 78 nodev, /* dump */
79 79 ugen_skel_read, /* read */
80 80 ugen_skel_write, /* write */
81 81 nodev, /* ioctl */
82 82 nodev, /* devmap */
83 83 nodev, /* mmap */
84 84 nodev, /* segmap */
85 85 ugen_skel_poll, /* poll */
86 86 ddi_prop_op, /* cb_prop_op */
87 87 0, /* streamtab */
88 88 D_MP, /* Driver compatibility flag */
89 89 CB_REV, /* revision */
90 90 nodev, /* aread */
91 91 nodev /* awrite */
92 92 };
93 93
94 94 /*
95 95 * Modloading support
96 96 * driver dev_ops structure
97 97 */
98 98 static struct dev_ops ugen_skel_ops = {
99 99 DEVO_REV, /* devo_rev, */
100 100 0, /* refct */
101 101 ugen_skel_getinfo, /* info */
102 102 nulldev, /* indetify */
103 103 nulldev, /* probe */
104 104 ugen_skel_attach, /* attach */
105 105 ugen_skel_detach, /* detach */
106 106 nodev, /* reset */
107 107 &ugen_skel_cb_ops, /* driver operations */
108 108 NULL, /* bus operations */
109 109 ugen_skel_power, /* power */
110 110 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
110 lines elided |
↑ open up ↑ |
111 111 };
112 112
113 113 static struct modldrv modldrv = {
114 114 &mod_driverops, /* Module type */
115 115 "USB Generic driver", /* Name of the module. */
116 116 &ugen_skel_ops, /* driver ops */
117 117 };
118 118
119 119 static struct modlinkage modlinkage = {
120 120 MODREV_1,
121 - (void *)&modldrv,
122 - NULL
121 + { (void *)&modldrv, NULL }
123 122 };
124 123
125 124
126 125 int
127 126 _init()
128 127 {
129 128 int rval;
130 129
131 130 if ((rval = ddi_soft_state_init(&ugen_skel_statep,
132 131 sizeof (ugen_skel_state_t), UGEN_INSTANCES)) != 0) {
133 132
134 133 return (rval);
135 134 }
136 135
137 136 if ((rval = mod_install(&modlinkage)) != 0) {
138 137 ddi_soft_state_fini(&ugen_skel_statep);
139 138
140 139 return (rval);
141 140 }
142 141
143 142 return (rval);
144 143 }
145 144
146 145
147 146 int
148 147 _fini()
149 148 {
150 149 int rval;
151 150
152 151 if ((rval = mod_remove(&modlinkage)) != 0) {
153 152
154 153 return (rval);
155 154 }
156 155 ddi_soft_state_fini(&ugen_skel_statep);
157 156
158 157 return (rval);
159 158 }
160 159
161 160
162 161 int
163 162 _info(struct modinfo *modinfop)
164 163 {
165 164 return (mod_info(&modlinkage, modinfop));
166 165 }
167 166
168 167
169 168 /*ARGSUSED*/
170 169 static int
171 170 ugen_skel_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
172 171 void **result)
173 172 {
174 173 int rval = DDI_FAILURE;
175 174 int instance =
176 175 UGEN_MINOR_TO_INSTANCE(getminor((dev_t)arg));
177 176 ugen_skel_state_t *ugen_skelp;
178 177
179 178 switch (infocmd) {
180 179 case DDI_INFO_DEVT2DEVINFO:
181 180 ugen_skelp = ddi_get_soft_state(ugen_skel_statep, instance);
182 181 if (ugen_skelp != NULL) {
183 182 *result = ugen_skelp->ugen_skel_dip;
184 183 if (*result != NULL) {
185 184 rval = DDI_SUCCESS;
186 185 }
187 186 } else {
188 187 *result = NULL;
189 188 }
190 189
191 190 break;
192 191 case DDI_INFO_DEVT2INSTANCE:
193 192 *result = (void *)(uintptr_t)instance;
194 193 rval = DDI_SUCCESS;
195 194
196 195 break;
197 196 default:
198 197
199 198 break;
200 199 }
201 200
202 201 return (rval);
203 202 }
204 203
205 204
206 205 /*
207 206 * ugen_skel_attach()
208 207 */
209 208 static int
210 209 ugen_skel_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
211 210 {
212 211 ugen_skel_state_t *ugen_skelp;
213 212 int instance; /* Driver instance number */
214 213 int rval;
215 214 usb_ugen_info_t usb_ugen_info;
216 215
217 216 /* Get instance number */
218 217 instance = ddi_get_instance(dip);
219 218
220 219 switch (cmd) {
221 220 case DDI_ATTACH:
222 221
223 222 break;
224 223 case DDI_RESUME:
225 224 ugen_skelp = ddi_get_soft_state(ugen_skel_statep, instance);
226 225 if (ugen_skelp == NULL) {
227 226
228 227 return (DDI_FAILURE);
229 228 }
230 229
231 230 rval = usb_ugen_attach(ugen_skelp->ugen_skel_hdl, cmd);
232 231
233 232 return (rval == USB_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
234 233 default:
235 234
236 235 return (DDI_FAILURE);
237 236 }
238 237
239 238 if (ddi_soft_state_zalloc(ugen_skel_statep, instance) ==
240 239 DDI_SUCCESS) {
241 240 ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
242 241 instance);
243 242 }
244 243 if (ugen_skelp == NULL) {
245 244
246 245 return (DDI_FAILURE);
247 246 }
248 247
249 248 if ((rval = usb_client_attach(dip, USBDRV_VERSION, 0)) !=
250 249 USB_SUCCESS) {
251 250
252 251 goto fail;
253 252 }
254 253
255 254 ugen_skelp->ugen_skel_dip = dip;
256 255 ugen_skelp->ugen_skel_instance = instance;
257 256
258 257 /* get a ugen handle */
259 258 bzero(&usb_ugen_info, sizeof (usb_ugen_info));
260 259 usb_ugen_info.usb_ugen_flags =
261 260 USB_UGEN_ENABLE_PM | USB_UGEN_REMOVE_CHILDREN;
262 261 usb_ugen_info.usb_ugen_minor_node_ugen_bits_mask =
263 262 (dev_t)UGEN_MINOR_UGEN_BITS_MASK;
264 263 usb_ugen_info.usb_ugen_minor_node_instance_mask =
265 264 (dev_t)~UGEN_MINOR_UGEN_BITS_MASK;
266 265 ugen_skelp->ugen_skel_hdl = usb_ugen_get_hdl(dip,
267 266 &usb_ugen_info);
268 267
269 268 if (usb_ugen_attach(ugen_skelp->ugen_skel_hdl, cmd) != USB_SUCCESS) {
270 269
271 270 goto fail;
272 271 }
273 272
274 273 /* register for hotplug events */
275 274 if (usb_register_event_cbs(dip, &ugen_skel_events, 0) != USB_SUCCESS) {
276 275
277 276 goto fail;
278 277 }
279 278
280 279 ddi_report_dev(dip);
281 280
282 281 return (DDI_SUCCESS);
283 282
284 283 fail:
285 284 if (ugen_skelp) {
286 285 usb_unregister_event_cbs(dip, &ugen_skel_events);
287 286 usb_ugen_release_hdl(ugen_skelp->
288 287 ugen_skel_hdl);
289 288 ddi_soft_state_free(ugen_skel_statep,
290 289 ugen_skelp->ugen_skel_instance);
291 290 usb_client_detach(dip, NULL);
292 291 }
293 292
294 293 return (DDI_FAILURE);
295 294 }
296 295
297 296
298 297 /*
299 298 * ugen_skel_detach()
300 299 */
301 300 static int
302 301 ugen_skel_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
303 302 {
304 303 int rval = USB_FAILURE;
305 304 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
306 305 ddi_get_instance(dip));
307 306
308 307 if (ugen_skelp) {
309 308 switch (cmd) {
310 309 case DDI_DETACH:
311 310 rval = usb_ugen_detach(ugen_skelp->ugen_skel_hdl, cmd);
312 311 if (rval == USB_SUCCESS) {
313 312 usb_unregister_event_cbs(dip,
314 313 &ugen_skel_events);
315 314 usb_ugen_release_hdl(ugen_skelp->
316 315 ugen_skel_hdl);
317 316 ddi_soft_state_free(ugen_skel_statep,
318 317 ugen_skelp->ugen_skel_instance);
319 318 usb_client_detach(dip, NULL);
320 319 }
321 320
322 321 break;
323 322 case DDI_SUSPEND:
324 323 rval = usb_ugen_detach(ugen_skelp->ugen_skel_hdl, cmd);
325 324
326 325 break;
327 326 default:
328 327
329 328 break;
330 329 }
331 330 }
332 331
333 332 return (rval == USB_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
334 333 }
335 334
336 335
337 336 /*
338 337 * ugen_skel_disconnect_ev_cb:
339 338 */
340 339 static int
341 340 ugen_skel_disconnect_ev_cb(dev_info_t *dip)
342 341 {
343 342 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
344 343 ddi_get_instance(dip));
345 344
346 345 return (usb_ugen_disconnect_ev_cb(ugen_skelp->ugen_skel_hdl));
347 346 }
348 347
349 348
350 349 /*
351 350 * ugen_skel_reconnect_ev_cb:
352 351 */
353 352 static int
354 353 ugen_skel_reconnect_ev_cb(dev_info_t *dip)
355 354 {
356 355 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
357 356 ddi_get_instance(dip));
358 357
359 358 return (usb_ugen_reconnect_ev_cb(ugen_skelp->ugen_skel_hdl));
360 359 }
361 360
362 361
363 362 /*
364 363 * ugen_skel_open:
365 364 */
366 365 static int
367 366 ugen_skel_open(dev_t *devp, int flag, int sflag, cred_t *cr)
368 367 {
369 368 ugen_skel_state_t *ugen_skelp;
370 369
371 370 if ((ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
372 371 UGEN_MINOR_TO_INSTANCE(getminor(*devp)))) == NULL) {
373 372 /* deferred detach */
374 373
375 374 return (ENXIO);
376 375 }
377 376
378 377 return (usb_ugen_open(ugen_skelp->ugen_skel_hdl, devp, flag,
379 378 sflag, cr));
380 379 }
381 380
382 381
383 382 /*
384 383 * ugen_skel_close()
385 384 */
386 385 static int
387 386 ugen_skel_close(dev_t dev, int flag, int otype, cred_t *cr)
388 387 {
389 388 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
390 389 UGEN_MINOR_TO_INSTANCE(getminor(dev)));
391 390
392 391 return (usb_ugen_close(ugen_skelp->ugen_skel_hdl, dev, flag,
393 392 otype, cr));
394 393 }
395 394
396 395
397 396 /*
398 397 * ugen_skel_read/write()
399 398 */
400 399 static int
401 400 ugen_skel_read(dev_t dev, struct uio *uiop, cred_t *credp)
402 401 {
403 402 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
404 403 UGEN_MINOR_TO_INSTANCE(getminor(dev)));
405 404 if (ugen_skelp == NULL) {
406 405
407 406 return (ENXIO);
408 407 }
409 408
410 409 return (usb_ugen_read(ugen_skelp->ugen_skel_hdl, dev,
411 410 uiop, credp));
412 411 }
413 412
414 413
415 414 static int
416 415 ugen_skel_write(dev_t dev, struct uio *uiop, cred_t *credp)
417 416 {
418 417 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
419 418 UGEN_MINOR_TO_INSTANCE(getminor(dev)));
420 419 if (ugen_skelp == NULL) {
421 420
422 421 return (ENXIO);
423 422 }
424 423 return (usb_ugen_write(ugen_skelp->ugen_skel_hdl,
425 424 dev, uiop, credp));
426 425 }
427 426
428 427
429 428 /*
430 429 * ugen_skel_poll
431 430 */
432 431 static int
433 432 ugen_skel_poll(dev_t dev, short events,
434 433 int anyyet, short *reventsp, struct pollhead **phpp)
435 434 {
436 435 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
437 436 UGEN_MINOR_TO_INSTANCE(getminor(dev)));
438 437 if (ugen_skelp == NULL) {
439 438
440 439 return (ENXIO);
441 440 }
442 441
443 442 return (usb_ugen_poll(ugen_skelp->ugen_skel_hdl, dev, events,
444 443 anyyet, reventsp, phpp));
445 444 }
446 445
447 446
448 447 /*
449 448 * ugen_skel_power:
450 449 * PM entry point
451 450 */
452 451 static int
453 452 ugen_skel_power(dev_info_t *dip, int comp, int level)
454 453 {
455 454 int rval;
456 455
457 456 ugen_skel_state_t *ugen_skelp = ddi_get_soft_state(ugen_skel_statep,
458 457 ddi_get_instance(dip));
459 458 if (ugen_skelp == NULL) {
460 459
461 460 return (DDI_FAILURE);
462 461 }
463 462 rval = usb_ugen_power(ugen_skelp->ugen_skel_hdl, comp, level);
464 463
465 464 return (rval == USB_SUCCESS ? DDI_SUCCESS : DDI_FAILURE);
466 465 }
↓ open down ↓ |
334 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX