source: mainline/uspace/drv/vhc/connhost.c@ 70c85211

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

Virtual host controller works again

Added correct implementation of transfer_ops, thus making VHC ready
to be used with the hcdhubd mini-framework.

  • Property mode set to 100644
File size: 4.9 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 usb
30 * @{
31 */
32/** @file
33 * @brief Connection handling of calls from host (implementation).
34 */
35#include <assert.h>
36#include <errno.h>
37#include <usb/usb.h>
38
39#include "vhcd.h"
40#include "conn.h"
41#include "hc.h"
42
43typedef struct {
44 usb_direction_t direction;
45 usb_hcd_transfer_callback_out_t out_callback;
46 usb_hcd_transfer_callback_in_t in_callback;
47 usb_hc_device_t *hc;
48 void *arg;
49} transfer_info_t;
50
51static void universal_callback(void *buffer, size_t size,
52 usb_transaction_outcome_t outcome, void *arg)
53{
54 transfer_info_t *transfer = (transfer_info_t *) arg;
55
56 switch (transfer->direction) {
57 case USB_DIRECTION_IN:
58 transfer->in_callback(transfer->hc,
59 size, outcome,
60 transfer->arg);
61 break;
62 case USB_DIRECTION_OUT:
63 transfer->out_callback(transfer->hc,
64 outcome,
65 transfer->arg);
66 break;
67 default:
68 assert(false && "unreachable");
69 break;
70 }
71
72 free(transfer);
73}
74
75static transfer_info_t *create_transfer_info(usb_hc_device_t *hc,
76 usb_direction_t direction, void *arg)
77{
78 transfer_info_t *transfer = malloc(sizeof(transfer_info_t));
79
80 transfer->direction = direction;
81 transfer->in_callback = NULL;
82 transfer->out_callback = NULL;
83 transfer->arg = arg;
84 transfer->hc = hc;
85
86 return transfer;
87}
88
89static int enqueue_transfer_out(usb_hc_device_t *hc,
90 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
91 void *buffer, size_t size,
92 usb_hcd_transfer_callback_out_t callback, void *arg)
93{
94 printf(NAME ": transfer OUT [%d.%d (%s); %u]\n",
95 dev->address, endpoint->endpoint,
96 usb_str_transfer_type(endpoint->transfer_type),
97 size);
98
99 transfer_info_t *transfer
100 = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
101 transfer->out_callback = callback;
102
103 usb_target_t target = {
104 .address = dev->address,
105 .endpoint = endpoint->endpoint
106 };
107
108 hc_add_transaction_to_device(false, target, buffer, size,
109 universal_callback, transfer);
110
111 return EOK;
112}
113
114static int enqueue_transfer_setup(usb_hc_device_t *hc,
115 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
116 void *buffer, size_t size,
117 usb_hcd_transfer_callback_out_t callback, void *arg)
118{
119 printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n",
120 dev->address, endpoint->endpoint,
121 usb_str_transfer_type(endpoint->transfer_type),
122 size);
123
124 transfer_info_t *transfer
125 = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
126 transfer->out_callback = callback;
127
128 usb_target_t target = {
129 .address = dev->address,
130 .endpoint = endpoint->endpoint
131 };
132
133 hc_add_transaction_to_device(true, target, buffer, size,
134 universal_callback, transfer);
135
136 return EOK;
137}
138
139static int enqueue_transfer_in(usb_hc_device_t *hc,
140 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
141 void *buffer, size_t size,
142 usb_hcd_transfer_callback_in_t callback, void *arg)
143{
144 printf(NAME ": transfer IN [%d.%d (%s); %u]\n",
145 dev->address, endpoint->endpoint,
146 usb_str_transfer_type(endpoint->transfer_type),
147 size);
148
149 transfer_info_t *transfer
150 = create_transfer_info(hc, USB_DIRECTION_IN, arg);
151 transfer->in_callback = callback;
152
153 usb_target_t target = {
154 .address = dev->address,
155 .endpoint = endpoint->endpoint
156 };
157
158 hc_add_transaction_from_device(target, buffer, size,
159 universal_callback, transfer);
160
161 return EOK;
162}
163
164
165usb_hcd_transfer_ops_t vhc_transfer_ops = {
166 .transfer_out = enqueue_transfer_out,
167 .transfer_in = enqueue_transfer_in,
168 .transfer_setup = enqueue_transfer_setup
169};
170
171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.