Changeset 5fe0a69 in mainline for uspace/drv/bus/usb/uhci/batch.c


Ignore:
Timestamp:
2011-08-24T14:40:26Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3afb758
Parents:
df8f3fa
Message:

UHCI: Use new usb hc driver architecture.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/batch.c

    rdf8f3fa r5fe0a69  
    4545#define DEFAULT_ERROR_COUNT 3
    4646
     47static void batch_setup_control(usb_transfer_batch_t *batch)
     48{
     49        // TODO Find a better way to do this
     50        if (batch->setup_buffer[0] & (1 << 7))
     51                batch_control_read(batch);
     52        else
     53                batch_control_write(batch);
     54}
     55
     56void (*batch_setup[4][3])(usb_transfer_batch_t*) =
     57{
     58        { NULL, NULL, batch_setup_control },
     59        { NULL, NULL, NULL },
     60        { batch_bulk_in, batch_bulk_out, NULL },
     61        { batch_interrupt_in, batch_interrupt_out, NULL },
     62};
     63 // */
    4764/** UHCI specific data required for USB transfer */
    4865typedef struct uhci_transfer_batch {
     
    6885 * @param[in] uhci_batch Instance to destroy.
    6986 */
    70 static void uhci_transfer_batch_dispose(void *uhci_batch)
     87void uhci_transfer_batch_dispose(void *uhci_batch)
    7188{
    7289        uhci_transfer_batch_t *instance = uhci_batch;
     
    7491        free32(instance->device_buffer);
    7592        free(instance);
     93}
     94/*----------------------------------------------------------------------------*/
     95void * uhci_transfer_batch_create(usb_transfer_batch_t *batch)
     96{
     97#define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
     98        if (ptr == NULL) { \
     99                usb_log_error(message); \
     100                if (uhci_data) { \
     101                        uhci_transfer_batch_dispose(uhci_data); \
     102                } \
     103                return NULL; \
     104        } else (void)0
     105
     106        uhci_transfer_batch_t *uhci_data =
     107            calloc(1, sizeof(uhci_transfer_batch_t));
     108        CHECK_NULL_DISPOSE_RETURN(uhci_data,
     109            "Failed to allocate UHCI batch.\n");
     110
     111        uhci_data->td_count =
     112            (batch->buffer_size + batch->ep->max_packet_size - 1)
     113            / batch->ep->max_packet_size;
     114        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
     115                uhci_data->td_count += 2;
     116        }
     117
     118        assert((sizeof(td_t) % 16) == 0);
     119        const size_t total_size = (sizeof(td_t) * uhci_data->td_count)
     120            + sizeof(qh_t) + batch->setup_size + batch->buffer_size;
     121        uhci_data->device_buffer = malloc32(total_size);
     122        CHECK_NULL_DISPOSE_RETURN(uhci_data->device_buffer,
     123            "Failed to allocate UHCI buffer.\n");
     124        bzero(uhci_data->device_buffer, total_size);
     125
     126        uhci_data->tds = uhci_data->device_buffer;
     127        uhci_data->qh =
     128            (uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count));
     129
     130        qh_init(uhci_data->qh);
     131        qh_set_element_td(uhci_data->qh, uhci_data->tds);
     132
     133        void *setup =
     134            uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count)
     135            + sizeof(qh_t);
     136        /* Copy SETUP packet data to device buffer */
     137        memcpy(setup, batch->setup_buffer, batch->setup_size);
     138        /* Set generic data buffer pointer */
     139        batch->data_buffer = setup + batch->setup_size;
     140        batch->private_data = uhci_data;
     141        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT
     142            " memory structures ready.\n", batch,
     143            USB_TRANSFER_BATCH_ARGS(*batch));
     144        assert(batch_setup[batch->ep->transfer_type][batch->ep->direction]);
     145        batch_setup[batch->ep->transfer_type][batch->ep->direction](batch);
     146
     147        return uhci_data;
    76148}
    77149/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.