Changeset 70d72dd in mainline


Ignore:
Timestamp:
2011-10-16T14:24:05Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d5abaf4
Parents:
9515f674
Message:

ohci: OHCI TD routines refactoring.

Merge td_set_next to td_init: td list is built during initialization.
Add doxygen and other comments.
Add ed_inactive and ed_transfer_pending routines, these will be used later.

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

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h

    r9515f674 r70d72dd  
    109109
    110110/**
     111 * Check for SKIP or HALTED flag being set.
     112 * @param instance ED
     113 * @return true if either SKIP or HALTED flag is set, false otherwise.
     114 */
     115static inline bool ed_inactive(const ed_t *instance)
     116{
     117        assert(instance);
     118        return (instance->td_head & ED_TDHEAD_HALTED_FLAG)
     119            || (instance->status & ED_STATUS_K_FLAG);
     120}
     121
     122/**
     123 * Check whether this ED contains TD to be executed.
     124 * @param instance ED
     125 * @return true if there are pending TDs, false otherwise.
     126 */
     127static inline bool ed_transfer_pending(const ed_t *instance)
     128{
     129        assert(instance);
     130        return (instance->td_head & ED_TDHEAD_PTR_MASK)
     131            != (instance->td_tail & ED_TDTAIL_PTR_MASK);
     132}
     133
     134/**
    111135 * Set the last element of TD list
    112136 * @param instance ED
  • uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c

    r9515f674 r70d72dd  
    3535#include "transfer_descriptor.h"
    3636
    37 static unsigned dp[3] =
    38     { TD_STATUS_DP_IN, TD_STATUS_DP_OUT, TD_STATUS_DP_SETUP };
    39 static unsigned togg[2] = { TD_STATUS_T_0, TD_STATUS_T_1 };
     37/** USB direction to OHCI TD values translation table */
     38static const uint32_t dir[] = {
     39        [USB_DIRECTION_IN] = TD_STATUS_DP_IN,
     40        [USB_DIRECTION_OUT] = TD_STATUS_DP_OUT,
     41        [USB_DIRECTION_BOTH] = TD_STATUS_DP_SETUP,
     42};
    4043
    41 void td_init(td_t *instance,
    42     usb_direction_t dir, const void *buffer, size_t size, int toggle)
     44/**
     45 * Initialize OHCI TD.
     46 * @param instance TD structure to initialize.
     47 * @param next Next TD in ED list.
     48 * @param direction Used to determine PID, BOTH means setup PID.
     49 * @param buffer Pointer to the first byte of transferred data.
     50 * @param size Size of the buffer.
     51 * @param toggle Toggle bit value, use 0/1 to set explicitly,
     52 *        any other value means that ED toggle will be used.
     53 */
     54void td_init(td_t *instance, const td_t *next,
     55    usb_direction_t direction, const void *buffer, size_t size, int toggle)
    4356{
    4457        assert(instance);
    4558        bzero(instance, sizeof(td_t));
     59        /* Set PID and Error code */
    4660        instance->status = 0
    47             | ((dp[dir] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT)
     61            | ((dir[direction] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT)
    4862            | ((CC_NOACCESS2 & TD_STATUS_CC_MASK) << TD_STATUS_CC_SHIFT);
     63
    4964        if (toggle == 0 || toggle == 1) {
    50                 instance->status |= togg[toggle] << TD_STATUS_T_SHIFT;
     65                /* Set explicit toggle bit */
     66                instance->status |= TD_STATUS_T_USE_TD_FLAG;
     67                instance->status |= toggle ? TD_STATUS_T_FLAG : 0;
    5168        }
     69
     70        /* Alow less data on input. */
    5271        if (dir == USB_DIRECTION_IN) {
    5372                instance->status |= TD_STATUS_ROUND_FLAG;
    5473        }
     74
    5575        if (buffer != NULL) {
    5676                assert(size != 0);
     
    5878                instance->be = addr_to_phys(buffer + size - 1);
    5979        }
     80
     81        instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
     82
    6083}
    6184/**
  • uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h

    r9515f674 r70d72dd  
    3737#include <bool.h>
    3838#include <stdint.h>
     39
    3940#include "../utils/malloc32.h"
    40 
    4141#include "completion_codes.h"
    4242
     
    4646#define OHCI_TD_MAX_TRANSFER (4 * 1024)
    4747
     48/**
     49 * Transfer Descriptor representation.
     50 *
     51 * See OHCI spec chapter 4.3.1 General Transfer Descriptor on page 19
     52 * (pdf page 33) for details.
     53 */
    4854typedef struct td {
     55        /** Status field. Do not touch on active TDs. */
    4956        volatile uint32_t status;
    5057#define TD_STATUS_ROUND_FLAG (1 << 18)
    51 #define TD_STATUS_DP_MASK (0x3) /* direction/PID */
     58#define TD_STATUS_DP_MASK (0x3) /* Direction/PID */
    5259#define TD_STATUS_DP_SHIFT (19)
    5360#define TD_STATUS_DP_SETUP (0x0)
    5461#define TD_STATUS_DP_OUT (0x1)
    5562#define TD_STATUS_DP_IN (0x2)
    56 #define TD_STATUS_DI_MASK (0x7) /* delay interrupt, wait DI frames before int */
     63#define TD_STATUS_DI_MASK (0x7) /* Delay interrupt, wait n frames before irq */
    5764#define TD_STATUS_DI_SHIFT (21)
    5865#define TD_STATUS_DI_NO_INTERRUPT (0x7)
    59 #define TD_STATUS_T_MASK (0x3)  /* data toggle 1x = use ED toggle carry */
    60 #define TD_STATUS_T_SHIFT (24)
    61 #define TD_STATUS_T_0 (0x2)
    62 #define TD_STATUS_T_1 (0x3)
    63 #define TD_STATUS_T_ED (0)
    64 #define TD_STATUS_EC_MASK (0x3) /* error count */
     66#define TD_STATUS_T_FLAG (1 << 24) /* Explicit toggle bit value for this TD */
     67#define TD_STATUS_T_USE_TD_FLAG (1 << 25) /* 1 = use bit 24 as toggle bit */
     68#define TD_STATUS_EC_MASK (0x3) /* Error count */
    6569#define TD_STATUS_EC_SHIFT (26)
    66 #define TD_STATUS_CC_MASK (0xf) /* condition code */
     70#define TD_STATUS_CC_MASK (0xf) /* Condition code */
    6771#define TD_STATUS_CC_SHIFT (28)
    6872
    69         volatile uint32_t cbp; /* current buffer ptr, data to be transfered */
     73        /**
     74         * Current buffer pointer.
     75         * Phys address of the first byte to be transferred. */
     76        volatile uint32_t cbp;
     77
     78        /** Pointer to the next TD in chain. 16-byte aligned. */
    7079        volatile uint32_t next;
    7180#define TD_NEXT_PTR_MASK (0xfffffff0)
    7281#define TD_NEXT_PTR_SHIFT (0)
    7382
    74         volatile uint32_t be; /* buffer end, address of the last byte */
     83        /**
     84         * Buffer end.
     85         * Phys address of the last byte of the transfer.
     86         * @note this does not have to be on the same page as cbp.
     87         */
     88        volatile uint32_t be;
    7589} __attribute__((packed)) td_t;
    7690
    77 void td_init(td_t *instance,
     91void td_init(td_t *instance, const td_t *next,
    7892    usb_direction_t dir, const void *buffer, size_t size, int toggle);
    7993
    80 inline static void td_set_next(td_t *instance, td_t *next)
     94/**
     95 * Check TD for completion.
     96 * @param instance TD structure.
     97 * @return true if the TD was accessed and processed by hw, false otherwise.
     98 */
     99inline static bool td_is_finished(const td_t *instance)
    81100{
    82101        assert(instance);
    83         instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
    84 }
    85 
    86 inline static bool td_is_finished(td_t *instance)
    87 {
    88         assert(instance);
    89         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    90         /* something went wrong, error code is set */
     102        const int cc =
     103            (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     104        /* This value is changed on transfer completion,
     105         * either to CC_NOERROR or and error code.
     106         * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) */
    91107        if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
    92                 return true;
    93         }
    94         /* everything done */
    95         if (cc == CC_NOERROR && instance->cbp == 0) {
    96108                return true;
    97109        }
     
    99111}
    100112
    101 static inline int td_error(td_t *instance)
     113/**
     114 * Get error code that indicates transfer status.
     115 * @param instance TD structure.
     116 * @return Error code.
     117 */
     118static inline int td_error(const td_t *instance)
    102119{
    103120        assert(instance);
    104         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     121        const int cc =
     122            (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    105123        return cc_to_rc(cc);
    106124}
    107125
     126/**
     127 * Get remaining portion of buffer to be read/written
     128 * @param instance TD structure
     129 * @return size of remaining buffer.
     130 */
    108131static inline size_t td_remain_size(td_t *instance)
    109132{
    110133        assert(instance);
     134        /* Current buffer pointer is cleared on successful transfer */
    111135        if (instance->cbp == 0)
    112136                return 0;
     137        /* Buffer end points to the last byte of transfer buffer, so add 1 */
    113138        return instance->be - instance->cbp + 1;
    114139}
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r9515f674 r70d72dd  
    248248
    249249        /* setup stage */
    250         td_init(ohci_batch->tds[0], USB_DIRECTION_BOTH, buffer,
    251                 ohci_batch->usb_batch->setup_size, toggle);
    252         td_set_next(ohci_batch->tds[0], ohci_batch->tds[1]);
     250        td_init(
     251            ohci_batch->tds[0], ohci_batch->tds[1], USB_DIRECTION_BOTH,
     252            buffer, ohci_batch->usb_batch->setup_size, toggle);
    253253        usb_log_debug("Created CONTROL SETUP TD: %08x:%08x:%08x:%08x.\n",
    254254            ohci_batch->tds[0]->status, ohci_batch->tds[0]->cbp,
     
    265265                toggle = 1 - toggle;
    266266
    267                 td_init(ohci_batch->tds[td_current], data_dir, buffer,
    268                     transfer_size, toggle);
    269                 td_set_next(ohci_batch->tds[td_current],
    270                     ohci_batch->tds[td_current + 1]);
     267                td_init(ohci_batch->tds[td_current],
     268                    ohci_batch->tds[td_current + 1],
     269                    data_dir, buffer, transfer_size, toggle);
    271270                usb_log_debug("Created CONTROL DATA TD: %08x:%08x:%08x:%08x.\n",
    272271                    ohci_batch->tds[td_current]->status,
     
    283282        /* status stage */
    284283        assert(td_current == ohci_batch->td_count - 1);
    285         td_init(ohci_batch->tds[td_current], status_dir, NULL, 0, 1);
    286         td_set_next(ohci_batch->tds[td_current],
    287             ohci_batch->tds[td_current + 1]);
     284        td_init(ohci_batch->tds[td_current], ohci_batch->tds[td_current + 1],
     285            status_dir, NULL, 0, 1);
    288286        usb_log_debug("Created CONTROL STATUS TD: %08x:%08x:%08x:%08x.\n",
    289287            ohci_batch->tds[td_current]->status,
     
    323321                    ? OHCI_TD_MAX_TRANSFER : remain_size;
    324322
    325                 td_init(ohci_batch->tds[td_current], dir, buffer,
    326                     transfer_size, -1);
    327                 td_set_next(ohci_batch->tds[td_current],
    328                     ohci_batch->tds[td_current + 1]);
     323                td_init(
     324                    ohci_batch->tds[td_current], ohci_batch->tds[td_current + 1],
     325                    dir, buffer, transfer_size, -1);
    329326
    330327                usb_log_debug("Created DATA TD: %08x:%08x:%08x:%08x.\n",
Note: See TracChangeset for help on using the changeset viewer.