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


Ignore:
Timestamp:
2017-12-14T23:01:57Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
837d53d
Parents:
bd05140
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:54)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:57)
Message:

usbhost bus: refactor the bus ops

This way, method names better represent the entity it is working with.
Their semantics was shifted a bit.

Regarding the tree of structures:

bus ← device ← endpoint ← batch

Previously, devices were kept in DDF function nodes, and endpoints had
pointer to the bus and device. Now, devices have pointer to bus,
endpoints don't.

Pointer to hcd_t in bus is WIP, and will be removed.

File:
1 edited

Legend:

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

    rbd05140 r6832245  
    4747/** Initialize provided endpoint structure.
    4848 */
    49 void endpoint_init(endpoint_t *ep, bus_t *bus)
     49void endpoint_init(endpoint_t *ep, device_t *dev, const usb_endpoint_desc_t *desc)
    5050{
    5151        memset(ep, 0, sizeof(endpoint_t));
    5252
    53         ep->bus = bus;
     53        assert(dev);
     54        ep->device = dev;
     55
    5456        atomic_set(&ep->refcnt, 0);
    5557        link_initialize(&ep->link);
    5658        fibril_mutex_initialize(&ep->guard);
    5759        fibril_condvar_initialize(&ep->avail);
     60
     61        ep->endpoint = desc->endpoint_no;
     62        ep->direction = desc->direction;
     63        ep->transfer_type = desc->transfer_type;
     64        ep->max_packet_size = desc->max_packet_size;
     65        ep->packets = desc->packets;
     66
     67        ep->bandwidth = endpoint_count_bw(ep, desc->max_packet_size);
     68}
     69
     70static inline const bus_ops_t *get_bus_ops(endpoint_t *ep)
     71{
     72        return ep->device->bus->ops;
    5873}
    5974
     
    6378}
    6479
     80static inline void endpoint_destroy(endpoint_t *ep)
     81{
     82        const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_destroy);
     83        if (ops) {
     84                ops->endpoint_destroy(ep);
     85        } else {
     86                assert(ep->active_batch == NULL);
     87
     88                /* Assume mostly the eps will be allocated by malloc. */
     89                free(ep);
     90        }
     91}
     92
    6593void endpoint_del_ref(endpoint_t *ep)
    6694{
    6795        if (atomic_predec(&ep->refcnt) == 0) {
    68                 if (ep->bus->ops.destroy_endpoint) {
    69                         ep->bus->ops.destroy_endpoint(ep);
    70                 }
    71                 else {
    72                         assert(ep->active_batch == NULL);
    73 
    74                         /* Assume mostly the eps will be allocated by malloc. */
    75                         free(ep);
    76                 }
     96                endpoint_destroy(ep);
    7797        }
    7898}
     
    133153        assert(ep);
    134154
    135         return ep->bus->ops.endpoint_get_toggle
    136             ? ep->bus->ops.endpoint_get_toggle(ep)
     155        const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_get_toggle);
     156        return ops
     157            ? ops->endpoint_get_toggle(ep)
    137158            : ep->toggle;
    138159}
     
    146167        assert(ep);
    147168
    148         if (ep->bus->ops.endpoint_set_toggle) {
    149                 ep->bus->ops.endpoint_set_toggle(ep, toggle);
     169        const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_set_toggle);
     170        if (ops) {
     171                ops->endpoint_set_toggle(ep, toggle);
    150172        }
    151173        else {
     
    154176}
    155177
     178ssize_t endpoint_count_bw(endpoint_t *ep, size_t packet_size)
     179{
     180        assert(ep);
     181
     182        const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_count_bw);
     183        if (!ops)
     184                return 0;
     185
     186        return ops->endpoint_count_bw(ep, packet_size);
     187}
     188
    156189/**
    157190 * @}
Note: See TracChangeset for help on using the changeset viewer.