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

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

Whitespace fixes (no functionality changed)

iface.c should be more or less identical

  • Property mode set to 100644
File size: 12.8 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(ddf_fun_t *fun, usb_speed_t speed,
81 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/*----------------------------------------------------------------------------*/
130/** Interrupt out transaction interface function
131 *
132 * @param[in] fun DDF function that was called.
133 * @param[in] target USB device to write to.
134 * @param[in] max_packet_size maximum size of data packet the device accepts
135 * @param[in] data Source of data.
136 * @param[in] size Size of data source.
137 * @param[in] callback Function to call on transaction completion
138 * @param[in] arg Additional for callback function.
139 * @return Error code.
140 */
141static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
142 size_t max_packet_size, void *data, size_t size,
143 usbhc_iface_transfer_out_callback_t callback, void *arg)
144{
145 assert(fun);
146 hc_t *hc = fun_to_hc(fun);
147 assert(hc);
148 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
149
150 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
151 target.address, target.endpoint, size, max_packet_size);
152
153 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
154 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
155 &hc->manager);
156 if (!batch)
157 return ENOMEM;
158 batch_interrupt_out(batch);
159 const int ret = hc_schedule(hc, batch);
160 if (ret != EOK) {
161 batch_dispose(batch);
162 return ret;
163 }
164 return EOK;
165}
166/*----------------------------------------------------------------------------*/
167/** Interrupt in transaction interface function
168 *
169 * @param[in] fun DDF function that was called.
170 * @param[in] target USB device to write to.
171 * @param[in] max_packet_size maximum size of data packet the device accepts
172 * @param[out] data Data destination.
173 * @param[in] size Size of data source.
174 * @param[in] callback Function to call on transaction completion
175 * @param[in] arg Additional for callback function.
176 * @return Error code.
177 */
178static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
179 size_t max_packet_size, void *data, size_t size,
180 usbhc_iface_transfer_in_callback_t callback, void *arg)
181{
182 assert(fun);
183 hc_t *hc = fun_to_hc(fun);
184 assert(hc);
185 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
186 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
187 target.address, target.endpoint, size, max_packet_size);
188
189 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
190 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
191 &hc->manager);
192 if (!batch)
193 return ENOMEM;
194 batch_interrupt_in(batch);
195 const int ret = hc_schedule(hc, batch);
196 if (ret != EOK) {
197 batch_dispose(batch);
198 return ret;
199 }
200 return EOK;
201}
202/*----------------------------------------------------------------------------*/
203/** Bulk out transaction interface function
204 *
205 * @param[in] fun DDF function that was called.
206 * @param[in] target USB device to write to.
207 * @param[in] max_packet_size maximum size of data packet the device accepts
208 * @param[in] data Source of data.
209 * @param[in] size Size of data source.
210 * @param[in] callback Function to call on transaction completion
211 * @param[in] arg Additional for callback function.
212 * @return Error code.
213 */
214static int bulk_out(ddf_fun_t *fun, usb_target_t target,
215 size_t max_packet_size, void *data, size_t size,
216 usbhc_iface_transfer_out_callback_t callback, void *arg)
217{
218 assert(fun);
219 hc_t *hc = fun_to_hc(fun);
220 assert(hc);
221 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
222
223 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
224 target.address, target.endpoint, size, max_packet_size);
225
226 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
227 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
228 &hc->manager);
229 if (!batch)
230 return ENOMEM;
231 batch_bulk_out(batch);
232 const int ret = hc_schedule(hc, batch);
233 if (ret != EOK) {
234 batch_dispose(batch);
235 return ret;
236 }
237 return EOK;
238}
239/*----------------------------------------------------------------------------*/
240/** Bulk in transaction interface function
241 *
242 * @param[in] fun DDF function that was called.
243 * @param[in] target USB device to write to.
244 * @param[in] max_packet_size maximum size of data packet the device accepts
245 * @param[out] data Data destination.
246 * @param[in] size Size of data source.
247 * @param[in] callback Function to call on transaction completion
248 * @param[in] arg Additional for callback function.
249 * @return Error code.
250 */
251static int bulk_in(ddf_fun_t *fun, usb_target_t target,
252 size_t max_packet_size, void *data, size_t size,
253 usbhc_iface_transfer_in_callback_t callback, void *arg)
254{
255 assert(fun);
256 hc_t *hc = fun_to_hc(fun);
257 assert(hc);
258 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
259 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
260 target.address, target.endpoint, size, max_packet_size);
261
262 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
263 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
264 &hc->manager);
265 if (!batch)
266 return ENOMEM;
267 batch_bulk_in(batch);
268 const int ret = hc_schedule(hc, batch);
269 if (ret != EOK) {
270 batch_dispose(batch);
271 return ret;
272 }
273 return EOK;
274}
275/*----------------------------------------------------------------------------*/
276/** Control write transaction interface function
277 *
278 * @param[in] fun DDF function that was called.
279 * @param[in] target USB device to write to.
280 * @param[in] max_packet_size maximum size of data packet the device accepts.
281 * @param[in] setup_data Data to send with SETUP packet.
282 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
283 * @param[in] data Source of data.
284 * @param[in] size Size of data source.
285 * @param[in] callback Function to call on transaction completion.
286 * @param[in] arg Additional for callback function.
287 * @return Error code.
288 */
289static int control_write(ddf_fun_t *fun, usb_target_t target,
290 size_t max_packet_size,
291 void *setup_data, size_t setup_size, void *data, size_t size,
292 usbhc_iface_transfer_out_callback_t callback, void *arg)
293{
294 assert(fun);
295 hc_t *hc = fun_to_hc(fun);
296 assert(hc);
297 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
298 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
299 speed, target.address, target.endpoint, size, max_packet_size);
300
301 if (setup_size != 8)
302 return EINVAL;
303
304 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
305 max_packet_size, speed, data, size, setup_data, setup_size,
306 NULL, callback, arg, &hc->manager);
307 if (!batch)
308 return ENOMEM;
309 usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
310 batch_control_write(batch);
311 const int ret = hc_schedule(hc, batch);
312 if (ret != EOK) {
313 batch_dispose(batch);
314 return ret;
315 }
316 return EOK;
317}
318/*----------------------------------------------------------------------------*/
319/** Control read transaction interface function
320 *
321 * @param[in] fun DDF function that was called.
322 * @param[in] target USB device to write to.
323 * @param[in] max_packet_size maximum size of data packet the device accepts.
324 * @param[in] setup_data Data to send with SETUP packet.
325 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
326 * @param[out] data Source of data.
327 * @param[in] size Size of data source.
328 * @param[in] callback Function to call on transaction completion.
329 * @param[in] arg Additional for callback function.
330 * @return Error code.
331 */
332static int control_read(ddf_fun_t *fun, usb_target_t target,
333 size_t max_packet_size,
334 void *setup_data, size_t setup_size, void *data, size_t size,
335 usbhc_iface_transfer_in_callback_t callback, void *arg)
336{
337 assert(fun);
338 hc_t *hc = fun_to_hc(fun);
339 assert(hc);
340 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, target.address);
341
342 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
343 speed, target.address, target.endpoint, size, max_packet_size);
344 usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
345 max_packet_size, speed, data, size, setup_data, setup_size, callback,
346 NULL, arg, &hc->manager);
347 if (!batch)
348 return ENOMEM;
349 batch_control_read(batch);
350 const int ret = hc_schedule(hc, batch);
351 if (ret != EOK) {
352 batch_dispose(batch);
353 return ret;
354 }
355 return EOK;
356}
357/*----------------------------------------------------------------------------*/
358usbhc_iface_t hc_iface = {
359 .reserve_default_address = reserve_default_address,
360 .release_default_address = release_default_address,
361 .request_address = request_address,
362 .bind_address = bind_address,
363 .release_address = release_address,
364
365 .interrupt_out = interrupt_out,
366 .interrupt_in = interrupt_in,
367
368 .bulk_out = bulk_out,
369 .bulk_in = bulk_in,
370
371 .control_write = control_write,
372 .control_read = control_read,
373};
374/**
375 * @}
376 */
Note: See TracBrowser for help on using the repository browser.