[91db50ac] | 1 | /*
|
---|
[9753220] | 2 | * Copyright (c) 2010-2011 Vojtech Horky
|
---|
[91db50ac] | 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 libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <async.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 |
|
---|
[cb59f787] | 38 | #include "usbhc_iface.h"
|
---|
[91db50ac] | 39 | #include "driver.h"
|
---|
| 40 |
|
---|
[1b22bd4] | 41 | #define USB_MAX_PAYLOAD_SIZE 1020
|
---|
| 42 |
|
---|
[aae339e9] | 43 | static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[cb59f787] | 44 | static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 45 | static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[a3dfb2e] | 46 | static void remote_usbhc_control_write_setup(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 47 | static void remote_usbhc_control_write_data(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 48 | static void remote_usbhc_control_write_status(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 49 | static void remote_usbhc_control_read_setup(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 50 | static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 51 | static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[9753220] | 52 | static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 53 | static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[6f04905] | 54 | static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 55 | static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 56 | static void remote_usbhc_request_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[4689d40] | 57 | static void remote_usbhc_bind_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[6f04905] | 58 | static void remote_usbhc_release_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[a3dfb2e] | 59 | //static void remote_usbhc(device_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[91db50ac] | 60 |
|
---|
[6edd494] | 61 | /** Remote USB host controller interface operations. */
|
---|
[cb59f787] | 62 | static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
|
---|
[aae339e9] | 63 | remote_usbhc_get_address,
|
---|
[6f04905] | 64 |
|
---|
| 65 | remote_usbhc_reserve_default_address,
|
---|
| 66 | remote_usbhc_release_default_address,
|
---|
| 67 |
|
---|
| 68 | remote_usbhc_request_address,
|
---|
[4689d40] | 69 | remote_usbhc_bind_address,
|
---|
[6f04905] | 70 | remote_usbhc_release_address,
|
---|
| 71 |
|
---|
[aae339e9] | 72 | remote_usbhc_interrupt_out,
|
---|
[a3dfb2e] | 73 | remote_usbhc_interrupt_in,
|
---|
[6f04905] | 74 |
|
---|
[a3dfb2e] | 75 | remote_usbhc_control_write_setup,
|
---|
| 76 | remote_usbhc_control_write_data,
|
---|
| 77 | remote_usbhc_control_write_status,
|
---|
[6f04905] | 78 |
|
---|
[a3dfb2e] | 79 | remote_usbhc_control_read_setup,
|
---|
| 80 | remote_usbhc_control_read_data,
|
---|
[9753220] | 81 | remote_usbhc_control_read_status,
|
---|
| 82 |
|
---|
| 83 | remote_usbhc_control_write,
|
---|
| 84 | remote_usbhc_control_read
|
---|
[91db50ac] | 85 | };
|
---|
| 86 |
|
---|
[6edd494] | 87 | /** Remote USB host controller interface structure.
|
---|
[91db50ac] | 88 | */
|
---|
[cb59f787] | 89 | remote_iface_t remote_usbhc_iface = {
|
---|
| 90 | .method_count = sizeof(remote_usbhc_iface_ops) /
|
---|
| 91 | sizeof(remote_usbhc_iface_ops[0]),
|
---|
| 92 | .methods = remote_usbhc_iface_ops
|
---|
[91db50ac] | 93 | };
|
---|
| 94 |
|
---|
[1b22bd4] | 95 | typedef struct {
|
---|
| 96 | ipc_callid_t caller;
|
---|
[0a6fa9f] | 97 | ipc_callid_t data_caller;
|
---|
[1b22bd4] | 98 | void *buffer;
|
---|
[9753220] | 99 | void *setup_packet;
|
---|
[1b22bd4] | 100 | size_t size;
|
---|
| 101 | } async_transaction_t;
|
---|
[91db50ac] | 102 |
|
---|
[93f8da1] | 103 | static void async_transaction_destroy(async_transaction_t *trans)
|
---|
| 104 | {
|
---|
| 105 | if (trans == NULL) {
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | if (trans->setup_packet != NULL) {
|
---|
| 110 | free(trans->setup_packet);
|
---|
| 111 | }
|
---|
| 112 | if (trans->buffer != NULL) {
|
---|
| 113 | free(trans->buffer);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | free(trans);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | static async_transaction_t *async_transaction_create(ipc_callid_t caller)
|
---|
| 120 | {
|
---|
| 121 | async_transaction_t *trans = malloc(sizeof(async_transaction_t));
|
---|
| 122 | if (trans == NULL) {
|
---|
| 123 | return NULL;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | trans->caller = caller;
|
---|
[0a6fa9f] | 127 | trans->data_caller = 0;
|
---|
[93f8da1] | 128 | trans->buffer = NULL;
|
---|
| 129 | trans->setup_packet = NULL;
|
---|
| 130 | trans->size = 0;
|
---|
| 131 |
|
---|
| 132 | return trans;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[aae339e9] | 135 | void remote_usbhc_get_address(device_t *device, void *iface,
|
---|
| 136 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 137 | {
|
---|
| 138 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 139 |
|
---|
| 140 | if (!usb_iface->tell_address) {
|
---|
[17aca1c] | 141 | async_answer_0(callid, ENOTSUP);
|
---|
[aae339e9] | 142 | return;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[eac610e] | 145 | devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
|
---|
[aae339e9] | 146 |
|
---|
| 147 | usb_address_t address;
|
---|
| 148 | int rc = usb_iface->tell_address(device, handle, &address);
|
---|
| 149 | if (rc != EOK) {
|
---|
[17aca1c] | 150 | async_answer_0(callid, rc);
|
---|
[aae339e9] | 151 | } else {
|
---|
[17aca1c] | 152 | async_answer_1(callid, EOK, address);
|
---|
[aae339e9] | 153 | }
|
---|
| 154 | }
|
---|
[91db50ac] | 155 |
|
---|
[6f04905] | 156 | void remote_usbhc_reserve_default_address(device_t *device, void *iface,
|
---|
| 157 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 158 | {
|
---|
| 159 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 160 |
|
---|
| 161 | if (!usb_iface->reserve_default_address) {
|
---|
[17aca1c] | 162 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 163 | return;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | int rc = usb_iface->reserve_default_address(device);
|
---|
| 167 |
|
---|
[17aca1c] | 168 | async_answer_0(callid, rc);
|
---|
[6f04905] | 169 | }
|
---|
| 170 |
|
---|
| 171 | void remote_usbhc_release_default_address(device_t *device, void *iface,
|
---|
| 172 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 173 | {
|
---|
| 174 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 175 |
|
---|
| 176 | if (!usb_iface->release_default_address) {
|
---|
[17aca1c] | 177 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 178 | return;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | int rc = usb_iface->release_default_address(device);
|
---|
| 182 |
|
---|
[17aca1c] | 183 | async_answer_0(callid, rc);
|
---|
[6f04905] | 184 | }
|
---|
| 185 |
|
---|
| 186 | void remote_usbhc_request_address(device_t *device, void *iface,
|
---|
| 187 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 188 | {
|
---|
| 189 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 190 |
|
---|
| 191 | if (!usb_iface->request_address) {
|
---|
[17aca1c] | 192 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 193 | return;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | usb_address_t address;
|
---|
| 197 | int rc = usb_iface->request_address(device, &address);
|
---|
| 198 | if (rc != EOK) {
|
---|
[17aca1c] | 199 | async_answer_0(callid, rc);
|
---|
[6f04905] | 200 | } else {
|
---|
[17aca1c] | 201 | async_answer_1(callid, EOK, (sysarg_t) address);
|
---|
[6f04905] | 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[4689d40] | 205 | void remote_usbhc_bind_address(device_t *device, void *iface,
|
---|
| 206 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 207 | {
|
---|
| 208 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 209 |
|
---|
| 210 | if (!usb_iface->bind_address) {
|
---|
[17aca1c] | 211 | async_answer_0(callid, ENOTSUP);
|
---|
[4689d40] | 212 | return;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[eac610e] | 215 | usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
| 216 | devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
|
---|
[4689d40] | 217 |
|
---|
| 218 | int rc = usb_iface->bind_address(device, address, handle);
|
---|
| 219 |
|
---|
[17aca1c] | 220 | async_answer_0(callid, rc);
|
---|
[4689d40] | 221 | }
|
---|
| 222 |
|
---|
[6f04905] | 223 | void remote_usbhc_release_address(device_t *device, void *iface,
|
---|
| 224 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 225 | {
|
---|
| 226 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 227 |
|
---|
| 228 | if (!usb_iface->release_address) {
|
---|
[17aca1c] | 229 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 230 | return;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[eac610e] | 233 | usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
[6f04905] | 234 |
|
---|
| 235 | int rc = usb_iface->release_address(device, address);
|
---|
| 236 |
|
---|
[17aca1c] | 237 | async_answer_0(callid, rc);
|
---|
[6f04905] | 238 | }
|
---|
| 239 |
|
---|
[1b22bd4] | 240 |
|
---|
| 241 | static void callback_out(device_t *device,
|
---|
| 242 | usb_transaction_outcome_t outcome, void *arg)
|
---|
| 243 | {
|
---|
| 244 | async_transaction_t *trans = (async_transaction_t *)arg;
|
---|
| 245 |
|
---|
[17aca1c] | 246 | async_answer_0(trans->caller, outcome);
|
---|
[1b22bd4] | 247 |
|
---|
[93f8da1] | 248 | async_transaction_destroy(trans);
|
---|
[1b22bd4] | 249 | }
|
---|
| 250 |
|
---|
| 251 | static void callback_in(device_t *device,
|
---|
| 252 | usb_transaction_outcome_t outcome, size_t actual_size, void *arg)
|
---|
| 253 | {
|
---|
| 254 | async_transaction_t *trans = (async_transaction_t *)arg;
|
---|
| 255 |
|
---|
[93f8da1] | 256 | if (outcome != USB_OUTCOME_OK) {
|
---|
[17aca1c] | 257 | async_answer_0(trans->caller, outcome);
|
---|
[93f8da1] | 258 | async_transaction_destroy(trans);
|
---|
| 259 | return;
|
---|
| 260 | }
|
---|
[1b22bd4] | 261 |
|
---|
| 262 | trans->size = actual_size;
|
---|
[0a6fa9f] | 263 |
|
---|
| 264 | if (trans->data_caller) {
|
---|
| 265 | async_data_read_finalize(trans->data_caller,
|
---|
| 266 | trans->buffer, actual_size);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | async_answer_0(trans->caller, USB_OUTCOME_OK);
|
---|
[1e64b250] | 270 |
|
---|
| 271 | async_transaction_destroy(trans);
|
---|
[91db50ac] | 272 | }
|
---|
| 273 |
|
---|
[fb1dca09] | 274 | /** Process an outgoing transfer (both OUT and SETUP).
|
---|
| 275 | *
|
---|
| 276 | * @param device Target device.
|
---|
| 277 | * @param callid Initiating caller.
|
---|
| 278 | * @param call Initiating call.
|
---|
| 279 | * @param transfer_func Transfer function (might be NULL).
|
---|
| 280 | */
|
---|
| 281 | static void remote_usbhc_out_transfer(device_t *device,
|
---|
| 282 | ipc_callid_t callid, ipc_call_t *call,
|
---|
| 283 | usbhc_iface_transfer_out_t transfer_func)
|
---|
[91db50ac] | 284 | {
|
---|
[fb1dca09] | 285 | if (!transfer_func) {
|
---|
[17aca1c] | 286 | async_answer_0(callid, ENOTSUP);
|
---|
[fb1dca09] | 287 | return;
|
---|
| 288 | }
|
---|
[1b22bd4] | 289 |
|
---|
[eac610e] | 290 | size_t expected_len = DEV_IPC_GET_ARG3(*call);
|
---|
[1b22bd4] | 291 | usb_target_t target = {
|
---|
[eac610e] | 292 | .address = DEV_IPC_GET_ARG1(*call),
|
---|
| 293 | .endpoint = DEV_IPC_GET_ARG2(*call)
|
---|
[1b22bd4] | 294 | };
|
---|
| 295 |
|
---|
| 296 | size_t len = 0;
|
---|
| 297 | void *buffer = NULL;
|
---|
| 298 | if (expected_len > 0) {
|
---|
| 299 | int rc = async_data_write_accept(&buffer, false,
|
---|
| 300 | 1, USB_MAX_PAYLOAD_SIZE,
|
---|
| 301 | 0, &len);
|
---|
| 302 |
|
---|
| 303 | if (rc != EOK) {
|
---|
[17aca1c] | 304 | async_answer_0(callid, rc);
|
---|
[1b22bd4] | 305 | return;
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[93f8da1] | 309 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 310 | if (trans == NULL) {
|
---|
| 311 | if (buffer != NULL) {
|
---|
| 312 | free(buffer);
|
---|
| 313 | }
|
---|
[17aca1c] | 314 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 315 | return;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[fb1dca09] | 318 | trans->buffer = buffer;
|
---|
| 319 | trans->size = len;
|
---|
[1b22bd4] | 320 |
|
---|
[fb1dca09] | 321 | int rc = transfer_func(device, target, buffer, len,
|
---|
[1b22bd4] | 322 | callback_out, trans);
|
---|
| 323 |
|
---|
| 324 | if (rc != EOK) {
|
---|
[17aca1c] | 325 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 326 | async_transaction_destroy(trans);
|
---|
[1b22bd4] | 327 | }
|
---|
[91db50ac] | 328 | }
|
---|
| 329 |
|
---|
[fb1dca09] | 330 | /** Process an incoming transfer.
|
---|
| 331 | *
|
---|
| 332 | * @param device Target device.
|
---|
| 333 | * @param callid Initiating caller.
|
---|
| 334 | * @param call Initiating call.
|
---|
| 335 | * @param transfer_func Transfer function (might be NULL).
|
---|
| 336 | */
|
---|
| 337 | static void remote_usbhc_in_transfer(device_t *device,
|
---|
| 338 | ipc_callid_t callid, ipc_call_t *call,
|
---|
| 339 | usbhc_iface_transfer_in_t transfer_func)
|
---|
[91db50ac] | 340 | {
|
---|
[fb1dca09] | 341 | if (!transfer_func) {
|
---|
[17aca1c] | 342 | async_answer_0(callid, ENOTSUP);
|
---|
[fb1dca09] | 343 | return;
|
---|
| 344 | }
|
---|
[1b22bd4] | 345 |
|
---|
[eac610e] | 346 | size_t len = DEV_IPC_GET_ARG3(*call);
|
---|
[1b22bd4] | 347 | usb_target_t target = {
|
---|
[eac610e] | 348 | .address = DEV_IPC_GET_ARG1(*call),
|
---|
| 349 | .endpoint = DEV_IPC_GET_ARG2(*call)
|
---|
[1b22bd4] | 350 | };
|
---|
| 351 |
|
---|
[0a6fa9f] | 352 | ipc_callid_t data_callid;
|
---|
| 353 | if (!async_data_read_receive(&data_callid, &len)) {
|
---|
| 354 | async_answer_0(callid, EPARTY);
|
---|
| 355 | return;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[93f8da1] | 358 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 359 | if (trans == NULL) {
|
---|
[17aca1c] | 360 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 361 | return;
|
---|
| 362 | }
|
---|
[0a6fa9f] | 363 | trans->data_caller = data_callid;
|
---|
[1b22bd4] | 364 | trans->buffer = malloc(len);
|
---|
| 365 | trans->size = len;
|
---|
| 366 |
|
---|
[fb1dca09] | 367 | int rc = transfer_func(device, target, trans->buffer, len,
|
---|
[1b22bd4] | 368 | callback_in, trans);
|
---|
| 369 |
|
---|
| 370 | if (rc != EOK) {
|
---|
[17aca1c] | 371 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 372 | async_transaction_destroy(trans);
|
---|
[1b22bd4] | 373 | }
|
---|
[91db50ac] | 374 | }
|
---|
| 375 |
|
---|
[fb1dca09] | 376 | /** Process status part of control transfer.
|
---|
| 377 | *
|
---|
| 378 | * @param device Target device.
|
---|
| 379 | * @param callid Initiating caller.
|
---|
| 380 | * @param call Initiating call.
|
---|
| 381 | * @param direction Transfer direction (read ~ in, write ~ out).
|
---|
| 382 | * @param transfer_in_func Transfer function for control read (might be NULL).
|
---|
| 383 | * @param transfer_out_func Transfer function for control write (might be NULL).
|
---|
| 384 | */
|
---|
| 385 | static void remote_usbhc_status_transfer(device_t *device,
|
---|
| 386 | ipc_callid_t callid, ipc_call_t *call,
|
---|
| 387 | usb_direction_t direction,
|
---|
| 388 | int (*transfer_in_func)(device_t *, usb_target_t,
|
---|
| 389 | usbhc_iface_transfer_in_callback_t, void *),
|
---|
| 390 | int (*transfer_out_func)(device_t *, usb_target_t,
|
---|
| 391 | usbhc_iface_transfer_out_callback_t, void *))
|
---|
[a3dfb2e] | 392 | {
|
---|
[fb1dca09] | 393 | switch (direction) {
|
---|
| 394 | case USB_DIRECTION_IN:
|
---|
| 395 | if (!transfer_in_func) {
|
---|
[17aca1c] | 396 | async_answer_0(callid, ENOTSUP);
|
---|
[fb1dca09] | 397 | return;
|
---|
| 398 | }
|
---|
| 399 | break;
|
---|
| 400 | case USB_DIRECTION_OUT:
|
---|
| 401 | if (!transfer_out_func) {
|
---|
[17aca1c] | 402 | async_answer_0(callid, ENOTSUP);
|
---|
[fb1dca09] | 403 | return;
|
---|
| 404 | }
|
---|
| 405 | break;
|
---|
| 406 | default:
|
---|
| 407 | assert(false && "unreachable code");
|
---|
| 408 | break;
|
---|
| 409 | }
|
---|
[a3dfb2e] | 410 |
|
---|
| 411 | usb_target_t target = {
|
---|
[eac610e] | 412 | .address = DEV_IPC_GET_ARG1(*call),
|
---|
| 413 | .endpoint = DEV_IPC_GET_ARG2(*call)
|
---|
[a3dfb2e] | 414 | };
|
---|
| 415 |
|
---|
[93f8da1] | 416 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 417 | if (trans == NULL) {
|
---|
[17aca1c] | 418 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 419 | return;
|
---|
| 420 | }
|
---|
[a3dfb2e] | 421 |
|
---|
[fb1dca09] | 422 | int rc;
|
---|
| 423 | switch (direction) {
|
---|
| 424 | case USB_DIRECTION_IN:
|
---|
| 425 | rc = transfer_in_func(device, target,
|
---|
| 426 | callback_in, trans);
|
---|
| 427 | break;
|
---|
| 428 | case USB_DIRECTION_OUT:
|
---|
| 429 | rc = transfer_out_func(device, target,
|
---|
| 430 | callback_out, trans);
|
---|
| 431 | break;
|
---|
| 432 | default:
|
---|
| 433 | assert(false && "unreachable code");
|
---|
| 434 | break;
|
---|
| 435 | }
|
---|
[a3dfb2e] | 436 |
|
---|
| 437 | if (rc != EOK) {
|
---|
[17aca1c] | 438 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 439 | async_transaction_destroy(trans);
|
---|
[a3dfb2e] | 440 | }
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[fb1dca09] | 443 |
|
---|
| 444 | void remote_usbhc_interrupt_out(device_t *device, void *iface,
|
---|
| 445 | ipc_callid_t callid, ipc_call_t *call)
|
---|
[a3dfb2e] | 446 | {
|
---|
| 447 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
[fb1dca09] | 448 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 449 |
|
---|
[fb1dca09] | 450 | return remote_usbhc_out_transfer(device, callid, call,
|
---|
| 451 | usb_iface->interrupt_out);
|
---|
| 452 | }
|
---|
[a3dfb2e] | 453 |
|
---|
[fb1dca09] | 454 | void remote_usbhc_interrupt_in(device_t *device, void *iface,
|
---|
| 455 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 456 | {
|
---|
| 457 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 458 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 459 |
|
---|
[fb1dca09] | 460 | return remote_usbhc_in_transfer(device, callid, call,
|
---|
| 461 | usb_iface->interrupt_in);
|
---|
| 462 | }
|
---|
[a3dfb2e] | 463 |
|
---|
[fb1dca09] | 464 | void remote_usbhc_control_write_setup(device_t *device, void *iface,
|
---|
| 465 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 466 | {
|
---|
| 467 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 468 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 469 |
|
---|
[fb1dca09] | 470 | return remote_usbhc_out_transfer(device, callid, call,
|
---|
| 471 | usb_iface->control_write_setup);
|
---|
| 472 | }
|
---|
[a3dfb2e] | 473 |
|
---|
[fb1dca09] | 474 | void remote_usbhc_control_write_data(device_t *device, void *iface,
|
---|
| 475 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 476 | {
|
---|
| 477 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 478 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 479 |
|
---|
[fb1dca09] | 480 | return remote_usbhc_out_transfer(device, callid, call,
|
---|
| 481 | usb_iface->control_write_data);
|
---|
[a3dfb2e] | 482 | }
|
---|
| 483 |
|
---|
| 484 | void remote_usbhc_control_write_status(device_t *device, void *iface,
|
---|
[fb1dca09] | 485 | ipc_callid_t callid, ipc_call_t *call)
|
---|
[a3dfb2e] | 486 | {
|
---|
| 487 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
[fb1dca09] | 488 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 489 |
|
---|
[fb1dca09] | 490 | return remote_usbhc_status_transfer(device, callid, call,
|
---|
| 491 | USB_DIRECTION_IN, usb_iface->control_write_status, NULL);
|
---|
[a3dfb2e] | 492 | }
|
---|
| 493 |
|
---|
| 494 | void remote_usbhc_control_read_setup(device_t *device, void *iface,
|
---|
[fb1dca09] | 495 | ipc_callid_t callid, ipc_call_t *call)
|
---|
[a3dfb2e] | 496 | {
|
---|
| 497 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
[fb1dca09] | 498 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 499 |
|
---|
[fb1dca09] | 500 | return remote_usbhc_out_transfer(device, callid, call,
|
---|
| 501 | usb_iface->control_read_setup);
|
---|
[a3dfb2e] | 502 | }
|
---|
| 503 |
|
---|
| 504 | void remote_usbhc_control_read_data(device_t *device, void *iface,
|
---|
| 505 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 506 | {
|
---|
| 507 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
[fb1dca09] | 508 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 509 |
|
---|
[fb1dca09] | 510 | return remote_usbhc_in_transfer(device, callid, call,
|
---|
| 511 | usb_iface->control_read_data);
|
---|
[a3dfb2e] | 512 | }
|
---|
| 513 |
|
---|
| 514 | void remote_usbhc_control_read_status(device_t *device, void *iface,
|
---|
| 515 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 516 | {
|
---|
| 517 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
[fb1dca09] | 518 | assert(usb_iface != NULL);
|
---|
[a3dfb2e] | 519 |
|
---|
[fb1dca09] | 520 | return remote_usbhc_status_transfer(device, callid, call,
|
---|
| 521 | USB_DIRECTION_OUT, NULL, usb_iface->control_read_status);
|
---|
[a3dfb2e] | 522 | }
|
---|
| 523 |
|
---|
[9753220] | 524 | void remote_usbhc_control_write(device_t *device, void *iface,
|
---|
| 525 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 526 | {
|
---|
| 527 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 528 | assert(usb_iface != NULL);
|
---|
| 529 |
|
---|
| 530 | if (!usb_iface->control_write) {
|
---|
[17aca1c] | 531 | async_answer_0(callid, ENOTSUP);
|
---|
[9753220] | 532 | return;
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | usb_target_t target = {
|
---|
| 536 | .address = DEV_IPC_GET_ARG1(*call),
|
---|
| 537 | .endpoint = DEV_IPC_GET_ARG2(*call)
|
---|
| 538 | };
|
---|
| 539 |
|
---|
| 540 | int rc;
|
---|
| 541 |
|
---|
| 542 | void *setup_packet = NULL;
|
---|
| 543 | void *data_buffer = NULL;
|
---|
| 544 | size_t setup_packet_len = 0;
|
---|
| 545 | size_t data_buffer_len = 0;
|
---|
| 546 |
|
---|
| 547 | rc = async_data_write_accept(&setup_packet, false,
|
---|
| 548 | 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
|
---|
| 549 | if (rc != EOK) {
|
---|
[17aca1c] | 550 | async_answer_0(callid, rc);
|
---|
[9753220] | 551 | return;
|
---|
| 552 | }
|
---|
| 553 | rc = async_data_write_accept(&data_buffer, false,
|
---|
| 554 | 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
|
---|
| 555 | if (rc != EOK) {
|
---|
[17aca1c] | 556 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 557 | free(setup_packet);
|
---|
[9753220] | 558 | return;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[93f8da1] | 561 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 562 | if (trans == NULL) {
|
---|
[17aca1c] | 563 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 564 | free(setup_packet);
|
---|
| 565 | free(data_buffer);
|
---|
| 566 | return;
|
---|
| 567 | }
|
---|
[9753220] | 568 | trans->setup_packet = setup_packet;
|
---|
| 569 | trans->buffer = data_buffer;
|
---|
| 570 | trans->size = data_buffer_len;
|
---|
| 571 |
|
---|
| 572 | rc = usb_iface->control_write(device, target,
|
---|
| 573 | setup_packet, setup_packet_len,
|
---|
| 574 | data_buffer, data_buffer_len,
|
---|
| 575 | callback_out, trans);
|
---|
| 576 |
|
---|
| 577 | if (rc != EOK) {
|
---|
[17aca1c] | 578 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 579 | async_transaction_destroy(trans);
|
---|
[9753220] | 580 | }
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 |
|
---|
| 584 | void remote_usbhc_control_read(device_t *device, void *iface,
|
---|
| 585 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 586 | {
|
---|
| 587 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 588 | assert(usb_iface != NULL);
|
---|
| 589 |
|
---|
| 590 | if (!usb_iface->control_read) {
|
---|
[17aca1c] | 591 | async_answer_0(callid, ENOTSUP);
|
---|
[9753220] | 592 | return;
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | size_t data_len = DEV_IPC_GET_ARG3(*call);
|
---|
| 596 | usb_target_t target = {
|
---|
| 597 | .address = DEV_IPC_GET_ARG1(*call),
|
---|
| 598 | .endpoint = DEV_IPC_GET_ARG2(*call)
|
---|
| 599 | };
|
---|
| 600 |
|
---|
| 601 | int rc;
|
---|
| 602 |
|
---|
| 603 | void *setup_packet = NULL;
|
---|
| 604 | size_t setup_packet_len = 0;
|
---|
| 605 |
|
---|
| 606 | rc = async_data_write_accept(&setup_packet, false,
|
---|
| 607 | 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
|
---|
| 608 | if (rc != EOK) {
|
---|
[17aca1c] | 609 | async_answer_0(callid, rc);
|
---|
[9753220] | 610 | return;
|
---|
| 611 | }
|
---|
| 612 |
|
---|
[0a6fa9f] | 613 | ipc_callid_t data_callid;
|
---|
| 614 | if (!async_data_read_receive(&data_callid, &data_len)) {
|
---|
| 615 | async_answer_0(callid, EPARTY);
|
---|
| 616 | free(setup_packet);
|
---|
| 617 | return;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[93f8da1] | 620 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 621 | if (trans == NULL) {
|
---|
[17aca1c] | 622 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 623 | free(setup_packet);
|
---|
| 624 | return;
|
---|
| 625 | }
|
---|
[0a6fa9f] | 626 | trans->data_caller = data_callid;
|
---|
[9753220] | 627 | trans->setup_packet = setup_packet;
|
---|
| 628 | trans->size = data_len;
|
---|
[93f8da1] | 629 | trans->buffer = malloc(data_len);
|
---|
| 630 | if (trans->buffer == NULL) {
|
---|
[17aca1c] | 631 | async_answer_0(callid, ENOMEM);
|
---|
[93f8da1] | 632 | async_transaction_destroy(trans);
|
---|
| 633 | return;
|
---|
| 634 | }
|
---|
[9753220] | 635 |
|
---|
| 636 | rc = usb_iface->control_read(device, target,
|
---|
| 637 | setup_packet, setup_packet_len,
|
---|
| 638 | trans->buffer, trans->size,
|
---|
| 639 | callback_in, trans);
|
---|
| 640 |
|
---|
| 641 | if (rc != EOK) {
|
---|
[17aca1c] | 642 | async_answer_0(callid, rc);
|
---|
[93f8da1] | 643 | async_transaction_destroy(trans);
|
---|
[9753220] | 644 | }
|
---|
| 645 | }
|
---|
| 646 |
|
---|
[a3dfb2e] | 647 |
|
---|
[1b22bd4] | 648 |
|
---|
[91db50ac] | 649 | /**
|
---|
| 650 | * @}
|
---|
| 651 | */
|
---|