Changeset b5f813c in mainline


Ignore:
Timestamp:
2015-07-04T03:28:02Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
55346870
Parents:
2dbfe44
Message:

libusbhost,ehci,ohci,uhci,vhc: Pass ops structure instead of function pointers to intialization

Location:
uspace
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/ehci_endpoint.c

    r2dbfe44 rb5f813c  
    8080{
    8181        assert(ep);
     82        hc_t *hc = hcd_get_driver_data(hcd);
     83
    8284        ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
    8385        if (ehci_ep == NULL)
     
    9597        endpoint_set_hc_data(
    9698            ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
    97         hc_enqueue_endpoint(hcd->driver.data, ep);
     99        hc_enqueue_endpoint(hc, ep);
    98100        return EOK;
    99101}
     
    108110        assert(hcd);
    109111        assert(ep);
     112        hc_t *hc = hcd_get_driver_data(hcd);
     113
    110114        ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    111         hc_dequeue_endpoint(hcd->driver.data, ep);
     115        hc_dequeue_endpoint(hc, ep);
    112116        endpoint_clear_hc_data(ep);
    113117        usb_log_debug2("EP(%p): Destroying for %p", instance, ep);
  • uspace/drv/bus/usb/ehci/hc.c

    r2dbfe44 rb5f813c  
    273273{
    274274        assert(hcd);
    275         hc_t *instance = hcd->driver.data;
     275        hc_t *instance = hcd_get_driver_data(hcd);
    276276        assert(instance);
    277277        assert(status);
     
    294294{
    295295        assert(hcd);
    296         hc_t *instance = hcd->driver.data;
     296        hc_t *instance = hcd_get_driver_data(hcd);
    297297        assert(instance);
    298298
     
    325325{
    326326        assert(hcd);
    327         hc_t *instance = hcd->driver.data;
     327        hc_t *instance = hcd_get_driver_data(hcd);
    328328        status = EHCI_RD(status);
    329329        assert(instance);
  • uspace/drv/bus/usb/ehci/main.c

    r2dbfe44 rb5f813c  
    5050#define NAME "ehci"
    5151
     52static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
     53static void ehci_driver_fini(hcd_t *);
     54
     55static const ddf_hc_driver_t ehci_hc_driver = {
     56        .claim = disable_legacy,
     57        .hc_speed = USB_SPEED_HIGH,
     58        .irq_code_gen = ehci_hc_gen_irq_code,
     59        .init = ehci_driver_init,
     60        .fini = ehci_driver_fini,
     61        .name = "EHCI-PCI",
     62        .ops = {
     63                .schedule       = ehci_hc_schedule,
     64                .ep_add_hook    = ehci_endpoint_init,
     65                .ep_remove_hook = ehci_endpoint_fini,
     66                .irq_hook       = ehci_hc_interrupt,
     67                .status_hook    = ehci_hc_status,
     68        }
     69};
     70
     71
    5272static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
    5373{
    5474        assert(hcd);
    55         assert(hcd->driver.data == NULL);
     75        assert(hcd_get_driver_data(hcd) == NULL);
    5676
    5777        hc_t *instance = malloc(sizeof(hc_t));
     
    6181        const int ret = hc_init(instance, res, irq);
    6282        if (ret == EOK)
    63                 hcd_set_implementation(hcd, instance, ehci_hc_schedule,
    64                     ehci_endpoint_init, ehci_endpoint_fini, ehci_hc_interrupt,
    65                     ehci_hc_status);
     83                hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops);
    6684        return ret;
    6785}
     
    7088{
    7189        assert(hcd);
    72         if (hcd->driver.data)
    73                 hc_fini(hcd->driver.data);
     90        hc_t *hc = hcd_get_driver_data(hcd);
     91        if (hc)
     92                hc_fini(hc);
    7493
    75         free(hcd->driver.data);
    76         hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
     94        free(hc);
     95        hcd_set_implementation(hcd, NULL, NULL);
    7796}
    78 
    79 static int ehci_dev_add(ddf_dev_t *device);
    80 
    81 static const driver_ops_t ehci_driver_ops = {
    82         .dev_add = ehci_dev_add,
    83 };
    84 
    85 static const driver_t ehci_driver = {
    86         .name = NAME,
    87         .driver_ops = &ehci_driver_ops
    88 };
    89 
    90 
    91 static const ddf_hc_driver_t ehci_hc_driver = {
    92         .claim = disable_legacy,
    93         .hc_speed = USB_SPEED_HIGH,
    94         .irq_code_gen = ehci_hc_gen_irq_code,
    95         .init = ehci_driver_init,
    96         .fini = ehci_driver_fini,
    97         .name = "EHCI-PCI"
    98 };
    9997
    10098/** Initializes a new ddf driver instance of EHCI hcd.
     
    111109
    112110}
     111
     112
     113static const driver_ops_t ehci_driver_ops = {
     114        .dev_add = ehci_dev_add,
     115};
     116
     117static const driver_t ehci_driver = {
     118        .name = NAME,
     119        .driver_ops = &ehci_driver_ops
     120};
     121
    113122
    114123/** Initializes global driver structures (NONE).
  • uspace/drv/bus/usb/ohci/hc.c

    r2dbfe44 rb5f813c  
    271271        assert(hcd);
    272272        assert(status);
    273         hc_t *instance = hcd->driver.data;
     273        hc_t *instance = hcd_get_driver_data(hcd);
    274274        assert(instance);
    275275
     
    290290{
    291291        assert(hcd);
    292         hc_t *instance = hcd->driver.data;
     292        hc_t *instance = hcd_get_driver_data(hcd);
    293293        assert(instance);
    294294
     
    330330{
    331331        assert(hcd);
    332         hc_t *instance = hcd->driver.data;
     332        hc_t *instance = hcd_get_driver_data(hcd);
    333333        status = OHCI_RD(status);
    334334        assert(instance);
  • uspace/drv/bus/usb/ohci/main.c

    r2dbfe44 rb5f813c  
    4646
    4747#define NAME "ohci"
     48static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
     49static void ohci_driver_fini(hcd_t *);
     50
     51static const ddf_hc_driver_t ohci_hc_driver = {
     52        .hc_speed = USB_SPEED_FULL,
     53        .irq_code_gen = ohci_hc_gen_irq_code,
     54        .init = ohci_driver_init,
     55        .fini = ohci_driver_fini,
     56        .name = "OHCI",
     57        .ops = {
     58                .schedule       = ohci_hc_schedule,
     59                .ep_add_hook    = ohci_endpoint_init,
     60                .ep_remove_hook = ohci_endpoint_fini,
     61                .irq_hook       = ohci_hc_interrupt,
     62                .status_hook    = ohci_hc_status,
     63        },
     64};
     65
    4866
    4967static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
    5068{
    5169        assert(hcd);
    52         assert(hcd->driver.data == NULL);
     70        assert(hcd_get_driver_data(hcd) == NULL);
    5371
    5472        hc_t *instance = malloc(sizeof(hc_t));
     
    5876        const int ret = hc_init(instance, res, irq);
    5977        if (ret == EOK)
    60                 hcd_set_implementation(hcd, instance, ohci_hc_schedule,
    61                     ohci_endpoint_init, ohci_endpoint_fini, ohci_hc_interrupt,
    62                     ohci_hc_status);
     78                hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops);
    6379        return ret;
    6480}
     
    6783{
    6884        assert(hcd);
    69         if (hcd->driver.data)
    70                 hc_fini(hcd->driver.data);
     85        hc_t *hc = hcd_get_driver_data(hcd);
     86        if (hc)
     87                hc_fini(hc);
    7188
    72         free(hcd->driver.data);
    73         hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
     89        hcd_set_implementation(hcd, NULL, NULL);
     90        free(hc);
    7491}
    75 
    76 static const ddf_hc_driver_t ohci_hc_driver = {
    77         .hc_speed = USB_SPEED_FULL,
    78         .irq_code_gen = ohci_hc_gen_irq_code,
    79         .init = ohci_driver_init,
    80         .fini = ohci_driver_fini,
    81         .name = "OHCI"
    82 };
    8392
    8493/** Initializes a new ddf driver instance of OHCI hcd.
  • uspace/drv/bus/usb/ohci/ohci_endpoint.c

    r2dbfe44 rb5f813c  
    9595        endpoint_set_hc_data(
    9696            ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
    97         hc_enqueue_endpoint(hcd->driver.data, ep);
     97        hc_enqueue_endpoint(hcd_get_driver_data(hcd), ep);
    9898        return EOK;
    9999}
     
    109109        assert(ep);
    110110        ohci_endpoint_t *instance = ohci_endpoint_get(ep);
    111         hc_dequeue_endpoint(hcd->driver.data, ep);
     111        hc_dequeue_endpoint(hcd_get_driver_data(hcd), ep);
     112        endpoint_clear_hc_data(ep);
    112113        if (instance) {
    113114                free32(instance->ed);
     
    115116                free(instance);
    116117        }
    117         endpoint_clear_hc_data(ep);
    118118}
    119119/**
  • uspace/drv/bus/usb/uhci/hc.c

    r2dbfe44 rb5f813c  
    157157{
    158158        assert(hcd);
    159         hc_t *instance = hcd->driver.data;
     159        hc_t *instance = hcd_get_driver_data(hcd);
    160160        assert(instance);
    161161        /* Lower 2 bits are transaction error and transaction complete */
     
    412412        assert(hcd);
    413413        assert(status);
    414         hc_t *instance = hcd->driver.data;
     414        hc_t *instance = hcd_get_driver_data(hcd);
    415415        assert(instance);
    416416
     
    435435{
    436436        assert(hcd);
    437         hc_t *instance = hcd->driver.data;
     437        hc_t *instance = hcd_get_driver_data(hcd);
    438438        assert(instance);
    439439        assert(batch);
  • uspace/drv/bus/usb/uhci/main.c

    r2dbfe44 rb5f813c  
    4848#define NAME "uhci"
    4949
     50static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
     51static void uhci_driver_fini(hcd_t *);
     52static int disable_legacy(ddf_dev_t *);
     53
     54static const ddf_hc_driver_t uhci_hc_driver = {
     55        .claim = disable_legacy,
     56        .hc_speed = USB_SPEED_FULL,
     57        .irq_code_gen = uhci_hc_gen_irq_code,
     58        .init = uhci_driver_init,
     59        .fini = uhci_driver_fini,
     60        .name = "UHCI",
     61        .ops = {
     62                .schedule    = uhci_hc_schedule,
     63                .irq_hook    = uhci_hc_interrupt,
     64                .status_hook = uhci_hc_status,
     65        },
     66};
     67
    5068static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
    5169{
    5270        assert(hcd);
    53         assert(hcd->driver.data == NULL);
     71        assert(hcd_get_driver_data(hcd) == NULL);
    5472
    5573        hc_t *instance = malloc(sizeof(hc_t));
     
    5977        const int ret = hc_init(instance, res, irq);
    6078        if (ret == EOK)
    61                 hcd_set_implementation(hcd, instance, uhci_hc_schedule, NULL,
    62                     NULL, uhci_hc_interrupt, uhci_hc_status);
     79                hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
    6380        return ret;
    6481}
     
    6784{
    6885        assert(hcd);
    69         if (hcd->driver.data)
    70                 hc_fini(hcd->driver.data);
     86        hc_t *hc = hcd_get_driver_data(hcd);
     87        if (hc)
     88                hc_fini(hc);
    7189
    72         free(hcd->driver.data);
    73         hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
     90        hcd_set_implementation(hcd, NULL, NULL);
     91        free(hc);
    7492}
    75 
    76 static int uhci_dev_add(ddf_dev_t *device);
    77 
    78 static const driver_ops_t uhci_driver_ops = {
    79         .dev_add = uhci_dev_add,
    80 };
    81 
    82 static const driver_t uhci_driver = {
    83         .name = NAME,
    84         .driver_ops = &uhci_driver_ops
    85 };
    8693
    8794/** Call the PCI driver with a request to clear legacy support register
     
    106113        return rc;
    107114}
    108 static const ddf_hc_driver_t uhci_hc_driver = {
    109         .claim = disable_legacy,
    110         .hc_speed = USB_SPEED_FULL,
    111         .irq_code_gen = uhci_hc_gen_irq_code,
    112         .init = uhci_driver_init,
    113         .fini = uhci_driver_fini,
    114         .name = "UHCI"
    115 };
    116 
    117115
    118116/** Initialize a new ddf driver instance for uhci hc and hub.
     
    121119 * @return Error code.
    122120 */
    123 int uhci_dev_add(ddf_dev_t *device)
     121static int uhci_dev_add(ddf_dev_t *device)
    124122{
    125123        usb_log_debug2("uhci_dev_add() called\n");
     
    127125        return hcd_ddf_add_hc(device, &uhci_hc_driver);
    128126}
     127
     128static const driver_ops_t uhci_driver_ops = {
     129        .dev_add = uhci_dev_add,
     130};
     131
     132static const driver_t uhci_driver = {
     133        .name = NAME,
     134        .driver_ops = &uhci_driver_ops
     135};
     136
    129137
    130138/** Initialize global driver structures (NONE).
  • uspace/drv/bus/usb/vhc/main.c

    r2dbfe44 rb5f813c  
    7474}
    7575
     76hcd_ops_t vhc_hc_ops = {
     77        .schedule = vhc_schedule,
     78};
     79
    7680static int vhc_dev_add(ddf_dev_t *dev)
    7781{
     
    9599        }
    96100
    97         hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL, NULL, NULL);
     101        hcd_set_implementation(dev_to_hcd(dev), data, &vhc_hc_ops);
    98102
    99103        /* Add virtual hub device */
  • uspace/drv/bus/usb/vhc/transfer.c

    r2dbfe44 rb5f813c  
    167167        assert(hcd);
    168168        assert(batch);
    169         vhc_data_t *vhc = hcd->driver.data;
     169        vhc_data_t *vhc = hcd_get_driver_data(hcd);
    170170        assert(vhc);
    171171
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    r2dbfe44 rb5f813c  
    5151
    5252typedef struct {
    53         hc_driver_t ops;
     53        hcd_ops_t ops;
    5454        claim_t claim;
    5555        usb_speed_t hc_speed;
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r2dbfe44 rb5f813c  
    5555
    5656typedef struct {
    57         /** Device specific driver data. */
    58         void *data;
    5957        /** Transfer scheduling, implement in device driver. */
    6058        schedule_hook_t schedule;
     
    6765        /** Periodic polling hook */
    6866        status_hook_t status_hook;
    69 } hc_driver_t;
     67} hcd_ops_t;
    7068
    7169/** Generic host controller driver structure. */
     
    7472        usb_bus_t bus;
    7573
    76         /** Driver implementation */
    77         hc_driver_t driver;
    78 
    7974        /** Interrupt replacement fibril */
    8075        fid_t polling_fibril;
     76
     77        /** Driver implementation */
     78        hcd_ops_t ops;
     79        /** Device specific driver data. */
     80        void * driver_data;
    8181};
    8282
     
    8585
    8686static inline void hcd_set_implementation(hcd_t *hcd, void *data,
    87     schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook,
    88     interrupt_hook_t irq_hook, status_hook_t status_hook)
     87    const hcd_ops_t *ops)
    8988{
    9089        assert(hcd);
    91         hcd->driver.data = data;
    92         hcd->driver.schedule = schedule;
    93         hcd->driver.ep_add_hook = add_hook;
    94         hcd->driver.ep_remove_hook = rem_hook;
    95         hcd->driver.irq_hook = irq_hook;
    96         hcd->driver.status_hook = status_hook;
     90        if (ops) {
     91                hcd->driver_data = data;
     92                hcd->ops = *ops;
     93        } else {
     94                memset(&hcd->ops, 0, sizeof(hcd->ops));
     95        }
     96}
     97
     98static inline void * hcd_get_driver_data(hcd_t *hcd)
     99{
     100        assert(hcd);
     101        return hcd->driver_data;
    97102}
    98103
  • uspace/lib/usbhost/src/ddf_helpers.c

    r2dbfe44 rb5f813c  
    690690}
    691691
     692//TODO: Move this to generic ddf?
    692693int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res)
    693694{
     
    779780        assert(dev);
    780781        hcd_t *hcd = dev_to_hcd(dev);
    781         if (!hcd || !hcd->driver.irq_hook) {
     782        if (!hcd || !hcd->ops.irq_hook) {
    782783                usb_log_error("Interrupt on not yet initialized device.\n");
    783784                return;
    784785        }
    785786        const uint32_t status = IPC_GET_ARG1(*call);
    786         hcd->driver.irq_hook(hcd, status);
     787        hcd->ops.irq_hook(hcd, status);
    787788}
    788789
     
    791792        hcd_t *hcd = arg;
    792793        assert(hcd);
    793         if (!hcd->driver.status_hook || !hcd->driver.irq_hook)
     794        if (!hcd->ops.status_hook || !hcd->ops.irq_hook)
    794795                return ENOTSUP;
    795796        uint32_t status = 0;
    796         while (hcd->driver.status_hook(hcd, &status) == EOK) {
    797                 hcd->driver.irq_hook(hcd, status);
     797        while (hcd->ops.status_hook(hcd, &status) == EOK) {
     798                hcd->ops.irq_hook(hcd, status);
    798799                status = 0;
    799800                /* We should wait 1 frame - 1ms here, but this polling is a
     
    885886
    886887        /* Need working irq replacement to setup root hub */
    887         if ((irq < 0) && hcd->driver.status_hook) {
     888        if ((irq < 0) && hcd->ops.status_hook) {
    888889                hcd->polling_fibril = fibril_create(interrupt_polling, hcd);
    889890                if (hcd->polling_fibril == 0) {
  • uspace/lib/usbhost/src/hcd.c

    r2dbfe44 rb5f813c  
    5454        assert(ep);
    5555        assert(hcd);
    56         if (hcd->driver.ep_add_hook)
    57                 return hcd->driver.ep_add_hook(hcd, ep);
     56        if (hcd->ops.ep_add_hook)
     57                return hcd->ops.ep_add_hook(hcd, ep);
    5858        return EOK;
    5959}
     
    6868        assert(ep);
    6969        assert(hcd);
    70         if (hcd->driver.ep_remove_hook)
    71                 hcd->driver.ep_remove_hook(hcd, ep);
     70        if (hcd->ops.ep_remove_hook)
     71                hcd->ops.ep_remove_hook(hcd, ep);
    7272}
    7373
     
    9999        usb_bus_init(&hcd->bus, bandwidth, bw_count, max_speed);
    100100
    101         hcd->driver.data = NULL;
    102         hcd->driver.schedule = NULL;
    103         hcd->driver.ep_add_hook = NULL;
    104         hcd->driver.ep_remove_hook = NULL;
     101        hcd_set_implementation(hcd, NULL, NULL);
    105102}
    106103
     
    127124        assert(hcd);
    128125        usb_address_t address = 0;
    129         return usb_bus_request_address(
    130             &hcd->bus, &address, true, speed);
     126        return usb_bus_request_address(&hcd->bus, &address, true, speed);
    131127}
    132128
     
    209205                return ENOSPC;
    210206        }
    211         if (!hcd->driver.schedule) {
     207        if (!hcd->ops.schedule) {
    212208                usb_log_error("HCD does not implement scheduler.\n");
    213209                return ENOTSUP;
     
    241237        }
    242238
    243         const int ret = hcd->driver.schedule(hcd, batch);
     239        const int ret = hcd->ops.schedule(hcd, batch);
    244240        if (ret != EOK)
    245241                usb_transfer_batch_destroy(batch);
Note: See TracChangeset for help on using the changeset viewer.