Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 9a6fde4 in mainline


Ignore:
Timestamp:
2011-04-13T13:56:51Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
7013b14
Parents:
592369ae
Message:

Batch uses static endpoint descriptors

Location:
uspace/drv/ohci
Files:
4 edited

Legend:

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

    r592369ae r9a6fde4  
    3939
    4040#include "batch.h"
     41#include "hcd_endpoint.h"
    4142#include "utils/malloc32.h"
    4243#include "hw_struct/endpoint_descriptor.h"
     
    4546typedef struct ohci_transfer_batch {
    4647        ed_t *ed;
    47         td_t *tds;
     48        td_t **tds;
    4849        size_t td_count;
     50        size_t leave_td;
     51        char *device_buffer;
    4952} ohci_transfer_batch_t;
    5053
    5154static void ohci_transfer_batch_dispose(void *ohci_batch)
    5255{
    53         //TODO: add buffer disposal
    5456        ohci_transfer_batch_t *instance = ohci_batch;
    55         assert(instance);
    56         free32(instance->ed);
    57         free32(instance->tds);
    58 }
    59 
     57        if (!instance)
     58                return;
     59        free32(instance->device_buffer);
     60        unsigned i = 0;
     61        if (instance->tds) {
     62                for (; i< instance->td_count; ++i) {
     63                        if (i != instance->leave_td)
     64                                free32(instance->tds[i]);
     65                }
     66                free(instance->tds);
     67        }
     68        free(instance);
     69}
     70/*----------------------------------------------------------------------------*/
    6071static void batch_control(usb_transfer_batch_t *instance,
    6172    usb_direction_t data_dir, usb_direction_t status_dir);
    6273static void batch_data(usb_transfer_batch_t *instance);
    63 
    64 #define DEFAULT_ERROR_COUNT 3
     74/*----------------------------------------------------------------------------*/
    6575usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
    6676    char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
     
    8494            ohci_transfer_batch_dispose);
    8595
    86         ohci_transfer_batch_t *data = malloc(sizeof(ohci_transfer_batch_t));
     96        hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);
     97        assert(hcd_ep);
     98
     99        ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1);
    87100        CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n");
    88         bzero(data, sizeof(ohci_transfer_batch_t));
    89101        instance->private_data = data;
    90102
    91         /* we needs + 1 transfer descriptor as the last one won't be executed */
    92         data->td_count = 1 +
     103        data->td_count =
    93104            ((buffer_size + OHCI_TD_MAX_TRANSFER - 1) / OHCI_TD_MAX_TRANSFER);
    94105        if (ep->transfer_type == USB_TRANSFER_CONTROL) {
     
    96107        }
    97108
    98         data->tds = malloc32(sizeof(td_t) * data->td_count);
     109        /* we need one extra place for td that is currently assigned to hcd_ep*/
     110        data->tds = calloc(sizeof(td_t*), data->td_count + 1);
    99111        CHECK_NULL_DISPOSE_RETURN(data->tds,
    100112            "Failed to allocate transfer descriptors.\n");
    101         bzero(data->tds, sizeof(td_t) * data->td_count);
    102 
    103         data->ed = malloc32(sizeof(ed_t));
    104         CHECK_NULL_DISPOSE_RETURN(data->ed,
    105             "Failed to allocate endpoint descriptor.\n");
    106 
    107         if (buffer_size > 0) {
    108                 instance->data_buffer = malloc32(buffer_size);
    109                 CHECK_NULL_DISPOSE_RETURN(instance->data_buffer,
     113
     114        data->tds[0] = hcd_ep->td;
     115        data->leave_td = 0;
     116        unsigned i = 1;
     117        for (; i <= data->td_count; ++i) {
     118                data->tds[i] = malloc32(sizeof(td_t));
     119                CHECK_NULL_DISPOSE_RETURN(data->tds[i],
     120                    "Failed to allocate TD %d.\n", i );
     121        }
     122
     123        data->ed = hcd_ep->ed;
     124
     125        if (setup_size + buffer_size > 0) {
     126                data->device_buffer = malloc32(setup_size + buffer_size);
     127                CHECK_NULL_DISPOSE_RETURN(data->device_buffer,
    110128                    "Failed to allocate device accessible buffer.\n");
    111         }
    112 
    113         if (setup_size > 0) {
    114                 instance->setup_buffer = malloc32(setup_size);
    115                 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
    116                     "Failed to allocate device accessible setup buffer.\n");
     129                instance->setup_buffer = data->device_buffer;
     130                instance->data_buffer = data->device_buffer + setup_size;
    117131                memcpy(instance->setup_buffer, setup_buffer, setup_size);
    118132        }
     
    126140        ohci_transfer_batch_t *data = instance->private_data;
    127141        assert(data);
    128         size_t tds = data->td_count - 1;
     142        size_t tds = data->td_count;
    129143        usb_log_debug("Batch(%p) checking %d td(s) for completion.\n",
    130144            instance, tds);
     
    134148        size_t i = 0;
    135149        for (; i < tds; ++i) {
     150                assert(data->tds[i] != NULL);
    136151                usb_log_debug("TD %d: %x:%x:%x:%x.\n", i,
    137                     data->tds[i].status, data->tds[i].cbp, data->tds[i].next,
    138                     data->tds[i].be);
    139                 if (!td_is_finished(&data->tds[i])) {
     152                    data->tds[i]->status, data->tds[i]->cbp, data->tds[i]->next,
     153                    data->tds[i]->be);
     154                if (!td_is_finished(data->tds[i])) {
    140155                        return false;
    141156                }
    142                 instance->error = td_error(&data->tds[i]);
     157                instance->error = td_error(data->tds[i]);
    143158                /* FIXME: calculate real transfered size */
    144159                instance->transfered_size = instance->buffer_size;
    145160                if (instance->error != EOK) {
    146161                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    147                             instance, i, data->tds[i].status);
    148                         return true;
    149 //                      endpoint_toggle_set(instance->ep,
     162                            instance, i, data->tds[i]->status);
     163                        break;
    150164                }
    151165        }
     166        data->leave_td = ++i;
     167        assert(data->leave_td <= data->td_count);
    152168        return true;
    153169}
     
    220236        assert(data);
    221237        ed_init(data->ed, instance->ep);
    222         ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
     238//      ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
    223239        usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed,
    224240            data->ed->status, data->ed->td_tail, data->ed->td_head,
     
    226242        int toggle = 0;
    227243        /* setup stage */
    228         td_init(&data->tds[0], USB_DIRECTION_BOTH, instance->setup_buffer,
     244        td_init(data->tds[0], USB_DIRECTION_BOTH, instance->setup_buffer,
    229245                instance->setup_size, toggle);
    230         td_set_next(&data->tds[0], &data->tds[1]);
    231         usb_log_debug("Created SETUP TD: %x:%x:%x:%x.\n", data->tds[0].status,
    232             data->tds[0].cbp, data->tds[0].next, data->tds[0].be);
     246        td_set_next(data->tds[0], data->tds[1]);
     247        usb_log_debug("Created SETUP TD: %x:%x:%x:%x.\n", data->tds[0]->status,
     248            data->tds[0]->cbp, data->tds[0]->next, data->tds[0]->be);
    233249
    234250        /* data stage */
     
    241257                toggle = 1 - toggle;
    242258
    243                 td_init(&data->tds[td_current], data_dir, buffer,
     259                td_init(data->tds[td_current], data_dir, buffer,
    244260                    transfer_size, toggle);
    245                 td_set_next(&data->tds[td_current], &data->tds[td_current + 1]);
     261                td_set_next(data->tds[td_current], data->tds[td_current + 1]);
    246262                usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
    247                     data->tds[td_current].status, data->tds[td_current].cbp,
    248                     data->tds[td_current].next, data->tds[td_current].be);
     263                    data->tds[td_current]->status, data->tds[td_current]->cbp,
     264                    data->tds[td_current]->next, data->tds[td_current]->be);
    249265
    250266                buffer += transfer_size;
    251267                remain_size -= transfer_size;
    252                 assert(td_current < data->td_count - 2);
     268                assert(td_current < data->td_count - 1);
    253269                ++td_current;
    254270        }
    255271
    256272        /* status stage */
    257         assert(td_current == data->td_count - 2);
    258         td_init(&data->tds[td_current], status_dir, NULL, 0, 1);
     273        assert(td_current == data->td_count - 1);
     274        td_init(data->tds[td_current], status_dir, NULL, 0, 1);
     275        td_set_next(data->tds[td_current], data->tds[td_current + 1]);
    259276        usb_log_debug("Created STATUS TD: %x:%x:%x:%x.\n",
    260             data->tds[td_current].status, data->tds[td_current].cbp,
    261             data->tds[td_current].next, data->tds[td_current].be);
     277            data->tds[td_current]->status, data->tds[td_current]->cbp,
     278            data->tds[td_current]->next, data->tds[td_current]->be);
    262279}
    263280/*----------------------------------------------------------------------------*/
     
    268285        assert(data);
    269286        ed_init(data->ed, instance->ep);
    270         ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
     287//      ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
    271288        usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed,
    272289            data->ed->status, data->ed->td_tail, data->ed->td_head,
     
    281298                    OHCI_TD_MAX_TRANSFER : remain_size;
    282299
    283                 td_init(&data->tds[td_current], instance->ep->direction,
     300                td_init(data->tds[td_current], instance->ep->direction,
    284301                    buffer, transfer_size, -1);
    285                 td_set_next(&data->tds[td_current], &data->tds[td_current + 1]);
     302                td_set_next(data->tds[td_current], data->tds[td_current + 1]);
    286303                usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
    287                     data->tds[td_current].status, data->tds[td_current].cbp,
    288                     data->tds[td_current].next, data->tds[td_current].be);
     304                    data->tds[td_current]->status, data->tds[td_current]->cbp,
     305                    data->tds[td_current]->next, data->tds[td_current]->be);
    289306
    290307                buffer += transfer_size;
  • uspace/drv/ohci/hc.c

    r592369ae r9a6fde4  
    6868            &instance->manager, hub_address, hub_fun->handle);
    6969
    70         ret = usb_endpoint_manager_add_ep(&instance->ep_manager,
    71             hub_address, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
    72             USB_SPEED_FULL, 64, 0);
     70        ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
     71            USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0);
    7372        if (ret != EOK) {
    7473                usb_log_error("Failed to add OHCI rh endpoint 0.\n");
  • uspace/drv/ohci/hcd_endpoint.c

    r592369ae r9a6fde4  
    5656
    5757        ed_init(hcd_ep->ed, ep);
    58         ed_add_tds(hcd_ep->ed, hcd_ep->td, hcd_ep->td);
     58        ed_set_td(hcd_ep->ed, hcd_ep->td);
    5959        endpoint_set_hc_data(ep, hcd_ep, NULL, NULL);
    6060
  • uspace/drv/ohci/hw_struct/endpoint_descriptor.h

    r592369ae r9a6fde4  
    8181void ed_init(ed_t *instance, endpoint_t *ep);
    8282
    83 static inline void ed_add_tds(ed_t *instance, td_t *head, td_t *tail)
     83static inline void ed_set_td(ed_t *instance, td_t *td)
    8484{
    8585        assert(instance);
     86        uintptr_t pa = addr_to_phys(td);
    8687        instance->td_head =
    87             ((addr_to_phys(head) & ED_TDHEAD_PTR_MASK)
     88            ((pa & ED_TDHEAD_PTR_MASK)
    8889            | (instance->td_head & ~ED_TDHEAD_PTR_MASK));
    89         instance->td_tail = addr_to_phys(tail) & ED_TDTAIL_PTR_MASK;
     90        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
     91}
     92
     93static inline void ed_set_end_td(ed_t *instance, td_t *td)
     94{
     95        assert(instance);
     96        uintptr_t pa = addr_to_phys(td);
     97        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
    9098}
    9199
Note: See TracChangeset for help on using the changeset viewer.