9c5b6eac758b814bc9f5f877854e678e6911fb12
[dragonfly.git] / sys / bus / usb / usb_port.h
1 /*
2  * $OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $
3  * $NetBSD: usb_port.h,v 1.68 2005/07/30 06:14:50 skrll Exp $
4  * $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.65 2003/11/09 23:54:21 joe Exp $
5  * $DragonFly: src/sys/bus/usb/usb_port.h,v 1.16 2006/12/22 23:12:17 swildner Exp $
6  */
7
8 /* Also already merged from NetBSD:
9  *      $NetBSD: usb_port.h,v 1.57 2002/09/27 20:42:01 thorpej Exp $
10  *      $NetBSD: usb_port.h,v 1.58 2002/10/01 01:25:26 thorpej Exp $
11  */
12
13 /*
14  * Copyright (c) 1998 The NetBSD Foundation, Inc.
15  * All rights reserved.
16  *
17  * This code is derived from software contributed to The NetBSD Foundation
18  * by Lennart Augustsson (lennart@augustsson.net) at
19  * Carlstedt Research & Technology.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  * 3. All advertising materials mentioning features or use of this software
30  *    must display the following acknowledgement:
31  *        This product includes software developed by the NetBSD
32  *        Foundation, Inc. and its contributors.
33  * 4. Neither the name of The NetBSD Foundation nor the names of its
34  *    contributors may be used to endorse or promote products derived
35  *    from this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
38  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
39  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
41  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  * POSSIBILITY OF SUCH DAMAGE.
48  */
49
50 #ifndef _USB_PORT_H
51 #define _USB_PORT_H
52
53 /*
54  * Macro's to cope with the differences between operating systems.
55  */
56
57 #if defined(__NetBSD__)
58 /*
59  * NetBSD
60  */
61
62 #include "opt_usbverbose.h"
63
64 #if defined(_KERNEL)
65 #include <sys/mallocvar.h>
66
67 MALLOC_DECLARE(M_USB);
68 MALLOC_DECLARE(M_USBDEV);
69 MALLOC_DECLARE(M_USBHC);
70
71 #endif
72
73 #define USB_USE_SOFTINTR
74
75 #ifdef USB_DEBUG
76 #define Static
77 #else
78 #define Static static
79 #endif
80
81 #define SCSI_MODE_SENSE         MODE_SENSE
82
83 typedef struct proc *usb_proc_ptr;
84
85 typedef struct device *device_ptr_t;
86 #define USBBASEDEVICE struct device
87 #define USBDEV(bdev) (&(bdev))
88 #define USBDEVNAME(bdev) ((bdev).dv_xname)
89 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
90 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
91 #define USBGETSOFTC(d) ((void *)(d))
92
93 #define DECLARE_USB_DMA_T \
94         struct usb_dma_block; \
95         typedef struct { \
96                 struct usb_dma_block *block; \
97                 u_int offs; \
98         } usb_dma_t
99
100 typedef struct callout usb_callout_t;
101 #define usb_callout_init(h)     callout_init(&(h))
102 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
103 #define usb_uncallout(h, f, d)  callout_stop(&(h))
104
105 #define usb_kthread_create1     kthread_create1
106 #define usb_kthread_create      kthread_create
107
108 typedef struct malloc_type *usb_malloc_type;
109
110 #define Ether_ifattach ether_ifattach
111
112 #define logprintf kprintf
113
114 #define USB_DNAME(dname)        dname
115 #define USB_DECLARE_DRIVER(dname)  \
116 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
117 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
118 int __CONCAT(dname,_detach)(struct device *, int); \
119 int __CONCAT(dname,_activate)(struct device *, enum devact); \
120 \
121 extern struct cfdriver __CONCAT(dname,_cd); \
122 \
123 CFATTACH_DECL(USB_DNAME(dname), \
124     sizeof(struct ___CONCAT(dname,_softc)), \
125     ___CONCAT(dname,_match), \
126     ___CONCAT(dname,_attach), \
127     ___CONCAT(dname,_detach), \
128     ___CONCAT(dname,_activate))
129
130 #define USB_MATCH(dname) \
131 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
132
133 #define USB_MATCH_START(dname, uaa) \
134         struct usb_attach_arg *uaa = aux
135
136 #define USB_ATTACH(dname) \
137 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
138
139 #define USB_ATTACH_START(dname, sc, uaa) \
140         struct __CONCAT(dname,_softc) *sc = \
141                 (struct __CONCAT(dname,_softc) *)self; \
142         struct usb_attach_arg *uaa = aux
143
144 /* Returns from attach */
145 #define USB_ATTACH_ERROR_RETURN return
146 #define USB_ATTACH_SUCCESS_RETURN       return
147
148 #define USB_ATTACH_SETUP kprintf("\n")
149
150 #define USB_DETACH(dname) \
151 int __CONCAT(dname,_detach)(struct device *self, int flags)
152
153 #define USB_DETACH_START(dname, sc) \
154         struct __CONCAT(dname,_softc) *sc = \
155                 (struct __CONCAT(dname,_softc) *)self
156
157 #define USB_GET_SC_OPEN(dname, unit, sc) \
158         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
159                 return (ENXIO); \
160         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
161         if (sc == NULL) \
162                 return (ENXIO)
163
164 #define USB_GET_SC(dname, unit, sc) \
165         sc = __CONCAT(dname,_cd).cd_devs[unit]
166
167 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
168         (config_found_sm_loc(parent, (args)->port == 0 ? "usb" : "uhub", \
169                              NULL, args, print, sub))
170
171 #elif defined(__OpenBSD__)
172 /*
173  * OpenBSD
174  */
175 #define Static
176
177 typedef struct proc *usb_proc_ptr;
178
179 #define UCOMBUSCF_PORTNO                -1
180 #define UCOMBUSCF_PORTNO_DEFAULT        -1
181
182 #define SCSI_MODE_SENSE         MODE_SENSE
183 #define XS_STS_DONE             ITSDONE
184 #define XS_CTL_POLL             SCSI_POLL
185 #define XS_CTL_DATA_IN          SCSI_DATA_IN
186 #define XS_CTL_DATA_OUT         SCSI_DATA_OUT
187 #define scsipi_adapter          scsi_adapter
188 #define scsipi_cmd              scsi_cmd
189 #define scsipi_device           scsi_device
190 #define scsipi_done             scsi_done
191 #define scsipi_link             scsi_link
192 #define scsipi_minphys          scsi_minphys
193 #define scsipi_sense            scsi_sense
194 #define scsipi_xfer             scsi_xfer
195 #define xs_control              flags
196 #define xs_status               status
197
198 #define memcpy(d, s, l)         bcopy((s),(d),(l))
199 #define memset(d, v, l)         bzero((d),(l))
200 #define bswap32(x)              swap32(x)
201 #define bswap16(x)              swap16(x)
202
203 /*
204  * The UHCI/OHCI controllers are little endian, so on big endian machines
205  * the data strored in memory needs to be swapped.
206  */
207
208 #if defined(letoh32)
209 #define le32toh(x) letoh32(x)
210 #define le16toh(x) letoh16(x)
211 #endif
212
213 #define usb_kthread_create1     kthread_create
214 #define usb_kthread_create      kthread_create_deferred
215
216 #define config_pending_incr()
217 #define config_pending_decr()
218
219 typedef int usb_malloc_type;
220
221 #define Ether_ifattach ether_ifattach
222 #define if_deactivate(x)
223
224 #define usbpoll                 usbselect
225 #define uhidpoll                uhidselect
226 #define ugenpoll                ugenselect
227 #define uscannerpoll            uscannerselect
228
229 #define powerhook_establish(fn, sc) (fn)
230 #define powerhook_disestablish(hdl)
231 #define PWR_RESUME 0
232
233 #define logprintf kprintf
234
235 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
236 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
237 #define change_sign16_le change_sign16
238
239 #define realloc usb_realloc
240 void *usb_realloc(void *, u_int, int, int);
241
242 extern int cold;
243
244 typedef struct device *device_ptr_t;
245 #define USBBASEDEVICE struct device
246 #define USBDEV(bdev) (&(bdev))
247 #define USBDEVNAME(bdev) ((bdev).dv_xname)
248 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
249 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
250 #define USBGETSOFTC(d) ((void *)(d))
251
252 #define DECLARE_USB_DMA_T \
253         struct usb_dma_block; \
254         typedef struct { \
255                 struct usb_dma_block *block; \
256                 u_int offs; \
257         } usb_dma_t
258
259 typedef char usb_callout_t;
260 #define usb_callout_init(h)
261 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
262 #define usb_uncallout(h, f, d) untimeout((f), (d))
263
264 #define USB_DECLARE_DRIVER(dname)  \
265 int __CONCAT(dname,_match)(struct device *, void *, void *); \
266 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
267 int __CONCAT(dname,_detach)(struct device *, int); \
268 int __CONCAT(dname,_activate)(struct device *, enum devact); \
269 \
270 struct cfdriver __CONCAT(dname,_cd) = { \
271         NULL, #dname, DV_DULL \
272 }; \
273 \
274 const struct cfattach __CONCAT(dname,_ca) = { \
275         sizeof(struct __CONCAT(dname,_softc)), \
276         __CONCAT(dname,_match), \
277         __CONCAT(dname,_attach), \
278         __CONCAT(dname,_detach), \
279         __CONCAT(dname,_activate), \
280 }
281
282 #define USB_MATCH(dname) \
283 int \
284 __CONCAT(dname,_match)(parent, match, aux) \
285         struct device *parent; \
286         void *match; \
287         void *aux;
288
289 #define USB_MATCH_START(dname, uaa) \
290         struct usb_attach_arg *uaa = aux
291
292 #define USB_ATTACH(dname) \
293 void \
294 __CONCAT(dname,_attach)(parent, self, aux) \
295         struct device *parent; \
296         struct device *self; \
297         void *aux;
298
299 #define USB_ATTACH_START(dname, sc, uaa) \
300         struct __CONCAT(dname,_softc) *sc = \
301                 (struct __CONCAT(dname,_softc) *)self; \
302         struct usb_attach_arg *uaa = aux
303
304 /* Returns from attach */
305 #define USB_ATTACH_ERROR_RETURN return
306 #define USB_ATTACH_SUCCESS_RETURN       return
307
308 #define USB_ATTACH_SETUP kprintf("\n")
309
310 #define USB_DETACH(dname) \
311 int \
312 __CONCAT(dname,_detach)(self, flags) \
313         struct device *self; \
314         int flags;
315
316 #define USB_DETACH_START(dname, sc) \
317         struct __CONCAT(dname,_softc) *sc = \
318                 (struct __CONCAT(dname,_softc) *)self
319
320 #define USB_GET_SC_OPEN(dname, unit, sc) \
321         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
322                 return (ENXIO); \
323         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
324         if (sc == NULL) \
325                 return (ENXIO)
326
327 #define USB_GET_SC(dname, unit, sc) \
328         sc = __CONCAT(dname,_cd).cd_devs[unit]
329
330 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
331         (config_found_sm(parent, args, print, sub))
332
333 #elif defined(__DragonFly__)
334 /***************************************************************************
335  *                                      DRAGONFLY
336  */
337 #include "opt_usb.h"
338
339 #if defined(_KERNEL)
340 #include <sys/malloc.h>
341
342 MALLOC_DECLARE(M_USB);
343 MALLOC_DECLARE(M_USBDEV);
344 MALLOC_DECLARE(M_USBHC);
345
346 #endif
347
348 #define USBVERBOSE
349
350 /* We don't use the soft interrupt code in FreeBSD. */
351 /* #undef USB_USE_SOFTINTR */
352
353 #define Static static
354
355 #define device_ptr_t device_t
356 #define USBBASEDEVICE device_t
357 #define USBDEV(bdev) (bdev)
358 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
359 #define USBDEVUNIT(bdev) device_get_unit(bdev)
360 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
361 #define USBDEVUNIT(bdev) device_get_unit(bdev)
362 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
363
364 #define DECLARE_USB_DMA_T \
365         struct usb_dma_block; \
366         typedef struct { \
367                 struct usb_dma_block *block; \
368                 u_int offs; \
369                 u_int len; \
370         } usb_dma_t
371
372 #define PROC_LOCK(p)
373 #define PROC_UNLOCK(p)
374 #define uio_procp uio_td
375
376 #define selwakeuppri(p, pri)    selwakeup(p)
377
378 typedef struct thread *usb_proc_ptr;
379
380 /* XXX Change this when FreeBSD has memset */
381 #define memcpy(d, s, l)         bcopy((s),(d),(l))
382 #define memset(d, v, l)         bzero((d),(l))
383
384 #define config_pending_incr()
385 #define config_pending_decr()
386
387 #define usb_kthread_create(f, s)                        \
388                 kthread_create(f, s, NULL, "dummy")
389 #define usb_kthread_create1(f, s, p, name, arg)         \
390                 kthread_create(f, s, p, name, arg)
391 #define usb_kthread_create2(f, s, p, name)              \
392                 kthread_create(f, s, p, name)
393
394 typedef struct callout usb_callout_t;
395 #define usb_callout_init(h)     callout_init(&(h))
396 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
397 #define usb_uncallout(h, f, d)  callout_stop(&(h))
398
399 #define ETHER_ALIGN             2
400
401 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
402 #define clfree(p) clist_free_cblocks((p))
403
404 #define PWR_RESUME 0
405 #define PWR_SUSPEND 1
406
407 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
408
409 typedef struct malloc_type *usb_malloc_type;
410
411 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
412 Static device_probe_t __CONCAT(dname,_match); \
413 Static device_attach_t __CONCAT(dname,_attach); \
414 Static device_detach_t __CONCAT(dname,_detach); \
415 \
416 Static devclass_t __CONCAT(dname,_devclass); \
417 \
418 Static device_method_t __CONCAT(dname,_methods)[] = { \
419         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
420         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
421         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
422         init, \
423         {0,0} \
424 }; \
425 \
426 Static driver_t __CONCAT(dname,_driver) = { \
427         #dname, \
428         __CONCAT(dname,_methods), \
429         sizeof(struct __CONCAT(dname,_softc)) \
430 }; \
431 MODULE_DEPEND(dname, usb, 1, 1, 1)
432
433
434 #define METHODS_NONE                    {0,0}
435 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
436
437 #define USB_MATCH(dname) \
438 Static int \
439 __CONCAT(dname,_match)(device_t self)
440
441 #define USB_MATCH_START(dname, uaa) \
442         struct usb_attach_arg *uaa = device_get_ivars(self)
443
444 #define USB_MATCH_SETUP \
445         sc->sc_dev = self
446
447 #define USB_ATTACH(dname) \
448 Static int \
449 __CONCAT(dname,_attach)(device_t self)
450
451 #define USB_ATTACH_START(dname, sc, uaa) \
452         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
453         struct usb_attach_arg *uaa = device_get_ivars(self)
454
455 /* Returns from attach */
456 #define USB_ATTACH_ERROR_RETURN return ENXIO
457 #define USB_ATTACH_SUCCESS_RETURN       return 0
458
459 #define USB_ATTACH_SETUP \
460         sc->sc_dev = self; \
461         device_set_desc_copy(self, devinfo)
462
463 #define USB_DETACH(dname) \
464 Static int \
465 __CONCAT(dname,_detach)(device_t self)
466
467 #define USB_DETACH_START(dname, sc) \
468         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
469
470 #define USB_GET_SC_OPEN(dname, unit, sc) \
471         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
472         if (sc == NULL) \
473                 return (ENXIO)
474
475 #define USB_GET_SC(dname, unit, sc) \
476         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
477
478 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
479         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
480
481 /* conversion from one type of queue to the other */
482 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
483 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
484 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
485 #define SIMPLEQ_NEXT            STAILQ_NEXT
486 #define SIMPLEQ_FIRST           STAILQ_FIRST
487 #define SIMPLEQ_HEAD            STAILQ_HEAD
488 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
489 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
490 #define SIMPLEQ_INIT            STAILQ_INIT
491 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
492 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
493
494 #include <sys/syslog.h>
495 /*
496 #define logprintf(args...)      log(LOG_DEBUG, args)
497 */
498 #define logprintf               kprintf
499
500 #ifdef SYSCTL_DECL
501 SYSCTL_DECL(_hw_usb);
502 #endif
503
504 #elif defined(__FreeBSD__) || defined(__DragonFly__)
505 /***************************************************************************
506  *                                      FREEBSD
507  */
508
509 #include "opt_usb.h"
510
511 #if defined(_KERNEL)
512 #include <sys/malloc.h>
513
514 MALLOC_DECLARE(M_USB);
515 MALLOC_DECLARE(M_USBDEV);
516 MALLOC_DECLARE(M_USBHC);
517
518 #endif
519
520 #define USBVERBOSE
521
522 /* We don't use the soft interrupt code in FreeBSD. */
523 #if 0
524 #define USB_USE_SOFTINTR
525 #endif
526
527 #define Static static
528
529 #define device_ptr_t device_t
530 #define USBBASEDEVICE device_t
531 #define USBDEV(bdev) (bdev)
532 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
533 #define USBDEVUNIT(bdev) device_get_unit(bdev)
534 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
535 #define USBDEVUNIT(bdev) device_get_unit(bdev)
536 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
537
538 #define DECLARE_USB_DMA_T \
539         struct usb_dma_block; \
540         typedef struct { \
541                 struct usb_dma_block *block; \
542                 u_int offs; \
543                 u_int len; \
544         } usb_dma_t
545
546 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
547 typedef struct thread *usb_proc_ptr;
548
549 #define uio_procp uio_td
550
551 #define usb_kthread_create1(f, s, p, a0, a1) \
552                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
553 #define usb_kthread_create2(f, s, p, a0) \
554                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
555 #define usb_kthread_create      kthread_create
556
557 #define config_pending_incr()
558 #define config_pending_decr()
559
560 typedef struct callout usb_callout_t;
561 #define usb_callout_init(h)     callout_init(&(h), 0)
562 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
563 #define usb_uncallout(h, f, d)  callout_stop(&(h))
564 #else
565 typedef struct proc *usb_proc_ptr;
566
567 #define PROC_LOCK(p)
568 #define PROC_UNLOCK(p)
569
570 #define usb_kthread_create1(f, s, p, a0, a1) \
571                 kthread_create((f), (s), (p), (a0), (a1))
572 #define usb_kthread_create2(f, s, p, a0) \
573                 kthread_create((f), (s), (p), (a0))
574 #define usb_kthread_create      kthread_create
575
576 #define config_pending_incr()
577 #define config_pending_decr()
578
579 typedef struct callout usb_callout_t;
580 #define usb_callout_init(h)     callout_init(&(h))
581 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
582 #define usb_uncallout(h, f, d)  callout_stop(&(h))
583 #endif
584
585 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
586 #define clfree(p) clist_free_cblocks((p))
587
588 #define PWR_RESUME 0
589 #define PWR_SUSPEND 1
590
591 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
592
593 typedef struct malloc_type *usb_malloc_type;
594
595 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
596 Static device_probe_t __CONCAT(dname,_match); \
597 Static device_attach_t __CONCAT(dname,_attach); \
598 Static device_detach_t __CONCAT(dname,_detach); \
599 \
600 Static devclass_t __CONCAT(dname,_devclass); \
601 \
602 Static device_method_t __CONCAT(dname,_methods)[] = { \
603         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
604         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
605         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
606         init, \
607         {0,0} \
608 }; \
609 \
610 Static driver_t __CONCAT(dname,_driver) = { \
611         #dname, \
612         __CONCAT(dname,_methods), \
613         sizeof(struct __CONCAT(dname,_softc)) \
614 }; \
615 MODULE_DEPEND(dname, usb, 1, 1, 1)
616
617
618 #define METHODS_NONE                    {0,0}
619 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
620
621 #define USB_MATCH(dname) \
622 Static int \
623 __CONCAT(dname,_match)(device_t self)
624
625 #define USB_MATCH_START(dname, uaa) \
626         struct usb_attach_arg *uaa = device_get_ivars(self)
627
628 #define USB_MATCH_SETUP \
629         sc->sc_dev = self
630
631 #define USB_ATTACH(dname) \
632 Static int \
633 __CONCAT(dname,_attach)(device_t self)
634
635 #define USB_ATTACH_START(dname, sc, uaa) \
636         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
637         struct usb_attach_arg *uaa = device_get_ivars(self)
638
639 /* Returns from attach */
640 #define USB_ATTACH_ERROR_RETURN return ENXIO
641 #define USB_ATTACH_SUCCESS_RETURN       return 0
642
643 #define USB_ATTACH_SETUP \
644         sc->sc_dev = self; \
645         device_set_desc_copy(self, devinfo)
646
647 #define USB_DETACH(dname) \
648 Static int \
649 __CONCAT(dname,_detach)(device_t self)
650
651 #define USB_DETACH_START(dname, sc) \
652         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
653
654 #define USB_GET_SC_OPEN(dname, unit, sc) \
655         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
656         if (sc == NULL) \
657                 return (ENXIO)
658
659 #define USB_GET_SC(dname, unit, sc) \
660         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
661
662 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
663         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
664
665 /* conversion from one type of queue to the other */
666 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
667 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
668 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
669 #define SIMPLEQ_NEXT            STAILQ_NEXT
670 #define SIMPLEQ_FIRST           STAILQ_FIRST
671 #define SIMPLEQ_HEAD            STAILQ_HEAD
672 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
673 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
674 #define SIMPLEQ_INIT            STAILQ_INIT
675 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
676 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
677
678 #include <sys/syslog.h>
679 /*
680 #define logprintf(args...)      log(LOG_DEBUG, args)
681 */
682 #define logprintf               kprintf
683
684 #ifdef SYSCTL_DECL
685 SYSCTL_DECL(_hw_usb);
686 #endif
687
688 #endif /* __FreeBSD__ */
689
690 #endif /* _USB_PORT_H */
691