Changeset d083126 in mainline for uspace/lib/usbdev/src/devdrv.c


Ignore:
Timestamp:
2011-10-13T13:20:26Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3a5506a
Parents:
cff3fb6 (diff), 22a2b763 (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:

Merge initial USB unplug support.

Support device_remove and device_gone in libusbdev.
usbhub and uhcirh try to unbind and destroy functions of attached devices.
add unplug support for usbhub driver (only works on empty hubs as there is no support in other drivers).

Drivers to go:

usbmid
usbflbk
usbhid
usbmast
usbmouse

Tested on:

qemu UHCI and emulated hub,
ICH8 hw and Alcor Micro Corp. USB Hub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/devdrv.c

    rcff3fb6 rd083126  
    4141#include <assert.h>
    4242
    43 static int generic_add_device(ddf_dev_t *);
     43static int generic_device_add(ddf_dev_t *);
     44static int generic_device_remove(ddf_dev_t *);
     45static int generic_device_gone(ddf_dev_t *);
    4446
    4547static driver_ops_t generic_driver_ops = {
    46         .add_device = generic_add_device
     48        .add_device = generic_device_add,
     49        .dev_remove = generic_device_remove,
     50        .dev_gone = generic_device_gone,
    4751};
    4852static driver_t generic_driver = {
     
    123127        return EOK;
    124128}
    125 
    126 /** Callback when new device is supposed to be controlled by this driver.
    127  *
    128  * This callback is a wrapper for USB specific version of @c add_device.
     129/*----------------------------------------------------------------------------*/
     130/** Callback when a new device is supposed to be controlled by this driver.
     131 *
     132 * This callback is a wrapper for USB specific version of @c device_add.
    129133 *
    130134 * @param gen_dev Device structure as prepared by DDF.
    131135 * @return Error code.
    132136 */
    133 int generic_add_device(ddf_dev_t *gen_dev)
     137int generic_device_add(ddf_dev_t *gen_dev)
    134138{
    135139        assert(driver);
    136140        assert(driver->ops);
    137         assert(driver->ops->add_device);
     141        assert(driver->ops->device_add);
    138142
    139143        int rc;
     
    147151                return rc;
    148152        }
    149 
    150         return driver->ops->add_device(dev);
    151 }
    152 
     153        gen_dev->driver_data = dev;
     154
     155        return driver->ops->device_add(dev);
     156}
     157/*----------------------------------------------------------------------------*/
     158/** Callback when a device is supposed to be removed from the system.
     159 *
     160 * This callback is a wrapper for USB specific version of @c device_remove.
     161 *
     162 * @param gen_dev Device structure as prepared by DDF.
     163 * @return Error code.
     164 */
     165int generic_device_remove(ddf_dev_t *gen_dev)
     166{
     167        assert(driver);
     168        assert(driver->ops);
     169        if (driver->ops->device_rem == NULL)
     170                return ENOTSUP;
     171        /* Just tell the driver to stop whatever it is doing, keep structures */
     172        return driver->ops->device_rem(gen_dev->driver_data);
     173}
     174/*----------------------------------------------------------------------------*/
     175/** Callback when a device was removed from the system.
     176 *
     177 * This callback is a wrapper for USB specific version of @c device_gone.
     178 *
     179 * @param gen_dev Device structure as prepared by DDF.
     180 * @return Error code.
     181 */
     182int generic_device_gone(ddf_dev_t *gen_dev)
     183{
     184        assert(driver);
     185        assert(driver->ops);
     186        if (driver->ops->device_gone == NULL)
     187                return ENOTSUP;
     188        const int ret = driver->ops->device_gone(gen_dev->driver_data);
     189        if (ret == EOK)
     190                usb_device_destroy(gen_dev->driver_data);
     191
     192        return ret;
     193}
     194/*----------------------------------------------------------------------------*/
    153195/** Destroy existing pipes of a USB device.
    154196 *
     
    275317 * @return Error code.
    276318 */
    277 int usb_device_create_pipes(ddf_dev_t *dev, usb_device_connection_t *wire,
     319int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire,
    278320    usb_endpoint_description_t **endpoints,
    279321    uint8_t *config_descr, size_t config_descr_size,
     
    349391        }
    350392
    351         usb_hc_connection_close(&hc_conn);
     393        if (usb_hc_connection_close(&hc_conn) != EOK)
     394                usb_log_warning("usb_device_create_pipes(): "
     395                    "Failed to close connection.\n");
    352396
    353397        *pipes_ptr = pipes;
     
    371415        }
    372416
    373         usb_hc_connection_close(&hc_conn);
     417        if (usb_hc_connection_close(&hc_conn) != EOK)
     418                usb_log_warning("usb_device_create_pipes(): "
     419                    "Failed to close connection.\n");
    374420
    375421        /*
     
    395441 * @param[in] pipes_count Number of endpoints.
    396442 */
    397 int usb_device_destroy_pipes(ddf_dev_t *dev,
     443int usb_device_destroy_pipes(const ddf_dev_t *dev,
    398444    usb_endpoint_mapping_t *pipes, size_t pipes_count)
    399445{
     
    426472        }
    427473
    428         usb_hc_connection_close(&hc_conn);
     474        if (usb_hc_connection_close(&hc_conn) != EOK)
     475                usb_log_warning("usb_device_destroy_pipes(): "
     476                    "Failed to close connection.\n");
    429477
    430478        free(pipes);
     
    545593        /* Ignore errors and hope for the best. */
    546594        usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count);
    547         if (dev->descriptors.configuration != NULL) {
    548                 free(dev->descriptors.configuration);
    549         }
     595        free(dev->descriptors.configuration);
    550596
    551597        if (dev->alternate_interfaces != NULL) {
    552                 if (dev->alternate_interfaces->alternatives != NULL) {
    553                         free(dev->alternate_interfaces->alternatives);
    554                 }
    555                 free(dev->alternate_interfaces);
    556         }
     598                free(dev->alternate_interfaces->alternatives);
     599        }
     600        free(dev->alternate_interfaces);
    557601
    558602        free(dev);
Note: See TracChangeset for help on using the changeset viewer.