1ed84daf9a1e6b4842d9455cf86397146db6995b
[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.9 2004/07/23 07:16:24 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 #define bswap32(x)              swap32(x)
377
378 #define config_pending_incr()
379 #define config_pending_decr()
380
381 #define usb_kthread_create(f, s)                        \
382                 kthread_create(f, s, NULL, "dummy")
383 #define usb_kthread_create1(f, s, p, name, arg)         \
384                 kthread_create(f, s, p, name, arg)
385 #define usb_kthread_create2(f, s, p, name)              \
386                 kthread_create(f, s, p, name)
387
388 typedef struct callout usb_callout_t;
389 #define usb_callout_init(h)     callout_init(&(h))
390 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
391 #define usb_uncallout(h, f, d)  callout_stop(&(h))
392
393 #define ETHER_ALIGN             2
394
395 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
396 #define clfree(p) clist_free_cblocks((p))
397
398 #define PWR_RESUME 0
399 #define PWR_SUSPEND 1
400
401 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
402
403 typedef struct malloc_type *usb_malloc_type;
404
405 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
406 Static device_probe_t __CONCAT(dname,_match); \
407 Static device_attach_t __CONCAT(dname,_attach); \
408 Static device_detach_t __CONCAT(dname,_detach); \
409 \
410 Static devclass_t __CONCAT(dname,_devclass); \
411 \
412 Static device_method_t __CONCAT(dname,_methods)[] = { \
413         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
414         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
415         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
416         init, \
417         {0,0} \
418 }; \
419 \
420 Static driver_t __CONCAT(dname,_driver) = { \
421         #dname, \
422         __CONCAT(dname,_methods), \
423         sizeof(struct __CONCAT(dname,_softc)) \
424 }; \
425 MODULE_DEPEND(dname, usb, 1, 1, 1)
426
427
428 #define METHODS_NONE                    {0,0}
429 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
430
431 #define USB_MATCH(dname) \
432 Static int \
433 __CONCAT(dname,_match)(device_t self)
434
435 #define USB_MATCH_START(dname, uaa) \
436         struct usb_attach_arg *uaa = device_get_ivars(self)
437
438 #define USB_MATCH_SETUP \
439         sc->sc_dev = self
440
441 #define USB_ATTACH(dname) \
442 Static int \
443 __CONCAT(dname,_attach)(device_t self)
444
445 #define USB_ATTACH_START(dname, sc, uaa) \
446         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
447         struct usb_attach_arg *uaa = device_get_ivars(self)
448
449 /* Returns from attach */
450 #define USB_ATTACH_ERROR_RETURN return ENXIO
451 #define USB_ATTACH_SUCCESS_RETURN       return 0
452
453 #define USB_ATTACH_SETUP \
454         sc->sc_dev = self; \
455         device_set_desc_copy(self, devinfo)
456
457 #define USB_DETACH(dname) \
458 Static int \
459 __CONCAT(dname,_detach)(device_t self)
460
461 #define USB_DETACH_START(dname, sc) \
462         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
463
464 #define USB_GET_SC_OPEN(dname, unit, sc) \
465         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
466         if (sc == NULL) \
467                 return (ENXIO)
468
469 #define USB_GET_SC(dname, unit, sc) \
470         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
471
472 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
473         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
474
475 /* conversion from one type of queue to the other */
476 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
477 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
478 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
479 #define SIMPLEQ_NEXT            STAILQ_NEXT
480 #define SIMPLEQ_FIRST           STAILQ_FIRST
481 #define SIMPLEQ_HEAD            STAILQ_HEAD
482 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
483 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
484 #define SIMPLEQ_INIT            STAILQ_INIT
485 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
486 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
487
488 #include <sys/syslog.h>
489 /*
490 #define logprintf(args...)      log(LOG_DEBUG, args)
491 */
492 #define logprintf               printf
493
494 #ifdef SYSCTL_DECL
495 SYSCTL_DECL(_hw_usb);
496 #endif
497
498 #elif defined(__FreeBSD__) || defined(__DragonFly__)
499 /***************************************************************************
500  *                                      FREEBSD
501  */
502
503 #include "opt_usb.h"
504
505 #if defined(_KERNEL)
506 #include <sys/malloc.h>
507
508 MALLOC_DECLARE(M_USB);
509 MALLOC_DECLARE(M_USBDEV);
510 MALLOC_DECLARE(M_USBHC);
511
512 #endif
513
514 #define USBVERBOSE
515
516 /* We don't use the soft interrupt code in FreeBSD. */
517 #if 0
518 #define USB_USE_SOFTINTR
519 #endif
520
521 #define Static static
522
523 #define device_ptr_t device_t
524 #define USBBASEDEVICE device_t
525 #define USBDEV(bdev) (bdev)
526 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
527 #define USBDEVUNIT(bdev) device_get_unit(bdev)
528 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
529 #define USBDEVUNIT(bdev) device_get_unit(bdev)
530 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
531
532 #define DECLARE_USB_DMA_T \
533         struct usb_dma_block; \
534         typedef struct { \
535                 struct usb_dma_block *block; \
536                 u_int offs; \
537                 u_int len; \
538         } usb_dma_t
539
540 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
541 typedef struct thread *usb_proc_ptr;
542
543 #define uio_procp uio_td
544
545 #define usb_kthread_create1(f, s, p, a0, a1) \
546                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
547 #define usb_kthread_create2(f, s, p, a0) \
548                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
549 #define usb_kthread_create      kthread_create
550
551 #define config_pending_incr()
552 #define config_pending_decr()
553
554 typedef struct callout usb_callout_t;
555 #define usb_callout_init(h)     callout_init(&(h), 0)
556 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
557 #define usb_uncallout(h, f, d)  callout_stop(&(h))
558 #else
559 typedef struct proc *usb_proc_ptr;
560
561 #define PROC_LOCK(p)
562 #define PROC_UNLOCK(p)
563
564 #define usb_kthread_create1(f, s, p, a0, a1) \
565                 kthread_create((f), (s), (p), (a0), (a1))
566 #define usb_kthread_create2(f, s, p, a0) \
567                 kthread_create((f), (s), (p), (a0))
568 #define usb_kthread_create      kthread_create
569
570 #define config_pending_incr()
571 #define config_pending_decr()
572
573 typedef struct callout usb_callout_t;
574 #define usb_callout_init(h)     callout_init(&(h))
575 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
576 #define usb_uncallout(h, f, d)  callout_stop(&(h))
577
578 #define BUS_DMA_COHERENT        0
579 #define ETHER_ALIGN             2
580 #define BPF_MTAP(ifp, m)        if ((ifp)->if_bpf) bpf_mtap((ifp), (m));
581 #endif
582
583 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
584 #define clfree(p) clist_free_cblocks((p))
585
586 #define PWR_RESUME 0
587 #define PWR_SUSPEND 1
588
589 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
590
591 typedef struct malloc_type *usb_malloc_type;
592
593 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
594 Static device_probe_t __CONCAT(dname,_match); \
595 Static device_attach_t __CONCAT(dname,_attach); \
596 Static device_detach_t __CONCAT(dname,_detach); \
597 \
598 Static devclass_t __CONCAT(dname,_devclass); \
599 \
600 Static device_method_t __CONCAT(dname,_methods)[] = { \
601         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
602         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
603         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
604         init, \
605         {0,0} \
606 }; \
607 \
608 Static driver_t __CONCAT(dname,_driver) = { \
609         #dname, \
610         __CONCAT(dname,_methods), \
611         sizeof(struct __CONCAT(dname,_softc)) \
612 }; \
613 MODULE_DEPEND(dname, usb, 1, 1, 1)
614
615
616 #define METHODS_NONE                    {0,0}
617 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
618
619 #define USB_MATCH(dname) \
620 Static int \
621 __CONCAT(dname,_match)(device_t self)
622
623 #define USB_MATCH_START(dname, uaa) \
624         struct usb_attach_arg *uaa = device_get_ivars(self)
625
626 #define USB_MATCH_SETUP \
627         sc->sc_dev = self
628
629 #define USB_ATTACH(dname) \
630 Static int \
631 __CONCAT(dname,_attach)(device_t self)
632
633 #define USB_ATTACH_START(dname, sc, uaa) \
634         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
635         struct usb_attach_arg *uaa = device_get_ivars(self)
636
637 /* Returns from attach */
638 #define USB_ATTACH_ERROR_RETURN return ENXIO
639 #define USB_ATTACH_SUCCESS_RETURN       return 0
640
641 #define USB_ATTACH_SETUP \
642         sc->sc_dev = self; \
643         device_set_desc_copy(self, devinfo)
644
645 #define USB_DETACH(dname) \
646 Static int \
647 __CONCAT(dname,_detach)(device_t self)
648
649 #define USB_DETACH_START(dname, sc) \
650         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
651
652 #define USB_GET_SC_OPEN(dname, unit, sc) \
653         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
654         if (sc == NULL) \
655                 return (ENXIO)
656
657 #define USB_GET_SC(dname, unit, sc) \
658         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
659
660 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
661         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
662
663 /* conversion from one type of queue to the other */
664 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
665 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
666 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
667 #define SIMPLEQ_NEXT            STAILQ_NEXT
668 #define SIMPLEQ_FIRST           STAILQ_FIRST
669 #define SIMPLEQ_HEAD            STAILQ_HEAD
670 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
671 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
672 #define SIMPLEQ_INIT            STAILQ_INIT
673 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
674 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
675
676 #include <sys/syslog.h>
677 /*
678 #define logprintf(args...)      log(LOG_DEBUG, args)
679 */
680 #define logprintf               printf
681
682 #ifdef SYSCTL_DECL
683 SYSCTL_DECL(_hw_usb);
684 #endif
685
686 #endif /* __FreeBSD__ */
687
688 #endif /* _USB_PORT_H */
689