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

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

WIP usbhost refactoring

This commit replaces callbacks with more systematic virtual-like inheritance-like solution. Currently breaks build of HelenOS, but both xhci and usbhost are buildable. More refactoring follows…

  • Property mode set to 100644
File size: 4.8 KB
Line 
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 "endpoint.h"
45
46#define NAME "xhci"
47
48static int hc_driver_init(hcd_t *, const hw_res_list_parsed_t *);
49static int hcd_irq_code_gen(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *);
50static int hcd_claim(hcd_t *, ddf_dev_t *);
51static int hcd_start(hcd_t *, bool);
52static int hcd_status(hcd_t *, uint32_t *);
53static void hcd_interrupt(hcd_t *, uint32_t);
54static int hcd_schedule(hcd_t *, usb_transfer_batch_t *);
55static void hc_driver_fini(hcd_t *);
56
57static const ddf_hc_driver_t xhci_ddf_hc_driver = {
58 .hc_speed = USB_SPEED_SUPER,
59 .name = "XHCI-PCI",
60 .init = hc_driver_init,
61 .irq_code_gen = hcd_irq_code_gen,
62 .claim = hcd_claim,
63 .start = hcd_start,
64 .fini = hc_driver_fini,
65 .ops = {
66 .schedule = hcd_schedule,
67 .irq_hook = hcd_interrupt,
68 .status_hook = hcd_status,
69 }
70};
71
72static int hc_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
73{
74 int err;
75
76 xhci_hc_t *hc = malloc(sizeof(xhci_hc_t));
77 if (!hc)
78 return ENOMEM;
79
80 if ((err = hc_init_mmio(hc, hw_res)))
81 goto err;
82
83 if ((err = xhci_bus_init(&hc->bus, hcd)))
84 goto err;
85
86 if ((err = hc_init_memory(hc)))
87 goto err;
88
89 hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base);
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
121static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
122{
123 xhci_hc_t *hc = hcd_get_driver_data(hcd);
124 assert(hc);
125
126 return hc_schedule(hc, batch);
127}
128
129static int hcd_status(hcd_t *hcd, uint32_t *status)
130{
131 xhci_hc_t *hc = hcd_get_driver_data(hcd);
132 assert(hc);
133 assert(status);
134
135 return hc_status(hc, status);
136}
137
138static void hcd_interrupt(hcd_t *hcd, uint32_t status)
139{
140 xhci_hc_t *hc = hcd_get_driver_data(hcd);
141 assert(hc);
142
143 hc_interrupt(hc, status);
144}
145
146static void hc_driver_fini(hcd_t *hcd)
147{
148 xhci_hc_t *hc = hcd_get_driver_data(hcd);
149 assert(hc);
150
151 hc_fini(hc);
152 free(hc);
153}
154
155/** Initializes a new ddf driver instance of XHCI hcd.
156 *
157 * @param[in] device DDF instance of the device to initialize.
158 * @return Error code.
159 */
160static int xhci_dev_add(ddf_dev_t *device)
161{
162 usb_log_info("Adding device %s", ddf_dev_get_name(device));
163 return hcd_ddf_add_hc(device, &xhci_ddf_hc_driver);
164}
165
166
167static const driver_ops_t xhci_driver_ops = {
168 .dev_add = xhci_dev_add,
169};
170
171static const driver_t xhci_driver = {
172 .name = NAME,
173 .driver_ops = &xhci_driver_ops
174};
175
176
177/** Initializes global driver structures (NONE).
178 *
179 * @param[in] argc Nmber of arguments in argv vector (ignored).
180 * @param[in] argv Cmdline argument vector (ignored).
181 * @return Error code.
182 *
183 * Driver debug level is set here.
184 */
185int main(int argc, char *argv[])
186{
187 log_init(NAME);
188 logctl_set_log_level(NAME, LVL_DEBUG2);
189 return ddf_driver_main(&xhci_driver);
190}
191
192/**
193 * @}
194 */
Note: See TracBrowser for help on using the repository browser.