Changeset 6832245 in mainline for uspace/drv/bus/usb/ohci/ohci_bus.c


Ignore:
Timestamp:
2017-12-14T23:01:57Z (7 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/ohci/ohci_bus.c

    rbd05140 r6832245  
    7272/** Creates new hcd endpoint representation.
    7373 */
    74 static endpoint_t *ohci_endpoint_create(bus_t *bus)
     74static endpoint_t *ohci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc)
    7575{
    76         assert(bus);
     76        assert(dev);
    7777
    7878        ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
     
    8080                return NULL;
    8181
    82         endpoint_init(&ohci_ep->base, bus);
     82        endpoint_init(&ohci_ep->base, dev, desc);
    8383
    8484        ohci_ep->ed = malloc32(sizeof(ed_t));
     
    115115
    116116
    117 static int ohci_register_ep(bus_t *bus_base, device_t *dev, endpoint_t *ep, const usb_endpoint_desc_t *desc)
     117static int ohci_register_ep(endpoint_t *ep)
    118118{
     119        bus_t *bus_base = endpoint_get_bus(ep);
    119120        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
    120121        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
    121122
    122         const int err = bus->parent_ops.register_endpoint(bus_base, dev, ep, desc);
     123        const int err = usb2_bus_ops.endpoint_register(ep);
    123124        if (err)
    124125                return err;
     
    130131}
    131132
    132 static int ohci_unregister_ep(bus_t *bus_base, endpoint_t *ep)
     133static int ohci_unregister_ep(endpoint_t *ep)
    133134{
    134         ohci_bus_t *bus = (ohci_bus_t *) bus_base;
    135         assert(bus);
     135        ohci_bus_t *bus = (ohci_bus_t *) endpoint_get_bus(ep);
    136136        assert(ep);
    137137
    138         const int err = bus->parent_ops.unregister_endpoint(bus_base, ep);
     138        const int err = usb2_bus_ops.endpoint_unregister(ep);
    139139        if (err)
    140140                return err;
     
    144144}
    145145
    146 static usb_transfer_batch_t *ohci_bus_create_batch(bus_t *bus, endpoint_t *ep)
     146static usb_transfer_batch_t *ohci_create_batch(endpoint_t *ep)
    147147{
    148148        ohci_transfer_batch_t *batch = ohci_transfer_batch_create(ep);
     
    150150}
    151151
    152 static void ohci_bus_destroy_batch(usb_transfer_batch_t *batch)
     152static void ohci_destroy_batch(usb_transfer_batch_t *batch)
    153153{
    154154        ohci_transfer_batch_destroy(ohci_transfer_batch_get(batch));
    155155}
    156156
    157 int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
     157static const bus_ops_t ohci_bus_ops = {
     158        .parent = &usb2_bus_ops,
     159
     160        .endpoint_destroy = ohci_endpoint_destroy,
     161        .endpoint_create = ohci_endpoint_create,
     162        .endpoint_register = ohci_register_ep,
     163        .endpoint_unregister = ohci_unregister_ep,
     164        .endpoint_count_bw = bandwidth_count_usb11,
     165        .endpoint_set_toggle = ohci_ep_toggle_set,
     166        .endpoint_get_toggle = ohci_ep_toggle_get,
     167        .batch_create = ohci_create_batch,
     168        .batch_destroy = ohci_destroy_batch,
     169};
     170
     171
     172int ohci_bus_init(ohci_bus_t *bus, hcd_t *hcd, hc_t *hc)
    158173{
    159174        assert(hc);
    160175        assert(bus);
    161176
    162         usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
    163177
    164         bus_ops_t *ops = &bus->base.base.ops;
    165         bus->parent_ops = *ops;
    166         ops->create_endpoint = ohci_endpoint_create;
    167         ops->destroy_endpoint = ohci_endpoint_destroy;
    168         ops->endpoint_set_toggle = ohci_ep_toggle_set;
    169         ops->endpoint_get_toggle = ohci_ep_toggle_get;
     178        usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;
     179        bus_t *bus_base = (bus_t *) bus;
    170180
    171         ops->register_endpoint = ohci_register_ep;
    172         ops->unregister_endpoint = ohci_unregister_ep;
    173 
    174         ops->create_batch = ohci_bus_create_batch;
    175         ops->destroy_batch = ohci_bus_destroy_batch;
     181        usb2_bus_init(usb2_bus, hcd, BANDWIDTH_AVAILABLE_USB11);
     182        bus_base->ops = &ohci_bus_ops;
    176183
    177184        bus->hc = hc;
Note: See TracChangeset for help on using the changeset viewer.