Changeset c6394aa in mainline for uspace/lib/usb/src
- Timestamp:
- 2011-04-09T16:56:51Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 77223f8
- Parents:
- b6c9e1e (diff), 5410c04 (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. - Location:
- uspace/lib/usb/src
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/devdrv.c
rb6c9e1e rc6394aa 161 161 162 162 /* 163 * For further actions, we need open session on default control pipe. 163 * We will do some querying of the device, it is worth to prepare 164 * the long transfer. 164 165 */ 165 rc = usb_pipe_start_ session(&dev->ctrl_pipe);166 if (rc != EOK) { 167 usb_log_error("Failed to start an IPC session: %s.\n",166 rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe); 167 if (rc != EOK) { 168 usb_log_error("Failed to start transfer: %s.\n", 168 169 str_error(rc)); 169 170 return rc; … … 185 186 } 186 187 187 /* No checking here. */ 188 usb_pipe_end_session(&dev->ctrl_pipe); 188 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 189 189 190 190 /* Rollback actions. */ -
uspace/lib/usb/src/devpoll.c
rb6c9e1e rc6394aa 77 77 int rc; 78 78 79 rc = usb_pipe_start_session(pipe);80 if (rc != EOK) {81 failed_attempts++;82 continue;83 }84 85 79 size_t actual_size; 86 80 rc = usb_pipe_read(pipe, polling_data->buffer, 87 81 polling_data->request_size, &actual_size); 88 82 89 /* Quit the session regardless of errors. */90 usb_pipe_end_session(pipe);91 83 92 84 // if (rc == ESTALL) { -
uspace/lib/usb/src/host/batch.c
rb6c9e1e rc6394aa 63 63 instance->transfer_type = transfer_type; 64 64 instance->speed = speed; 65 instance->direction = USB_DIRECTION_BOTH;65 instance->direction = ep->direction; 66 66 instance->callback_in = func_in; 67 67 instance->callback_out = func_out; -
uspace/lib/usb/src/hub.c
rb6c9e1e rc6394aa 288 288 } 289 289 290 291 rc = usb_pipe_start_session(&ctrl_pipe); 292 if (rc != EOK) { 293 rc = ENOTCONN; 290 rc = usb_request_set_address(&ctrl_pipe, dev_addr); 291 if (rc != EOK) { 292 rc = ESTALL; 294 293 goto leave_release_default_address; 295 294 } 296 297 rc = usb_request_set_address(&ctrl_pipe, dev_addr);298 if (rc != EOK) {299 rc = ESTALL;300 goto leave_stop_session;301 }302 303 usb_pipe_end_session(&ctrl_pipe);304 295 305 296 /* … … 361 352 * Completely ignoring errors here. 362 353 */ 363 364 leave_stop_session:365 usb_pipe_end_session(&ctrl_pipe);366 367 354 leave_release_default_address: 368 355 usb_pipe_unregister(&ctrl_pipe, &hc_conn); -
uspace/lib/usb/src/pipes.c
rb6c9e1e rc6394aa 41 41 #include <errno.h> 42 42 #include <assert.h> 43 #include "pipepriv.h" 43 44 44 45 #define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */ … … 241 242 * necessary. 242 243 * 244 * @deprecated 245 * Obsoleted with introduction of usb_pipe_start_long_transfer 246 * 243 247 * @param pipe Endpoint pipe to start the session on. 244 248 * @return Error code. … … 246 250 int usb_pipe_start_session(usb_pipe_t *pipe) 247 251 { 248 assert(pipe); 249 250 if (usb_pipe_is_session_started(pipe)) { 251 return EBUSY; 252 } 253 254 int phone = devman_device_connect(pipe->wire->hc_handle, 0); 255 if (phone < 0) { 256 return phone; 257 } 258 259 pipe->hc_phone = phone; 260 252 usb_log_warning("usb_pipe_start_session() was deprecated.\n"); 261 253 return EOK; 262 254 } … … 265 257 /** Ends a session on the endpoint pipe. 266 258 * 259 * @deprecated 260 * Obsoleted with introduction of usb_pipe_end_long_transfer 261 * 267 262 * @see usb_pipe_start_session 268 263 * … … 272 267 int usb_pipe_end_session(usb_pipe_t *pipe) 273 268 { 274 assert(pipe); 275 276 if (!usb_pipe_is_session_started(pipe)) { 277 return ENOENT; 278 } 279 280 int rc = async_hangup(pipe->hc_phone); 281 if (rc != EOK) { 282 return rc; 283 } 284 285 pipe->hc_phone = -1; 286 269 usb_log_warning("usb_pipe_end_session() was deprecated.\n"); 287 270 return EOK; 288 271 } … … 298 281 bool usb_pipe_is_session_started(usb_pipe_t *pipe) 299 282 { 300 return (pipe->hc_phone >= 0); 283 pipe_acquire(pipe); 284 bool started = pipe->refcount > 0; 285 pipe_release(pipe); 286 return started; 287 } 288 289 /** Prepare pipe for a long transfer. 290 * 291 * By a long transfer is mean transfer consisting of several 292 * requests to the HC. 293 * Calling such function is optional and it has positive effect of 294 * improved performance because IPC session is initiated only once. 295 * 296 * @param pipe Pipe over which the transfer will happen. 297 * @return Error code. 298 */ 299 int usb_pipe_start_long_transfer(usb_pipe_t *pipe) 300 { 301 return pipe_add_ref(pipe); 302 } 303 304 /** Terminate a long transfer on a pipe. 305 * 306 * @see usb_pipe_start_long_transfer 307 * 308 * @param pipe Pipe where to end the long transfer. 309 */ 310 void usb_pipe_end_long_transfer(usb_pipe_t *pipe) 311 { 312 pipe_drop_ref(pipe); 301 313 } 302 314 -
uspace/lib/usb/src/pipesinit.c
rb6c9e1e rc6394aa 356 356 assert(connection); 357 357 358 fibril_mutex_initialize(&pipe->guard); 358 359 pipe->wire = connection; 359 360 pipe->hc_phone = -1; 361 fibril_mutex_initialize(&pipe->hc_phone_mutex); 360 362 pipe->endpoint_no = endpoint_no; 361 363 pipe->transfer_type = transfer_type; 362 364 pipe->max_packet_size = max_packet_size; 363 365 pipe->direction = direction; 366 pipe->refcount = 0; 364 367 365 368 return EOK; … … 413 416 int rc; 414 417 415 TRY_LOOP(failed_attempts) { 416 rc = usb_pipe_start_session(pipe); 417 if (rc == EOK) { 418 break; 419 } 420 } 418 rc = usb_pipe_start_long_transfer(pipe); 421 419 if (rc != EOK) { 422 420 return rc; … … 439 437 } 440 438 } 441 usb_pipe_end_ session(pipe);439 usb_pipe_end_long_transfer(pipe); 442 440 if (rc != EOK) { 443 441 return rc; -
uspace/lib/usb/src/pipesio.c
rb6c9e1e rc6394aa 49 49 #include <assert.h> 50 50 #include <usbhc_iface.h> 51 #include "pipepriv.h" 51 52 52 53 /** Request an in transfer, no checking of input parameters. … … 78 79 } 79 80 81 /* Ensure serialization over the phone. */ 82 pipe_start_transaction(pipe); 83 80 84 /* 81 85 * Make call identifying target USB device and type of transfer. … … 87 91 NULL); 88 92 if (opening_request == 0) { 93 pipe_end_transaction(pipe); 89 94 return ENOMEM; 90 95 } … … 96 101 aid_t data_request = async_data_read(pipe->hc_phone, buffer, size, 97 102 &data_request_call); 103 104 /* 105 * Since now on, someone else might access the backing phone 106 * without breaking the transfer IPC protocol. 107 */ 108 pipe_end_transaction(pipe); 98 109 99 110 if (data_request == 0) { … … 146 157 147 158 if (buffer == NULL) { 148 159 return EINVAL; 149 160 } 150 161 151 162 if (size == 0) { 152 163 return EINVAL; 153 }154 155 if (!usb_pipe_is_session_started(pipe)) {156 return EBADF;157 164 } 158 165 … … 165 172 } 166 173 174 int rc; 175 rc = pipe_add_ref(pipe); 176 if (rc != EOK) { 177 return rc; 178 } 179 180 167 181 size_t act_size = 0; 168 int rc;169 182 170 183 rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size); 184 185 pipe_drop_ref(pipe); 186 171 187 if (rc != EOK) { 172 188 return rc; … … 210 226 } 211 227 228 /* Ensure serialization over the phone. */ 229 pipe_start_transaction(pipe); 230 212 231 /* 213 232 * Make call identifying target USB device and type of transfer. … … 219 238 NULL); 220 239 if (opening_request == 0) { 240 pipe_end_transaction(pipe); 221 241 return ENOMEM; 222 242 } … … 226 246 */ 227 247 int rc = async_data_write_start(pipe->hc_phone, buffer, size); 248 249 /* 250 * Since now on, someone else might access the backing phone 251 * without breaking the transfer IPC protocol. 252 */ 253 pipe_end_transaction(pipe); 254 228 255 if (rc != EOK) { 229 256 async_wait_for(opening_request, NULL); … … 260 287 } 261 288 262 if (!usb_pipe_is_session_started(pipe)) {263 return EBADF;264 }265 266 289 if (pipe->direction != USB_DIRECTION_OUT) { 267 290 return EBADF; … … 272 295 } 273 296 274 int rc = usb_pipe_write_no_check(pipe, buffer, size); 297 int rc; 298 299 rc = pipe_add_ref(pipe); 300 if (rc != EOK) { 301 return rc; 302 } 303 304 rc = usb_pipe_write_no_check(pipe, buffer, size); 305 306 pipe_drop_ref(pipe); 275 307 276 308 return rc; … … 293 325 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size) 294 326 { 327 /* Ensure serialization over the phone. */ 328 pipe_start_transaction(pipe); 329 295 330 /* 296 331 * Make call identifying target USB device and control transfer type. … … 311 346 setup_buffer, setup_buffer_size); 312 347 if (rc != EOK) { 348 pipe_end_transaction(pipe); 313 349 async_wait_for(opening_request, NULL); 314 350 return rc; … … 322 358 data_buffer, data_buffer_size, 323 359 &data_request_call); 360 361 /* 362 * Since now on, someone else might access the backing phone 363 * without breaking the transfer IPC protocol. 364 */ 365 pipe_end_transaction(pipe); 366 367 324 368 if (data_request == 0) { 325 369 async_wait_for(opening_request, NULL); … … 379 423 } 380 424 381 if (!usb_pipe_is_session_started(pipe)) {382 return EBADF;383 }384 385 425 if ((pipe->direction != USB_DIRECTION_BOTH) 386 426 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 388 428 } 389 429 430 int rc; 431 432 rc = pipe_add_ref(pipe); 433 if (rc != EOK) { 434 return rc; 435 } 436 390 437 size_t act_size = 0; 391 intrc = usb_pipe_control_read_no_check(pipe,438 rc = usb_pipe_control_read_no_check(pipe, 392 439 setup_buffer, setup_buffer_size, 393 440 data_buffer, data_buffer_size, &act_size); 441 442 pipe_drop_ref(pipe); 394 443 395 444 if (rc != EOK) { … … 418 467 void *data_buffer, size_t data_buffer_size) 419 468 { 469 /* Ensure serialization over the phone. */ 470 pipe_start_transaction(pipe); 471 420 472 /* 421 473 * Make call identifying target USB device and control transfer type. … … 428 480 NULL); 429 481 if (opening_request == 0) { 482 pipe_end_transaction(pipe); 430 483 return ENOMEM; 431 484 } … … 437 490 setup_buffer, setup_buffer_size); 438 491 if (rc != EOK) { 492 pipe_end_transaction(pipe); 439 493 async_wait_for(opening_request, NULL); 440 494 return rc; … … 447 501 rc = async_data_write_start(pipe->hc_phone, 448 502 data_buffer, data_buffer_size); 503 504 /* All data sent, pipe can be released. */ 505 pipe_end_transaction(pipe); 506 449 507 if (rc != EOK) { 450 508 async_wait_for(opening_request, NULL); 451 509 return rc; 452 510 } 511 } else { 512 /* No data to send, we can release the pipe for others. */ 513 pipe_end_transaction(pipe); 453 514 } 454 515 … … 491 552 } 492 553 493 if (!usb_pipe_is_session_started(pipe)) {494 return EBADF;495 }496 497 554 if ((pipe->direction != USB_DIRECTION_BOTH) 498 555 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 500 557 } 501 558 502 int rc = usb_pipe_control_write_no_check(pipe, 559 int rc; 560 561 rc = pipe_add_ref(pipe); 562 if (rc != EOK) { 563 return rc; 564 } 565 566 rc = usb_pipe_control_write_no_check(pipe, 503 567 setup_buffer, setup_buffer_size, data_buffer, data_buffer_size); 568 569 pipe_drop_ref(pipe); 504 570 505 571 return rc; -
uspace/lib/usb/src/recognise.c
rb6c9e1e rc6394aa 404 404 child->driver_data = dev_data; 405 405 406 rc = usb_pipe_start_session(&ctrl_pipe);407 if (rc != EOK) {408 goto failure;409 }410 411 406 rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids); 412 if (rc != EOK) {413 goto failure;414 }415 416 rc = usb_pipe_end_session(&ctrl_pipe);417 407 if (rc != EOK) { 418 408 goto failure;
Note:
See TracChangeset
for help on using the changeset viewer.