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