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

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

Doxygen

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