Changeset 17873ac7 in mainline for uspace/lib/usbhost/src/endpoint.c


Ignore:
Timestamp:
2017-10-31T19:06:57Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
479e32d
Parents:
a312d8f
Message:

usbhost endpoint: endpoint→active replaced by tracking active batch

The mechanism is optional, synchronization over endpoint is now not forced. It will be used by xhci to utilize streams.

File:
1 edited

Legend:

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

    ra312d8f r17873ac7  
    3636
    3737#include <usb/host/endpoint.h>
     38#include <usb/host/usb_transfer_batch.h>
    3839#include <usb/host/bus.h>
    3940
     
    6869                }
    6970                else {
    70                         assert(!ep->active);
     71                        assert(ep->active_batch == NULL);
    7172
    7273                        /* Assume mostly the eps will be allocated by malloc. */
     
    7980 * @param ep endpoint_t structure.
    8081 */
    81 void endpoint_use(endpoint_t *ep)
     82void endpoint_activate_locked(endpoint_t *ep, usb_transfer_batch_t *batch)
    8283{
    8384        assert(ep);
    84         /* Add reference for active endpoint. */
    85         endpoint_add_ref(ep);
    86         fibril_mutex_lock(&ep->guard);
    87         while (ep->active)
     85        assert(batch);
     86        assert(batch->ep == ep);
     87        assert(fibril_mutex_is_locked(&ep->guard));
     88
     89        while (ep->active_batch != NULL)
    8890                fibril_condvar_wait(&ep->avail, &ep->guard);
    89         ep->active = true;
    90         fibril_mutex_unlock(&ep->guard);
     91        ep->active_batch = batch;
    9192}
    9293
     
    9495 * @param ep endpoint_t structure.
    9596 */
    96 void endpoint_release(endpoint_t *ep)
     97void endpoint_deactivate_locked(endpoint_t *ep)
    9798{
    9899        assert(ep);
     100        assert(fibril_mutex_is_locked(&ep->guard));
     101
     102        if (ep->active_batch && ep->active_batch->error == EOK)
     103                usb_transfer_batch_reset_toggle(ep->active_batch);
     104
     105        ep->active_batch = NULL;
     106        fibril_condvar_signal(&ep->avail);
     107}
     108
     109/** Abort an active batch on endpoint, if any.
     110 *
     111 * @param[in] ep endpoint_t structure.
     112 */
     113void endpoint_abort(endpoint_t *ep)
     114{
     115        assert(ep);
     116
    99117        fibril_mutex_lock(&ep->guard);
    100         ep->active = false;
     118        usb_transfer_batch_t *batch = ep->active_batch;
     119        endpoint_deactivate_locked(ep);
    101120        fibril_mutex_unlock(&ep->guard);
    102         fibril_condvar_signal(&ep->avail);
    103         /* Drop reference for active endpoint. */
    104         endpoint_del_ref(ep);
     121
     122        if (batch)
     123                usb_transfer_batch_abort(batch);
    105124}
    106125
     
    112131{
    113132        assert(ep);
    114         fibril_mutex_lock(&ep->guard);
    115         const int ret = ep->bus->ops.endpoint_get_toggle
     133
     134        return ep->bus->ops.endpoint_get_toggle
    116135            ? ep->bus->ops.endpoint_get_toggle(ep)
    117136            : ep->toggle;
    118         fibril_mutex_unlock(&ep->guard);
    119         return ret;
    120137}
    121138
     
    124141 * @param ep endpoint_t structure.
    125142 */
    126 void endpoint_toggle_set(endpoint_t *ep, unsigned toggle)
     143void endpoint_toggle_set(endpoint_t *ep, bool toggle)
    127144{
    128145        assert(ep);
    129         assert(toggle == 0 || toggle == 1);
    130         fibril_mutex_lock(&ep->guard);
     146
    131147        if (ep->bus->ops.endpoint_set_toggle) {
    132148                ep->bus->ops.endpoint_set_toggle(ep, toggle);
     
    135151                ep->toggle = toggle;
    136152        }
    137         fibril_mutex_unlock(&ep->guard);
    138153}
    139154
Note: See TracChangeset for help on using the changeset viewer.