Ignore:
Timestamp:
2011-09-16T14:50:20Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
432a269, d1e18573
Parents:
47fecbb (diff), 82a31261 (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 USB changes from bzr://krabicka.net/orome/helenos/usb/

  • Move common HC code from uhci/ohci drivers to libusbhost
  • Rewrite USB HC interface to have common read/write functions for all transfer types.
  • Restructure hc drivers to avoid some hooks and void* casts
  • Cleanup the code and remove unnecessary mallocs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/transfer_list.c

    r47fecbb rfd07e526  
    3737#include <usb/debug.h>
    3838#include <libarch/barrier.h>
     39
    3940#include "transfer_list.h"
    40 #include "batch.h"
    4141
    4242static void transfer_list_remove_batch(
    43     transfer_list_t *instance, usb_transfer_batch_t *batch);
     43    transfer_list_t *instance, uhci_transfer_batch_t *uhci_batch);
    4444/*----------------------------------------------------------------------------*/
    4545/** Initialize transfer list structures.
     
    106106 */
    107107void transfer_list_add_batch(
    108     transfer_list_t *instance, usb_transfer_batch_t *batch)
    109 {
    110         assert(instance);
    111         assert(batch);
    112         usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
     108    transfer_list_t *instance, uhci_transfer_batch_t *uhci_batch)
     109{
     110        assert(instance);
     111        assert(uhci_batch);
     112        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name,
     113            uhci_batch->usb_batch);
    113114
    114115        fibril_mutex_lock(&instance->guard);
    115116
    116         qh_t *last_qh = NULL;
     117        /* Assume there is nothing scheduled */
     118        qh_t *last_qh = instance->queue_head;
     119        /* There is something scheduled */
     120        if (!list_empty(&instance->batch_list)) {
     121                last_qh = uhci_transfer_batch_from_link(
     122                    list_last(&instance->batch_list))->qh;
     123        }
    117124        /* Add to the hardware queue. */
    118         if (list_empty(&instance->batch_list)) {
    119                 /* There is nothing scheduled */
    120                 last_qh = instance->queue_head;
    121         } else {
    122                 /* There is something scheduled */
    123                 usb_transfer_batch_t *last = usb_transfer_batch_from_link(
    124                     list_last(&instance->batch_list));
    125                 last_qh = batch_qh(last);
    126         }
    127         const uint32_t pa = addr_to_phys(batch_qh(batch));
     125        const uint32_t pa = addr_to_phys(uhci_batch->qh);
    128126        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    129127
     
    132130
    133131        /* keep link */
    134         batch_qh(batch)->next = last_qh->next;
    135         qh_set_next_qh(last_qh, batch_qh(batch));
     132        uhci_batch->qh->next = last_qh->next;
     133        qh_set_next_qh(last_qh, uhci_batch->qh);
    136134
    137135        /* Make sure the pointer is updated */
     
    139137
    140138        /* Add to the driver's list */
    141         list_append(&batch->link, &instance->batch_list);
     139        list_append(&uhci_batch->link, &instance->batch_list);
    142140
    143141        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " scheduled in queue %s.\n",
    144             batch, USB_TRANSFER_BATCH_ARGS(*batch), instance->name);
     142            uhci_batch, USB_TRANSFER_BATCH_ARGS(*uhci_batch->usb_batch),
     143            instance->name);
    145144        fibril_mutex_unlock(&instance->guard);
    146145}
     
    157156
    158157        fibril_mutex_lock(&instance->guard);
    159         link_t *current = instance->batch_list.head.next;
    160         while (current != &instance->batch_list.head) {
     158        link_t *current = list_first(&instance->batch_list);
     159        while (current && current != &instance->batch_list.head) {
    161160                link_t * const next = current->next;
    162                 usb_transfer_batch_t *batch =
    163                     usb_transfer_batch_from_link(current);
    164 
    165                 if (batch_is_complete(batch)) {
     161                uhci_transfer_batch_t *batch =
     162                    uhci_transfer_batch_from_link(current);
     163
     164                if (uhci_transfer_batch_is_complete(batch)) {
    166165                        /* Save for processing */
    167166                        transfer_list_remove_batch(instance, batch);
     
    182181        while (!list_empty(&instance->batch_list)) {
    183182                link_t * const current = list_first(&instance->batch_list);
    184                 usb_transfer_batch_t *batch =
    185                     usb_transfer_batch_from_link(current);
     183                uhci_transfer_batch_t *batch =
     184                    uhci_transfer_batch_from_link(current);
    186185                transfer_list_remove_batch(instance, batch);
    187                 usb_transfer_batch_finish_error(batch, EINTR);
     186                batch->usb_batch->error = EINTR;
     187                uhci_transfer_batch_call_dispose(batch);
    188188        }
    189189        fibril_mutex_unlock(&instance->guard);
     
    198198 */
    199199void transfer_list_remove_batch(
    200     transfer_list_t *instance, usb_transfer_batch_t *batch)
     200    transfer_list_t *instance, uhci_transfer_batch_t *uhci_batch)
    201201{
    202202        assert(instance);
    203203        assert(instance->queue_head);
    204         assert(batch);
    205         assert(batch_qh(batch));
     204        assert(uhci_batch);
     205        assert(uhci_batch->qh);
    206206        assert(fibril_mutex_is_locked(&instance->guard));
    207207
    208         usb_log_debug2(
    209             "Queue %s: removing batch(%p).\n", instance->name, batch);
    210 
    211         const char *qpos = NULL;
    212         qh_t *prev_qh = NULL;
     208        usb_log_debug2("Queue %s: removing batch(%p).\n",
     209            instance->name, uhci_batch->usb_batch);
     210
     211        /* Assume I'm the first */
     212        const char *qpos = "FIRST";
     213        qh_t *prev_qh = instance->queue_head;
    213214        /* Remove from the hardware queue */
    214         if (list_first(&instance->batch_list) == &batch->link) {
    215                 /* I'm the first one here */
    216                 prev_qh = instance->queue_head;
    217                 qpos = "FIRST";
    218         } else {
    219                 /* The thing before me is a batch too */
    220                 usb_transfer_batch_t *prev =
    221                     usb_transfer_batch_from_link(batch->link.prev);
    222                 prev_qh = batch_qh(prev);
     215        if (list_first(&instance->batch_list) != &uhci_batch->link) {
     216                /* There is a batch in front of me */
     217                prev_qh =
     218                    uhci_transfer_batch_from_link(uhci_batch->link.prev)->qh;
    223219                qpos = "NOT FIRST";
    224220        }
    225221        assert((prev_qh->next & LINK_POINTER_ADDRESS_MASK)
    226             == addr_to_phys(batch_qh(batch)));
    227         prev_qh->next = batch_qh(batch)->next;
     222            == addr_to_phys(uhci_batch->qh));
     223        prev_qh->next = uhci_batch->qh->next;
    228224
    229225        /* Make sure the pointer is updated */
     
    231227
    232228        /* Remove from the batch list */
    233         list_remove(&batch->link);
     229        list_remove(&uhci_batch->link);
    234230        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " removed (%s) "
    235231            "from %s, next: %x.\n",
    236             batch, USB_TRANSFER_BATCH_ARGS(*batch),
    237             qpos, instance->name, batch_qh(batch)->next);
     232            uhci_batch, USB_TRANSFER_BATCH_ARGS(*uhci_batch->usb_batch),
     233            qpos, instance->name, uhci_batch->qh->next);
    238234}
    239235/**
Note: See TracChangeset for help on using the changeset viewer.