Changeset e2976bb in mainline


Ignore:
Timestamp:
2011-08-25T11:34:19Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f0e510
Parents:
27873be
Message:

OHCI: Begin move to new hcd arch, plug in batch init hook.

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

Legend:

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

    r27873be re2976bb  
    6666 * @param[in] ohci_batch Instance to destroy.
    6767 */
    68 static void ohci_transfer_batch_dispose(void *ohci_batch)
     68static void ohci_batch_dispose(void *ohci_batch)
    6969{
    7070        ohci_transfer_batch_t *instance = ohci_batch;
     
    8383}
    8484/*----------------------------------------------------------------------------*/
     85int batch_init_ohci(usb_transfer_batch_t *batch)
     86{
     87        assert(batch);
     88#define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
     89        if (ptr == NULL) { \
     90                usb_log_error(message); \
     91                if (data) { \
     92                        ohci_batch_dispose(data); \
     93                } \
     94                return ENOMEM; \
     95        } else (void)0
     96
     97        const hcd_endpoint_t *hcd_ep = hcd_endpoint_get(batch->ep);
     98        assert(hcd_ep);
     99
     100        ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1);
     101        CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n");
     102
     103        data->td_count = ((batch->buffer_size + OHCI_TD_MAX_TRANSFER - 1)
     104            / OHCI_TD_MAX_TRANSFER);
     105        /* Control transfer need Setup and Status stage */
     106        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
     107                data->td_count += 2;
     108        }
     109
     110        /* We need an extra place for TD that is currently assigned to hcd_ep*/
     111        data->tds = calloc(sizeof(td_t*), data->td_count + 1);
     112        CHECK_NULL_DISPOSE_RETURN(data->tds,
     113            "Failed to allocate transfer descriptors.\n");
     114
     115        /* Add TD left over by the previous transfer */
     116        data->tds[0] = hcd_ep->td;
     117        data->leave_td = 0;
     118        unsigned i = 1;
     119        for (; i <= data->td_count; ++i) {
     120                data->tds[i] = malloc32(sizeof(td_t));
     121                CHECK_NULL_DISPOSE_RETURN(data->tds[i],
     122                    "Failed to allocate TD %d.\n", i );
     123        }
     124
     125        data->ed = hcd_ep->ed;
     126        batch->private_data = data;
     127        batch->private_data_dtor = ohci_batch_dispose;
     128
     129        /* NOTE: OHCI is capable of handling buffer that crosses page boundaries
     130         * it is, however, not capable of handling buffer that occupies more
     131         * than two pages (the first page is computed using start pointer, the
     132         * other using the end pointer) */
     133        if (batch->setup_size + batch->buffer_size > 0) {
     134                data->device_buffer =
     135                    malloc32(batch->setup_size + batch->buffer_size);
     136                CHECK_NULL_DISPOSE_RETURN(data->device_buffer,
     137                    "Failed to allocate device accessible buffer.\n");
     138                memcpy(data->device_buffer, batch->setup_buffer,
     139                    batch->setup_size);
     140                batch->data_buffer = data->device_buffer + batch->setup_size;
     141        }
     142
     143        return EOK;
     144#undef CHECK_NULL_DISPOSE_RETURN
     145}
     146/*----------------------------------------------------------------------------*/
    85147/** Allocate memory initialize internal structures
    86148 *
     
    119181        usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size,
    120182            NULL, setup_size, func_in, func_out, arg, fun, NULL,
    121             ohci_transfer_batch_dispose);
     183            ohci_batch_dispose);
    122184
    123185        const hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);
  • uspace/drv/bus/usb/ohci/batch.h

    r27873be re2976bb  
    4848    void *arg);
    4949
    50 bool batch_is_complete(usb_transfer_batch_t *instance);
     50int batch_init_ohci(usb_transfer_batch_t *batch);
     51
     52bool batch_is_complete(usb_transfer_batch_t *batch);
    5153
    5254void batch_commit(usb_transfer_batch_t *instance);
  • uspace/drv/bus/usb/ohci/hc.c

    r27873be re2976bb  
    193193        CHECK_RET_RETURN(ret, "Failed to initialize endpoint manager: %s.\n",
    194194            str_error(ret));
     195
     196        ret = hcd_init(&instance->generic, BANDWIDTH_AVAILABLE_USB11);
     197        instance->generic.schedule = NULL;
     198        instance->generic.batch_init_hook = batch_init_ohci;
     199        instance->generic.ep_add_hook = NULL;
    195200
    196201        ret = hc_init_memory(instance);
  • uspace/drv/bus/usb/ohci/hc.h

    r27873be re2976bb  
    4343#include <usb/host/device_keeper.h>
    4444#include <usb/host/usb_endpoint_manager.h>
    45 #include <usbhc_iface.h>
     45#include <usb/host/hcd.h>
    4646
    4747#include "batch.h"
     
    5757        /** USB bus driver, endpoints */
    5858        usb_endpoint_manager_t ep_manager;
     59
     60        /** Generic USB hc driver */
     61        hcd_t generic;
    5962
    6063        /** Memory mapped I/O registers area */
Note: See TracChangeset for help on using the changeset viewer.