source: mainline/uspace/drv/vhc/hcd.c@ ace12560

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ace12560 was 357a302, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

USB interfaces reorganization

The most important change is that getting USB address of a device
is an operation of generic USB interface, not USB-HC interface.
That is needed for proper functionality of a MID driver.

Also added sample implementation of USB interface operations as is
needed by most drivers (sample does not mean unfunctional or partially
implemented here).
They are stored in libusb/ddfiface.h

Updated UHCI, UHCI-RH, hub, VHC drivers to use these sample
implementations.

Updated libusb device recognition routines to route get_address requests
through USB interface.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2010 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 * @brief Virtual host controller driver.
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 <driver.h>
45
46#include <usb/usb.h>
47#include <usb/ddfiface.h>
48#include <usb_iface.h>
49#include "vhcd.h"
50#include "hc.h"
51#include "devices.h"
52#include "hub.h"
53#include "conn.h"
54
55static device_ops_t vhc_ops = {
56 .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
57 .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
58 .close = on_client_close,
59 .default_handler = default_connection_handler
60};
61
62static int vhc_count = 0;
63static int vhc_add_device(device_t *dev)
64{
65 /*
66 * Currently, we know how to simulate only single HC.
67 */
68 if (vhc_count > 0) {
69 return ELIMIT;
70 }
71
72 vhc_count++;
73
74 dev->ops = &vhc_ops;
75
76 devman_add_device_to_class(dev->handle, "usbhc");
77
78 /*
79 * Initialize our hub and announce its presence.
80 */
81 virtual_hub_device_init(dev);
82
83 usb_log_info("Virtual USB host controller ready (id = %zu).\n",
84 (size_t) dev->handle);
85
86 return EOK;
87}
88
89static driver_ops_t vhc_driver_ops = {
90 .add_device = vhc_add_device,
91};
92
93static driver_t vhc_driver = {
94 .name = NAME,
95 .driver_ops = &vhc_driver_ops
96};
97
98
99int main(int argc, char * argv[])
100{
101 /*
102 * Temporary workaround. Wait a little bit to be the last driver
103 * in devman output.
104 */
105 sleep(5);
106
107 usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
108
109 printf(NAME ": virtual USB host controller driver.\n");
110
111 /*
112 * Initialize address management.
113 */
114 address_init();
115
116 /*
117 * Run the transfer scheduler.
118 */
119 hc_manager();
120
121 /*
122 * We are also a driver within devman framework.
123 */
124 return driver_main(&vhc_driver);
125}
126
127
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.