Changeset 56257ba in mainline for uspace/lib/usbhost/src/bus.c


Ignore:
Timestamp:
2018-01-07T01:01:42Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63431db
Parents:
9efad54
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-07 01:01:41)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-07 01:01:42)
Message:

usbhost: manage endpoints by library + get/set_toggle → reset_toggle

That simplifies things A LOT. Now you can find endpoints for device in
an array inside device. This array is managed automatically in
register/unregister endpoint. HC drivers still needs to write to it when
setting up/tearing down the device.

Sorry for these two changes being in one commit, but splitting them
would be simply more work for no benefit.

File:
1 edited

Legend:

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

    r9efad54 r56257ba  
    9999
    100100        const bus_ops_t *ops = BUS_OPS_LOOKUP(dev->bus->ops, device_remove);
    101 
    102101        if (!ops)
    103102                return ENOTSUP;
     
    162161
    163162        fibril_mutex_lock(&bus->guard);
    164         err = register_ops->endpoint_register(ep);
    165         fibril_mutex_unlock(&bus->guard);
     163        if (!device->online && ep->endpoint != 0) {
     164                err = EAGAIN;
     165        } else if (device->endpoints[ep->endpoint] != NULL) {
     166                err = EEXIST;
     167        } else {
     168                err = register_ops->endpoint_register(ep);
     169                if (!err)
     170                        device->endpoints[ep->endpoint] = ep;
     171        }
     172        fibril_mutex_unlock(&bus->guard);
     173        if (err) {
     174                endpoint_del_ref(ep);
     175                return err;
     176        }
    166177
    167178        if (out_ep) {
     
    171182        }
    172183
    173         return err;
     184        return EOK;
    174185}
    175186
    176187/** Searches for an endpoint. Returns a reference.
    177188 */
    178 endpoint_t *bus_find_endpoint(device_t *device, usb_target_t endpoint, usb_direction_t dir)
     189endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint)
    179190{
    180191        assert(device);
     
    182193        bus_t *bus = device->bus;
    183194
    184         const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, device_find_endpoint);
    185         if (!ops)
    186                 return NULL;
    187 
    188         fibril_mutex_lock(&bus->guard);
    189         endpoint_t *ep = ops->device_find_endpoint(device, endpoint, dir);
     195        fibril_mutex_lock(&bus->guard);
     196        endpoint_t *ep = device->endpoints[endpoint];
    190197        if (ep) {
    191198                /* Exporting reference */
    192199                endpoint_add_ref(ep);
    193200        }
    194 
    195201        fibril_mutex_unlock(&bus->guard);
    196202        return ep;
     
    201207        assert(ep);
    202208        assert(ep->device);
    203         assert(ep->device->bus);
    204         assert(ep->device->bus->ops);
    205209
    206210        bus_t *bus = endpoint_get_bus(ep);
     
    218222        fibril_mutex_lock(&bus->guard);
    219223        const int r = ops->endpoint_unregister(ep);
     224        if (!r)
     225                ep->device->endpoints[ep->endpoint] = NULL;
    220226        fibril_mutex_unlock(&bus->guard);
    221227
     
    253259        fibril_mutex_lock(&bus->guard);
    254260        const int r = ops->release_default_address(bus);
    255         fibril_mutex_unlock(&bus->guard);
    256         return r;
    257 }
    258 
    259 int bus_reset_toggle(bus_t *bus, usb_target_t target, bool all)
    260 {
    261         assert(bus);
    262 
    263         const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, reset_toggle);
    264         if (!ops)
    265                 return ENOTSUP;
    266 
    267         fibril_mutex_lock(&bus->guard);
    268         const int r = ops->reset_toggle(bus, target, all);
    269261        fibril_mutex_unlock(&bus->guard);
    270262        return r;
     
    288280
    289281        /* Temporary reference */
    290         endpoint_t *ep = bus_find_endpoint(device, target, direction);
     282        endpoint_t *ep = bus_find_endpoint(device, target.endpoint);
    291283        if (ep == NULL) {
    292284                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
Note: See TracChangeset for help on using the changeset viewer.