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