Changeset e6b9182 in mainline for uspace/drv/bus/usb/ohci


Ignore:
Timestamp:
2017-10-13T08:49:29Z (8 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.

Location:
uspace/drv/bus/usb/ohci
Files:
8 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),
Note: See TracChangeset for help on using the changeset viewer.