Changes in uspace/drv/vhc/connhost.c [357a302:76daaf9f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/connhost.c
r357a302 r76daaf9f 27 27 */ 28 28 29 /** @addtogroup drvusbvhc29 /** @addtogroup usb 30 30 * @{ 31 31 */ … … 36 36 #include <errno.h> 37 37 #include <usb/usb.h> 38 #include <usb/addrkeep.h> 39 #include <usb/ddfiface.h> 38 #include <usb/hcd.h> 40 39 41 40 #include "vhcd.h" 42 41 #include "conn.h" 43 42 #include "hc.h" 44 45 43 46 44 typedef struct { … … 49 47 usbhc_iface_transfer_in_callback_t in_callback; 50 48 device_t *dev; 51 size_t reported_size;52 49 void *arg; 53 50 } transfer_info_t; 54 51 55 typedef struct {56 usb_direction_t direction;57 usb_target_t target;58 usbhc_iface_transfer_out_callback_t out_callback;59 usbhc_iface_transfer_in_callback_t in_callback;60 device_t *dev;61 void *arg;62 void *data_buffer;63 size_t data_buffer_size;64 } control_transfer_info_t;65 66 52 static void universal_callback(void *buffer, size_t size, 67 int outcome, void *arg)53 usb_transaction_outcome_t outcome, void *arg) 68 54 { 69 55 transfer_info_t *transfer = (transfer_info_t *) arg; 70 71 if (transfer->reported_size != (size_t) -1) {72 size = transfer->reported_size;73 }74 56 75 57 switch (transfer->direction) { … … 102 84 transfer->arg = arg; 103 85 transfer->dev = dev; 104 transfer->reported_size = (size_t) -1;105 106 return transfer;107 }108 109 static void control_abort_prematurely(control_transfer_info_t *transfer,110 size_t size, int outcome)111 {112 switch (transfer->direction) {113 case USB_DIRECTION_IN:114 transfer->in_callback(transfer->dev,115 outcome, size,116 transfer->arg);117 break;118 case USB_DIRECTION_OUT:119 transfer->out_callback(transfer->dev,120 outcome,121 transfer->arg);122 break;123 default:124 assert(false && "unreachable");125 break;126 }127 }128 129 static void control_callback_two(void *buffer, size_t size,130 int outcome, void *arg)131 {132 control_transfer_info_t *ctrl_transfer = (control_transfer_info_t *) arg;133 134 if (outcome != EOK) {135 control_abort_prematurely(ctrl_transfer, outcome, size);136 free(ctrl_transfer);137 return;138 }139 140 transfer_info_t *transfer = create_transfer_info(ctrl_transfer->dev,141 ctrl_transfer->direction, ctrl_transfer->arg);142 transfer->out_callback = ctrl_transfer->out_callback;143 transfer->in_callback = ctrl_transfer->in_callback;144 transfer->reported_size = size;145 146 switch (ctrl_transfer->direction) {147 case USB_DIRECTION_IN:148 hc_add_transaction_to_device(false, ctrl_transfer->target,149 USB_TRANSFER_CONTROL,150 NULL, 0,151 universal_callback, transfer);152 break;153 case USB_DIRECTION_OUT:154 hc_add_transaction_from_device(ctrl_transfer->target,155 USB_TRANSFER_CONTROL,156 NULL, 0,157 universal_callback, transfer);158 break;159 default:160 assert(false && "unreachable");161 break;162 }163 164 free(ctrl_transfer);165 }166 167 static void control_callback_one(void *buffer, size_t size,168 int outcome, void *arg)169 {170 control_transfer_info_t *transfer = (control_transfer_info_t *) arg;171 172 if (outcome != EOK) {173 control_abort_prematurely(transfer, outcome, size);174 free(transfer);175 return;176 }177 178 switch (transfer->direction) {179 case USB_DIRECTION_IN:180 hc_add_transaction_from_device(transfer->target,181 USB_TRANSFER_CONTROL,182 transfer->data_buffer, transfer->data_buffer_size,183 control_callback_two, transfer);184 break;185 case USB_DIRECTION_OUT:186 hc_add_transaction_to_device(false, transfer->target,187 USB_TRANSFER_CONTROL,188 transfer->data_buffer, transfer->data_buffer_size,189 control_callback_two, transfer);190 break;191 default:192 assert(false && "unreachable");193 break;194 }195 }196 197 static control_transfer_info_t *create_control_transfer_info(device_t *dev,198 usb_direction_t direction, usb_target_t target,199 void *data_buffer, size_t data_buffer_size,200 void *arg)201 {202 control_transfer_info_t *transfer203 = malloc(sizeof(control_transfer_info_t));204 205 transfer->direction = direction;206 transfer->target = target;207 transfer->in_callback = NULL;208 transfer->out_callback = NULL;209 transfer->arg = arg;210 transfer->dev = dev;211 transfer->data_buffer = data_buffer;212 transfer->data_buffer_size = data_buffer_size;213 86 214 87 return transfer; … … 220 93 usbhc_iface_transfer_out_callback_t callback, void *arg) 221 94 { 222 usb_log_debug2("Transfer OUT [%d.%d (%s); %zu].\n",95 dprintf(3, "transfer OUT [%d.%d (%s); %zu]", 223 96 target.address, target.endpoint, 224 97 usb_str_transfer_type(transfer_type), … … 235 108 } 236 109 110 static int enqueue_transfer_setup(device_t *dev, 111 usb_target_t target, usb_transfer_type_t transfer_type, 112 void *buffer, size_t size, 113 usbhc_iface_transfer_out_callback_t callback, void *arg) 114 { 115 dprintf(3, "transfer SETUP [%d.%d (%s); %zu]", 116 target.address, target.endpoint, 117 usb_str_transfer_type(transfer_type), 118 size); 119 120 transfer_info_t *transfer 121 = create_transfer_info(dev, USB_DIRECTION_OUT, arg); 122 transfer->out_callback = callback; 123 124 hc_add_transaction_to_device(true, target, transfer_type, buffer, size, 125 universal_callback, transfer); 126 127 return EOK; 128 } 129 237 130 static int enqueue_transfer_in(device_t *dev, 238 131 usb_target_t target, usb_transfer_type_t transfer_type, … … 240 133 usbhc_iface_transfer_in_callback_t callback, void *arg) 241 134 { 242 usb_log_debug2("Transfer IN [%d.%d (%s); %zu].\n",135 dprintf(3, "transfer IN [%d.%d (%s); %zu]", 243 136 target.address, target.endpoint, 244 137 usb_str_transfer_type(transfer_type), … … 257 150 258 151 static int interrupt_out(device_t *dev, usb_target_t target, 259 size_t max_packet_size,260 152 void *data, size_t size, 261 153 usbhc_iface_transfer_out_callback_t callback, void *arg) … … 267 159 268 160 static int interrupt_in(device_t *dev, usb_target_t target, 269 size_t max_packet_size,270 161 void *data, size_t size, 271 162 usbhc_iface_transfer_in_callback_t callback, void *arg) … … 276 167 } 277 168 278 static int control_write(device_t *dev, usb_target_t target, 279 size_t max_packet_size, 280 void *setup_packet, size_t setup_packet_size, 281 void *data, size_t data_size, 282 usbhc_iface_transfer_out_callback_t callback, void *arg) 283 { 284 control_transfer_info_t *transfer 285 = create_control_transfer_info(dev, USB_DIRECTION_OUT, target, 286 data, data_size, arg); 287 transfer->out_callback = callback; 288 289 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL, 290 setup_packet, setup_packet_size, 291 control_callback_one, transfer); 292 293 return EOK; 294 } 295 296 static int control_read(device_t *dev, usb_target_t target, 297 size_t max_packet_size, 298 void *setup_packet, size_t setup_packet_size, 299 void *data, size_t data_size, 300 usbhc_iface_transfer_in_callback_t callback, void *arg) 301 { 302 control_transfer_info_t *transfer 303 = create_control_transfer_info(dev, USB_DIRECTION_IN, target, 304 data, data_size, arg); 305 transfer->in_callback = callback; 306 307 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL, 308 setup_packet, setup_packet_size, 309 control_callback_one, transfer); 310 311 return EOK; 169 static int control_write_setup(device_t *dev, usb_target_t target, 170 void *data, size_t size, 171 usbhc_iface_transfer_out_callback_t callback, void *arg) 172 { 173 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 174 data, size, 175 callback, arg); 176 } 177 178 static int control_write_data(device_t *dev, usb_target_t target, 179 void *data, size_t size, 180 usbhc_iface_transfer_out_callback_t callback, void *arg) 181 { 182 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 183 data, size, 184 callback, arg); 185 } 186 187 static int control_write_status(device_t *dev, usb_target_t target, 188 usbhc_iface_transfer_in_callback_t callback, void *arg) 189 { 190 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 191 NULL, 0, 192 callback, arg); 193 } 194 195 static int control_read_setup(device_t *dev, usb_target_t target, 196 void *data, size_t size, 197 usbhc_iface_transfer_out_callback_t callback, void *arg) 198 { 199 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 200 data, size, 201 callback, arg); 202 } 203 204 static int control_read_data(device_t *dev, usb_target_t target, 205 void *data, size_t size, 206 usbhc_iface_transfer_in_callback_t callback, void *arg) 207 { 208 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 209 data, size, 210 callback, arg); 211 } 212 213 static int control_read_status(device_t *dev, usb_target_t target, 214 usbhc_iface_transfer_out_callback_t callback, void *arg) 215 { 216 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 217 NULL, 0, 218 callback, arg); 312 219 } 313 220 314 221 static usb_address_keeping_t addresses; 222 223 224 static int reserve_default_address(device_t *dev) 225 { 226 usb_address_keeping_reserve_default(&addresses); 227 return EOK; 228 } 229 230 static int release_default_address(device_t *dev) 231 { 232 usb_address_keeping_release_default(&addresses); 233 return EOK; 234 } 235 236 static int request_address(device_t *dev, usb_address_t *address) 237 { 238 usb_address_t addr = usb_address_keeping_request(&addresses); 239 if (addr < 0) { 240 return (int)addr; 241 } 242 243 *address = addr; 244 return EOK; 245 } 246 247 static int release_address(device_t *dev, usb_address_t address) 248 { 249 return usb_address_keeping_release(&addresses, address); 250 } 251 252 static int bind_address(device_t *dev, usb_address_t address, 253 devman_handle_t handle) 254 { 255 usb_address_keeping_devman_bind(&addresses, address, handle); 256 return EOK; 257 } 315 258 316 259 static int tell_address(device_t *dev, devman_handle_t handle, … … 326 269 } 327 270 328 static int reserve_default_address(device_t *dev, usb_speed_t ignored)329 {330 usb_address_keeping_reserve_default(&addresses);331 return EOK;332 }333 334 static int release_default_address(device_t *dev)335 {336 usb_address_keeping_release_default(&addresses);337 return EOK;338 }339 340 static int request_address(device_t *dev, usb_speed_t ignored,341 usb_address_t *address)342 {343 usb_address_t addr = usb_address_keeping_request(&addresses);344 if (addr < 0) {345 return (int)addr;346 }347 348 *address = addr;349 return EOK;350 }351 352 static int release_address(device_t *dev, usb_address_t address)353 {354 return usb_address_keeping_release(&addresses, address);355 }356 357 static int bind_address(device_t *dev, usb_address_t address,358 devman_handle_t handle)359 {360 usb_address_keeping_devman_bind(&addresses, address, handle);361 return EOK;362 }363 364 271 void address_init(void) 365 272 { … … 368 275 369 276 usbhc_iface_t vhc_iface = { 277 .tell_address = tell_address, 278 370 279 .reserve_default_address = reserve_default_address, 371 280 .release_default_address = release_default_address, … … 377 286 .interrupt_in = interrupt_in, 378 287 379 .control_write = control_write, 380 .control_read = control_read 288 .control_write_setup = control_write_setup, 289 .control_write_data = control_write_data, 290 .control_write_status = control_write_status, 291 292 .control_read_setup = control_read_setup, 293 .control_read_data = control_read_data, 294 .control_read_status = control_read_status 381 295 }; 382 383 usb_iface_t vhc_usb_iface = {384 .get_hc_handle = usb_iface_get_hc_handle_hc_impl,385 .get_address = tell_address386 };387 388 296 389 297 /**
Note:
See TracChangeset
for help on using the changeset viewer.