Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/hcd.c

    rf527f58 r20eaa82  
    4444#include "hcd.h"
    4545
    46 /** Calls ep_add_hook upon endpoint registration.
    47  * @param ep Endpoint to be registered.
    48  * @param arg hcd_t in disguise.
    49  * @return Error code.
    50  */
    51 static int register_helper(endpoint_t *ep, void *arg)
    52 {
    53         hcd_t *hcd = arg;
    54         assert(ep);
    55         assert(hcd);
    56         if (hcd->ops.ep_add_hook)
    57                 return hcd->ops.ep_add_hook(hcd, ep);
    58         return EOK;
    59 }
    60 
    61 /** Calls ep_remove_hook upon endpoint removal.
    62  * @param ep Endpoint to be unregistered.
    63  * @param arg hcd_t in disguise.
    64  */
    65 static void unregister_helper(endpoint_t *ep, void *arg)
    66 {
    67         hcd_t *hcd = arg;
    68         assert(ep);
    69         assert(hcd);
    70         if (hcd->ops.ep_remove_hook)
    71                 hcd->ops.ep_remove_hook(hcd, ep);
    72 }
    73 
    74 /** Calls ep_remove_hook upon endpoint removal. Prints warning.
    75  *  * @param ep Endpoint to be unregistered.
    76  *   * @param arg hcd_t in disguise.
    77  *    */
    78 static void unregister_helper_warn(endpoint_t *ep, void *arg)
    79 {
    80         assert(ep);
    81         usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n",
    82             ep->address, ep->endpoint, usb_str_direction(ep->direction));
    83         unregister_helper(ep, arg);
    84 }
    85 
    8646
    8747/** Initialize hcd_t structure.
     
    9353 * @param bw_count Bandwidth compute function, passed to endpoint manager.
    9454 */
    95 void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
    96     bw_count_func_t bw_count)
    97 {
    98         assert(hcd);
    99         usb_bus_init(&hcd->bus, bandwidth, bw_count, max_speed);
    100 
    101         hcd_set_implementation(hcd, NULL, NULL);
     55void hcd_init(hcd_t *hcd) {
     56        assert(hcd);
     57
     58        hcd_set_implementation(hcd, NULL, NULL, NULL);
    10259}
    10360
     
    10663        assert(hcd);
    10764        usb_address_t address = 0;
    108         const int ret = usb_bus_request_address(
    109             &hcd->bus, &address, false, speed);
     65        const int ret = bus_request_address(hcd->bus, &address, false, speed);
    11066        if (ret != EOK)
    11167                return ret;
    11268        return address;
    11369}
    114 
    115 int hcd_release_address(hcd_t *hcd, usb_address_t address)
    116 {
    117         assert(hcd);
    118         return usb_bus_remove_address(&hcd->bus, address,
    119             unregister_helper_warn, hcd);
    120 }
    121 
    122 int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed)
    123 {
    124         assert(hcd);
    125         usb_address_t address = 0;
    126         return usb_bus_request_address(&hcd->bus, &address, true, speed);
    127 }
    128 
    129 int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
    130     usb_transfer_type_t type, size_t max_packet_size, unsigned packets,
    131     size_t size, usb_address_t tt_address, unsigned tt_port)
    132 {
    133         assert(hcd);
    134         return usb_bus_add_ep(&hcd->bus, target.address,
    135             target.endpoint, dir, type, max_packet_size, packets, size,
    136             register_helper, hcd, tt_address, tt_port);
    137 }
    138 
    139 int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir)
    140 {
    141         assert(hcd);
    142         return usb_bus_remove_ep(&hcd->bus, target.address,
    143             target.endpoint, dir, unregister_helper, hcd);
    144 }
    145 
    14670
    14771typedef struct {
     
    15983                usb_log_debug2("Reseting toggle on %d:%d.\n",
    16084                    toggle->target.address, toggle->target.endpoint);
    161                 usb_bus_reset_toggle(&toggle->hcd->bus,
     85                bus_reset_toggle(toggle->hcd->bus,
    16286                    toggle->target, toggle->target.endpoint == 0);
    16387        }
     
    185109        assert(hcd);
    186110
    187         endpoint_t *ep = usb_bus_find_ep(&hcd->bus,
    188             target.address, target.endpoint, direction);
     111        endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction);
    189112        if (ep == NULL) {
    190113                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     
    196119            name, target.address, target.endpoint, size, ep->max_packet_size);
    197120
    198         const size_t bw = bandwidth_count_usb11(
    199             ep->speed, ep->transfer_type, size, ep->max_packet_size);
     121        const size_t bw = bus_count_bw(ep, size);
    200122        /* Check if we have enough bandwidth reserved */
    201123        if (ep->bandwidth < bw) {
    202124                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    203125                    "but only %zu is reserved.\n",
    204                     ep->address, ep->endpoint, name, bw, ep->bandwidth);
     126                    ep->target.address, ep->target.endpoint, name, bw, ep->bandwidth);
    205127                return ENOSPC;
    206128        }
     
    248170
    249171typedef struct {
    250         volatile unsigned done;
     172        fibril_mutex_t done_mtx;
     173        fibril_condvar_t done_cv;
     174        unsigned done;
    251175        int ret;
    252176        size_t size;
     
    258182        assert(d);
    259183        d->ret = ret;
     184        d->size = size;
     185        fibril_mutex_lock(&d->done_mtx);
    260186        d->done = 1;
    261         d->size = size;
     187        fibril_condvar_broadcast(&d->done_cv);
     188        fibril_mutex_unlock(&d->done_mtx);
    262189}
    263190
     
    267194        assert(data);
    268195        d->ret = ret;
     196        fibril_mutex_lock(&d->done_mtx);
    269197        d->done = 1;
     198        fibril_condvar_broadcast(&d->done_cv);
     199        fibril_mutex_unlock(&d->done_mtx);
    270200}
    271201
     
    277207        assert(hcd);
    278208        sync_data_t sd = { .done = 0, .ret = EBUSY, .size = size };
     209        fibril_mutex_initialize(&sd.done_mtx);
     210        fibril_condvar_initialize(&sd.done_cv);
    279211
    280212        const int ret = hcd_send_batch(hcd, target, dir, data, size, setup_data,
     
    284216                return ret;
    285217
    286         while (!sd.done) {
    287                 async_usleep(1000);
    288         }
     218        fibril_mutex_lock(&sd.done_mtx);
     219        while (!sd.done)
     220                fibril_condvar_wait(&sd.done_cv, &sd.done_mtx);
     221        fibril_mutex_unlock(&sd.done_mtx);
    289222
    290223        if (sd.ret == EOK)
Note: See TracChangeset for help on using the changeset viewer.