Changeset cd4ae1e in mainline for uspace/drv/vhc/main.c


Ignore:
Timestamp:
2011-04-28T13:14:14Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54d71e1, a146aa33
Parents:
74f00b6 (diff), c82135a8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Better virtual USB HID; USB-virt rewritten

The new virtual USB HID is easily extensible with new interfaces that
might provide different report descriptors.

The virtual host controller was completely rewritten together
with the libusbvirt.

The documentation is missing and the code would deserver some refactoring.
That will appear later.

File:
1 moved

Legend:

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

    r74f00b6 rcd4ae1e  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
    33  * @brief Virtual host controller driver.
     33 * Virtual host controller.
    3434 */
    3535
     
    4848#include <usb_iface.h>
    4949#include "vhcd.h"
    50 #include "hc.h"
    51 #include "devices.h"
    5250#include "hub.h"
    5351#include "conn.h"
     
    6563        int rc;
    6664
    67         /*
    68          * Currently, we know how to simulate only single HC.
    69          */
    7065        if (vhc_count > 0) {
    7166                return ELIMIT;
    7267        }
    7368
    74         /*
    75          * Create exposed function representing the host controller
    76          * itself.
    77          */
     69        vhc_data_t *data = malloc(sizeof(vhc_data_t));
     70        if (data == NULL) {
     71                usb_log_fatal("Failed to allocate memory.\n");
     72                return ENOMEM;
     73        }
     74        data->magic = 0xDEADBEEF;
     75        rc = usb_endpoint_manager_init(&data->ep_manager, (size_t) -1);
     76        if (rc != EOK) {
     77                usb_log_fatal("Failed to initialize endpoint manager.\n");
     78                free(data);
     79                return rc;
     80        }
     81        usb_device_keeper_init(&data->dev_keeper);
     82
    7883        ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");
    7984        if (hc == NULL) {
    8085                usb_log_fatal("Failed to create device function.\n");
     86                free(data);
    8187                return ENOMEM;
    8288        }
    8389
    8490        hc->ops = &vhc_ops;
     91        list_initialize(&data->devices);
     92        fibril_mutex_initialize(&data->guard);
     93        data->hub = &virtual_hub_device;
     94        data->hc_fun = hc;
     95
     96        dev->driver_data = data;
    8597
    8698        rc = ddf_fun_bind(hc);
     
    88100                usb_log_fatal("Failed to bind HC function: %s.\n",
    89101                    str_error(rc));
     102                free(data);
    90103                return rc;
    91104        }
     
    93106        ddf_fun_add_to_class(hc, "usbhc");
    94107
    95         /*
    96          * Initialize our hub and announce its presence.
    97          */
    98108        virtual_hub_device_init(hc);
    99109
    100110        usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",
    101111            (size_t) dev->handle, (size_t) hc->handle);
     112
     113
     114
     115        rc = vhc_virtdev_plug_hub(data, data->hub, NULL);
     116        if (rc != EOK) {
     117                usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc));
     118                free(data);
     119                return rc;
     120        }
    102121
    103122        return EOK;
     
    116135int main(int argc, char * argv[])
    117136{       
    118         /*
    119          * Temporary workaround. Wait a little bit to be the last driver
    120          * in devman output.
    121          */
    122         //sleep(5);
    123 
    124137        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    125138
    126139        printf(NAME ": virtual USB host controller driver.\n");
    127140
    128         /*
    129          * Initialize address management.
    130          */
    131         address_init();
    132 
    133         /*
    134          * Run the transfer scheduler.
    135          */
    136         hc_manager();
    137 
    138         /*
    139          * We are also a driver within devman framework.
    140          */
    141141        return ddf_driver_main(&vhc_driver);
    142142}
Note: See TracChangeset for help on using the changeset viewer.