Changeset 335382d in mainline for uspace/drv/uhci-hcd/uhci_struct


Ignore:
Timestamp:
2011-03-13T18:17:30Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
deb4ba7
Parents:
0f3e68c (diff), a9f91cd (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:

BIG refactoring, fixed a memory leak and few TODOs

Location:
uspace/drv/uhci-hcd/uhci_struct
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/uhci_struct/link_pointer.h

    r0f3e68c r335382d  
    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

    r0f3e68c r335382d  
    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.c

    r0f3e68c r335382d  
    4444 * @param[in] size Size of data source.
    4545 * @param[in] toggle Value of toggle bit.
    46  * @param[in] iso True if TD is for Isochronous transfer.
     46 * @param[in] iso True if TD represents Isochronous transfer.
    4747 * @param[in] low_speed Target device's speed.
    4848 * @param[in] target Address and endpoint receiving the transfer.
     
    5151 * @param[in] next Net TD in transaction.
    5252 * @return Error code.
     53 *
     54 * Uses a mix of supplied and default values.
     55 * Implicit values:
     56 *  - all TDs have vertical flag set (makes transfers to endpoints atomic)
     57 *  - in the error field only active it is set
     58 *  - if the packet uses PID_IN and is not isochronous SPD is set
     59 *
     60 * Dumps 8 bytes of buffer if PID_SETUP is used.
    5361 */
    5462void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
     
    94102        if (pid == USB_PID_SETUP) {
    95103                usb_log_debug("SETUP BUFFER: %s\n",
    96                         usb_debug_str_buffer(buffer, 8, 8));
     104                    usb_debug_str_buffer(buffer, 8, 8));
    97105        }
    98106}
     
    128136}
    129137/*----------------------------------------------------------------------------*/
     138/** Print values in status field (dw1) in a human readable way.
     139 *
     140 * @param[in] instance TD structure to use.
     141 */
    130142void td_print_status(td_t *instance)
    131143{
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h

    r0f3e68c r335382d  
    4545
    4646        volatile uint32_t status;
    47 
    4847#define TD_STATUS_RESERVED_MASK 0xc000f800
    4948#define TD_STATUS_SPD_FLAG ( 1 << 29 )
    5049#define TD_STATUS_ERROR_COUNT_POS ( 27 )
    5150#define TD_STATUS_ERROR_COUNT_MASK ( 0x3 )
    52 #define TD_STATUS_ERROR_COUNT_DEFAULT 3
    5351#define TD_STATUS_LOW_SPEED_FLAG ( 1 << 26 )
    5452#define TD_STATUS_ISOCHRONOUS_FLAG ( 1 << 25 )
     
    7068
    7169        volatile uint32_t device;
    72 
    7370#define TD_DEVICE_MAXLEN_POS 21
    7471#define TD_DEVICE_MAXLEN_MASK ( 0x7ff )
     
    8582
    8683        /* there is 16 bytes of data available here, according to UHCI
    87          * Design guide, according to linux kernel the hardware does not care
    88          * we don't use it anyway
     84         * Design guide, according to linux kernel the hardware does not care,
     85         * it just needs to be aligned, we don't use it anyway
    8986         */
    9087} __attribute__((packed)) td_t;
     
    9794int td_status(td_t *instance);
    9895
     96void td_print_status(td_t *instance);
     97/*----------------------------------------------------------------------------*/
     98/** Helper function for parsing actual size out of TD.
     99 *
     100 * @param[in] instance TD structure to use.
     101 * @return Parsed actual size.
     102 */
    99103static inline size_t td_act_size(td_t *instance)
    100104{
    101105        assert(instance);
    102         return
    103             ((instance->status >> TD_STATUS_ACTLEN_POS) + 1)
    104             & TD_STATUS_ACTLEN_MASK;
     106        const uint32_t s = instance->status;
     107        return ((s >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK;
    105108}
    106 
     109/*----------------------------------------------------------------------------*/
     110/** Checks whether less than max data were recieved and packet is marked as SPD.
     111 *
     112 * @param[in] instance TD structure to use.
     113 * @return True if packet is short (less than max bytes and SPD set), false
     114 *     otherwise.
     115 */
    107116static inline bool td_is_short(td_t *instance)
    108117{
     
    114123            (instance->status | TD_STATUS_SPD_FLAG) && act_size < max_size;
    115124}
    116 
     125/*----------------------------------------------------------------------------*/
     126/** Helper function for parsing value of toggle bit.
     127 *
     128 * @param[in] instance TD structure to use.
     129 * @return Toggle bit value.
     130 */
    117131static inline int td_toggle(td_t *instance)
    118132{
    119133        assert(instance);
    120         return ((instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) != 0)
    121             ? 1 : 0;
     134        return (instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) ? 1 : 0;
    122135}
    123 
     136/*----------------------------------------------------------------------------*/
     137/** Helper function for parsing value of active bit
     138 *
     139 * @param[in] instance TD structure to use.
     140 * @return Active bit value.
     141 */
    124142static inline bool td_is_active(td_t *instance)
    125143{
     
    127145        return (instance->status & TD_STATUS_ERROR_ACTIVE) != 0;
    128146}
    129 
    130 void td_print_status(td_t *instance);
     147/*----------------------------------------------------------------------------*/
     148/** Helper function for setting IOC bit.
     149 *
     150 * @param[in] instance TD structure to use.
     151 */
     152static inline void td_set_ioc(td_t *instance)
     153{
     154        assert(instance);
     155        instance->status |= TD_STATUS_IOC_FLAG;
     156}
     157/*----------------------------------------------------------------------------*/
    131158#endif
    132159/**
Note: See TracChangeset for help on using the changeset viewer.