[5119d34] | 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>
|
---|
[5cbccd4] | 41 | #include <usb/host/ddf_helpers.h>
|
---|
| 42 |
|
---|
| 43 | #include "hc.h"
|
---|
[867b375] | 44 | #include "rh.h"
|
---|
[c0ec9e7] | 45 | #include "endpoint.h"
|
---|
[5119d34] | 46 |
|
---|
| 47 | #define NAME "xhci"
|
---|
| 48 |
|
---|
[32fb6bce] | 49 | static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
| 50 | {
|
---|
| 51 | assert(hcd);
|
---|
| 52 | return (xhci_hc_t *) hcd;
|
---|
| 53 | }
|
---|
[e4d7363] | 54 |
|
---|
[32fb6bce] | 55 | static int hcd_hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
|
---|
[e4d7363] | 56 | {
|
---|
| 57 | int err;
|
---|
[32fb6bce] | 58 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 59 | hc_device_setup(hcd, (bus_t *) &hc->bus);
|
---|
[e4d7363] | 60 |
|
---|
| 61 | if ((err = hc_init_mmio(hc, hw_res)))
|
---|
[32fb6bce] | 62 | return err;
|
---|
[e4d7363] | 63 |
|
---|
[32fb6bce] | 64 | if ((err = hc_init_memory(hc, hcd->ddf_dev)))
|
---|
| 65 | return err;
|
---|
[e4d7363] | 66 |
|
---|
| 67 | return EOK;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[32fb6bce] | 70 | static int hcd_irq_code_gen(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
|
---|
[e4d7363] | 71 | {
|
---|
[32fb6bce] | 72 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
[e4d7363] | 73 | return hc_irq_code_gen(code, hc, hw_res);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[32fb6bce] | 76 | static int hcd_claim(hc_device_t *hcd)
|
---|
[e4d7363] | 77 | {
|
---|
[32fb6bce] | 78 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 79 | return hc_claim(hc, hcd->ddf_dev);
|
---|
[e4d7363] | 80 | }
|
---|
| 81 |
|
---|
[32fb6bce] | 82 | static int hcd_start(hc_device_t *hcd)
|
---|
[e4d7363] | 83 | {
|
---|
[32fb6bce] | 84 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 85 | return hc_start(hc, hcd->irq_cap >= 0);
|
---|
[e4d7363] | 86 | }
|
---|
| 87 |
|
---|
[32fb6bce] | 88 | static int hcd_hc_gone(hc_device_t *hcd)
|
---|
[e4d7363] | 89 | {
|
---|
[32fb6bce] | 90 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
[e4d7363] | 91 | hc_fini(hc);
|
---|
[32fb6bce] | 92 | return EOK;
|
---|
[d37514e] | 93 | }
|
---|
[5119d34] | 94 |
|
---|
[32fb6bce] | 95 | static const hc_driver_t xhci_driver = {
|
---|
[5119d34] | 96 | .name = NAME,
|
---|
[32fb6bce] | 97 | .hc_device_size = sizeof(xhci_hc_t),
|
---|
[5119d34] | 98 |
|
---|
[32fb6bce] | 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 | };
|
---|
[5119d34] | 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);
|
---|
[398a94c] | 117 | logctl_set_log_level(NAME, LVL_DEBUG);
|
---|
[32fb6bce] | 118 | return hc_driver_main(&xhci_driver);
|
---|
[5119d34] | 119 | }
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | * @}
|
---|
| 123 | */
|
---|