Changeset 5fe0a69 in mainline


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.

Location:
uspace/drv/bus/usb/uhci
Files:
5 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/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/uhci/batch.h

    rdf8f3fa r5fe0a69  
    4646    void *arg);
    4747
     48void * uhci_transfer_batch_create(usb_transfer_batch_t *batch);
     49void uhci_transfer_batch_dispose(void *uhci_batch);
     50
    4851void batch_dispose(usb_transfer_batch_t *instance);
    4952
  • uspace/drv/bus/usb/uhci/hc.c

    rdf8f3fa r5fe0a69  
    4141
    4242#include "hc.h"
     43#include "batch.h"
    4344
    4445#define UHCI_INTR_ALLOW_INTERRUPTS \
     
    4647#define UHCI_STATUS_USED_INTERRUPTS \
    4748    (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)
     49
     50static int schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
     51{
     52        assert(hcd);
     53        return hc_schedule(hcd->private_data, batch);
     54}
    4855
    4956static const irq_cmd_t uhci_irq_commands[] =
     
    131138        usb_log_debug(
    132139            "Device registers at %p (%zuB) accessible.\n", io, reg_size);
     140        hcd_init(&instance->generic, BANDWIDTH_AVAILABLE_USB11);
     141        instance->generic.private_data = instance;
     142        instance->generic.schedule = schedule;
     143        instance->generic.batch_private_ctor = uhci_transfer_batch_create;
     144        instance->generic.batch_private_dtor = uhci_transfer_batch_dispose;
    133145
    134146        ret = hc_init_mem_structures(instance);
  • uspace/drv/bus/usb/uhci/hc.h

    rdf8f3fa r5fe0a69  
    4242#include <usb/host/usb_endpoint_manager.h>
    4343#include <usb/host/batch.h>
     44#include <usb/host/hcd.h>
    4445
    4546#include "transfer_list.h"
     
    9495/** Main UHCI driver structure */
    9596typedef struct hc {
     97        hcd_t generic;
    9698        /** USB bus driver, devices and addresses */
    9799        usb_device_keeper_t manager;
  • uspace/drv/bus/usb/uhci/uhci.c

    rdf8f3fa r5fe0a69  
    8787/** Operations supported by the HC driver */
    8888static ddf_dev_ops_t hc_ops = {
    89         .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
     89        .interfaces[USBHC_DEV_IFACE] = &hcd_iface, /* see iface.h/c */
    9090};
    9191/*----------------------------------------------------------------------------*/
     
    100100{
    101101        assert(fun);
    102         usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager;
     102        usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.generic.dev_manager;
    103103        usb_address_t addr = usb_device_keeper_find(manager, handle);
    104104
     
    202202        CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n");
    203203        instance->hc_fun->ops = &hc_ops;
    204         instance->hc_fun->driver_data = &instance->hc;
     204        instance->hc_fun->driver_data = &instance->hc.generic;
    205205
    206206        instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
Note: See TracChangeset for help on using the changeset viewer.