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

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

Rename batch_* ⇒ usb_transfer_batch_*

No change in functionality.

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