Changeset 5410c04 in mainline
- Timestamp:
- 2011-04-09T16:11:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a9d67aa, c6394aa
- Parents:
- 8e8b84f (diff), 7b715892 (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
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dev.c
r8e8b84f r5410c04 50 50 51 51 int rc; 52 bool transfer_started = false; 52 53 53 54 rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr); … … 76 77 } 77 78 78 rc = usb_pipe_start_ session(&dev->ctrl_pipe);79 rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe); 79 80 if (rc != EOK) { 80 81 fprintf(stderr, 81 NAME ": failed to start sessionon control pipe: %s.\n",82 NAME ": failed to start transfer on control pipe: %s.\n", 82 83 str_error(rc)); 83 84 goto leave; 84 85 } 86 transfer_started = true; 85 87 86 88 rc = usb_request_get_device_descriptor(&dev->ctrl_pipe, … … 107 109 108 110 leave: 109 if ( usb_pipe_is_session_started(&dev->ctrl_pipe)) {110 usb_pipe_end_ session(&dev->ctrl_pipe);111 if (transfer_started) { 112 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 111 113 } 112 114 … … 118 120 void destroy_device(usbinfo_device_t *dev) 119 121 { 120 usb_pipe_end_ session(&dev->ctrl_pipe);122 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 121 123 free(dev); 122 124 } -
uspace/drv/usbmid/main.c
r8e8b84f r5410c04 55 55 int rc; 56 56 57 rc = usb_pipe_start_ session(&dev->ctrl_pipe);57 rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe); 58 58 if (rc != EOK) { 59 usb_log_error("Failed to start sessionon control pipe: %s.\n",59 usb_log_error("Failed to start transfer on control pipe: %s.\n", 60 60 str_error(rc)); 61 61 return rc; … … 64 64 bool accept = usbmid_explore_device(dev); 65 65 66 rc = usb_pipe_end_session(&dev->ctrl_pipe); 67 if (rc != EOK) { 68 usb_log_warning("Failed to end session on control pipe: %s.\n", 69 str_error(rc)); 70 } 66 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 71 67 72 68 if (!accept) { -
uspace/lib/usb/Makefile
r8e8b84f r5410c04 43 43 src/hidparser.c \ 44 44 src/hub.c \ 45 src/pipepriv.c \ 45 46 src/pipes.c \ 46 47 src/pipesinit.c \ -
uspace/lib/usb/include/usb/pipes.h
r8e8b84f r5410c04 42 42 #include <ipc/devman.h> 43 43 #include <ddf/driver.h> 44 #include <fibril_synch.h> 44 45 45 46 /** Abstraction of a physical connection to the device. … … 59 60 * This endpoint must be bound with existing usb_device_connection_t 60 61 * (i.e. the wire to send data over). 62 * 63 * Locking order: if you want to lock both mutexes 64 * (@c guard and @c hc_phone_mutex), lock @c guard first. 65 * It is not necessary to lock @c guard if you want to lock @c hc_phone_mutex 66 * only. 61 67 */ 62 68 typedef struct { 69 /** Guard of the whole pipe. */ 70 fibril_mutex_t guard; 71 63 72 /** The connection used for sending the data. */ 64 73 usb_device_connection_t *wire; … … 78 87 /** Phone to the host controller. 79 88 * Negative when no session is active. 89 * It is an error to access this member without @c hc_phone_mutex 90 * being locked. 91 * If call over the phone is to be made, it must be preceeded by 92 * call to pipe_add_ref() [internal libusb function]. 80 93 */ 81 94 int hc_phone; 95 96 /** Guard for serialization of requests over the phone. */ 97 fibril_mutex_t hc_phone_mutex; 98 99 /** Number of active transfers over the pipe. */ 100 int refcount; 82 101 } usb_pipe_t; 83 102 … … 141 160 bool usb_pipe_is_session_started(usb_pipe_t *); 142 161 162 int usb_pipe_start_long_transfer(usb_pipe_t *); 163 void usb_pipe_end_long_transfer(usb_pipe_t *); 164 143 165 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *); 144 166 int usb_pipe_write(usb_pipe_t *, void *, size_t); -
uspace/lib/usb/src/devdrv.c
r8e8b84f r5410c04 239 239 240 240 /* 241 * For further actions, we need open session on default control pipe. 241 * We will do some querying of the device, it is worth to prepare 242 * the long transfer. 242 243 */ 243 rc = usb_pipe_start_ session(&dev->ctrl_pipe);244 if (rc != EOK) { 245 usb_log_error("Failed to start an IPC session: %s.\n",244 rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe); 245 if (rc != EOK) { 246 usb_log_error("Failed to start transfer: %s.\n", 246 247 str_error(rc)); 247 248 return rc; … … 252 253 &dev->descriptors.device); 253 254 if (rc != EOK) { 255 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 254 256 usb_log_error("Failed to retrieve device descriptor: %s.\n", 255 257 str_error(rc)); … … 262 264 &dev->descriptors.configuration_size); 263 265 if (rc != EOK) { 266 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 264 267 usb_log_error("Failed retrieving configuration descriptor: %s. %s\n", 265 268 dev->ddf_dev->name, str_error(rc)); … … 271 274 } 272 275 273 /* No checking here. */ 274 usb_pipe_end_session(&dev->ctrl_pipe); 276 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 275 277 276 278 /* Rollback actions. */ -
uspace/lib/usb/src/devpoll.c
r8e8b84f r5410c04 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/hub.c
r8e8b84f r5410c04 287 287 } 288 288 289 rc = usb_pipe_start_session(&ctrl_pipe);290 if (rc != EOK) {291 rc = ENOTCONN;292 goto leave_unregister_endpoint;293 }294 295 289 rc = usb_request_set_address(&ctrl_pipe, dev_addr); 296 290 if (rc != EOK) { … … 298 292 goto leave_stop_session; 299 293 } 300 301 usb_pipe_end_session(&ctrl_pipe);302 294 303 295 /* -
uspace/lib/usb/src/pipes.c
r8e8b84f r5410c04 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
r8e8b84f r5410c04 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
r8e8b84f r5410c04 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
r8e8b84f r5410c04 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.