]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/usb/usb_port.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 /* 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 $
8  */
9
10 /*-
11  * Copyright (c) 1998 The NetBSD Foundation, Inc.
12  * All rights reserved.
13  *
14  * This code is derived from software contributed to The NetBSD Foundation
15  * by Lennart Augustsson (lennart@augustsson.net) at
16  * Carlstedt Research & Technology.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
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.
33  *
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.
45  */
46
47 #ifndef _USB_PORT_H
48 #define _USB_PORT_H
49
50 /*
51  * Macro's to cope with the differences between operating systems.
52  */
53
54 /*
55  * FreeBSD
56  */
57
58 /* We don't use the soft interrupt code in FreeBSD. */
59 #if 0
60 #define USB_USE_SOFTINTR
61 #endif
62
63 #define Static static
64
65 #define device_ptr_t device_t
66 #define USBBASEDEVICE device_t
67 #define USBDEV(bdev) (bdev)
68 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
69 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
70 #define USBDEVUNIT(bdev) device_get_unit(bdev)
71 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
72
73 #define DECLARE_USB_DMA_T \
74         struct usb_dma_block; \
75         typedef struct { \
76                 struct usb_dma_block *block; \
77                 u_int offs; \
78                 u_int len; \
79         } usb_dma_t
80
81 typedef struct thread *usb_proc_ptr;
82
83 #define uio_procp uio_td
84
85 #define usb_kthread_create1(f, s, p, a0, a1) \
86                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
87 #define usb_kthread_create2(f, s, p, a0) \
88                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
89 #define usb_kthread_create      kthread_create
90
91 #define config_pending_incr()
92 #define config_pending_decr()
93
94 typedef struct callout usb_callout_t;
95 #define usb_callout_init(h)     callout_init(&(h), 0)
96 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
97 #define usb_uncallout(h, f, d)  callout_stop(&(h))
98 #define usb_uncallout_drain(h, f, d)  callout_drain(&(h))
99
100 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
101 #define clfree(p) clist_free_cblocks((p))
102
103 #define config_detach(dev, flag) \
104         do { \
105                 device_detach(dev); \
106                 free(device_get_ivars(dev), M_USB); \
107                 device_delete_child(device_get_parent(dev), dev); \
108         } while (0);
109
110 typedef struct malloc_type *usb_malloc_type;
111
112 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
113 static device_probe_t __CONCAT(dname,_match); \
114 static device_attach_t __CONCAT(dname,_attach); \
115 static device_detach_t __CONCAT(dname,_detach); \
116 \
117 static devclass_t __CONCAT(dname,_devclass); \
118 \
119 static device_method_t __CONCAT(dname,_methods)[] = { \
120         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
121         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
122         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
123         init, \
124         {0,0} \
125 }; \
126 \
127 static driver_t __CONCAT(dname,_driver) = { \
128         #dname, \
129         __CONCAT(dname,_methods), \
130         sizeof(struct __CONCAT(dname,_softc)) \
131 }; \
132 MODULE_DEPEND(dname, usb, 1, 1, 1)
133
134
135 #define METHODS_NONE                    {0,0}
136 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
137
138 #define USB_MATCH(dname) \
139 static int \
140 __CONCAT(dname,_match)(device_t self)
141
142 #define USB_MATCH_START(dname, uaa) \
143         struct usb_attach_arg *uaa = device_get_ivars(self)
144
145 #define USB_MATCH_SETUP \
146         sc->sc_dev = self
147
148 #define USB_ATTACH(dname) \
149 static int \
150 __CONCAT(dname,_attach)(device_t self)
151
152 #define USB_ATTACH_START(dname, sc, uaa) \
153         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
154         struct usb_attach_arg *uaa = device_get_ivars(self)
155
156 /* Returns from attach */
157 #define USB_ATTACH_ERROR_RETURN return ENXIO
158 #define USB_ATTACH_SUCCESS_RETURN       return 0
159
160 #define USB_ATTACH_SETUP \
161         sc->sc_dev = self; \
162
163 #define USB_DETACH(dname) \
164 static int \
165 __CONCAT(dname,_detach)(device_t self)
166
167 #define USB_DETACH_START(dname, sc) \
168         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
169
170 #define USB_GET_SC_OPEN(dname, unit, sc) \
171         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
172         if (sc == NULL) \
173                 return (ENXIO)
174
175 #define USB_GET_SC(dname, unit, sc) \
176         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
177
178 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
179         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
180
181 /* conversion from one type of queue to the other */
182 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
183 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
184 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
185 #define SIMPLEQ_NEXT            STAILQ_NEXT
186 #define SIMPLEQ_FIRST           STAILQ_FIRST
187 #define SIMPLEQ_HEAD            STAILQ_HEAD
188 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
189 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
190 #define SIMPLEQ_INIT            STAILQ_INIT
191 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
192 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
193
194 #include <sys/syslog.h>
195 /*
196 #define logprintf(args...)      log(LOG_DEBUG, args)
197 */
198 #define logprintf               printf
199
200 #endif /* _USB_PORT_H */