Changeset 32fb6bce in mainline for uspace/drv/bus/usb/vhc
- Timestamp:
- 2017-12-18T22:50:21Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f70d1c
- Parents:
- 1ea0bbf
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
- Location:
- uspace/drv/bus/usb/vhc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/vhc/main.c
r1ea0bbf r32fb6bce 69 69 return ret; 70 70 } 71 vhc_init(vhc, dev_to_hcd(dev));72 71 return EOK; 73 72 } 74 73 75 hcd_ops_t vhc_hc_ops = {76 .schedule = vhc_schedule,77 };78 79 74 static int vhc_dev_add(ddf_dev_t *dev) 80 75 { 76 /* Initialize generic structures */ 77 int ret = hcd_ddf_setup_hc(dev, sizeof(vhc_data_t)); 78 if (ret != EOK) { 79 usb_log_error("Failed to init HCD structures: %s.\n", 80 str_error(ret)); 81 return ret; 82 } 83 vhc_data_t *vhc = ddf_dev_data_get(dev); 84 vhc_init(vhc); 85 86 hc_device_setup(&vhc->base, (bus_t *) &vhc->bus); 87 81 88 /* Initialize virtual structure */ 82 89 ddf_fun_t *ctl_fun = NULL; 83 intret = vhc_control_node(dev, &ctl_fun);90 ret = vhc_control_node(dev, &ctl_fun); 84 91 if (ret != EOK) { 85 92 usb_log_error("Failed to setup control node.\n"); 86 93 return ret; 87 94 } 88 vhc_data_t *data = ddf_fun_data_get(ctl_fun);89 90 /* Initialize generic structures */91 ret = hcd_ddf_setup_hc(dev);92 if (ret != EOK) {93 usb_log_error("Failed to init HCD structures: %s.\n",94 str_error(ret));95 ddf_fun_destroy(ctl_fun);96 return ret;97 }98 99 hcd_set_implementation(dev_to_hcd(dev), data, &vhc_hc_ops, &data->bus.base);100 95 101 96 /* Add virtual hub device */ 102 ret = vhc_virtdev_plug_hub( data, &data->hub, NULL, 0);97 ret = vhc_virtdev_plug_hub(vhc, &vhc->hub, NULL, 0); 103 98 if (ret != EOK) { 104 99 usb_log_error("Failed to plug root hub: %s.\n", str_error(ret)); … … 111 106 * needs to be ready at this time. 112 107 */ 113 ret = hcd_setup_virtual_root_hub( dev_to_hcd(dev), dev);108 ret = hcd_setup_virtual_root_hub(&vhc->base); 114 109 if (ret != EOK) { 115 110 usb_log_error("Failed to init VHC root hub: %s\n", -
uspace/drv/bus/usb/vhc/transfer.c
r1ea0bbf r32fb6bce 40 40 static bool is_set_address_transfer(vhc_transfer_t *transfer) 41 41 { 42 if (transfer->batch ->target.endpoint != 0) {43 return false; 44 } 45 if (transfer->batch ->ep->transfer_type != USB_TRANSFER_CONTROL) {46 return false; 47 } 48 if (transfer->batch ->dir != USB_DIRECTION_OUT) {42 if (transfer->batch.target.endpoint != 0) { 43 return false; 44 } 45 if (transfer->batch.ep->transfer_type != USB_TRANSFER_CONTROL) { 46 return false; 47 } 48 if (transfer->batch.dir != USB_DIRECTION_OUT) { 49 49 return false; 50 50 } 51 51 const usb_device_request_setup_packet_t *setup 52 = &transfer->batch ->setup.packet;52 = &transfer->batch.setup.packet; 53 53 if (setup->request_type != 0) { 54 54 return false; … … 150 150 assert(outcome != ENAK); 151 151 assert(transfer); 152 assert(transfer->batch); 153 transfer->batch->error = outcome; 154 transfer->batch->transfered_size = data_transfer_size; 155 usb_transfer_batch_finish(transfer->batch); 152 transfer->batch.error = outcome; 153 transfer->batch.transfered_size = data_transfer_size; 154 usb_transfer_batch_finish(&transfer->batch); 156 155 free(transfer); 156 } 157 158 static usb_transfer_batch_t *batch_create(endpoint_t *ep) 159 { 160 vhc_transfer_t *transfer = calloc(1, sizeof(vhc_transfer_t)); 161 usb_transfer_batch_init(&transfer->batch, ep); 162 link_initialize(&transfer->link); 163 return &transfer->batch; 157 164 } 158 165 159 166 static const bus_ops_t vhc_bus_ops = { 160 167 .parent = &usb2_bus_ops, 168 161 169 .endpoint_count_bw = bandwidth_count_usb11, 170 .batch_create = batch_create, 171 .batch_schedule = vhc_schedule, 162 172 }; 163 173 164 int vhc_init(vhc_data_t *instance , hcd_t *hcd)174 int vhc_init(vhc_data_t *instance) 165 175 { 166 176 assert(instance); 167 177 list_initialize(&instance->devices); 168 178 fibril_mutex_initialize(&instance->guard); 169 usb2_bus_init(&instance->bus, hcd,BANDWIDTH_AVAILABLE_USB11);179 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11); 170 180 instance->bus.base.ops = &vhc_bus_ops; 171 instance->magic = 0xDEADBEEF;172 181 return virthub_init(&instance->hub, "root hub"); 173 182 } 174 183 175 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch) 176 { 177 assert(hcd); 184 int vhc_schedule(usb_transfer_batch_t *batch) 185 { 178 186 assert(batch); 179 vhc_data_t *vhc = hcd_get_driver_data(hcd); 187 vhc_transfer_t *transfer = (vhc_transfer_t *) batch; 188 vhc_data_t *vhc = bus_to_vhc(endpoint_get_bus(batch->ep)); 180 189 assert(vhc); 181 182 vhc_transfer_t *transfer = malloc(sizeof(vhc_transfer_t));183 if (!transfer)184 return ENOMEM;185 link_initialize(&transfer->link);186 transfer->batch = batch;187 190 188 191 fibril_mutex_lock(&vhc->guard); … … 192 195 list_foreach(vhc->devices, link, vhc_virtdev_t, dev) { 193 196 fibril_mutex_lock(&dev->guard); 194 if (dev->address == transfer->batch ->target.address) {197 if (dev->address == transfer->batch.target.address) { 195 198 if (!targets) { 196 199 list_append(&transfer->link, &dev->transfer_queue); … … 227 230 size_t data_transfer_size = 0; 228 231 if (dev->dev_sess) { 229 rc = process_transfer_remote( transfer->batch,232 rc = process_transfer_remote(&transfer->batch, 230 233 dev->dev_sess, &data_transfer_size); 231 234 } else if (dev->dev_local != NULL) { 232 rc = process_transfer_local( transfer->batch,235 rc = process_transfer_local(&transfer->batch, 233 236 dev->dev_local, &data_transfer_size); 234 237 } else { … … 244 247 if (is_set_address_transfer(transfer)) { 245 248 usb_device_request_setup_packet_t *setup = 246 (void*) transfer->batch ->setup.buffer;249 (void*) transfer->batch.setup.buffer; 247 250 dev->address = setup->value; 248 251 usb_log_debug2("Address changed to %d\n", -
uspace/drv/bus/usb/vhc/vhcd.h
r1ea0bbf r32fb6bce 39 39 #include <usbvirt/device.h> 40 40 #include <async.h> 41 #include <macros.h> 41 42 42 43 #include <usb/host/hcd.h> 43 44 #include <usb/host/usb2_bus.h> 45 #include <usb/host/usb_transfer_batch.h> 44 46 45 47 #define NAME "vhc" … … 56 58 57 59 typedef struct { 58 uint32_t magic; 60 hc_device_t base; 61 62 usb2_bus_t bus; 63 ddf_fun_t *virtual_fun; 59 64 list_t devices; 60 65 fibril_mutex_t guard; 61 66 usbvirt_device_t hub; 62 usb2_bus_t bus;63 67 } vhc_data_t; 64 68 65 69 typedef struct { 70 usb_transfer_batch_t batch; 66 71 link_t link; 67 usb_transfer_batch_t *batch;68 72 } vhc_transfer_t; 73 74 static inline vhc_data_t *hcd_to_vhc(hc_device_t *hcd) 75 { 76 assert(hcd); 77 return (vhc_data_t *) hcd; 78 } 79 80 static inline vhc_data_t *bus_to_vhc(bus_t *bus) 81 { 82 assert(bus); 83 return member_to_inst(bus, vhc_data_t, bus); 84 } 69 85 70 86 void on_client_close(ddf_fun_t *fun); … … 77 93 void vhc_virtdev_unplug(vhc_data_t *, uintptr_t); 78 94 79 int vhc_init(vhc_data_t * instance, hcd_t *);80 int vhc_schedule( hcd_t *hcd, usb_transfer_batch_t *batch);95 int vhc_init(vhc_data_t *); 96 int vhc_schedule(usb_transfer_batch_t *); 81 97 int vhc_transfer_queue_processor(void *arg); 82 98
Note:
See TracChangeset
for help on using the changeset viewer.
