Ignore:
File:
1 edited

Legend:

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

    r33d19a7 r4125b7d  
    4444#include "hw_struct/transfer_descriptor.h"
    4545
    46 /** OHCI specific data required for USB transfer */
    4746typedef struct ohci_transfer_batch {
    48         /** Endpoint descriptor of the target endpoint. */
    4947        ed_t *ed;
    50         /** List of TDs needed for the transfer */
    5148        td_t **tds;
    52         /** Number of TDs used by the transfer */
    5349        size_t td_count;
    54         /** Dummy TD to be left at the ED and used by the next transfer */
    5550        size_t leave_td;
    56         /** Data buffer, must be accessible byb the OHCI hw. */
    57         void *device_buffer;
     51        char *device_buffer;
    5852} ohci_transfer_batch_t;
    59 /*----------------------------------------------------------------------------*/
    60 static void batch_control(usb_transfer_batch_t *instance,
    61     usb_direction_t data_dir, usb_direction_t status_dir);
    62 static void batch_data(usb_transfer_batch_t *instance);
    63 /*----------------------------------------------------------------------------*/
    64 /** Safely destructs ohci_transfer_batch_t structure
    65  *
    66  * @param[in] ohci_batch Instance to destroy.
    67  */
     53
    6854static void ohci_transfer_batch_dispose(void *ohci_batch)
    6955{
     
    8369}
    8470/*----------------------------------------------------------------------------*/
    85 /** Allocate memory initialize internal structures
    86  *
    87  * @param[in] fun DDF function to pass to callback.
    88  * @param[in] ep Communication target
    89  * @param[in] buffer Data source/destination.
    90  * @param[in] buffer_size Size of the buffer.
    91  * @param[in] setup_buffer Setup data source (if not NULL)
    92  * @param[in] setup_size Size of setup_buffer (should be always 8)
    93  * @param[in] func_in function to call on inbound transfer completion
    94  * @param[in] func_out function to call on outbound transfer completion
    95  * @param[in] arg additional parameter to func_in or func_out
    96  * @return Valid pointer if all structures were successfully created,
    97  * NULL otherwise.
    98  *
    99  * Allocates and initializes structures needed by the OHCI hw for the transfer.
    100  */
     71static void batch_control(usb_transfer_batch_t *instance,
     72    usb_direction_t data_dir, usb_direction_t status_dir);
     73static void batch_data(usb_transfer_batch_t *instance);
     74/*----------------------------------------------------------------------------*/
    10175usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
    10276    char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
     
    133107        }
    134108
    135         /* We need an extra place for TD that is currently assigned to hcd_ep*/
     109        /* we need one extra place for td that is currently assigned to hcd_ep*/
    136110        data->tds = calloc(sizeof(td_t*), data->td_count + 1);
    137111        CHECK_NULL_DISPOSE_RETURN(data->tds,
    138112            "Failed to allocate transfer descriptors.\n");
    139113
    140         /* Add TD left over by the previous transfer */
    141114        data->tds[0] = hcd_ep->td;
    142115        data->leave_td = 0;
     
    150123        data->ed = hcd_ep->ed;
    151124
    152         /* NOTE: OHCI is capable of handling buffer that crosses page boundaries
    153          * it is, however, not capable of handling buffer that occupies more
    154          * than two pages (the first page is computed using start pointer, the
    155          * other using the end pointer) */
    156125        if (setup_size + buffer_size > 0) {
    157126                data->device_buffer = malloc32(setup_size + buffer_size);
     
    166135}
    167136/*----------------------------------------------------------------------------*/
    168 /** Check batch TDs' status.
    169  *
    170  * @param[in] instance Batch structure to use.
    171  * @return False, if there is an active TD, true otherwise.
    172  *
    173  * Walk all TDs (usually there is just one). Stop with false if there is an
    174  * active TD. Stop with true if an error is found. Return true if the walk
    175  * completes with the last TD.
    176  */
    177137bool batch_is_complete(usb_transfer_batch_t *instance)
    178138{
     
    180140        ohci_transfer_batch_t *data = instance->private_data;
    181141        assert(data);
     142        size_t tds = data->td_count;
    182143        usb_log_debug("Batch(%p) checking %zu td(s) for completion.\n",
    183             instance, data->td_count);
     144            instance, tds);
    184145        usb_log_debug("ED: %x:%x:%x:%x.\n",
    185146            data->ed->status, data->ed->td_head, data->ed->td_tail,
     
    187148        size_t i = 0;
    188149        instance->transfered_size = instance->buffer_size;
    189         for (; i < data->td_count; ++i) {
     150        for (; i < tds; ++i) {
    190151                assert(data->tds[i] != NULL);
    191152                usb_log_debug("TD %zu: %x:%x:%x:%x.\n", i,
     
    212173        assert(hcd_ep);
    213174        hcd_ep->td = data->tds[i];
    214         assert(i > 0);
    215         for (--i;i < data->td_count; ++i)
    216                 instance->transfered_size -= td_remain_size(data->tds[i]);
     175        if (i > 0)
     176                instance->transfered_size -= td_remain_size(data->tds[i - 1]);
    217177
    218178        /* Clear possible ED HALT */
    219179        data->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
    220         const uint32_t pa = addr_to_phys(hcd_ep->td);
     180        uint32_t pa = addr_to_phys(hcd_ep->td);
    221181        assert(pa == (data->ed->td_head & ED_TDHEAD_PTR_MASK));
    222182        assert(pa == (data->ed->td_tail & ED_TDTAIL_PTR_MASK));
     
    225185}
    226186/*----------------------------------------------------------------------------*/
    227 /** Starts execution of the TD list
    228  *
    229  * @param[in] instance Batch structure to use
    230  */
    231187void batch_commit(usb_transfer_batch_t *instance)
    232188{
     
    237193}
    238194/*----------------------------------------------------------------------------*/
    239 /** Prepares control write transfer.
    240  *
    241  * @param[in] instance Batch structure to use.
    242  *
    243  * Uses generic control transfer using direction OUT(data stage) and
    244  * IN(status stage).
    245  */
    246195void batch_control_write(usb_transfer_batch_t *instance)
    247196{
     
    254203}
    255204/*----------------------------------------------------------------------------*/
    256 /** Prepares control read transfer.
    257  *
    258  * @param[in] instance Batch structure to use.
    259  *
    260  * Uses generic control transfer using direction IN(data stage) and
    261  * OUT(status stage).
    262  */
    263205void batch_control_read(usb_transfer_batch_t *instance)
    264206{
     
    269211}
    270212/*----------------------------------------------------------------------------*/
    271 /** Prepare interrupt in transfer.
    272  *
    273  * @param[in] instance Batch structure to use.
    274  *
    275  * Data transfer.
    276  */
    277213void batch_interrupt_in(usb_transfer_batch_t *instance)
    278214{
     
    283219}
    284220/*----------------------------------------------------------------------------*/
    285 /** Prepare interrupt out transfer.
    286  *
    287  * @param[in] instance Batch structure to use.
    288  *
    289  * Data transfer.
    290  */
    291221void batch_interrupt_out(usb_transfer_batch_t *instance)
    292222{
     
    299229}
    300230/*----------------------------------------------------------------------------*/
    301 /** Prepare bulk in transfer.
    302  *
    303  * @param[in] instance Batch structure to use.
    304  *
    305  * Data transfer.
    306  */
    307231void batch_bulk_in(usb_transfer_batch_t *instance)
    308232{
     
    313237}
    314238/*----------------------------------------------------------------------------*/
    315 /** Prepare bulk out transfer.
    316  *
    317  * @param[in] instance Batch structure to use.
    318  *
    319  * Data transfer.
    320  */
    321239void batch_bulk_out(usb_transfer_batch_t *instance)
    322240{
     
    329247}
    330248/*----------------------------------------------------------------------------*/
    331 /** Prepare generic control transfer
    332  *
    333  * @param[in] instance Batch structure to use.
    334  * @param[in] data_dir Direction to use for data stage.
    335  * @param[in] status_dir Direction to use for status stage.
    336  *
    337  * Setup stage with toggle 0 and direction BOTH(SETUP_PID)
    338  * Data stage with alternating toggle and direction supplied by parameter.
    339  * Status stage with toggle 1 and direction supplied by parameter.
    340  */
     249ed_t * batch_ed(usb_transfer_batch_t *instance)
     250{
     251        assert(instance);
     252        ohci_transfer_batch_t *data = instance->private_data;
     253        assert(data);
     254        return data->ed;
     255}
     256/*----------------------------------------------------------------------------*/
    341257void batch_control(usb_transfer_batch_t *instance,
    342258    usb_direction_t data_dir, usb_direction_t status_dir)
     
    387303}
    388304/*----------------------------------------------------------------------------*/
    389 /** Prepare generic data transfer
    390  *
    391  * @param[in] instance Batch structure to use.
    392  *
    393  * Direction is supplied by the associated ep and toggle is maintained by the
    394  * OHCI hw in ED.
    395  */
    396305void batch_data(usb_transfer_batch_t *instance)
    397306{
Note: See TracChangeset for help on using the changeset viewer.