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


Ignore:
Timestamp:
2011-04-14T07:54:33Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e05d6c3
Parents:
3f3afb9 (diff), 34e8bab (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 from development

File:
1 moved

Legend:

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

    r3f3afb9 ra39cfb8  
    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);
     
    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);
     
    8279}
    8380/*----------------------------------------------------------------------------*/
    84 /** Submit transfer batch to the list and queue.
    85  *
    86  * @param[in] instance List to use.
    87  * @param[in] batch Transfer batch to submit.
    88  * @return Error code
    89  *
    90  * The batch is added to the end of the list and queue.
    91  */
    92 void transfer_list_add_batch(
    93     transfer_list_t *instance, usb_transfer_batch_t *batch)
    94 {
    95         assert(instance);
    96         assert(batch);
    97         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);
    9895
    9996        fibril_mutex_lock(&instance->guard);
     
    10198        ed_t *last_ed = NULL;
    10299        /* Add to the hardware queue. */
    103         if (list_empty(&instance->batch_list)) {
     100        if (list_empty(&instance->endpoint_list)) {
    104101                /* There is nothing scheduled */
    105102                last_ed = instance->list_head;
    106103        } else {
    107104                /* There is something scheduled */
    108                 usb_transfer_batch_t *last = list_get_instance(
    109                     instance->batch_list.prev, usb_transfer_batch_t, link);
    110                 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;
    111108        }
    112109        /* keep link */
    113         batch_ed(batch)->next = last_ed->next;
    114         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);
    115112
    116113        asm volatile ("": : :"memory");
    117114
    118115        /* Add to the driver list */
    119         list_append(&batch->link, &instance->batch_list);
    120 
    121         usb_transfer_batch_t *first = list_get_instance(
    122             instance->batch_list.next, usb_transfer_batch_t, link);
    123         usb_log_debug("Batch(%p) added to list %s, first is %p(%p).\n",
    124                 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);
    125122        if (last_ed == instance->list_head) {
    126123                usb_log_debug2("%s head ED(%p-%p): %x:%x:%x:%x.\n",
     
    132129}
    133130/*----------------------------------------------------------------------------*/
    134 /** Create list for finished batches.
     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         usb_log_debug2("Checking list %s for completed batches(%d).\n",
    146             instance->name, list_count(&instance->batch_list));
    147         link_t *current = instance->batch_list.next;
    148         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) {
    149147                link_t *next = current->next;
    150                 usb_transfer_batch_t *batch =
    151                     list_get_instance(current, usb_transfer_batch_t, link);
    152 
    153                 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)) {
    154152                        /* Save for post-processing */
    155                         transfer_list_remove_batch(instance, batch);
     153                        endpoint_list_remove_endpoint(instance, endpoint);
    156154                        list_append(current, done);
    157155                }
     
    161159}
    162160/*----------------------------------------------------------------------------*/
    163 /** Walk the list and abort all batches.
    164  *
    165  * @param[in] instance List to use.
    166  */
    167 void transfer_list_abort_all(transfer_list_t *instance)
    168 {
    169         fibril_mutex_lock(&instance->guard);
    170         while (!list_empty(&instance->batch_list)) {
    171                 link_t *current = instance->batch_list.next;
    172                 usb_transfer_batch_t *batch =
    173                     list_get_instance(current, usb_transfer_batch_t, link);
    174                 transfer_list_remove_batch(instance, batch);
    175                 usb_transfer_batch_finish_error(batch, EIO);
    176         }
    177         fibril_mutex_unlock(&instance->guard);
    178 }
    179 /*----------------------------------------------------------------------------*/
    180 /** Remove a transfer batch from the list and queue.
    181  *
    182  * @param[in] instance List to use.
    183  * @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.
    184183 * @return Error code
    185184 *
    186185 * Does not lock the transfer list, caller is responsible for that.
    187186 */
    188 void transfer_list_remove_batch(
    189     transfer_list_t *instance, usb_transfer_batch_t *batch)
     187void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep)
    190188{
    191189        assert(instance);
    192190        assert(instance->list_head);
    193         assert(batch);
    194         assert(batch_ed(batch));
    195         assert(fibril_mutex_is_locked(&instance->guard));
     191        assert(hcd_ep);
     192        assert(hcd_ep->ed);
     193
     194        fibril_mutex_lock(&instance->guard);
    196195
    197196        usb_log_debug2(
    198             "Queue %s: removing batch(%p).\n", instance->name, batch);
     197            "Queue %s: removing endpoint(%p).\n", instance->name, hcd_ep);
    199198
    200199        const char *qpos = NULL;
     200        ed_t *prev_ed;
    201201        /* Remove from the hardware queue */
    202         if (instance->batch_list.next == &batch->link) {
     202        if (instance->endpoint_list.next == &hcd_ep->link) {
    203203                /* I'm the first one here */
    204                 assert((instance->list_head->next & ED_NEXT_PTR_MASK)
    205                     == addr_to_phys(batch_ed(batch)));
    206                 instance->list_head->next = batch_ed(batch)->next;
     204                prev_ed = instance->list_head;
    207205                qpos = "FIRST";
    208206        } else {
    209                 usb_transfer_batch_t *prev =
    210                     list_get_instance(
    211                         batch->link.prev, usb_transfer_batch_t, link);
    212                 assert((batch_ed(prev)->next & ED_NEXT_PTR_MASK)
    213                     == addr_to_phys(batch_ed(batch)));
    214                 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;
    215210                qpos = "NOT FIRST";
    216211        }
     212        assert((prev_ed->next & ED_NEXT_PTR_MASK) == addr_to_phys(hcd_ep->ed));
     213        prev_ed->next = hcd_ep->ed->next;
     214
    217215        asm volatile ("": : :"memory");
    218         usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
    219             batch, qpos, instance->name, batch_ed(batch)->next);
    220 
    221         /* Remove from the batch list */
    222         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);
    223222}
    224223/**
Note: See TracChangeset for help on using the changeset viewer.