]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/dev/usb/usb_port.h
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / sys / dev / usb / usb_port.h
1 /*      $OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $ */
2 /*      $NetBSD: usb_port.h,v 1.54 2002/03/28 21:49:19 ichiro Exp $     */
3 /*      $FreeBSD$       */
4
5 /* Also already merged from NetBSD:
6  *      $NetBSD: usb_port.h,v 1.57 2002/09/27 20:42:01 thorpej Exp $
7  *      $NetBSD: usb_port.h,v 1.58 2002/10/01 01:25:26 thorpej Exp $
8  */
9
10 /*-
11  * Copyright (c) 1998 The NetBSD Foundation, Inc.
12  * All rights reserved.
13  *
14  * This code is derived from software contributed to The NetBSD Foundation
15  * by Lennart Augustsson (lennart@augustsson.net) at
16  * Carlstedt Research & Technology.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  *    notice, this list of conditions and the following disclaimer in the
25  *    documentation and/or other materials provided with the distribution.
26  * 3. All advertising materials mentioning features or use of this software
27  *    must display the following acknowledgement:
28  *        This product includes software developed by the NetBSD
29  *        Foundation, Inc. and its contributors.
30  * 4. Neither the name of The NetBSD Foundation nor the names of its
31  *    contributors may be used to endorse or promote products derived
32  *    from this software without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
35  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46
47 #ifndef _USB_PORT_H
48 #define _USB_PORT_H
49
50 /*
51  * Macro's to cope with the differences between operating systems.
52  */
53
54 #if defined(__NetBSD__)
55 /*
56  * NetBSD
57  */
58
59 #include "opt_usbverbose.h"
60
61 #define USB_USE_SOFTINTR
62
63 #ifdef USB_DEBUG
64 #define Static
65 #else
66 #define Static static
67 #endif
68
69 #define SCSI_MODE_SENSE         MODE_SENSE
70
71 typedef struct proc *usb_proc_ptr;
72
73 typedef struct device *device_ptr_t;
74 #define USBBASEDEVICE struct device
75 #define USBDEV(bdev) (&(bdev))
76 #define USBDEVNAME(bdev) ((bdev).dv_xname)
77 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
78 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
79 #define USBGETSOFTC(d) ((void *)(d))
80
81 #define DECLARE_USB_DMA_T \
82         struct usb_dma_block; \
83         typedef struct { \
84                 struct usb_dma_block *block; \
85                 u_int offs; \
86         } usb_dma_t
87
88 typedef struct callout usb_callout_t;
89 #define usb_callout_init(h)     callout_init(&(h))
90 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
91 #define usb_uncallout(h, f, d)  callout_stop(&(h))
92
93 #define usb_kthread_create1     kthread_create1
94 #define usb_kthread_create      kthread_create
95
96 typedef int usb_malloc_type;
97
98 #define Ether_ifattach ether_ifattach
99 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
100
101 #define logprintf printf
102
103 #define USB_DNAME(dname)        dname
104 #define USB_DECLARE_DRIVER(dname)  \
105 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
106 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
107 int __CONCAT(dname,_detach)(struct device *, int); \
108 int __CONCAT(dname,_activate)(struct device *, enum devact); \
109 \
110 extern struct cfdriver __CONCAT(dname,_cd); \
111 \
112 CFATTACH_DECL(USB_DNAME(dname), \
113     sizeof(struct ___CONCAT(dname,_softc)), \
114     ___CONCAT(dname,_match), \
115     ___CONCAT(dname,_attach), \
116     ___CONCAT(dname,_detach), \
117     ___CONCAT(dname,_activate))
118
119 #define USB_MATCH(dname) \
120 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
121
122 #define USB_MATCH_START(dname, uaa) \
123         struct usb_attach_arg *uaa = aux
124
125 #define USB_ATTACH(dname) \
126 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
127
128 #define USB_ATTACH_START(dname, sc, uaa) \
129         struct __CONCAT(dname,_softc) *sc = \
130                 (struct __CONCAT(dname,_softc) *)self; \
131         struct usb_attach_arg *uaa = aux
132
133 /* Returns from attach */
134 #define USB_ATTACH_ERROR_RETURN return
135 #define USB_ATTACH_SUCCESS_RETURN       return
136
137 #define USB_ATTACH_SETUP
138         printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
139
140 #define USB_DETACH(dname) \
141 int __CONCAT(dname,_detach)(struct device *self, int flags)
142
143 #define USB_DETACH_START(dname, sc) \
144         struct __CONCAT(dname,_softc) *sc = \
145                 (struct __CONCAT(dname,_softc) *)self
146
147 #define USB_GET_SC_OPEN(dname, unit, sc) \
148         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
149                 return (ENXIO); \
150         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
151         if (sc == NULL) \
152                 return (ENXIO)
153
154 #define USB_GET_SC(dname, unit, sc) \
155         sc = __CONCAT(dname,_cd).cd_devs[unit]
156
157 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
158         (config_found_sm(parent, args, print, sub))
159
160 #elif defined(__OpenBSD__)
161 /*
162  * OpenBSD
163  */
164 #define Static
165
166 typedef struct proc *usb_proc_ptr;
167
168 #define UCOMBUSCF_PORTNO                -1
169 #define UCOMBUSCF_PORTNO_DEFAULT        -1
170
171 #define SCSI_MODE_SENSE         MODE_SENSE
172 #define XS_STS_DONE             ITSDONE
173 #define XS_CTL_POLL             SCSI_POLL
174 #define XS_CTL_DATA_IN          SCSI_DATA_IN
175 #define XS_CTL_DATA_OUT         SCSI_DATA_OUT
176 #define scsipi_adapter          scsi_adapter
177 #define scsipi_cmd              scsi_cmd
178 #define scsipi_device           scsi_device
179 #define scsipi_done             scsi_done
180 #define scsipi_link             scsi_link
181 #define scsipi_minphys          scsi_minphys
182 #define scsipi_sense            scsi_sense
183 #define scsipi_xfer             scsi_xfer
184 #define xs_control              flags
185 #define xs_status               status
186
187 #define memcpy(d, s, l)         bcopy((s),(d),(l))
188 #define memset(d, v, l)         bzero((d),(l))
189 #define bswap32(x)              swap32(x)
190 #define bswap16(x)              swap16(x)
191
192 /*
193  * The UHCI/OHCI controllers are little endian, so on big endian machines
194  * the data strored in memory needs to be swapped.
195  */
196
197 #if defined(letoh32)
198 #define le32toh(x) letoh32(x)
199 #define le16toh(x) letoh16(x)
200 #endif
201
202 #define usb_kthread_create1     kthread_create
203 #define usb_kthread_create      kthread_create_deferred
204
205 #define config_pending_incr()
206 #define config_pending_decr()
207
208 typedef int usb_malloc_type;
209
210 #define Ether_ifattach(ifp, eaddr) ether_ifattach(ifp)
211 #define if_deactivate(x)
212 #define IF_INPUT(ifp, m) do {                                           \
213         struct ether_header *eh;                                        \
214                                                                         \
215         eh = mtod(m, struct ether_header *);                            \
216         m_adj(m, sizeof(struct ether_header));                          \
217         ether_input((ifp), (eh), (m));                                  \
218 } while (0)
219
220 #define usbpoll                 usbselect
221 #define uhidpoll                uhidselect
222 #define ugenpoll                ugenselect
223 #define uriopoll                urioselect
224 #define uscannerpoll            uscannerselect
225
226 #define powerhook_establish(fn, sc) (fn)
227 #define powerhook_disestablish(hdl)
228 #define PWR_RESUME 0
229
230 #define logprintf printf
231
232 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
233 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
234 #define change_sign16_le change_sign16
235
236 #define realloc usb_realloc
237 void *usb_realloc(void *, u_int, int, int);
238
239 extern int cold;
240
241 typedef struct device *device_ptr_t;
242 #define USBBASEDEVICE struct device
243 #define USBDEV(bdev) (&(bdev))
244 #define USBDEVNAME(bdev) ((bdev).dv_xname)
245 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
246 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
247 #define USBGETSOFTC(d) ((void *)(d))
248
249 #define DECLARE_USB_DMA_T \
250         struct usb_dma_block; \
251         typedef struct { \
252                 struct usb_dma_block *block; \
253                 u_int offs; \
254         } usb_dma_t
255
256 typedef char usb_callout_t;
257 #define usb_callout_init(h)
258 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
259 #define usb_uncallout(h, f, d) untimeout((f), (d))
260
261 #define USB_DECLARE_DRIVER(dname)  \
262 int __CONCAT(dname,_match)(struct device *, void *, void *); \
263 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
264 int __CONCAT(dname,_detach)(struct device *, int); \
265 int __CONCAT(dname,_activate)(struct device *, enum devact); \
266 \
267 struct cfdriver __CONCAT(dname,_cd) = { \
268         NULL, #dname, DV_DULL \
269 }; \
270 \
271 const struct cfattach __CONCAT(dname,_ca) = { \
272         sizeof(struct __CONCAT(dname,_softc)), \
273         __CONCAT(dname,_match), \
274         __CONCAT(dname,_attach), \
275         __CONCAT(dname,_detach), \
276         __CONCAT(dname,_activate), \
277 }
278
279 #define USB_MATCH(dname) \
280 int \
281 __CONCAT(dname,_match)(parent, match, aux) \
282         struct device *parent; \
283         void *match; \
284         void *aux;
285
286 #define USB_MATCH_START(dname, uaa) \
287         struct usb_attach_arg *uaa = aux
288
289 #define USB_ATTACH(dname) \
290 void \
291 __CONCAT(dname,_attach)(parent, self, aux) \
292         struct device *parent; \
293         struct device *self; \
294         void *aux;
295
296 #define USB_ATTACH_START(dname, sc, uaa) \
297         struct __CONCAT(dname,_softc) *sc = \
298                 (struct __CONCAT(dname,_softc) *)self; \
299         struct usb_attach_arg *uaa = aux
300
301 /* Returns from attach */
302 #define USB_ATTACH_ERROR_RETURN return
303 #define USB_ATTACH_SUCCESS_RETURN       return
304
305 #define USB_ATTACH_SETUP
306         printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
307
308 #define USB_DETACH(dname) \
309 int \
310 __CONCAT(dname,_detach)(self, flags) \
311         struct device *self; \
312         int flags;
313
314 #define USB_DETACH_START(dname, sc) \
315         struct __CONCAT(dname,_softc) *sc = \
316                 (struct __CONCAT(dname,_softc) *)self
317
318 #define USB_GET_SC_OPEN(dname, unit, sc) \
319         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
320                 return (ENXIO); \
321         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
322         if (sc == NULL) \
323                 return (ENXIO)
324
325 #define USB_GET_SC(dname, unit, sc) \
326         sc = __CONCAT(dname,_cd).cd_devs[unit]
327
328 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
329         (config_found_sm(parent, args, print, sub))
330
331 #elif defined(__FreeBSD__)
332 /*
333  * FreeBSD
334  */
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 /* We don't use the soft interrupt code in FreeBSD. */
348 #if 0
349 #define USB_USE_SOFTINTR
350 #endif
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 #if __FreeBSD_version >= 500000
372 typedef struct thread *usb_proc_ptr;
373
374 #define uio_procp uio_td
375
376 #define usb_kthread_create1(f, s, p, a0, a1) \
377                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
378 #define usb_kthread_create2(f, s, p, a0) \
379                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
380 #define usb_kthread_create      kthread_create
381
382 #define config_pending_incr()
383 #define config_pending_decr()
384
385 typedef struct callout usb_callout_t;
386 #define usb_callout_init(h)     callout_init(&(h), 0)
387 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
388 #define usb_uncallout(h, f, d)  callout_stop(&(h))
389 #define usb_uncallout_drain(h, f, d)  callout_drain(&(h))
390 #else
391 typedef struct proc *usb_proc_ptr;
392
393 #define PROC_LOCK(p)
394 #define PROC_UNLOCK(p)
395
396 #define usb_kthread_create1(f, s, p, a0, a1) \
397                 kthread_create((f), (s), (p), (a0), (a1))
398 #define usb_kthread_create2(f, s, p, a0) \
399                 kthread_create((f), (s), (p), (a0))
400 #define usb_kthread_create      kthread_create
401
402 #define config_pending_incr()
403 #define config_pending_decr()
404
405 typedef struct callout usb_callout_t;
406 #define usb_callout_init(h)     callout_init(&(h))
407 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
408 #define usb_uncallout(h, f, d)  callout_stop(&(h))
409
410 #define BUS_DMA_COHERENT        0
411 #define ETHER_ALIGN             2
412 #define BPF_MTAP(ifp, m)        if ((ifp)->if_bpf) bpf_mtap((ifp), (m));
413 #endif
414
415 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
416 #define clfree(p) clist_free_cblocks((p))
417
418 #define PWR_RESUME 0
419 #define PWR_SUSPEND 1
420
421 #define config_detach(dev, flag) \
422         do { \
423                 device_detach(dev); \
424                 free(device_get_ivars(dev), M_USB); \
425                 device_delete_child(device_get_parent(dev), dev); \
426         } while (0);
427
428 typedef struct malloc_type *usb_malloc_type;
429
430 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
431 Static device_probe_t __CONCAT(dname,_match); \
432 Static device_attach_t __CONCAT(dname,_attach); \
433 Static device_detach_t __CONCAT(dname,_detach); \
434 \
435 Static devclass_t __CONCAT(dname,_devclass); \
436 \
437 Static device_method_t __CONCAT(dname,_methods)[] = { \
438         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
439         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
440         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
441         init, \
442         {0,0} \
443 }; \
444 \
445 Static driver_t __CONCAT(dname,_driver) = { \
446         #dname, \
447         __CONCAT(dname,_methods), \
448         sizeof(struct __CONCAT(dname,_softc)) \
449 }; \
450 MODULE_DEPEND(dname, usb, 1, 1, 1)
451
452
453 #define METHODS_NONE                    {0,0}
454 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
455
456 #define USB_MATCH(dname) \
457 Static int \
458 __CONCAT(dname,_match)(device_t self)
459
460 #define USB_MATCH_START(dname, uaa) \
461         struct usb_attach_arg *uaa = device_get_ivars(self)
462
463 #define USB_MATCH_SETUP \
464         sc->sc_dev = self
465
466 #define USB_ATTACH(dname) \
467 Static int \
468 __CONCAT(dname,_attach)(device_t self)
469
470 #define USB_ATTACH_START(dname, sc, uaa) \
471         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
472         struct usb_attach_arg *uaa = device_get_ivars(self)
473
474 /* Returns from attach */
475 #define USB_ATTACH_ERROR_RETURN return ENXIO
476 #define USB_ATTACH_SUCCESS_RETURN       return 0
477
478 #define USB_ATTACH_SETUP \
479         do { \
480                 sc->sc_dev = self; \
481                 device_set_desc_copy(self, devinfo); \
482                 device_printf(self, "%s\n", devinfo); \
483         } while (0);
484
485 #define USB_DETACH(dname) \
486 Static int \
487 __CONCAT(dname,_detach)(device_t self)
488
489 #define USB_DETACH_START(dname, sc) \
490         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
491
492 #define USB_GET_SC_OPEN(dname, unit, sc) \
493         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
494         if (sc == NULL) \
495                 return (ENXIO)
496
497 #define USB_GET_SC(dname, unit, sc) \
498         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
499
500 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
501         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
502
503 /* conversion from one type of queue to the other */
504 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
505 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
506 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
507 #define SIMPLEQ_NEXT            STAILQ_NEXT
508 #define SIMPLEQ_FIRST           STAILQ_FIRST
509 #define SIMPLEQ_HEAD            STAILQ_HEAD
510 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
511 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
512 #define SIMPLEQ_INIT            STAILQ_INIT
513 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
514 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
515
516 #include <sys/syslog.h>
517 /*
518 #define logprintf(args...)      log(LOG_DEBUG, args)
519 */
520 #define logprintf               printf
521
522 #ifdef SYSCTL_DECL
523 SYSCTL_DECL(_hw_usb);
524 #endif
525
526 #endif /* __FreeBSD__ */
527
528 #endif /* _USB_PORT_H */
529