source: mainline/uspace/drv/vhc/main.c@ 4a4c8bcf

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4a4c8bcf was 79ae36dd, checked in by Martin Decky <martin@…>, 14 years ago

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
  • Property mode set to 100644
File size: 3.8 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 <devmap.h>
37#include <async.h>
38#include <unistd.h>
39#include <stdlib.h>
40#include <sysinfo.h>
41#include <stdio.h>
42#include <errno.h>
43#include <str_error.h>
44#include <ddf/driver.h>
45
46#include <usb/usb.h>
47#include <usb/ddfiface.h>
48#include <usb_iface.h>
49#include "vhcd.h"
50#include "hub.h"
51#include "conn.h"
52
53static ddf_dev_ops_t vhc_ops = {
54 .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
55 .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
56 .close = on_client_close,
57 .default_handler = default_connection_handler
58};
59
60static int vhc_add_device(ddf_dev_t *dev)
61{
62 static int vhc_count = 0;
63 int rc;
64
65 if (vhc_count > 0) {
66 return ELIMIT;
67 }
68
69 vhc_data_t *data = malloc(sizeof(vhc_data_t));
70 if (data == NULL) {
71 usb_log_fatal("Failed to allocate memory.\n");
72 return ENOMEM;
73 }
74 data->magic = 0xDEADBEEF;
75 rc = usb_endpoint_manager_init(&data->ep_manager, (size_t) -1);
76 if (rc != EOK) {
77 usb_log_fatal("Failed to initialize endpoint manager.\n");
78 free(data);
79 return rc;
80 }
81 usb_device_keeper_init(&data->dev_keeper);
82
83 ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");
84 if (hc == NULL) {
85 usb_log_fatal("Failed to create device function.\n");
86 free(data);
87 return ENOMEM;
88 }
89
90 hc->ops = &vhc_ops;
91 list_initialize(&data->devices);
92 fibril_mutex_initialize(&data->guard);
93 data->hub = &virtual_hub_device;
94 data->hc_fun = hc;
95
96 dev->driver_data = data;
97
98 rc = ddf_fun_bind(hc);
99 if (rc != EOK) {
100 usb_log_fatal("Failed to bind HC function: %s.\n",
101 str_error(rc));
102 free(data);
103 return rc;
104 }
105
106 rc = ddf_fun_add_to_class(hc, USB_HC_DDF_CLASS_NAME);
107 if (rc != EOK) {
108 usb_log_fatal("Failed to add function to HC class: %s.\n",
109 str_error(rc));
110 free(data);
111 return rc;
112 }
113
114 virtual_hub_device_init(hc);
115
116 usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",
117 (size_t) dev->handle, (size_t) hc->handle);
118
119
120
121 rc = vhc_virtdev_plug_hub(data, data->hub, NULL);
122 if (rc != EOK) {
123 usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc));
124 free(data);
125 return rc;
126 }
127
128 return EOK;
129}
130
131static driver_ops_t vhc_driver_ops = {
132 .add_device = vhc_add_device,
133};
134
135static driver_t vhc_driver = {
136 .name = NAME,
137 .driver_ops = &vhc_driver_ops
138};
139
140
141int main(int argc, char * argv[])
142{
143 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
144
145 printf(NAME ": virtual USB host controller driver.\n");
146
147 return ddf_driver_main(&vhc_driver);
148}
149
150
151/**
152 * @}
153 */
Note: See TracBrowser for help on using the repository browser.