Changeset 32fb6bce in mainline for uspace/drv/bus/usb/ehci/main.c


Ignore:
Timestamp:
2017-12-18T22:50:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

File:
1 edited

Legend:

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

    r1ea0bbf r32fb6bce  
    3535 */
    3636
    37 #include <ddf/driver.h>
    38 #include <ddf/interrupt.h>
    39 #include <device/hw_res.h>
    40 #include <errno.h>
    41 #include <str_error.h>
    4237#include <io/logctl.h>
    43 
    44 #include <usb_iface.h>
    45 #include <usb/debug.h>
     38#include <usb/host/hcd.h>
    4639#include <usb/host/ddf_helpers.h>
    4740
     
    5144#define NAME "ehci"
    5245
    53 static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
    54 static int ehci_driver_claim(hcd_t *, ddf_dev_t *);
    55 static int ehci_driver_start(hcd_t *, bool);
    56 static void ehci_driver_fini(hcd_t *);
     46static const hc_driver_t ehci_driver = {
     47        .name = NAME,
     48        .hc_device_size = sizeof(hc_t),
    5749
    58 static const ddf_hc_driver_t ehci_hc_driver = {
    59         .name = "EHCI-PCI",
    60         .init = ehci_driver_init,
    61         .irq_code_gen = ehci_hc_gen_irq_code,
    62         .claim = ehci_driver_claim,
    63         .start = ehci_driver_start,
     50        .hc_add = hc_add,
     51        .irq_code_gen = hc_gen_irq_code,
     52        .claim = disable_legacy,
     53        .start = hc_start,
    6454        .setup_root_hub = hcd_setup_virtual_root_hub,
    65         .fini = ehci_driver_fini,
    66         .ops = {
    67                 .schedule       = ehci_hc_schedule,
    68                 .irq_hook       = ehci_hc_interrupt,
    69                 .status_hook    = ehci_hc_status,
    70         }
     55        .hc_gone = hc_gone,
    7156};
    72 
    73 
    74 static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, ddf_dev_t *device)
    75 {
    76         assert(hcd);
    77         assert(hcd_get_driver_data(hcd) == NULL);
    78 
    79         hc_t *instance = malloc(sizeof(hc_t));
    80         if (!instance)
    81                 return ENOMEM;
    82 
    83         const int ret = hc_init(instance, hcd, res);
    84         if (ret == EOK) {
    85                 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops, &instance->bus.base.base);
    86         } else {
    87                 free(instance);
    88         }
    89         return ret;
    90 }
    91 
    92 static int ehci_driver_claim(hcd_t *hcd, ddf_dev_t *dev)
    93 {
    94         hc_t *instance = hcd_get_driver_data(hcd);
    95         assert(instance);
    96 
    97         return disable_legacy(instance, dev);
    98 }
    99 
    100 static int ehci_driver_start(hcd_t *hcd, bool irq) {
    101         hc_t *instance = hcd_get_driver_data(hcd);
    102         assert(instance);
    103 
    104         return hc_start(instance, irq);
    105 }
    106 
    107 static void ehci_driver_fini(hcd_t *hcd)
    108 {
    109         assert(hcd);
    110         hc_t *hc = hcd_get_driver_data(hcd);
    111         if (hc)
    112                 hc_fini(hc);
    113 
    114         free(hc);
    115         hcd_set_implementation(hcd, NULL, NULL, NULL);
    116 }
    117 
    118 /** Initializes a new ddf driver instance of EHCI hcd.
    119  *
    120  * @param[in] device DDF instance of the device to initialize.
    121  * @return Error code.
    122  */
    123 static int ehci_dev_add(ddf_dev_t *device)
    124 {
    125         usb_log_debug("ehci_dev_add() called\n");
    126         assert(device);
    127 
    128         return hcd_ddf_add_hc(device, &ehci_hc_driver);
    129 
    130 }
    131 
    132 static int ehci_fun_online(ddf_fun_t *fun)
    133 {
    134         return hcd_ddf_device_online(fun);
    135 }
    136 
    137 static int ehci_fun_offline(ddf_fun_t *fun)
    138 {
    139         return hcd_ddf_device_offline(fun);
    140 }
    141 
    142 
    143 static const driver_ops_t ehci_driver_ops = {
    144         .dev_add = ehci_dev_add,
    145         .fun_online = ehci_fun_online,
    146         .fun_offline = ehci_fun_offline
    147 };
    148 
    149 static const driver_t ehci_driver = {
    150         .name = NAME,
    151         .driver_ops = &ehci_driver_ops
    152 };
    153 
    15457
    15558/** Initializes global driver structures (NONE).
     
    16568        log_init(NAME);
    16669        logctl_set_log_level(NAME, LVL_NOTE);
    167         return ddf_driver_main(&ehci_driver);
     70        return hc_driver_main(&ehci_driver);
    16871}
    16972
Note: See TracChangeset for help on using the changeset viewer.