Changes in / [4deca9b:1324ff3] in mainline
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/batch.c
r4deca9b r1324ff3 73 73 CHECK_NULL_DISPOSE_RETURN(instance, 74 74 "Failed to allocate batch instance.\n"); 75 usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size, 76 NULL, setup_size, func_in, func_out, arg, fun, NULL); 75 usb_target_t target = 76 { .address = ep->address, .endpoint = ep->endpoint }; 77 usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed, 78 ep->max_packet_size, buffer, NULL, buffer_size, NULL, setup_size, 79 func_in, func_out, arg, fun, ep, NULL); 77 80 78 81 ohci_batch_t *data = malloc(sizeof(ohci_batch_t)); … … 98 101 99 102 if (buffer_size > 0) { 100 instance-> data_buffer = malloc32(buffer_size);101 CHECK_NULL_DISPOSE_RETURN(instance-> data_buffer,103 instance->transport_buffer = malloc32(buffer_size); 104 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer, 102 105 "Failed to allocate device accessible buffer.\n"); 103 106 } … … 121 124 free32(data->tds); 122 125 free32(instance->setup_buffer); 123 free32(instance-> data_buffer);126 free32(instance->transport_buffer); 124 127 free(data); 125 128 free(instance); … … 162 165 assert(instance); 163 166 /* We are data out, we are supposed to provide data */ 164 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 167 memcpy(instance->transport_buffer, instance->buffer, 168 instance->buffer_size); 165 169 instance->next_step = batch_call_out_and_dispose; 166 170 batch_control(instance, USB_DIRECTION_OUT, USB_DIRECTION_IN); … … 179 183 { 180 184 assert(instance); 185 assert(instance->direction == USB_DIRECTION_IN); 181 186 instance->next_step = batch_call_in_and_dispose; 182 187 batch_data(instance); … … 187 192 { 188 193 assert(instance); 194 assert(instance->direction == USB_DIRECTION_OUT); 189 195 /* We are data out, we are supposed to provide data */ 190 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 196 memcpy(instance->transport_buffer, instance->buffer, 197 instance->buffer_size); 191 198 instance->next_step = batch_call_out_and_dispose; 192 199 batch_data(instance); … … 197 204 { 198 205 assert(instance); 206 instance->direction = USB_DIRECTION_IN; 199 207 instance->next_step = batch_call_in_and_dispose; 200 208 batch_data(instance); … … 205 213 { 206 214 assert(instance); 215 instance->direction = USB_DIRECTION_IN; 207 216 instance->next_step = batch_call_in_and_dispose; 208 217 batch_data(instance); … … 240 249 size_t td_current = 1; 241 250 size_t remain_size = instance->buffer_size; 242 char * buffer = instance->data_buffer;251 char *transfer_buffer = instance->transport_buffer; 243 252 while (remain_size > 0) { 244 253 size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ? … … 246 255 toggle = 1 - toggle; 247 256 248 td_init(&data->tds[td_current], data_dir, buffer,257 td_init(&data->tds[td_current], data_dir, transfer_buffer, 249 258 transfer_size, toggle); 250 259 td_set_next(&data->tds[td_current], &data->tds[td_current + 1]); … … 253 262 data->tds[td_current].next, data->tds[td_current].be); 254 263 255 buffer += transfer_size;264 transfer_buffer += transfer_size; 256 265 remain_size -= transfer_size; 257 266 assert(td_current < data->td_count - 2); … … 281 290 size_t td_current = 0; 282 291 size_t remain_size = instance->buffer_size; 283 char * buffer = instance->data_buffer;292 char *transfer_buffer = instance->transport_buffer; 284 293 while (remain_size > 0) { 285 294 size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ? … … 287 296 288 297 td_init(&data->tds[td_current], instance->ep->direction, 289 buffer, transfer_size, -1);298 transfer_buffer, transfer_size, -1); 290 299 td_set_next(&data->tds[td_current], &data->tds[td_current + 1]); 291 300 usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n", … … 293 302 data->tds[td_current].next, data->tds[td_current].be); 294 303 295 buffer += transfer_size;304 transfer_buffer += transfer_size; 296 305 remain_size -= transfer_size; 297 306 assert(td_current < data->td_count); -
uspace/drv/ohci/hc.c
r4deca9b r1324ff3 55 55 assert(hub_fun); 56 56 57 int ret;58 59 57 usb_address_t hub_address = 60 58 device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL); 61 if (hub_address <= 0) {62 usb_log_error("Failed to get OHCI root hub address.\n");63 return hub_address;64 }65 59 instance->rh.address = hub_address; 66 60 usb_device_keeper_bind( 67 61 &instance->manager, hub_address, hub_fun->handle); 68 62 69 ret = usb_endpoint_manager_add_ep(&instance->ep_manager, 70 hub_address, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, 71 USB_SPEED_FULL, 64, 0); 72 if (ret != EOK) { 73 usb_log_error("Failed to add OHCI rh endpoint 0.\n"); 74 usb_device_keeper_release(&instance->manager, hub_address); 75 return ret; 76 } 63 endpoint_t *ep = malloc(sizeof(endpoint_t)); 64 assert(ep); 65 int ret = endpoint_init(ep, hub_address, 0, USB_DIRECTION_BOTH, 66 USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64); 67 assert(ret == EOK); 68 ret = usb_endpoint_manager_register_ep(&instance->ep_manager, ep, 0); 69 assert(ret == EOK); 77 70 78 71 char *match_str = NULL; 79 /* DDF needs heap allocated string */80 72 ret = asprintf(&match_str, "usb&class=hub"); 73 // ret = (match_str == NULL) ? ret : EOK; 81 74 if (ret < 0) { 82 75 usb_log_error( 83 76 "Failed(%d) to create root hub match-id string.\n", ret); 84 usb_device_keeper_release(&instance->manager, hub_address);85 77 return ret; 86 78 } … … 88 80 ret = ddf_fun_add_match_id(hub_fun, match_str, 100); 89 81 if (ret != EOK) { 90 usb_log_error("Failed add root hub match-id.\n");82 usb_log_error("Failed add create root hub match-id.\n"); 91 83 } 92 84 return ret; … … 123 115 fibril_mutex_initialize(&instance->guard); 124 116 125 rh_init(&instance->rh, instance->registers);117 rh_init(&instance->rh, dev, instance->registers); 126 118 127 119 if (!interrupts) { … … 138 130 assert(instance); 139 131 assert(batch); 140 assert(batch->ep);141 132 142 133 /* check for root hub communication */ 143 if (batch-> ep->address == instance->rh.address) {134 if (batch->target.address == instance->rh.address) { 144 135 return rh_request(&instance->rh, batch); 145 136 } 146 137 147 138 fibril_mutex_lock(&instance->guard); 148 switch (batch-> ep->transfer_type) {139 switch (batch->transfer_type) { 149 140 case USB_TRANSFER_CONTROL: 150 141 instance->registers->control &= ~C_CLE; 151 142 transfer_list_add_batch( 152 instance->transfers[batch-> ep->transfer_type], batch);143 instance->transfers[batch->transfer_type], batch); 153 144 instance->registers->command_status |= CS_CLF; 154 145 usb_log_debug2("Set CS control transfer filled: %x.\n", … … 160 151 instance->registers->control &= ~C_BLE; 161 152 transfer_list_add_batch( 162 instance->transfers[batch-> ep->transfer_type], batch);153 instance->transfers[batch->transfer_type], batch); 163 154 instance->registers->command_status |= CS_BLF; 164 155 usb_log_debug2("Set bulk transfer filled: %x.\n", … … 170 161 instance->registers->control &= (~C_PLE & ~C_IE); 171 162 transfer_list_add_batch( 172 instance->transfers[batch-> ep->transfer_type], batch);163 instance->transfers[batch->transfer_type], batch); 173 164 instance->registers->control |= C_PLE | C_IE; 174 165 usb_log_debug2("Added periodic transfer: %x.\n", -
uspace/drv/ohci/root_hub.c
r4deca9b r1324ff3 205 205 * @return Error code. 206 206 */ 207 int rh_init(rh_t *instance, ohci_regs_t *regs) {207 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) { 208 208 assert(instance); 209 //instance->address = -1; 209 210 instance->registers = regs; 211 instance->device = dev; 210 212 instance->port_count = 211 213 (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK; 212 214 rh_init_descriptors(instance); 213 215 // set port power mode to no-power-switching 214 instance->registers->rh_desc_a |= RHDA_NPS_FLAG; 216 instance->registers->rh_desc_a = 217 instance->registers->rh_desc_a | (1<<9); 215 218 216 219 usb_log_info("OHCI root hub with %d ports.\n", instance->port_count); 220 221 //start generic usb hub driver 222 223 /* TODO: implement */ 217 224 return EOK; 218 225 } … … 230 237 assert(request); 231 238 int opResult; 232 if (request-> ep->transfer_type == USB_TRANSFER_CONTROL) {239 if (request->transfer_type == USB_TRANSFER_CONTROL) { 233 240 usb_log_info("Root hub got CONTROL packet\n"); 234 241 opResult = process_ctrl_request(instance, request); 235 } else if (request-> ep->transfer_type == USB_TRANSFER_INTERRUPT) {242 } else if (request->transfer_type == USB_TRANSFER_INTERRUPT) { 236 243 usb_log_info("Root hub got INTERRUPT packet\n"); 237 244 void * buffer; 238 245 create_interrupt_mask(instance, &buffer, 239 246 &(request->transfered_size)); 240 memcpy(request-> data_buffer, buffer,247 memcpy(request->transport_buffer, buffer, 241 248 request->transfered_size); 242 249 opResult = EOK; … … 367 374 if (port < 1 || port > instance->port_count) 368 375 return EINVAL; 369 uint32_t * uint32_buffer = (uint32_t*) request-> data_buffer;376 uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer; 370 377 request->transfered_size = 4; 371 378 uint32_buffer[0] = instance->registers->rh_port_status[port - 1]; … … 393 400 static int process_get_hub_status_request(rh_t *instance, 394 401 usb_transfer_batch_t * request) { 395 uint32_t * uint32_buffer = (uint32_t*) request-> data_buffer;402 uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer; 396 403 request->transfered_size = 4; 397 404 //bits, 0,1,16,17 … … 543 550 } 544 551 request->transfered_size = size; 545 memcpy(request-> data_buffer, result_descriptor, size);552 memcpy(request->transport_buffer, result_descriptor, size); 546 553 if (del) 547 554 free(result_descriptor); … … 564 571 if (request->buffer_size != 1) 565 572 return EINVAL; 566 request-> data_buffer[0] = 1;573 request->transport_buffer[0] = 1; 567 574 request->transfered_size = 1; 568 575 return EOK; -
uspace/drv/ohci/root_hub.h
r4deca9b r1324ff3 50 50 /** usb address of the root hub */ 51 51 usb_address_t address; 52 /** ddf device information */ 53 ddf_dev_t *device; 52 54 /** hub port count */ 53 55 int port_count; … … 56 58 } rh_t; 57 59 58 int rh_init(rh_t *instance, ohci_regs_t *regs);60 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs); 59 61 60 62 int rh_request(rh_t *instance, usb_transfer_batch_t *request); -
uspace/drv/uhci-hcd/batch.c
r4deca9b r1324ff3 30 30 */ 31 31 /** @file 32 * @brief UHCI driver USB trans ferstructure32 * @brief UHCI driver USB transaction structure 33 33 */ 34 34 #include <errno.h> … … 48 48 qh_t *qh; 49 49 td_t *tds; 50 size_t t d_count;50 size_t transfers; 51 51 } uhci_batch_t; 52 52 … … 61 61 * 62 62 * @param[in] fun DDF function to pass to callback. 63 * @param[in] ep Communication target 63 * @param[in] target Device and endpoint target of the transaction. 64 * @param[in] transfer_type Interrupt, Control or Bulk. 65 * @param[in] max_packet_size maximum allowed size of data transfers. 66 * @param[in] speed Speed of the transaction. 64 67 * @param[in] buffer Data source/destination. 65 68 * @param[in] size Size of the buffer. 66 69 * @param[in] setup_buffer Setup data source (if not NULL) 67 70 * @param[in] setup_size Size of setup_buffer (should be always 8) 68 * @param[in] func_in function to call on inbound trans fercompletion69 * @param[in] func_out function to call on outbound trans fercompletion71 * @param[in] func_in function to call on inbound transaction completion 72 * @param[in] func_out function to call on outbound transaction completion 70 73 * @param[in] arg additional parameter to func_in or func_out 74 * @param[in] ep Pointer to endpoint toggle management structure. 71 75 * @return Valid pointer if all substructures were successfully created, 72 76 * NULL otherwise. 73 77 * 74 * Determines the number of needed transfer descriptors (TDs).75 * Prepares a transport buffer (that is accessible by the hardware).76 * Initializes parameters needed for the transferand callback.78 * Determines the number of needed transfers (TDs). Prepares a transport buffer 79 * (that is accessible by the hardware). Initializes parameters needed for the 80 * transaction and callback. 77 81 */ 78 82 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, … … 99 103 usb_target_t target = 100 104 { .address = ep->address, .endpoint = ep->endpoint }; 101 usb_transfer_batch_init(instance, ep,102 buffer, NULL, buffer_size, NULL, setup_size,103 func_in, func_out, arg, fun, NULL);105 usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed, 106 ep->max_packet_size, buffer, NULL, buffer_size, NULL, setup_size, 107 func_in, func_out, arg, fun, ep, NULL); 104 108 105 109 … … 109 113 instance->private_data = data; 110 114 111 data->t d_count=115 data->transfers = 112 116 (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size; 113 117 if (ep->transfer_type == USB_TRANSFER_CONTROL) { 114 data->t d_count+= 2;115 } 116 117 data->tds = malloc32(sizeof(td_t) * data->t d_count);118 data->transfers += 2; 119 } 120 121 data->tds = malloc32(sizeof(td_t) * data->transfers); 118 122 CHECK_NULL_DISPOSE_RETURN( 119 123 data->tds, "Failed to allocate transfer descriptors.\n"); 120 bzero(data->tds, sizeof(td_t) * data->t d_count);124 bzero(data->tds, sizeof(td_t) * data->transfers); 121 125 122 126 data->qh = malloc32(sizeof(qh_t)); … … 127 131 128 132 if (buffer_size > 0) { 129 instance-> data_buffer = malloc32(buffer_size);130 CHECK_NULL_DISPOSE_RETURN(instance-> data_buffer,133 instance->transport_buffer = malloc32(buffer_size); 134 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer, 131 135 "Failed to allocate device accessible buffer.\n"); 132 136 } … … 150 154 * 151 155 * Walk all TDs. Stop with false if there is an active one (it is to be 152 * processed). Stop with true if an error is found. Return true if the last T D156 * processed). Stop with true if an error is found. Return true if the last TS 153 157 * is reached. 154 158 */ … … 160 164 161 165 usb_log_debug2("Batch(%p) checking %d transfer(s) for completion.\n", 162 instance, data->t d_count);166 instance, data->transfers); 163 167 instance->transfered_size = 0; 164 168 size_t i = 0; 165 for (;i < data->t d_count; ++i) {169 for (;i < data->transfers; ++i) { 166 170 if (td_is_active(&data->tds[i])) { 167 171 return false; … … 173 177 instance, i, data->tds[i].status); 174 178 td_print_status(&data->tds[i]); 175 176 179 assert(instance->ep != NULL); 180 177 181 endpoint_toggle_set(instance->ep, 178 182 td_toggle(&data->tds[i])); … … 191 195 } 192 196 /*----------------------------------------------------------------------------*/ 193 /** Prepares control write trans fer.194 * 195 * @param[in] instance Batch structure to use. 196 * 197 * Uses gener iccontrol function with pids OUT and IN.197 /** Prepares control write transaction. 198 * 199 * @param[in] instance Batch structure to use. 200 * 201 * Uses genercir control function with pids OUT and IN. 198 202 */ 199 203 void batch_control_write(usb_transfer_batch_t *instance) … … 201 205 assert(instance); 202 206 /* We are data out, we are supposed to provide data */ 203 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 207 memcpy(instance->transport_buffer, instance->buffer, 208 instance->buffer_size); 204 209 batch_control(instance, USB_PID_OUT, USB_PID_IN); 205 210 instance->next_step = batch_call_out_and_dispose; … … 207 212 } 208 213 /*----------------------------------------------------------------------------*/ 209 /** Prepares control read trans fer.214 /** Prepares control read transaction. 210 215 * 211 216 * @param[in] instance Batch structure to use. … … 221 226 } 222 227 /*----------------------------------------------------------------------------*/ 223 /** Prepare interrupt in trans fer.224 * 225 * @param[in] instance Batch structure to use. 226 * 227 * Data trans ferwith PID_IN.228 /** Prepare interrupt in transaction. 229 * 230 * @param[in] instance Batch structure to use. 231 * 232 * Data transaction with PID_IN. 228 233 */ 229 234 void batch_interrupt_in(usb_transfer_batch_t *instance) 230 235 { 231 236 assert(instance); 237 instance->direction = USB_DIRECTION_IN; 232 238 batch_data(instance, USB_PID_IN); 233 239 instance->next_step = batch_call_in_and_dispose; … … 235 241 } 236 242 /*----------------------------------------------------------------------------*/ 237 /** Prepare interrupt out trans fer.238 * 239 * @param[in] instance Batch structure to use. 240 * 241 * Data trans ferwith PID_OUT.243 /** Prepare interrupt out transaction. 244 * 245 * @param[in] instance Batch structure to use. 246 * 247 * Data transaction with PID_OUT. 242 248 */ 243 249 void batch_interrupt_out(usb_transfer_batch_t *instance) 244 250 { 245 251 assert(instance); 252 instance->direction = USB_DIRECTION_OUT; 246 253 /* We are data out, we are supposed to provide data */ 247 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 254 memcpy(instance->transport_buffer, instance->buffer, 255 instance->buffer_size); 248 256 batch_data(instance, USB_PID_OUT); 249 257 instance->next_step = batch_call_out_and_dispose; … … 251 259 } 252 260 /*----------------------------------------------------------------------------*/ 253 /** Prepare bulk in trans fer.254 * 255 * @param[in] instance Batch structure to use. 256 * 257 * Data trans ferwith PID_IN.261 /** Prepare bulk in transaction. 262 * 263 * @param[in] instance Batch structure to use. 264 * 265 * Data transaction with PID_IN. 258 266 */ 259 267 void batch_bulk_in(usb_transfer_batch_t *instance) … … 261 269 assert(instance); 262 270 batch_data(instance, USB_PID_IN); 271 instance->direction = USB_DIRECTION_IN; 263 272 instance->next_step = batch_call_in_and_dispose; 264 273 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance); 265 274 } 266 275 /*----------------------------------------------------------------------------*/ 267 /** Prepare bulk out trans fer.268 * 269 * @param[in] instance Batch structure to use. 270 * 271 * Data trans ferwith PID_OUT.276 /** Prepare bulk out transaction. 277 * 278 * @param[in] instance Batch structure to use. 279 * 280 * Data transaction with PID_OUT. 272 281 */ 273 282 void batch_bulk_out(usb_transfer_batch_t *instance) 274 283 { 275 284 assert(instance); 285 instance->direction = USB_DIRECTION_OUT; 276 286 /* We are data out, we are supposed to provide data */ 277 memcpy(instance->data_buffer, instance->buffer, instance->buffer_size); 287 memcpy(instance->transport_buffer, instance->buffer, 288 instance->buffer_size); 278 289 batch_data(instance, USB_PID_OUT); 279 290 instance->next_step = batch_call_out_and_dispose; … … 281 292 } 282 293 /*----------------------------------------------------------------------------*/ 283 /** Prepare generic data trans fer284 * 285 * @param[in] instance Batch structure to use. 286 * @param[in] pid Pid to use for data trans actions.287 * 288 * Transactions with alternating toggle bit and supplied pid value.294 /** Prepare generic data transaction 295 * 296 * @param[in] instance Batch structure to use. 297 * @param[in] pid Pid to use for data transfers. 298 * 299 * Packets with alternating toggle bit and supplied pid value. 289 300 * The last transfer is marked with IOC flag. 290 301 */ … … 295 306 assert(data); 296 307 297 const bool low_speed = instance-> ep->speed == USB_SPEED_LOW;308 const bool low_speed = instance->speed == USB_SPEED_LOW; 298 309 int toggle = endpoint_toggle_get(instance->ep); 299 310 assert(toggle == 0 || toggle == 1); 300 311 301 size_t t d= 0;312 size_t transfer = 0; 302 313 size_t remain_size = instance->buffer_size; 303 char *buffer = instance->data_buffer;304 314 while (remain_size > 0) { 315 char *trans_data = 316 instance->transport_buffer + instance->buffer_size 317 - remain_size; 318 305 319 const size_t packet_size = 306 (instance->ep->max_packet_size > remain_size) ? 307 remain_size : instance->ep->max_packet_size; 308 309 td_t *next_td = (td + 1 < data->td_count) 310 ? &data->tds[td + 1] : NULL; 311 312 313 usb_target_t target = 314 { instance->ep->address, instance->ep->endpoint }; 315 316 assert(td < data->td_count); 320 (instance->max_packet_size > remain_size) ? 321 remain_size : instance->max_packet_size; 322 323 td_t *next_transfer = (transfer + 1 < data->transfers) 324 ? &data->tds[transfer + 1] : NULL; 325 326 assert(transfer < data->transfers); 327 assert(packet_size <= remain_size); 328 317 329 td_init( 318 &data->tds[td], DEFAULT_ERROR_COUNT, packet_size, 319 toggle, false, low_speed, target, pid, buffer, next_td); 320 321 ++td; 330 &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size, 331 toggle, false, low_speed, instance->target, pid, trans_data, 332 next_transfer); 333 334 322 335 toggle = 1 - toggle; 323 buffer += packet_size;324 assert(packet_size <= remain_size);325 336 remain_size -= packet_size; 326 } 327 td_set_ioc(&data->tds[td - 1]); 337 ++transfer; 338 } 339 td_set_ioc(&data->tds[transfer - 1]); 328 340 endpoint_toggle_set(instance->ep, toggle); 329 341 } 330 342 /*----------------------------------------------------------------------------*/ 331 /** Prepare generic control trans fer332 * 333 * @param[in] instance Batch structure to use. 334 * @param[in] data_stage Pid to use for data t ds.335 * @param[in] status_stage Pid to use for data t ds.343 /** Prepare generic control transaction 344 * 345 * @param[in] instance Batch structure to use. 346 * @param[in] data_stage Pid to use for data transfers. 347 * @param[in] status_stage Pid to use for data transfers. 336 348 * 337 349 * Setup stage with toggle 0 and USB_PID_SETUP. … … 346 358 uhci_batch_t *data = instance->private_data; 347 359 assert(data); 348 assert(data->td_count >= 2); 349 350 const bool low_speed = instance->ep->speed == USB_SPEED_LOW; 351 const usb_target_t target = 352 { instance->ep->address, instance->ep->endpoint }; 353 360 assert(data->transfers >= 2); 361 362 const bool low_speed = instance->speed == USB_SPEED_LOW; 363 int toggle = 0; 354 364 /* setup stage */ 355 365 td_init( 356 data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, 0, false,357 low_speed, target, USB_PID_SETUP, instance->setup_buffer,366 data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false, 367 low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer, 358 368 &data->tds[1]); 359 369 360 370 /* data stage */ 361 size_t td = 1; 362 unsigned toggle = 1; 371 size_t transfer = 1; 363 372 size_t remain_size = instance->buffer_size; 364 char *buffer = instance->data_buffer;365 373 while (remain_size > 0) { 374 char *control_data = 375 instance->transport_buffer + instance->buffer_size 376 - remain_size; 377 378 toggle = 1 - toggle; 379 366 380 const size_t packet_size = 367 (instance-> ep->max_packet_size > remain_size) ?368 remain_size : instance-> ep->max_packet_size;381 (instance->max_packet_size > remain_size) ? 382 remain_size : instance->max_packet_size; 369 383 370 384 td_init( 371 &data->tds[td], DEFAULT_ERROR_COUNT, packet_size, 372 toggle, false, low_speed, target, data_stage, 373 buffer, &data->tds[td + 1]); 374 375 ++td; 376 toggle = 1 - toggle; 377 buffer += packet_size; 378 assert(td < data->td_count); 385 &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size, 386 toggle, false, low_speed, instance->target, data_stage, 387 control_data, &data->tds[transfer + 1]); 388 389 ++transfer; 390 assert(transfer < data->transfers); 379 391 assert(packet_size <= remain_size); 380 392 remain_size -= packet_size; … … 382 394 383 395 /* status stage */ 384 assert(t d == data->td_count- 1);396 assert(transfer == data->transfers - 1); 385 397 386 398 td_init( 387 &data->tds[t d], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,388 target, status_stage, NULL, NULL);389 td_set_ioc(&data->tds[t d]);399 &data->tds[transfer], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed, 400 instance->target, status_stage, NULL, NULL); 401 td_set_ioc(&data->tds[transfer]); 390 402 391 403 usb_log_debug2("Control last TD status: %x.\n", 392 data->tds[t d].status);404 data->tds[transfer].status); 393 405 } 394 406 /*----------------------------------------------------------------------------*/ … … 401 413 } 402 414 /*----------------------------------------------------------------------------*/ 403 /** Helper function , calls callback and correctly destroysbatch structure.415 /** Helper function calls callback and correctly disposes of batch structure. 404 416 * 405 417 * @param[in] instance Batch structure to use. … … 412 424 } 413 425 /*----------------------------------------------------------------------------*/ 414 /** Helper function calls callback and correctly d estroysbatch structure.426 /** Helper function calls callback and correctly disposes of batch structure. 415 427 * 416 428 * @param[in] instance Batch structure to use. … … 437 449 free32(data->qh); 438 450 free32(instance->setup_buffer); 439 free32(instance-> data_buffer);451 free32(instance->transport_buffer); 440 452 free(data); 441 453 free(instance); -
uspace/drv/uhci-hcd/hc.c
r4deca9b r1324ff3 329 329 330 330 transfer_list_t *list = 331 instance->transfers[batch-> ep->speed][batch->ep->transfer_type];331 instance->transfers[batch->speed][batch->transfer_type]; 332 332 assert(list); 333 333 transfer_list_add_batch(list, batch); -
uspace/drv/uhci-hcd/iface.c
r4deca9b r1324ff3 148 148 assert(hc); 149 149 const size_t size = max_packet_size; 150 int ret; 150 151 usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address); 151 152 if (speed >= USB_SPEED_MAX) { … … 156 157 usb_str_speed(speed), direction, size, max_packet_size, interval); 157 158 158 return usb_endpoint_manager_add_ep(&hc->ep_manager, address, endpoint, 159 direction, transfer_type, speed, max_packet_size, size); 159 160 endpoint_t *ep = malloc(sizeof(endpoint_t)); 161 if (ep == NULL) 162 return ENOMEM; 163 ret = endpoint_init(ep, address, endpoint, direction, 164 transfer_type, speed, max_packet_size); 165 if (ret != EOK) { 166 free(ep); 167 return ret; 168 } 169 170 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size); 171 if (ret != EOK) { 172 endpoint_destroy(ep); 173 } 174 return ret; 160 175 } 161 176 /*----------------------------------------------------------------------------*/ -
uspace/lib/usb/include/usb/host/batch.h
r4deca9b r1324ff3 43 43 typedef struct usb_transfer_batch usb_transfer_batch_t; 44 44 struct usb_transfer_batch { 45 endpoint_t *ep;46 45 link_t link; 46 usb_target_t target; 47 usb_transfer_type_t transfer_type; 48 usb_speed_t speed; 49 usb_direction_t direction; 47 50 usbhc_iface_transfer_in_callback_t callback_in; 48 51 usbhc_iface_transfer_out_callback_t callback_out; 49 void *arg;50 52 char *buffer; 51 char * data_buffer;53 char *transport_buffer; 52 54 size_t buffer_size; 53 55 char *setup_buffer; 54 56 size_t setup_size; 57 size_t max_packet_size; 55 58 size_t transfered_size; 56 59 void (*next_step)(usb_transfer_batch_t *); 57 60 int error; 58 61 ddf_fun_t *fun; 62 void *arg; 63 endpoint_t *ep; 59 64 void *private_data; 60 65 }; … … 62 67 void usb_transfer_batch_init( 63 68 usb_transfer_batch_t *instance, 64 endpoint_t *ep, 69 usb_target_t target, 70 usb_transfer_type_t transfer_type, 71 usb_speed_t speed, 72 size_t max_packet_size, 65 73 char *buffer, 66 char * data_buffer,74 char *transport_buffer, 67 75 size_t buffer_size, 68 76 char *setup_buffer, … … 72 80 void *arg, 73 81 ddf_fun_t *fun, 82 endpoint_t *ep, 74 83 void *private_data 75 84 ); -
uspace/lib/usb/include/usb/host/device_keeper.h
r4deca9b r1324ff3 54 54 usb_speed_t speed; 55 55 bool occupied; 56 link_t endpoints; 57 uint16_t control_used; 56 58 devman_handle_t handle; 57 59 }; … … 63 65 struct usb_device_info devices[USB_ADDRESS_COUNT]; 64 66 fibril_mutex_t guard; 67 fibril_condvar_t change; 65 68 usb_address_t last_address; 66 69 } usb_device_keeper_t; 67 70 68 71 void usb_device_keeper_init(usb_device_keeper_t *instance); 72 73 void usb_device_keeper_reserve_default_address( 74 usb_device_keeper_t *instance, usb_speed_t speed); 75 76 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance); 77 78 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance, 79 usb_target_t target, const uint8_t *setup_data); 69 80 70 81 usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance, -
uspace/lib/usb/include/usb/host/usb_endpoint_manager.h
r4deca9b r1324ff3 66 66 endpoint_t *ep, size_t data_size); 67 67 68 int usb_endpoint_manager_register_ep_wait(usb_endpoint_manager_t *instance, 69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction, 70 void *data, void (*data_remove_callback)(void* data, void* arg), void *arg, 71 size_t bw); 72 68 73 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance, 69 74 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); … … 75 80 void usb_endpoint_manager_reset_if_need( 76 81 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data); 77 78 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,79 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,80 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,81 size_t data_size)82 {83 endpoint_t *ep = malloc(sizeof(endpoint_t));84 if (ep == NULL)85 return ENOMEM;86 87 int ret = endpoint_init(ep, address, endpoint, direction, type, speed,88 max_packet_size);89 if (ret != EOK) {90 free(ep);91 return ret;92 }93 94 ret = usb_endpoint_manager_register_ep(instance, ep, data_size);95 if (ret != EOK) {96 endpoint_destroy(ep);97 return ret;98 }99 return EOK;100 }101 82 #endif 102 83 /** -
uspace/lib/usb/src/host/batch.c
r4deca9b r1324ff3 41 41 void usb_transfer_batch_init( 42 42 usb_transfer_batch_t *instance, 43 endpoint_t *ep, 43 usb_target_t target, 44 usb_transfer_type_t transfer_type, 45 usb_speed_t speed, 46 size_t max_packet_size, 44 47 char *buffer, 45 char * data_buffer,48 char *transport_buffer, 46 49 size_t buffer_size, 47 50 char *setup_buffer, … … 51 54 void *arg, 52 55 ddf_fun_t *fun, 56 endpoint_t *ep, 53 57 void *private_data 54 58 ) … … 56 60 assert(instance); 57 61 link_initialize(&instance->link); 58 instance->ep = ep; 62 instance->target = target; 63 instance->transfer_type = transfer_type; 64 instance->speed = speed; 65 instance->direction = ep->direction; 59 66 instance->callback_in = func_in; 60 67 instance->callback_out = func_out; 61 68 instance->arg = arg; 62 69 instance->buffer = buffer; 63 instance-> data_buffer = data_buffer;70 instance->transport_buffer = transport_buffer; 64 71 instance->buffer_size = buffer_size; 65 72 instance->setup_buffer = setup_buffer; 66 73 instance->setup_size = setup_size; 74 instance->max_packet_size = max_packet_size; 67 75 instance->fun = fun; 68 76 instance->private_data = private_data; … … 70 78 instance->next_step = NULL; 71 79 instance->error = EOK; 80 instance->ep = ep; 72 81 endpoint_use(instance->ep); 73 82 } … … 96 105 assert(instance); 97 106 assert(instance->callback_in); 98 assert(instance->ep);99 107 100 108 /* We are data in, we need data */ 101 memcpy(instance->buffer, instance->data_buffer, instance->buffer_size); 109 memcpy(instance->buffer, instance->transport_buffer, 110 instance->buffer_size); 102 111 103 112 usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n", 104 instance, instance->ep->address, instance->ep->endpoint, 105 usb_str_speed(instance->ep->speed), 106 usb_str_transfer_type_short(instance->ep->transfer_type), 107 instance->transfered_size, str_error(instance->error), instance->error); 113 instance, 114 instance->target.address, instance->target.endpoint, 115 usb_str_speed(instance->speed), 116 usb_str_transfer_type_short(instance->transfer_type), 117 instance->transfered_size, 118 str_error(instance->error), instance->error); 108 119 109 120 instance->callback_in(instance->fun, instance->error, … … 121 132 122 133 usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n", 123 instance, instance->ep->address, instance->ep->endpoint, 124 usb_str_speed(instance->ep->speed), 125 usb_str_transfer_type_short(instance->ep->transfer_type), 134 instance, 135 instance->target.address, instance->target.endpoint, 136 usb_str_speed(instance->speed), 137 usb_str_transfer_type_short(instance->transfer_type), 126 138 str_error(instance->error), instance->error); 127 139 -
uspace/lib/usb/src/host/device_keeper.c
r4deca9b r1324ff3 48 48 { 49 49 assert(instance); 50 fibril_mutex_initialize(&instance->guard); 51 fibril_condvar_initialize(&instance->change); 52 instance->last_address = 0; 50 53 unsigned i = 0; 51 54 for (; i < USB_ADDRESS_COUNT; ++i) { … … 57 60 // (it is needed to allow smooth registration at default address) 58 61 instance->devices[0].occupied = true; 59 instance->last_address = 0; 60 fibril_mutex_initialize(&instance->guard); 61 } 62 } 63 /*----------------------------------------------------------------------------*/ 64 /** Attempt to obtain address 0, blocks. 65 * 66 * @param[in] instance Device keeper structure to use. 67 * @param[in] speed Speed of the device requesting default address. 68 */ 69 void usb_device_keeper_reserve_default_address( 70 usb_device_keeper_t *instance, usb_speed_t speed) 71 { 72 assert(instance); 73 fibril_mutex_lock(&instance->guard); 74 while (instance->devices[USB_ADDRESS_DEFAULT].occupied) { 75 fibril_condvar_wait(&instance->change, &instance->guard); 76 } 77 instance->devices[USB_ADDRESS_DEFAULT].occupied = true; 78 instance->devices[USB_ADDRESS_DEFAULT].speed = speed; 79 fibril_mutex_unlock(&instance->guard); 80 } 81 /*----------------------------------------------------------------------------*/ 82 /** Attempt to obtain address 0, blocks. 83 * 84 * @param[in] instance Device keeper structure to use. 85 * @param[in] speed Speed of the device requesting default address. 86 */ 87 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance) 88 { 89 assert(instance); 90 fibril_mutex_lock(&instance->guard); 91 instance->devices[USB_ADDRESS_DEFAULT].occupied = false; 92 fibril_mutex_unlock(&instance->guard); 93 fibril_condvar_signal(&instance->change); 94 } 95 /*----------------------------------------------------------------------------*/ 62 96 /*----------------------------------------------------------------------------*/ 63 97 /** Get a free USB address … … 86 120 assert(new_address != USB_ADDRESS_DEFAULT); 87 121 assert(instance->devices[new_address].occupied == false); 88 89 122 instance->devices[new_address].occupied = true; 90 123 instance->devices[new_address].speed = speed; 91 124 instance->last_address = new_address; 92 93 125 fibril_mutex_unlock(&instance->guard); 94 126 return new_address; … … 106 138 assert(instance); 107 139 fibril_mutex_lock(&instance->guard); 108 109 140 assert(address > 0); 110 141 assert(address <= USB11_ADDRESS_MAX); 111 142 assert(instance->devices[address].occupied); 112 113 143 instance->devices[address].handle = handle; 114 144 fibril_mutex_unlock(&instance->guard); … … 129 159 fibril_mutex_lock(&instance->guard); 130 160 assert(instance->devices[address].occupied); 131 132 161 instance->devices[address].occupied = false; 133 162 fibril_mutex_unlock(&instance->guard); … … 148 177 while (address <= USB11_ADDRESS_MAX) { 149 178 if (instance->devices[address].handle == handle) { 150 assert(instance->devices[address].occupied);151 179 fibril_mutex_unlock(&instance->guard); 152 180 return address; … … 170 198 assert(address >= 0); 171 199 assert(address <= USB11_ADDRESS_MAX); 172 173 200 return instance->devices[address].speed; 174 201 }
Note:
See TracChangeset
for help on using the changeset viewer.