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 $ */
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (lennart@augustsson.net) at
11 * Carlstedt Research & Technology.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
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.
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.
46 * Macro's to cope with the differences between operating systems.
49 #if defined(__NetBSD__)
54 #include "opt_usbverbose.h"
56 #define USB_USE_SOFTINTR
64 #define SCSI_MODE_SENSE MODE_SENSE
66 typedef struct proc *usb_proc_ptr;
68 typedef struct device *device_ptr_t;
69 #define USBBASEDEVICE struct device
70 #define USBDEV(bdev) (&(bdev))
71 #define USBDEVNAME(bdev) ((bdev).dv_xname)
72 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
73 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
74 #define USBGETSOFTC(d) ((void *)(d))
76 #define DECLARE_USB_DMA_T \
77 struct usb_dma_block; \
79 struct usb_dma_block *block; \
83 typedef struct callout usb_callout_t;
84 #define usb_callout_init(h) callout_init(&(h))
85 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
86 #define usb_uncallout(h, f, d) callout_stop(&(h))
88 #define usb_kthread_create1 kthread_create1
89 #define usb_kthread_create kthread_create
91 typedef int usb_malloc_type;
93 #define Ether_ifattach ether_ifattach
94 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
96 #define logprintf printf
98 #define USB_DECLARE_DRIVER(dname) \
99 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
100 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
101 int __CONCAT(dname,_detach)(struct device *, int); \
102 int __CONCAT(dname,_activate)(struct device *, enum devact); \
104 extern struct cfdriver __CONCAT(dname,_cd); \
106 struct cfattach __CONCAT(dname,_ca) = { \
107 sizeof(struct __CONCAT(dname,_softc)), \
108 __CONCAT(dname,_match), \
109 __CONCAT(dname,_attach), \
110 __CONCAT(dname,_detach), \
111 __CONCAT(dname,_activate), \
114 #define USB_MATCH(dname) \
115 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
117 #define USB_MATCH_START(dname, uaa) \
118 struct usb_attach_arg *uaa = aux
120 #define USB_ATTACH(dname) \
121 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
123 #define USB_ATTACH_START(dname, sc, uaa) \
124 struct __CONCAT(dname,_softc) *sc = \
125 (struct __CONCAT(dname,_softc) *)self; \
126 struct usb_attach_arg *uaa = aux
128 /* Returns from attach */
129 #define USB_ATTACH_ERROR_RETURN return
130 #define USB_ATTACH_SUCCESS_RETURN return
132 #define USB_ATTACH_SETUP printf("\n")
134 #define USB_DETACH(dname) \
135 int __CONCAT(dname,_detach)(struct device *self, int flags)
137 #define USB_DETACH_START(dname, sc) \
138 struct __CONCAT(dname,_softc) *sc = \
139 (struct __CONCAT(dname,_softc) *)self
141 #define USB_GET_SC_OPEN(dname, unit, sc) \
142 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
144 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
148 #define USB_GET_SC(dname, unit, sc) \
149 sc = __CONCAT(dname,_cd).cd_devs[unit]
151 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
152 (config_found_sm(parent, args, print, sub))
154 #elif defined(__OpenBSD__)
160 typedef struct proc *usb_proc_ptr;
162 #define UCOMBUSCF_PORTNO -1
163 #define UCOMBUSCF_PORTNO_DEFAULT -1
165 #define SCSI_MODE_SENSE MODE_SENSE
166 #define XS_STS_DONE ITSDONE
167 #define XS_CTL_POLL SCSI_POLL
168 #define XS_CTL_DATA_IN SCSI_DATA_IN
169 #define XS_CTL_DATA_OUT SCSI_DATA_OUT
170 #define scsipi_adapter scsi_adapter
171 #define scsipi_cmd scsi_cmd
172 #define scsipi_device scsi_device
173 #define scsipi_done scsi_done
174 #define scsipi_link scsi_link
175 #define scsipi_minphys scsi_minphys
176 #define scsipi_sense scsi_sense
177 #define scsipi_xfer scsi_xfer
178 #define xs_control flags
179 #define xs_status status
181 #define memcpy(d, s, l) bcopy((s),(d),(l))
182 #define memset(d, v, l) bzero((d),(l))
183 #define bswap32(x) swap32(x)
184 #define bswap16(x) swap16(x)
187 * The UHCI/OHCI controllers are little endian, so on big endian machines
188 * the data strored in memory needs to be swapped.
192 #define le32toh(x) letoh32(x)
193 #define le16toh(x) letoh16(x)
196 #define usb_kthread_create1 kthread_create
197 #define usb_kthread_create kthread_create_deferred
199 #define config_pending_incr()
200 #define config_pending_decr()
202 typedef int usb_malloc_type;
204 #define Ether_ifattach(ifp, eaddr) ether_ifattach(ifp)
205 #define if_deactivate(x)
206 #define IF_INPUT(ifp, m) do { \
207 struct ether_header *eh; \
209 eh = mtod(m, struct ether_header *); \
210 m_adj(m, sizeof(struct ether_header)); \
211 ether_input((ifp), (eh), (m)); \
214 #define usbpoll usbselect
215 #define uhidpoll uhidselect
216 #define ugenpoll ugenselect
217 #define uriopoll urioselect
218 #define uscannerpoll uscannerselect
220 #define powerhook_establish(fn, sc) (fn)
221 #define powerhook_disestablish(hdl)
224 #define logprintf printf
226 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
227 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
228 #define change_sign16_le change_sign16
230 #define realloc usb_realloc
231 void *usb_realloc(void *, u_int, int, int);
235 typedef struct device *device_ptr_t;
236 #define USBBASEDEVICE struct device
237 #define USBDEV(bdev) (&(bdev))
238 #define USBDEVNAME(bdev) ((bdev).dv_xname)
239 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
240 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
241 #define USBGETSOFTC(d) ((void *)(d))
243 #define DECLARE_USB_DMA_T \
244 struct usb_dma_block; \
246 struct usb_dma_block *block; \
250 typedef char usb_callout_t;
251 #define usb_callout_init(h)
252 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
253 #define usb_uncallout(h, f, d) untimeout((f), (d))
255 #define USB_DECLARE_DRIVER(dname) \
256 int __CONCAT(dname,_match)(struct device *, void *, void *); \
257 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
258 int __CONCAT(dname,_detach)(struct device *, int); \
259 int __CONCAT(dname,_activate)(struct device *, enum devact); \
261 struct cfdriver __CONCAT(dname,_cd) = { \
262 NULL, #dname, DV_DULL \
265 struct cfattach __CONCAT(dname,_ca) = { \
266 sizeof(struct __CONCAT(dname,_softc)), \
267 __CONCAT(dname,_match), \
268 __CONCAT(dname,_attach), \
269 __CONCAT(dname,_detach), \
270 __CONCAT(dname,_activate), \
273 #define USB_MATCH(dname) \
275 __CONCAT(dname,_match)(parent, match, aux) \
276 struct device *parent; \
280 #define USB_MATCH_START(dname, uaa) \
281 struct usb_attach_arg *uaa = aux
283 #define USB_ATTACH(dname) \
285 __CONCAT(dname,_attach)(parent, self, aux) \
286 struct device *parent; \
287 struct device *self; \
290 #define USB_ATTACH_START(dname, sc, uaa) \
291 struct __CONCAT(dname,_softc) *sc = \
292 (struct __CONCAT(dname,_softc) *)self; \
293 struct usb_attach_arg *uaa = aux
295 /* Returns from attach */
296 #define USB_ATTACH_ERROR_RETURN return
297 #define USB_ATTACH_SUCCESS_RETURN return
299 #define USB_ATTACH_SETUP printf("\n")
301 #define USB_DETACH(dname) \
303 __CONCAT(dname,_detach)(self, flags) \
304 struct device *self; \
307 #define USB_DETACH_START(dname, sc) \
308 struct __CONCAT(dname,_softc) *sc = \
309 (struct __CONCAT(dname,_softc) *)self
311 #define USB_GET_SC_OPEN(dname, unit, sc) \
312 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
314 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
318 #define USB_GET_SC(dname, unit, sc) \
319 sc = __CONCAT(dname,_cd).cd_devs[unit]
321 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
322 (config_found_sm(parent, args, print, sub))
324 #elif defined(__FreeBSD__)
332 #include <sys/malloc.h>
334 MALLOC_DECLARE(M_USB);
335 MALLOC_DECLARE(M_USBDEV);
336 MALLOC_DECLARE(M_USBHC);
342 /* We don't use the soft interrupt code in FreeBSD. */
344 #define USB_USE_SOFTINTR
347 #define Static static
349 #define device_ptr_t device_t
350 #define USBBASEDEVICE device_t
351 #define USBDEV(bdev) (bdev)
352 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
353 #define USBDEVUNIT(bdev) device_get_unit(bdev)
354 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
355 #define USBDEVUNIT(bdev) device_get_unit(bdev)
356 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
358 #define DECLARE_USB_DMA_T typedef char * usb_dma_t
360 typedef struct thread *usb_proc_ptr;
362 #define uio_procp uio_td
364 /* XXX Change this when FreeBSD has memset */
365 #define memcpy(d, s, l) bcopy((s),(d),(l))
366 #define memset(d, v, l) bzero((d),(l))
367 #define usb_kthread_create1(f, s, p, a0, a1) \
368 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
369 #define usb_kthread_create2(f, s, p, a0) \
370 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
371 #define usb_kthread_create kthread_create
373 #define config_pending_incr()
374 #define config_pending_decr()
376 typedef struct callout usb_callout_t;
377 #define usb_callout_init(h) callout_init(&(h), 0)
378 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
379 #define usb_uncallout(h, f, d) callout_stop(&(h))
381 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
382 #define clfree(p) clist_free_cblocks((p))
385 #define PWR_SUSPEND 1
387 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
389 typedef struct malloc_type *usb_malloc_type;
391 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
392 Static device_probe_t __CONCAT(dname,_match); \
393 Static device_attach_t __CONCAT(dname,_attach); \
394 Static device_detach_t __CONCAT(dname,_detach); \
396 Static devclass_t __CONCAT(dname,_devclass); \
398 Static device_method_t __CONCAT(dname,_methods)[] = { \
399 DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
400 DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
401 DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
406 Static driver_t __CONCAT(dname,_driver) = { \
408 __CONCAT(dname,_methods), \
409 sizeof(struct __CONCAT(dname,_softc)) \
411 MODULE_DEPEND(dname, usb, 1, 1, 1)
414 #define METHODS_NONE {0,0}
415 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
417 #define USB_MATCH(dname) \
419 __CONCAT(dname,_match)(device_t self)
421 #define USB_MATCH_START(dname, uaa) \
422 struct usb_attach_arg *uaa = device_get_ivars(self)
424 #define USB_MATCH_SETUP \
427 #define USB_ATTACH(dname) \
429 __CONCAT(dname,_attach)(device_t self)
431 #define USB_ATTACH_START(dname, sc, uaa) \
432 struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
433 struct usb_attach_arg *uaa = device_get_ivars(self)
435 /* Returns from attach */
436 #define USB_ATTACH_ERROR_RETURN return ENXIO
437 #define USB_ATTACH_SUCCESS_RETURN return 0
439 #define USB_ATTACH_SETUP \
441 device_set_desc_copy(self, devinfo)
443 #define USB_DETACH(dname) \
445 __CONCAT(dname,_detach)(device_t self)
447 #define USB_DETACH_START(dname, sc) \
448 struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
450 #define USB_GET_SC_OPEN(dname, unit, sc) \
451 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
455 #define USB_GET_SC(dname, unit, sc) \
456 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
458 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
459 (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
461 /* conversion from one type of queue to the other */
462 /* XXX In FreeBSD SIMPLEQ_REMOVE_HEAD only removes the head element.
464 #define SIMPLEQ_REMOVE_HEAD(h, e, f) do { \
465 if ( (e) != SIMPLEQ_FIRST((h)) ) \
466 panic("Removing other than first element"); \
467 STAILQ_REMOVE_HEAD(h, f); \
469 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD
470 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL
471 #define SIMPLEQ_NEXT STAILQ_NEXT
472 #define SIMPLEQ_FIRST STAILQ_FIRST
473 #define SIMPLEQ_HEAD STAILQ_HEAD
474 #define SIMPLEQ_INIT STAILQ_INIT
475 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER
476 #define SIMPLEQ_ENTRY STAILQ_ENTRY
478 #include <sys/syslog.h>
480 #define logprintf(args...) log(LOG_DEBUG, args)
482 #define logprintf printf
485 SYSCTL_DECL(_hw_usb);
488 #endif /* __FreeBSD__ */
490 #endif /* _USB_PORT_H */