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

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

Endpoint registration sends address as well

This is the first step towards using endpoint registration instead
of reservation of default address.

  • Property mode set to 100644
File size: 8.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 "ddf/driver.h"
41#include <usb/usb.h>
42#include <bool.h>
43
44
45/** IPC methods for communication with HC through DDF interface.
46 *
47 * Notes for async methods:
48 *
49 * Methods for sending data to device (OUT transactions)
50 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
51 * always use the same semantics:
52 * - first, IPC call with given method is made
53 * - argument #1 is target address
54 * - argument #2 is target endpoint
55 * - argument #3 is max packet size of the endpoint
56 * - this call is immediately followed by IPC data write (from caller)
57 * - the initial call (and the whole transaction) is answer after the
58 * transaction is scheduled by the HC and acknowledged by the device
59 * or immediately after error is detected
60 * - the answer carries only the error code
61 *
62 * Methods for retrieving data from device (IN transactions)
63 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
64 * also use the same semantics:
65 * - first, IPC call with given method is made
66 * - argument #1 is target address
67 * - argument #2 is target endpoint
68 * - this call is immediately followed by IPC data read (async version)
69 * - the call is not answered until the device returns some data (or until
70 * error occurs)
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 * For all these methods, wrap functions exists. Important rule: functions
77 * for IN transactions have (as parameters) buffers where retrieved data
78 * will be stored. These buffers must be already allocated and shall not be
79 * touch until the transaction is completed
80 * (e.g. not before calling usb_wait_for() with appropriate handle).
81 * OUT transactions buffers can be freed immediately after call is dispatched
82 * (i.e. after return from wrapping function).
83 *
84 */
85typedef enum {
86 /** Reserve usage of default address.
87 * This call informs the host controller that the caller will be
88 * using default USB address. It is duty of the HC driver to ensure
89 * that only single entity will have it reserved.
90 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
91 * The caller can start using the address after receiving EOK
92 * answer.
93 */
94 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
95
96 /** Release usage of default address.
97 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
98 */
99 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
100
101 /** Asks for address assignment by host controller.
102 * Answer:
103 * - ELIMIT - host controller run out of address
104 * - EOK - address assigned
105 * Answer arguments:
106 * - assigned address
107 *
108 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
109 */
110 IPC_M_USBHC_REQUEST_ADDRESS,
111
112 /** Bind USB address with devman handle.
113 * Parameters:
114 * - USB address
115 * - devman handle
116 * Answer:
117 * - EOK - address binded
118 * - ENOENT - address is not in use
119 */
120 IPC_M_USBHC_BIND_ADDRESS,
121
122 /** Release address in use.
123 * Arguments:
124 * - address to be released
125 * Answer:
126 * - ENOENT - address not in use
127 * - EPERM - trying to release default USB address
128 */
129 IPC_M_USBHC_RELEASE_ADDRESS,
130
131
132 /** Send interrupt data to device.
133 * See explanation at usb_iface_funcs_t (OUT transaction).
134 */
135 IPC_M_USBHC_INTERRUPT_OUT,
136
137 /** Get interrupt data from device.
138 * See explanation at usb_iface_funcs_t (IN transaction).
139 */
140 IPC_M_USBHC_INTERRUPT_IN,
141
142 /** Send bulk data to device.
143 * See explanation at usb_iface_funcs_t (OUT transaction).
144 */
145 IPC_M_USBHC_BULK_OUT,
146
147 /** Get bulk data from device.
148 * See explanation at usb_iface_funcs_t (IN transaction).
149 */
150 IPC_M_USBHC_BULK_IN,
151
152 /** Issue control WRITE transfer.
153 * See explanation at usb_iface_funcs_t (OUT transaction) for
154 * call parameters.
155 * This call is immediately followed by two IPC data writes
156 * from the caller (setup packet and actual data).
157 */
158 IPC_M_USBHC_CONTROL_WRITE,
159
160 /** Issue control READ transfer.
161 * See explanation at usb_iface_funcs_t (IN transaction) for
162 * call parameters.
163 * This call is immediately followed by IPC data write from the caller
164 * (setup packet) and IPC data read (buffer that was read).
165 */
166 IPC_M_USBHC_CONTROL_READ,
167
168 /** Register endpoint attributes at host controller.
169 * This is used to reserve portion of USB bandwidth.
170 * When speed is invalid, speed of the device is used.
171 * Parameters:
172 * - USB address + endpoint number
173 * - packed as ADDR << 16 + EP
174 * - speed + transfer type + direction
175 * - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
176 * - maximum packet size + interval (in milliseconds)
177 * - packed as MPS << 16 + INT
178 * Answer:
179 * - EOK - reservation successful
180 * - ELIMIT - not enough bandwidth to satisfy the request
181 */
182 IPC_M_USBHC_REGISTER_ENDPOINT,
183
184 /** Revert endpoint registration.
185 * Parameters:
186 * - USB address
187 * - endpoint number
188 * - data direction
189 * Answer:
190 * - EOK - endpoint unregistered
191 * - ENOENT - unknown endpoint
192 */
193 IPC_M_USBHC_UNREGISTER_ENDPOINT
194} usbhc_iface_funcs_t;
195
196/** Callback for outgoing transfer. */
197typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *,
198 int, void *);
199
200/** Callback for incoming transfer. */
201typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
202 int, size_t, void *);
203
204
205/** Out transfer processing function prototype. */
206typedef int (*usbhc_iface_transfer_out_t)(ddf_fun_t *, usb_target_t,
207 void *, size_t,
208 usbhc_iface_transfer_out_callback_t, void *);
209
210/** Setup transfer processing function prototype. @deprecated */
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)(ddf_fun_t *, usb_target_t,
215 void *, size_t,
216 usbhc_iface_transfer_in_callback_t, void *);
217
218/** USB host controller communication interface. */
219typedef struct {
220 int (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
221 int (*release_default_address)(ddf_fun_t *);
222 int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
223 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
224 int (*release_address)(ddf_fun_t *, usb_address_t);
225
226 int (*register_endpoint)(ddf_fun_t *,
227 usb_address_t, usb_speed_t, usb_endpoint_t,
228 usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
229 int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
230 usb_direction_t);
231
232 usbhc_iface_transfer_out_t interrupt_out;
233 usbhc_iface_transfer_in_t interrupt_in;
234
235 usbhc_iface_transfer_out_t bulk_out;
236 usbhc_iface_transfer_in_t bulk_in;
237
238 int (*control_write)(ddf_fun_t *, usb_target_t,
239 void *, size_t, void *, size_t,
240 usbhc_iface_transfer_out_callback_t, void *);
241
242 int (*control_read)(ddf_fun_t *, usb_target_t,
243 void *, size_t, void *, size_t,
244 usbhc_iface_transfer_in_callback_t, void *);
245} usbhc_iface_t;
246
247
248#endif
249/**
250 * @}
251 */
Note: See TracBrowser for help on using the repository browser.