Changeset e4d7363 in mainline for uspace/drv/bus/usb/xhci/main.c


Ignore:
Timestamp:
2017-06-22T21:34:39Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
91ca111
Parents:
cb89430
Message:

usbhost: refactor the initialization

Before that, drivers had to setup MMIO range multiple times, or even parse hw
resources themselves again. The former init method was split in half - init and
start. Init shall allocate and initialize inner structures, start shall start
the HC.

In the XHCI it is demonstrated how to isolate inner HC implementation from the
fact this driver is using libusbhost. It adds some boilerplate code, but
I think it leads to cleaner design.

File:
1 edited

Legend:

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

    rcb89430 re4d7363  
    4545#define NAME "xhci"
    4646
     47static int hc_driver_init(hcd_t *, const hw_res_list_parsed_t *);
     48static int hcd_irq_code_gen(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *);
     49static int hcd_claim(hcd_t *, ddf_dev_t *);
     50static int hcd_start(hcd_t *, bool);
     51static int hcd_status(hcd_t *, uint32_t *);
     52static void hcd_interrupt(hcd_t *, uint32_t);
     53static int hcd_schedule(hcd_t *, usb_transfer_batch_t *);
     54static void hc_driver_fini(hcd_t *);
     55
     56static const ddf_hc_driver_t xhci_ddf_hc_driver = {
     57        .hc_speed = USB_SPEED_SUPER,
     58        .name = "XHCI-PCI",
     59        .init = hc_driver_init,
     60        .irq_code_gen = hcd_irq_code_gen,
     61        .claim = hcd_claim,
     62        .start = hcd_start,
     63        .fini = hc_driver_fini,
     64        .ops = {
     65                .schedule       = hcd_schedule,
     66                .irq_hook       = hcd_interrupt,
     67                .status_hook    = hcd_status,
     68        }
     69};
     70
     71static int hc_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
     72{
     73        int err;
     74
     75        xhci_hc_t *hc = malloc(sizeof(xhci_hc_t));
     76        if (!hc)
     77                return ENOMEM;
     78
     79        if ((err = hc_init_mmio(hc, hw_res)))
     80                goto err;
     81
     82        if ((err = hc_init_memory(hc)))
     83                goto err;
     84
     85        hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops);
     86
     87        return EOK;
     88err:
     89        free(hc);
     90        return err;
     91}
     92
     93static int hcd_irq_code_gen(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
     94{
     95        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     96        assert(hc);
     97
     98        return hc_irq_code_gen(code, hc, hw_res);
     99}
     100
     101static int hcd_claim(hcd_t *hcd, ddf_dev_t *dev)
     102{
     103        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     104        assert(hc);
     105
     106        return hc_claim(hc, dev);
     107}
     108
     109static int hcd_start(hcd_t *hcd, bool irq)
     110{
     111        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     112        assert(hc);
     113
     114        return hc_start(hc, irq);
     115}
     116
     117static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
     118{
     119        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     120        assert(hc);
     121
     122        return hc_schedule(hc, batch);
     123}
     124
     125static int hcd_status(hcd_t *hcd, uint32_t *status)
     126{
     127        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     128        assert(hc);
     129        assert(status);
     130
     131        return hc_status(hc, status);
     132}
     133
     134static void hcd_interrupt(hcd_t *hcd, uint32_t status)
     135{
     136        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     137        assert(hc);
     138
     139        hc_interrupt(hc, status);
     140}
     141
     142static void hc_driver_fini(hcd_t *hcd)
     143{
     144        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     145        assert(hc);
     146
     147        hc_fini(hc);
     148        free(hc);
     149}
     150
    47151/** Initializes a new ddf driver instance of XHCI hcd.
    48152 *
Note: See TracChangeset for help on using the changeset viewer.