Changeset 41924f30 in mainline for uspace/drv/bus


Ignore:
Timestamp:
2017-10-12T14:07:27Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a5976973
Parents:
7e74911
Message:

WIP usbhost refactoring

This commit replaces callbacks with more systematic virtual-like inheritance-like solution. Currently breaks build of HelenOS, but both xhci and usbhost are buildable. More refactoring follows…

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

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/status.h

    r7e74911 r41924f30  
    112112        if ((status & USB_HUB_PORT_STATUS_HIGH_SPEED) != 0)
    113113                return USB_SPEED_HIGH;
     114        /* TODO: add super speed */
    114115        return USB_SPEED_FULL;
    115116}
  • uspace/drv/bus/usb/xhci/Makefile

    r7e74911 r41924f30  
    4545
    4646SOURCES = \
     47        bus.c \
     48        commands.c \
     49        debug.c \
     50        endpoint.c \
    4751        hc.c \
    48         endpoint.c \
    49         debug.c \
    50         trb_ring.c \
     52        main.c \
     53        rh.c \
    5154        scratchpad.c \
    52         commands.c \
    5355        transfers.c \
    54         rh.c \
    55         main.c
     56        trb_ring.c
    5657
    5758TEST_SOURCES = \
  • uspace/drv/bus/usb/xhci/endpoint.c

    r7e74911 r41924f30  
    3434 */
    3535
     36#include <usb/host/endpoint.h>
     37
    3638#include <errno.h>
    3739
     40#include "bus.h"
    3841#include "endpoint.h"
    3942
    40 int endpoint_init(hcd_t *hcd, endpoint_t *ep)
     43int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, xhci_bus_t *xhci_bus)
    4144{
    42         assert(ep);
    43         xhci_endpoint_t *xhci_ep = malloc(sizeof(xhci_endpoint_t));
    44         if (xhci_ep == NULL)
    45                 return ENOMEM;
     45        assert(xhci_ep);
     46        assert(xhci_bus);
     47
     48        bus_t *bus = &xhci_bus->base;
     49        endpoint_t *ep = &xhci_ep->base;
     50
     51        endpoint_init(ep, bus);
    4652
    4753        /* FIXME: Set xhci_ep->slot_id */
    4854
    49         fibril_mutex_lock(&ep->guard);
    50         ep->hc_data.data = xhci_ep;
    51         /* FIXME: The two handlers below should be implemented. */
    52         ep->hc_data.toggle_get = NULL;
    53         ep->hc_data.toggle_set = NULL;
    54         fibril_mutex_unlock(&ep->guard);
    55 
    56         usb_log_debug("Endpoint %d:%d initialized.", ep->address, ep->endpoint);
     55        usb_log_debug("XHCI Endpoint %d:%d initialized.", ep->target.address, ep->target.endpoint);
    5756
    5857        return EOK;
    5958}
    6059
    61 void endpoint_fini(hcd_t *hcd, endpoint_t *ep)
     60void xhci_endpoint_fini(xhci_endpoint_t *xhci_ep)
    6261{
    63         assert(hcd);
    64         assert(ep);
    65         xhci_endpoint_t *xhci_ep = endpoint_get(ep);
     62        assert(xhci_ep);
     63
    6664        /* FIXME: Tear down TR's? */
    67         if (xhci_ep) {
    68                 free(xhci_ep);
    69         }
    7065
    71         fibril_mutex_lock(&ep->guard);
    72         ep->hc_data.data = NULL;
    73         ep->hc_data.toggle_get = NULL;
    74         ep->hc_data.toggle_set = NULL;
    75         fibril_mutex_unlock(&ep->guard);
     66        endpoint_t *ep = &xhci_ep->base;
    7667
    77         usb_log_debug("Endpoint %d:%d destroyed.", ep->address, ep->endpoint);
     68        usb_log_debug("XHCI Endpoint %d:%d destroyed.", ep->target.address, ep->target.endpoint);
    7869}
    7970
  • uspace/drv/bus/usb/xhci/endpoint.h

    r7e74911 r41924f30  
    4343#include <usb/host/hcd.h>
    4444
     45typedef struct xhci_endpoint xhci_endpoint_t;
     46typedef struct xhci_bus xhci_bus_t;
     47
    4548enum {
    4649        EP_TYPE_INVALID = 0,
     
    5659/** Connector structure linking endpoint context to the endpoint. */
    5760typedef struct xhci_endpoint {
     61        endpoint_t base;        /**< Inheritance. Keep this first. */
     62
    5863        uint32_t slot_id;
    5964} xhci_endpoint_t;
    6065
    61 int endpoint_init(hcd_t *hcd, endpoint_t *ep);
    62 void endpoint_fini(hcd_t *hcd, endpoint_t *ep);
     66int xhci_endpoint_init(xhci_endpoint_t *, xhci_bus_t *);
     67void xhci_endpoint_fini(xhci_endpoint_t *);
    6368
    64 static inline xhci_endpoint_t * endpoint_get(const endpoint_t *ep)
     69static inline xhci_endpoint_t * xhci_endpoint_get(endpoint_t *ep)
    6570{
    6671        assert(ep);
    67         return ep->hc_data.data;
     72        return (xhci_endpoint_t *) ep;
    6873}
    6974
  • uspace/drv/bus/usb/xhci/hc.c

    r7e74911 r41924f30  
    447447
    448448        /* Check for root hub communication */
    449         if (batch->ep->address == xhci_rh_get_address(&hc->rh)) {
     449        if (batch->ep->target.address == xhci_rh_get_address(&hc->rh)) {
    450450                usb_log_debug("XHCI root hub request.\n");
    451451                return xhci_rh_schedule(&hc->rh, batch);
     
    453453
    454454        usb_log_debug2("EP(%d:%d) started %s transfer of size %lu.",
    455                 batch->ep->address, batch->ep->endpoint,
     455                batch->ep->target.address, batch->ep->target.endpoint,
    456456                usb_str_transfer_type(batch->ep->transfer_type),
    457457                batch->buffer_size);
    458458
    459         if (!batch->ep->address) {
     459        if (!batch->ep->target.address) {
    460460                usb_log_error("Attempted to schedule transfer to address 0.");
    461461                return EINVAL;
  • uspace/drv/bus/usb/xhci/hc.h

    r7e74911 r41924f30  
    4343#include "trb_ring.h"
    4444#include "rh.h"
     45#include "bus.h"
    4546
    4647typedef struct xhci_virt_device_ctx {
     
    7273        xhci_rh_t rh;
    7374
     75        /* Bus bookkeeping */
     76        xhci_bus_t bus;
     77
    7478        /* Cached capabilities */
    7579        unsigned max_slots;
  • uspace/drv/bus/usb/xhci/main.c

    r7e74911 r41924f30  
    6666                .schedule       = hcd_schedule,
    6767                .irq_hook       = hcd_interrupt,
    68                 .ep_add_hook    = endpoint_init,
    69                 .ep_remove_hook = endpoint_fini,
    7068                .status_hook    = hcd_status,
    7169        }
     
    8381                goto err;
    8482
     83        if ((err = xhci_bus_init(&hc->bus, hcd)))
     84                goto err;
     85
    8586        if ((err = hc_init_memory(hc)))
    8687                goto err;
    8788
    88         hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops);
     89        hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base);
    8990
    9091        return EOK;
  • uspace/drv/bus/usb/xhci/rh.c

    r7e74911 r41924f30  
    266266        assert(rh);
    267267        assert(batch);
    268         const usb_target_t target = {{
    269                 .address = batch->ep->address,
    270                 .endpoint = batch->ep->endpoint,
    271         }};
     268        const usb_target_t target = batch->ep->target;
    272269        batch->error = virthub_base_request(&rh->base, target,
    273270            usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
     
    294291        rh->unfinished_interrupt_transfer = NULL;
    295292        if (batch) {
    296                 const usb_target_t target = {{
    297                         .address = batch->ep->address,
    298                         .endpoint = batch->ep->endpoint,
    299                 }};
     293                const usb_target_t target = batch->ep->target;
    300294                batch->error = virthub_base_request(&rh->base, target,
    301295                    usb_transfer_batch_direction(batch),
  • uspace/drv/bus/usb/xhci/transfers.c

    r7e74911 r41924f30  
    3636#include <usb/host/utils/malloc32.h>
    3737#include <usb/debug.h>
     38#include "endpoint.h"
    3839#include "hc.h"
    3940#include "hw_struct/trb.h"
     
    141142                return EINVAL;
    142143        }
    143         if (batch->ep->endpoint != 0 || batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
     144        if (batch->ep->target.endpoint != 0 || batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
    144145                /* This method only works for control transfers. */
    145146                usb_log_error("Attempted to schedule control transfer to non 0 endpoint.");
     
    147148        }
    148149
    149         uint8_t slot_id = batch->ep->hc_data.slot_id;
     150        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(batch->ep);
     151
     152        uint8_t slot_id = xhci_ep->slot_id;
    150153        xhci_trb_ring_t* ring = hc->dcbaa_virt[slot_id].trs[0];
    151154
     
    230233        }
    231234
    232         uint8_t slot_id = batch->ep->hc_data.slot_id;
    233         xhci_trb_ring_t* ring = hc->dcbaa_virt[slot_id].trs[batch->ep->endpoint];
     235        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(batch->ep);
     236        uint8_t slot_id = xhci_ep->slot_id;
     237        xhci_trb_ring_t* ring = hc->dcbaa_virt[slot_id].trs[batch->ep->target.endpoint];
    234238
    235239        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
Note: See TracChangeset for help on using the changeset viewer.