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 $ */
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 $
11 * Copyright (c) 1998 The NetBSD Foundation, Inc.
12 * All rights reserved.
14 * This code is derived from software contributed to The NetBSD Foundation
15 * by Lennart Augustsson (lennart@augustsson.net) at
16 * Carlstedt Research & Technology.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
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.
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.
51 * Macro's to cope with the differences between operating systems.
54 #if defined(__NetBSD__)
59 #include "opt_usbverbose.h"
61 #define USB_USE_SOFTINTR
69 #define SCSI_MODE_SENSE MODE_SENSE
71 typedef struct proc *usb_proc_ptr;
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))
81 #define DECLARE_USB_DMA_T \
82 struct usb_dma_block; \
84 struct usb_dma_block *block; \
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))
93 #define usb_kthread_create1 kthread_create1
94 #define usb_kthread_create kthread_create
96 typedef int usb_malloc_type;
98 #define Ether_ifattach ether_ifattach
99 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
101 #define logprintf printf
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); \
110 extern struct cfdriver __CONCAT(dname,_cd); \
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))
119 #define USB_MATCH(dname) \
120 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
122 #define USB_MATCH_START(dname, uaa) \
123 struct usb_attach_arg *uaa = aux
125 #define USB_ATTACH(dname) \
126 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
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
133 /* Returns from attach */
134 #define USB_ATTACH_ERROR_RETURN return
135 #define USB_ATTACH_SUCCESS_RETURN return
137 #define USB_ATTACH_SETUP
138 printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
140 #define USB_DETACH(dname) \
141 int __CONCAT(dname,_detach)(struct device *self, int flags)
143 #define USB_DETACH_START(dname, sc) \
144 struct __CONCAT(dname,_softc) *sc = \
145 (struct __CONCAT(dname,_softc) *)self
147 #define USB_GET_SC_OPEN(dname, unit, sc) \
148 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
150 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
154 #define USB_GET_SC(dname, unit, sc) \
155 sc = __CONCAT(dname,_cd).cd_devs[unit]
157 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
158 (config_found_sm(parent, args, print, sub))
160 #elif defined(__OpenBSD__)
166 typedef struct proc *usb_proc_ptr;
168 #define UCOMBUSCF_PORTNO -1
169 #define UCOMBUSCF_PORTNO_DEFAULT -1
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
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)
193 * The UHCI/OHCI controllers are little endian, so on big endian machines
194 * the data strored in memory needs to be swapped.
198 #define le32toh(x) letoh32(x)
199 #define le16toh(x) letoh16(x)
202 #define usb_kthread_create1 kthread_create
203 #define usb_kthread_create kthread_create_deferred
205 #define config_pending_incr()
206 #define config_pending_decr()
208 typedef int usb_malloc_type;
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; \
215 eh = mtod(m, struct ether_header *); \
216 m_adj(m, sizeof(struct ether_header)); \
217 ether_input((ifp), (eh), (m)); \
220 #define usbpoll usbselect
221 #define uhidpoll uhidselect
222 #define ugenpoll ugenselect
223 #define uriopoll urioselect
224 #define uscannerpoll uscannerselect
226 #define powerhook_establish(fn, sc) (fn)
227 #define powerhook_disestablish(hdl)
230 #define logprintf printf
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
236 #define realloc usb_realloc
237 void *usb_realloc(void *, u_int, int, int);
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))
249 #define DECLARE_USB_DMA_T \
250 struct usb_dma_block; \
252 struct usb_dma_block *block; \
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))
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); \
267 struct cfdriver __CONCAT(dname,_cd) = { \
268 NULL, #dname, DV_DULL \
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), \
279 #define USB_MATCH(dname) \
281 __CONCAT(dname,_match)(parent, match, aux) \
282 struct device *parent; \
286 #define USB_MATCH_START(dname, uaa) \
287 struct usb_attach_arg *uaa = aux
289 #define USB_ATTACH(dname) \
291 __CONCAT(dname,_attach)(parent, self, aux) \
292 struct device *parent; \
293 struct device *self; \
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
301 /* Returns from attach */
302 #define USB_ATTACH_ERROR_RETURN return
303 #define USB_ATTACH_SUCCESS_RETURN return
305 #define USB_ATTACH_SETUP
306 printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
308 #define USB_DETACH(dname) \
310 __CONCAT(dname,_detach)(self, flags) \
311 struct device *self; \
314 #define USB_DETACH_START(dname, sc) \
315 struct __CONCAT(dname,_softc) *sc = \
316 (struct __CONCAT(dname,_softc) *)self
318 #define USB_GET_SC_OPEN(dname, unit, sc) \
319 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
321 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
325 #define USB_GET_SC(dname, unit, sc) \
326 sc = __CONCAT(dname,_cd).cd_devs[unit]
328 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
329 (config_found_sm(parent, args, print, sub))
331 #elif defined(__FreeBSD__)
339 #include <sys/malloc.h>
341 MALLOC_DECLARE(M_USB);
342 MALLOC_DECLARE(M_USBDEV);
343 MALLOC_DECLARE(M_USBHC);
347 /* We don't use the soft interrupt code in FreeBSD. */
349 #define USB_USE_SOFTINTR
352 #define Static static
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))
363 #define DECLARE_USB_DMA_T \
364 struct usb_dma_block; \
366 struct usb_dma_block *block; \
371 #if __FreeBSD_version >= 500000
372 typedef struct thread *usb_proc_ptr;
374 #define uio_procp uio_td
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
382 #define config_pending_incr()
383 #define config_pending_decr()
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))
391 typedef struct proc *usb_proc_ptr;
394 #define PROC_UNLOCK(p)
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
402 #define config_pending_incr()
403 #define config_pending_decr()
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))
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));
415 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
416 #define clfree(p) clist_free_cblocks((p))
419 #define PWR_SUSPEND 1
421 #define config_detach(dev, flag) \
423 device_detach(dev); \
424 free(device_get_ivars(dev), M_USB); \
425 device_delete_child(device_get_parent(dev), dev); \
428 typedef struct malloc_type *usb_malloc_type;
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); \
435 Static devclass_t __CONCAT(dname,_devclass); \
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)), \
445 Static driver_t __CONCAT(dname,_driver) = { \
447 __CONCAT(dname,_methods), \
448 sizeof(struct __CONCAT(dname,_softc)) \
450 MODULE_DEPEND(dname, usb, 1, 1, 1)
453 #define METHODS_NONE {0,0}
454 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
456 #define USB_MATCH(dname) \
458 __CONCAT(dname,_match)(device_t self)
460 #define USB_MATCH_START(dname, uaa) \
461 struct usb_attach_arg *uaa = device_get_ivars(self)
463 #define USB_MATCH_SETUP \
466 #define USB_ATTACH(dname) \
468 __CONCAT(dname,_attach)(device_t self)
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)
474 /* Returns from attach */
475 #define USB_ATTACH_ERROR_RETURN return ENXIO
476 #define USB_ATTACH_SUCCESS_RETURN return 0
478 #define USB_ATTACH_SETUP \
481 device_set_desc_copy(self, devinfo); \
482 device_printf(self, "%s\n", devinfo); \
485 #define USB_DETACH(dname) \
487 __CONCAT(dname,_detach)(device_t self)
489 #define USB_DETACH_START(dname, sc) \
490 struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
492 #define USB_GET_SC_OPEN(dname, unit, sc) \
493 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
497 #define USB_GET_SC(dname, unit, sc) \
498 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
500 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
501 (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
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
516 #include <sys/syslog.h>
518 #define logprintf(args...) log(LOG_DEBUG, args)
520 #define logprintf printf
523 SYSCTL_DECL(_hw_usb);
526 #endif /* __FreeBSD__ */
528 #endif /* _USB_PORT_H */