| 1 | /*
|
|---|
| 2 | * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz>
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup drvusbxhci
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * Main routines of XHCI driver.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <ddf/driver.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <io/log.h>
|
|---|
| 39 | #include <io/logctl.h>
|
|---|
| 40 | #include <usb/debug.h>
|
|---|
| 41 | #include <usb/host/ddf_helpers.h>
|
|---|
| 42 |
|
|---|
| 43 | #include "hc.h"
|
|---|
| 44 | #include "rh.h"
|
|---|
| 45 | #include "endpoint.h"
|
|---|
| 46 |
|
|---|
| 47 | #define NAME "xhci"
|
|---|
| 48 |
|
|---|
| 49 | static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd)
|
|---|
| 50 | {
|
|---|
| 51 | assert(hcd);
|
|---|
| 52 | return (xhci_hc_t *) hcd;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | static 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 |
|
|---|
| 70 | static 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 |
|
|---|
| 76 | static 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 |
|
|---|
| 82 | static 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 |
|
|---|
| 88 | static 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 |
|
|---|
| 95 | static const hc_driver_t xhci_driver = {
|
|---|
| 96 | .name = NAME,
|
|---|
| 97 | .hc_device_size = sizeof(xhci_hc_t),
|
|---|
| 98 |
|
|---|
| 99 | .hc_add = hcd_hc_add,
|
|---|
| 100 | .irq_code_gen = hcd_irq_code_gen,
|
|---|
| 101 | .claim = hcd_claim,
|
|---|
| 102 | .start = hcd_start,
|
|---|
| 103 | .hc_gone = hcd_hc_gone,
|
|---|
| 104 | };
|
|---|
| 105 |
|
|---|
| 106 | /** Initializes global driver structures (NONE).
|
|---|
| 107 | *
|
|---|
| 108 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
|---|
| 109 | * @param[in] argv Cmdline argument vector (ignored).
|
|---|
| 110 | * @return Error code.
|
|---|
| 111 | *
|
|---|
| 112 | * Driver debug level is set here.
|
|---|
| 113 | */
|
|---|
| 114 | int main(int argc, char *argv[])
|
|---|
| 115 | {
|
|---|
| 116 | log_init(NAME);
|
|---|
| 117 | logctl_set_log_level(NAME, LVL_DEBUG);
|
|---|
| 118 | return hc_driver_main(&xhci_driver);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /**
|
|---|
| 122 | * @}
|
|---|
| 123 | */
|
|---|