Changeset 741bcdeb in mainline for uspace/drv/bus/usb/ehci/ehci_bus.c


Ignore:
Timestamp:
2017-10-13T09:21:22Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c0e4b5b2
Parents:
e6b9182
Message:

WIP usbhost refactoring: ehci completed

vhc to go…

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/ehci_bus.c

    re6b9182 r741bcdeb  
    11/*
    2  * Copyright (c) 2014 Jan Vesely
     2 * Copyright (c) 2011 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbehci
    2930 * @{
     
    3536#include <assert.h>
    3637#include <stdlib.h>
     38#include <usb/host/utils/malloc32.h>
     39#include <usb/host/bandwidth.h>
    3740#include <usb/debug.h>
    38 #include <usb/host/utils/malloc32.h>
    3941
    40 #include "ehci_endpoint.h"
     42#include "ehci_bus.h"
    4143#include "hc.h"
    4244
     
    4648 * @param[in] toggle new value of toggle bit
    4749 */
    48 static void ehci_ep_toggle_set(void *ehci_ep, int toggle)
     50static void ehci_ep_toggle_set(endpoint_t *ep, bool toggle)
    4951{
    50         ehci_endpoint_t *instance = ehci_ep;
     52        ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    5153        assert(instance);
    5254        assert(instance->qh);
     55        ep->toggle = toggle;
    5356        if (qh_toggle_from_td(instance->qh))
    5457                usb_log_warning("EP(%p): Setting toggle bit for transfer "
     
    6265 * @return Current value of toggle bit.
    6366 */
    64 static int ehci_ep_toggle_get(void *ehci_ep)
     67static bool ehci_ep_toggle_get(endpoint_t *ep)
    6568{
    66         ehci_endpoint_t *instance = ehci_ep;
     69        ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    6770        assert(instance);
    6871        assert(instance->qh);
     72
    6973        if (qh_toggle_from_td(instance->qh))
    7074                usb_log_warning("EP(%p): Reading useless toggle bit", instance);
     
    7377
    7478/** Creates new hcd endpoint representation.
    75  *
    76  * @param[in] ep USBD endpoint structure
    77  * @return Error code.
    7879 */
    79 int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
     80static endpoint_t *ehci_endpoint_create(bus_t *bus)
    8081{
    81         assert(ep);
    82         hc_t *hc = hcd_get_driver_data(hcd);
     82        assert(bus);
    8383
    8484        ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
    8585        if (ehci_ep == NULL)
    86                 return ENOMEM;
     86                return NULL;
     87
     88        endpoint_init(&ehci_ep->base, bus);
    8789
    8890        ehci_ep->qh = malloc32(sizeof(qh_t));
    8991        if (ehci_ep->qh == NULL) {
    9092                free(ehci_ep);
    91                 return ENOMEM;
     93                return NULL;
    9294        }
    9395
    94         usb_log_debug2("EP(%p): Creating for %p", ehci_ep, ep);
    9596        link_initialize(&ehci_ep->link);
    96         qh_init(ehci_ep->qh, ep);
    97         endpoint_set_hc_data(
    98             ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
    99         hc_enqueue_endpoint(hc, ep);
    10097        return EOK;
    10198}
     
    106103 * @param[in] ep endpoint structure.
    107104 */
    108 void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
     105static void ehci_endpoint_destroy(endpoint_t *ep)
    109106{
    110         assert(hcd);
    111107        assert(ep);
    112         hc_t *hc = hcd_get_driver_data(hcd);
     108        ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    113109
    114         ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    115         hc_dequeue_endpoint(hc, ep);
    116         endpoint_clear_hc_data(ep);
    117         usb_log_debug2("EP(%p): Destroying for %p", instance, ep);
    118         if (instance) {
    119                 free32(instance->qh);
    120                 free(instance);
    121         }
     110        free32(instance->qh);
     111        free(instance);
    122112}
     113
     114
     115static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep)
     116{
     117        ehci_bus_t *bus = (ehci_bus_t *) bus_base;
     118        ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
     119
     120        const int err = bus->parent_ops.register_endpoint(bus_base, ep);
     121        if (err)
     122                return err;
     123
     124        qh_init(ehci_ep->qh, ep);
     125        hc_enqueue_endpoint(bus->hc, ep);
     126
     127        return EOK;
     128}
     129
     130static int ehci_release_ep(bus_t *bus_base, endpoint_t *ep)
     131{
     132        ehci_bus_t *bus = (ehci_bus_t *) bus_base;
     133        assert(bus);
     134        assert(ep);
     135
     136        const int err = bus->parent_ops.release_endpoint(bus_base, ep);
     137        if (err)
     138                return err;
     139
     140        hc_dequeue_endpoint(bus->hc, ep);
     141        return EOK;
     142
     143}
     144
     145int ehci_bus_init(ehci_bus_t *bus, hc_t *hc)
     146{
     147        assert(hc);
     148        assert(bus);
     149
     150        // FIXME: Implement the USB2 bw counting.
     151        usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
     152
     153        bus_ops_t *ops = &bus->base.base.ops;
     154        bus->parent_ops = *ops;
     155        ops->create_endpoint = ehci_endpoint_create;
     156        ops->destroy_endpoint = ehci_endpoint_destroy;
     157        ops->endpoint_set_toggle = ehci_ep_toggle_set;
     158        ops->endpoint_get_toggle = ehci_ep_toggle_get;
     159
     160        ops->register_endpoint = ehci_register_ep;
     161        ops->release_endpoint = ehci_release_ep;
     162
     163        return EOK;
     164}
     165
    123166/**
    124167 * @}
    125168 */
    126 
Note: See TracChangeset for help on using the changeset viewer.