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