[91db50ac] | 1 | /*
|
---|
[9753220] | 2 | * Copyright (c) 2010-2011 Vojtech Horky
|
---|
[02fc5c4] | 3 | * Copyright (c) 2011 Jan Vesely
|
---|
[91db50ac] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libdrv
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <async.h>
|
---|
| 37 | #include <errno.h>
|
---|
[eb1a2f4] | 38 | #include <assert.h>
|
---|
[91db50ac] | 39 |
|
---|
[cb59f787] | 40 | #include "usbhc_iface.h"
|
---|
[eb1a2f4] | 41 | #include "ddf/driver.h"
|
---|
[91db50ac] | 42 |
|
---|
[1b22bd4] | 43 | #define USB_MAX_PAYLOAD_SIZE 1020
|
---|
| 44 |
|
---|
[02fc5c4] | 45 | /** IPC methods for communication with HC through DDF interface.
|
---|
| 46 | *
|
---|
| 47 | * Notes for async methods:
|
---|
| 48 | *
|
---|
| 49 | * Methods for sending data to device (OUT transactions)
|
---|
| 50 | * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
|
---|
| 51 | * always use the same semantics:
|
---|
| 52 | * - first, IPC call with given method is made
|
---|
| 53 | * - argument #1 is target address
|
---|
| 54 | * - argument #2 is target endpoint
|
---|
| 55 | * - argument #3 is max packet size of the endpoint
|
---|
| 56 | * - this call is immediately followed by IPC data write (from caller)
|
---|
| 57 | * - the initial call (and the whole transaction) is answer after the
|
---|
| 58 | * transaction is scheduled by the HC and acknowledged by the device
|
---|
| 59 | * or immediately after error is detected
|
---|
| 60 | * - the answer carries only the error code
|
---|
| 61 | *
|
---|
| 62 | * Methods for retrieving data from device (IN transactions)
|
---|
| 63 | * - e.g. IPC_M_USBHC_INTERRUPT_IN -
|
---|
| 64 | * also use the same semantics:
|
---|
| 65 | * - first, IPC call with given method is made
|
---|
| 66 | * - argument #1 is target address
|
---|
| 67 | * - argument #2 is target endpoint
|
---|
| 68 | * - this call is immediately followed by IPC data read (async version)
|
---|
| 69 | * - the call is not answered until the device returns some data (or until
|
---|
| 70 | * error occurs)
|
---|
| 71 | *
|
---|
| 72 | * Some special methods (NO-DATA transactions) do not send any data. These
|
---|
| 73 | * might behave as both OUT or IN transactions because communication parts
|
---|
| 74 | * where actual buffers are exchanged are omitted.
|
---|
| 75 | **
|
---|
| 76 | * For all these methods, wrap functions exists. Important rule: functions
|
---|
| 77 | * for IN transactions have (as parameters) buffers where retrieved data
|
---|
| 78 | * will be stored. These buffers must be already allocated and shall not be
|
---|
| 79 | * touch until the transaction is completed
|
---|
| 80 | * (e.g. not before calling usb_wait_for() with appropriate handle).
|
---|
| 81 | * OUT transactions buffers can be freed immediately after call is dispatched
|
---|
| 82 | * (i.e. after return from wrapping function).
|
---|
| 83 | *
|
---|
| 84 | */
|
---|
| 85 | typedef enum {
|
---|
| 86 | /** Asks for address assignment by host controller.
|
---|
| 87 | * Answer:
|
---|
| 88 | * - ELIMIT - host controller run out of address
|
---|
| 89 | * - EOK - address assigned
|
---|
| 90 | * Answer arguments:
|
---|
| 91 | * - assigned address
|
---|
| 92 | *
|
---|
| 93 | * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
|
---|
| 94 | */
|
---|
| 95 | IPC_M_USBHC_REQUEST_ADDRESS,
|
---|
| 96 |
|
---|
| 97 | /** Bind USB address with devman handle.
|
---|
| 98 | * Parameters:
|
---|
| 99 | * - USB address
|
---|
| 100 | * - devman handle
|
---|
| 101 | * Answer:
|
---|
| 102 | * - EOK - address binded
|
---|
| 103 | * - ENOENT - address is not in use
|
---|
| 104 | */
|
---|
| 105 | IPC_M_USBHC_BIND_ADDRESS,
|
---|
| 106 |
|
---|
| 107 | /** Get handle binded with given USB address.
|
---|
| 108 | * Parameters
|
---|
| 109 | * - USB address
|
---|
| 110 | * Answer:
|
---|
| 111 | * - EOK - address binded, first parameter is the devman handle
|
---|
| 112 | * - ENOENT - address is not in use at the moment
|
---|
| 113 | */
|
---|
| 114 | IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
|
---|
| 115 |
|
---|
| 116 | /** Release address in use.
|
---|
| 117 | * Arguments:
|
---|
| 118 | * - address to be released
|
---|
| 119 | * Answer:
|
---|
| 120 | * - ENOENT - address not in use
|
---|
| 121 | * - EPERM - trying to release default USB address
|
---|
| 122 | */
|
---|
| 123 | IPC_M_USBHC_RELEASE_ADDRESS,
|
---|
| 124 |
|
---|
| 125 | /** Register endpoint attributes at host controller.
|
---|
| 126 | * This is used to reserve portion of USB bandwidth.
|
---|
| 127 | * When speed is invalid, speed of the device is used.
|
---|
| 128 | * Parameters:
|
---|
| 129 | * - USB address + endpoint number
|
---|
| 130 | * - packed as ADDR << 16 + EP
|
---|
| 131 | * - speed + transfer type + direction
|
---|
| 132 | * - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
|
---|
| 133 | * - maximum packet size + interval (in milliseconds)
|
---|
| 134 | * - packed as MPS << 16 + INT
|
---|
| 135 | * Answer:
|
---|
| 136 | * - EOK - reservation successful
|
---|
| 137 | * - ELIMIT - not enough bandwidth to satisfy the request
|
---|
| 138 | */
|
---|
| 139 | IPC_M_USBHC_REGISTER_ENDPOINT,
|
---|
| 140 |
|
---|
| 141 | /** Revert endpoint registration.
|
---|
| 142 | * Parameters:
|
---|
| 143 | * - USB address
|
---|
| 144 | * - endpoint number
|
---|
| 145 | * - data direction
|
---|
| 146 | * Answer:
|
---|
| 147 | * - EOK - endpoint unregistered
|
---|
| 148 | * - ENOENT - unknown endpoint
|
---|
| 149 | */
|
---|
| 150 | IPC_M_USBHC_UNREGISTER_ENDPOINT,
|
---|
| 151 |
|
---|
| 152 | /** Get data from device.
|
---|
| 153 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
| 154 | */
|
---|
| 155 | IPC_M_USBHC_READ,
|
---|
| 156 |
|
---|
| 157 | /** Send data to device.
|
---|
| 158 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
| 159 | */
|
---|
| 160 | IPC_M_USBHC_WRITE,
|
---|
| 161 | } usbhc_iface_funcs_t;
|
---|
| 162 |
|
---|
| 163 | int usbhc_request_address(async_exch_t *exch, usb_address_t *address,
|
---|
| 164 | bool strict, usb_speed_t speed)
|
---|
| 165 | {
|
---|
| 166 | if (!exch || !address)
|
---|
| 167 | return EINVAL;
|
---|
| 168 | sysarg_t new_address;
|
---|
| 169 | const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 170 | IPC_M_USBHC_REQUEST_ADDRESS, *address, strict, speed, &new_address);
|
---|
| 171 | if (ret == EOK)
|
---|
| 172 | *address = (usb_address_t)new_address;
|
---|
| 173 | return ret;
|
---|
| 174 | }
|
---|
| 175 | /*----------------------------------------------------------------------------*/
|
---|
| 176 | int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
|
---|
| 177 | devman_handle_t handle)
|
---|
| 178 | {
|
---|
| 179 | if (!exch)
|
---|
| 180 | return EINVAL;
|
---|
| 181 | return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 182 | IPC_M_USBHC_BIND_ADDRESS, address, handle);
|
---|
| 183 | }
|
---|
| 184 | /*----------------------------------------------------------------------------*/
|
---|
| 185 | int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
|
---|
| 186 | devman_handle_t *handle)
|
---|
| 187 | {
|
---|
| 188 | if (!exch)
|
---|
| 189 | return EINVAL;
|
---|
| 190 | sysarg_t h;
|
---|
| 191 | const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 192 | IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, address, &h);
|
---|
| 193 | if (ret == EOK && handle)
|
---|
| 194 | *handle = (devman_handle_t)h;
|
---|
| 195 | return ret;
|
---|
| 196 | }
|
---|
| 197 | /*----------------------------------------------------------------------------*/
|
---|
| 198 | int usbhc_release_address(async_exch_t *exch, usb_address_t address)
|
---|
| 199 | {
|
---|
| 200 | if (!exch)
|
---|
| 201 | return EINVAL;
|
---|
| 202 | return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 203 | IPC_M_USBHC_RELEASE_ADDRESS, address);
|
---|
| 204 | }
|
---|
| 205 | /*----------------------------------------------------------------------------*/
|
---|
| 206 | int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
|
---|
| 207 | usb_endpoint_t endpoint, usb_transfer_type_t type,
|
---|
| 208 | usb_direction_t direction, size_t mps, unsigned interval)
|
---|
| 209 | {
|
---|
| 210 | if (!exch)
|
---|
| 211 | return EINVAL;
|
---|
| 212 | const usb_target_t target =
|
---|
| 213 | {{ .address = address, .endpoint = endpoint }};
|
---|
| 214 | #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
|
---|
| 215 |
|
---|
| 216 | return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 217 | IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
|
---|
| 218 | _PACK2(type, direction), _PACK2(mps, interval));
|
---|
| 219 |
|
---|
| 220 | #undef _PACK2
|
---|
| 221 | }
|
---|
| 222 | /*----------------------------------------------------------------------------*/
|
---|
| 223 | int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
|
---|
| 224 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
| 225 | {
|
---|
| 226 | if (!exch)
|
---|
| 227 | return EINVAL;
|
---|
| 228 | return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 229 | IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
|
---|
| 230 | }
|
---|
| 231 | /*----------------------------------------------------------------------------*/
|
---|
| 232 | int usbhc_read(async_exch_t *exch, usb_address_t address,
|
---|
| 233 | usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
|
---|
| 234 | size_t *rec_size)
|
---|
| 235 | {
|
---|
| 236 | if (size == 0 && setup == 0)
|
---|
| 237 | return EOK;
|
---|
| 238 |
|
---|
| 239 | if (!exch)
|
---|
| 240 | return EINVAL;
|
---|
| 241 | const usb_target_t target =
|
---|
| 242 | {{ .address = address, .endpoint = endpoint }};
|
---|
| 243 |
|
---|
| 244 | /* Make call identifying target USB device and type of transfer. */
|
---|
| 245 | aid_t opening_request = async_send_4(exch,
|
---|
| 246 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 247 | IPC_M_USBHC_READ, target.packed,
|
---|
| 248 | (setup & UINT32_MAX), (setup >> 32), NULL);
|
---|
| 249 |
|
---|
| 250 | if (opening_request == 0) {
|
---|
| 251 | return ENOMEM;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | /* Retrieve the data. */
|
---|
| 255 | ipc_call_t data_request_call;
|
---|
| 256 | aid_t data_request =
|
---|
| 257 | async_data_read(exch, data, size, &data_request_call);
|
---|
| 258 |
|
---|
| 259 | if (data_request == 0) {
|
---|
| 260 | // FIXME: How to let the other side know that we want to abort?
|
---|
| 261 | async_wait_for(opening_request, NULL);
|
---|
| 262 | return ENOMEM;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | /* Wait for the answer. */
|
---|
| 266 | sysarg_t data_request_rc;
|
---|
| 267 | sysarg_t opening_request_rc;
|
---|
| 268 | async_wait_for(data_request, &data_request_rc);
|
---|
| 269 | async_wait_for(opening_request, &opening_request_rc);
|
---|
| 270 |
|
---|
| 271 | if (data_request_rc != EOK) {
|
---|
| 272 | /* Prefer the return code of the opening request. */
|
---|
| 273 | if (opening_request_rc != EOK) {
|
---|
| 274 | return (int) opening_request_rc;
|
---|
| 275 | } else {
|
---|
| 276 | return (int) data_request_rc;
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 | if (opening_request_rc != EOK) {
|
---|
| 280 | return (int) opening_request_rc;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | *rec_size = IPC_GET_ARG2(data_request_call);
|
---|
| 284 | return EOK;
|
---|
| 285 | }
|
---|
| 286 | /*----------------------------------------------------------------------------*/
|
---|
| 287 | int usbhc_write(async_exch_t *exch, usb_address_t address,
|
---|
| 288 | usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size)
|
---|
| 289 | {
|
---|
| 290 | if (size == 0 && setup == 0)
|
---|
| 291 | return EOK;
|
---|
| 292 |
|
---|
| 293 | if (!exch)
|
---|
| 294 | return EINVAL;
|
---|
| 295 | const usb_target_t target =
|
---|
| 296 | {{ .address = address, .endpoint = endpoint }};
|
---|
| 297 |
|
---|
| 298 | aid_t opening_request = async_send_5(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 299 | IPC_M_USBHC_WRITE, target.packed, size,
|
---|
| 300 | (setup & UINT32_MAX), (setup >> 32), NULL);
|
---|
| 301 |
|
---|
| 302 | if (opening_request == 0) {
|
---|
| 303 | return ENOMEM;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | /* Send the data if any. */
|
---|
| 307 | if (size > 0) {
|
---|
| 308 | const int ret = async_data_write_start(exch, data, size);
|
---|
| 309 | if (ret != EOK) {
|
---|
| 310 | async_wait_for(opening_request, NULL);
|
---|
| 311 | return ret;
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | /* Wait for the answer. */
|
---|
| 316 | sysarg_t opening_request_rc;
|
---|
| 317 | async_wait_for(opening_request, &opening_request_rc);
|
---|
| 318 |
|
---|
| 319 | return (int) opening_request_rc;
|
---|
| 320 | }
|
---|
| 321 | /*----------------------------------------------------------------------------*/
|
---|
| 322 |
|
---|
[eb1a2f4] | 323 | static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 324 | static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[02fc5c4] | 325 | static void remote_usbhc_get_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[eb1a2f4] | 326 | static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[b7d8fd9] | 327 | static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 328 | static void remote_usbhc_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[bbce2c2] | 329 | static void remote_usbhc_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 330 | static void remote_usbhc_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[eb1a2f4] | 331 | //static void remote_usbhc(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[91db50ac] | 332 |
|
---|
[6edd494] | 333 | /** Remote USB host controller interface operations. */
|
---|
[ffe3fe1] | 334 | static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
|
---|
| 335 | [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
|
---|
[27736cf] | 336 | [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
|
---|
[ffe3fe1] | 337 | [IPC_M_USBHC_BIND_ADDRESS] = remote_usbhc_bind_address,
|
---|
[02fc5c4] | 338 | [IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_get_handle,
|
---|
[6f04905] | 339 |
|
---|
[1e647c7d] | 340 | [IPC_M_USBHC_REGISTER_ENDPOINT] = remote_usbhc_register_endpoint,
|
---|
| 341 | [IPC_M_USBHC_UNREGISTER_ENDPOINT] = remote_usbhc_unregister_endpoint,
|
---|
[0a46c41e] | 342 |
|
---|
[bbce2c2] | 343 | [IPC_M_USBHC_READ] = remote_usbhc_read,
|
---|
| 344 | [IPC_M_USBHC_WRITE] = remote_usbhc_write,
|
---|
[91db50ac] | 345 | };
|
---|
| 346 |
|
---|
[6edd494] | 347 | /** Remote USB host controller interface structure.
|
---|
[91db50ac] | 348 | */
|
---|
[cb59f787] | 349 | remote_iface_t remote_usbhc_iface = {
|
---|
| 350 | .method_count = sizeof(remote_usbhc_iface_ops) /
|
---|
| 351 | sizeof(remote_usbhc_iface_ops[0]),
|
---|
| 352 | .methods = remote_usbhc_iface_ops
|
---|
[91db50ac] | 353 | };
|
---|
| 354 |
|
---|
[1b22bd4] | 355 | typedef struct {
|
---|
| 356 | ipc_callid_t caller;
|
---|
[0a6fa9f] | 357 | ipc_callid_t data_caller;
|
---|
[1b22bd4] | 358 | void *buffer;
|
---|
| 359 | size_t size;
|
---|
| 360 | } async_transaction_t;
|
---|
[91db50ac] | 361 |
|
---|
[93f8da1] | 362 | static void async_transaction_destroy(async_transaction_t *trans)
|
---|
| 363 | {
|
---|
| 364 | if (trans == NULL) {
|
---|
| 365 | return;
|
---|
| 366 | }
|
---|
| 367 | if (trans->buffer != NULL) {
|
---|
| 368 | free(trans->buffer);
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | free(trans);
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | static async_transaction_t *async_transaction_create(ipc_callid_t caller)
|
---|
| 375 | {
|
---|
| 376 | async_transaction_t *trans = malloc(sizeof(async_transaction_t));
|
---|
| 377 | if (trans == NULL) {
|
---|
| 378 | return NULL;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | trans->caller = caller;
|
---|
[0a6fa9f] | 382 | trans->data_caller = 0;
|
---|
[93f8da1] | 383 | trans->buffer = NULL;
|
---|
| 384 | trans->size = 0;
|
---|
| 385 |
|
---|
| 386 | return trans;
|
---|
| 387 | }
|
---|
[02fc5c4] | 388 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 389 | void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
|
---|
[6f04905] | 390 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 391 | {
|
---|
[02fc5c4] | 392 | const usbhc_iface_t *usb_iface = iface;
|
---|
[6f04905] | 393 |
|
---|
| 394 | if (!usb_iface->request_address) {
|
---|
[17aca1c] | 395 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 396 | return;
|
---|
| 397 | }
|
---|
[ffe3fe1] | 398 |
|
---|
[67f55e7b] | 399 | usb_address_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 400 | const bool strict = DEV_IPC_GET_ARG2(*call);
|
---|
| 401 | const usb_speed_t speed = DEV_IPC_GET_ARG3(*call);
|
---|
[6f04905] | 402 |
|
---|
[67f55e7b] | 403 | const int rc = usb_iface->request_address(fun, &address, strict, speed);
|
---|
[6f04905] | 404 | if (rc != EOK) {
|
---|
[17aca1c] | 405 | async_answer_0(callid, rc);
|
---|
[6f04905] | 406 | } else {
|
---|
[17aca1c] | 407 | async_answer_1(callid, EOK, (sysarg_t) address);
|
---|
[6f04905] | 408 | }
|
---|
| 409 | }
|
---|
[02fc5c4] | 410 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 411 | void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
|
---|
[4689d40] | 412 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 413 | {
|
---|
[02fc5c4] | 414 | const usbhc_iface_t *usb_iface = iface;
|
---|
[4689d40] | 415 |
|
---|
| 416 | if (!usb_iface->bind_address) {
|
---|
[17aca1c] | 417 | async_answer_0(callid, ENOTSUP);
|
---|
[4689d40] | 418 | return;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[02fc5c4] | 421 | const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
| 422 | const devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
|
---|
[4689d40] | 423 |
|
---|
[02fc5c4] | 424 | const int ret = usb_iface->bind_address(fun, address, handle);
|
---|
| 425 | async_answer_0(callid, ret);
|
---|
[4689d40] | 426 | }
|
---|
[02fc5c4] | 427 | /*----------------------------------------------------------------------------*/
|
---|
| 428 | void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
|
---|
[eb2f7dd] | 429 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 430 | {
|
---|
[02fc5c4] | 431 | const usbhc_iface_t *usb_iface = iface;
|
---|
[eb2f7dd] | 432 |
|
---|
[02fc5c4] | 433 | if (!usb_iface->get_handle) {
|
---|
[eb2f7dd] | 434 | async_answer_0(callid, ENOTSUP);
|
---|
| 435 | return;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[02fc5c4] | 438 | const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
[eb2f7dd] | 439 | devman_handle_t handle;
|
---|
[02fc5c4] | 440 | const int ret = usb_iface->get_handle(fun, address, &handle);
|
---|
[eb2f7dd] | 441 |
|
---|
[02fc5c4] | 442 | if (ret == EOK) {
|
---|
| 443 | async_answer_1(callid, ret, handle);
|
---|
[eb2f7dd] | 444 | } else {
|
---|
[02fc5c4] | 445 | async_answer_0(callid, ret);
|
---|
[eb2f7dd] | 446 | }
|
---|
| 447 | }
|
---|
[02fc5c4] | 448 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 449 | void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
|
---|
[6f04905] | 450 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 451 | {
|
---|
[02fc5c4] | 452 | const usbhc_iface_t *usb_iface = iface;
|
---|
[6f04905] | 453 |
|
---|
| 454 | if (!usb_iface->release_address) {
|
---|
[17aca1c] | 455 | async_answer_0(callid, ENOTSUP);
|
---|
[6f04905] | 456 | return;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[02fc5c4] | 459 | const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
[6f04905] | 460 |
|
---|
[02fc5c4] | 461 | const int ret = usb_iface->release_address(fun, address);
|
---|
| 462 | async_answer_0(callid, ret);
|
---|
[6f04905] | 463 | }
|
---|
[02fc5c4] | 464 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 465 | static void callback_out(ddf_fun_t *fun,
|
---|
[daec5e04] | 466 | int outcome, void *arg)
|
---|
[1b22bd4] | 467 | {
|
---|
| 468 | async_transaction_t *trans = (async_transaction_t *)arg;
|
---|
| 469 |
|
---|
[17aca1c] | 470 | async_answer_0(trans->caller, outcome);
|
---|
[1b22bd4] | 471 |
|
---|
[93f8da1] | 472 | async_transaction_destroy(trans);
|
---|
[1b22bd4] | 473 | }
|
---|
| 474 |
|
---|
[eb1a2f4] | 475 | static void callback_in(ddf_fun_t *fun,
|
---|
[daec5e04] | 476 | int outcome, size_t actual_size, void *arg)
|
---|
[1b22bd4] | 477 | {
|
---|
| 478 | async_transaction_t *trans = (async_transaction_t *)arg;
|
---|
| 479 |
|
---|
[daec5e04] | 480 | if (outcome != EOK) {
|
---|
[17aca1c] | 481 | async_answer_0(trans->caller, outcome);
|
---|
[5842493] | 482 | if (trans->data_caller) {
|
---|
| 483 | async_answer_0(trans->data_caller, EINTR);
|
---|
| 484 | }
|
---|
[93f8da1] | 485 | async_transaction_destroy(trans);
|
---|
| 486 | return;
|
---|
| 487 | }
|
---|
[1b22bd4] | 488 |
|
---|
| 489 | trans->size = actual_size;
|
---|
[0a6fa9f] | 490 |
|
---|
| 491 | if (trans->data_caller) {
|
---|
| 492 | async_data_read_finalize(trans->data_caller,
|
---|
| 493 | trans->buffer, actual_size);
|
---|
| 494 | }
|
---|
| 495 |
|
---|
[daec5e04] | 496 | async_answer_0(trans->caller, EOK);
|
---|
[1e64b250] | 497 |
|
---|
| 498 | async_transaction_destroy(trans);
|
---|
[91db50ac] | 499 | }
|
---|
| 500 |
|
---|
[b7d8fd9] | 501 | void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
|
---|
| 502 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 503 | {
|
---|
| 504 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 505 |
|
---|
| 506 | if (!usb_iface->register_endpoint) {
|
---|
| 507 | async_answer_0(callid, ENOTSUP);
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
[1998bcd] | 511 | #define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
|
---|
[27736cf] | 512 | type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)
|
---|
[1998bcd] | 513 | #define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
|
---|
[27736cf] | 514 | type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)
|
---|
[1998bcd] | 515 |
|
---|
[365e29e2] | 516 | const usb_target_t target = { .packed = DEV_IPC_GET_ARG1(*call) };
|
---|
[1998bcd] | 517 |
|
---|
[27736cf] | 518 | _INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);
|
---|
| 519 | _INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);
|
---|
[1998bcd] | 520 |
|
---|
| 521 | _INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
|
---|
| 522 | _INIT_FROM_LOW_DATA2(unsigned int, interval, 3);
|
---|
| 523 |
|
---|
| 524 | #undef _INIT_FROM_HIGH_DATA2
|
---|
| 525 | #undef _INIT_FROM_LOW_DATA2
|
---|
| 526 |
|
---|
[27736cf] | 527 | int rc = usb_iface->register_endpoint(fun, target.address,
|
---|
[bdd8ad2f] | 528 | target.endpoint, transfer_type, direction, max_packet_size, interval);
|
---|
[b7d8fd9] | 529 |
|
---|
| 530 | async_answer_0(callid, rc);
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | void remote_usbhc_unregister_endpoint(ddf_fun_t *fun, void *iface,
|
---|
| 534 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 535 | {
|
---|
| 536 | usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
|
---|
| 537 |
|
---|
| 538 | if (!usb_iface->unregister_endpoint) {
|
---|
| 539 | async_answer_0(callid, ENOTSUP);
|
---|
| 540 | return;
|
---|
| 541 | }
|
---|
| 542 |
|
---|
| 543 | usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
|
---|
| 544 | usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG2(*call);
|
---|
| 545 | usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG3(*call);
|
---|
| 546 |
|
---|
| 547 | int rc = usb_iface->unregister_endpoint(fun,
|
---|
| 548 | address, endpoint, direction);
|
---|
| 549 |
|
---|
| 550 | async_answer_0(callid, rc);
|
---|
| 551 | }
|
---|
| 552 |
|
---|
[bbce2c2] | 553 | void remote_usbhc_read(
|
---|
[ffe3fe1] | 554 | ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 555 | {
|
---|
| 556 | assert(fun);
|
---|
| 557 | assert(iface);
|
---|
| 558 | assert(call);
|
---|
| 559 |
|
---|
| 560 | const usbhc_iface_t *hc_iface = iface;
|
---|
| 561 |
|
---|
| 562 | if (!hc_iface->read) {
|
---|
| 563 | async_answer_0(callid, ENOTSUP);
|
---|
| 564 | return;
|
---|
| 565 | }
|
---|
| 566 |
|
---|
[365e29e2] | 567 | const usb_target_t target = { .packed = DEV_IPC_GET_ARG1(*call) };
|
---|
[bdd8ad2f] | 568 | const uint64_t setup =
|
---|
| 569 | ((uint64_t)DEV_IPC_GET_ARG2(*call)) |
|
---|
| 570 | (((uint64_t)DEV_IPC_GET_ARG3(*call)) << 32);
|
---|
[ffe3fe1] | 571 |
|
---|
| 572 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 573 | if (trans == NULL) {
|
---|
| 574 | async_answer_0(callid, ENOMEM);
|
---|
| 575 | return;
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | if (!async_data_read_receive(&trans->data_caller, &trans->size)) {
|
---|
| 579 | async_answer_0(callid, EPARTY);
|
---|
| 580 | return;
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 | trans->buffer = malloc(trans->size);
|
---|
| 584 | if (trans->buffer == NULL) {
|
---|
| 585 | async_answer_0(trans->data_caller, ENOMEM);
|
---|
| 586 | async_answer_0(callid, ENOMEM);
|
---|
| 587 | async_transaction_destroy(trans);
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | const int rc = hc_iface->read(
|
---|
[bdd8ad2f] | 591 | fun, target, setup, trans->buffer, trans->size, callback_in, trans);
|
---|
[ffe3fe1] | 592 |
|
---|
| 593 | if (rc != EOK) {
|
---|
| 594 | async_answer_0(trans->data_caller, rc);
|
---|
| 595 | async_answer_0(callid, rc);
|
---|
| 596 | async_transaction_destroy(trans);
|
---|
| 597 | }
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[bbce2c2] | 600 | void remote_usbhc_write(
|
---|
[ffe3fe1] | 601 | ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 602 | {
|
---|
| 603 | assert(fun);
|
---|
| 604 | assert(iface);
|
---|
| 605 | assert(call);
|
---|
| 606 |
|
---|
| 607 | const usbhc_iface_t *hc_iface = iface;
|
---|
| 608 |
|
---|
| 609 | if (!hc_iface->write) {
|
---|
| 610 | async_answer_0(callid, ENOTSUP);
|
---|
| 611 | return;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[365e29e2] | 614 | const usb_target_t target = { .packed = DEV_IPC_GET_ARG1(*call) };
|
---|
[bdd8ad2f] | 615 | const size_t data_buffer_len = DEV_IPC_GET_ARG2(*call);
|
---|
| 616 | const uint64_t setup =
|
---|
| 617 | ((uint64_t)DEV_IPC_GET_ARG3(*call)) |
|
---|
| 618 | (((uint64_t)DEV_IPC_GET_ARG4(*call)) << 32);
|
---|
[ffe3fe1] | 619 |
|
---|
| 620 | async_transaction_t *trans = async_transaction_create(callid);
|
---|
| 621 | if (trans == NULL) {
|
---|
| 622 | async_answer_0(callid, ENOMEM);
|
---|
| 623 | return;
|
---|
| 624 | }
|
---|
| 625 |
|
---|
[bdd8ad2f] | 626 | if (data_buffer_len > 0) {
|
---|
| 627 | int rc = async_data_write_accept(&trans->buffer, false,
|
---|
| 628 | 1, USB_MAX_PAYLOAD_SIZE,
|
---|
| 629 | 0, &trans->size);
|
---|
[ffe3fe1] | 630 |
|
---|
[bdd8ad2f] | 631 | if (rc != EOK) {
|
---|
| 632 | async_answer_0(callid, rc);
|
---|
| 633 | async_transaction_destroy(trans);
|
---|
| 634 | return;
|
---|
| 635 | }
|
---|
[ffe3fe1] | 636 | }
|
---|
| 637 |
|
---|
[bdd8ad2f] | 638 | int rc = hc_iface->write(
|
---|
| 639 | fun, target, setup, trans->buffer, trans->size, callback_out, trans);
|
---|
[ffe3fe1] | 640 |
|
---|
| 641 | if (rc != EOK) {
|
---|
| 642 | async_answer_0(callid, rc);
|
---|
| 643 | async_transaction_destroy(trans);
|
---|
| 644 | }
|
---|
| 645 | }
|
---|
| 646 |
|
---|
[1b22bd4] | 647 |
|
---|
[91db50ac] | 648 | /**
|
---|
| 649 | * @}
|
---|
| 650 | */
|
---|