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

Changeset 85c47729 in mainline


Ignore:
Timestamp:
2011-04-08T13:25:58Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial
Children:
61727bf
Parents:
8b74997f (diff), 4b39af4 (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:

Per endpoint communication mutex

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/root_hub.c

    r8b74997f r85c47729  
    249249                opResult = EINVAL;
    250250        }
    251         usb_transfer_batch_finish(request, opResult);
     251        usb_transfer_batch_finish_error(request, opResult);
    252252        return EOK;
    253253}
     
    863863}
    864864
    865 
    866 
    867 
    868865/**
    869866 * @}
  • uspace/drv/uhci-hcd/hc.c

    r8b74997f r85c47729  
    332332            instance->transfers[batch->speed][batch->transfer_type];
    333333        assert(list);
    334         if (batch->transfer_type == USB_TRANSFER_CONTROL) {
    335                 usb_device_keeper_use_control(
    336                     &instance->manager, batch->target);
    337         }
    338334        transfer_list_add_batch(list, batch);
    339335
     
    373369                        usb_transfer_batch_t *batch =
    374370                            list_get_instance(item, usb_transfer_batch_t, link);
    375                         switch (batch->transfer_type)
    376                         {
    377                         case USB_TRANSFER_CONTROL:
    378                                 usb_device_keeper_release_control(
    379                                     &instance->manager, batch->target);
    380                                 break;
    381                         case USB_TRANSFER_INTERRUPT:
    382                         case USB_TRANSFER_ISOCHRONOUS: {
    383 /*
    384                                 int ret = bandwidth_free(&instance->bandwidth,
    385                                     batch->target.address,
    386                                     batch->target.endpoint,
    387                                     batch->direction);
    388                                 if (ret != EOK)
    389                                         usb_log_warning("Failed(%d) to free "
    390                                             "reserved bw: %s.\n", ret,
    391                                             str_error(ret));
    392 */
    393                                 }
    394                         default:
    395                                 break;
    396                         }
    397                         batch->next_step(batch);
     371                        usb_transfer_batch_finish(batch);
    398372                }
    399373        }
  • uspace/drv/uhci-hcd/transfer_list.c

    r8b74997f r85c47729  
    132132}
    133133/*----------------------------------------------------------------------------*/
    134 /** Check list for finished batches.
    135  *
    136  * @param[in] instance List to use.
    137  * @return Error code
    138  *
    139  * Creates a local list of finished batches and calls next_step on each and
    140  * every one. This is safer because next_step may theoretically access
    141  * this transfer list leading to the deadlock if its done inline.
     134/** Create list for finished batches.
     135 *
     136 * @param[in] instance List to use.
     137 * @param[in] done list to fill
    142138 */
    143139void transfer_list_remove_finished(transfer_list_t *instance, link_t *done)
     
    161157        }
    162158        fibril_mutex_unlock(&instance->guard);
    163 
    164159}
    165160/*----------------------------------------------------------------------------*/
     
    176171                    list_get_instance(current, usb_transfer_batch_t, link);
    177172                transfer_list_remove_batch(instance, batch);
    178                 usb_transfer_batch_finish(batch, EIO);
     173                usb_transfer_batch_finish_error(batch, EIO);
    179174        }
    180175        fibril_mutex_unlock(&instance->guard);
  • uspace/lib/usb/include/usb/host/batch.h

    r8b74997f r85c47729  
    9292void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
    9393void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
    94 void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error);
     94void usb_transfer_batch_finish(usb_transfer_batch_t *instance);
     95
     96static inline void usb_transfer_batch_finish_error(
     97    usb_transfer_batch_t *instance, int error)
     98{
     99        assert(instance);
     100        instance->error = error;
     101        usb_transfer_batch_finish(instance);
     102}
    95103
    96104#endif
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r8b74997f r85c47729  
    9696usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
    9797    usb_address_t address);
    98 
    99 void usb_device_keeper_use_control(usb_device_keeper_t *instance,
    100     usb_target_t target);
    101 
    102 void usb_device_keeper_release_control(usb_device_keeper_t *instance,
    103     usb_target_t target);
    104 
    10598#endif
    10699/**
  • uspace/lib/usb/include/usb/host/endpoint.h

    r8b74997f r85c47729  
    3939#include <bool.h>
    4040#include <adt/list.h>
     41#include <fibril_synch.h>
     42
    4143#include <usb/usb.h>
    4244
     
    4850        usb_speed_t speed;
    4951        size_t max_packet_size;
    50         bool active;
    5152        unsigned toggle:1;
     53        fibril_mutex_t guard;
     54        fibril_condvar_t avail;
     55        volatile bool active;
    5256        link_t same_device_eps;
    5357} endpoint_t;
     
    5862
    5963void endpoint_destroy(endpoint_t *instance);
     64
     65void endpoint_use(endpoint_t *instance);
     66
     67void endpoint_release(endpoint_t *instance);
    6068
    6169int endpoint_toggle_get(endpoint_t *instance);
  • uspace/lib/usb/src/host/batch.c

    r8b74997f r85c47729  
    7979        instance->error = EOK;
    8080        instance->ep = ep;
     81        endpoint_use(instance->ep);
    8182}
    8283/*----------------------------------------------------------------------------*/
     
    8687 *
    8788 */
    88 void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error)
     89void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
    8990{
    9091        assert(instance);
    91         instance->error = error;
     92        assert(instance->ep);
     93        endpoint_release(instance->ep);
    9294        instance->next_step(instance);
    9395}
  • uspace/lib/usb/src/host/device_keeper.c

    r8b74997f r85c47729  
    264264        return instance->devices[address].speed;
    265265}
    266 /*----------------------------------------------------------------------------*/
    267 void usb_device_keeper_use_control(
    268     usb_device_keeper_t *instance, usb_target_t target)
    269 {
    270         assert(instance);
    271         const uint16_t ep = 1 << target.endpoint;
    272         fibril_mutex_lock(&instance->guard);
    273         while (instance->devices[target.address].control_used & ep) {
    274                 fibril_condvar_wait(&instance->change, &instance->guard);
    275         }
    276         instance->devices[target.address].control_used |= ep;
    277         fibril_mutex_unlock(&instance->guard);
    278 }
    279 /*----------------------------------------------------------------------------*/
    280 void usb_device_keeper_release_control(
    281     usb_device_keeper_t *instance, usb_target_t target)
    282 {
    283         assert(instance);
    284         const uint16_t ep = 1 << target.endpoint;
    285         fibril_mutex_lock(&instance->guard);
    286         assert((instance->devices[target.address].control_used & ep) != 0);
    287         instance->devices[target.address].control_used &= ~ep;
    288         fibril_mutex_unlock(&instance->guard);
    289         fibril_condvar_signal(&instance->change);
    290 }
    291266/**
    292267 * @}
  • uspace/lib/usb/src/host/endpoint.c

    r8b74997f r85c47729  
    3434 */
    3535
     36#include <assert.h>
    3637#include <errno.h>
    3738#include <usb/host/endpoint.h>
     
    4950        instance->max_packet_size = max_packet_size;
    5051        instance->toggle = 0;
     52        instance->active = false;
     53        fibril_mutex_initialize(&instance->guard);
     54        fibril_condvar_initialize(&instance->avail);
    5155        link_initialize(&instance->same_device_eps);
    5256        return EOK;
     
    5660{
    5761        assert(instance);
     62        assert(!instance->active);
    5863        list_remove(&instance->same_device_eps);
    5964        free(instance);
     65}
     66/*----------------------------------------------------------------------------*/
     67void endpoint_use(endpoint_t *instance)
     68{
     69        assert(instance);
     70        fibril_mutex_lock(&instance->guard);
     71        while (instance->active)
     72                fibril_condvar_wait(&instance->avail, &instance->guard);
     73        instance->active = true;
     74        fibril_mutex_unlock(&instance->guard);
     75}
     76/*----------------------------------------------------------------------------*/
     77void endpoint_release(endpoint_t *instance)
     78{
     79        assert(instance);
     80        fibril_mutex_lock(&instance->guard);
     81        instance->active = false;
     82        fibril_mutex_unlock(&instance->guard);
     83        fibril_condvar_signal(&instance->avail);
    6084}
    6185/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.