usbdivar.h revision 1.29 1 /* $NetBSD: usbdivar.h,v 1.29 1999/09/09 12:26:48 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) carlstedt.se) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /* From usb_mem.h */
41 #if defined(__NetBSD__) || defined(__OpenBSD__)
42 struct usb_dma_block;
43 typedef struct {
44 struct usb_dma_block *block;
45 u_int offs;
46 } usb_dma_t;
47 #elif defined(__FreeBSD__)
48 typedef void * usb_dma_t;
49 #endif
50
51 struct usbd_request;
52 struct usbd_pipe;
53
54 struct usbd_endpoint {
55 usb_endpoint_descriptor_t *edesc;
56 int refcnt;
57 };
58
59 struct usbd_bus_methods {
60 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
61 void (*do_poll)__P((struct usbd_bus *));
62 usbd_status (*allocm)__P((struct usbd_bus *, usb_dma_t *,
63 u_int32_t bufsize));
64 void (*freem)__P((struct usbd_bus *, usb_dma_t *));
65 };
66
67 struct usbd_pipe_methods {
68 usbd_status (*transfer)__P((usbd_request_handle reqh));
69 usbd_status (*start)__P((usbd_request_handle reqh));
70 void (*abort)__P((usbd_request_handle reqh));
71 void (*close)__P((usbd_pipe_handle pipe));
72 void (*cleartoggle)__P((usbd_pipe_handle pipe));
73 void (*done)__P((usbd_request_handle reqh));
74 };
75
76 struct usbd_port {
77 usb_port_status_t status;
78 u_int16_t power; /* mA of current on port */
79 u_int8_t portno;
80 u_int8_t restartcnt;
81 #define USBD_RESTART_MAX 5
82 struct usbd_device *device;
83 struct usbd_device *parent; /* The ports hub */
84 };
85
86 struct usbd_hub {
87 usbd_status (*explore)__P((usbd_device_handle hub));
88 void *hubsoftc;
89 usb_hub_descriptor_t hubdesc;
90 struct usbd_port ports[1];
91 };
92
93 struct usb_softc;
94
95 /*****/
96
97 struct usbd_bus {
98 /* Filled by HC driver */
99 USBBASEDEVICE bdev; /* base device, host adapter */
100 struct usbd_bus_methods *methods;
101 u_int32_t pipe_size; /* size of a pipe struct */
102 /* Filled by usb driver */
103 struct usbd_device *root_hub;
104 usbd_device_handle devices[USB_MAX_DEVICES];
105 char needs_explore;/* a hub a signalled a change */
106 char use_polling;
107 struct usb_softc *usbctl;
108 struct usb_device_stats stats;
109 };
110
111 struct usbd_device {
112 struct usbd_bus *bus;
113 struct usbd_pipe *default_pipe;
114 u_int8_t address;
115 u_int8_t depth;
116 u_int8_t lowspeed;
117 u_int16_t power;
118 u_int8_t self_powered;
119 int config;
120 int langid; /* language to use for strings */
121 #define USBD_NOLANG (-1)
122 struct usbd_port *powersrc;
123 struct usbd_endpoint def_ep; /* for pipe 0 */
124 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
125 struct usbd_interface *ifaces;
126 usb_device_descriptor_t ddesc;
127 usb_config_descriptor_t *cdesc; /* full config descr */
128 struct usbd_quirks *quirks;
129 struct usbd_hub *hub; /* only if this is a hub */
130 device_ptr_t *subdevs; /* sub-devices, 0 terminated */
131 };
132
133 struct usbd_interface {
134 struct usbd_device *device;
135 usb_interface_descriptor_t *idesc;
136 int index;
137 int altindex;
138 struct usbd_endpoint *endpoints;
139 void *priv;
140 LIST_HEAD(, usbd_pipe) pipes;
141 };
142
143 struct usbd_pipe {
144 struct usbd_interface *iface;
145 struct usbd_device *device;
146 struct usbd_endpoint *endpoint;
147 int refcnt;
148 char running;
149 SIMPLEQ_HEAD(, usbd_request) queue;
150 LIST_ENTRY(usbd_pipe) next;
151
152 usbd_request_handle intrreqh; /* used for repeating requests */
153 char repeat;
154
155 /* Filled by HC driver. */
156 struct usbd_pipe_methods *methods;
157 };
158
159 struct usbd_request {
160 struct usbd_pipe *pipe;
161 void *priv;
162 void *buffer;
163 u_int32_t length;
164 u_int32_t actlen;
165 u_int16_t flags;
166 u_int32_t timeout;
167 usbd_status status;
168 usbd_callback callback;
169 __volatile char done;
170
171 /* For control pipe */
172 usb_device_request_t request;
173
174 /* For isoc */
175 u_int16_t *frlengths;
176 int nframes;
177
178 /* For memory allocation */
179 struct usbd_device *dev;
180 usb_dma_t dmabuf;
181
182 int rqflags;
183 #define URQ_REQUEST 0x01
184 #define URQ_SYSDMABUF 0x10
185 #define URQ_USRDMABUF 0x20
186
187 SIMPLEQ_ENTRY(usbd_request) next;
188
189 void *hcpriv; /* private use by the HC driver */
190 int hcprivint; /* ditto */
191
192 #if defined(__FreeBSD__)
193 struct callout_handle timo_handle;
194 #endif
195 };
196
197 void usbd_init __P((void));
198
199 /* Routines from usb_subr.c */
200 int usbctlprint __P((void *, const char *));
201 void usb_delay_ms __P((usbd_bus_handle, u_int));
202 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
203 usbd_status usbd_reset_port __P((usbd_device_handle dev,
204 int port, usb_port_status_t *ps));
205 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
206 usbd_interface_handle iface,
207 struct usbd_endpoint *,
208 usbd_pipe_handle *pipe));
209 usbd_status usbd_new_device __P((device_ptr_t parent,
210 usbd_bus_handle bus, int depth,
211 int lowspeed, int port,
212 struct usbd_port *));
213 void usbd_remove_device __P((usbd_device_handle,
214 struct usbd_port *));
215 int usbd_printBCD __P((char *cp, int bcd));
216 usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
217 int i, int a));
218 void usb_free_device __P((usbd_device_handle));
219
220 usbd_status usb_insert_transfer __P((usbd_request_handle reqh));
221 void usb_transfer_complete __P((usbd_request_handle reqh));
222
223 /* Routines from usb.c */
224 int usb_bus_count __P((void));
225 void usb_needs_explore __P((usbd_bus_handle));
226
227 /* Locator stuff. */
228
229 #if defined(__NetBSD__)
230 #include "locators.h"
231 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
232 /* XXX these values are used to statically bind some elements in the USB tree
233 * to specific driver instances. This should be somehow emulated in FreeBSD
234 * but can be done later on.
235 * The values are copied from the files.usb file in the NetBSD sources.
236 */
237 #define UHUBCF_PORT_DEFAULT -1
238 #define UHUBCF_CONFIGURATION_DEFAULT -1
239 #define UHUBCF_INTERFACE_DEFAULT -1
240 #define UHUBCF_VENDOR_DEFAULT -1
241 #define UHUBCF_PRODUCT_DEFAULT -1
242 #define UHUBCF_RELEASE_DEFAULT -1
243 #endif
244
245 #if defined (__OpenBSD__)
246 #define UHUBCF_PORT 0
247 #define UHUBCF_CONFIGURATION 1
248 #define UHUBCF_INTERFACE 2
249 #define UHUBCF_VENDOR 3
250 #define UHUBCF_PRODUCT 4
251 #define UHUBCF_RELEASE 5
252 #endif
253
254 #define uhubcf_port cf_loc[UHUBCF_PORT]
255 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
256 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
257 #define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
258 #define uhubcf_product cf_loc[UHUBCF_PRODUCT]
259 #define uhubcf_release cf_loc[UHUBCF_RELEASE]
260 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
261 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
262 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
263 #define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
264 #define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
265 #define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
266
267