Changeset 32fb6bce in mainline for uspace/drv/bus/usb/vhc


Ignore:
Timestamp:
2017-12-18T22:50:21Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

Location:
uspace/drv/bus/usb/vhc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/vhc/main.c

    r1ea0bbf r32fb6bce  
    6969                return ret;
    7070        }
    71         vhc_init(vhc, dev_to_hcd(dev));
    7271        return EOK;
    7372}
    7473
    75 hcd_ops_t vhc_hc_ops = {
    76         .schedule = vhc_schedule,
    77 };
    78 
    7974static int vhc_dev_add(ddf_dev_t *dev)
    8075{
     76        /* Initialize generic structures */
     77        int ret = hcd_ddf_setup_hc(dev, sizeof(vhc_data_t));
     78        if (ret != EOK) {
     79                usb_log_error("Failed to init HCD structures: %s.\n",
     80                   str_error(ret));
     81                return ret;
     82        }
     83        vhc_data_t *vhc = ddf_dev_data_get(dev);
     84        vhc_init(vhc);
     85
     86        hc_device_setup(&vhc->base, (bus_t *) &vhc->bus);
     87
    8188        /* Initialize virtual structure */
    8289        ddf_fun_t *ctl_fun = NULL;
    83         int ret = vhc_control_node(dev, &ctl_fun);
     90        ret = vhc_control_node(dev, &ctl_fun);
    8491        if (ret != EOK) {
    8592                usb_log_error("Failed to setup control node.\n");
    8693                return ret;
    8794        }
    88         vhc_data_t *data = ddf_fun_data_get(ctl_fun);
    89 
    90         /* Initialize generic structures */
    91         ret = hcd_ddf_setup_hc(dev);
    92         if (ret != EOK) {
    93                 usb_log_error("Failed to init HCD structures: %s.\n",
    94                    str_error(ret));
    95                 ddf_fun_destroy(ctl_fun);
    96                 return ret;
    97         }
    98 
    99         hcd_set_implementation(dev_to_hcd(dev), data, &vhc_hc_ops, &data->bus.base);
    10095
    10196        /* Add virtual hub device */
    102         ret = vhc_virtdev_plug_hub(data, &data->hub, NULL, 0);
     97        ret = vhc_virtdev_plug_hub(vhc, &vhc->hub, NULL, 0);
    10398        if (ret != EOK) {
    10499                usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
     
    111106         * needs to be ready at this time.
    112107         */
    113         ret = hcd_setup_virtual_root_hub(dev_to_hcd(dev), dev);
     108        ret = hcd_setup_virtual_root_hub(&vhc->base);
    114109        if (ret != EOK) {
    115110                usb_log_error("Failed to init VHC root hub: %s\n",
  • uspace/drv/bus/usb/vhc/transfer.c

    r1ea0bbf r32fb6bce  
    4040static bool is_set_address_transfer(vhc_transfer_t *transfer)
    4141{
    42         if (transfer->batch->target.endpoint != 0) {
    43                 return false;
    44         }
    45         if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
    46                 return false;
    47         }
    48         if (transfer->batch->dir != USB_DIRECTION_OUT) {
     42        if (transfer->batch.target.endpoint != 0) {
     43                return false;
     44        }
     45        if (transfer->batch.ep->transfer_type != USB_TRANSFER_CONTROL) {
     46                return false;
     47        }
     48        if (transfer->batch.dir != USB_DIRECTION_OUT) {
    4949                return false;
    5050        }
    5151        const usb_device_request_setup_packet_t *setup
    52                 = &transfer->batch->setup.packet;
     52                = &transfer->batch.setup.packet;
    5353        if (setup->request_type != 0) {
    5454                return false;
     
    150150        assert(outcome != ENAK);
    151151        assert(transfer);
    152         assert(transfer->batch);
    153         transfer->batch->error = outcome;
    154         transfer->batch->transfered_size = data_transfer_size;
    155         usb_transfer_batch_finish(transfer->batch);
     152        transfer->batch.error = outcome;
     153        transfer->batch.transfered_size = data_transfer_size;
     154        usb_transfer_batch_finish(&transfer->batch);
    156155        free(transfer);
     156}
     157
     158static usb_transfer_batch_t *batch_create(endpoint_t *ep)
     159{
     160        vhc_transfer_t *transfer = calloc(1, sizeof(vhc_transfer_t));
     161        usb_transfer_batch_init(&transfer->batch, ep);
     162        link_initialize(&transfer->link);
     163        return &transfer->batch;
    157164}
    158165
    159166static const bus_ops_t vhc_bus_ops = {
    160167        .parent = &usb2_bus_ops,
     168
    161169        .endpoint_count_bw = bandwidth_count_usb11,
     170        .batch_create = batch_create,
     171        .batch_schedule = vhc_schedule,
    162172};
    163173
    164 int vhc_init(vhc_data_t *instance, hcd_t *hcd)
     174int vhc_init(vhc_data_t *instance)
    165175{
    166176        assert(instance);
    167177        list_initialize(&instance->devices);
    168178        fibril_mutex_initialize(&instance->guard);
    169         usb2_bus_init(&instance->bus, hcd, BANDWIDTH_AVAILABLE_USB11);
     179        usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
    170180        instance->bus.base.ops = &vhc_bus_ops;
    171         instance->magic = 0xDEADBEEF;
    172181        return virthub_init(&instance->hub, "root hub");
    173182}
    174183
    175 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    176 {
    177         assert(hcd);
     184int vhc_schedule(usb_transfer_batch_t *batch)
     185{
    178186        assert(batch);
    179         vhc_data_t *vhc = hcd_get_driver_data(hcd);
     187        vhc_transfer_t *transfer = (vhc_transfer_t *) batch;
     188        vhc_data_t *vhc = bus_to_vhc(endpoint_get_bus(batch->ep));
    180189        assert(vhc);
    181 
    182         vhc_transfer_t *transfer = malloc(sizeof(vhc_transfer_t));
    183         if (!transfer)
    184                 return ENOMEM;
    185         link_initialize(&transfer->link);
    186         transfer->batch = batch;
    187190
    188191        fibril_mutex_lock(&vhc->guard);
     
    192195        list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
    193196                fibril_mutex_lock(&dev->guard);
    194                 if (dev->address == transfer->batch->target.address) {
     197                if (dev->address == transfer->batch.target.address) {
    195198                        if (!targets) {
    196199                                list_append(&transfer->link, &dev->transfer_queue);
     
    227230                size_t data_transfer_size = 0;
    228231                if (dev->dev_sess) {
    229                         rc = process_transfer_remote(transfer->batch,
     232                        rc = process_transfer_remote(&transfer->batch,
    230233                            dev->dev_sess, &data_transfer_size);
    231234                } else if (dev->dev_local != NULL) {
    232                         rc = process_transfer_local(transfer->batch,
     235                        rc = process_transfer_local(&transfer->batch,
    233236                            dev->dev_local, &data_transfer_size);
    234237                } else {
     
    244247                        if (is_set_address_transfer(transfer)) {
    245248                                usb_device_request_setup_packet_t *setup =
    246                                     (void*) transfer->batch->setup.buffer;
     249                                    (void*) transfer->batch.setup.buffer;
    247250                                dev->address = setup->value;
    248251                                usb_log_debug2("Address changed to %d\n",
  • uspace/drv/bus/usb/vhc/vhcd.h

    r1ea0bbf r32fb6bce  
    3939#include <usbvirt/device.h>
    4040#include <async.h>
     41#include <macros.h>
    4142
    4243#include <usb/host/hcd.h>
    4344#include <usb/host/usb2_bus.h>
     45#include <usb/host/usb_transfer_batch.h>
    4446
    4547#define NAME "vhc"
     
    5658
    5759typedef struct {
    58         uint32_t magic;
     60        hc_device_t base;
     61
     62        usb2_bus_t bus;
     63        ddf_fun_t *virtual_fun;
    5964        list_t devices;
    6065        fibril_mutex_t guard;
    6166        usbvirt_device_t hub;
    62         usb2_bus_t bus;
    6367} vhc_data_t;
    6468
    6569typedef struct {
     70        usb_transfer_batch_t batch;
    6671        link_t link;
    67         usb_transfer_batch_t *batch;
    6872} vhc_transfer_t;
     73
     74static inline vhc_data_t *hcd_to_vhc(hc_device_t *hcd)
     75{
     76        assert(hcd);
     77        return (vhc_data_t *) hcd;
     78}
     79
     80static inline vhc_data_t *bus_to_vhc(bus_t *bus)
     81{
     82        assert(bus);
     83        return member_to_inst(bus, vhc_data_t, bus);
     84}
    6985
    7086void on_client_close(ddf_fun_t *fun);
     
    7793void vhc_virtdev_unplug(vhc_data_t *, uintptr_t);
    7894
    79 int vhc_init(vhc_data_t *instance, hcd_t *);
    80 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
     95int vhc_init(vhc_data_t *);
     96int vhc_schedule(usb_transfer_batch_t *);
    8197int vhc_transfer_queue_processor(void *arg);
    8298
Note: See TracChangeset for help on using the changeset viewer.