usbdivar.h revision 1.3 1 /* $NetBSD: usbdivar.h,v 1.3 1998/07/24 21:02:51 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Author: Lennart Augustsson <augustss (at) carlstedt.se>
8 * Carlstedt Research & Technology
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 struct usbd_request;
40 struct usbd_pipe;
41
42 struct usbd_endpoint {
43 usb_endpoint_descriptor_t *edesc;
44 usbd_endpoint_state state;
45 int refcnt;
46 int toggle; /* XXX */
47 };
48
49 typedef void (*usbd_xfercb)__P((usbd_request_handle req));
50
51 struct usbd_methods {
52 usbd_status (*transfer)__P((usbd_request_handle reqh));
53 void (*abort)__P((usbd_request_handle reqh));
54 void (*close)__P((usbd_pipe_handle pipe));
55 };
56
57 struct usbd_port {
58 usb_port_status_t status;
59 int power; /* mA of current on port */
60 struct usbd_device *device;
61 struct usbd_device *parent; /* The ports hub */
62 };
63
64 struct usbd_hub {
65 usbd_status (*explore)__P((struct device *parent,
66 usbd_device_handle hub));
67 void *hubdata;
68 usb_hub_descriptor_t hubdesc;
69 struct usbd_port ports[1];
70 };
71
72 struct usb_softc;
73
74 /*****/
75
76 struct usbd_bus {
77 /* Filled by HC driver */
78 struct device bdev; /* base device */
79 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
80 u_int32_t pipe_size; /* size of a pipe struct */
81 /* Filled by usb driver */
82 struct usbd_device *root_hub;
83 usbd_device_handle devices[USB_MAX_DEVICES];
84 char needs_explore;/* a hub a signalled a change */
85 struct usb_softc *usbctl;
86 };
87
88 struct usbd_device {
89 struct usbd_bus *bus;
90 usbd_device_state state;
91 struct usbd_pipe *default_pipe;
92 u_int8_t address;
93 u_int8_t depth;
94 u_int8_t lowspeed;
95 u_int16_t power;
96 u_int8_t self_powered;
97 int config;
98 struct usbd_port *powersrc;
99 struct usbd_endpoint def_ep; /* for pipe 0 */
100 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
101 struct usbd_interface *ifaces;
102 usb_device_descriptor_t ddesc;
103 usb_config_descriptor_t *cdesc; /* full config descr */
104 struct usbd_quirks *quirks;
105 struct usbd_hub *hub; /* only if this is a hub */
106 };
107
108 struct usbd_interface {
109 struct usbd_device *device;
110 usbd_interface_state state;
111 usb_interface_descriptor_t *idesc;
112 struct usbd_endpoint *endpoints;
113 void *priv;
114 LIST_HEAD(, usbd_pipe) pipes;
115 };
116
117 struct usbd_pipe {
118 struct usbd_interface *iface;
119 struct usbd_device *device;
120 struct usbd_endpoint *endpoint;
121 usbd_pipe_state state;
122 int32_t refcnt;
123 char running;
124 SIMPLEQ_HEAD(, usbd_request) queue;
125 LIST_ENTRY(usbd_pipe) next;
126
127 void (*disco) __P((void *));
128 void *discoarg;
129
130 usbd_request_handle intrreqh; /* used for repeating requests */
131 usbd_request_handle curreqh; /* currently running request */
132
133 /* Filled by HC driver. */
134 struct usbd_methods *methods;
135 };
136
137 struct usbd_request {
138 struct usbd_pipe *pipe;
139 void *priv;
140 void *buffer;
141 u_int32_t length;
142 u_int32_t actlen;
143 u_int16_t flags;
144 u_int32_t timeout;
145 usbd_status status;
146 usbd_callback callback;
147 usbd_xfercb xfercb;
148 u_int32_t retries;
149 char done;
150
151 usb_device_request_t request;
152 u_int8_t isreq;
153
154 SIMPLEQ_ENTRY(usbd_request) next;
155
156 void *hcpriv; /* XXX private use by the HC driver */
157 };
158
159 void usbd_init __P((void));
160
161 /* Routines from usb_subr.c */
162 int usbctlprint __P((void *, const char *));
163 void usbd_delay_ms __P((int));
164 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
165 usbd_status usbd_set_config_no __P((usbd_device_handle, int));
166 usbd_status usbd_reset_port __P((usbd_device_handle dev,
167 int port, usb_port_status_t *ps));
168 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
169 usbd_interface_handle iface,
170 struct usbd_endpoint *,
171 usbd_pipe_handle *pipe));
172 usbd_status usbd_new_device __P((struct device *parent,
173 usbd_bus_handle bus, int depth,
174 int lowspeed, int port,
175 struct usbd_port *));
176 int usbd_printBCD __P((char *cp, int bcd));
177
178 /* Routines from usb.c */
179 int usb_bus_count __P((void));
180 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
181 void usb_needs_explore __P((usbd_bus_handle));
182
183 extern int usbd_use_polling;
184
185 /* Locator stuff. */
186
187 #include "locators.h"
188
189 #define uhubcf_port cf_loc[UHUBCF_PORT]
190 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
191
192 /* Junk. */
193
194 /* XXX */
195 #define splusb splbio
196 #define IPL_USB IPL_BIO
197 /* XXX */
198
199