source: mainline/uspace/drv/bus/usb/xhci/main.c@ 2770b66

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2770b66 was 20eaa82, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhost refactoring: introduced bus→enumerate_device

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[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
[e4d7363]49static int hc_driver_init(hcd_t *, const hw_res_list_parsed_t *);
50static int hcd_irq_code_gen(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *);
51static int hcd_claim(hcd_t *, ddf_dev_t *);
52static int hcd_start(hcd_t *, bool);
[867b375]53static int hcd_setup_root_hub(hcd_t *, ddf_dev_t *);
[e4d7363]54static int hcd_status(hcd_t *, uint32_t *);
55static void hcd_interrupt(hcd_t *, uint32_t);
56static int hcd_schedule(hcd_t *, usb_transfer_batch_t *);
57static void hc_driver_fini(hcd_t *);
58
59static const ddf_hc_driver_t xhci_ddf_hc_driver = {
60 .name = "XHCI-PCI",
61 .init = hc_driver_init,
62 .irq_code_gen = hcd_irq_code_gen,
63 .claim = hcd_claim,
64 .start = hcd_start,
[867b375]65 .setup_root_hub = hcd_setup_root_hub,
[e4d7363]66 .fini = hc_driver_fini,
67 .ops = {
68 .schedule = hcd_schedule,
69 .irq_hook = hcd_interrupt,
70 .status_hook = hcd_status,
71 }
72};
73
74static int hc_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
75{
76 int err;
77
78 xhci_hc_t *hc = malloc(sizeof(xhci_hc_t));
79 if (!hc)
80 return ENOMEM;
81
82 if ((err = hc_init_mmio(hc, hw_res)))
83 goto err;
84
85 if ((err = hc_init_memory(hc)))
86 goto err;
87
[41924f30]88 hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base);
[20eaa82]89 hc->hcd = hcd;
[e4d7363]90
91 return EOK;
92err:
93 free(hc);
94 return err;
95}
96
97static int hcd_irq_code_gen(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
98{
99 xhci_hc_t *hc = hcd_get_driver_data(hcd);
100 assert(hc);
101
102 return hc_irq_code_gen(code, hc, hw_res);
103}
104
105static int hcd_claim(hcd_t *hcd, ddf_dev_t *dev)
106{
107 xhci_hc_t *hc = hcd_get_driver_data(hcd);
108 assert(hc);
109
110 return hc_claim(hc, dev);
111}
112
113static int hcd_start(hcd_t *hcd, bool irq)
114{
115 xhci_hc_t *hc = hcd_get_driver_data(hcd);
116 assert(hc);
117
118 return hc_start(hc, irq);
119}
120
[867b375]121static int hcd_setup_root_hub(hcd_t *hcd, ddf_dev_t *dev)
122{
123 xhci_hc_t *hc = hcd_get_driver_data(hcd);
124 assert(hc);
125
[20eaa82]126 hc->rh.hc_device = dev;
127 return device_init(&hc->rh.device);
[867b375]128}
129
[e4d7363]130static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
131{
132 xhci_hc_t *hc = hcd_get_driver_data(hcd);
133 assert(hc);
134
135 return hc_schedule(hc, batch);
136}
137
138static int hcd_status(hcd_t *hcd, uint32_t *status)
139{
140 xhci_hc_t *hc = hcd_get_driver_data(hcd);
141 assert(hc);
142 assert(status);
143
144 return hc_status(hc, status);
145}
146
147static void hcd_interrupt(hcd_t *hcd, uint32_t status)
148{
149 xhci_hc_t *hc = hcd_get_driver_data(hcd);
150 assert(hc);
151
152 hc_interrupt(hc, status);
153}
154
155static void hc_driver_fini(hcd_t *hcd)
156{
157 xhci_hc_t *hc = hcd_get_driver_data(hcd);
158 assert(hc);
159
160 hc_fini(hc);
[a8435eb5]161
[e4d7363]162 free(hc);
163}
164
[5119d34]165/** Initializes a new ddf driver instance of XHCI hcd.
166 *
167 * @param[in] device DDF instance of the device to initialize.
168 * @return Error code.
169 */
170static int xhci_dev_add(ddf_dev_t *device)
171{
[5cbccd4]172 usb_log_info("Adding device %s", ddf_dev_get_name(device));
173 return hcd_ddf_add_hc(device, &xhci_ddf_hc_driver);
[5119d34]174}
175
176
177static const driver_ops_t xhci_driver_ops = {
178 .dev_add = xhci_dev_add,
179};
180
181static const driver_t xhci_driver = {
182 .name = NAME,
183 .driver_ops = &xhci_driver_ops
184};
185
186
187/** Initializes global driver structures (NONE).
188 *
189 * @param[in] argc Nmber of arguments in argv vector (ignored).
190 * @param[in] argv Cmdline argument vector (ignored).
191 * @return Error code.
192 *
193 * Driver debug level is set here.
194 */
195int main(int argc, char *argv[])
196{
197 log_init(NAME);
[5cbccd4]198 logctl_set_log_level(NAME, LVL_DEBUG2);
[5119d34]199 return ddf_driver_main(&xhci_driver);
200}
201
202/**
203 * @}
204 */
Note: See TracBrowser for help on using the repository browser.