Changeset 32fb6bce in mainline for uspace/drv/bus/usb/xhci/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/xhci/main.c

    r1ea0bbf r32fb6bce  
    4747#define NAME "xhci"
    4848
    49 static int hc_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
    50 static int hcd_irq_code_gen(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *);
    51 static int hcd_claim(hcd_t *, ddf_dev_t *);
    52 static int hcd_start(hcd_t *, bool);
    53 static int hcd_status(hcd_t *, uint32_t *);
    54 static void hcd_interrupt(hcd_t *, uint32_t);
    55 static int hcd_schedule(hcd_t *, usb_transfer_batch_t *);
    56 static void hc_driver_fini(hcd_t *);
     49static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd)
     50{
     51        assert(hcd);
     52        return (xhci_hc_t *) hcd;
     53}
    5754
    58 static const ddf_hc_driver_t xhci_ddf_hc_driver = {
    59         .name = "XHCI-PCI",
    60         .init = hc_driver_init,
     55static int hcd_hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
     56{
     57        int err;
     58        xhci_hc_t *hc = hcd_to_hc(hcd);
     59        hc_device_setup(hcd, (bus_t *) &hc->bus);
     60
     61        if ((err = hc_init_mmio(hc, hw_res)))
     62                return err;
     63
     64        if ((err = hc_init_memory(hc, hcd->ddf_dev)))
     65                return err;
     66
     67        return EOK;
     68}
     69
     70static int hcd_irq_code_gen(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
     71{
     72        xhci_hc_t *hc = hcd_to_hc(hcd);
     73        return hc_irq_code_gen(code, hc, hw_res);
     74}
     75
     76static int hcd_claim(hc_device_t *hcd)
     77{
     78        xhci_hc_t *hc = hcd_to_hc(hcd);
     79        return hc_claim(hc, hcd->ddf_dev);
     80}
     81
     82static int hcd_start(hc_device_t *hcd)
     83{
     84        xhci_hc_t *hc = hcd_to_hc(hcd);
     85        return hc_start(hc, hcd->irq_cap >= 0);
     86}
     87
     88static int hcd_hc_gone(hc_device_t *hcd)
     89{
     90        xhci_hc_t *hc = hcd_to_hc(hcd);
     91        hc_fini(hc);
     92        return EOK;
     93}
     94
     95static const hc_driver_t xhci_driver = {
     96        .name = NAME,
     97        .hc_device_size = sizeof(xhci_hc_t),
     98
     99        .hc_add = hcd_hc_add,
    61100        .irq_code_gen = hcd_irq_code_gen,
    62101        .claim = hcd_claim,
    63102        .start = hcd_start,
    64         .setup_root_hub = NULL,
    65         .fini = hc_driver_fini,
    66         .ops = {
    67                 .schedule       = hcd_schedule,
    68                 .irq_hook       = hcd_interrupt,
    69                 .status_hook    = hcd_status,
    70         }
     103        .hc_gone = hcd_hc_gone,
    71104};
    72 
    73 static int hc_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res, ddf_dev_t *device)
    74 {
    75         int err;
    76 
    77         xhci_hc_t *hc = malloc(sizeof(xhci_hc_t));
    78         if (!hc)
    79                 return ENOMEM;
    80 
    81         if ((err = hc_init_mmio(hc, hw_res)))
    82                 goto err;
    83 
    84         hc->hcd = hcd;
    85 
    86         if ((err = hc_init_memory(hc, device)))
    87                 goto err;
    88 
    89         hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base);
    90 
    91         return EOK;
    92 err:
    93         free(hc);
    94         return err;
    95 }
    96 
    97 static int hcd_irq_code_gen(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
    98 {
    99         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    100         assert(hc);
    101 
    102         return hc_irq_code_gen(code, hc, hw_res);
    103 }
    104 
    105 static int hcd_claim(hcd_t *hcd, ddf_dev_t *dev)
    106 {
    107         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    108         assert(hc);
    109 
    110         return hc_claim(hc, dev);
    111 }
    112 
    113 static int hcd_start(hcd_t *hcd, bool irq)
    114 {
    115         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    116         assert(hc);
    117 
    118         return hc_start(hc, irq);
    119 }
    120 
    121 static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    122 {
    123         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    124         assert(hc);
    125 
    126         return hc_schedule(hc, batch);
    127 }
    128 
    129 static int hcd_status(hcd_t *hcd, uint32_t *status)
    130 {
    131         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    132         assert(hc);
    133         assert(status);
    134 
    135         return hc_status(hc, status);
    136 }
    137 
    138 static void hcd_interrupt(hcd_t *hcd, uint32_t status)
    139 {
    140         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    141         assert(hc);
    142 
    143         hc_interrupt(hc, status);
    144 }
    145 
    146 static void hc_driver_fini(hcd_t *hcd)
    147 {
    148         xhci_hc_t *hc = hcd_get_driver_data(hcd);
    149         assert(hc);
    150 
    151         hc_fini(hc);
    152 
    153         free(hc);
    154 }
    155 
    156 /** Initializes a new ddf driver instance of XHCI hcd.
    157  *
    158  * @param[in] device DDF instance of the device to initialize.
    159  * @return Error code.
    160  */
    161 static int xhci_dev_add(ddf_dev_t *device)
    162 {
    163         usb_log_info("Adding device %s", ddf_dev_get_name(device));
    164         return hcd_ddf_add_hc(device, &xhci_ddf_hc_driver);
    165 }
    166 
    167 static int xhci_fun_online(ddf_fun_t *fun)
    168 {
    169         return hcd_ddf_device_online(fun);
    170 }
    171 
    172 static int xhci_fun_offline(ddf_fun_t *fun)
    173 {
    174         return hcd_ddf_device_offline(fun);
    175 }
    176 
    177 
    178 static const driver_ops_t xhci_driver_ops = {
    179         .dev_add = xhci_dev_add,
    180         .fun_online = xhci_fun_online,
    181         .fun_offline = xhci_fun_offline
    182 };
    183 
    184 static const driver_t xhci_driver = {
    185         .name = NAME,
    186         .driver_ops = &xhci_driver_ops
    187 };
    188 
    189105
    190106/** Initializes global driver structures (NONE).
     
    200116        log_init(NAME);
    201117        logctl_set_log_level(NAME, LVL_DEBUG2);
    202         return ddf_driver_main(&xhci_driver);
     118        return hc_driver_main(&xhci_driver);
    203119}
    204120
Note: See TracChangeset for help on using the changeset viewer.