Changeset f6577d9 in mainline
- Timestamp:
- 2012-12-22T15:48:33Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f5f0cfb
- Parents:
- 01eeaaf
- Location:
- uspace/drv/bus/usb/vhc
- Files:
-
- 4 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/vhc/Makefile
r01eeaaf rf6577d9 49 49 hub/virthubops.c \ 50 50 conndev.c \ 51 connhost.c \52 51 devconn.c \ 53 hub.c \54 52 main.c \ 55 53 transfer.c -
uspace/drv/bus/usb/vhc/conndev.c
r01eeaaf rf6577d9 38 38 #include <ddf/driver.h> 39 39 #include <usbvirt/ipc.h> 40 #include <usb/debug.h> 40 41 #include <async.h> 41 #include "conn.h" 42 43 #include "vhcd.h" 42 44 43 45 static fibril_local uintptr_t plugged_device_handle = 0; -
uspace/drv/bus/usb/vhc/hub/virthub.c
r01eeaaf rf6577d9 38 38 #include <errno.h> 39 39 #include <str_error.h> 40 #include <stdio.h> 40 41 #include <assert.h> 41 42 #include <stdlib.h> -
uspace/drv/bus/usb/vhc/main.c
r01eeaaf rf6577d9 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> … … 46 41 #include <usb/host/ddf_helpers.h> 47 42 48 #include <usb/usb.h>49 43 #include <usb/ddfiface.h> 50 #include <usb _iface.h>44 #include <usb/debug.h> 51 45 #include "vhcd.h" 52 #include "hub.h" 53 #include "conn.h" 46 #include "hub/hub.h" 47 #include "hub/virthub.h" 48 49 static usbvirt_device_t virtual_hub_device = { 50 .name = "root hub", 51 .ops = &hub_ops, 52 .address = 0 53 }; 54 54 55 55 static ddf_dev_ops_t vhc_ops = { 56 #if 057 .interfaces[USBHC_DEV_IFACE] = &vhc_iface,58 .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,59 #endif60 56 .close = on_client_close, 61 57 .default_handler = default_connection_handler … … 131 127 132 128 return ret; 133 #if 0134 static int vhc_count = 0;135 int rc;136 137 if (vhc_count > 0) {138 return ELIMIT;139 }140 141 vhc_data_t *data = ddf_dev_data_alloc(dev, sizeof(vhc_data_t));142 if (data == NULL) {143 usb_log_fatal("Failed to allocate memory.\n");144 return ENOMEM;145 }146 data->magic = 0xDEADBEEF;147 rc = usb_endpoint_manager_init(&data->ep_manager, (size_t) -1,148 bandwidth_count_usb11);149 if (rc != EOK) {150 usb_log_fatal("Failed to initialize endpoint manager.\n");151 free(data);152 return rc;153 }154 usb_device_manager_init(&data->dev_manager, USB_SPEED_MAX);155 156 ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");157 if (hc == NULL) {158 usb_log_fatal("Failed to create device function.\n");159 free(data);160 return ENOMEM;161 }162 163 ddf_fun_set_ops(hc, &vhc_ops);164 list_initialize(&data->devices);165 fibril_mutex_initialize(&data->guard);166 data->hub = &virtual_hub_device;167 data->hc_fun = hc;168 169 rc = ddf_fun_bind(hc);170 if (rc != EOK) {171 usb_log_fatal("Failed to bind HC function: %s.\n",172 str_error(rc));173 free(data);174 return rc;175 }176 177 rc = ddf_fun_add_to_category(hc, USB_HC_CATEGORY);178 if (rc != EOK) {179 usb_log_fatal("Failed to add function to HC class: %s.\n",180 str_error(rc));181 free(data);182 return rc;183 }184 185 virtual_hub_device_init(hc);186 187 usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",188 (size_t) ddf_dev_get_handle(dev), (size_t) ddf_fun_get_handle(hc));189 190 rc = vhc_virtdev_plug_hub(data, data->hub, NULL);191 if (rc != EOK) {192 usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc));193 free(data);194 return rc;195 }196 197 return EOK;198 #endif199 129 } 200 130 … … 208 138 }; 209 139 210 211 140 int main(int argc, char * argv[]) 212 141 { 213 142 log_init(NAME); 214 215 143 printf(NAME ": virtual USB host controller driver.\n"); 216 144 -
uspace/drv/bus/usb/vhc/transfer.c
r01eeaaf rf6577d9 29 29 #include <errno.h> 30 30 #include <str_error.h> 31 #include <usb/debug.h> 31 32 #include <usbvirt/device.h> 32 33 #include <usbvirt/ipc.h> 33 34 #include "vhcd.h" 34 35 vhc_transfer_t *vhc_transfer_create(usb_address_t address, usb_endpoint_t ep,36 usb_direction_t dir, usb_transfer_type_t tr_type,37 ddf_fun_t *fun, void *callback_arg)38 {39 vhc_transfer_t *result = malloc(sizeof(vhc_transfer_t));40 if (result == NULL) {41 return NULL;42 }43 link_initialize(&result->link);44 result->address = address;45 result->endpoint = ep;46 result->direction = dir;47 result->transfer_type = tr_type;48 result->setup_buffer = NULL;49 result->setup_buffer_size = 0;50 result->data_buffer = NULL;51 result->data_buffer_size = 0;52 result->ddf_fun = fun;53 result->callback_arg = callback_arg;54 result->callback_in = NULL;55 result->callback_out = NULL;56 57 usb_log_debug2("Created transfer %p (%d.%d %s %s)\n", result,58 address, ep, usb_str_transfer_type_short(tr_type),59 dir == USB_DIRECTION_IN ? "in" : "out");60 61 return result;62 }63 64 static bool is_set_address_transfer(vhc_transfer_t *transfer)65 {66 if (transfer->batch->ep->endpoint != 0) {67 return false;68 }69 if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) {70 return false;71 }72 if (usb_transfer_batch_direction(transfer->batch) != USB_DIRECTION_OUT) {73 return false;74 }75 const usb_device_request_setup_packet_t *setup =76 (void*)transfer->batch->setup_buffer;77 if (setup->request_type != 0) {78 return false;79 }80 if (setup->request != USB_DEVREQ_SET_ADDRESS) {81 return false;82 }83 84 return true;85 }86 35 87 36 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch) … … 122 71 } 123 72 124 int vhc_virtdev_add_transfer(vhc_data_t *vhc, vhc_transfer_t *transfer) 125 { 126 fibril_mutex_lock(&vhc->guard); 127 128 bool target_found = false; 129 list_foreach(vhc->devices, pos) { 130 vhc_virtdev_t *dev = list_get_instance(pos, vhc_virtdev_t, link); 131 fibril_mutex_lock(&dev->guard); 132 if (dev->address == transfer->address) { 133 if (target_found) { 134 usb_log_warning("Transfer would be accepted by more devices!\n"); 135 goto next; 136 } 137 target_found = true; 138 list_append(&transfer->link, &dev->transfer_queue); 139 } 140 next: 141 fibril_mutex_unlock(&dev->guard); 142 } 143 144 fibril_mutex_unlock(&vhc->guard); 145 146 if (target_found) { 147 return EOK; 148 } else { 149 return ENOENT; 150 } 73 static bool is_set_address_transfer(vhc_transfer_t *transfer) 74 { 75 if (transfer->batch->ep->endpoint != 0) { 76 return false; 77 } 78 if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) { 79 return false; 80 } 81 if (usb_transfer_batch_direction(transfer->batch) != USB_DIRECTION_OUT) { 82 return false; 83 } 84 const usb_device_request_setup_packet_t *setup = 85 (void*)transfer->batch->setup_buffer; 86 if (setup->request_type != 0) { 87 return false; 88 } 89 if (setup->request != USB_DEVREQ_SET_ADDRESS) { 90 return false; 91 } 92 93 return true; 151 94 } 152 95 … … 234 177 return transfer; 235 178 } 236 237 179 238 180 static void execute_transfer_callback_and_free(vhc_transfer_t *transfer, … … 246 188 usb_transfer_batch_destroy(transfer->batch); 247 189 free(transfer); 248 #if 0249 assert(outcome != ENAK);250 251 usb_log_debug2("Transfer %p ended: %s.\n",252 transfer, str_error(outcome));253 254 if (transfer->direction == USB_DIRECTION_IN) {255 transfer->callback_in(outcome,256 data_transfer_size, transfer->callback_arg);257 } else {258 assert(transfer->direction == USB_DIRECTION_OUT);259 transfer->callback_out(outcome, transfer->callback_arg);260 }261 262 free(transfer);263 #endif264 190 } 265 191 … … 332 258 return EOK; 333 259 } 334 -
uspace/drv/bus/usb/vhc/vhcd.h
r01eeaaf rf6577d9 36 36 #define VHCD_VHCD_H_ 37 37 38 #include <usb/debug.h>39 38 #include <usbvirt/device.h> 40 #include <usb/host/usb_endpoint_manager.h>41 #include <usb/host/usb_device_manager.h>42 39 #include <usbhc_iface.h> 43 40 #include <async.h> … … 62 59 list_t devices; 63 60 fibril_mutex_t guard; 64 usb_endpoint_manager_t ep_manager;65 usb_device_manager_t dev_manager;66 61 usbvirt_device_t *hub; 67 62 ddf_fun_t *hc_fun; … … 70 65 typedef struct { 71 66 link_t link; 72 73 67 usb_transfer_batch_t *batch; 74 75 usb_address_t address;76 usb_endpoint_t endpoint;77 usb_direction_t direction;78 usb_transfer_type_t transfer_type;79 void *setup_buffer;80 size_t setup_buffer_size;81 void *data_buffer;82 size_t data_buffer_size;83 ddf_fun_t *ddf_fun;84 void *callback_arg;85 usbhc_iface_transfer_in_callback_t callback_in;86 usbhc_iface_transfer_out_callback_t callback_out;87 68 } vhc_transfer_t; 88 69 … … 95 76 } 96 77 78 void on_client_close(ddf_fun_t *fun); 79 void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid, 80 ipc_call_t *icall); 97 81 98 vhc_transfer_t *vhc_transfer_create(usb_address_t, usb_endpoint_t,99 usb_direction_t, usb_transfer_type_t, ddf_fun_t *, void *);100 82 int vhc_virtdev_plug(vhc_data_t *, async_sess_t *, uintptr_t *); 101 83 int vhc_virtdev_plug_local(vhc_data_t *, usbvirt_device_t *, uintptr_t *); 102 84 int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *, usb_address_t address); 103 85 void vhc_virtdev_unplug(vhc_data_t *, uintptr_t); 104 int vhc_virtdev_add_transfer(vhc_data_t *, vhc_transfer_t *);105 106 int vhc_transfer_queue_processor(void *arg);107 86 108 87 109 88 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch); 89 int vhc_transfer_queue_processor(void *arg); 110 90 111 91 #endif
Note:
See TracChangeset
for help on using the changeset viewer.