Changeset b5f813c in mainline for uspace/drv


Ignore:
Timestamp:
2015-07-04T03:28:02Z (10 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/drv/bus/usb
Files:
10 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
Note: See TracChangeset for help on using the changeset viewer.