Changeset 2cc6e97 in mainline for uspace/drv/ohci/batch.c


Ignore:
Timestamp:
2011-04-12T14:07:02Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3d932af6
Parents:
910ca3f
Message:

Move more functionality to libUSB usb_transfer_batch_t

UHCI uses one device accessible buffer for both structures and data

File:
1 edited

Legend:

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

    r910ca3f r2cc6e97  
    4343#include "hw_struct/transfer_descriptor.h"
    4444
    45 typedef struct ohci_batch {
     45typedef struct ohci_transfer_batch {
    4646        ed_t *ed;
    4747        td_t *tds;
    4848        size_t td_count;
    49 } ohci_batch_t;
     49} ohci_transfer_batch_t;
     50
     51static void ohci_transfer_batch_dispose(void *ohci_batch)
     52{
     53        //TODO: add buffer disposal
     54        ohci_transfer_batch_t *instance = ohci_batch;
     55        assert(instance);
     56        free32(instance->ed);
     57        free32(instance->tds);
     58}
    5059
    5160static void batch_control(usb_transfer_batch_t *instance,
    5261    usb_direction_t data_dir, usb_direction_t status_dir);
    5362static void batch_data(usb_transfer_batch_t *instance);
    54 static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
    55 static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
    5663
    5764#define DEFAULT_ERROR_COUNT 3
     
    6572                usb_log_error(message); \
    6673                if (instance) { \
    67                         batch_dispose(instance); \
     74                        usb_transfer_batch_dispose(instance); \
    6875                } \
    6976                return NULL; \
     
    7481            "Failed to allocate batch instance.\n");
    7582        usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size,
    76             NULL, setup_size, func_in, func_out, arg, fun, NULL);
    77 
    78         ohci_batch_t *data = malloc(sizeof(ohci_batch_t));
     83            NULL, setup_size, func_in, func_out, arg, fun, NULL,
     84            ohci_transfer_batch_dispose);
     85
     86        ohci_transfer_batch_t *data = malloc(sizeof(ohci_transfer_batch_t));
    7987        CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n");
    80         bzero(data, sizeof(ohci_batch_t));
     88        bzero(data, sizeof(ohci_transfer_batch_t));
    8189        instance->private_data = data;
    8290
     
    113121}
    114122/*----------------------------------------------------------------------------*/
    115 void batch_dispose(usb_transfer_batch_t *instance)
    116 {
    117         assert(instance);
    118         ohci_batch_t *data = instance->private_data;
    119         assert(data);
    120         free32(data->ed);
    121         free32(data->tds);
    122         free32(instance->setup_buffer);
    123         free32(instance->data_buffer);
    124         free(data);
    125         free(instance);
    126 }
    127 /*----------------------------------------------------------------------------*/
    128123bool batch_is_complete(usb_transfer_batch_t *instance)
    129124{
    130125        assert(instance);
    131         ohci_batch_t *data = instance->private_data;
     126        ohci_transfer_batch_t *data = instance->private_data;
    132127        assert(data);
    133128        size_t tds = data->td_count - 1;
     
    163158        /* We are data out, we are supposed to provide data */
    164159        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    165         instance->next_step = batch_call_out_and_dispose;
     160        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    166161        batch_control(instance, USB_DIRECTION_OUT, USB_DIRECTION_IN);
    167162        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
     
    171166{
    172167        assert(instance);
    173         instance->next_step = batch_call_in_and_dispose;
     168        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    174169        batch_control(instance, USB_DIRECTION_IN, USB_DIRECTION_OUT);
    175170        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
     
    179174{
    180175        assert(instance);
    181         instance->next_step = batch_call_in_and_dispose;
     176        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    182177        batch_data(instance);
    183178        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
     
    189184        /* We are data out, we are supposed to provide data */
    190185        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    191         instance->next_step = batch_call_out_and_dispose;
     186        instance->next_step = usb_transfer_batch_call_out_and_dispose;
    192187        batch_data(instance);
    193188        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
     
    197192{
    198193        assert(instance);
    199         instance->next_step = batch_call_in_and_dispose;
     194        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    200195        batch_data(instance);
    201196        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    205200{
    206201        assert(instance);
    207         instance->next_step = batch_call_in_and_dispose;
     202        instance->next_step = usb_transfer_batch_call_in_and_dispose;
    208203        batch_data(instance);
    209204        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    213208{
    214209        assert(instance);
    215         ohci_batch_t *data = instance->private_data;
     210        ohci_transfer_batch_t *data = instance->private_data;
    216211        assert(data);
    217212        return data->ed;
     
    222217{
    223218        assert(instance);
    224         ohci_batch_t *data = instance->private_data;
     219        ohci_transfer_batch_t *data = instance->private_data;
    225220        assert(data);
    226221        ed_init(data->ed, instance->ep);
     
    270265{
    271266        assert(instance);
    272         ohci_batch_t *data = instance->private_data;
     267        ohci_transfer_batch_t *data = instance->private_data;
    273268        assert(data);
    274269        ed_init(data->ed, instance->ep);
     
    299294        }
    300295}
    301 /*----------------------------------------------------------------------------*/
    302 /** Helper function calls callback and correctly disposes of batch structure.
    303  *
    304  * @param[in] instance Batch structure to use.
    305  */
    306 void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
    307 {
    308         assert(instance);
    309         usb_transfer_batch_call_in(instance);
    310         batch_dispose(instance);
    311 }
    312 /*----------------------------------------------------------------------------*/
    313 /** Helper function calls callback and correctly disposes of batch structure.
    314  *
    315  * @param[in] instance Batch structure to use.
    316  */
    317 void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
    318 {
    319         assert(instance);
    320         usb_transfer_batch_call_out(instance);
    321         batch_dispose(instance);
    322 }
    323296/**
    324297 * @}
Note: See TracChangeset for help on using the changeset viewer.