Bring in the entire FreeBSD-5 USB infrastructure. As of this commit my
[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.5 2003/12/30 01:01:44 dillon 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(ifp, eaddr) ether_ifattach(ifp)
213 #define if_deactivate(x)
214 #define IF_INPUT(ifp, m) do {                                           \
215         struct ether_header *eh;                                        \
216                                                                         \
217         eh = mtod(m, struct ether_header *);                            \
218         m_adj(m, sizeof(struct ether_header));                          \
219         ether_input((ifp), (eh), (m));                                  \
220 } while (0)
221
222 #define usbpoll                 usbselect
223 #define uhidpoll                uhidselect
224 #define ugenpoll                ugenselect
225 #define uriopoll                urioselect
226 #define uscannerpoll            uscannerselect
227
228 #define powerhook_establish(fn, sc) (fn)
229 #define powerhook_disestablish(hdl)
230 #define PWR_RESUME 0
231
232 #define logprintf printf
233
234 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
235 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
236 #define change_sign16_le change_sign16
237
238 #define realloc usb_realloc
239 void *usb_realloc(void *, u_int, int, int);
240
241 extern int cold;
242
243 typedef struct device *device_ptr_t;
244 #define USBBASEDEVICE struct device
245 #define USBDEV(bdev) (&(bdev))
246 #define USBDEVNAME(bdev) ((bdev).dv_xname)
247 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
248 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
249 #define USBGETSOFTC(d) ((void *)(d))
250
251 #define DECLARE_USB_DMA_T \
252         struct usb_dma_block; \
253         typedef struct { \
254                 struct usb_dma_block *block; \
255                 u_int offs; \
256         } usb_dma_t
257
258 typedef char usb_callout_t;
259 #define usb_callout_init(h)
260 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
261 #define usb_uncallout(h, f, d) untimeout((f), (d))
262
263 #define USB_DECLARE_DRIVER(dname)  \
264 int __CONCAT(dname,_match)(struct device *, void *, void *); \
265 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
266 int __CONCAT(dname,_detach)(struct device *, int); \
267 int __CONCAT(dname,_activate)(struct device *, enum devact); \
268 \
269 struct cfdriver __CONCAT(dname,_cd) = { \
270         NULL, #dname, DV_DULL \
271 }; \
272 \
273 const struct cfattach __CONCAT(dname,_ca) = { \
274         sizeof(struct __CONCAT(dname,_softc)), \
275         __CONCAT(dname,_match), \
276         __CONCAT(dname,_attach), \
277         __CONCAT(dname,_detach), \
278         __CONCAT(dname,_activate), \
279 }
280
281 #define USB_MATCH(dname) \
282 int \
283 __CONCAT(dname,_match)(parent, match, aux) \
284         struct device *parent; \
285         void *match; \
286         void *aux;
287
288 #define USB_MATCH_START(dname, uaa) \
289         struct usb_attach_arg *uaa = aux
290
291 #define USB_ATTACH(dname) \
292 void \
293 __CONCAT(dname,_attach)(parent, self, aux) \
294         struct device *parent; \
295         struct device *self; \
296         void *aux;
297
298 #define USB_ATTACH_START(dname, sc, uaa) \
299         struct __CONCAT(dname,_softc) *sc = \
300                 (struct __CONCAT(dname,_softc) *)self; \
301         struct usb_attach_arg *uaa = aux
302
303 /* Returns from attach */
304 #define USB_ATTACH_ERROR_RETURN return
305 #define USB_ATTACH_SUCCESS_RETURN       return
306
307 #define USB_ATTACH_SETUP printf("\n")
308
309 #define USB_DETACH(dname) \
310 int \
311 __CONCAT(dname,_detach)(self, flags) \
312         struct device *self; \
313         int flags;
314
315 #define USB_DETACH_START(dname, sc) \
316         struct __CONCAT(dname,_softc) *sc = \
317                 (struct __CONCAT(dname,_softc) *)self
318
319 #define USB_GET_SC_OPEN(dname, unit, sc) \
320         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
321                 return (ENXIO); \
322         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
323         if (sc == NULL) \
324                 return (ENXIO)
325
326 #define USB_GET_SC(dname, unit, sc) \
327         sc = __CONCAT(dname,_cd).cd_devs[unit]
328
329 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
330         (config_found_sm(parent, args, print, sub))
331
332 #elif defined(__DragonFly__)
333 /***************************************************************************
334  *                                      DRAGONFLY
335  */
336 #include "opt_usb.h"
337
338 #if defined(_KERNEL)
339 #include <sys/malloc.h>
340
341 MALLOC_DECLARE(M_USB);
342 MALLOC_DECLARE(M_USBDEV);
343 MALLOC_DECLARE(M_USBHC);
344
345 #endif
346
347 #define USBVERBOSE
348
349 /* We don't use the soft interrupt code in FreeBSD. */
350 /* #undef USB_USE_SOFTINTR */
351
352 #define Static static
353
354 #define device_ptr_t device_t
355 #define USBBASEDEVICE device_t
356 #define USBDEV(bdev) (bdev)
357 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
358 #define USBDEVUNIT(bdev) device_get_unit(bdev)
359 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
360 #define USBDEVUNIT(bdev) device_get_unit(bdev)
361 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
362
363 #define DECLARE_USB_DMA_T \
364         struct usb_dma_block; \
365         typedef struct { \
366                 struct usb_dma_block *block; \
367                 u_int offs; \
368                 u_int len; \
369         } usb_dma_t
370
371 #define PROC_LOCK(p)
372 #define PROC_UNLOCK(p)
373 #define uio_procp uio_td
374
375 #define selwakeuppri(p, pri)    selwakeup(p)
376
377 typedef struct thread *usb_proc_ptr;
378
379 /* XXX Change this when FreeBSD has memset */
380 #define memcpy(d, s, l)         bcopy((s),(d),(l))
381 #define memset(d, v, l)         bzero((d),(l))
382 #define bswap32(x)              swap32(x)
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 #define BPF_MTAP(ifp, m)        if ((ifp)->if_bpf) bpf_mtap((ifp), (m));
401
402 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
403 #define clfree(p) clist_free_cblocks((p))
404
405 #define PWR_RESUME 0
406 #define PWR_SUSPEND 1
407
408 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
409
410 typedef struct malloc_type *usb_malloc_type;
411
412 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
413 Static device_probe_t __CONCAT(dname,_match); \
414 Static device_attach_t __CONCAT(dname,_attach); \
415 Static device_detach_t __CONCAT(dname,_detach); \
416 \
417 Static devclass_t __CONCAT(dname,_devclass); \
418 \
419 Static device_method_t __CONCAT(dname,_methods)[] = { \
420         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
421         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
422         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
423         init, \
424         {0,0} \
425 }; \
426 \
427 Static driver_t __CONCAT(dname,_driver) = { \
428         #dname, \
429         __CONCAT(dname,_methods), \
430         sizeof(struct __CONCAT(dname,_softc)) \
431 }; \
432 MODULE_DEPEND(dname, usb, 1, 1, 1)
433
434
435 #define METHODS_NONE                    {0,0}
436 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
437
438 #define USB_MATCH(dname) \
439 Static int \
440 __CONCAT(dname,_match)(device_t self)
441
442 #define USB_MATCH_START(dname, uaa) \
443         struct usb_attach_arg *uaa = device_get_ivars(self)
444
445 #define USB_MATCH_SETUP \
446         sc->sc_dev = self
447
448 #define USB_ATTACH(dname) \
449 Static int \
450 __CONCAT(dname,_attach)(device_t self)
451
452 #define USB_ATTACH_START(dname, sc, uaa) \
453         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
454         struct usb_attach_arg *uaa = device_get_ivars(self)
455
456 /* Returns from attach */
457 #define USB_ATTACH_ERROR_RETURN return ENXIO
458 #define USB_ATTACH_SUCCESS_RETURN       return 0
459
460 #define USB_ATTACH_SETUP \
461         sc->sc_dev = self; \
462         device_set_desc_copy(self, devinfo)
463
464 #define USB_DETACH(dname) \
465 Static int \
466 __CONCAT(dname,_detach)(device_t self)
467
468 #define USB_DETACH_START(dname, sc) \
469         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
470
471 #define USB_GET_SC_OPEN(dname, unit, sc) \
472         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
473         if (sc == NULL) \
474                 return (ENXIO)
475
476 #define USB_GET_SC(dname, unit, sc) \
477         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
478
479 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
480         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
481
482 /* conversion from one type of queue to the other */
483 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
484 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
485 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
486 #define SIMPLEQ_NEXT            STAILQ_NEXT
487 #define SIMPLEQ_FIRST           STAILQ_FIRST
488 #define SIMPLEQ_HEAD            STAILQ_HEAD
489 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
490 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
491 #define SIMPLEQ_INIT            STAILQ_INIT
492 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
493 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
494
495 #include <sys/syslog.h>
496 /*
497 #define logprintf(args...)      log(LOG_DEBUG, args)
498 */
499 #define logprintf               printf
500
501 #ifdef SYSCTL_DECL
502 SYSCTL_DECL(_hw_usb);
503 #endif
504
505 #elif defined(__FreeBSD__)
506 /***************************************************************************
507  *                                      FREEBSD
508  */
509
510 #include "opt_usb.h"
511
512 #if defined(_KERNEL)
513 #include <sys/malloc.h>
514
515 MALLOC_DECLARE(M_USB);
516 MALLOC_DECLARE(M_USBDEV);
517 MALLOC_DECLARE(M_USBHC);
518
519 #endif
520
521 #define USBVERBOSE
522
523 /* We don't use the soft interrupt code in FreeBSD. */
524 #if 0
525 #define USB_USE_SOFTINTR
526 #endif
527
528 #define Static static
529
530 #define device_ptr_t device_t
531 #define USBBASEDEVICE device_t
532 #define USBDEV(bdev) (bdev)
533 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
534 #define USBDEVUNIT(bdev) device_get_unit(bdev)
535 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
536 #define USBDEVUNIT(bdev) device_get_unit(bdev)
537 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
538
539 #define DECLARE_USB_DMA_T \
540         struct usb_dma_block; \
541         typedef struct { \
542                 struct usb_dma_block *block; \
543                 u_int offs; \
544                 u_int len; \
545         } usb_dma_t
546
547 #if __FreeBSD_version >= 500000
548 typedef struct thread *usb_proc_ptr;
549
550 #define uio_procp uio_td
551
552 #define usb_kthread_create1(f, s, p, a0, a1) \
553                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
554 #define usb_kthread_create2(f, s, p, a0) \
555                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
556 #define usb_kthread_create      kthread_create
557
558 #define config_pending_incr()
559 #define config_pending_decr()
560
561 typedef struct callout usb_callout_t;
562 #define usb_callout_init(h)     callout_init(&(h), 0)
563 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
564 #define usb_uncallout(h, f, d)  callout_stop(&(h))
565 #else
566 typedef struct proc *usb_proc_ptr;
567
568 #define PROC_LOCK(p)
569 #define PROC_UNLOCK(p)
570
571 #define usb_kthread_create1(f, s, p, a0, a1) \
572                 kthread_create((f), (s), (p), (a0), (a1))
573 #define usb_kthread_create2(f, s, p, a0) \
574                 kthread_create((f), (s), (p), (a0))
575 #define usb_kthread_create      kthread_create
576
577 #define config_pending_incr()
578 #define config_pending_decr()
579
580 typedef struct callout usb_callout_t;
581 #define usb_callout_init(h)     callout_init(&(h))
582 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
583 #define usb_uncallout(h, f, d)  callout_stop(&(h))
584
585 #define BUS_DMA_COHERENT        0
586 #define ETHER_ALIGN             2
587 #define BPF_MTAP(ifp, m)        if ((ifp)->if_bpf) bpf_mtap((ifp), (m));
588 #endif
589
590 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
591 #define clfree(p) clist_free_cblocks((p))
592
593 #define PWR_RESUME 0
594 #define PWR_SUSPEND 1
595
596 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
597
598 typedef struct malloc_type *usb_malloc_type;
599
600 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
601 Static device_probe_t __CONCAT(dname,_match); \
602 Static device_attach_t __CONCAT(dname,_attach); \
603 Static device_detach_t __CONCAT(dname,_detach); \
604 \
605 Static devclass_t __CONCAT(dname,_devclass); \
606 \
607 Static device_method_t __CONCAT(dname,_methods)[] = { \
608         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
609         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
610         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
611         init, \
612         {0,0} \
613 }; \
614 \
615 Static driver_t __CONCAT(dname,_driver) = { \
616         #dname, \
617         __CONCAT(dname,_methods), \
618         sizeof(struct __CONCAT(dname,_softc)) \
619 }; \
620 MODULE_DEPEND(dname, usb, 1, 1, 1)
621
622
623 #define METHODS_NONE                    {0,0}
624 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
625
626 #define USB_MATCH(dname) \
627 Static int \
628 __CONCAT(dname,_match)(device_t self)
629
630 #define USB_MATCH_START(dname, uaa) \
631         struct usb_attach_arg *uaa = device_get_ivars(self)
632
633 #define USB_MATCH_SETUP \
634         sc->sc_dev = self
635
636 #define USB_ATTACH(dname) \
637 Static int \
638 __CONCAT(dname,_attach)(device_t self)
639
640 #define USB_ATTACH_START(dname, sc, uaa) \
641         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
642         struct usb_attach_arg *uaa = device_get_ivars(self)
643
644 /* Returns from attach */
645 #define USB_ATTACH_ERROR_RETURN return ENXIO
646 #define USB_ATTACH_SUCCESS_RETURN       return 0
647
648 #define USB_ATTACH_SETUP \
649         sc->sc_dev = self; \
650         device_set_desc_copy(self, devinfo)
651
652 #define USB_DETACH(dname) \
653 Static int \
654 __CONCAT(dname,_detach)(device_t self)
655
656 #define USB_DETACH_START(dname, sc) \
657         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
658
659 #define USB_GET_SC_OPEN(dname, unit, sc) \
660         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
661         if (sc == NULL) \
662                 return (ENXIO)
663
664 #define USB_GET_SC(dname, unit, sc) \
665         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
666
667 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
668         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
669
670 /* conversion from one type of queue to the other */
671 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
672 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
673 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
674 #define SIMPLEQ_NEXT            STAILQ_NEXT
675 #define SIMPLEQ_FIRST           STAILQ_FIRST
676 #define SIMPLEQ_HEAD            STAILQ_HEAD
677 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
678 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
679 #define SIMPLEQ_INIT            STAILQ_INIT
680 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
681 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
682
683 #include <sys/syslog.h>
684 /*
685 #define logprintf(args...)      log(LOG_DEBUG, args)
686 */
687 #define logprintf               printf
688
689 #ifdef SYSCTL_DECL
690 SYSCTL_DECL(_hw_usb);
691 #endif
692
693 #endif /* __FreeBSD__ */
694
695 #endif /* _USB_PORT_H */
696