Changeset 6143ce3 in mainline


Ignore:
Timestamp:
2011-03-13T15:37:28Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8850690
Parents:
eb0dc58
Message:

Rename queue_head_t ⇒ qh_t

Refactoring

Location:
uspace/drv/uhci-hcd
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/batch.c

    reb0dc58 r6143ce3  
    100100        bzero(instance, sizeof(batch_t));
    101101
    102         instance->qh = malloc32(sizeof(queue_head_t));
     102        instance->qh = malloc32(sizeof(qh_t));
    103103        CHECK_NULL_DISPOSE_RETURN(instance->qh,
    104104            "Failed to allocate batch queue head.\n");
    105         queue_head_init(instance->qh);
     105        qh_init(instance->qh);
    106106
    107107        instance->packets = (size + max_packet_size - 1) / max_packet_size;
     
    114114            instance->tds, "Failed to allocate transfer descriptors.\n");
    115115        bzero(instance->tds, sizeof(td_t) * instance->packets);
    116 
    117 //      const size_t transport_size = max_packet_size * instance->packets;
    118116
    119117        if (size > 0) {
     
    143141        instance->speed = speed;
    144142        instance->manager = manager;
    145 
    146         if (func_out)
    147                 instance->callback_out = func_out;
    148         if (func_in)
    149                 instance->callback_in = func_in;
    150 
    151         queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds));
     143        instance->callback_out = func_out;
     144        instance->callback_in = func_in;
     145
     146        qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
    152147
    153148        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
  • uspace/drv/uhci-hcd/batch.h

    reb0dc58 r6143ce3  
    5050        usb_target_t target;
    5151        usb_transfer_type_t transfer_type;
    52         union {
    53                 usbhc_iface_transfer_in_callback_t callback_in;
    54                 usbhc_iface_transfer_out_callback_t callback_out;
    55         };
     52        usbhc_iface_transfer_in_callback_t callback_in;
     53        usbhc_iface_transfer_out_callback_t callback_out;
    5654        void *arg;
    5755        char *transport_buffer;
     
    6563        int error;
    6664        ddf_fun_t *fun;
    67         queue_head_t *qh;
     65        qh_t *qh;
    6866        td_t *tds;
    6967        void (*next_step)(struct batch*);
  • uspace/drv/uhci-hcd/transfer_list.c

    reb0dc58 r6143ce3  
    4747 * @return Error code
    4848 *
    49  * Allocates memory for internat queue_head_t structure.
     49 * Allocates memory for internal qh_t structure.
    5050 */
    5151int transfer_list_init(transfer_list_t *instance, const char *name)
    5252{
    5353        assert(instance);
    54         instance->next = NULL;
    5554        instance->name = name;
    56         instance->queue_head = malloc32(sizeof(queue_head_t));
     55        instance->queue_head = malloc32(sizeof(qh_t));
    5756        if (!instance->queue_head) {
    5857                usb_log_error("Failed to allocate queue head.\n");
     
    6160        instance->queue_head_pa = addr_to_phys(instance->queue_head);
    6261
    63         queue_head_init(instance->queue_head);
     62        qh_init(instance->queue_head);
    6463        list_initialize(&instance->batch_list);
    6564        fibril_mutex_initialize(&instance->guard);
     
    7271 * @param[in] next List to append.
    7372 * @return Error code
     73 *
     74 * Does not check whether there was a next list already.
    7475 */
    7576void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
     
    7980        if (!instance->queue_head)
    8081                return;
    81         queue_head_append_qh(instance->queue_head, next->queue_head_pa);
    82         instance->queue_head->element = instance->queue_head->next_queue;
     82        /* set both next and element to point to the same QH */
     83        qh_set_next_qh(instance->queue_head, next->queue_head_pa);
     84        qh_set_element_qh(instance->queue_head, next->queue_head_pa);
    8385}
    8486/*----------------------------------------------------------------------------*/
     
    9395        assert(instance);
    9496        assert(batch);
    95         usb_log_debug2(
    96             "Adding batch(%p) to queue %s.\n", batch, instance->name);
     97        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    9798
    98         uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
     99        const uint32_t pa = addr_to_phys(batch->qh);
    99100        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    100         pa |= LINK_POINTER_QUEUE_HEAD_FLAG;
    101101
    102         batch->qh->next_queue = instance->queue_head->next_queue;
     102        /* New batch will be added to the end of the current list
     103         * so set the link accordingly */
     104        qh_set_next_qh(batch->qh, instance->queue_head->next);
    103105
    104106        fibril_mutex_lock(&instance->guard);
    105107
    106         if (instance->queue_head->element == instance->queue_head->next_queue) {
    107                 /* there is nothing scheduled */
    108                 list_append(&batch->link, &instance->batch_list);
    109                 instance->queue_head->element = pa;
    110                 usb_log_debug("Batch(%p) added to queue %s first.\n",
    111                         batch, instance->name);
    112                 fibril_mutex_unlock(&instance->guard);
    113                 return;
     108        if (list_empty(&instance->batch_list)) {
     109                /* There is nothing scheduled */
     110                qh_t *qh = instance->queue_head;
     111                assert(qh->element == qh->next);
     112                qh_set_element_qh(qh, pa);
     113        } else {
     114                /* There is something scheduled */
     115                batch_t *last = list_get_instance(
     116                    instance->batch_list.prev, batch_t, link);
     117                qh_set_next_qh(last->qh, pa);
    114118        }
    115         /* now we can be sure that there is someting scheduled */
    116         assert(!list_empty(&instance->batch_list));
    117         batch_t *first = list_get_instance(
    118                   instance->batch_list.next, batch_t, link);
    119         batch_t *last = list_get_instance(
    120             instance->batch_list.prev, batch_t, link);
    121         queue_head_append_qh(last->qh, pa);
    122119        list_append(&batch->link, &instance->batch_list);
    123120
    124         usb_log_debug("Batch(%p) added to queue %s last, first is %p.\n",
     121        batch_t *first = list_get_instance(
     122            instance->batch_list.next, batch_t, link);
     123        usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
    125124                batch, instance->name, first);
    126125        fibril_mutex_unlock(&instance->guard);
    127126}
    128127/*----------------------------------------------------------------------------*/
    129 /** Removes a transfer batch from list and queue.
     128/** Removes a transfer batch from the list and queue.
    130129 *
    131130 * @param[in] instance List to use.
    132131 * @param[in] batch Transfer batch to remove.
    133132 * @return Error code
     133 *
     134 * Does not lock the transfer list, caller is responsible for that.
    134135 */
    135136void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
     
    140141        assert(batch->qh);
    141142        usb_log_debug2(
    142             "Removing batch(%p) from queue %s.\n", batch, instance->name);
     143            "Queue %s: removing batch(%p).\n", instance->name, batch);
    143144
     145        const char * pos = NULL;
    144146        if (batch->link.prev == &instance->batch_list) {
    145147                /* I'm the first one here */
    146                 usb_log_debug(
    147                     "Batch(%p) removed (FIRST) from %s, next element %x.\n",
    148                     batch, instance->name, batch->qh->next_queue);
    149                 instance->queue_head->element = batch->qh->next_queue;
     148                qh_set_element_qh(instance->queue_head, batch->qh->next);
     149                pos = "FIRST";
    150150        } else {
    151                 usb_log_debug(
    152                     "Batch(%p) removed (FIRST:NO) from %s, next element %x.\n",
    153                     batch, instance->name, batch->qh->next_queue);
    154151                batch_t *prev =
    155152                    list_get_instance(batch->link.prev, batch_t, link);
    156                 prev->qh->next_queue = batch->qh->next_queue;
     153                qh_set_next_qh(prev->qh, batch->qh->next);
     154                pos = "NOT FIRST";
    157155        }
    158156        list_remove(&batch->link);
     157        usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
     158            batch, pos, instance->name, batch->qh->next);
    159159}
    160160/*----------------------------------------------------------------------------*/
    161 /** Checks list for finished transfers.
     161/** Checks list for finished batches.
    162162 *
    163163 * @param[in] instance List to use.
  • uspace/drv/uhci-hcd/transfer_list.h

    reb0dc58 r6143ce3  
    4444{
    4545        fibril_mutex_t guard;
    46         queue_head_t *queue_head;
     46        qh_t *queue_head;
    4747        uint32_t queue_head_pa;
    48         struct transfer_list *next;
    4948        const char *name;
    5049        link_t batch_list;
  • uspace/drv/uhci-hcd/uhci.c

    reb0dc58 r6143ce3  
    437437                int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
    438438
    439                 uintptr_t expected_pa = instance->frame_list[frnum] & (~0xf);
     439                uintptr_t expected_pa = instance->frame_list[frnum]
     440                    & LINK_POINTER_ADDRESS_MASK;
    440441                uintptr_t real_pa = addr_to_phys(QH(interrupt));
    441442                if (expected_pa != real_pa) {
     
    444445                }
    445446
    446                 expected_pa = QH(interrupt)->next_queue & (~0xf);
     447                expected_pa = QH(interrupt)->next & LINK_POINTER_ADDRESS_MASK;
    447448                real_pa = addr_to_phys(QH(control_slow));
    448449                if (expected_pa != real_pa) {
     
    451452                }
    452453
    453                 expected_pa = QH(control_slow)->next_queue & (~0xf);
     454                expected_pa = QH(control_slow)->next & LINK_POINTER_ADDRESS_MASK;
    454455                real_pa = addr_to_phys(QH(control_full));
    455456                if (expected_pa != real_pa) {
     
    458459                }
    459460
    460                 expected_pa = QH(control_full)->next_queue & (~0xf);
     461                expected_pa = QH(control_full)->next & LINK_POINTER_ADDRESS_MASK;
    461462                real_pa = addr_to_phys(QH(bulk_full));
    462463                if (expected_pa != real_pa ) {
  • uspace/drv/uhci-hcd/uhci_struct/link_pointer.h

    reb0dc58 r6143ce3  
    4646#define LINK_POINTER_ADDRESS_MASK 0xfffffff0 /* upper 28 bits */
    4747
     48#define LINK_POINTER_QH(address) \
     49        ((address & LINK_POINTER_ADDRESS_MASK) | LINK_POINTER_QUEUE_HEAD_FLAG)
     50
    4851#endif
    4952/**
  • uspace/drv/uhci-hcd/uhci_struct/queue_head.h

    reb0dc58 r6143ce3  
    4343
    4444typedef struct queue_head {
    45         volatile link_pointer_t next_queue;
     45        volatile link_pointer_t next;
    4646        volatile link_pointer_t element;
    47 } __attribute__((packed)) queue_head_t;
    48 
    49 static inline void queue_head_init(queue_head_t *instance)
     47} __attribute__((packed)) qh_t;
     48/*----------------------------------------------------------------------------*/
     49static inline void qh_init(qh_t *instance)
    5050{
    5151        assert(instance);
    5252
    5353        instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
    54         instance->next_queue = 0 | LINK_POINTER_TERMINATE_FLAG;
     54        instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
    5555}
    56 
    57 static inline void queue_head_append_qh(queue_head_t *instance, uint32_t pa)
     56/*----------------------------------------------------------------------------*/
     57static inline void qh_set_next_qh(qh_t *instance, uint32_t pa)
    5858{
    59         if (pa) {
    60                 instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
     59        /* address is valid and not terminal */
     60        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
     61                instance->next = (pa & LINK_POINTER_ADDRESS_MASK)
    6162                    | LINK_POINTER_QUEUE_HEAD_FLAG;
     63        } else {
     64                instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
    6265        }
    6366}
    64 
    65 static inline void queue_head_element_qh(queue_head_t *instance, uint32_t pa)
     67/*----------------------------------------------------------------------------*/
     68static inline void qh_set_element_qh(qh_t *instance, uint32_t pa)
    6669{
    67         if (pa) {
    68                 instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
     70        /* address is valid and not terminal */
     71        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
     72                instance->element = (pa & LINK_POINTER_ADDRESS_MASK)
    6973                    | LINK_POINTER_QUEUE_HEAD_FLAG;
     74        } else {
     75                instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
    7076        }
    7177}
    72 
    73 static inline void queue_head_set_element_td(queue_head_t *instance, uint32_t pa)
     78/*----------------------------------------------------------------------------*/
     79static inline void qh_set_element_td(qh_t *instance, uint32_t pa)
    7480{
    75         if (pa) {
     81        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    7682                instance->element = (pa & LINK_POINTER_ADDRESS_MASK);
     83        } else {
     84                instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;
    7785        }
    7886}
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h

    reb0dc58 r6143ce3  
    4949#define TD_STATUS_ERROR_COUNT_POS ( 27 )
    5050#define TD_STATUS_ERROR_COUNT_MASK ( 0x3 )
    51 #define TD_STATUS_ERROR_COUNT_DEFAULT 3
    5251#define TD_STATUS_LOW_SPEED_FLAG ( 1 << 26 )
    5352#define TD_STATUS_ISOCHRONOUS_FLAG ( 1 << 25 )
Note: See TracChangeset for help on using the changeset viewer.