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

Changeset fc0271a5 in mainline


Ignore:
Timestamp:
2017-10-12T16:06:37Z (3 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
master
Children:
f9d787c
Parents:
d0db4a0
Message:

WIP usbhost refactoring: uhci converted

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/hc.c

    rd0db4a0 rfc0271a5  
    442442        assert(batch);
    443443
    444         if (batch->ep->address == uhci_rh_get_address(&instance->rh))
     444        if (batch->ep->target.address == uhci_rh_get_address(&instance->rh))
    445445                return uhci_rh_schedule(&instance->rh, batch);
    446446
  • uspace/drv/bus/usb/uhci/hc.h

    rd0db4a0 rfc0271a5  
    4343#include <ddi.h>
    4444#include <usb/host/hcd.h>
     45#include <usb/host/usb2_bus.h>
    4546#include <usb/host/usb_transfer_batch.h>
    4647
     
    100101typedef struct hc {
    101102        uhci_rh_t rh;
     103        usb2_bus_t bus;
    102104        /** Addresses of I/O registers */
    103105        uhci_regs_t *registers;
  • uspace/drv/bus/usb/uhci/main.c

    rd0db4a0 rfc0271a5  
    4545#include <usb/debug.h>
    4646#include <usb/host/ddf_helpers.h>
     47#include <usb/host/bandwidth.h>
    4748
    4849#include "hc.h"
     
    5758static const ddf_hc_driver_t uhci_hc_driver = {
    5859        .claim = disable_legacy,
    59         .hc_speed = USB_SPEED_FULL,
    6060        .irq_code_gen = uhci_hc_gen_irq_code,
    6161        .init = uhci_driver_init,
     
    7272static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res)
    7373{
     74        int err;
     75
    7476        assert(hcd);
    7577        assert(hcd_get_driver_data(hcd) == NULL);
     
    7981                return ENOMEM;
    8082
    81         const int ret = hc_init(instance, res);
    82         if (ret == EOK) {
    83                 hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
    84         } else {
    85                 free(instance);
    86         }
    87         return ret;
     83        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)))
     87                goto err;
     88
     89        hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops, &instance->bus.base);
     90
     91        return EOK;
     92
     93err:
     94        free(instance);
     95        return err;
    8896}
    8997
     
    105113                hc_fini(hc);
    106114
    107         hcd_set_implementation(hcd, NULL, NULL);
     115        hcd_set_implementation(hcd, NULL, NULL, NULL);
    108116        free(hc);
    109117}
  • uspace/drv/bus/usb/uhci/uhci_batch.c

    rd0db4a0 rfc0271a5  
    228228            uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW;
    229229        const size_t mps = uhci_batch->usb_batch->ep->max_packet_size;
    230         const usb_target_t target = {{
    231             uhci_batch->usb_batch->ep->address,
    232             uhci_batch->usb_batch->ep->endpoint }};
     230        const usb_target_t target = uhci_batch->usb_batch->ep->target;
    233231
    234232        int toggle = endpoint_toggle_get(uhci_batch->usb_batch->ep);
     
    293291            uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW;
    294292        const size_t mps = uhci_batch->usb_batch->ep->max_packet_size;
    295         const usb_target_t target = {{
    296             uhci_batch->usb_batch->ep->address,
    297             uhci_batch->usb_batch->ep->endpoint }};
     293        const usb_target_t target = uhci_batch->usb_batch->ep->target;
    298294
    299295        /* setup stage */
  • uspace/drv/bus/usb/uhci/uhci_rh.c

    rd0db4a0 rfc0271a5  
    103103        assert(batch);
    104104
    105         const usb_target_t target = {{
    106                 .address = batch->ep->address,
    107                 .endpoint = batch->ep->endpoint
    108         }};
     105        const usb_target_t target = batch->ep->target;
    109106        do {
    110107                batch->error = virthub_base_request(&instance->base, target,
  • uspace/lib/usbhost/include/usb/host/bandwidth.h

    rd0db4a0 rfc0271a5  
    4949#define BANDWIDTH_AVAILABLE_USB20  1
    5050
    51 extern size_t bandwidth_count_usb11(usb_speed_t, usb_transfer_type_t, size_t, size_t);
     51typedef struct endpoint endpoint_t;
    5252
    53 extern size_t bandwidth_count_usb20(usb_speed_t, usb_transfer_type_t, size_t, size_t);
     53extern size_t bandwidth_count_usb11(endpoint_t *, size_t);
     54
     55extern size_t bandwidth_count_usb20(endpoint_t *, size_t);
    5456
    5557#endif
  • uspace/lib/usbhost/include/usb/host/hcd.h

    rd0db4a0 rfc0271a5  
    5858        /** Transfer scheduling, implement in device driver. */
    5959        schedule_hook_t schedule;
    60         /** Hook called upon registering new endpoint. */
    61         ep_add_hook_t ep_add_hook;
    62         /** Hook called upon removing of an endpoint. */
    63         ep_remove_hook_t ep_remove_hook;
    6460        /** Hook to be called on device interrupt, passes ARG1 */
    6561        interrupt_hook_t irq_hook;
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    rd0db4a0 rfc0271a5  
    5050/** Endpoint management structure */
    5151typedef struct usb2_bus {
    52         bus_t bus;                      /**< Inheritance - keep this first */
     52        bus_t base;                     /**< Inheritance - keep this first */
    5353
    5454        /* Device bookkeeping */
  • uspace/lib/usbhost/src/bandwidth.c

    rd0db4a0 rfc0271a5  
    3535
    3636#include <usb/host/bandwidth.h>
     37#include <usb/host/endpoint.h>
    3738
    3839#include <assert.h>
     
    4647 * @param max_packet_size Maximum bytes in one packet.
    4748 */
    48 size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
    49     size_t size, size_t max_packet_size)
     49size_t bandwidth_count_usb11(endpoint_t *ep, size_t size)
    5050{
     51        assert(ep);
     52
     53        const usb_transfer_type_t type = ep->transfer_type;
     54
    5155        /* We care about bandwidth only for interrupt and isochronous. */
    5256        if ((type != USB_TRANSFER_INTERRUPT)
     
    5559        }
    5660
     61        const size_t max_packet_size = ep->max_packet_size;
     62
    5763        const unsigned packet_count =
    5864            (size + max_packet_size - 1) / max_packet_size;
     
    6066         * transaction, but I did not find text in USB spec to confirm this */
    6167        /* NOTE: All data packets will be considered to be max_packet_size */
    62         switch (speed)
     68        switch (ep->speed)
    6369        {
    6470        case USB_SPEED_LOW:
     
    94100 * @param max_packet_size Maximum bytes in one packet.
    95101 */
    96 size_t bandwidth_count_usb20(usb_speed_t speed, usb_transfer_type_t type,
    97     size_t size, size_t max_packet_size)
     102size_t bandwidth_count_usb20(endpoint_t *ep, size_t size)
    98103{
     104        assert(ep);
     105
     106        const usb_transfer_type_t type = ep->transfer_type;
     107
    99108        /* We care about bandwidth only for interrupt and isochronous. */
    100109        if ((type != USB_TRANSFER_INTERRUPT)
  • uspace/lib/usbhost/src/usb2_bus.c

    rd0db4a0 rfc0271a5  
    291291        assert(bus);
    292292
    293         bus_init(&bus->bus, hcd);
    294 
    295         bus->bus.ops = usb2_bus_ops;
    296         bus->bus.ops.count_bw = count_bw;
     293        bus_init(&bus->base, hcd);
     294
     295        bus->base.ops = usb2_bus_ops;
     296        bus->base.ops.count_bw = count_bw;
    297297
    298298        bus->free_bw = available_bandwidth;
Note: See TracChangeset for help on using the changeset viewer.