]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/usb_port.h
Consolidate the device recognition code.
[FreeBSD/FreeBSD.git] / 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.54 2002/03/28 21:49:19 ichiro Exp $     */
3 /*      $FreeBSD$       */
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 #define USB_USE_SOFTINTR
57
58 #ifdef USB_DEBUG
59 #define Static
60 #else
61 #define Static static
62 #endif
63
64 #define SCSI_MODE_SENSE         MODE_SENSE
65
66 typedef struct proc *usb_proc_ptr;
67
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))
75
76 #define DECLARE_USB_DMA_T \
77         struct usb_dma_block; \
78         typedef struct { \
79                 struct usb_dma_block *block; \
80                 u_int offs; \
81         } usb_dma_t
82
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))
87
88 #define usb_kthread_create1     kthread_create1
89 #define usb_kthread_create      kthread_create
90
91 typedef int usb_malloc_type;
92
93 #define Ether_ifattach ether_ifattach
94 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
95
96 #define logprintf printf
97
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); \
103 \
104 extern struct cfdriver __CONCAT(dname,_cd); \
105 \
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), \
112 }
113
114 #define USB_MATCH(dname) \
115 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
116
117 #define USB_MATCH_START(dname, uaa) \
118         struct usb_attach_arg *uaa = aux
119
120 #define USB_ATTACH(dname) \
121 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
122
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
127
128 /* Returns from attach */
129 #define USB_ATTACH_ERROR_RETURN return
130 #define USB_ATTACH_SUCCESS_RETURN       return
131
132 #define USB_ATTACH_SETUP printf("\n")
133
134 #define USB_DETACH(dname) \
135 int __CONCAT(dname,_detach)(struct device *self, int flags)
136
137 #define USB_DETACH_START(dname, sc) \
138         struct __CONCAT(dname,_softc) *sc = \
139                 (struct __CONCAT(dname,_softc) *)self
140
141 #define USB_GET_SC_OPEN(dname, unit, sc) \
142         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
143                 return (ENXIO); \
144         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
145         if (sc == NULL) \
146                 return (ENXIO)
147
148 #define USB_GET_SC(dname, unit, sc) \
149         sc = __CONCAT(dname,_cd).cd_devs[unit]
150
151 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
152         (config_found_sm(parent, args, print, sub))
153
154 #elif defined(__OpenBSD__)
155 /*
156  * OpenBSD
157  */
158 #define Static
159
160 typedef struct proc *usb_proc_ptr;
161
162 #define UCOMBUSCF_PORTNO                -1
163 #define UCOMBUSCF_PORTNO_DEFAULT        -1
164
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
180
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)
185
186 /*
187  * The UHCI/OHCI controllers are little endian, so on big endian machines
188  * the data strored in memory needs to be swapped.
189  */
190
191 #if defined(letoh32)
192 #define le32toh(x) letoh32(x)
193 #define le16toh(x) letoh16(x)
194 #endif
195
196 #define usb_kthread_create1     kthread_create
197 #define usb_kthread_create      kthread_create_deferred
198
199 #define config_pending_incr()
200 #define config_pending_decr()
201
202 typedef int usb_malloc_type;
203
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;                                        \
208                                                                         \
209         eh = mtod(m, struct ether_header *);                            \
210         m_adj(m, sizeof(struct ether_header));                          \
211         ether_input((ifp), (eh), (m));                                  \
212 } while (0)
213
214 #define usbpoll                 usbselect
215 #define uhidpoll                uhidselect
216 #define ugenpoll                ugenselect
217 #define uriopoll                urioselect
218 #define uscannerpoll            uscannerselect
219
220 #define powerhook_establish(fn, sc) (fn)
221 #define powerhook_disestablish(hdl)
222 #define PWR_RESUME 0
223
224 #define logprintf printf
225
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
229
230 #define realloc usb_realloc
231 void *usb_realloc(void *, u_int, int, int);
232
233 extern int cold;
234
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))
242
243 #define DECLARE_USB_DMA_T \
244         struct usb_dma_block; \
245         typedef struct { \
246                 struct usb_dma_block *block; \
247                 u_int offs; \
248         } usb_dma_t
249
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))
254
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); \
260 \
261 struct cfdriver __CONCAT(dname,_cd) = { \
262         NULL, #dname, DV_DULL \
263 }; \
264 \
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), \
271 }
272
273 #define USB_MATCH(dname) \
274 int \
275 __CONCAT(dname,_match)(parent, match, aux) \
276         struct device *parent; \
277         void *match; \
278         void *aux;
279
280 #define USB_MATCH_START(dname, uaa) \
281         struct usb_attach_arg *uaa = aux
282
283 #define USB_ATTACH(dname) \
284 void \
285 __CONCAT(dname,_attach)(parent, self, aux) \
286         struct device *parent; \
287         struct device *self; \
288         void *aux;
289
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
294
295 /* Returns from attach */
296 #define USB_ATTACH_ERROR_RETURN return
297 #define USB_ATTACH_SUCCESS_RETURN       return
298
299 #define USB_ATTACH_SETUP printf("\n")
300
301 #define USB_DETACH(dname) \
302 int \
303 __CONCAT(dname,_detach)(self, flags) \
304         struct device *self; \
305         int flags;
306
307 #define USB_DETACH_START(dname, sc) \
308         struct __CONCAT(dname,_softc) *sc = \
309                 (struct __CONCAT(dname,_softc) *)self
310
311 #define USB_GET_SC_OPEN(dname, unit, sc) \
312         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
313                 return (ENXIO); \
314         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
315         if (sc == NULL) \
316                 return (ENXIO)
317
318 #define USB_GET_SC(dname, unit, sc) \
319         sc = __CONCAT(dname,_cd).cd_devs[unit]
320
321 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
322         (config_found_sm(parent, args, print, sub))
323
324 #elif defined(__FreeBSD__)
325 /*
326  * FreeBSD
327  */
328
329 #include "opt_usb.h"
330
331 #if defined(_KERNEL)
332 #include <sys/malloc.h>
333
334 MALLOC_DECLARE(M_USB);
335 MALLOC_DECLARE(M_USBDEV);
336 MALLOC_DECLARE(M_USBHC);
337
338 #endif
339
340 #define USBVERBOSE
341
342 #define USB_USE_SOFTINTR
343
344 #define Static static
345
346 #define device_ptr_t device_t
347 #define USBBASEDEVICE device_t
348 #define USBDEV(bdev) (bdev)
349 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
350 #define USBDEVUNIT(bdev) device_get_unit(bdev)
351 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
352 #define USBDEVUNIT(bdev) device_get_unit(bdev)
353 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
354
355 #define DECLARE_USB_DMA_T typedef char * usb_dma_t
356
357 typedef struct thread *usb_proc_ptr;
358
359 #define uio_procp uio_td
360
361 /* XXX Change this when FreeBSD has memset */
362 #define memcpy(d, s, l)         bcopy((s),(d),(l))
363 #define memset(d, v, l)         bzero((d),(l))
364 #define usb_kthread_create1(f, s, p, a0, a1) \
365                 kthread_create((f), (s), (p), RFHIGHPID, (a0), (a1))
366 #define usb_kthread_create2(f, s, p, a0) \
367                 kthread_create((f), (s), (p), RFHIGHPID, (a0))
368 #define usb_kthread_create      kthread_create
369
370 #define config_pending_incr()
371 #define config_pending_decr()
372
373 typedef struct callout usb_callout_t;
374 #define usb_callout_init(h)     callout_init(&(h), 0)
375 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
376 #define usb_uncallout(h, f, d)  callout_stop(&(h))
377
378 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
379 #define clfree(p) clist_free_cblocks((p))
380
381 #define PWR_RESUME 0
382 #define PWR_SUSPEND 1
383
384 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
385
386 typedef struct malloc_type *usb_malloc_type;
387
388 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
389 Static device_probe_t __CONCAT(dname,_match); \
390 Static device_attach_t __CONCAT(dname,_attach); \
391 Static device_detach_t __CONCAT(dname,_detach); \
392 \
393 Static devclass_t __CONCAT(dname,_devclass); \
394 \
395 Static device_method_t __CONCAT(dname,_methods)[] = { \
396         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
397         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
398         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
399         init, \
400         {0,0} \
401 }; \
402 \
403 Static driver_t __CONCAT(dname,_driver) = { \
404         #dname, \
405         __CONCAT(dname,_methods), \
406         sizeof(struct __CONCAT(dname,_softc)) \
407 }; \
408 MODULE_DEPEND(dname, usb, 1, 1, 1)
409
410
411 #define METHODS_NONE                    {0,0}
412 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
413
414 #define USB_MATCH(dname) \
415 Static int \
416 __CONCAT(dname,_match)(device_t self)
417
418 #define USB_MATCH_START(dname, uaa) \
419         struct usb_attach_arg *uaa = device_get_ivars(self)
420
421 #define USB_MATCH_SETUP \
422         sc->sc_dev = self
423
424 #define USB_ATTACH(dname) \
425 Static int \
426 __CONCAT(dname,_attach)(device_t self)
427
428 #define USB_ATTACH_START(dname, sc, uaa) \
429         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
430         struct usb_attach_arg *uaa = device_get_ivars(self)
431
432 /* Returns from attach */
433 #define USB_ATTACH_ERROR_RETURN return ENXIO
434 #define USB_ATTACH_SUCCESS_RETURN       return 0
435
436 #define USB_ATTACH_SETUP \
437         sc->sc_dev = self; \
438         device_set_desc_copy(self, devinfo)
439
440 #define USB_DETACH(dname) \
441 Static int \
442 __CONCAT(dname,_detach)(device_t self)
443
444 #define USB_DETACH_START(dname, sc) \
445         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
446
447 #define USB_GET_SC_OPEN(dname, unit, sc) \
448         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
449         if (sc == NULL) \
450                 return (ENXIO)
451
452 #define USB_GET_SC(dname, unit, sc) \
453         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
454
455 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
456         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
457
458 /* conversion from one type of queue to the other */
459 /* XXX In FreeBSD SIMPLEQ_REMOVE_HEAD only removes the head element.
460  */
461 #define SIMPLEQ_REMOVE_HEAD(h, e, f)    do {                            \
462                 if ( (e) != SIMPLEQ_FIRST((h)) )                        \
463                         panic("Removing other than first element");     \
464                 STAILQ_REMOVE_HEAD(h, f);                               \
465 } while (0)
466 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
467 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
468 #define SIMPLEQ_NEXT            STAILQ_NEXT
469 #define SIMPLEQ_FIRST           STAILQ_FIRST
470 #define SIMPLEQ_HEAD            STAILQ_HEAD
471 #define SIMPLEQ_INIT            STAILQ_INIT
472 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
473 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
474
475 #include <sys/syslog.h>
476 /*
477 #define logprintf(args...)      log(LOG_DEBUG, args)
478 */
479 #define logprintf               printf
480
481 #ifdef SYSCTL_DECL
482 SYSCTL_DECL(_hw_usb);
483 #endif
484
485 #endif /* __FreeBSD__ */
486
487 #endif /* _USB_PORT_H */
488