Changeset 6832245 in mainline for uspace/drv/bus/usb/ehci/ehci_bus.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/drv/bus/usb/ehci/ehci_bus.c

    rbd05140 r6832245  
    7979/** Creates new hcd endpoint representation.
    8080 */
    81 static endpoint_t *ehci_endpoint_create(bus_t *bus)
     81static endpoint_t *ehci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc)
    8282{
    83         assert(bus);
     83        assert(dev);
    8484
    8585        ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
     
    8787                return NULL;
    8888
    89         endpoint_init(&ehci_ep->base, bus);
     89        endpoint_init(&ehci_ep->base, dev, desc);
     90
     91        // TODO: extract USB2 information from desc
    9092
    9193        ehci_ep->qh = malloc32(sizeof(qh_t));
     
    114116
    115117
    116 static int ehci_register_ep(bus_t *bus_base, device_t *dev, endpoint_t *ep, const usb_endpoint_desc_t *desc)
     118static int ehci_register_ep(endpoint_t *ep)
    117119{
     120        bus_t *bus_base = endpoint_get_bus(ep);
    118121        ehci_bus_t *bus = (ehci_bus_t *) bus_base;
    119122        ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
     123        assert(fibril_mutex_is_locked(&bus_base->guard));
    120124
    121         // TODO utilize desc->usb2
    122 
    123         const int err = bus->parent_ops.register_endpoint(bus_base, dev, ep, desc);
     125        const int err = usb2_bus_ops.endpoint_register(ep);
    124126        if (err)
    125127                return err;
     
    131133}
    132134
    133 static int ehci_unregister_ep(bus_t *bus_base, endpoint_t *ep)
     135static int ehci_unregister_ep(endpoint_t *ep)
    134136{
     137        bus_t *bus_base = endpoint_get_bus(ep);
    135138        ehci_bus_t *bus = (ehci_bus_t *) bus_base;
    136139        assert(bus);
    137140        assert(ep);
    138141
    139         const int err = bus->parent_ops.unregister_endpoint(bus_base, ep);
     142        const int err = usb2_bus_ops.endpoint_unregister(ep);
    140143        if (err)
    141144                return err;
     
    145148}
    146149
    147 static usb_transfer_batch_t *ehci_bus_create_batch(bus_t *bus, endpoint_t *ep)
     150static usb_transfer_batch_t *ehci_create_batch(endpoint_t *ep)
    148151{
    149152        ehci_transfer_batch_t *batch = ehci_transfer_batch_create(ep);
     
    151154}
    152155
    153 static void ehci_bus_destroy_batch(usb_transfer_batch_t *batch)
     156static void ehci_destroy_batch(usb_transfer_batch_t *batch)
    154157{
    155158        ehci_transfer_batch_destroy(ehci_transfer_batch_get(batch));
    156159}
    157160
    158 int ehci_bus_init(ehci_bus_t *bus, hc_t *hc)
     161static const bus_ops_t ehci_bus_ops = {
     162        .parent = &usb2_bus_ops,
     163
     164        .endpoint_destroy = ehci_endpoint_destroy,
     165        .endpoint_create = ehci_endpoint_create,
     166        .endpoint_register = ehci_register_ep,
     167        .endpoint_unregister = ehci_unregister_ep,
     168        .endpoint_set_toggle = ehci_ep_toggle_set,
     169        .endpoint_get_toggle = ehci_ep_toggle_get,
     170        .endpoint_count_bw = bandwidth_count_usb11,
     171        .batch_create = ehci_create_batch,
     172        .batch_destroy = ehci_destroy_batch,
     173};
     174
     175int ehci_bus_init(ehci_bus_t *bus, hcd_t *hcd, hc_t *hc)
    159176{
    160177        assert(hc);
    161178        assert(bus);
    162179
    163         // FIXME: Implement the USB2 bw counting.
    164         usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
     180        usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;
     181        bus_t *bus_base = (bus_t *) bus;
    165182
    166         bus_ops_t *ops = &bus->base.base.ops;
    167         bus->parent_ops = *ops;
    168         ops->create_endpoint = ehci_endpoint_create;
    169         ops->destroy_endpoint = ehci_endpoint_destroy;
    170         ops->endpoint_set_toggle = ehci_ep_toggle_set;
    171         ops->endpoint_get_toggle = ehci_ep_toggle_get;
    172 
    173         ops->register_endpoint = ehci_register_ep;
    174         ops->unregister_endpoint = ehci_unregister_ep;
    175 
    176         ops->create_batch = ehci_bus_create_batch;
    177         ops->destroy_batch = ehci_bus_destroy_batch;
     183        usb2_bus_init(usb2_bus, hcd, BANDWIDTH_AVAILABLE_USB11);
     184        bus_base->ops = &ehci_bus_ops;
    178185
    179186        bus->hc = hc;
Note: See TracChangeset for help on using the changeset viewer.