Merge from vendor branch GPERF:
[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.54 2002/03/28 21:49:19 ichiro 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.12 2005/01/23 20:21:30 joerg 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 #define USB_USE_SOFTINTR
65
66 #ifdef USB_DEBUG
67 #define Static
68 #else
69 #define Static static
70 #endif
71
72 #define SCSI_MODE_SENSE         MODE_SENSE
73
74 typedef struct proc *usb_proc_ptr;
75
76 typedef struct device *device_ptr_t;
77 #define USBBASEDEVICE struct device
78 #define USBDEV(bdev) (&(bdev))
79 #define USBDEVNAME(bdev) ((bdev).dv_xname)
80 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
81 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
82 #define USBGETSOFTC(d) ((void *)(d))
83
84 #define DECLARE_USB_DMA_T \
85         struct usb_dma_block; \
86         typedef struct { \
87                 struct usb_dma_block *block; \
88                 u_int offs; \
89         } usb_dma_t
90
91 typedef struct callout usb_callout_t;
92 #define usb_callout_init(h)     callout_init(&(h))
93 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
94 #define usb_uncallout(h, f, d)  callout_stop(&(h))
95
96 #define usb_kthread_create1     kthread_create1
97 #define usb_kthread_create      kthread_create
98
99 typedef int usb_malloc_type;
100
101 #define Ether_ifattach ether_ifattach
102 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
103
104 #define logprintf printf
105
106 #define USB_DNAME(dname)        dname
107 #define USB_DECLARE_DRIVER(dname)  \
108 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
109 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
110 int __CONCAT(dname,_detach)(struct device *, int); \
111 int __CONCAT(dname,_activate)(struct device *, enum devact); \
112 \
113 extern struct cfdriver __CONCAT(dname,_cd); \
114 \
115 CFATTACH_DECL(USB_DNAME(dname), \
116     sizeof(struct ___CONCAT(dname,_softc)), \
117     ___CONCAT(dname,_match), \
118     ___CONCAT(dname,_attach), \
119     ___CONCAT(dname,_detach), \
120     ___CONCAT(dname,_activate))
121
122 #define USB_MATCH(dname) \
123 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
124
125 #define USB_MATCH_START(dname, uaa) \
126         struct usb_attach_arg *uaa = aux
127
128 #define USB_ATTACH(dname) \
129 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
130
131 #define USB_ATTACH_START(dname, sc, uaa) \
132         struct __CONCAT(dname,_softc) *sc = \
133                 (struct __CONCAT(dname,_softc) *)self; \
134         struct usb_attach_arg *uaa = aux
135
136 /* Returns from attach */
137 #define USB_ATTACH_ERROR_RETURN return
138 #define USB_ATTACH_SUCCESS_RETURN       return
139
140 #define USB_ATTACH_SETUP printf("\n")
141
142 #define USB_DETACH(dname) \
143 int __CONCAT(dname,_detach)(struct device *self, int flags)
144
145 #define USB_DETACH_START(dname, sc) \
146         struct __CONCAT(dname,_softc) *sc = \
147                 (struct __CONCAT(dname,_softc) *)self
148
149 #define USB_GET_SC_OPEN(dname, unit, sc) \
150         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
151                 return (ENXIO); \
152         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
153         if (sc == NULL) \
154                 return (ENXIO)
155
156 #define USB_GET_SC(dname, unit, sc) \
157         sc = __CONCAT(dname,_cd).cd_devs[unit]
158
159 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
160         (config_found_sm(parent, args, print, sub))
161
162 #elif defined(__OpenBSD__)
163 /*
164  * OpenBSD
165  */
166 #define Static
167
168 typedef struct proc *usb_proc_ptr;
169
170 #define UCOMBUSCF_PORTNO                -1
171 #define UCOMBUSCF_PORTNO_DEFAULT        -1
172
173 #define SCSI_MODE_SENSE         MODE_SENSE
174 #define XS_STS_DONE             ITSDONE
175 #define XS_CTL_POLL             SCSI_POLL
176 #define XS_CTL_DATA_IN          SCSI_DATA_IN
177 #define XS_CTL_DATA_OUT         SCSI_DATA_OUT
178 #define scsipi_adapter          scsi_adapter
179 #define scsipi_cmd              scsi_cmd
180 #define scsipi_device           scsi_device
181 #define scsipi_done             scsi_done
182 #define scsipi_link             scsi_link
183 #define scsipi_minphys          scsi_minphys
184 #define scsipi_sense            scsi_sense
185 #define scsipi_xfer             scsi_xfer
186 #define xs_control              flags
187 #define xs_status               status
188
189 #define memcpy(d, s, l)         bcopy((s),(d),(l))
190 #define memset(d, v, l)         bzero((d),(l))
191 #define bswap32(x)              swap32(x)
192 #define bswap16(x)              swap16(x)
193
194 /*
195  * The UHCI/OHCI controllers are little endian, so on big endian machines
196  * the data strored in memory needs to be swapped.
197  */
198
199 #if defined(letoh32)
200 #define le32toh(x) letoh32(x)
201 #define le16toh(x) letoh16(x)
202 #endif
203
204 #define usb_kthread_create1     kthread_create
205 #define usb_kthread_create      kthread_create_deferred
206
207 #define config_pending_incr()
208 #define config_pending_decr()
209
210 typedef int usb_malloc_type;
211
212 #define Ether_ifattach ether_ifattach
213 #define if_deactivate(x)
214 #define IF_INPUT(ifp, m) (*(ifp)->if_input)(ifp, m)
215
216 #define usbpoll                 usbselect
217 #define uhidpoll                uhidselect
218 #define ugenpoll                ugenselect
219 #define uriopoll                urioselect
220 #define uscannerpoll            uscannerselect
221
222 #define powerhook_establish(fn, sc) (fn)
223 #define powerhook_disestablish(hdl)
224 #define PWR_RESUME 0
225
226 #define logprintf printf
227
228 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
229 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
230 #define change_sign16_le change_sign16
231
232 #define realloc usb_realloc
233 void *usb_realloc(void *, u_int, int, int);
234
235 extern int cold;
236
237 typedef struct device *device_ptr_t;
238 #define USBBASEDEVICE struct device
239 #define USBDEV(bdev) (&(bdev))
240 #define USBDEVNAME(bdev) ((bdev).dv_xname)
241 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
242 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
243 #define USBGETSOFTC(d) ((void *)(d))
244
245 #define DECLARE_USB_DMA_T \
246         struct usb_dma_block; \
247         typedef struct { \
248                 struct usb_dma_block *block; \
249                 u_int offs; \
250         } usb_dma_t
251
252 typedef char usb_callout_t;
253 #define usb_callout_init(h)
254 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
255 #define usb_uncallout(h, f, d) untimeout((f), (d))
256
257 #define USB_DECLARE_DRIVER(dname)  \
258 int __CONCAT(dname,_match)(struct device *, void *, void *); \
259 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
260 int __CONCAT(dname,_detach)(struct device *, int); \
261 int __CONCAT(dname,_activate)(struct device *, enum devact); \
262 \
263 struct cfdriver __CONCAT(dname,_cd) = { \
264         NULL, #dname, DV_DULL \
265 }; \
266 \
267 const struct cfattach __CONCAT(dname,_ca) = { \
268         sizeof(struct __CONCAT(dname,_softc)), \
269         __CONCAT(dname,_match), \
270         __CONCAT(dname,_attach), \
271         __CONCAT(dname,_detach), \
272         __CONCAT(dname,_activate), \
273 }
274
275 #define USB_MATCH(dname) \
276 int \
277 __CONCAT(dname,_match)(parent, match, aux) \
278         struct device *parent; \
279         void *match; \
280         void *aux;
281
282 #define USB_MATCH_START(dname, uaa) \
283         struct usb_attach_arg *uaa = aux
284
285 #define USB_ATTACH(dname) \
286 void \
287 __CONCAT(dname,_attach)(parent, self, aux) \
288         struct device *parent; \
289         struct device *self; \
290         void *aux;
291
292 #define USB_ATTACH_START(dname, sc, uaa) \
293         struct __CONCAT(dname,_softc) *sc = \
294                 (struct __CONCAT(dname,_softc) *)self; \
295         struct usb_attach_arg *uaa = aux
296
297 /* Returns from attach */
298 #define USB_ATTACH_ERROR_RETURN return
299 #define USB_ATTACH_SUCCESS_RETURN       return
300
301 #define USB_ATTACH_SETUP printf("\n")
302
303 #define USB_DETACH(dname) \
304 int \
305 __CONCAT(dname,_detach)(self, flags) \
306         struct device *self; \
307         int flags;
308
309 #define USB_DETACH_START(dname, sc) \
310         struct __CONCAT(dname,_softc) *sc = \
311                 (struct __CONCAT(dname,_softc) *)self
312
313 #define USB_GET_SC_OPEN(dname, unit, sc) \
314         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
315                 return (ENXIO); \
316         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
317         if (sc == NULL) \
318                 return (ENXIO)
319
320 #define USB_GET_SC(dname, unit, sc) \
321         sc = __CONCAT(dname,_cd).cd_devs[unit]
322
323 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
324         (config_found_sm(parent, args, print, sub))
325
326 #elif defined(__DragonFly__)
327 /***************************************************************************
328  *                                      DRAGONFLY
329  */
330 #include "opt_usb.h"
331
332 #if defined(_KERNEL)
333 #include <sys/malloc.h>
334
335 MALLOC_DECLARE(M_USB);
336 MALLOC_DECLARE(M_USBDEV);
337 MALLOC_DECLARE(M_USBHC);
338
339 #endif
340
341 #define USBVERBOSE
342
343 /* We don't use the soft interrupt code in FreeBSD. */
344 /* #undef USB_USE_SOFTINTR */
345
346 #define Static static
347
348 #define device_ptr_t device_t
349 #define USBBASEDEVICE device_t
350 #define USBDEV(bdev) (bdev)
351 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
352 #define USBDEVUNIT(bdev) device_get_unit(bdev)
353 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
354 #define USBDEVUNIT(bdev) device_get_unit(bdev)
355 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
356
357 #define DECLARE_USB_DMA_T \
358         struct usb_dma_block; \
359         typedef struct { \
360                 struct usb_dma_block *block; \
361                 u_int offs; \
362                 u_int len; \
363         } usb_dma_t
364
365 #define PROC_LOCK(p)
366 #define PROC_UNLOCK(p)
367 #define uio_procp uio_td
368
369 #define selwakeuppri(p, pri)    selwakeup(p)
370
371 typedef struct thread *usb_proc_ptr;
372
373 /* XXX Change this when FreeBSD has memset */
374 #define memcpy(d, s, l)         bcopy((s),(d),(l))
375 #define memset(d, v, l)         bzero((d),(l))
376
377 #define config_pending_incr()
378 #define config_pending_decr()
379
380 #define usb_kthread_create(f, s)                        \
381                 kthread_create(f, s, NULL, "dummy")
382 #define usb_kthread_create1(f, s, p, name, arg)         \
383                 kthread_create(f, s, p, name, arg)
384 #define usb_kthread_create2(f, s, p, name)              \
385                 kthread_create(f, s, p, name)
386
387 typedef struct callout usb_callout_t;
388 #define usb_callout_init(h)     callout_init(&(h))
389 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
390 #define usb_uncallout(h, f, d)  callout_stop(&(h))
391
392 #define ETHER_ALIGN             2
393
394 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
395 #define clfree(p) clist_free_cblocks((p))
396
397 #define PWR_RESUME 0
398 #define PWR_SUSPEND 1
399
400 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
401
402 typedef struct malloc_type *usb_malloc_type;
403
404 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
405 Static device_probe_t __CONCAT(dname,_match); \
406 Static device_attach_t __CONCAT(dname,_attach); \
407 Static device_detach_t __CONCAT(dname,_detach); \
408 \
409 Static devclass_t __CONCAT(dname,_devclass); \
410 \
411 Static device_method_t __CONCAT(dname,_methods)[] = { \
412         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
413         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
414         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
415         init, \
416         {0,0} \
417 }; \
418 \
419 Static driver_t __CONCAT(dname,_driver) = { \
420         #dname, \
421         __CONCAT(dname,_methods), \
422         sizeof(struct __CONCAT(dname,_softc)) \
423 }; \
424 MODULE_DEPEND(dname, usb, 1, 1, 1)
425
426
427 #define METHODS_NONE                    {0,0}
428 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
429
430 #define USB_MATCH(dname) \
431 Static int \
432 __CONCAT(dname,_match)(device_t self)
433
434 #define USB_MATCH_START(dname, uaa) \
435         struct usb_attach_arg *uaa = device_get_ivars(self)
436
437 #define USB_MATCH_SETUP \
438         sc->sc_dev = self
439
440 #define USB_ATTACH(dname) \
441 Static int \
442 __CONCAT(dname,_attach)(device_t self)
443
444 #define USB_ATTACH_START(dname, sc, uaa) \
445         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
446         struct usb_attach_arg *uaa = device_get_ivars(self)
447
448 /* Returns from attach */
449 #define USB_ATTACH_ERROR_RETURN return ENXIO
450 #define USB_ATTACH_SUCCESS_RETURN       return 0
451
452 #define USB_ATTACH_SETUP \
453         sc->sc_dev = self; \
454         device_set_desc_copy(self, devinfo)
455
456 #define USB_DETACH(dname) \
457 Static int \
458 __CONCAT(dname,_detach)(device_t self)
459
460 #define USB_DETACH_START(dname, sc) \
461         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
462
463 #define USB_GET_SC_OPEN(dname, unit, sc) \
464         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
465         if (sc == NULL) \
466                 return (ENXIO)
467
468 #define USB_GET_SC(dname, unit, sc) \
469         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
470
471 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
472         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
473
474 /* conversion from one type of queue to the other */
475 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
476 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
477 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
478 #define SIMPLEQ_NEXT            STAILQ_NEXT
479 #define SIMPLEQ_FIRST           STAILQ_FIRST
480 #define SIMPLEQ_HEAD            STAILQ_HEAD
481 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
482 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
483 #define SIMPLEQ_INIT            STAILQ_INIT
484 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
485 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
486
487 #include <sys/syslog.h>
488 /*
489 #define logprintf(args...)      log(LOG_DEBUG, args)
490 */
491 #define logprintf               printf
492
493 #ifdef SYSCTL_DECL
494 SYSCTL_DECL(_hw_usb);
495 #endif
496
497 #elif defined(__FreeBSD__) || defined(__DragonFly__)
498 /***************************************************************************
499  *                                      FREEBSD
500  */
501
502 #include "opt_usb.h"
503
504 #if defined(_KERNEL)
505 #include <sys/malloc.h>
506
507 MALLOC_DECLARE(M_USB);
508 MALLOC_DECLARE(M_USBDEV);
509 MALLOC_DECLARE(M_USBHC);
510
511 #endif
512
513 #define USBVERBOSE
514
515 /* We don't use the soft interrupt code in FreeBSD. */
516 #if 0
517 #define USB_USE_SOFTINTR
518 #endif
519
520 #define Static static
521
522 #define device_ptr_t device_t
523 #define USBBASEDEVICE device_t
524 #define USBDEV(bdev) (bdev)
525 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
526 #define USBDEVUNIT(bdev) device_get_unit(bdev)
527 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
528 #define USBDEVUNIT(bdev) device_get_unit(bdev)
529 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
530
531 #define DECLARE_USB_DMA_T \
532         struct usb_dma_block; \
533         typedef struct { \
534                 struct usb_dma_block *block; \
535                 u_int offs; \
536                 u_int len; \
537         } usb_dma_t
538
539 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
540 typedef struct thread *usb_proc_ptr;
541
542 #define uio_procp uio_td
543
544 #define usb_kthread_create1(f, s, p, a0, a1) \
545                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
546 #define usb_kthread_create2(f, s, p, a0) \
547                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
548 #define usb_kthread_create      kthread_create
549
550 #define config_pending_incr()
551 #define config_pending_decr()
552
553 typedef struct callout usb_callout_t;
554 #define usb_callout_init(h)     callout_init(&(h), 0)
555 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
556 #define usb_uncallout(h, f, d)  callout_stop(&(h))
557 #else
558 typedef struct proc *usb_proc_ptr;
559
560 #define PROC_LOCK(p)
561 #define PROC_UNLOCK(p)
562
563 #define usb_kthread_create1(f, s, p, a0, a1) \
564                 kthread_create((f), (s), (p), (a0), (a1))
565 #define usb_kthread_create2(f, s, p, a0) \
566                 kthread_create((f), (s), (p), (a0))
567 #define usb_kthread_create      kthread_create
568
569 #define config_pending_incr()
570 #define config_pending_decr()
571
572 typedef struct callout usb_callout_t;
573 #define usb_callout_init(h)     callout_init(&(h))
574 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
575 #define usb_uncallout(h, f, d)  callout_stop(&(h))
576 #endif
577
578 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
579 #define clfree(p) clist_free_cblocks((p))
580
581 #define PWR_RESUME 0
582 #define PWR_SUSPEND 1
583
584 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
585
586 typedef struct malloc_type *usb_malloc_type;
587
588 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
589 Static device_probe_t __CONCAT(dname,_match); \
590 Static device_attach_t __CONCAT(dname,_attach); \
591 Static device_detach_t __CONCAT(dname,_detach); \
592 \
593 Static devclass_t __CONCAT(dname,_devclass); \
594 \
595 Static device_method_t __CONCAT(dname,_methods)[] = { \
596         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
597         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
598         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
599         init, \
600         {0,0} \
601 }; \
602 \
603 Static driver_t __CONCAT(dname,_driver) = { \
604         #dname, \
605         __CONCAT(dname,_methods), \
606         sizeof(struct __CONCAT(dname,_softc)) \
607 }; \
608 MODULE_DEPEND(dname, usb, 1, 1, 1)
609
610
611 #define METHODS_NONE                    {0,0}
612 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
613
614 #define USB_MATCH(dname) \
615 Static int \
616 __CONCAT(dname,_match)(device_t self)
617
618 #define USB_MATCH_START(dname, uaa) \
619         struct usb_attach_arg *uaa = device_get_ivars(self)
620
621 #define USB_MATCH_SETUP \
622         sc->sc_dev = self
623
624 #define USB_ATTACH(dname) \
625 Static int \
626 __CONCAT(dname,_attach)(device_t self)
627
628 #define USB_ATTACH_START(dname, sc, uaa) \
629         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
630         struct usb_attach_arg *uaa = device_get_ivars(self)
631
632 /* Returns from attach */
633 #define USB_ATTACH_ERROR_RETURN return ENXIO
634 #define USB_ATTACH_SUCCESS_RETURN       return 0
635
636 #define USB_ATTACH_SETUP \
637         sc->sc_dev = self; \
638         device_set_desc_copy(self, devinfo)
639
640 #define USB_DETACH(dname) \
641 Static int \
642 __CONCAT(dname,_detach)(device_t self)
643
644 #define USB_DETACH_START(dname, sc) \
645         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
646
647 #define USB_GET_SC_OPEN(dname, unit, sc) \
648         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
649         if (sc == NULL) \
650                 return (ENXIO)
651
652 #define USB_GET_SC(dname, unit, sc) \
653         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
654
655 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
656         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
657
658 /* conversion from one type of queue to the other */
659 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
660 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
661 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
662 #define SIMPLEQ_NEXT            STAILQ_NEXT
663 #define SIMPLEQ_FIRST           STAILQ_FIRST
664 #define SIMPLEQ_HEAD            STAILQ_HEAD
665 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
666 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
667 #define SIMPLEQ_INIT            STAILQ_INIT
668 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
669 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
670
671 #include <sys/syslog.h>
672 /*
673 #define logprintf(args...)      log(LOG_DEBUG, args)
674 */
675 #define logprintf               printf
676
677 #ifdef SYSCTL_DECL
678 SYSCTL_DECL(_hw_usb);
679 #endif
680
681 #endif /* __FreeBSD__ */
682
683 #endif /* _USB_PORT_H */
684