916e1b1e7cad1a03ceed6c21e8258a4a5fdcd3df
[dragonfly.git] / sys / bus / usb / usb_port.h
1 /*
2  * $OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $
3  * $NetBSD: usb_port.h,v 1.68 2005/07/30 06:14:50 skrll Exp $
4  * $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.65 2003/11/09 23:54:21 joe Exp $
5  * $DragonFly: src/sys/bus/usb/usb_port.h,v 1.17 2007/06/26 08:36:24 hasso Exp $
6  */
7
8 /* Also already merged from NetBSD:
9  *      $NetBSD: usb_port.h,v 1.57 2002/09/27 20:42:01 thorpej Exp $
10  *      $NetBSD: usb_port.h,v 1.58 2002/10/01 01:25:26 thorpej Exp $
11  */
12
13 /*
14  * Copyright (c) 1998 The NetBSD Foundation, Inc.
15  * All rights reserved.
16  *
17  * This code is derived from software contributed to The NetBSD Foundation
18  * by Lennart Augustsson (lennart@augustsson.net) at
19  * Carlstedt Research & Technology.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  * 3. All advertising materials mentioning features or use of this software
30  *    must display the following acknowledgement:
31  *        This product includes software developed by the NetBSD
32  *        Foundation, Inc. and its contributors.
33  * 4. Neither the name of The NetBSD Foundation nor the names of its
34  *    contributors may be used to endorse or promote products derived
35  *    from this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
38  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
39  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
41  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  * POSSIBILITY OF SUCH DAMAGE.
48  */
49
50 #ifndef _USB_PORT_H
51 #define _USB_PORT_H
52
53 /*
54  * Macros to ease the import of USB drivers from other BSD systems.
55  */
56
57 #include "opt_usb.h"
58
59 #if defined(_KERNEL)
60 #include <sys/malloc.h>
61
62 MALLOC_DECLARE(M_USB);
63 MALLOC_DECLARE(M_USBDEV);
64 MALLOC_DECLARE(M_USBHC);
65
66 #endif
67
68 #define USBVERBOSE
69
70 #define Static static
71
72 #define device_ptr_t device_t
73 #define USBBASEDEVICE device_t
74 #define USBDEV(bdev) (bdev)
75 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
76 #define USBDEVUNIT(bdev) device_get_unit(bdev)
77 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
78 #define USBDEVUNIT(bdev) device_get_unit(bdev)
79 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
80
81 #define DECLARE_USB_DMA_T \
82         struct usb_dma_block; \
83         typedef struct { \
84                 struct usb_dma_block *block; \
85                 u_int offs; \
86                 u_int len; \
87         } usb_dma_t
88
89 #define PROC_LOCK(p)
90 #define PROC_UNLOCK(p)
91 #define uio_procp uio_td
92
93 #define selwakeuppri(p, pri)    selwakeup(p)
94
95 typedef struct thread *usb_proc_ptr;
96
97 #define config_pending_incr()
98 #define config_pending_decr()
99
100 #define usb_kthread_create(f, s)                        \
101                 kthread_create(f, s, NULL, "dummy")
102 #define usb_kthread_create1(f, s, p, name, arg)         \
103                 kthread_create(f, s, p, name, arg)
104 #define usb_kthread_create2(f, s, p, name)              \
105                 kthread_create(f, s, p, name)
106
107 typedef struct callout usb_callout_t;
108 #define usb_callout_init(h)     callout_init(&(h))
109 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
110 #define usb_uncallout(h, f, d)  callout_stop(&(h))
111
112 #define ETHER_ALIGN             2
113
114 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
115 #define clfree(p) clist_free_cblocks((p))
116
117 #define PWR_RESUME 0
118 #define PWR_SUSPEND 1
119
120 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
121
122 typedef struct malloc_type *usb_malloc_type;
123
124 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
125 Static device_probe_t __CONCAT(dname,_match); \
126 Static device_attach_t __CONCAT(dname,_attach); \
127 Static device_detach_t __CONCAT(dname,_detach); \
128 \
129 Static devclass_t __CONCAT(dname,_devclass); \
130 \
131 Static device_method_t __CONCAT(dname,_methods)[] = { \
132         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
133         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
134         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
135         init, \
136         {0,0} \
137 }; \
138 \
139 Static driver_t __CONCAT(dname,_driver) = { \
140         #dname, \
141         __CONCAT(dname,_methods), \
142         sizeof(struct __CONCAT(dname,_softc)) \
143 }; \
144 MODULE_DEPEND(dname, usb, 1, 1, 1)
145
146
147 #define METHODS_NONE                    {0,0}
148 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
149
150 #define USB_MATCH(dname) \
151 Static int \
152 __CONCAT(dname,_match)(device_t self)
153
154 #define USB_MATCH_START(dname, uaa) \
155         struct usb_attach_arg *uaa = device_get_ivars(self)
156
157 #define USB_MATCH_SETUP \
158         sc->sc_dev = self
159
160 #define USB_ATTACH(dname) \
161 Static int \
162 __CONCAT(dname,_attach)(device_t self)
163
164 #define USB_ATTACH_START(dname, sc, uaa) \
165         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
166         struct usb_attach_arg *uaa = device_get_ivars(self)
167
168 /* Returns from attach */
169 #define USB_ATTACH_ERROR_RETURN         return ENXIO
170 #define USB_ATTACH_SUCCESS_RETURN       return 0
171
172 #define USB_ATTACH_SETUP \
173         sc->sc_dev = self; \
174         device_set_desc_copy(self, devinfo)
175
176 #define USB_DETACH(dname) \
177 Static int \
178 __CONCAT(dname,_detach)(device_t self)
179
180 #define USB_DETACH_START(dname, sc) \
181         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
182
183 #define USB_GET_SC_OPEN(dname, unit, sc) \
184         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
185         if (sc == NULL) \
186                 return (ENXIO)
187
188 #define USB_GET_SC(dname, unit, sc) \
189         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
190
191 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
192         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
193
194 /* conversion from one type of queue to the other */
195 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
196 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
197 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
198 #define SIMPLEQ_NEXT            STAILQ_NEXT
199 #define SIMPLEQ_FIRST           STAILQ_FIRST
200 #define SIMPLEQ_HEAD            STAILQ_HEAD
201 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
202 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
203 #define SIMPLEQ_INIT            STAILQ_INIT
204 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
205 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
206
207 #define logprintf               kprintf
208
209 #ifdef SYSCTL_DECL
210 SYSCTL_DECL(_hw_usb);
211 #endif
212
213 #endif /* _USB_PORT_H */
214