1 /* $NetBSD: usb_port.h,v 1.15 1999/11/16 12:04:28 augustss Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.25.2.7 2002/08/12 14:19:49 joe Exp $ */
3 /* $DragonFly: src/sys/bus/usb/usb_port.h,v 1.4 2003/06/27 01:53:24 dillon 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.
44 * Macro's to cope with the differences between operating systems.
47 #if defined(__NetBSD__)
52 #include "opt_usbverbose.h"
56 typedef struct proc *usb_proc_ptr;
58 typedef struct device *device_ptr_t;
59 #define USBBASEDEVICE struct device
60 #define USBDEV(bdev) (&(bdev))
61 #define USBDEVNAME(bdev) ((bdev).dv_xname)
62 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
63 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
65 #define DECLARE_USB_DMA_T \
66 struct usb_dma_block; \
68 struct usb_dma_block *block; \
72 #define usb_timeout(f, d, t, h) timeout((f), (d), (t))
73 #define usb_untimeout(f, d, h) untimeout((f), (d))
75 #define logprintf printf
77 #define USB_DECLARE_DRIVER(dname) \
78 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
79 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
80 int __CONCAT(dname,_detach)(struct device *, int); \
81 int __CONCAT(dname,_activate)(struct device *, enum devact); \
83 extern struct cfdriver __CONCAT(dname,_cd); \
85 struct cfattach __CONCAT(dname,_ca) = { \
86 sizeof(struct __CONCAT(dname,_softc)), \
87 __CONCAT(dname,_match), \
88 __CONCAT(dname,_attach), \
89 __CONCAT(dname,_detach), \
90 __CONCAT(dname,_activate), \
93 #define USB_MATCH(dname) \
95 __CONCAT(dname,_match)(parent, match, aux) \
96 struct device *parent; \
97 struct cfdata *match; \
100 #define USB_MATCH_START(dname, uaa) \
101 struct usb_attach_arg *uaa = aux
103 #define USB_MATCH_SETUP /* nop */
105 #define USB_ATTACH(dname) \
107 __CONCAT(dname,_attach)(parent, self, aux) \
108 struct device *parent; \
109 struct device *self; \
112 #define USB_ATTACH_START(dname, sc, uaa) \
113 struct __CONCAT(dname,_softc) *sc = \
114 (struct __CONCAT(dname,_softc) *)self; \
115 struct usb_attach_arg *uaa = aux
117 /* Returns from attach */
118 #define USB_ATTACH_ERROR_RETURN return
119 #define USB_ATTACH_SUCCESS_RETURN return
121 #define USB_ATTACH_SETUP printf("\n")
123 #define USB_DETACH(dname) \
125 __CONCAT(dname,_detach)(self, flags) \
126 struct device *self; \
129 #define USB_DETACH_START(dname, sc) \
130 struct __CONCAT(dname,_softc) *sc = \
131 (struct __CONCAT(dname,_softc) *)self
133 #define USB_GET_SC_OPEN(dname, unit, sc) \
134 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
136 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
140 #define USB_GET_SC(dname, unit, sc) \
141 sc = __CONCAT(dname,_cd).cd_devs[unit]
143 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
144 (config_found_sm(parent, args, print, sub))
146 #elif defined(__OpenBSD__)
150 #define Static static
152 typedef struct proc *usb_proc_ptr;
154 #define memcpy(d, s, l) bcopy((s),(d),(l))
155 #define memset(d, v, l) bzero((d),(l))
156 #define bswap32(x) swap32(x)
157 #define kthread_create1 kthread_create
158 #define kthread_create kthread_create_deferred
160 #define usbpoll usbselect
161 #define uhidpoll uhidselect
162 #define ugenpoll ugenselect
165 #define PWR_SUSPEND 1
167 typedef struct device device_ptr_t;
168 #define USBBASEDEVICE struct device
169 #define USBDEV(bdev) (&(bdev))
170 #define USBDEVNAME(bdev) ((bdev).dv_xname)
171 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
172 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
174 #define DECLARE_USB_DMA_T \
175 struct usb_dma_block; \
177 struct usb_dma_block *block; \
181 #define usb_timeout(f, d, t, h) timeout((f), (d), (t))
182 #define usb_untimeout(f, d, h) untimeout((f), (d))
184 #define USB_DECLARE_DRIVER(dname) \
185 int __CONCAT(dname,_match)(struct device *, void *, void *); \
186 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
187 int __CONCAT(dname,_detach)(struct device *, int); \
188 int __CONCAT(dname,_activate)(struct device *, enum devact); \
190 struct cfdriver __CONCAT(dname,_cd) = { \
191 NULL, #dname, DV_DULL \
194 struct cfattach __CONCAT(dname,_ca) = { \
195 sizeof(struct __CONCAT(dname,_softc)), \
196 __CONCAT(dname,_match), \
197 __CONCAT(dname,_attach), \
198 __CONCAT(dname,_detach), \
199 __CONCAT(dname,_activate), \
202 #define USB_MATCH(dname) \
204 __CONCAT(dname,_match)(parent, match, aux) \
205 struct device *parent; \
209 #define USB_MATCH_START(dname, uaa) \
210 struct usb_attach_arg *uaa = aux
212 #define USB_MATCH_SETUP /* nop */
214 #define USB_ATTACH(dname) \
216 __CONCAT(dname,_attach)(parent, self, aux) \
217 struct device *parent; \
218 struct device *self; \
221 #define USB_ATTACH_START(dname, sc, uaa) \
222 struct __CONCAT(dname,_softc) *sc = \
223 (struct __CONCAT(dname,_softc) *)self; \
224 struct usb_attach_arg *uaa = aux
226 /* Returns from attach */
227 #define USB_ATTACH_ERROR_RETURN return
228 #define USB_ATTACH_SUCCESS_RETURN return
230 #define USB_ATTACH_SETUP printf("\n")
232 #define USB_DETACH(dname) \
234 __CONCAT(dname,_detach)(self, flags) \
235 struct device *self; \
238 #define USB_DETACH_START(dname, sc) \
239 struct __CONCAT(dname,_softc) *sc = \
240 (struct __CONCAT(dname,_softc) *)self
242 #define USB_GET_SC_OPEN(dname, unit, sc) \
243 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
245 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
249 #define USB_GET_SC(dname, unit, sc) \
250 sc = __CONCAT(dname,_cd).cd_devs[unit]
252 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
253 (config_found_sm(parent, args, print, sub))
255 #elif defined(__FreeBSD__)
264 #define Static static
266 #define device_ptr_t device_t
267 #define USBBASEDEVICE device_t
268 #define USBDEV(bdev) (bdev)
269 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
270 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
271 #define USBDEVUNIT(bdev) device_get_unit(bdev)
273 #define DECLARE_USB_DMA_T typedef char * usb_dma_t
275 typedef struct thread *usb_proc_ptr;
277 /* XXX Change this when FreeBSD has memset */
278 #define memcpy(d, s, l) bcopy((s),(d),(l))
279 #define memset(d, v, l) bzero((d),(l))
280 #define bswap32(x) swap32(x)
281 #define kthread_create1(function, sc, priv, string, name)
282 #define kthread_create(create_function, sc)
283 #define kthread_exit()
285 #define usb_timeout(f, d, t, h) ((h) = timeout((f), (d), (t)))
286 #define usb_untimeout(f, d, h) untimeout((f), (d), (h))
288 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
289 #define clfree(p) clist_free_cblocks((p))
292 #define PWR_SUSPEND 1
294 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
295 Static device_probe_t __CONCAT(dname,_match); \
296 Static device_attach_t __CONCAT(dname,_attach); \
297 Static device_detach_t __CONCAT(dname,_detach); \
299 Static devclass_t __CONCAT(dname,_devclass); \
301 Static device_method_t __CONCAT(dname,_methods)[] = { \
302 DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
303 DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
304 DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
309 Static driver_t __CONCAT(dname,_driver) = { \
311 __CONCAT(dname,_methods), \
312 sizeof(struct __CONCAT(dname,_softc)) \
314 #define METHODS_NONE {0,0}
315 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
317 #define USB_MATCH(dname) \
319 __CONCAT(dname,_match)(device_t self)
321 #define USB_MATCH_START(dname, uaa) \
322 struct usb_attach_arg *uaa = device_get_ivars(self)
324 #define USB_MATCH_SETUP \
327 #define USB_ATTACH(dname) \
329 __CONCAT(dname,_attach)(device_t self)
331 #define USB_ATTACH_START(dname, sc, uaa) \
332 struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
333 struct usb_attach_arg *uaa = device_get_ivars(self)
335 /* Returns from attach */
336 #define USB_ATTACH_ERROR_RETURN return ENXIO
337 #define USB_ATTACH_SUCCESS_RETURN return 0
339 #define USB_ATTACH_SETUP \
341 device_set_desc_copy(self, devinfo)
343 #define USB_DETACH(dname) \
345 __CONCAT(dname,_detach)(device_t self)
347 #define USB_DETACH_START(dname, sc) \
348 struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
350 #define USB_GET_SC_OPEN(dname, unit, sc) \
351 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
355 #define USB_GET_SC(dname, unit, sc) \
356 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
358 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
359 (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
361 /* conversion from one type of queue to the other */
362 /* XXX In FreeBSD SIMPLEQ_REMOVE_HEAD only removes the head element.
364 #define SIMPLEQ_REMOVE_HEAD(h, e, f) do { \
365 if ( (e) != SIMPLEQ_FIRST((h)) ) \
366 panic("Removing other than first element"); \
367 STAILQ_REMOVE_HEAD(h, f); \
369 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD
370 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL
371 #define SIMPLEQ_NEXT STAILQ_NEXT
372 #define SIMPLEQ_FIRST STAILQ_FIRST
373 #define SIMPLEQ_HEAD STAILQ_HEAD
374 #define SIMPLEQ_INIT STAILQ_INIT
375 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER
376 #define SIMPLEQ_ENTRY STAILQ_ENTRY
378 #include <sys/syslog.h>
380 #define logprintf(args...) log(LOG_DEBUG, args)
382 #define logprintf printf
385 SYSCTL_DECL(_hw_usb);
388 #endif /* __FreeBSD__ */