source: mainline/uspace/drv/bus/usb/vhc/main.c@ 237df2f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 237df2f was f5f0cfb, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

vhc: Remove single instance limitation.

Embed hub vitrul device instead of using global instance.

  • Property mode set to 100644
File size: 3.6 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/ddfiface.h>
44#include <usb/debug.h>
45#include "vhcd.h"
46
47
48static ddf_dev_ops_t vhc_ops = {
49 .close = on_client_close,
50 .default_handler = default_connection_handler
51};
52
53
54static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
55{
56 assert(dev);
57 assert(fun);
58
59 *fun = ddf_fun_create(dev, fun_exposed, "ctl");
60 if (!*fun)
61 return ENOMEM;
62
63 vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
64 if (!vhc) {
65 ddf_fun_destroy(*fun);
66 }
67 ddf_fun_set_ops(*fun, &vhc_ops);
68 const int ret = ddf_fun_bind(*fun);
69 if (ret != EOK) {
70 ddf_fun_destroy(*fun);
71 *fun = NULL;
72 return ret;
73 }
74 vhc_init(vhc);
75 return EOK;
76}
77
78static int vhc_dev_add(ddf_dev_t *dev)
79{
80 /* Initialize virtual structure */
81 ddf_fun_t *ctl_fun = NULL;
82 int ret = vhc_control_node(dev, &ctl_fun);
83 if (ret != EOK) {
84 usb_log_error("Failed to setup control node.\n");
85 return ret;
86 }
87 vhc_data_t *data = ddf_fun_data_get(ctl_fun);
88
89 /* Initialize generic structures */
90 ret = hcd_ddf_setup_device(dev, NULL, USB_SPEED_FULL,
91 BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
92 if (ret != EOK) {
93 usb_log_error("Failed to init HCD structures: %s.\n",
94 str_error(ret));
95 free(data);
96 return ret;
97 }
98
99 hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL);
100
101 /* Add virtual hub device */
102 usb_address_t address = 1;
103 ret = vhc_virtdev_plug_hub(data, &data->hub, NULL, address);
104 if (ret != EOK) {
105 usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
106 free(data);
107 return ret;
108 }
109
110 // TODO fix the address hack
111 ret = hcd_ddf_setup_hub(dev, &address);
112 if (ret != EOK) {
113 usb_log_error("Failed to init VHC root hub: %s\n",
114 str_error(ret));
115 // TODO do something here...
116 }
117
118 return ret;
119}
120
121static driver_ops_t vhc_driver_ops = {
122 .dev_add = vhc_dev_add,
123};
124
125static driver_t vhc_driver = {
126 .name = NAME,
127 .driver_ops = &vhc_driver_ops
128};
129
130int main(int argc, char * argv[])
131{
132 log_init(NAME);
133 printf(NAME ": virtual USB host controller driver.\n");
134
135 return ddf_driver_main(&vhc_driver);
136}
137
138/**
139 * @}
140 */
Note: See TracBrowser for help on using the repository browser.