source: mainline/uspace/lib/drv/include/usbhc_iface.h@ ef7f043

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ef7f043 was 9753220, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Add atomic control transfers to remote USBHC

Only the remote part is implemented. This commit might have serious BUGS.

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdrv
30 * @addtogroup usb
31 * @{
32 */
33/** @file
34 * @brief USB host controller interface definition.
35 */
36
37#ifndef LIBDRV_USBHC_IFACE_H_
38#define LIBDRV_USBHC_IFACE_H_
39
40#include "driver.h"
41#include <usb/usb.h>
42
43
44/** IPC methods for communication with HC through DDF interface.
45 *
46 * Notes for async methods:
47 *
48 * Methods for sending data to device (OUT transactions)
49 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
50 * always use the same semantics:
51 * - first, IPC call with given method is made
52 * - argument #1 is target address
53 * - argument #2 is target endpoint
54 * - argument #3 is buffer size
55 * - this call is immediately followed by IPC data write (from caller)
56 * - the initial call (and the whole transaction) is answer after the
57 * transaction is scheduled by the HC and acknowledged by the device
58 * or immediately after error is detected
59 * - the answer carries only the error code
60 *
61 * Methods for retrieving data from device (IN transactions)
62 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
63 * also use the same semantics:
64 * - first, IPC call with given method is made
65 * - argument #1 is target address
66 * - argument #2 is target endpoint
67 * - argument #3 is buffer size
68 * - the call is not answered until the device returns some data (or until
69 * error occurs)
70 * - if the call is answered with EOK, first argument of the answer is buffer
71 * hash that could be used to retrieve the actual data
72 *
73 * Some special methods (NO-DATA transactions) do not send any data. These
74 * might behave as both OUT or IN transactions because communication parts
75 * where actual buffers are exchanged are omitted.
76 *
77 * The mentioned data retrieval can be done any time after receiving EOK
78 * answer to IN method.
79 * This retrieval is done using the IPC_M_USBHC_GET_BUFFER where
80 * the first argument is buffer hash from call answer.
81 * This call must be immediately followed by data read-in and after the
82 * data are transferred, the initial call (IPC_M_USBHC_GET_BUFFER)
83 * is answered. Each buffer can be retrieved only once.
84 *
85 * For all these methods, wrap functions exists. Important rule: functions
86 * for IN transactions have (as parameters) buffers where retrieved data
87 * will be stored. These buffers must be already allocated and shall not be
88 * touch until the transaction is completed
89 * (e.g. not before calling usb_wait_for() with appropriate handle).
90 * OUT transactions buffers can be freed immediately after call is dispatched
91 * (i.e. after return from wrapping function).
92 *
93 */
94typedef enum {
95 /** Tell USB address assigned to device.
96 * Parameters:
97 * - devman handle id
98 * Answer:
99 * - EINVAL - unknown handle or handle not managed by this driver
100 * - ENOTSUP - operation not supported by HC (shall not happen)
101 * - arbitrary error code if returned by remote implementation
102 * - EOK - handle found, first parameter contains the USB address
103 */
104 IPC_M_USBHC_GET_ADDRESS,
105
106 /** Asks for data buffer.
107 * See explanation at usb_iface_funcs_t.
108 * This function does not have counter part in functional interface
109 * as it is handled by the remote part itself.
110 */
111 IPC_M_USBHC_GET_BUFFER,
112
113
114 /** Reserve usage of default address.
115 * This call informs the host controller that the caller will be
116 * using default USB address. It is duty of the HC driver to ensure
117 * that only single entity will have it reserved.
118 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
119 * The caller can start using the address after receiving EOK
120 * answer.
121 */
122 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
123
124 /** Release usage of default address.
125 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
126 */
127 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
128
129 /** Asks for address assignment by host controller.
130 * Answer:
131 * - ELIMIT - host controller run out of address
132 * - EOK - address assigned
133 * Answer arguments:
134 * - assigned address
135 *
136 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
137 */
138 IPC_M_USBHC_REQUEST_ADDRESS,
139
140 /** Bind USB address with devman handle.
141 * Parameters:
142 * - USB address
143 * - devman handle
144 * Answer:
145 * - EOK - address binded
146 * - ENOENT - address is not in use
147 */
148 IPC_M_USBHC_BIND_ADDRESS,
149
150 /** Release address in use.
151 * Arguments:
152 * - address to be released
153 * Answer:
154 * - ENOENT - address not in use
155 * - EPERM - trying to release default USB address
156 */
157 IPC_M_USBHC_RELEASE_ADDRESS,
158
159
160 /** Send interrupt data to device.
161 * See explanation at usb_iface_funcs_t (OUT transaction).
162 */
163 IPC_M_USBHC_INTERRUPT_OUT,
164
165 /** Get interrupt data from device.
166 * See explanation at usb_iface_funcs_t (IN transaction).
167 */
168 IPC_M_USBHC_INTERRUPT_IN,
169
170
171 /** Start WRITE control transfer.
172 * See explanation at usb_iface_funcs_t (OUT transaction).
173 */
174 IPC_M_USBHC_CONTROL_WRITE_SETUP,
175
176 /** Send control-transfer data to device.
177 * See explanation at usb_iface_funcs_t (OUT transaction).
178 */
179 IPC_M_USBHC_CONTROL_WRITE_DATA,
180
181 /** Terminate WRITE control transfer.
182 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
183 */
184 IPC_M_USBHC_CONTROL_WRITE_STATUS,
185
186
187
188 /** Start READ control transfer.
189 * See explanation at usb_iface_funcs_t (OUT transaction).
190 */
191 IPC_M_USBHC_CONTROL_READ_SETUP,
192
193 /** Get control-transfer data from device.
194 * See explanation at usb_iface_funcs_t (IN transaction).
195 */
196 IPC_M_USBHC_CONTROL_READ_DATA,
197
198 /** Terminate READ control transfer.
199 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
200 */
201 IPC_M_USBHC_CONTROL_READ_STATUS,
202
203 /** Issue control WRITE transfer.
204 * See explanation at usb_iface_funcs_t (OUT transaction) for
205 * call parameters.
206 * This call is immediately followed by two IPC data writes
207 * from the caller (setup packet and actual data).
208 */
209 IPC_M_USBHC_CONTROL_WRITE,
210
211 /** Issue control WRITE transfer.
212 * See explanation at usb_iface_funcs_t (IN transaction) for
213 * call parameters.
214 * This call is immediately followed by IPC data read from the caller
215 * (setup packet).
216 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER.
217 */
218 IPC_M_USBHC_CONTROL_READ,
219
220 /* IPC_M_USB_ */
221} usbhc_iface_funcs_t;
222
223/** Callback for outgoing transfer. */
224typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
225 usb_transaction_outcome_t, void *);
226
227/** Callback for incoming transfer. */
228typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
229 usb_transaction_outcome_t, size_t, void *);
230
231
232/** Out transfer processing function prototype. */
233typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t,
234 void *, size_t,
235 usbhc_iface_transfer_out_callback_t, void *);
236
237/** Setup transfer processing function prototype. */
238typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
239
240/** In transfer processing function prototype. */
241typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t,
242 void *, size_t,
243 usbhc_iface_transfer_in_callback_t, void *);
244
245/** USB host controller communication interface. */
246typedef struct {
247 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
248
249 int (*reserve_default_address)(device_t *);
250 int (*release_default_address)(device_t *);
251 int (*request_address)(device_t *, usb_address_t *);
252 int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
253 int (*release_address)(device_t *, usb_address_t);
254
255 usbhc_iface_transfer_out_t interrupt_out;
256 usbhc_iface_transfer_in_t interrupt_in;
257
258 usbhc_iface_transfer_setup_t control_write_setup;
259 usbhc_iface_transfer_out_t control_write_data;
260 int (*control_write_status)(device_t *, usb_target_t,
261 usbhc_iface_transfer_in_callback_t, void *);
262
263 usbhc_iface_transfer_setup_t control_read_setup;
264 usbhc_iface_transfer_in_t control_read_data;
265 int (*control_read_status)(device_t *, usb_target_t,
266 usbhc_iface_transfer_out_callback_t, void *);
267
268 int (*control_write)(device_t *, usb_target_t,
269 void *, size_t, void *, size_t,
270 usbhc_iface_transfer_out_callback_t, void *);
271
272 int (*control_read)(device_t *, usb_target_t,
273 void *, size_t, void *, size_t,
274 usbhc_iface_transfer_in_callback_t, void *);
275} usbhc_iface_t;
276
277
278#endif
279/**
280 * @}
281 */
Note: See TracBrowser for help on using the repository browser.