Changeset 327f147 in mainline for uspace/lib/usbhost/src/hcd.c


Ignore:
Timestamp:
2017-10-23T19:03:37Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b724494
Parents:
e160bfe8
Message:

usbhost: change parameters of methods

Pass (device_t, usb_target_t) to read and write, which finally allows to drop hash tables and access device right away. Then, all callbacks to complete transfer now uses usb_transfer_batch. This requires libdrv to include libusbhost, but it is not linked against it - it is there only to share definition of usb_transfer_batch_t.

File:
1 edited

Legend:

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

    re160bfe8 r327f147  
    8080 * @return Error code.
    8181 */
    82 int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
    83         void *data, size_t size, uint64_t setup_data,
    84         usbhc_iface_transfer_in_callback_t in, usbhc_iface_transfer_out_callback_t out,
    85         void *arg, const char *name)
     82int hcd_send_batch(hcd_t *hcd, device_t *device, usb_target_t target,
     83    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     84    usb_transfer_batch_callback_t on_complete, void *arg, const char *name)
    8685{
    8786        assert(hcd);
     87        assert(device->address == target.address);
    8888
    89         endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction);
     89        endpoint_t *ep = bus_find_endpoint(hcd->bus, device, target, direction);
    9090        if (ep == NULL) {
    9191                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
    92                     target.address, target.endpoint, name);
     92                    device->address, target.endpoint, name);
    9393                return ENOENT;
    9494        }
     
    120120        batch->setup.packed = setup_data;
    121121        batch->dir = direction;
     122        batch->on_complete = on_complete;
     123        batch->on_complete_data = arg;
    122124
    123125        /* Check for commands that reset toggle bit */
     
    125127                batch->toggle_reset_mode
    126128                        = usb_request_get_toggle_reset_mode(&batch->setup.packet);
    127 
    128         usb_transfer_batch_set_old_handlers(batch, in, out, arg);
    129129
    130130        const int ret = hcd->ops.schedule(hcd, batch);
     
    144144        fibril_condvar_t done_cv;
    145145        unsigned done;
    146         int ret;
    147         size_t size;
     146
     147        size_t transfered_size;
     148        int error;
    148149} sync_data_t;
    149150
    150 static void transfer_in_cb(int ret, size_t size, void* data)
     151static int sync_transfer_complete(usb_transfer_batch_t *batch)
    151152{
    152         sync_data_t *d = data;
     153        sync_data_t *d = batch->on_complete_data;
    153154        assert(d);
    154         d->ret = ret;
    155         d->size = size;
     155        d->transfered_size = batch->transfered_size;
     156        d->error = batch->error;
    156157        fibril_mutex_lock(&d->done_mtx);
    157158        d->done = 1;
    158159        fibril_condvar_broadcast(&d->done_cv);
    159160        fibril_mutex_unlock(&d->done_mtx);
     161        return EOK;
    160162}
    161163
    162 static void transfer_out_cb(int ret, void* data)
    163 {
    164         sync_data_t *d = data;
    165         assert(data);
    166         d->ret = ret;
    167         fibril_mutex_lock(&d->done_mtx);
    168         d->done = 1;
    169         fibril_condvar_broadcast(&d->done_cv);
    170         fibril_mutex_unlock(&d->done_mtx);
    171 }
    172 
    173 /** this is really ugly version of sync usb communication */
    174 ssize_t hcd_send_batch_sync(
    175     hcd_t *hcd, usb_target_t target, usb_direction_t dir,
    176     void *data, size_t size, uint64_t setup_data, const char* name)
     164ssize_t hcd_send_batch_sync(hcd_t *hcd, device_t *device, usb_target_t target,
     165    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     166    const char *name)
    177167{
    178168        assert(hcd);
    179         sync_data_t sd = { .done = 0, .ret = EBUSY, .size = size };
     169        sync_data_t sd = { .done = 0 };
    180170        fibril_mutex_initialize(&sd.done_mtx);
    181171        fibril_condvar_initialize(&sd.done_cv);
    182172
    183         const int ret = hcd_send_batch(hcd, target, dir, data, size, setup_data,
    184             dir == USB_DIRECTION_IN ? transfer_in_cb : NULL,
    185             dir == USB_DIRECTION_OUT ? transfer_out_cb : NULL, &sd, name);
     173        const int ret = hcd_send_batch(hcd, device, target, direction,
     174            data, size, setup_data,
     175            sync_transfer_complete, &sd, name);
    186176        if (ret != EOK)
    187177                return ret;
     
    192182        fibril_mutex_unlock(&sd.done_mtx);
    193183
    194         if (sd.ret == EOK)
    195                 return sd.size;
    196         return sd.ret;
     184        return (sd.error == EOK)
     185                ? (ssize_t) sd.transfered_size
     186                : (ssize_t) sd.error;
    197187}
    198188
Note: See TracChangeset for help on using the changeset viewer.