Changeset 5595841 in mainline for uspace/lib/usbhost/src/ddf_helpers.c


Ignore:
Timestamp:
2018-01-31T16:02:34Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3b60ea0
Parents:
2b3dd78
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-31 15:49:24)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-31 16:02:34)
Message:

libdrv: usbhc_iface now shares memory instead of sending data

Two more things that come along:
1) The two callbacks (read, write) were joined. As they were joined in

the only implementation (ddf_helpers) anyway, and now the code is
almost the same, we took the opportunity and joined them. The bad
thing about it is that there are not enough IPC arguments to
transfer the direction, so we still have to use two "interface IPC
methods".

2) The copying is still done by the former methods (usbhc_read and

usbhc_write) to ensure the page alignment, so this method just
moves the burden of copying from kernel to the caller (which is why
this is actually a performance regression).

But, the two sides can now resolve their issues separately. The caller
can prepare the memory area in advance, and HC can use the memory
directly if it can.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    r2b3dd78 r5595841  
    254254}
    255255
    256 /** Inbound communication interface function.
     256/**
     257 * Transfer issuing interface function.
     258 *
    257259 * @param fun DDF function.
    258260 * @param target Communication target.
     261 * @param dir Communication direction.
    259262 * @param setup_data Data to use in setup stage (control transfers).
    260263 * @param data Pointer to data buffer.
     
    264267 * @return Error code.
    265268 */
    266 static errno_t dev_read(ddf_fun_t *fun, usb_target_t target,
    267     uint64_t setup_data, char *data, size_t size,
     269static errno_t transfer(ddf_fun_t *fun, usb_target_t target,
     270    usb_direction_t dir, uint64_t setup_data, char *data, size_t size,
    268271    usbhc_iface_transfer_callback_t callback, void *arg)
    269272{
     
    283286                return EBADMEM;
    284287
    285         return bus_device_send_batch(dev, target, USB_DIRECTION_IN,
    286             data, size, setup_data,
    287             callback, arg, "READ");
    288 }
    289 
    290 /** Outbound communication interface function.
    291  * @param fun DDF function.
    292  * @param target Communication target.
    293  * @param setup_data Data to use in setup stage (control transfers).
    294  * @param data Pointer to data buffer.
    295  * @param size Size of the data buffer.
    296  * @param callback Function to call on communication end.
    297  * @param arg Argument passed to the callback function.
    298  * @return Error code.
    299  */
    300 static errno_t dev_write(ddf_fun_t *fun, usb_target_t target,
    301     uint64_t setup_data, const char *data, size_t size,
    302     usbhc_iface_transfer_callback_t callback, void *arg)
    303 {
    304         assert(fun);
    305         device_t *dev = ddf_fun_data_get(fun);
    306         assert(dev);
    307 
    308         target.address = dev->address;
    309 
    310         if (!usb_target_is_valid(&target))
    311                 return EINVAL;
    312 
    313         if (size > 0 && data == NULL)
    314                 return EBADMEM;
    315 
    316         if (!callback && arg)
    317                 return EBADMEM;
    318 
    319         return bus_device_send_batch(dev, target, USB_DIRECTION_OUT,
     288        const char *name = (dir == USB_DIRECTION_IN) ? "READ" : "WRITE";
     289
     290        return bus_device_send_batch(dev, target, dir,
    320291            (char *) data, size, setup_data,
    321             callback, arg, "WRITE");
     292            callback, arg, name);
    322293}
    323294
     
    337308        .unregister_endpoint = unregister_endpoint,
    338309
    339         .read = dev_read,
    340         .write = dev_write,
     310        .transfer = transfer,
    341311};
    342312
Note: See TracChangeset for help on using the changeset viewer.