Nuke device_ptr_t, USBBASEDEVICE, USBDEVNAME(), USBDEVUNIT(), USBGETSOFTC(),
[dragonfly.git] / sys / bus / usb / usbdivar.h
blob0783b89d2429a0a534602083b752e17822d702dc
1 /* $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.43.2.1 2006/03/01 01:59:05 iedowse Exp $ */
3 /* $DragonFly: src/sys/bus/usb/usbdivar.h,v 1.8 2007/06/28 06:32:31 hasso Exp $ */
5 /*
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (lennart@augustsson.net) at
11 * Carlstedt Research & Technology.
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.
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.
43 /* From usb_mem.h */
44 DECLARE_USB_DMA_T;
46 struct usbd_xfer;
47 struct usbd_pipe;
49 struct usbd_endpoint {
50 usb_endpoint_descriptor_t *edesc;
51 int refcnt;
52 int savedtoggle;
55 struct usbd_bus_methods {
56 usbd_status (*open_pipe)(struct usbd_pipe *pipe);
57 void (*soft_intr)(void *);
58 void (*do_poll)(struct usbd_bus *);
59 usbd_status (*allocm)(struct usbd_bus *, usb_dma_t *,
60 u_int32_t bufsize);
61 void (*freem)(struct usbd_bus *, usb_dma_t *);
62 struct usbd_xfer * (*allocx)(struct usbd_bus *);
63 void (*freex)(struct usbd_bus *, struct usbd_xfer *);
66 struct usbd_pipe_methods {
67 usbd_status (*transfer)(usbd_xfer_handle xfer);
68 usbd_status (*start)(usbd_xfer_handle xfer);
69 void (*abort)(usbd_xfer_handle xfer);
70 void (*close)(usbd_pipe_handle pipe);
71 void (*cleartoggle)(usbd_pipe_handle pipe);
72 void (*done)(usbd_xfer_handle xfer);
75 struct usbd_tt {
76 struct usbd_hub *hub;
79 struct usbd_port {
80 usb_port_status_t status;
81 u_int16_t power; /* mA of current on port */
82 u_int8_t portno;
83 u_int8_t restartcnt;
84 #define USBD_RESTART_MAX 5
85 struct usbd_device *device; /* Connected device */
86 struct usbd_device *parent; /* The ports hub */
87 struct usbd_tt *tt; /* Transaction translator (if any) */
90 struct usbd_hub {
91 usbd_status (*explore)(usbd_device_handle hub);
92 void *hubsoftc;
93 usb_hub_descriptor_t hubdesc;
94 struct usbd_port ports[1];
97 struct usb_softc;
99 /*****/
101 struct usbd_bus {
102 /* Filled by HC driver */
103 device_t bdev; /* base device, host adapter */
104 struct usbd_bus_methods *methods;
105 u_int32_t pipe_size; /* size of a pipe struct */
106 /* Filled by usb driver */
107 struct usbd_device *root_hub;
108 usbd_device_handle devices[USB_MAX_DEVICES];
109 char needs_explore;/* a hub a signalled a change */
110 char use_polling;
111 struct usb_softc *usbctl;
112 struct usb_device_stats stats;
113 int intr_context;
114 u_int no_intrs;
115 int usbrev; /* USB revision */
116 #define USBREV_UNKNOWN 0
117 #define USBREV_PRE_1_0 1
118 #define USBREV_1_0 2
119 #define USBREV_1_1 3
120 #define USBREV_2_0 4
121 #define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0" }
123 #ifdef USB_USE_SOFTINTR
124 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
125 void *soft; /* soft interrupt cookie */
126 #else
127 struct callout softi;
128 #endif
129 #endif
131 bus_dma_tag_t dmatag; /* DMA tag */
134 struct usbd_device {
135 struct usbd_bus *bus; /* our controller */
136 struct usbd_pipe *default_pipe; /* pipe 0 */
137 u_int8_t address; /* device addess */
138 u_int8_t config; /* current configuration # */
139 u_int8_t depth; /* distance from root hub */
140 u_int8_t speed; /* low/full/high speed */
141 u_int8_t self_powered; /* flag for self powered */
142 u_int16_t power; /* mA the device uses */
143 int16_t langid; /* language for strings */
144 #define USBD_NOLANG (-1)
145 usb_event_cookie_t cookie; /* unique connection id */
146 struct usbd_port *powersrc; /* upstream hub port, or 0 */
147 struct usbd_device *myhub; /* upstream hub */
148 struct usbd_port *myhsport; /* closest high speed port */
149 struct usbd_endpoint def_ep; /* for pipe 0 */
150 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
151 struct usbd_interface *ifaces; /* array of all interfaces */
152 usb_device_descriptor_t ddesc; /* device descriptor */
153 usb_config_descriptor_t *cdesc; /* full config descr */
154 const struct usbd_quirks *quirks; /* device quirks, always set */
155 struct usbd_hub *hub; /* only if this is a hub */
156 device_t *subdevs; /* sub-devices, 0 terminated */
157 uint8_t *ifacenums; /* sub-device interfacenumbers */
160 struct usbd_interface {
161 struct usbd_device *device;
162 usb_interface_descriptor_t *idesc;
163 int index;
164 int altindex;
165 struct usbd_endpoint *endpoints;
166 void *priv;
167 LIST_HEAD(, usbd_pipe) pipes;
170 struct usbd_pipe {
171 struct usbd_interface *iface;
172 struct usbd_device *device;
173 struct usbd_endpoint *endpoint;
174 int refcnt;
175 char running;
176 char aborting;
177 SIMPLEQ_HEAD(, usbd_xfer) queue;
178 LIST_ENTRY(usbd_pipe) next;
180 usbd_xfer_handle intrxfer; /* used for repeating requests */
181 char repeat;
182 int interval;
184 /* Filled by HC driver. */
185 struct usbd_pipe_methods *methods;
188 struct usbd_xfer {
189 struct usbd_pipe *pipe;
190 void *priv;
191 void *buffer;
192 u_int32_t length;
193 u_int32_t actlen;
194 u_int16_t flags;
195 u_int32_t timeout;
196 usbd_status status;
197 usbd_callback callback;
198 __volatile char done;
199 #ifdef DIAGNOSTIC
200 u_int32_t busy_free;
201 #define XFER_FREE 0x46524545
202 #define XFER_BUSY 0x42555359
203 #define XFER_ONQU 0x4f4e5155
204 #endif
206 /* For control pipe */
207 usb_device_request_t request;
209 /* For isoc */
210 u_int16_t *frlengths;
211 int nframes;
213 /* For memory allocation */
214 struct usbd_device *device;
215 usb_dma_t dmabuf;
217 int rqflags;
218 #define URQ_REQUEST 0x01
219 #define URQ_AUTO_DMABUF 0x10
220 #define URQ_DEV_DMABUF 0x20
222 SIMPLEQ_ENTRY(usbd_xfer) next;
224 void *hcpriv; /* private use by the HC driver */
226 usb_callout_t timeout_handle;
229 void usbd_init(void);
230 void usbd_finish(void);
232 #ifdef USB_DEBUG
233 void usbd_dump_iface(struct usbd_interface *iface);
234 void usbd_dump_device(struct usbd_device *dev);
235 void usbd_dump_endpoint(struct usbd_endpoint *endp);
236 void usbd_dump_queue(usbd_pipe_handle pipe);
237 void usbd_dump_pipe(usbd_pipe_handle pipe);
238 #endif
240 /* Routines from usb_subr.c */
241 int usbctlprint(void *, const char *);
242 void usb_delay_ms(usbd_bus_handle, u_int);
243 usbd_status usbd_reset_port(usbd_device_handle dev,
244 int port, usb_port_status_t *ps);
245 usbd_status usbd_setup_pipe(usbd_device_handle dev,
246 usbd_interface_handle iface,
247 struct usbd_endpoint *, int,
248 usbd_pipe_handle *pipe);
249 usbd_status usbd_new_device(device_t parent,
250 usbd_bus_handle bus, int depth,
251 int lowspeed, int port,
252 struct usbd_port *);
253 void usbd_remove_device(usbd_device_handle, struct usbd_port *);
254 int usbd_printBCD(char *cp, int bcd);
255 usbd_status usbd_fill_iface_data(usbd_device_handle dev, int i, int a);
256 void usb_free_device(usbd_device_handle);
258 usbd_status usb_insert_transfer(usbd_xfer_handle xfer);
259 void usb_transfer_complete(usbd_xfer_handle xfer);
260 void usb_disconnect_port(struct usbd_port *up, device_t);
262 /* Routines from usb.c */
263 void usb_needs_explore(usbd_device_handle);
264 void usb_schedsoftintr(struct usbd_bus *);
266 /* Locator stuff. */
268 /* XXX these values are used to statically bind some elements in the USB tree
269 * to specific driver instances. This should be somehow emulated in FreeBSD
270 * but can be done later on.
271 * The values are copied from the files.usb file in the NetBSD sources.
273 #define UHUBCF_PORT_DEFAULT -1
274 #define UHUBCF_CONFIGURATION_DEFAULT -1
275 #define UHUBCF_INTERFACE_DEFAULT -1
276 #define UHUBCF_VENDOR_DEFAULT -1
277 #define UHUBCF_PRODUCT_DEFAULT -1
278 #define UHUBCF_RELEASE_DEFAULT -1
280 #define uhubcf_port cf_loc[UHUBCF_PORT]
281 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
282 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
283 #define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
284 #define uhubcf_product cf_loc[UHUBCF_PRODUCT]
285 #define uhubcf_release cf_loc[UHUBCF_RELEASE]
286 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
287 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
288 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
289 #define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
290 #define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
291 #define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */