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

Changeset 41924f30 in mainline for uspace/lib/usbhost/src/hcd.c


Ignore:
Timestamp:
2017-10-12T14:07:27Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
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…

File:
1 edited

Legend:

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

    r7e74911 r41924f30  
    4444#include "hcd.h"
    4545
    46 /** Calls ep_add_hook upon endpoint registration.
     46
     47/*[>* Calls ep_add_hook upon endpoint registration.
    4748 * @param ep Endpoint to be registered.
    4849 * @param arg hcd_t in disguise.
    4950 * @return Error code.
    50  */
     51 * OH TODO: remove
     52 <]
    5153static int register_helper(endpoint_t *ep, void *arg)
    5254{
     
    5961}
    6062
    61 /** Calls ep_remove_hook upon endpoint removal.
     63[>* Calls ep_remove_hook upon endpoint removal.
    6264 * @param ep Endpoint to be unregistered.
    6365 * @param arg hcd_t in disguise.
    64  */
     66 * OH TODO: remove
     67 <]
    6568static void unregister_helper(endpoint_t *ep, void *arg)
    6669{
     
    7275}
    7376
    74 /** Calls ep_remove_hook upon endpoint removal. Prints warning.
     77[>* Calls ep_remove_hook upon endpoint removal. Prints warning.
    7578 *  * @param ep Endpoint to be unregistered.
    7679 *   * @param arg hcd_t in disguise.
    77  *    */
     80 * OH TODO: remove
     81 *    <]
    7882static void unregister_helper_warn(endpoint_t *ep, void *arg)
    7983{
    8084        assert(ep);
    8185        usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n",
    82             ep->address, ep->endpoint, usb_str_direction(ep->direction));
     86            ep->target.address, ep->target.endpoint, usb_str_direction(ep->direction));
    8387        unregister_helper(ep, arg);
    8488}
    85 
     89*/
    8690
    8791/** Initialize hcd_t structure.
     
    9397 * @param bw_count Bandwidth compute function, passed to endpoint manager.
    9498 */
    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);
     99void hcd_init(hcd_t *hcd) {
     100        assert(hcd);
     101
     102        hcd_set_implementation(hcd, NULL, NULL, NULL);
    102103}
    103104
     
    106107        assert(hcd);
    107108        usb_address_t address = 0;
    108         const int ret = usb_bus_request_address(
    109             &hcd->bus, &address, false, speed);
     109        const int ret = bus_request_address(hcd->bus, &address, false, speed);
    110110        if (ret != EOK)
    111111                return ret;
     
    116116{
    117117        assert(hcd);
    118         return usb_bus_remove_address(&hcd->bus, address,
    119             unregister_helper_warn, hcd);
     118        return bus_release_address(hcd->bus, address);
     119        // OH TODO removed helper
    120120}
    121121
     
    124124        assert(hcd);
    125125        usb_address_t address = 0;
    126         return usb_bus_request_address(&hcd->bus, &address, true, speed);
     126        return bus_request_address(hcd->bus, &address, true, speed);
    127127}
    128128
     
    132132{
    133133        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);
     134
     135        /* Temporary reference */
     136        endpoint_t *ep = bus_create_endpoint(hcd->bus);
     137        if (!ep)
     138                return ENOMEM;
     139
     140        ep->target = target;
     141        ep->direction = dir;
     142        ep->transfer_type = type;
     143        ep->max_packet_size = max_packet_size;
     144        ep->packets = packets;
     145
     146        ep->tt.address = tt_address;
     147        ep->tt.port = tt_port;
     148
     149        const int err = bus_register_endpoint(hcd->bus, ep);
     150
     151        /* drop Temporary reference */
     152        endpoint_del_ref(ep);
     153
     154        return err;
    137155}
    138156
     
    140158{
    141159        assert(hcd);
    142         return usb_bus_remove_ep(&hcd->bus, target.address,
    143             target.endpoint, dir, unregister_helper, hcd);
     160        endpoint_t *ep = bus_find_endpoint(hcd->bus, target, dir);
     161        if (!ep)
     162                return ENOENT;
     163
     164        return bus_release_endpoint(hcd->bus, ep);
     165        // OH TODO removed helper
    144166}
    145167
     
    159181                usb_log_debug2("Reseting toggle on %d:%d.\n",
    160182                    toggle->target.address, toggle->target.endpoint);
    161                 usb_bus_reset_toggle(&toggle->hcd->bus,
     183                bus_reset_toggle(toggle->hcd->bus,
    162184                    toggle->target, toggle->target.endpoint == 0);
    163185        }
     
    185207        assert(hcd);
    186208
    187         endpoint_t *ep = usb_bus_find_ep(&hcd->bus,
    188             target.address, target.endpoint, direction);
     209        endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction);
    189210        if (ep == NULL) {
    190211                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     
    196217            name, target.address, target.endpoint, size, ep->max_packet_size);
    197218
    198         const size_t bw = bandwidth_count_usb11(
    199             ep->speed, ep->transfer_type, size, ep->max_packet_size);
     219        const size_t bw = bus_count_bw(ep, size);
    200220        /* Check if we have enough bandwidth reserved */
    201221        if (ep->bandwidth < bw) {
    202222                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    203223                    "but only %zu is reserved.\n",
    204                     ep->address, ep->endpoint, name, bw, ep->bandwidth);
     224                    ep->target.address, ep->target.endpoint, name, bw, ep->bandwidth);
    205225                return ENOSPC;
    206226        }
Note: See TracChangeset for help on using the changeset viewer.