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

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

Add binding of USB address and devman handle to usbhc iface

  • Property mode set to 100644
File size: 8.5 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 usb
30 * @{
31 */
32/** @file
33 * @brief USB interface definition.
34 */
35
36#ifndef LIBDRV_USBHC_IFACE_H_
37#define LIBDRV_USBHC_IFACE_H_
38
39#include "driver.h"
40#include <usb/usb.h>
41
42
43/** IPC methods for communication with HC through DDF interface.
44 *
45 * Notes for async methods:
46 *
47 * Methods for sending data to device (OUT transactions)
48 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
49 * always use the same semantics:
50 * - first, IPC call with given method is made
51 * - argument #1 is target address
52 * - argument #2 is target endpoint
53 * - argument #3 is buffer size
54 * - this call is immediately followed by IPC data write (from caller)
55 * - the initial call (and the whole transaction) is answer after the
56 * transaction is scheduled by the HC and acknowledged by the device
57 * or immediately after error is detected
58 * - the answer carries only the error code
59 *
60 * Methods for retrieving data from device (IN transactions)
61 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
62 * also use the same semantics:
63 * - first, IPC call with given method is made
64 * - argument #1 is target address
65 * - argument #2 is target endpoint
66 * - argument #3 is buffer size
67 * - the call is not answered until the device returns some data (or until
68 * error occurs)
69 * - if the call is answered with EOK, first argument of the answer is buffer
70 * hash that could be used to retrieve the actual data
71 *
72 * Some special methods (NO-DATA transactions) do not send any data. These
73 * might behave as both OUT or IN transactions because communication parts
74 * where actual buffers are exchanged are omitted.
75 *
76 * The mentioned data retrieval can be done any time after receiving EOK
77 * answer to IN method.
78 * This retrieval is done using the IPC_M_USBHC_GET_BUFFER where
79 * the first argument is buffer hash from call answer.
80 * This call must be immediately followed by data read-in and after the
81 * data are transferred, the initial call (IPC_M_USBHC_GET_BUFFER)
82 * is answered. Each buffer can be retrieved only once.
83 *
84 * For all these methods, wrap functions exists. Important rule: functions
85 * for IN transactions have (as parameters) buffers where retrieved data
86 * will be stored. These buffers must be already allocated and shall not be
87 * touch until the transaction is completed
88 * (e.g. not before calling usb_wait_for() with appropriate handle).
89 * OUT transactions buffers can be freed immediately after call is dispatched
90 * (i.e. after return from wrapping function).
91 *
92 */
93typedef enum {
94 /** Tell USB address assigned to device.
95 * Parameters:
96 * - devman handle id
97 * Answer:
98 * - EINVAL - unknown handle or handle not managed by this driver
99 * - ENOTSUP - operation not supported by HC (shall not happen)
100 * - arbitrary error code if returned by remote implementation
101 * - EOK - handle found, first parameter contains the USB address
102 */
103 IPC_M_USBHC_GET_ADDRESS,
104
105 /** Asks for data buffer.
106 * See explanation at usb_iface_funcs_t.
107 * This function does not have counter part in functional interface
108 * as it is handled by the remote part itself.
109 */
110 IPC_M_USBHC_GET_BUFFER,
111
112
113 /** Reserve usage of default address.
114 * This call informs the host controller that the caller will be
115 * using default USB address. It is duty of the HC driver to ensure
116 * that only single entity will have it reserved.
117 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
118 * The caller can start using the address after receiving EOK
119 * answer.
120 */
121 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
122
123 /** Release usage of default address.
124 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
125 */
126 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
127
128 /** Asks for address assignment by host controller.
129 * Answer:
130 * - ELIMIT - host controller run out of address
131 * - EOK - address assigned
132 * Answer arguments:
133 * - assigned address
134 *
135 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
136 */
137 IPC_M_USBHC_REQUEST_ADDRESS,
138
139 /** Bind USB address with devman handle.
140 * Parameters:
141 * - USB address
142 * - devman handle
143 * Answer:
144 * - EOK - address binded
145 * - ENOENT - address is not in use
146 */
147 IPC_M_USBHC_BIND_ADDRESS,
148
149 /** Release address in use.
150 * Arguments:
151 * - address to be released
152 * Answer:
153 * - ENOENT - address not in use
154 * - EPERM - trying to release default USB address
155 */
156 IPC_M_USBHC_RELEASE_ADDRESS,
157
158
159 /** Send interrupt data to device.
160 * See explanation at usb_iface_funcs_t (OUT transaction).
161 */
162 IPC_M_USBHC_INTERRUPT_OUT,
163
164 /** Get interrupt data from device.
165 * See explanation at usb_iface_funcs_t (IN transaction).
166 */
167 IPC_M_USBHC_INTERRUPT_IN,
168
169
170 /** Start WRITE control transfer.
171 * See explanation at usb_iface_funcs_t (OUT transaction).
172 */
173 IPC_M_USBHC_CONTROL_WRITE_SETUP,
174
175 /** Send control-transfer data to device.
176 * See explanation at usb_iface_funcs_t (OUT transaction).
177 */
178 IPC_M_USBHC_CONTROL_WRITE_DATA,
179
180 /** Terminate WRITE control transfer.
181 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
182 */
183 IPC_M_USBHC_CONTROL_WRITE_STATUS,
184
185
186
187 /** Start READ control transfer.
188 * See explanation at usb_iface_funcs_t (OUT transaction).
189 */
190 IPC_M_USBHC_CONTROL_READ_SETUP,
191
192 /** Get control-transfer data from device.
193 * See explanation at usb_iface_funcs_t (IN transaction).
194 */
195 IPC_M_USBHC_CONTROL_READ_DATA,
196
197 /** Terminate READ control transfer.
198 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
199 */
200 IPC_M_USBHC_CONTROL_READ_STATUS,
201
202
203 /* IPC_M_USB_ */
204} usbhc_iface_funcs_t;
205
206/** Callback for outgoing transfer. */
207typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
208 usb_transaction_outcome_t, void *);
209
210/** Callback for incoming transfer. */
211typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
212 usb_transaction_outcome_t, size_t, void *);
213
214
215/** Out transfer processing function prototype. */
216typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t,
217 void *, size_t,
218 usbhc_iface_transfer_out_callback_t, void *);
219
220/** Setup transfer processing function prototype. */
221typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
222
223/** In transfer processing function prototype. */
224typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t,
225 void *, size_t,
226 usbhc_iface_transfer_in_callback_t, void *);
227
228/** USB devices communication interface. */
229typedef struct {
230 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
231
232 int (*reserve_default_address)(device_t *);
233 int (*release_default_address)(device_t *);
234 int (*request_address)(device_t *, usb_address_t *);
235 int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
236 int (*release_address)(device_t *, usb_address_t);
237
238 usbhc_iface_transfer_out_t interrupt_out;
239 usbhc_iface_transfer_in_t interrupt_in;
240
241 usbhc_iface_transfer_setup_t control_write_setup;
242 usbhc_iface_transfer_out_t control_write_data;
243 int (*control_write_status)(device_t *, usb_target_t,
244 usbhc_iface_transfer_in_callback_t, void *);
245
246 usbhc_iface_transfer_setup_t control_read_setup;
247 usbhc_iface_transfer_in_t control_read_data;
248 int (*control_read_status)(device_t *, usb_target_t,
249 usbhc_iface_transfer_out_callback_t, void *);
250} usbhc_iface_t;
251
252
253#endif
254/**
255 * @}
256 */
Note: See TracBrowser for help on using the repository browser.