source: mainline/uspace/drv/bus/usb/vhc/main.c@ 36fb6d7

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

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
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 drvusbvhc
30 * @{
31 */
32/** @file
33 * Virtual host controller.
34 */
35
36#include <stdio.h>
37#include <errno.h>
38#include <str_error.h>
39#include <ddf/driver.h>
40
41#include <usb/host/ddf_helpers.h>
42
43#include <usb/debug.h>
44#include "vhcd.h"
45
46static ddf_dev_ops_t vhc_ops = {
47 .close = on_client_close,
48 .default_handler = default_connection_handler
49};
50
51static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
52{
53 assert(dev);
54 assert(fun);
55
56 *fun = ddf_fun_create(dev, fun_exposed, "virtual");
57 if (!*fun)
58 return ENOMEM;
59
60 vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
61 if (!vhc) {
62 ddf_fun_destroy(*fun);
63 }
64 ddf_fun_set_ops(*fun, &vhc_ops);
65 const int ret = ddf_fun_bind(*fun);
66 if (ret != EOK) {
67 ddf_fun_destroy(*fun);
68 *fun = NULL;
69 return ret;
70 }
71 return EOK;
72}
73
74static int vhc_dev_add(ddf_dev_t *dev)
75{
76 /* Initialize generic structures */
77 int ret = hcd_ddf_setup_hc(dev, sizeof(vhc_data_t));
78 if (ret != EOK) {
79 usb_log_error("Failed to init HCD structures: %s.\n",
80 str_error(ret));
81 return ret;
82 }
83 vhc_data_t *vhc = ddf_dev_data_get(dev);
84 vhc_init(vhc);
85
86 hc_device_setup(&vhc->base, (bus_t *) &vhc->bus);
87
88 /* Initialize virtual structure */
89 ddf_fun_t *ctl_fun = NULL;
90 ret = vhc_control_node(dev, &ctl_fun);
91 if (ret != EOK) {
92 usb_log_error("Failed to setup control node.\n");
93 return ret;
94 }
95
96 /* Add virtual hub device */
97 ret = vhc_virtdev_plug_hub(vhc, &vhc->hub, NULL, 0);
98 if (ret != EOK) {
99 usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
100 ddf_fun_destroy(ctl_fun);
101 return ret;
102 }
103
104 /*
105 * Creating root hub registers a new USB device so HC
106 * needs to be ready at this time.
107 */
108 ret = hcd_setup_virtual_root_hub(&vhc->base);
109 if (ret != EOK) {
110 usb_log_error("Failed to init VHC root hub: %s\n",
111 str_error(ret));
112 // TODO do something here...
113 }
114
115 return ret;
116}
117
118static driver_ops_t vhc_driver_ops = {
119 .dev_add = vhc_dev_add,
120};
121
122static driver_t vhc_driver = {
123 .name = NAME,
124 .driver_ops = &vhc_driver_ops
125};
126
127int main(int argc, char * argv[])
128{
129 log_init(NAME);
130 printf(NAME ": virtual USB host controller driver.\n");
131
132 return ddf_driver_main(&vhc_driver);
133}
134
135/**
136 * @}
137 */
Note: See TracBrowser for help on using the repository browser.