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


Ignore:
Timestamp:
2017-10-13T08:49:29Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
741bcdeb
Parents:
0a5833d7
Message:

WIP usbhost refactoring: ohci completed

Along with that we noticed hcd_t in bus_t is superfluous and it complicates initialization (and breaks isolation), so we removed it. Also, type of the toggle has changed to bool in the functions.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci_bus.c

    r0a5833d7 re6b9182  
    3737#include <stdlib.h>
    3838#include <usb/host/utils/malloc32.h>
     39#include <usb/host/bandwidth.h>
    3940
    40 #include "ohci_endpoint.h"
     41#include "ohci_bus.h"
    4142#include "hc.h"
    4243
     
    4647 * @param[in] toggle new value of toggle bit
    4748 */
    48 static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
     49static void ohci_ep_toggle_set(endpoint_t *ep, bool toggle)
    4950{
    50         ohci_endpoint_t *instance = ohci_ep;
     51        ohci_endpoint_t *instance = ohci_endpoint_get(ep);
    5152        assert(instance);
    5253        assert(instance->ed);
     54        ep->toggle = toggle;
    5355        ed_toggle_set(instance->ed, toggle);
    5456}
     
    5961 * @return Current value of toggle bit.
    6062 */
    61 static int ohci_ep_toggle_get(void *ohci_ep)
     63static bool ohci_ep_toggle_get(endpoint_t *ep)
    6264{
    63         ohci_endpoint_t *instance = ohci_ep;
     65        ohci_endpoint_t *instance = ohci_endpoint_get(ep);
    6466        assert(instance);
    6567        assert(instance->ed);
     
    6870
    6971/** Creates new hcd endpoint representation.
    70  *
    71  * @param[in] ep USBD endpoint structure
    72  * @return Error code.
    7372 */
    74 int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
     73static endpoint_t *ohci_endpoint_create(bus_t *bus)
    7574{
    76         assert(ep);
     75        assert(bus);
     76
    7777        ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
    7878        if (ohci_ep == NULL)
    79                 return ENOMEM;
     79                return NULL;
    8080
    8181        ohci_ep->ed = malloc32(sizeof(ed_t));
    8282        if (ohci_ep->ed == NULL) {
    8383                free(ohci_ep);
    84                 return ENOMEM;
     84                return NULL;
    8585        }
    8686
     
    8989                free32(ohci_ep->ed);
    9090                free(ohci_ep);
    91                 return ENOMEM;
     91                return NULL;
    9292        }
    9393
    9494        link_initialize(&ohci_ep->link);
    95         ed_init(ohci_ep->ed, ep, ohci_ep->td);
    96         endpoint_set_hc_data(
    97             ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
    98         hc_enqueue_endpoint(hcd_get_driver_data(hcd), ep);
    9995        return EOK;
    10096}
     
    105101 * @param[in] ep endpoint structure.
    106102 */
    107 void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
     103static void ohci_endpoint_destroy(endpoint_t *ep)
    108104{
    109         assert(hcd);
    110105        assert(ep);
    111106        ohci_endpoint_t *instance = ohci_endpoint_get(ep);
    112         hc_dequeue_endpoint(hcd_get_driver_data(hcd), ep);
    113         endpoint_clear_hc_data(ep);
    114         if (instance) {
    115                 free32(instance->ed);
    116                 free32(instance->td);
    117                 free(instance);
    118         }
     107
     108        free32(instance->ed);
     109        free32(instance->td);
     110        free(instance);
     111}
     112
     113
     114static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep)
     115{
     116        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
     117        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
     118
     119        const int err = bus->parent_ops.register_endpoint(bus_base, ep);
     120        if (err)
     121                return err;
     122
     123        ed_init(ohci_ep->ed, ep, ohci_ep->td);
     124        hc_enqueue_endpoint(bus->hc, ep);
     125
     126        return EOK;
     127}
     128
     129static int ohci_release_ep(bus_t *bus_base, endpoint_t *ep)
     130{
     131        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
     132        assert(bus);
     133        assert(ep);
     134
     135        const int err = bus->parent_ops.release_endpoint(bus_base, ep);
     136        if (err)
     137                return err;
     138
     139        hc_dequeue_endpoint(bus->hc, ep);
     140        return EOK;
     141
     142}
     143
     144int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
     145{
     146        assert(hc);
     147        assert(bus);
     148
     149        usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
     150
     151        bus_ops_t *ops = &bus->base.base.ops;
     152        bus->parent_ops = *ops;
     153        ops->create_endpoint = ohci_endpoint_create;
     154        ops->destroy_endpoint = ohci_endpoint_destroy;
     155        ops->endpoint_set_toggle = ohci_ep_toggle_set;
     156        ops->endpoint_get_toggle = ohci_ep_toggle_get;
     157
     158        ops->register_endpoint = ohci_register_ep;
     159        ops->release_endpoint = ohci_release_ep;
     160
     161        return EOK;
    119162}
    120163
Note: See TracChangeset for help on using the changeset viewer.