Changeset 91173333 in mainline for uspace/drv/bus


Ignore:
Timestamp:
2018-01-13T21:36:13Z (8 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
edc51615
Parents:
8a0c52a
Message:

usbdev: use centralized joining mechanism, move away from device_removed() callback

Location:
uspace/drv/bus/usb
Files:
6 edited

Legend:

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

    r8a0c52a r91173333  
    7777}
    7878
     79static int device_cleanup(usbdiag_dev_t *diag_dev)
     80{
     81        /* TODO: Join some fibrils? */
     82
     83        /* Free memory. */
     84        usbdiag_dev_destroy(diag_dev);
     85        return EOK;
     86}
     87
    7988static int device_remove(usb_device_t *dev)
    8089{
     
    91100        }
    92101
    93         return EOK;
     102        usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
     103        return device_cleanup(diag_dev);
    94104
    95105err:
    96106        return rc;
    97 }
    98 
    99 static int device_cleanup(usbdiag_dev_t *diag_dev)
    100 {
    101         /* TODO: Join some fibrils? */
    102 
    103         /* Free memory. */
    104         usbdiag_dev_destroy(diag_dev);
    105         return EOK;
    106 }
    107 
    108 static int device_removed(usb_device_t *dev)
    109 {
    110         usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
    111 
    112         usbdiag_dev_t *diag_dev = usb_device_to_usbdiag_dev(dev);
    113         return device_cleanup(diag_dev);
    114107}
    115108
     
    207200        .device_add = device_add,
    208201        .device_remove = device_remove,
    209         .device_removed = device_removed,
    210202        .device_gone = device_gone,
    211203        .function_online = function_online,
  • uspace/drv/bus/usb/usbflbk/main.c

    r8a0c52a r91173333  
    6969{
    7070        assert(dev);
    71         usb_log_info("Device '%s' will be removed.", usb_device_get_name(dev));
    72         return EOK;
    73 }
    74 
    75 static int usbfallback_device_removed(usb_device_t *dev)
    76 {
    77         assert(dev);
    7871        usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
    7972        return EOK;
     
    8477        .device_add = usbfallback_device_add,
    8578        .device_remove = usbfallback_device_remove,
    86         .device_removed = usbfallback_device_removed,
    8779        .device_gone = usbfallback_device_gone,
    8880};
  • uspace/drv/bus/usb/usbhub/main.c

    r8a0c52a r91173333  
    4949        .device_add = usb_hub_device_add,
    5050        .device_remove = usb_hub_device_remove,
    51         .device_removed = usb_hub_device_removed,
    5251        .device_gone = usb_hub_device_gone,
    5352};
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r8a0c52a r91173333  
    9999
    100100        /* Continue polling until the device is about to be removed. */
    101         return hub->running && !hub->poll_stop;
     101        return hub->running;
    102102}
    103103
     
    123123        hub_dev->pending_ops_count = 0;
    124124        hub_dev->running = false;
    125         hub_dev->poll_stop = false;
    126125        fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
    127         fibril_mutex_initialize(&hub_dev->poll_guard);
    128126        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    129         fibril_condvar_initialize(&hub_dev->poll_cv);
    130127
    131128        /* Set hub's first configuration. (There should be only one) */
     
    197194}
    198195
    199 /**
    200  * Turn off power to all ports.
    201  *
    202  * @param usb_dev generic usb device information
    203  * @return error code
    204  */
    205 int usb_hub_device_remove(usb_device_t *usb_dev)
    206 {
    207         assert(usb_dev);
    208         usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
    209         assert(hub);
    210 
    211         usb_log_info("(%p) USB hub will be removed.", hub);
    212 
    213         /* Instruct the hub to stop once endpoints are unregistered. */
    214         hub->poll_stop = true;
    215         return EOK;
    216 }
    217 
    218196static int usb_hub_cleanup(usb_hub_dev_t *hub)
    219197{
     
    241219}
    242220
    243 int usb_hub_device_removed(usb_device_t *usb_dev)
     221/**
     222 * Turn off power to all ports.
     223 *
     224 * @param usb_dev generic usb device information
     225 * @return error code
     226 */
     227int usb_hub_device_remove(usb_device_t *usb_dev)
    244228{
    245229        assert(usb_dev);
     
    247231        assert(hub);
    248232
    249         usb_log_info("(%p) USB hub was removed, joining polling fibril.", hub);
     233        usb_log_info("(%p) USB hub removed, joining polling fibril.", hub);
    250234
    251235        /* Join polling fibril. */
    252         fibril_mutex_lock(&hub->poll_guard);
    253         while (hub->running)
    254                 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard);
    255         fibril_mutex_unlock(&hub->poll_guard);
    256 
     236        usb_device_poll_join(hub->polling);
    257237        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    258238
     
    272252        assert(hub);
    273253
    274         hub->poll_stop = true;
    275254        usb_log_info("(%p) USB hub gone, joining polling fibril.", hub);
    276255
    277256        /* Join polling fibril. */
    278         fibril_mutex_lock(&hub->poll_guard);
    279         while (hub->running)
    280                 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard);
    281         fibril_mutex_unlock(&hub->poll_guard);
     257        usb_device_poll_join(hub->polling);
     258        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    282259
    283260        /* Destroy hub. */
     
    592569        fibril_mutex_unlock(&hub->pending_ops_mutex);
    593570        hub->running = false;
    594 
    595         /* Signal polling end to joining thread. */
    596         fibril_mutex_lock(&hub->poll_guard);
    597         fibril_condvar_signal(&hub->poll_cv);
    598         fibril_mutex_unlock(&hub->poll_guard);
    599 }
     571}
     572
    600573/**
    601574 * @}
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r8a0c52a r91173333  
    3939
    4040#include <ddf/driver.h>
     41#include <fibril_synch.h>
    4142
    4243#include <usb/classes/hub.h>
     
    4546#include <usb/dev/driver.h>
    4647#include <usb/dev/poll.h>
    47 
    48 #include <fibril_synch.h>
    4948
    5049#define NAME "usbhub"
     
    8180        /** Each port is switched individually. */
    8281        bool per_port_power;
    83         /** True if the device should stop running as soon as possible. */
    84         volatile bool poll_stop;
    85         fibril_mutex_t poll_guard;
    86         fibril_condvar_t poll_cv;
    8782};
    8883
     
    9186extern int usb_hub_device_add(usb_device_t *);
    9287extern int usb_hub_device_remove(usb_device_t *);
    93 extern int usb_hub_device_removed(usb_device_t *);
    9488extern int usb_hub_device_gone(usb_device_t *);
    9589
  • uspace/drv/bus/usb/usbmid/main.c

    r8a0c52a r91173333  
    5656}
    5757
     58static int destroy_interfaces(usb_mid_t *usb_mid)
     59{
     60        int ret = EOK;
     61
     62        while (!list_empty(&usb_mid->interface_list)) {
     63                link_t *item = list_first(&usb_mid->interface_list);
     64                list_remove(item);
     65
     66                usbmid_interface_t *iface = usbmid_interface_from_link(item);
     67
     68                const int pret = usbmid_interface_destroy(iface);
     69                if (pret != EOK) {
     70                        usb_log_error("Failed to remove child `%s': %s\n",
     71                            ddf_fun_get_name(iface->fun), str_error(pret));
     72                        ret = pret;
     73                }
     74        }
     75
     76        return ret;
     77}
     78
    5879/** Callback when a MID device is about to be removed from the host.
    5980 *
     
    90111        }
    91112
    92         return ret;
    93 }
    94 
    95 static int destroy_interfaces(usb_mid_t *usb_mid)
    96 {
    97         int ret = EOK;
    98 
    99         while (!list_empty(&usb_mid->interface_list)) {
    100                 link_t *item = list_first(&usb_mid->interface_list);
    101                 list_remove(item);
    102 
    103                 usbmid_interface_t *iface = usbmid_interface_from_link(item);
    104 
    105                 const int pret = usbmid_interface_destroy(iface);
    106                 if (pret != EOK) {
    107                         usb_log_error("Failed to remove child `%s': %s\n",
    108                             ddf_fun_get_name(iface->fun), str_error(pret));
    109                         ret = pret;
    110                 }
    111         }
    112 
    113         return ret;
    114 }
    115 
    116 static int usbmid_device_removed(usb_device_t *dev)
    117 {
    118         assert(dev);
    119         usb_mid_t *usb_mid = usb_device_data_get(dev);
    120         assert(usb_mid);
    121 
    122         /* Children are offline. Destroy them now. */
    123113        return destroy_interfaces(usb_mid);
    124114}
     
    166156        .device_add = usbmid_device_add,
    167157        .device_remove = usbmid_device_remove,
    168         .device_removed = usbmid_device_removed,
    169158        .device_gone = usbmid_device_gone,
    170159        .function_online = usbmid_function_online,
Note: See TracChangeset for help on using the changeset viewer.