Changeset e1dbcbc in mainline for uspace/drv/ohci/endpoint_list.c


Ignore:
Timestamp:
2011-04-29T13:43:01Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a81a1d09
Parents:
380e0364 (diff), f19f1b7 (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 development/ changes

File:
1 moved

Legend:

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

    r380e0364 re1dbcbc  
    3535#include <usb/debug.h>
    3636
    37 #include "transfer_list.h"
    38 
    39 static void transfer_list_remove_batch(
    40     transfer_list_t *instance, usb_transfer_batch_t *batch);
    41 /*----------------------------------------------------------------------------*/
     37#include "endpoint_list.h"
     38
    4239/** Initialize transfer list structures.
    4340 *
     
    4845 * Allocates memory for internal qh_t structure.
    4946 */
    50 int transfer_list_init(transfer_list_t *instance, const char *name)
     47int endpoint_list_init(endpoint_list_t *instance, const char *name)
    5148{
    5249        assert(instance);
     
    5855        }
    5956        instance->list_head_pa = addr_to_phys(instance->list_head);
    60         usb_log_debug2("Transfer list %s setup with ED: %p(%p).\n",
     57        usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n",
    6158            name, instance->list_head, instance->list_head_pa);
    6259
    6360        ed_init(instance->list_head, NULL);
    64         list_initialize(&instance->batch_list);
     61        list_initialize(&instance->endpoint_list);
    6562        fibril_mutex_initialize(&instance->guard);
    6663        return EOK;
     
    7572 * Does not check whether this replaces an existing list .
    7673 */
    77 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
     74void endpoint_list_set_next(endpoint_list_t *instance, endpoint_list_t *next)
    7875{
    7976        assert(instance);
    8077        assert(next);
    81         /* Set both queue_head.next to point to the follower */
    8278        ed_append_ed(instance->list_head, next->list_head);
    8379}
    8480/*----------------------------------------------------------------------------*/
    85 /** Submit transfer batch to the list and queue.
    86  *
    87  * @param[in] instance List to use.
    88  * @param[in] batch Transfer batch to submit.
    89  * @return Error code
    90  *
    91  * The batch is added to the end of the list and queue.
    92  */
    93 void transfer_list_add_batch(
    94     transfer_list_t *instance, usb_transfer_batch_t *batch)
    95 {
    96         assert(instance);
    97         assert(batch);
    98         usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
     81/** Submit transfer endpoint to the list and queue.
     82 *
     83 * @param[in] instance List to use.
     84 * @param[in] endpoint Transfer endpoint to submit.
     85 * @return Error code
     86 *
     87 * The endpoint is added to the end of the list and queue.
     88 */
     89void endpoint_list_add_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep)
     90{
     91        assert(instance);
     92        assert(hcd_ep);
     93        usb_log_debug2("Queue %s: Adding endpoint(%p).\n",
     94            instance->name, hcd_ep);
    9995
    10096        fibril_mutex_lock(&instance->guard);
     
    10298        ed_t *last_ed = NULL;
    10399        /* Add to the hardware queue. */
    104         if (list_empty(&instance->batch_list)) {
     100        if (list_empty(&instance->endpoint_list)) {
    105101                /* There is nothing scheduled */
    106102                last_ed = instance->list_head;
    107103        } else {
    108104                /* There is something scheduled */
    109                 usb_transfer_batch_t *last = list_get_instance(
    110                     instance->batch_list.prev, usb_transfer_batch_t, link);
    111                 last_ed = batch_ed(last);
     105                hcd_endpoint_t *last = list_get_instance(
     106                    instance->endpoint_list.prev, hcd_endpoint_t, link);
     107                last_ed = last->ed;
    112108        }
    113109        /* keep link */
    114         batch_ed(batch)->next = last_ed->next;
    115         ed_append_ed(last_ed, batch_ed(batch));
     110        hcd_ep->ed->next = last_ed->next;
     111        ed_append_ed(last_ed, hcd_ep->ed);
    116112
    117113        asm volatile ("": : :"memory");
    118114
    119115        /* Add to the driver list */
    120         list_append(&batch->link, &instance->batch_list);
    121 
    122         usb_transfer_batch_t *first = list_get_instance(
    123             instance->batch_list.next, usb_transfer_batch_t, link);
    124         usb_log_debug("Batch(%p) added to list %s, first is %p(%p).\n",
    125                 batch, instance->name, first, batch_ed(first));
     116        list_append(&hcd_ep->link, &instance->endpoint_list);
     117
     118        hcd_endpoint_t *first = list_get_instance(
     119            instance->endpoint_list.next, hcd_endpoint_t, link);
     120        usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
     121                hcd_ep, instance->name, first, first->ed);
    126122        if (last_ed == instance->list_head) {
    127                 usb_log_debug2("%s head ED: %x:%x:%x:%x.\n", instance->name,
    128                         last_ed->status, last_ed->td_tail, last_ed->td_head,
    129                         last_ed->next);
    130         }
    131         fibril_mutex_unlock(&instance->guard);
    132 }
    133 /*----------------------------------------------------------------------------*/
    134 /** Create list for finished batches.
     123                usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x:%x:%x.\n",
     124                    instance->name, last_ed, instance->list_head_pa,
     125                    last_ed->status, last_ed->td_tail, last_ed->td_head,
     126                    last_ed->next);
     127        }
     128        fibril_mutex_unlock(&instance->guard);
     129}
     130/*----------------------------------------------------------------------------*/
     131#if 0
     132/** Create list for finished endpoints.
    135133 *
    136134 * @param[in] instance List to use.
    137135 * @param[in] done list to fill
    138136 */
    139 void transfer_list_remove_finished(transfer_list_t *instance, link_t *done)
     137void endpoint_list_remove_finished(endpoint_list_t *instance, link_t *done)
    140138{
    141139        assert(instance);
     
    143141
    144142        fibril_mutex_lock(&instance->guard);
    145         link_t *current = instance->batch_list.next;
    146         while (current != &instance->batch_list) {
     143        usb_log_debug2("Checking list %s for completed endpointes(%d).\n",
     144            instance->name, list_count(&instance->endpoint_list));
     145        link_t *current = instance->endpoint_list.next;
     146        while (current != &instance->endpoint_list) {
    147147                link_t *next = current->next;
    148                 usb_transfer_batch_t *batch =
    149                     list_get_instance(current, usb_transfer_batch_t, link);
    150 
    151                 if (batch_is_complete(batch)) {
     148                hcd_endpoint_t *endpoint =
     149                    list_get_instance(current, hcd_endpoint_t, link);
     150
     151                if (endpoint_is_complete(endpoint)) {
    152152                        /* Save for post-processing */
    153                         transfer_list_remove_batch(instance, batch);
     153                        endpoint_list_remove_endpoint(instance, endpoint);
    154154                        list_append(current, done);
    155155                }
     
    159159}
    160160/*----------------------------------------------------------------------------*/
    161 /** Walk the list and abort all batches.
    162  *
    163  * @param[in] instance List to use.
    164  */
    165 void transfer_list_abort_all(transfer_list_t *instance)
    166 {
    167         fibril_mutex_lock(&instance->guard);
    168         while (!list_empty(&instance->batch_list)) {
    169                 link_t *current = instance->batch_list.next;
    170                 usb_transfer_batch_t *batch =
    171                     list_get_instance(current, usb_transfer_batch_t, link);
    172                 transfer_list_remove_batch(instance, batch);
    173                 usb_transfer_batch_finish_error(batch, EIO);
    174         }
    175         fibril_mutex_unlock(&instance->guard);
    176 }
    177 /*----------------------------------------------------------------------------*/
    178 /** Remove a transfer batch from the list and queue.
    179  *
    180  * @param[in] instance List to use.
    181  * @param[in] batch Transfer batch to remove.
     161/** Walk the list and abort all endpointes.
     162 *
     163 * @param[in] instance List to use.
     164 */
     165void endpoint_list_abort_all(endpoint_list_t *instance)
     166{
     167        fibril_mutex_lock(&instance->guard);
     168        while (!list_empty(&instance->endpoint_list)) {
     169                link_t *current = instance->endpoint_list.next;
     170                hcd_endpoint_t *endpoint =
     171                    list_get_instance(current, hcd_endpoint_t, link);
     172                endpoint_list_remove_endpoint(instance, endpoint);
     173                hcd_endpoint_finish_error(endpoint, EIO);
     174        }
     175        fibril_mutex_unlock(&instance->guard);
     176}
     177#endif
     178/*----------------------------------------------------------------------------*/
     179/** Remove a transfer endpoint from the list and queue.
     180 *
     181 * @param[in] instance List to use.
     182 * @param[in] endpoint Transfer endpoint to remove.
    182183 * @return Error code
    183184 *
    184185 * Does not lock the transfer list, caller is responsible for that.
    185186 */
    186 void transfer_list_remove_batch(
    187     transfer_list_t *instance, usb_transfer_batch_t *batch)
     187void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep)
    188188{
    189189        assert(instance);
    190190        assert(instance->list_head);
    191         assert(batch);
    192         assert(batch_ed(batch));
    193         assert(fibril_mutex_is_locked(&instance->guard));
     191        assert(hcd_ep);
     192        assert(hcd_ep->ed);
     193
     194        fibril_mutex_lock(&instance->guard);
    194195
    195196        usb_log_debug2(
    196             "Queue %s: removing batch(%p).\n", instance->name, batch);
     197            "Queue %s: removing endpoint(%p).\n", instance->name, hcd_ep);
    197198
    198199        const char *qpos = NULL;
     200        ed_t *prev_ed;
    199201        /* Remove from the hardware queue */
    200         if (instance->batch_list.next == &batch->link) {
     202        if (instance->endpoint_list.next == &hcd_ep->link) {
    201203                /* I'm the first one here */
    202                 assert((instance->list_head->next & ED_NEXT_PTR_MASK)
    203                     == addr_to_phys(batch_ed(batch)));
    204                 instance->list_head->next = batch_ed(batch)->next;
     204                prev_ed = instance->list_head;
    205205                qpos = "FIRST";
    206206        } else {
    207                 usb_transfer_batch_t *prev =
    208                     list_get_instance(
    209                         batch->link.prev, usb_transfer_batch_t, link);
    210                 assert((batch_ed(prev)->next & ED_NEXT_PTR_MASK)
    211                     == addr_to_phys(batch_ed(batch)));
    212                 batch_ed(prev)->next = batch_ed(batch)->next;
     207                hcd_endpoint_t *prev =
     208                    list_get_instance(hcd_ep->link.prev, hcd_endpoint_t, link);
     209                prev_ed = prev->ed;
    213210                qpos = "NOT FIRST";
    214211        }
     212        assert((prev_ed->next & ED_NEXT_PTR_MASK) == addr_to_phys(hcd_ep->ed));
     213        prev_ed->next = hcd_ep->ed->next;
     214
    215215        asm volatile ("": : :"memory");
    216         usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
    217             batch, qpos, instance->name, batch_ed(batch)->next);
    218 
    219         /* Remove from the batch list */
    220         list_remove(&batch->link);
     216        usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n",
     217            hcd_ep, qpos, instance->name, hcd_ep->ed->next);
     218
     219        /* Remove from the endpoint list */
     220        list_remove(&hcd_ep->link);
     221        fibril_mutex_unlock(&instance->guard);
    221222}
    222223/**
Note: See TracChangeset for help on using the changeset viewer.