Changeset 9515f674 in mainline


Ignore:
Timestamp:
2011-10-16T14:21:49Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
70d72dd
Parents:
721d4b6e
Message:

ohci: OHCI ED routines refactoring.

Merge ed_set_td to ed_init: td should be set explicitly only during initialization.
Add doxygen and other comments.

Location:
uspace/drv/bus/usb/ohci
Files:
5 edited

Legend:

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

    r721d4b6e r9515f674  
    6060            name, instance->list_head, instance->list_head_pa);
    6161
    62         ed_init(instance->list_head, NULL);
     62        ed_init(instance->list_head, NULL, NULL);
    6363        list_initialize(&instance->endpoint_list);
    6464        fibril_mutex_initialize(&instance->guard);
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c

    r721d4b6e r9515f674  
    3434#include "endpoint_descriptor.h"
    3535
    36 static unsigned direc[3] =
    37     { ED_STATUS_D_IN, ED_STATUS_D_OUT, ED_STATUS_D_TRANSFER };
     36/** USB direction to OHCI values translation table. */
     37static const uint32_t dir[] = {
     38        [USB_DIRECTION_IN] = ED_STATUS_D_IN,
     39        [USB_DIRECTION_OUT] = ED_STATUS_D_OUT,
     40        [USB_DIRECTION_BOTH] = ED_STATUS_D_TD,
     41};
    3842
    39 void ed_init(ed_t *instance, endpoint_t *ep)
     43/**
     44 * Initialize ED.
     45 *
     46 * @param instance ED structure to initialize.
     47 * @param ep Driver endpoint to use.
     48 * @param td TD to put in the list.
     49 *
     50 * If @param ep is NULL, dummy ED is initalized with only skip flag set.
     51 */
     52void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td)
    4053{
    4154        assert(instance);
    4255        bzero(instance, sizeof(ed_t));
     56
    4357        if (ep == NULL) {
     58                /* Mark as dead, used for dummy EDs at the beginning of
     59                 * endpoint lists. */
    4460                instance->status = ED_STATUS_K_FLAG;
    4561                return;
    4662        }
    47         assert(ep);
     63        /* Non-dummy ED must have TD assigned */
     64        assert(td);
     65
     66        /* Status: address, endpoint nr, direction mask and max packet size. */
    4867        instance->status = 0
    4968            | ((ep->address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT)
    5069            | ((ep->endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT)
    51             | ((direc[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
     70            | ((dir[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
    5271            | ((ep->max_packet_size & ED_STATUS_MPS_MASK)
    5372                << ED_STATUS_MPS_SHIFT);
    5473
    55 
     74        /* Low speed flag */
    5675        if (ep->speed == USB_SPEED_LOW)
    5776                instance->status |= ED_STATUS_S_FLAG;
     77
     78        /* Isochronous format flag */
    5879        if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
    5980                instance->status |= ED_STATUS_F_FLAG;
    6081
     82        /* Set TD to the list */
     83        const uintptr_t pa = addr_to_phys(td);
     84        instance->td_head = pa & ED_TDHEAD_PTR_MASK;
     85        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
     86
     87        /* Set toggle bit */
    6188        if (ep->toggle)
    6289                instance->td_head |= ED_TDHEAD_TOGGLE_CARRY;
     90
    6391}
    6492/**
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h

    r721d4b6e r9515f674  
    4545#include "completion_codes.h"
    4646
     47/**
     48 * OHCI Endpoint Descriptor representation.
     49 *
     50 * See OHCI spec. Chapter 4.2, page 16 (pdf page 30) for details */
    4751typedef struct ed {
     52        /**
     53         * Status field.
     54         *
     55         * See table 4-1, p. 17 OHCI spec (pdf page 31).
     56         */
    4857        volatile uint32_t status;
    4958#define ED_STATUS_FA_MASK (0x7f)   /* USB device address   */
     
    5160#define ED_STATUS_EN_MASK (0xf)    /* USB endpoint address */
    5261#define ED_STATUS_EN_SHIFT (7)
    53 #define ED_STATUS_D_MASK (0x3)     /* direction */
     62#define ED_STATUS_D_MASK (0x3)     /* Direction */
    5463#define ED_STATUS_D_SHIFT (11)
    5564#define ED_STATUS_D_OUT (0x1)
    5665#define ED_STATUS_D_IN (0x2)
    57 #define ED_STATUS_D_TRANSFER (0x3)
     66#define ED_STATUS_D_TD (0x3) /* Direction is specified by TD */
    5867
    59 #define ED_STATUS_S_FLAG (1 << 13) /* speed flag: 1 = low */
    60 #define ED_STATUS_K_FLAG (1 << 14) /* skip flag (no not execute this ED) */
    61 #define ED_STATUS_F_FLAG (1 << 15) /* format: 1 = isochronous*/
    62 #define ED_STATUS_MPS_MASK (0x3ff) /* max_packet_size*/
     68#define ED_STATUS_S_FLAG (1 << 13) /* Speed flag: 1 = low */
     69#define ED_STATUS_K_FLAG (1 << 14) /* Skip flag (no not execute this ED) */
     70#define ED_STATUS_F_FLAG (1 << 15) /* Format: 1 = isochronous */
     71#define ED_STATUS_MPS_MASK (0x3ff) /* Maximum packet size */
    6372#define ED_STATUS_MPS_SHIFT (16)
    6473
     74        /**
     75         * Pointer to the last TD.
     76         *
     77         * OHCI hw never changes this field and uses it only for a reference.
     78         */
    6579        volatile uint32_t td_tail;
    6680#define ED_TDTAIL_PTR_MASK (0xfffffff0)
    6781#define ED_TDTAIL_PTR_SHIFT (0)
    6882
     83        /**
     84         * Pointer to the first TD.
     85         *
     86         * Driver should not change this field if the ED is active.
     87         * This field is updated by OHCI hw and points to the next TD
     88         * to be executed.
     89         */
    6990        volatile uint32_t td_head;
    7091#define ED_TDHEAD_PTR_MASK (0xfffffff0)
     
    7596#define ED_TDHEAD_HALTED_FLAG (0x1)
    7697
     98        /**
     99         * Pointer to the next ED.
     100         *
     101         * Driver should not change this field on active EDs.
     102         */
    77103        volatile uint32_t next;
    78104#define ED_NEXT_PTR_MASK (0xfffffff0)
     
    80106} __attribute__((packed)) ed_t;
    81107
    82 void ed_init(ed_t *instance, endpoint_t *ep);
     108void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td);
    83109
    84 static inline void ed_set_td(ed_t *instance, td_t *td)
     110/**
     111 * Set the last element of TD list
     112 * @param instance ED
     113 * @param instance TD to set as the last item.
     114 */
     115static inline void ed_set_tail_td(ed_t *instance, const td_t *td)
    85116{
    86117        assert(instance);
    87         uintptr_t pa = addr_to_phys(td);
    88         instance->td_head =
    89             ((pa & ED_TDHEAD_PTR_MASK)
    90             | (instance->td_head & ~ED_TDHEAD_PTR_MASK));
     118        const uintptr_t pa = addr_to_phys(td);
    91119        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
    92120}
    93121
    94 static inline void ed_set_end_td(ed_t *instance, td_t *td)
    95 {
    96         assert(instance);
    97         uintptr_t pa = addr_to_phys(td);
    98         instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
    99 }
    100 
    101 static inline void ed_append_ed(ed_t *instance, ed_t *next)
     122/**
     123 * Set next ED in ED chain.
     124 * @param instance ED to modify
     125 * @param next ED to append
     126 */
     127static inline void ed_append_ed(ed_t *instance, const ed_t *next)
    102128{
    103129        assert(instance);
    104130        assert(next);
    105         uint32_t pa = addr_to_phys(next);
     131        const uint32_t pa = addr_to_phys(next);
    106132        assert((pa & ED_NEXT_PTR_MASK) << ED_NEXT_PTR_SHIFT == pa);
    107133        instance->next = pa;
    108134}
    109135
    110 static inline int ed_toggle_get(ed_t *instance)
     136/**
     137 * Get toggle bit value stored in this ED
     138 * @param instance ED
     139 * @return Toggle bit value
     140 */
     141static inline int ed_toggle_get(const ed_t *instance)
    111142{
    112143        assert(instance);
     
    114145}
    115146
    116 static inline void ed_toggle_set(ed_t *instance, int toggle)
     147/**
     148 * Set toggle bit value stored in this ED
     149 * @param instance ED
     150 * @param toggle Toggle bit value
     151 */
     152static inline void ed_toggle_set(ed_t *instance, bool toggle)
    117153{
    118154        assert(instance);
    119         assert(toggle == 0 || toggle == 1);
    120         if (toggle == 1) {
     155        if (toggle) {
    121156                instance->td_head |= ED_TDHEAD_TOGGLE_CARRY;
    122157        } else {
    123                 /* clear halted flag when reseting toggle */
     158                /* Clear halted flag when reseting toggle TODO: Why? */
    124159                instance->td_head &= ~ED_TDHEAD_TOGGLE_CARRY;
    125160                instance->td_head &= ~ED_TDHEAD_HALTED_FLAG;
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r721d4b6e r9515f674  
    217217{
    218218        assert(ohci_batch);
    219         ed_set_end_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
     219        ed_set_tail_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
    220220}
    221221/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/ohci/ohci_endpoint.c

    r721d4b6e r9515f674  
    102102        }
    103103
    104         ed_init(ohci_ep->ed, ep);
    105         ed_set_td(ohci_ep->ed, ohci_ep->td);
     104        ed_init(ohci_ep->ed, ep, ohci_ep->td);
    106105        endpoint_set_hc_data(
    107106            ep, ohci_ep, ohci_endpoint_fini, ohci_ep_toggle_get, ohci_ep_toggle_set);
Note: See TracChangeset for help on using the changeset viewer.