[5119d34] | 1 | /*
|
---|
[8300c72] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty, Petr Manek
|
---|
[5119d34] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup drvusbxhci
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | * Main routines of XHCI driver.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <ddf/driver.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <io/log.h>
|
---|
| 40 | #include <io/logctl.h>
|
---|
| 41 | #include <usb/debug.h>
|
---|
[5cbccd4] | 42 | #include <usb/host/ddf_helpers.h>
|
---|
| 43 |
|
---|
| 44 | #include "hc.h"
|
---|
[867b375] | 45 | #include "rh.h"
|
---|
[c0ec9e7] | 46 | #include "endpoint.h"
|
---|
[5119d34] | 47 |
|
---|
| 48 | #define NAME "xhci"
|
---|
| 49 |
|
---|
[32fb6bce] | 50 | static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
| 51 | {
|
---|
| 52 | assert(hcd);
|
---|
| 53 | return (xhci_hc_t *) hcd;
|
---|
| 54 | }
|
---|
[e4d7363] | 55 |
|
---|
[45457265] | 56 | static errno_t hcd_hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
|
---|
[e4d7363] | 57 | {
|
---|
[45457265] | 58 | errno_t err;
|
---|
[32fb6bce] | 59 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 60 | hc_device_setup(hcd, (bus_t *) &hc->bus);
|
---|
[e4d7363] | 61 |
|
---|
| 62 | if ((err = hc_init_mmio(hc, hw_res)))
|
---|
[32fb6bce] | 63 | return err;
|
---|
[e4d7363] | 64 |
|
---|
[32fb6bce] | 65 | if ((err = hc_init_memory(hc, hcd->ddf_dev)))
|
---|
| 66 | return err;
|
---|
[e4d7363] | 67 |
|
---|
| 68 | return EOK;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[ae3a941] | 71 | static errno_t hcd_irq_code_gen(irq_code_t *code, hc_device_t *hcd,
|
---|
| 72 | const hw_res_list_parsed_t *hw_res, int *irq)
|
---|
[e4d7363] | 73 | {
|
---|
[32fb6bce] | 74 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
[132ab5d1] | 75 | return hc_irq_code_gen(code, hc, hw_res, irq);
|
---|
[e4d7363] | 76 | }
|
---|
| 77 |
|
---|
[45457265] | 78 | static errno_t hcd_claim(hc_device_t *hcd)
|
---|
[e4d7363] | 79 | {
|
---|
[32fb6bce] | 80 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 81 | return hc_claim(hc, hcd->ddf_dev);
|
---|
[e4d7363] | 82 | }
|
---|
| 83 |
|
---|
[45457265] | 84 | static errno_t hcd_start(hc_device_t *hcd)
|
---|
[e4d7363] | 85 | {
|
---|
[32fb6bce] | 86 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
[19f0048] | 87 | return hc_start(hc);
|
---|
[e4d7363] | 88 | }
|
---|
| 89 |
|
---|
[45457265] | 90 | static errno_t hcd_hc_gone(hc_device_t *hcd)
|
---|
[e4d7363] | 91 | {
|
---|
[32fb6bce] | 92 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
[e4d7363] | 93 | hc_fini(hc);
|
---|
[32fb6bce] | 94 | return EOK;
|
---|
[d37514e] | 95 | }
|
---|
[5119d34] | 96 |
|
---|
[8300c72] | 97 | static errno_t hcd_hc_quiesce(hc_device_t *hcd)
|
---|
| 98 | {
|
---|
| 99 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
| 100 | hc_quiesce(hc);
|
---|
| 101 | return EOK;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[32fb6bce] | 104 | static const hc_driver_t xhci_driver = {
|
---|
[5119d34] | 105 | .name = NAME,
|
---|
[32fb6bce] | 106 | .hc_device_size = sizeof(xhci_hc_t),
|
---|
[5119d34] | 107 |
|
---|
[32fb6bce] | 108 | .hc_add = hcd_hc_add,
|
---|
| 109 | .irq_code_gen = hcd_irq_code_gen,
|
---|
| 110 | .claim = hcd_claim,
|
---|
| 111 | .start = hcd_start,
|
---|
| 112 | .hc_gone = hcd_hc_gone,
|
---|
[8300c72] | 113 | .hc_quiesce = hcd_hc_quiesce
|
---|
[32fb6bce] | 114 | };
|
---|
[5119d34] | 115 |
|
---|
| 116 | /** Initializes global driver structures (NONE).
|
---|
| 117 | *
|
---|
| 118 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 119 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 120 | * @return Error code.
|
---|
| 121 | *
|
---|
| 122 | * Driver debug level is set here.
|
---|
| 123 | */
|
---|
[45457265] | 124 | errno_t main(int argc, char *argv[])
|
---|
[5119d34] | 125 | {
|
---|
| 126 | log_init(NAME);
|
---|
[b2dca8de] | 127 | logctl_set_log_level(NAME, LVL_NOTE);
|
---|
[32fb6bce] | 128 | return hc_driver_main(&xhci_driver);
|
---|
[5119d34] | 129 | }
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * @}
|
---|
| 133 | */
|
---|