1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2018 Ondrej Hlavaty, Petr Manek
|
---|
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>
|
---|
42 | #include <usb/host/ddf_helpers.h>
|
---|
43 |
|
---|
44 | #include "hc.h"
|
---|
45 | #include "rh.h"
|
---|
46 | #include "endpoint.h"
|
---|
47 |
|
---|
48 | #define NAME "xhci"
|
---|
49 |
|
---|
50 | static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
51 | {
|
---|
52 | assert(hcd);
|
---|
53 | return (xhci_hc_t *) hcd;
|
---|
54 | }
|
---|
55 |
|
---|
56 | static errno_t hcd_hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
|
---|
57 | {
|
---|
58 | errno_t err;
|
---|
59 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
60 | hc_device_setup(hcd, (bus_t *) &hc->bus);
|
---|
61 |
|
---|
62 | if ((err = hc_init_mmio(hc, hw_res)))
|
---|
63 | return err;
|
---|
64 |
|
---|
65 | if ((err = hc_init_memory(hc, hcd->ddf_dev)))
|
---|
66 | return err;
|
---|
67 |
|
---|
68 | return EOK;
|
---|
69 | }
|
---|
70 |
|
---|
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)
|
---|
73 | {
|
---|
74 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
75 | return hc_irq_code_gen(code, hc, hw_res, irq);
|
---|
76 | }
|
---|
77 |
|
---|
78 | static errno_t hcd_claim(hc_device_t *hcd)
|
---|
79 | {
|
---|
80 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
81 | return hc_claim(hc, hcd->ddf_dev);
|
---|
82 | }
|
---|
83 |
|
---|
84 | static errno_t hcd_start(hc_device_t *hcd)
|
---|
85 | {
|
---|
86 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
87 | return hc_start(hc);
|
---|
88 | }
|
---|
89 |
|
---|
90 | static errno_t hcd_hc_gone(hc_device_t *hcd)
|
---|
91 | {
|
---|
92 | xhci_hc_t *hc = hcd_to_hc(hcd);
|
---|
93 | hc_fini(hc);
|
---|
94 | return EOK;
|
---|
95 | }
|
---|
96 |
|
---|
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 |
|
---|
104 | static const hc_driver_t xhci_driver = {
|
---|
105 | .name = NAME,
|
---|
106 | .hc_device_size = sizeof(xhci_hc_t),
|
---|
107 |
|
---|
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,
|
---|
113 | .hc_quiesce = hcd_hc_quiesce
|
---|
114 | };
|
---|
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 | */
|
---|
124 | errno_t main(int argc, char *argv[])
|
---|
125 | {
|
---|
126 | log_init(NAME);
|
---|
127 | logctl_set_log_level(NAME, LVL_NOTE);
|
---|
128 | return hc_driver_main(&xhci_driver);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * @}
|
---|
133 | */
|
---|