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

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

Merge mainline changes (DDF refactoring)

This merge includes DDF refactoring that brought multifunctional devices
(i.e. ddf_dev_t and ddf_fun_t). Please, see ticket #295 at HelenOS
upstream Trac.

The conflicts themselves were easy to solve (merely several renamings).

Changes to USB subsystem:

  • drivers uses ddf_dev_t and ddf_fun_t
  • different signatures of many library functions
  • several hacks around communication with parent device (now the communication is clearer and somehow what we have now is hack about other hacks)
    • will repair and clean later
  • maybe added some extra debugging messages (the diff has about 240K, and I admit I have no energy to double check that)

WARNING:

  • the diff is VERY long, recommended is viewing partial diffs of the merge (i.e. merges in mainline branch that lead to the parent one)
  • merging with your branches might involve huge renamings, sorry, no other way is possible

BUGS:

  • hub driver will not work (no function created)

GOOD NEWS:

  • QEMU keyboard seems to work with QEMU 0.13 and 0.14
  • we are up-to-date with mainline again
  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[355f7c2]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
[bd8c753d]29/** @addtogroup drvusbvhc
[355f7c2]30 * @{
[63b4f90]31 */
[355f7c2]32/** @file
[63b4f90]33 * @brief Virtual host controller driver.
[355f7c2]34 */
[63b4f90]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>
[eb1a2f4]44#include <ddf/driver.h>
[355f7c2]45
[4b4c797]46#include <usb/usb.h>
[357a302]47#include <usb/ddfiface.h>
[71ed4849]48#include <usb_iface.h>
[355f7c2]49#include "vhcd.h"
[63b4f90]50#include "hc.h"
51#include "devices.h"
52#include "hub.h"
53#include "conn.h"
[355f7c2]54
[eb1a2f4]55static ddf_dev_ops_t vhc_ops = {
[4317827]56 .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
[357a302]57 .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
[6967c14]58 .close = on_client_close,
[4317827]59 .default_handler = default_connection_handler
60};
[e27595b]61
[eb1a2f4]62static int vhc_add_device(ddf_dev_t *dev)
[355f7c2]63{
[eb1a2f4]64 static int vhc_count = 0;
65 int rc;
66
[63b4f90]67 /*
68 * Currently, we know how to simulate only single HC.
69 */
70 if (vhc_count > 0) {
71 return ELIMIT;
[355f7c2]72 }
[63b4f90]73
[eb1a2f4]74 /*
75 * Create exposed function representing the host controller
76 * itself.
77 */
78 ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");
79 if (hc == NULL) {
80 usb_log_fatal("Failed to create device function.\n");
81 return ENOMEM;
82 }
83
84 hc->ops = &vhc_ops;
[63b4f90]85
[eb1a2f4]86 rc = ddf_fun_bind(hc);
87 if (rc != EOK) {
88 usb_log_fatal("Failed to bind HC function: %s.\n",
89 str_error(rc));
90 return rc;
91 }
[7034be15]92
[eb1a2f4]93 ddf_fun_add_to_class(hc, "usbhc");
[70a9092]94
[7034be15]95 /*
[c4ba29c7]96 * Initialize our hub and announce its presence.
[7034be15]97 */
[eb1a2f4]98 virtual_hub_device_init(hc);
[7034be15]99
[eb1a2f4]100 usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",
101 (size_t) dev->handle, (size_t) hc->handle);
[e27595b]102
[7034be15]103 return EOK;
[355f7c2]104}
105
[4317827]106static driver_ops_t vhc_driver_ops = {
107 .add_device = vhc_add_device,
108};
109
110static driver_t vhc_driver = {
[63b4f90]111 .name = NAME,
[4317827]112 .driver_ops = &vhc_driver_ops
[63b4f90]113};
114
[c4ba29c7]115
[63b4f90]116int main(int argc, char * argv[])
117{
[774afaae]118 /*
119 * Temporary workaround. Wait a little bit to be the last driver
120 * in devman output.
121 */
[eb1a2f4]122 //sleep(5);
[63b4f90]123
[eb1a2f4]124 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
[c4ba29c7]125
[e63a4e1]126 printf(NAME ": virtual USB host controller driver.\n");
[e27595b]127
[1522b42]128 /*
129 * Initialize address management.
130 */
131 address_init();
132
133 /*
134 * Run the transfer scheduler.
135 */
[e63a4e1]136 hc_manager();
[f0da4eb2]137
[1522b42]138 /*
139 * We are also a driver within devman framework.
140 */
[eb1a2f4]141 return ddf_driver_main(&vhc_driver);
[355f7c2]142}
143
[63b4f90]144
[355f7c2]145/**
146 * @}
147 */
Note: See TracBrowser for help on using the repository browser.