Changeset b4b534ac in mainline for uspace/drv/bus/usb/vhc/main.c
- Timestamp:
- 2016-07-22T08:24:47Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/vhc/main.c
r5b18137 rb4b534ac 34 34 */ 35 35 36 #include <loc.h>37 #include <async.h>38 #include <unistd.h>39 #include <stdlib.h>40 #include <sysinfo.h>41 36 #include <stdio.h> 42 37 #include <errno.h> … … 44 39 #include <ddf/driver.h> 45 40 46 #include <usb/ usb.h>47 #include <usb/ddfiface.h> 48 #include <usb _iface.h>41 #include <usb/host/ddf_helpers.h> 42 43 #include <usb/debug.h> 49 44 #include "vhcd.h" 50 #include "hub.h" 51 #include "conn.h" 45 52 46 53 47 static ddf_dev_ops_t vhc_ops = { 54 .interfaces[USBHC_DEV_IFACE] = &vhc_iface,55 .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,56 48 .close = on_client_close, 57 49 .default_handler = default_connection_handler 58 50 }; 59 51 52 static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun) 53 { 54 assert(dev); 55 assert(fun); 56 57 *fun = ddf_fun_create(dev, fun_exposed, "virtual"); 58 if (!*fun) 59 return ENOMEM; 60 61 vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t)); 62 if (!vhc) { 63 ddf_fun_destroy(*fun); 64 } 65 ddf_fun_set_ops(*fun, &vhc_ops); 66 const int ret = ddf_fun_bind(*fun); 67 if (ret != EOK) { 68 ddf_fun_destroy(*fun); 69 *fun = NULL; 70 return ret; 71 } 72 vhc_init(vhc); 73 return EOK; 74 } 75 76 hcd_ops_t vhc_hc_ops = { 77 .schedule = vhc_schedule, 78 }; 79 60 80 static int vhc_dev_add(ddf_dev_t *dev) 61 81 { 62 static int vhc_count = 0; 63 int rc; 82 /* Initialize virtual structure */ 83 ddf_fun_t *ctl_fun = NULL; 84 int ret = vhc_control_node(dev, &ctl_fun); 85 if (ret != EOK) { 86 usb_log_error("Failed to setup control node.\n"); 87 return ret; 88 } 89 vhc_data_t *data = ddf_fun_data_get(ctl_fun); 64 90 65 if (vhc_count > 0) { 66 return ELIMIT; 91 /* Initialize generic structures */ 92 ret = hcd_ddf_setup_hc(dev, USB_SPEED_FULL, 93 BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11); 94 if (ret != EOK) { 95 usb_log_error("Failed to init HCD structures: %s.\n", 96 str_error(ret)); 97 ddf_fun_destroy(ctl_fun); 98 return ret; 67 99 } 68 100 69 vhc_data_t *data = ddf_dev_data_alloc(dev, 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 bandwidth_count_usb11); 77 if (rc != EOK) { 78 usb_log_fatal("Failed to initialize endpoint manager.\n"); 79 free(data); 80 return rc; 81 } 82 usb_device_manager_init(&data->dev_manager, USB_SPEED_MAX); 101 hcd_set_implementation(dev_to_hcd(dev), data, &vhc_hc_ops); 83 102 84 ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc"); 85 if (hc == NULL) { 86 usb_log_fatal("Failed to create device function.\n"); 87 free(data); 88 return ENOMEM; 103 /* Add virtual hub device */ 104 ret = vhc_virtdev_plug_hub(data, &data->hub, NULL, 0); 105 if (ret != EOK) { 106 usb_log_error("Failed to plug root hub: %s.\n", str_error(ret)); 107 ddf_fun_destroy(ctl_fun); 108 return ret; 89 109 } 90 110 91 ddf_fun_set_ops(hc, &vhc_ops); 92 list_initialize(&data->devices); 93 fibril_mutex_initialize(&data->guard); 94 data->hub = &virtual_hub_device; 95 data->hc_fun = hc; 96 97 rc = ddf_fun_bind(hc); 98 if (rc != EOK) { 99 usb_log_fatal("Failed to bind HC function: %s.\n", 100 str_error(rc)); 101 free(data); 102 return rc; 111 /* 112 * Creating root hub registers a new USB device so HC 113 * needs to be ready at this time. 114 */ 115 ret = hcd_ddf_setup_root_hub(dev); 116 if (ret != EOK) { 117 usb_log_error("Failed to init VHC root hub: %s\n", 118 str_error(ret)); 119 // TODO do something here... 103 120 } 104 121 105 rc = ddf_fun_add_to_category(hc, USB_HC_CATEGORY); 106 if (rc != EOK) { 107 usb_log_fatal("Failed to add function to HC class: %s.\n", 108 str_error(rc)); 109 free(data); 110 return rc; 111 } 112 113 virtual_hub_device_init(hc); 114 115 usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n", 116 (size_t) ddf_dev_get_handle(dev), (size_t) ddf_fun_get_handle(hc)); 117 118 rc = vhc_virtdev_plug_hub(data, data->hub, NULL); 119 if (rc != EOK) { 120 usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc)); 121 free(data); 122 return rc; 123 } 124 125 return EOK; 122 return ret; 126 123 } 127 124 … … 135 132 }; 136 133 137 138 134 int main(int argc, char * argv[]) 139 { 135 { 140 136 log_init(NAME); 141 142 137 printf(NAME ": virtual USB host controller driver.\n"); 143 138 … … 145 140 } 146 141 147 148 142 /** 149 143 * @}
Note:
See TracChangeset
for help on using the changeset viewer.