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

Changeset 620c710 in mainline


Ignore:
Timestamp:
2011-08-25T14:21:57Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
961c29e8
Parents:
e20eaed
Message:

libushost: promote endpoint data dtor to destruction hook

ohci: use new usb c driver architecture

Location:
uspace
Files:
7 edited

Legend:

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

    re20eaed r620c710  
    6161static int hc_init_memory(hc_t *instance);
    6262static int interrupt_emulator(hc_t *instance);
    63 
     63/*----------------------------------------------------------------------------*/
     64static int schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
     65{
     66        assert(hcd);
     67        return hc_schedule(hcd->private_data, batch);
     68}
    6469/*----------------------------------------------------------------------------*/
    6570/** Get number of commands used in IRQ code.
     
    163168}
    164169/*----------------------------------------------------------------------------*/
    165 static int schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    166 {
    167         assert(hcd);
    168         return hc_schedule(hcd->private_data, batch);
    169 }
    170 /*----------------------------------------------------------------------------*/
    171170/** Initialize OHCI hc driver structure
    172171 *
     
    203202        instance->generic.private_data = instance;
    204203        instance->generic.schedule = schedule;
    205         instance->generic.ep_add_hook = ohci_endpoint_assign;
     204        instance->generic.ep_add_hook = ohci_endpoint_init;
    206205
    207206        ret = hc_init_memory(instance);
     
    224223
    225224        return EOK;
     225}
     226/*----------------------------------------------------------------------------*/
     227void hc_enqueue_endpoint(hc_t *instance, endpoint_t *ep)
     228{
     229        endpoint_list_t *list = &instance->lists[ep->transfer_type];
     230        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
     231        /* Enqueue ep */
     232        switch (ep->transfer_type) {
     233        case USB_TRANSFER_CONTROL:
     234                instance->registers->control &= ~C_CLE;
     235                endpoint_list_add_ep(list, ohci_ep);
     236                instance->registers->control_current = 0;
     237                instance->registers->control |= C_CLE;
     238                break;
     239        case USB_TRANSFER_BULK:
     240                instance->registers->control &= ~C_BLE;
     241                endpoint_list_add_ep(
     242                    &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
     243                instance->registers->control |= C_BLE;
     244                break;
     245        case USB_TRANSFER_ISOCHRONOUS:
     246        case USB_TRANSFER_INTERRUPT:
     247                instance->registers->control &= (~C_PLE & ~C_IE);
     248                endpoint_list_add_ep(
     249                    &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
     250                instance->registers->control |= C_PLE | C_IE;
     251                break;
     252        }
     253}
     254/*----------------------------------------------------------------------------*/
     255void hc_dequeue_endpoint(hc_t *instance, endpoint_t *ep)
     256{
     257        /* Dequeue ep */
     258        endpoint_list_t *list = &instance->lists[ep->transfer_type];
     259        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
     260        switch (ep->transfer_type) {
     261        case USB_TRANSFER_CONTROL:
     262                instance->registers->control &= ~C_CLE;
     263                endpoint_list_remove_ep(list, ohci_ep);
     264                instance->registers->control_current = 0;
     265                instance->registers->control |= C_CLE;
     266                break;
     267        case USB_TRANSFER_BULK:
     268                instance->registers->control &= ~C_BLE;
     269                endpoint_list_remove_ep(list, ohci_ep);
     270                instance->registers->control |= C_BLE;
     271                break;
     272        case USB_TRANSFER_ISOCHRONOUS:
     273        case USB_TRANSFER_INTERRUPT:
     274                instance->registers->control &= (~C_PLE & ~C_IE);
     275                endpoint_list_remove_ep(list, ohci_ep);
     276                instance->registers->control |= C_PLE | C_IE;
     277                break;
     278        default:
     279                break;
     280        }
    226281}
    227282/*----------------------------------------------------------------------------*/
     
    249304                return ENOMEM;
    250305
    251         int ret = ohci_endpoint_assign(&instance->generic, ep);
     306        int ret = ohci_endpoint_init(&instance->generic, ep);
    252307        if (ret != EOK) {
    253308                endpoint_destroy(ep);
     
    260315                return ret;
    261316        }
    262 
    263         /* Enqueue ep */
    264         switch (ep->transfer_type) {
    265         case USB_TRANSFER_CONTROL:
    266                 instance->registers->control &= ~C_CLE;
    267                 endpoint_list_add_ep(
    268                     &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
    269                 instance->registers->control_current = 0;
    270                 instance->registers->control |= C_CLE;
    271                 break;
    272         case USB_TRANSFER_BULK:
    273                 instance->registers->control &= ~C_BLE;
    274                 endpoint_list_add_ep(
    275                     &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
    276                 instance->registers->control |= C_BLE;
    277                 break;
    278         case USB_TRANSFER_ISOCHRONOUS:
    279         case USB_TRANSFER_INTERRUPT:
    280                 instance->registers->control &= (~C_PLE & ~C_IE);
    281                 endpoint_list_add_ep(
    282                     &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
    283                 instance->registers->control |= C_PLE | C_IE;
    284                 break;
    285         }
     317        hc_enqueue_endpoint(instance, ep);
    286318
    287319        return EOK;
     
    311343        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
    312344        if (ohci_ep) {
    313                 /* Dequeue ep */
    314                 switch (ep->transfer_type) {
    315                 case USB_TRANSFER_CONTROL:
    316                         instance->registers->control &= ~C_CLE;
    317                         endpoint_list_remove_ep(
    318                             &instance->lists[ep->transfer_type], ohci_ep);
    319                         instance->registers->control_current = 0;
    320                         instance->registers->control |= C_CLE;
    321                         break;
    322                 case USB_TRANSFER_BULK:
    323                         instance->registers->control &= ~C_BLE;
    324                         endpoint_list_remove_ep(
    325                             &instance->lists[ep->transfer_type], ohci_ep);
    326                         instance->registers->control |= C_BLE;
    327                         break;
    328                 case USB_TRANSFER_ISOCHRONOUS:
    329                 case USB_TRANSFER_INTERRUPT:
    330                         instance->registers->control &= (~C_PLE & ~C_IE);
    331                         endpoint_list_remove_ep(
    332                             &instance->lists[ep->transfer_type], ohci_ep);
    333                         instance->registers->control |= C_PLE | C_IE;
    334                         break;
    335                 default:
    336                         break;
    337                 }
     345                hc_dequeue_endpoint(instance, ep);
    338346        } else {
    339347                usb_log_warning("Endpoint without hcd equivalent structure.\n");
  • uspace/drv/bus/usb/ohci/hc.h

    re20eaed r620c710  
    8484int hc_get_irq_commands(
    8585    irq_cmd_t cmds[], size_t cmd_size, uintptr_t regs, size_t reg_size);
     86int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    8687int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
    87 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    8888
    8989/** Safely dispose host controller internal structures
     
    9393static inline void hc_fini(hc_t *instance)
    9494        { /* TODO: implement*/ };
     95
     96void hc_enqueue_endpoint(hc_t *instance, endpoint_t *ep);
     97void hc_dequeue_endpoint(hc_t *instance, endpoint_t *ep);
    9598
    9699int hc_add_endpoint(hc_t *instance, usb_address_t address, usb_endpoint_t ep,
  • uspace/drv/bus/usb/ohci/ohci.c

    re20eaed r620c710  
    8989{
    9090        assert(fun);
    91         usb_device_keeper_t *manager = &dev_to_ohci(fun->dev)->hc.manager;
     91        usb_device_keeper_t *manager = &dev_to_ohci(fun->dev)->hc.generic.dev_manager;
    9292
    9393        usb_address_t addr = usb_device_keeper_find(manager, handle);
     
    129129/** Standard USB HC options (HC interface) */
    130130static ddf_dev_ops_t hc_ops = {
    131         .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
     131        .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
    132132};
    133133/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/ohci/ohci_endpoint.c

    re20eaed r620c710  
    3434#include "utils/malloc32.h"
    3535#include "ohci_endpoint.h"
     36#include "hc.h"
    3637
    3738/** Callback to set toggle on ED.
     
    6566 * @param[in] hcd_ep endpoint structure
    6667 */
    67 static void ohci_ep_destroy(void *ohci_ep)
     68static void ohci_endpoint_fini(endpoint_t *ep)
    6869{
    69         if (ohci_ep) {
    70                 ohci_endpoint_t *instance = ohci_ep;
     70        ohci_endpoint_t *instance = ep->hc_data.data;
     71        hc_dequeue_endpoint(instance->hcd->private_data, ep);
     72        if (instance) {
    7173                free32(instance->ed);
    7274                free32(instance->td);
     
    8082 * @return pointer to a new hcd endpoint structure, NULL on failure.
    8183 */
    82 int ohci_endpoint_assign(hcd_t *hcd, endpoint_t *ep)
     84int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
    8385{
    8486        assert(ep);
     
    103105        ed_set_td(ohci_ep->ed, ohci_ep->td);
    104106        endpoint_set_hc_data(
    105             ep, ohci_ep, ohci_ep_destroy, ohci_ep_toggle_get, ohci_ep_toggle_set);
    106 
     107            ep, ohci_ep, ohci_endpoint_fini, ohci_ep_toggle_get, ohci_ep_toggle_set);
     108        ohci_ep->hcd = hcd;
     109        hc_enqueue_endpoint(hcd->private_data, ep);
    107110        return EOK;
    108111}
  • uspace/drv/bus/usb/ohci/ohci_endpoint.h

    re20eaed r620c710  
    5555} ohci_endpoint_t;
    5656
    57 int ohci_endpoint_assign(hcd_t *hcd, endpoint_t *ep);
     57int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep);
    5858
    5959/** Get and convert assigned ohci_endpoint_t structure
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    re20eaed r620c710  
    5454        fibril_condvar_t avail;
    5555        volatile bool active;
     56        void (*destroy_hook)(struct endpoint *);
    5657        struct {
    5758                void *data;
    58                 void (*data_dtor)(void*);
    5959                int (*toggle_get)(void *);
    6060                void (*toggle_set)(void *, int);
     
    6969
    7070void endpoint_set_hc_data(endpoint_t *instance,
    71     void *data, void (*data_dtor)(void *),
     71    void *data, void (*destroy_hook)(endpoint_t *),
    7272    int (*toggle_get)(void *), void (*toggle_set)(void *, int));
    7373
  • uspace/lib/usbhost/src/endpoint.c

    re20eaed r620c710  
    5353                instance->toggle = 0;
    5454                instance->active = false;
     55                instance->destroy_hook = NULL;
    5556                instance->hc_data.data = NULL;
    56                 instance->hc_data.data_dtor = NULL;
    5757                instance->hc_data.toggle_get = NULL;
    5858                instance->hc_data.toggle_set = NULL;
     
    6969        assert(!instance->active);
    7070        if (instance->hc_data.data) {
    71                 assert(instance->hc_data.data_dtor);
    72                 instance->hc_data.data_dtor(instance->hc_data.data);
     71                assert(instance->destroy_hook);
     72                instance->destroy_hook(instance);
    7373        }
    7474        free(instance);
     
    7676/*----------------------------------------------------------------------------*/
    7777void endpoint_set_hc_data(endpoint_t *instance,
    78     void *data, void (*data_dtor)(void *),
     78    void *data, void (*destroy_hook)(endpoint_t *),
    7979    int (*toggle_get)(void *), void (*toggle_set)(void *, int))
    8080{
    8181        assert(instance);
     82        instance->destroy_hook = destroy_hook;
    8283        instance->hc_data.data = data;
    83         instance->hc_data.data_dtor = data_dtor;
    8484        instance->hc_data.toggle_get = toggle_get;
    8585        instance->hc_data.toggle_set = toggle_set;
Note: See TracChangeset for help on using the changeset viewer.