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 $ */
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
43 * Macro's to cope with the differences between operating systems.
46 #if defined(__NetBSD__)
51 #include "opt_usbverbose.h"
55 typedef struct proc *usb_proc_ptr;
57 typedef struct device *device_ptr_t;
58 #define USBBASEDEVICE struct device
59 #define USBDEV(bdev) (&(bdev))
60 #define USBDEVNAME(bdev) ((bdev).dv_xname)
61 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
62 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
64 #define DECLARE_USB_DMA_T \
65 struct usb_dma_block; \
67 struct usb_dma_block *block; \
71 #define usb_timeout(f, d, t, h) timeout((f), (d), (t))
72 #define usb_untimeout(f, d, h) untimeout((f), (d))
74 #define logprintf printf
76 #define USB_DECLARE_DRIVER(dname) \
77 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
78 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
79 int __CONCAT(dname,_detach)(struct device *, int); \
80 int __CONCAT(dname,_activate)(struct device *, enum devact); \
82 extern struct cfdriver __CONCAT(dname,_cd); \
84 struct cfattach __CONCAT(dname,_ca) = { \
85 sizeof(struct __CONCAT(dname,_softc)), \
86 __CONCAT(dname,_match), \
87 __CONCAT(dname,_attach), \
88 __CONCAT(dname,_detach), \
89 __CONCAT(dname,_activate), \
92 #define USB_MATCH(dname) \
94 __CONCAT(dname,_match)(parent, match, aux) \
95 struct device *parent; \
96 struct cfdata *match; \
99 #define USB_MATCH_START(dname, uaa) \
100 struct usb_attach_arg *uaa = aux
102 #define USB_MATCH_SETUP /* nop */
104 #define USB_ATTACH(dname) \
106 __CONCAT(dname,_attach)(parent, self, aux) \
107 struct device *parent; \
108 struct device *self; \
111 #define USB_ATTACH_START(dname, sc, uaa) \
112 struct __CONCAT(dname,_softc) *sc = \
113 (struct __CONCAT(dname,_softc) *)self; \
114 struct usb_attach_arg *uaa = aux
116 /* Returns from attach */
117 #define USB_ATTACH_ERROR_RETURN return
118 #define USB_ATTACH_SUCCESS_RETURN return
120 #define USB_ATTACH_SETUP printf("\n")
122 #define USB_DETACH(dname) \
124 __CONCAT(dname,_detach)(self, flags) \
125 struct device *self; \
128 #define USB_DETACH_START(dname, sc) \
129 struct __CONCAT(dname,_softc) *sc = \
130 (struct __CONCAT(dname,_softc) *)self
132 #define USB_GET_SC_OPEN(dname, unit, sc) \
133 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
135 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
139 #define USB_GET_SC(dname, unit, sc) \
140 sc = __CONCAT(dname,_cd).cd_devs[unit]
142 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
143 (config_found_sm(parent, args, print, sub))
145 #elif defined(__OpenBSD__)
149 #define Static static
151 typedef struct proc *usb_proc_ptr;
153 #define memcpy(d, s, l) bcopy((s),(d),(l))
154 #define memset(d, v, l) bzero((d),(l))
155 #define bswap32(x) swap32(x)
156 #define kthread_create1 kthread_create
157 #define kthread_create kthread_create_deferred
159 #define usbpoll usbselect
160 #define uhidpoll uhidselect
161 #define ugenpoll ugenselect
164 #define PWR_SUSPEND 1
166 typedef struct device device_ptr_t;
167 #define USBBASEDEVICE struct device
168 #define USBDEV(bdev) (&(bdev))
169 #define USBDEVNAME(bdev) ((bdev).dv_xname)
170 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
171 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
173 #define DECLARE_USB_DMA_T \
174 struct usb_dma_block; \
176 struct usb_dma_block *block; \
180 #define usb_timeout(f, d, t, h) timeout((f), (d), (t))
181 #define usb_untimeout(f, d, h) untimeout((f), (d))
183 #define USB_DECLARE_DRIVER(dname) \
184 int __CONCAT(dname,_match)(struct device *, void *, void *); \
185 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
186 int __CONCAT(dname,_detach)(struct device *, int); \
187 int __CONCAT(dname,_activate)(struct device *, enum devact); \
189 struct cfdriver __CONCAT(dname,_cd) = { \
190 NULL, #dname, DV_DULL \
193 struct cfattach __CONCAT(dname,_ca) = { \
194 sizeof(struct __CONCAT(dname,_softc)), \
195 __CONCAT(dname,_match), \
196 __CONCAT(dname,_attach), \
197 __CONCAT(dname,_detach), \
198 __CONCAT(dname,_activate), \
201 #define USB_MATCH(dname) \
203 __CONCAT(dname,_match)(parent, match, aux) \
204 struct device *parent; \
208 #define USB_MATCH_START(dname, uaa) \
209 struct usb_attach_arg *uaa = aux
211 #define USB_MATCH_SETUP /* nop */
213 #define USB_ATTACH(dname) \
215 __CONCAT(dname,_attach)(parent, self, aux) \
216 struct device *parent; \
217 struct device *self; \
220 #define USB_ATTACH_START(dname, sc, uaa) \
221 struct __CONCAT(dname,_softc) *sc = \
222 (struct __CONCAT(dname,_softc) *)self; \
223 struct usb_attach_arg *uaa = aux
225 /* Returns from attach */
226 #define USB_ATTACH_ERROR_RETURN return
227 #define USB_ATTACH_SUCCESS_RETURN return
229 #define USB_ATTACH_SETUP printf("\n")
231 #define USB_DETACH(dname) \
233 __CONCAT(dname,_detach)(self, flags) \
234 struct device *self; \
237 #define USB_DETACH_START(dname, sc) \
238 struct __CONCAT(dname,_softc) *sc = \
239 (struct __CONCAT(dname,_softc) *)self
241 #define USB_GET_SC_OPEN(dname, unit, sc) \
242 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
244 sc = __CONCAT(dname,_cd).cd_devs[unit]; \
248 #define USB_GET_SC(dname, unit, sc) \
249 sc = __CONCAT(dname,_cd).cd_devs[unit]
251 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
252 (config_found_sm(parent, args, print, sub))
254 #elif defined(__FreeBSD__)
263 #define Static static
265 #define device_ptr_t device_t
266 #define USBBASEDEVICE device_t
267 #define USBDEV(bdev) (bdev)
268 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
269 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
270 #define USBDEVUNIT(bdev) device_get_unit(bdev)
272 #define DECLARE_USB_DMA_T typedef char * usb_dma_t
274 typedef struct proc *usb_proc_ptr;
276 /* XXX Change this when FreeBSD has memset */
277 #define memcpy(d, s, l) bcopy((s),(d),(l))
278 #define memset(d, v, l) bzero((d),(l))
279 #define bswap32(x) swap32(x)
280 #define kthread_create1(function, sc, priv, string, name)
281 #define kthread_create(create_function, sc)
282 #define kthread_exit(err)
284 #define usb_timeout(f, d, t, h) ((h) = timeout((f), (d), (t)))
285 #define usb_untimeout(f, d, h) untimeout((f), (d), (h))
287 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
288 #define clfree(p) clist_free_cblocks((p))
291 #define PWR_SUSPEND 1
293 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
294 Static device_probe_t __CONCAT(dname,_match); \
295 Static device_attach_t __CONCAT(dname,_attach); \
296 Static device_detach_t __CONCAT(dname,_detach); \
298 Static devclass_t __CONCAT(dname,_devclass); \
300 Static device_method_t __CONCAT(dname,_methods)[] = { \
301 DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
302 DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
303 DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
308 Static driver_t __CONCAT(dname,_driver) = { \
310 __CONCAT(dname,_methods), \
311 sizeof(struct __CONCAT(dname,_softc)) \
313 #define METHODS_NONE {0,0}
314 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
316 #define USB_MATCH(dname) \
318 __CONCAT(dname,_match)(device_t self)
320 #define USB_MATCH_START(dname, uaa) \
321 struct usb_attach_arg *uaa = device_get_ivars(self)
323 #define USB_MATCH_SETUP \
326 #define USB_ATTACH(dname) \
328 __CONCAT(dname,_attach)(device_t self)
330 #define USB_ATTACH_START(dname, sc, uaa) \
331 struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
332 struct usb_attach_arg *uaa = device_get_ivars(self)
334 /* Returns from attach */
335 #define USB_ATTACH_ERROR_RETURN return ENXIO
336 #define USB_ATTACH_SUCCESS_RETURN return 0
338 #define USB_ATTACH_SETUP \
340 device_set_desc_copy(self, devinfo)
342 #define USB_DETACH(dname) \
344 __CONCAT(dname,_detach)(device_t self)
346 #define USB_DETACH_START(dname, sc) \
347 struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
349 #define USB_GET_SC_OPEN(dname, unit, sc) \
350 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
354 #define USB_GET_SC(dname, unit, sc) \
355 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
357 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
358 (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
360 /* conversion from one type of queue to the other */
361 /* XXX In FreeBSD SIMPLEQ_REMOVE_HEAD only removes the head element.
363 #define SIMPLEQ_REMOVE_HEAD(h, e, f) do { \
364 if ( (e) != SIMPLEQ_FIRST((h)) ) \
365 panic("Removing other than first element"); \
366 STAILQ_REMOVE_HEAD(h, f); \
368 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD
369 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL
370 #define SIMPLEQ_NEXT STAILQ_NEXT
371 #define SIMPLEQ_FIRST STAILQ_FIRST
372 #define SIMPLEQ_HEAD STAILQ_HEAD
373 #define SIMPLEQ_INIT STAILQ_INIT
374 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER
375 #define SIMPLEQ_ENTRY STAILQ_ENTRY
377 #include <sys/syslog.h>
379 #define logprintf(args...) log(LOG_DEBUG, args)
381 #define logprintf printf
384 SYSCTL_DECL(_hw_usb);
387 #endif /* __FreeBSD__ */