source: mainline/uspace/drv/vhc/devconn.c@ 6cb58e6

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

Virtual USB layer rewritten

Major changes include

  • IPC sends whole transfers (not transactions)
  • separate transfer queues for each device in host controller
  • possibility to return NAK from virtual device (handled by HC)
  • better implementation of callbacks for non-zero endpoints

Still missing

  • communication for some transfer types (bulk)
  • face-lift ;-)
  • documentation
  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include <errno.h>
2#include "vhcd.h"
3#include "hub/virthub.h"
4
5
6static vhc_virtdev_t *vhc_virtdev_create()
7{
8 vhc_virtdev_t *dev = malloc(sizeof(vhc_virtdev_t));
9 if (dev == NULL) {
10 return NULL;
11 }
12 dev->address = 0;
13 dev->dev_phone = -1;
14 dev->dev_local = NULL;
15 dev->plugged = true;
16 link_initialize(&dev->link);
17 fibril_mutex_initialize(&dev->guard);
18 list_initialize(&dev->transfer_queue);
19
20 return dev;
21}
22
23static int vhc_virtdev_plug_generic(vhc_data_t *vhc,
24 int phone, usbvirt_device_t *virtdev,
25 uintptr_t *handle, bool connect)
26{
27 vhc_virtdev_t *dev = vhc_virtdev_create();
28 if (dev == NULL) {
29 return ENOMEM;
30 }
31
32 dev->dev_phone = phone;
33 dev->dev_local = virtdev;
34
35 fibril_mutex_lock(&vhc->guard);
36 list_append(&dev->link, &vhc->devices);
37 fibril_mutex_unlock(&vhc->guard);
38
39 fid_t fibril = fibril_create(vhc_transfer_queue_processor, dev);
40 if (fibril == 0) {
41 free(dev);
42 return ENOMEM;
43 }
44 fibril_add_ready(fibril);
45
46 if (handle != NULL) {
47 *handle = (uintptr_t) dev;
48 }
49
50 if (connect) {
51 // FIXME: check status
52 (void) virthub_connect_device(vhc->hub, dev);
53 }
54
55 return EOK;
56}
57
58int vhc_virtdev_plug(vhc_data_t *vhc, int phone, uintptr_t *handle)
59{
60 return vhc_virtdev_plug_generic(vhc, phone, NULL, handle, true);
61}
62
63int vhc_virtdev_plug_local(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
64{
65 return vhc_virtdev_plug_generic(vhc, -1, dev, handle, true);
66}
67
68int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
69{
70 return vhc_virtdev_plug_generic(vhc, -1, dev, handle, false);
71}
72
73void vhc_virtdev_unplug(vhc_data_t *vhc, uintptr_t handle)
74{
75 vhc_virtdev_t *dev = (vhc_virtdev_t *) handle;
76
77 // FIXME: check status
78 (void) virthub_disconnect_device(vhc->hub, dev);
79
80 fibril_mutex_lock(&vhc->guard);
81 fibril_mutex_lock(&dev->guard);
82 dev->plugged = false;
83 list_remove(&dev->link);
84 fibril_mutex_unlock(&dev->guard);
85 fibril_mutex_unlock(&vhc->guard);
86}
Note: See TracBrowser for help on using the repository browser.