Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 741bcdeb in mainline


Ignore:
Timestamp:
2017-10-13T09:21:22Z (3 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
master
Children:
c0e4b5b2
Parents:
e6b9182
Message:

WIP usbhost refactoring: ehci completed

vhc to go…

Location:
uspace/drv/bus/usb
Files:
9 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/Makefile

    re6b9182 r741bcdeb  
    4646SOURCES = \
    4747        ehci_batch.c \
    48         ehci_endpoint.c \
     48        ehci_bus.c \
    4949        ehci_rh.c \
    5050        endpoint_list.c \
  • uspace/drv/bus/usb/ehci/ehci_batch.c

    re6b9182 r741bcdeb  
    4545
    4646#include "ehci_batch.h"
    47 #include "ehci_endpoint.h"
     47#include "ehci_bus.h"
    4848
    4949/* The buffer pointer list in the qTD is long enough to support a maximum
  • 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 
  • uspace/drv/bus/usb/ehci/ehci_bus.h

    re6b9182 r741bcdeb  
    11/*
    22 * Copyright (c) 2011 Jan Vesely
     3 * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz>
    34 * All rights reserved.
    45 *
     
    3233 * @brief EHCI driver
    3334 */
    34 #ifndef DRV_EHCI_HCD_ENDPOINT_H
    35 #define DRV_EHCI_HCD_ENDPOINT_H
     35#ifndef DRV_EHCI_HCD_BUS_H
     36#define DRV_EHCI_HCD_BUS_H
    3637
    3738#include <assert.h>
    3839#include <adt/list.h>
     40#include <usb/host/usb2_bus.h>
    3941#include <usb/host/endpoint.h>
    40 #include <usb/host/hcd.h>
    4142
    4243#include "hw_struct/queue_head.h"
    43 #include "hw_struct/transfer_descriptor.h"
    4444
    4545/** Connector structure linking ED to to prepared TD. */
    4646typedef struct ehci_endpoint {
     47        /* Inheritance */
     48        endpoint_t base;
     49
    4750        /** EHCI endpoint descriptor */
    4851        qh_t *qh;
     
    5154} ehci_endpoint_t;
    5255
    53 int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep);
    54 void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep);
     56typedef struct hc hc_t;
     57
     58typedef struct {
     59        usb2_bus_t base;
     60        hc_t *hc;
     61
     62        /* Stored original ops from base, they are called in our handlers */
     63        bus_ops_t parent_ops;
     64} ehci_bus_t;
     65
     66int ehci_bus_init(ehci_bus_t *, hc_t *);
    5567
    5668/** Get and convert assigned ehci_endpoint_t structure
     
    6173{
    6274        assert(ep);
    63         return ep->hc_data.data;
     75        return (ehci_endpoint_t *) ep;
    6476}
    6577
     
    7385 * @}
    7486 */
    75 
  • uspace/drv/bus/usb/ehci/ehci_rh.c

    re6b9182 r741bcdeb  
    144144        assert(instance);
    145145        assert(batch);
    146         const usb_target_t target = {{
    147                 .address = batch->ep->address,
    148                 .endpoint = batch->ep->endpoint,
    149         }};
     146        const usb_target_t target = batch->ep->target;
    150147        batch->error = virthub_base_request(&instance->base, target,
    151148            usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
     
    183180            instance, batch);
    184181        if (batch) {
    185                 const usb_target_t target = {{
    186                         .address = batch->ep->address,
    187                         .endpoint = batch->ep->endpoint,
    188                 }};
     182                const usb_target_t target = batch->ep->target;
    189183                batch->error = virthub_base_request(&instance->base, target,
    190184                    usb_transfer_batch_direction(batch),
  • uspace/drv/bus/usb/ehci/endpoint_list.h

    re6b9182 r741bcdeb  
    4040#include <usb/host/utils/malloc32.h>
    4141
    42 #include "ehci_endpoint.h"
     42#include "ehci_bus.h"
    4343#include "hw_struct/queue_head.h"
    4444
  • uspace/drv/bus/usb/ehci/hc.c

    re6b9182 r741bcdeb  
    190190            &instance->rh, instance->caps, instance->registers, "ehci rh");
    191191
     192        ehci_bus_init(&instance->bus, instance);
    192193        return EOK;
    193194}
     
    214215        ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
    215216        usb_log_debug("HC(%p) enqueue EP(%d:%d:%s:%s)\n", instance,
    216             ep->address, ep->endpoint,
     217            ep->target.address, ep->target.endpoint,
    217218            usb_str_transfer_type_short(ep->transfer_type),
    218219            usb_str_direction(ep->direction));
     
    238239        ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep);
    239240        usb_log_debug("HC(%p) dequeue EP(%d:%d:%s:%s)\n", instance,
    240             ep->address, ep->endpoint,
     241            ep->target.address, ep->target.endpoint,
    241242            usb_str_transfer_type_short(ep->transfer_type),
    242243            usb_str_direction(ep->direction));
     
    290291
    291292        /* Check for root hub communication */
    292         if (batch->ep->address == ehci_rh_get_address(&instance->rh)) {
     293        if (batch->ep->target.address == ehci_rh_get_address(&instance->rh)) {
    293294                usb_log_debug("HC(%p): Scheduling BATCH(%p) for RH(%p)",
    294295                    instance, batch, &instance->rh);
  • uspace/drv/bus/usb/ehci/hc.h

    re6b9182 r741bcdeb  
    8080        /** USB hub emulation structure */
    8181        ehci_rh_t rh;
     82
     83        /** USB bookkeeping */
     84        ehci_bus_t bus;
    8285} hc_t;
    8386
  • uspace/drv/bus/usb/ehci/hw_struct/queue_head.c

    re6b9182 r741bcdeb  
    6565        assert(ep->speed < ARRAY_SIZE(speed));
    6666        EHCI_MEM32_WR(instance->ep_char,
    67             QH_EP_CHAR_ADDR_SET(ep->address) |
    68             QH_EP_CHAR_EP_SET(ep->endpoint) |
     67            QH_EP_CHAR_ADDR_SET(ep->target.address) |
     68            QH_EP_CHAR_EP_SET(ep->target.endpoint) |
    6969            speed[ep->speed] |
    7070            QH_EP_CHAR_MAX_LENGTH_SET(ep->max_packet_size)
  • uspace/drv/bus/usb/ehci/main.c

    re6b9182 r741bcdeb  
    4848#include "res.h"
    4949#include "hc.h"
    50 #include "ehci_endpoint.h"
    5150
    5251#define NAME "ehci"
     
    6766        .ops = {
    6867                .schedule       = ehci_hc_schedule,
    69                 .ep_add_hook    = ehci_endpoint_init,
    70                 .ep_remove_hook = ehci_endpoint_fini,
    7168                .irq_hook       = ehci_hc_interrupt,
    7269                .status_hook    = ehci_hc_status,
     
    8683        const int ret = hc_init(instance, res);
    8784        if (ret == EOK) {
    88                 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops);
     85                hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops, &instance->bus.base.base);
    8986        } else {
    9087                free(instance);
     
    116113
    117114        free(hc);
    118         hcd_set_implementation(hcd, NULL, NULL);
     115        hcd_set_implementation(hcd, NULL, NULL, NULL);
    119116}
    120117
  • uspace/drv/bus/usb/ohci/ohci_bus.c

    re6b9182 r741bcdeb  
    7878        if (ohci_ep == NULL)
    7979                return NULL;
     80
     81        endpoint_init(&ohci_ep->base, bus);
    8082
    8183        ohci_ep->ed = malloc32(sizeof(ed_t));
Note: See TracChangeset for help on using the changeset viewer.