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

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

Add address reservation to USBHC interface in DDF

Any USB driver that needs to assign new USB address shall ask its HC
for it. When using default USB address (address 0), it must inform
HC about it as HC is the only element able to provide serialization.

  • Property mode set to 100644
File size: 8.2 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 /** Release address in use.
140 * Arguments:
141 * - address to be released
142 * Answer:
143 * - ENOENT - address not in use
144 * - EPERM - trying to release default USB address
145 */
146 IPC_M_USBHC_RELEASE_ADDRESS,
147
148
149 /** Send interrupt data to device.
150 * See explanation at usb_iface_funcs_t (OUT transaction).
151 */
152 IPC_M_USBHC_INTERRUPT_OUT,
153
154 /** Get interrupt data from device.
155 * See explanation at usb_iface_funcs_t (IN transaction).
156 */
157 IPC_M_USBHC_INTERRUPT_IN,
158
159
160 /** Start WRITE control transfer.
161 * See explanation at usb_iface_funcs_t (OUT transaction).
162 */
163 IPC_M_USBHC_CONTROL_WRITE_SETUP,
164
165 /** Send control-transfer data to device.
166 * See explanation at usb_iface_funcs_t (OUT transaction).
167 */
168 IPC_M_USBHC_CONTROL_WRITE_DATA,
169
170 /** Terminate WRITE control transfer.
171 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
172 */
173 IPC_M_USBHC_CONTROL_WRITE_STATUS,
174
175
176
177 /** Start READ control transfer.
178 * See explanation at usb_iface_funcs_t (OUT transaction).
179 */
180 IPC_M_USBHC_CONTROL_READ_SETUP,
181
182 /** Get control-transfer data from device.
183 * See explanation at usb_iface_funcs_t (IN transaction).
184 */
185 IPC_M_USBHC_CONTROL_READ_DATA,
186
187 /** Terminate READ control transfer.
188 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
189 */
190 IPC_M_USBHC_CONTROL_READ_STATUS,
191
192
193 /* IPC_M_USB_ */
194} usbhc_iface_funcs_t;
195
196/** Callback for outgoing transfer. */
197typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
198 usb_transaction_outcome_t, void *);
199
200/** Callback for incoming transfer. */
201typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
202 usb_transaction_outcome_t, size_t, void *);
203
204
205/** Out transfer processing function prototype. */
206typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t,
207 void *, size_t,
208 usbhc_iface_transfer_out_callback_t, void *);
209
210/** Setup transfer processing function prototype. */
211typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
212
213/** In transfer processing function prototype. */
214typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t,
215 void *, size_t,
216 usbhc_iface_transfer_in_callback_t, void *);
217
218/** USB devices communication interface. */
219typedef struct {
220 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
221
222 int (*reserve_default_address)(device_t *);
223 int (*release_default_address)(device_t *);
224 int (*request_address)(device_t *, usb_address_t *);
225 int (*release_address)(device_t *, usb_address_t);
226
227 usbhc_iface_transfer_out_t interrupt_out;
228 usbhc_iface_transfer_in_t interrupt_in;
229
230 usbhc_iface_transfer_setup_t control_write_setup;
231 usbhc_iface_transfer_out_t control_write_data;
232 int (*control_write_status)(device_t *, usb_target_t,
233 usbhc_iface_transfer_in_callback_t, void *);
234
235 usbhc_iface_transfer_setup_t control_read_setup;
236 usbhc_iface_transfer_in_t control_read_data;
237 int (*control_read_status)(device_t *, usb_target_t,
238 usbhc_iface_transfer_out_callback_t, void *);
239} usbhc_iface_t;
240
241
242#endif
243/**
244 * @}
245 */
Note: See TracBrowser for help on using the repository browser.