source: mainline/uspace/drv/uhci-hcd/iface.c@ 8870230

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8870230 was 8870230, checked in by Jan Vesely <jano.vesely@…>, 15 years ago

Remove useless parameters from bandwidth reservation API.
Add UHCI bandwidth reservation stubs

  • Property mode set to 100644
File size: 13.4 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky, Jan Vesely
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/** @addtogroup drvusbuhcihc
29 * @{
30 */
31/** @file
32 * @brief UHCI driver hc interface implementation
33 */
34#include <ddf/driver.h>
35#include <errno.h>
36
37#include <usb/debug.h>
38
39#include "iface.h"
40#include "hc.h"
41
42/** Reserve default address interface function
43 *
44 * @param[in] fun DDF function that was called.
45 * @param[in] speed Speed to associate with the new default address.
46 * @return Error code.
47 */
48static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
49{
50 assert(fun);
51 hc_t *hc = fun_to_hc(fun);
52 assert(hc);
53 usb_log_debug("Default address request with speed %d.\n", speed);
54 usb_device_keeper_reserve_default_address(&hc->manager, speed);
55 return EOK;
56}
57/*----------------------------------------------------------------------------*/
58/** Release default address interface function
59 *
60 * @param[in] fun DDF function that was called.
61 * @return Error code.
62 */
63static int release_default_address(ddf_fun_t *fun)
64{
65 assert(fun);
66 hc_t *hc = fun_to_hc(fun);
67 assert(hc);
68 usb_log_debug("Default address release.\n");
69 usb_device_keeper_release_default_address(&hc->manager);
70 return EOK;
71}
72/*----------------------------------------------------------------------------*/
73/** Request address interface function
74 *
75 * @param[in] fun DDF function that was called.
76 * @param[in] speed Speed to associate with the new default address.
77 * @param[out] address Place to write a new address.
78 * @return Error code.
79 */
80static int request_address(
81 ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
82{
83 assert(fun);
84 hc_t *hc = fun_to_hc(fun);
85 assert(hc);
86 assert(address);
87
88 usb_log_debug("Address request with speed %d.\n", speed);
89 *address = device_keeper_get_free_address(&hc->manager, speed);
90 usb_log_debug("Address request with result: %d.\n", *address);
91 if (*address <= 0)
92 return *address;
93 return EOK;
94}
95/*----------------------------------------------------------------------------*/
96/** Bind address interface function
97 *
98 * @param[in] fun DDF function that was called.
99 * @param[in] address Address of the device
100 * @param[in] handle Devman handle of the device driver.
101 * @return Error code.
102 */
103static int bind_address(
104 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
105{
106 assert(fun);
107 hc_t *hc = fun_to_hc(fun);
108 assert(hc);
109 usb_log_debug("Address bind %d-%d.\n", address, handle);
110 usb_device_keeper_bind(&hc->manager, address, handle);
111 return EOK;
112}
113/*----------------------------------------------------------------------------*/
114/** Release address interface function
115 *
116 * @param[in] fun DDF function that was called.
117 * @param[in] address USB address to be released.
118 * @return Error code.
119 */
120static int release_address(ddf_fun_t *fun, usb_address_t address)
121{
122 assert(fun);
123 hc_t *hc = fun_to_hc(fun);
124 assert(hc);
125 usb_log_debug("Address release %d.\n", address);
126 usb_device_keeper_release(&hc->manager, address);
127 return EOK;
128}
129/*----------------------------------------------------------------------------*/
130static int register_endpoint(
131 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
132 usb_transfer_type_t transfer_type, usb_direction_t direction,
133 size_t max_packet_size, unsigned int interval)
134{
135 return ENOTSUP;
136}
137/*----------------------------------------------------------------------------*/
138static int unregister_endpoint(
139 ddf_fun_t *fun, usb_address_t address,
140 usb_endpoint_t endpoint, usb_direction_t direction)
141{
142 return ENOTSUP;
143}
144/*----------------------------------------------------------------------------*/
145/** Interrupt out transaction interface function
146 *
147 * @param[in] fun DDF function that was called.
148 * @param[in] target USB device to write to.
149 * @param[in] max_packet_size maximum size of data packet the device accepts
150 * @param[in] data Source of data.
151 * @param[in] size Size of data source.
152 * @param[in] callback Function to call on transaction completion
153 * @param[in] arg Additional for callback function.
154 * @return Error code.
155 */
156static int interrupt_out(
157 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
158 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
159{
160 assert(fun);
161 hc_t *hc = fun_to_hc(fun);
162 assert(hc);
163 usb_speed_t speed =
164 usb_device_keeper_get_speed(&hc->manager, target.address);
165
166 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
167 target.address, target.endpoint, size, max_packet_size);
168
169 usb_transfer_batch_t *batch =
170 batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
171 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
172 if (!batch)
173 return ENOMEM;
174 batch_interrupt_out(batch);
175 const int ret = hc_schedule(hc, batch);
176 if (ret != EOK) {
177 batch_dispose(batch);
178 }
179 return ret;
180}
181/*----------------------------------------------------------------------------*/
182/** Interrupt in transaction interface function
183 *
184 * @param[in] fun DDF function that was called.
185 * @param[in] target USB device to write to.
186 * @param[in] max_packet_size maximum size of data packet the device accepts
187 * @param[out] data Data destination.
188 * @param[in] size Size of data source.
189 * @param[in] callback Function to call on transaction completion
190 * @param[in] arg Additional for callback function.
191 * @return Error code.
192 */
193static int interrupt_in(
194 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
195 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
196{
197 assert(fun);
198 hc_t *hc = fun_to_hc(fun);
199 assert(hc);
200 usb_speed_t speed =
201 usb_device_keeper_get_speed(&hc->manager, target.address);
202 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
203 target.address, target.endpoint, size, max_packet_size);
204
205 usb_transfer_batch_t *batch =
206 batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
207 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
208 if (!batch)
209 return ENOMEM;
210 batch_interrupt_in(batch);
211 const int ret = hc_schedule(hc, batch);
212 if (ret != EOK) {
213 batch_dispose(batch);
214 }
215 return ret;
216}
217/*----------------------------------------------------------------------------*/
218/** Bulk out transaction interface function
219 *
220 * @param[in] fun DDF function that was called.
221 * @param[in] target USB device to write to.
222 * @param[in] max_packet_size maximum size of data packet the device accepts
223 * @param[in] data Source of data.
224 * @param[in] size Size of data source.
225 * @param[in] callback Function to call on transaction completion
226 * @param[in] arg Additional for callback function.
227 * @return Error code.
228 */
229static int bulk_out(
230 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
231 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
232{
233 assert(fun);
234 hc_t *hc = fun_to_hc(fun);
235 assert(hc);
236 usb_speed_t speed =
237 usb_device_keeper_get_speed(&hc->manager, target.address);
238
239 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
240 target.address, target.endpoint, size, max_packet_size);
241
242 usb_transfer_batch_t *batch =
243 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
244 data, size, NULL, 0, NULL, callback, arg, &hc->manager);
245 if (!batch)
246 return ENOMEM;
247 batch_bulk_out(batch);
248 const int ret = hc_schedule(hc, batch);
249 if (ret != EOK) {
250 batch_dispose(batch);
251 }
252 return ret;
253}
254/*----------------------------------------------------------------------------*/
255/** Bulk in transaction interface function
256 *
257 * @param[in] fun DDF function that was called.
258 * @param[in] target USB device to write to.
259 * @param[in] max_packet_size maximum size of data packet the device accepts
260 * @param[out] data Data destination.
261 * @param[in] size Size of data source.
262 * @param[in] callback Function to call on transaction completion
263 * @param[in] arg Additional for callback function.
264 * @return Error code.
265 */
266static int bulk_in(
267 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
268 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
269{
270 assert(fun);
271 hc_t *hc = fun_to_hc(fun);
272 assert(hc);
273 usb_speed_t speed =
274 usb_device_keeper_get_speed(&hc->manager, target.address);
275 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
276 target.address, target.endpoint, size, max_packet_size);
277
278 usb_transfer_batch_t *batch =
279 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
280 data, size, NULL, 0, callback, NULL, arg, &hc->manager);
281 if (!batch)
282 return ENOMEM;
283 batch_bulk_in(batch);
284 const int ret = hc_schedule(hc, batch);
285 if (ret != EOK) {
286 batch_dispose(batch);
287 }
288 return ret;
289}
290/*----------------------------------------------------------------------------*/
291/** Control write transaction interface function
292 *
293 * @param[in] fun DDF function that was called.
294 * @param[in] target USB device to write to.
295 * @param[in] max_packet_size maximum size of data packet the device accepts.
296 * @param[in] setup_data Data to send with SETUP transfer.
297 * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
298 * @param[in] data Source of data.
299 * @param[in] size Size of data source.
300 * @param[in] callback Function to call on transaction completion.
301 * @param[in] arg Additional for callback function.
302 * @return Error code.
303 */
304static int control_write(
305 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
306 void *setup_data, size_t setup_size, void *data, size_t size,
307 usbhc_iface_transfer_out_callback_t callback, void *arg)
308{
309 assert(fun);
310 hc_t *hc = fun_to_hc(fun);
311 assert(hc);
312 usb_speed_t speed =
313 usb_device_keeper_get_speed(&hc->manager, target.address);
314 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
315 speed, target.address, target.endpoint, size, max_packet_size);
316
317 if (setup_size != 8)
318 return EINVAL;
319
320 usb_transfer_batch_t *batch =
321 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
322 data, size, setup_data, setup_size, NULL, callback, arg,
323 &hc->manager);
324 if (!batch)
325 return ENOMEM;
326 usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
327 batch_control_write(batch);
328 const int ret = hc_schedule(hc, batch);
329 if (ret != EOK) {
330 batch_dispose(batch);
331 }
332 return ret;
333}
334/*----------------------------------------------------------------------------*/
335/** Control read transaction interface function
336 *
337 * @param[in] fun DDF function that was called.
338 * @param[in] target USB device to write to.
339 * @param[in] max_packet_size maximum size of data packet the device accepts.
340 * @param[in] setup_data Data to send with SETUP packet.
341 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
342 * @param[out] data Source of data.
343 * @param[in] size Size of data source.
344 * @param[in] callback Function to call on transaction completion.
345 * @param[in] arg Additional for callback function.
346 * @return Error code.
347 */
348static int control_read(
349 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
350 void *setup_data, size_t setup_size, void *data, size_t size,
351 usbhc_iface_transfer_in_callback_t callback, void *arg)
352{
353 assert(fun);
354 hc_t *hc = fun_to_hc(fun);
355 assert(hc);
356 usb_speed_t speed =
357 usb_device_keeper_get_speed(&hc->manager, target.address);
358
359 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
360 speed, target.address, target.endpoint, size, max_packet_size);
361 usb_transfer_batch_t *batch =
362 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
363 data, size, setup_data, setup_size, callback, NULL, arg,
364 &hc->manager);
365 if (!batch)
366 return ENOMEM;
367 batch_control_read(batch);
368 const int ret = hc_schedule(hc, batch);
369 if (ret != EOK) {
370 batch_dispose(batch);
371 }
372 return ret;
373}
374/*----------------------------------------------------------------------------*/
375usbhc_iface_t hc_iface = {
376 .reserve_default_address = reserve_default_address,
377 .release_default_address = release_default_address,
378 .request_address = request_address,
379 .bind_address = bind_address,
380 .release_address = release_address,
381
382 .register_endpoint = register_endpoint,
383 .unregister_endpoint = unregister_endpoint,
384
385 .interrupt_out = interrupt_out,
386 .interrupt_in = interrupt_in,
387
388 .bulk_out = bulk_out,
389 .bulk_in = bulk_in,
390
391 .control_write = control_write,
392 .control_read = control_read,
393};
394/**
395 * @}
396 */
Note: See TracBrowser for help on using the repository browser.