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

Changeset e6b9182 in mainline


Ignore:
Timestamp:
2017-10-13T08:49:29Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
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.

Location:
uspace
Files:
18 edited
2 moved

Legend:

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

    r0a5833d7 re6b9182  
    4949        main.c \
    5050        ohci_batch.c \
    51         ohci_endpoint.c \
     51        ohci_bus.c \
    5252        ohci_rh.c \
    5353        hw_struct/endpoint_descriptor.c \
  • uspace/drv/bus/usb/ohci/endpoint_list.h

    r0a5833d7 re6b9182  
    4141#include <usb/host/utils/malloc32.h>
    4242
    43 #include "ohci_endpoint.h"
     43#include "ohci_bus.h"
    4444#include "hw_struct/endpoint_descriptor.h"
    4545
  • uspace/drv/bus/usb/ohci/hc.c

    r0a5833d7 re6b9182  
    4747#include <usb/usb.h>
    4848
    49 #include "ohci_endpoint.h"
     49#include "ohci_bus.h"
    5050#include "ohci_batch.h"
    5151
     
    287287
    288288        /* Check for root hub communication */
    289         if (batch->ep->address == ohci_rh_get_address(&instance->rh)) {
     289        if (batch->ep->target.address == ohci_rh_get_address(&instance->rh)) {
    290290                usb_log_debug("OHCI root hub request.\n");
    291291                return ohci_rh_schedule(&instance->rh, batch);
  • uspace/drv/bus/usb/ohci/hc.h

    r0a5833d7 re6b9182  
    5252#include "ohci_regs.h"
    5353#include "ohci_rh.h"
     54#include "ohci_bus.h"
    5455#include "endpoint_list.h"
    5556#include "hw_struct/hcca.h"
     
    8081        /** USB hub emulation structure */
    8182        ohci_rh_t rh;
     83
     84        /** USB bookkeeping */
     85        ohci_bus_t bus;
    8286} hc_t;
    8387
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c

    r0a5833d7 re6b9182  
    7979        /* Status: address, endpoint nr, direction mask and max packet size. */
    8080        OHCI_MEM32_WR(instance->status,
    81             ((ep->address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT)
    82             | ((ep->endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT)
     81            ((ep->target.address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT)
     82            | ((ep->target.endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT)
    8383            | ((dir[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
    8484            | ((ep->max_packet_size & ED_STATUS_MPS_MASK)
  • uspace/drv/bus/usb/ohci/main.c

    r0a5833d7 re6b9182  
    4545
    4646#include "hc.h"
     47#include "ohci_bus.h"
    4748
    4849#define NAME "ohci"
     
    5354
    5455static const ddf_hc_driver_t ohci_hc_driver = {
    55         .hc_speed = USB_SPEED_FULL,
    5656        .irq_code_gen = ohci_hc_gen_irq_code,
    5757        .init = ohci_driver_init,
     
    6262        .ops = {
    6363                .schedule       = ohci_hc_schedule,
    64                 .ep_add_hook    = ohci_endpoint_init,
    65                 .ep_remove_hook = ohci_endpoint_fini,
    6664                .irq_hook       = ohci_hc_interrupt,
    6765                .status_hook    = ohci_hc_status,
     
    7270static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res)
    7371{
     72        int err;
     73
    7474        assert(hcd);
    7575        assert(hcd_get_driver_data(hcd) == NULL);
     
    7979                return ENOMEM;
    8080
    81         const int ret = hc_init(instance, res);
    82         if (ret == EOK) {
    83                 hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops);
    84         } else {
    85                 free(instance);
    86         }
    87         return ret;
     81        if ((err = hc_init(instance, res)) != EOK)
     82                goto err;
     83
     84        if ((err = ohci_bus_init(&instance->bus, instance)))
     85                goto err;
     86
     87        hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops, &instance->bus.base.base);
     88
     89        return EOK;
     90
     91err:
     92        free(instance);
     93        return err;
    8894}
    8995
     
    115121                hc_fini(hc);
    116122
    117         hcd_set_implementation(hcd, NULL, NULL);
     123        hcd_set_implementation(hcd, NULL, NULL, NULL);
    118124        free(hc);
    119125}
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r0a5833d7 re6b9182  
    4545
    4646#include "ohci_batch.h"
    47 #include "ohci_endpoint.h"
     47#include "ohci_bus.h"
    4848
    4949static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t);
  • 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
  • uspace/drv/bus/usb/ohci/ohci_bus.h

    r0a5833d7 re6b9182  
    11/*
    22 * Copyright (c) 2011 Jan Vesely
     3 * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz>
    34 * All rights reserved.
    45 *
     
    3233 * @brief OHCI driver
    3334 */
    34 #ifndef DRV_OHCI_HCD_ENDPOINT_H
    35 #define DRV_OHCI_HCD_ENDPOINT_H
     35#ifndef DRV_OHCI_HCD_BUS_H
     36#define DRV_OHCI_HCD_BUS_H
    3637
    3738#include <assert.h>
    3839#include <adt/list.h>
    39 #include <usb/host/endpoint.h>
    40 #include <usb/host/hcd.h>
     40#include <usb/host/usb2_bus.h>
    4141
    4242#include "hw_struct/endpoint_descriptor.h"
     
    4545/** Connector structure linking ED to to prepared TD. */
    4646typedef struct ohci_endpoint {
     47        endpoint_t base;
     48
    4749        /** OHCI endpoint descriptor */
    4850        ed_t *ed;
     
    5355} ohci_endpoint_t;
    5456
    55 int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep);
    56 void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep);
     57typedef struct hc hc_t;
     58
     59typedef struct {
     60        usb2_bus_t base;
     61        hc_t *hc;
     62
     63        /* Stored original ops from base, they are called in our handlers */
     64        bus_ops_t parent_ops;
     65} ohci_bus_t;
     66
     67int ohci_bus_init(ohci_bus_t *, hc_t *);
    5768
    5869/** Get and convert assigned ohci_endpoint_t structure
     
    6374{
    6475        assert(ep);
    65         return ep->hc_data.data;
     76        return (ohci_endpoint_t *) ep;
    6677}
    6778
  • uspace/drv/bus/usb/ohci/ohci_rh.c

    r0a5833d7 re6b9182  
    178178        assert(instance);
    179179        assert(batch);
    180         const usb_target_t target = {{
    181                 .address = batch->ep->address,
    182                 .endpoint = batch->ep->endpoint,
    183         }};
     180        const usb_target_t target = batch->ep->target;
    184181        batch->error = virthub_base_request(&instance->base, target,
    185182            usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
     
    211208        instance->unfinished_interrupt_transfer = NULL;
    212209        if (batch) {
    213                 const usb_target_t target = {{
    214                         .address = batch->ep->address,
    215                         .endpoint = batch->ep->endpoint,
    216                 }};
     210                const usb_target_t target = batch->ep->target;
    217211                batch->error = virthub_base_request(&instance->base, target,
    218212                    usb_transfer_batch_direction(batch),
  • uspace/drv/bus/usb/uhci/hc.c

    r0a5833d7 re6b9182  
    5050#include <usb/usb.h>
    5151#include <usb/host/utils/malloc32.h>
     52#include <usb/host/bandwidth.h>
    5253
    5354#include "uhci_batch.h"
     
    320321int hc_init_mem_structures(hc_t *instance)
    321322{
    322         assert(instance);
     323        int err;
     324        assert(instance);
     325
     326        if ((err = usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11)))
     327                return err;
    323328
    324329        /* Init USB frame list page */
  • uspace/drv/bus/usb/uhci/main.c

    r0a5833d7 re6b9182  
    4545#include <usb/debug.h>
    4646#include <usb/host/ddf_helpers.h>
    47 #include <usb/host/bandwidth.h>
    4847
    4948#include "hc.h"
     
    8281
    8382        if ((err = hc_init(instance, res)) != EOK)
    84                 goto err;
    85 
    86         if ((err = usb2_bus_init(&instance->bus, hcd, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11)))
    8783                goto err;
    8884
  • uspace/drv/bus/usb/xhci/bus.c

    r0a5833d7 re6b9182  
    171171
    172172/* Endpoint ops, optional (have generic fallback) */
    173 static int endpoint_get_toggle(endpoint_t *ep)
    174 {
    175         // TODO: Implement me!
    176         return ENOTSUP;
    177 }
    178 
    179 static void endpoint_set_toggle(endpoint_t *ep, unsigned toggle)
     173static bool endpoint_get_toggle(endpoint_t *ep)
     174{
     175        // TODO: Implement me!
     176        return ENOTSUP;
     177}
     178
     179static void endpoint_set_toggle(endpoint_t *ep, bool toggle)
    180180{
    181181        // TODO: Implement me!
     
    227227};
    228228
    229 int xhci_bus_init(xhci_bus_t *bus, hcd_t *hcd)
    230 {
    231         assert(bus);
    232 
    233         bus_init(&bus->base, hcd);
     229int xhci_bus_init(xhci_bus_t *bus)
     230{
     231        assert(bus);
     232
     233        bus_init(&bus->base);
    234234
    235235        if (!hash_table_create(&bus->endpoints, 0, 0, &endpoint_ht_ops)) {
  • uspace/drv/bus/usb/xhci/bus.h

    r0a5833d7 re6b9182  
    5252         */
    5353
    54         hash_table_t endpoints;
     54        hash_table_t endpoints;
    5555} xhci_bus_t;
    5656
    57 int xhci_bus_init(xhci_bus_t *, hcd_t *);
     57int xhci_bus_init(xhci_bus_t *);
    5858void xhci_bus_fini(xhci_bus_t *);
    5959
  • uspace/drv/bus/usb/xhci/hc.c

    r0a5833d7 re6b9182  
    216216                goto err_cmd;
    217217
    218         return EOK;
    219 
     218        if ((err = xhci_bus_init(&hc->bus)))
     219                goto err_rh;
     220
     221
     222        return EOK;
     223
     224err_rh:
     225        xhci_rh_fini(&hc->rh);
    220226err_cmd:
    221227        xhci_fini_commands(hc);
     
    610616void hc_fini(xhci_hc_t *hc)
    611617{
     618        xhci_bus_fini(&hc->bus);
    612619        xhci_trb_ring_fini(&hc->command_ring);
    613620        xhci_event_ring_fini(&hc->event_ring);
  • uspace/drv/bus/usb/xhci/main.c

    r0a5833d7 re6b9182  
    8181                goto err;
    8282
    83         if ((err = xhci_bus_init(&hc->bus, hcd)))
    84                 goto err;
    85 
    8683        if ((err = hc_init_memory(hc)))
    8784                goto err;
     
    151148        hc_fini(hc);
    152149
    153         // FIXME: Probably move init/fini of XHCI bus into HC.
    154         xhci_bus_fini(&hc->bus);
    155 
    156150        free(hc);
    157151}
  • uspace/lib/usbhost/include/usb/host/bus.h

    r0a5833d7 re6b9182  
    6868        /* Endpoint ops, optional (have generic fallback) */
    6969        void (*destroy_endpoint)(endpoint_t *);
    70         int (*endpoint_get_toggle)(endpoint_t *);
    71         void (*endpoint_set_toggle)(endpoint_t *, unsigned);
     70        bool (*endpoint_get_toggle)(endpoint_t *);
     71        void (*endpoint_set_toggle)(endpoint_t *, bool);
    7272} bus_ops_t;
    7373
    7474/** Endpoint management structure */
    7575typedef struct bus {
    76         hcd_t *hcd;
    77 
    7876        /* Synchronization of ops */
    7977        fibril_mutex_t guard;
     
    8583} bus_t;
    8684
    87 void bus_init(bus_t *, hcd_t *hcd);
     85void bus_init(bus_t *);
    8886
    8987endpoint_t *bus_create_endpoint(bus_t *);
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    r0a5833d7 re6b9182  
    6565} usb2_bus_t;
    6666
    67 extern int usb2_bus_init(usb2_bus_t *, hcd_t *, size_t, count_bw_func_t);
     67extern int usb2_bus_init(usb2_bus_t *, size_t, count_bw_func_t);
    6868
    6969#endif
  • uspace/lib/usbhost/src/bus.c

    r0a5833d7 re6b9182  
    4343 * Initializes the bus structure.
    4444 */
    45 void bus_init(bus_t *bus, hcd_t *hcd)
     45void bus_init(bus_t *bus)
    4646{
    4747        memset(bus, 0, sizeof(bus_t));
    4848
    49         bus->hcd = hcd;
    5049        fibril_mutex_initialize(&bus->guard);
    5150}
  • uspace/lib/usbhost/src/usb2_bus.c

    r0a5833d7 re6b9182  
    4141#include <errno.h>
    4242#include <macros.h>
     43#include <stdlib.h>
    4344#include <stdbool.h>
    4445
     
    110111}
    111112
     113static endpoint_t *usb2_bus_create_ep(bus_t *bus)
     114{
     115        endpoint_t *ep = malloc(sizeof(endpoint_t));
     116        if (!ep)
     117                return NULL;
     118
     119        endpoint_init(ep, bus);
     120        return ep;
     121}
     122
    112123/** Register an endpoint to the bus. Reserves bandwidth.
    113124 * @param bus usb_bus structure, non-null.
     
    271282
    272283static const bus_ops_t usb2_bus_ops = {
     284        .create_endpoint = usb2_bus_create_ep,
    273285        .find_endpoint = usb2_bus_find_ep,
    274286        .release_endpoint = usb2_bus_release_ep,
     
    287299 * @return Error code.
    288300 */
    289 int usb2_bus_init(usb2_bus_t *bus, hcd_t *hcd, size_t available_bandwidth, count_bw_func_t count_bw)
     301int usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth, count_bw_func_t count_bw)
    290302{
    291303        assert(bus);
    292304
    293         bus_init(&bus->base, hcd);
     305        bus_init(&bus->base);
    294306
    295307        bus->base.ops = usb2_bus_ops;
Note: See TracChangeset for help on using the changeset viewer.