Changes in / [7b715892:8e8b84f] in mainline
- Location:
- uspace
- Files:
-
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dev.c
r7b715892 r8e8b84f 50 50 51 51 int rc; 52 bool transfer_started = false;53 52 54 53 rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr); … … 77 76 } 78 77 79 rc = usb_pipe_start_ long_transfer(&dev->ctrl_pipe);78 rc = usb_pipe_start_session(&dev->ctrl_pipe); 80 79 if (rc != EOK) { 81 80 fprintf(stderr, 82 NAME ": failed to start transferon control pipe: %s.\n",81 NAME ": failed to start session on control pipe: %s.\n", 83 82 str_error(rc)); 84 83 goto leave; 85 84 } 86 transfer_started = true;87 85 88 86 rc = usb_request_get_device_descriptor(&dev->ctrl_pipe, … … 109 107 110 108 leave: 111 if ( transfer_started) {112 usb_pipe_end_ long_transfer(&dev->ctrl_pipe);109 if (usb_pipe_is_session_started(&dev->ctrl_pipe)) { 110 usb_pipe_end_session(&dev->ctrl_pipe); 113 111 } 114 112 … … 120 118 void destroy_device(usbinfo_device_t *dev) 121 119 { 122 usb_pipe_end_ long_transfer(&dev->ctrl_pipe);120 usb_pipe_end_session(&dev->ctrl_pipe); 123 121 free(dev); 124 122 } -
uspace/drv/usbmid/main.c
r7b715892 r8e8b84f 55 55 int rc; 56 56 57 rc = usb_pipe_start_ long_transfer(&dev->ctrl_pipe);57 rc = usb_pipe_start_session(&dev->ctrl_pipe); 58 58 if (rc != EOK) { 59 usb_log_error("Failed to start transferon control pipe: %s.\n",59 usb_log_error("Failed to start session 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 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 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 } 67 71 68 72 if (!accept) { -
uspace/lib/usb/Makefile
r7b715892 r8e8b84f 43 43 src/hidparser.c \ 44 44 src/hub.c \ 45 src/pipepriv.c \46 45 src/pipes.c \ 47 46 src/pipesinit.c \ -
uspace/lib/usb/include/usb/pipes.h
r7b715892 r8e8b84f 42 42 #include <ipc/devman.h> 43 43 #include <ddf/driver.h> 44 #include <fibril_synch.h>45 44 46 45 /** Abstraction of a physical connection to the device. … … 60 59 * This endpoint must be bound with existing usb_device_connection_t 61 60 * (i.e. the wire to send data over). 62 *63 * Locking order: if you want to lock both mutexes64 * (@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_mutex66 * only.67 61 */ 68 62 typedef struct { 69 /** Guard of the whole pipe. */70 fibril_mutex_t guard;71 72 63 /** The connection used for sending the data. */ 73 64 usb_device_connection_t *wire; … … 87 78 /** Phone to the host controller. 88 79 * Negative when no session is active. 89 * It is an error to access this member without @c hc_phone_mutex90 * being locked.91 * If call over the phone is to be made, it must be preceeded by92 * call to pipe_add_ref() [internal libusb function].93 80 */ 94 81 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;101 82 } usb_pipe_t; 102 83 … … 160 141 bool usb_pipe_is_session_started(usb_pipe_t *); 161 142 162 int usb_pipe_start_long_transfer(usb_pipe_t *);163 void usb_pipe_end_long_transfer(usb_pipe_t *);164 165 143 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *); 166 144 int usb_pipe_write(usb_pipe_t *, void *, size_t); -
uspace/lib/usb/src/devdrv.c
r7b715892 r8e8b84f 239 239 240 240 /* 241 * We will do some querying of the device, it is worth to prepare 242 * the long transfer. 241 * For further actions, we need open session on default control pipe. 243 242 */ 244 rc = usb_pipe_start_ long_transfer(&dev->ctrl_pipe);245 if (rc != EOK) { 246 usb_log_error("Failed to start transfer: %s.\n",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", 247 246 str_error(rc)); 248 247 return rc; … … 253 252 &dev->descriptors.device); 254 253 if (rc != EOK) { 255 usb_pipe_end_long_transfer(&dev->ctrl_pipe);256 254 usb_log_error("Failed to retrieve device descriptor: %s.\n", 257 255 str_error(rc)); … … 264 262 &dev->descriptors.configuration_size); 265 263 if (rc != EOK) { 266 usb_pipe_end_long_transfer(&dev->ctrl_pipe);267 264 usb_log_error("Failed retrieving configuration descriptor: %s. %s\n", 268 265 dev->ddf_dev->name, str_error(rc)); … … 274 271 } 275 272 276 usb_pipe_end_long_transfer(&dev->ctrl_pipe); 273 /* No checking here. */ 274 usb_pipe_end_session(&dev->ctrl_pipe); 277 275 278 276 /* Rollback actions. */ -
uspace/lib/usb/src/devpoll.c
r7b715892 r8e8b84f 77 77 int rc; 78 78 79 rc = usb_pipe_start_session(pipe); 80 if (rc != EOK) { 81 failed_attempts++; 82 continue; 83 } 84 79 85 size_t actual_size; 80 86 rc = usb_pipe_read(pipe, polling_data->buffer, 81 87 polling_data->request_size, &actual_size); 82 88 89 /* Quit the session regardless of errors. */ 90 usb_pipe_end_session(pipe); 83 91 84 92 // if (rc == ESTALL) { -
uspace/lib/usb/src/hub.c
r7b715892 r8e8b84f 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 289 295 rc = usb_request_set_address(&ctrl_pipe, dev_addr); 290 296 if (rc != EOK) { … … 292 298 goto leave_stop_session; 293 299 } 300 301 usb_pipe_end_session(&ctrl_pipe); 294 302 295 303 /* -
uspace/lib/usb/src/pipes.c
r7b715892 r8e8b84f 41 41 #include <errno.h> 42 42 #include <assert.h> 43 #include "pipepriv.h"44 43 45 44 #define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */ … … 242 241 * necessary. 243 242 * 244 * @deprecated245 * Obsoleted with introduction of usb_pipe_start_long_transfer246 *247 243 * @param pipe Endpoint pipe to start the session on. 248 244 * @return Error code. … … 250 246 int usb_pipe_start_session(usb_pipe_t *pipe) 251 247 { 252 usb_log_warning("usb_pipe_start_session() was deprecated.\n"); 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 253 261 return EOK; 254 262 } … … 257 265 /** Ends a session on the endpoint pipe. 258 266 * 259 * @deprecated260 * Obsoleted with introduction of usb_pipe_end_long_transfer261 *262 267 * @see usb_pipe_start_session 263 268 * … … 267 272 int usb_pipe_end_session(usb_pipe_t *pipe) 268 273 { 269 usb_log_warning("usb_pipe_end_session() was deprecated.\n"); 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 270 287 return EOK; 271 288 } … … 281 298 bool usb_pipe_is_session_started(usb_pipe_t *pipe) 282 299 { 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); 300 return (pipe->hc_phone >= 0); 313 301 } 314 302 -
uspace/lib/usb/src/pipesinit.c
r7b715892 r8e8b84f 356 356 assert(connection); 357 357 358 fibril_mutex_initialize(&pipe->guard);359 358 pipe->wire = connection; 360 359 pipe->hc_phone = -1; 361 fibril_mutex_initialize(&pipe->hc_phone_mutex);362 360 pipe->endpoint_no = endpoint_no; 363 361 pipe->transfer_type = transfer_type; 364 362 pipe->max_packet_size = max_packet_size; 365 363 pipe->direction = direction; 366 pipe->refcount = 0;367 364 368 365 return EOK; … … 416 413 int rc; 417 414 418 rc = usb_pipe_start_long_transfer(pipe); 415 TRY_LOOP(failed_attempts) { 416 rc = usb_pipe_start_session(pipe); 417 if (rc == EOK) { 418 break; 419 } 420 } 419 421 if (rc != EOK) { 420 422 return rc; … … 437 439 } 438 440 } 439 usb_pipe_end_ long_transfer(pipe);441 usb_pipe_end_session(pipe); 440 442 if (rc != EOK) { 441 443 return rc; -
uspace/lib/usb/src/pipesio.c
r7b715892 r8e8b84f 49 49 #include <assert.h> 50 50 #include <usbhc_iface.h> 51 #include "pipepriv.h"52 51 53 52 /** Request an in transfer, no checking of input parameters. … … 79 78 } 80 79 81 /* Ensure serialization over the phone. */82 pipe_start_transaction(pipe);83 84 80 /* 85 81 * Make call identifying target USB device and type of transfer. … … 91 87 NULL); 92 88 if (opening_request == 0) { 93 pipe_end_transaction(pipe);94 89 return ENOMEM; 95 90 } … … 101 96 aid_t data_request = async_data_read(pipe->hc_phone, buffer, size, 102 97 &data_request_call); 103 104 /*105 * Since now on, someone else might access the backing phone106 * without breaking the transfer IPC protocol.107 */108 pipe_end_transaction(pipe);109 98 110 99 if (data_request == 0) { … … 157 146 158 147 if (buffer == NULL) { 159 return EINVAL;148 return EINVAL; 160 149 } 161 150 … … 164 153 } 165 154 155 if (!usb_pipe_is_session_started(pipe)) { 156 return EBADF; 157 } 158 166 159 if (pipe->direction != USB_DIRECTION_IN) { 167 160 return EBADF; … … 172 165 } 173 166 167 size_t act_size = 0; 174 168 int rc; 175 rc = pipe_add_ref(pipe);176 if (rc != EOK) {177 return rc;178 }179 180 181 size_t act_size = 0;182 169 183 170 rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size); 184 185 pipe_drop_ref(pipe);186 187 171 if (rc != EOK) { 188 172 return rc; … … 226 210 } 227 211 228 /* Ensure serialization over the phone. */229 pipe_start_transaction(pipe);230 231 212 /* 232 213 * Make call identifying target USB device and type of transfer. … … 238 219 NULL); 239 220 if (opening_request == 0) { 240 pipe_end_transaction(pipe);241 221 return ENOMEM; 242 222 } … … 246 226 */ 247 227 int rc = async_data_write_start(pipe->hc_phone, buffer, size); 248 249 /*250 * Since now on, someone else might access the backing phone251 * without breaking the transfer IPC protocol.252 */253 pipe_end_transaction(pipe);254 255 228 if (rc != EOK) { 256 229 async_wait_for(opening_request, NULL); … … 287 260 } 288 261 262 if (!usb_pipe_is_session_started(pipe)) { 263 return EBADF; 264 } 265 289 266 if (pipe->direction != USB_DIRECTION_OUT) { 290 267 return EBADF; … … 295 272 } 296 273 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); 274 int rc = usb_pipe_write_no_check(pipe, buffer, size); 307 275 308 276 return rc; … … 325 293 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size) 326 294 { 327 /* Ensure serialization over the phone. */328 pipe_start_transaction(pipe);329 330 295 /* 331 296 * Make call identifying target USB device and control transfer type. … … 346 311 setup_buffer, setup_buffer_size); 347 312 if (rc != EOK) { 348 pipe_end_transaction(pipe);349 313 async_wait_for(opening_request, NULL); 350 314 return rc; … … 358 322 data_buffer, data_buffer_size, 359 323 &data_request_call); 360 361 /*362 * Since now on, someone else might access the backing phone363 * without breaking the transfer IPC protocol.364 */365 pipe_end_transaction(pipe);366 367 368 324 if (data_request == 0) { 369 325 async_wait_for(opening_request, NULL); … … 423 379 } 424 380 381 if (!usb_pipe_is_session_started(pipe)) { 382 return EBADF; 383 } 384 425 385 if ((pipe->direction != USB_DIRECTION_BOTH) 426 386 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 428 388 } 429 389 430 int rc;431 432 rc = pipe_add_ref(pipe);433 if (rc != EOK) {434 return rc;435 }436 437 390 size_t act_size = 0; 438 rc = usb_pipe_control_read_no_check(pipe,391 int rc = usb_pipe_control_read_no_check(pipe, 439 392 setup_buffer, setup_buffer_size, 440 393 data_buffer, data_buffer_size, &act_size); 441 442 pipe_drop_ref(pipe);443 394 444 395 if (rc != EOK) { … … 467 418 void *data_buffer, size_t data_buffer_size) 468 419 { 469 /* Ensure serialization over the phone. */470 pipe_start_transaction(pipe);471 472 420 /* 473 421 * Make call identifying target USB device and control transfer type. … … 480 428 NULL); 481 429 if (opening_request == 0) { 482 pipe_end_transaction(pipe);483 430 return ENOMEM; 484 431 } … … 490 437 setup_buffer, setup_buffer_size); 491 438 if (rc != EOK) { 492 pipe_end_transaction(pipe);493 439 async_wait_for(opening_request, NULL); 494 440 return rc; … … 501 447 rc = async_data_write_start(pipe->hc_phone, 502 448 data_buffer, data_buffer_size); 503 504 /* All data sent, pipe can be released. */505 pipe_end_transaction(pipe);506 507 449 if (rc != EOK) { 508 450 async_wait_for(opening_request, NULL); 509 451 return rc; 510 452 } 511 } else {512 /* No data to send, we can release the pipe for others. */513 pipe_end_transaction(pipe);514 453 } 515 454 … … 552 491 } 553 492 493 if (!usb_pipe_is_session_started(pipe)) { 494 return EBADF; 495 } 496 554 497 if ((pipe->direction != USB_DIRECTION_BOTH) 555 498 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 557 500 } 558 501 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, 502 int rc = usb_pipe_control_write_no_check(pipe, 567 503 setup_buffer, setup_buffer_size, data_buffer, data_buffer_size); 568 569 pipe_drop_ref(pipe);570 504 571 505 return rc; -
uspace/lib/usb/src/recognise.c
r7b715892 r8e8b84f 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 406 411 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); 407 417 if (rc != EOK) { 408 418 goto failure;
Note:
See TracChangeset
for help on using the changeset viewer.