Changeset a546687 in mainline
- Timestamp:
- 2011-04-09T09:17:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d48fcc0
- Parents:
- d5ac90f
- Location:
- uspace/lib/usb
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/Makefile
rd5ac90f ra546687 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
rd5ac90f ra546687 84 84 /** Guard for serialization of requests over the phone. */ 85 85 fibril_mutex_t hc_phone_mutex; 86 87 /** Number of active transfers over the pipe. */ 88 int refcount; 86 89 } usb_pipe_t; 87 90 -
uspace/lib/usb/src/pipes.c
rd5ac90f ra546687 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 */ … … 246 247 int usb_pipe_start_session(usb_pipe_t *pipe) 247 248 { 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 261 return EOK; 249 return pipe_add_ref(pipe); 262 250 } 263 251 … … 272 260 int usb_pipe_end_session(usb_pipe_t *pipe) 273 261 { 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 262 pipe_drop_ref(pipe); 287 263 return EOK; 288 264 } … … 298 274 bool usb_pipe_is_session_started(usb_pipe_t *pipe) 299 275 { 300 return (pipe->hc_phone >= 0); 276 pipe_acquire(pipe); 277 bool started = pipe->refcount > 0; 278 pipe_release(pipe); 279 return started; 301 280 } 302 281 -
uspace/lib/usb/src/pipesinit.c
rd5ac90f ra546687 363 363 pipe->max_packet_size = max_packet_size; 364 364 pipe->direction = direction; 365 pipe->refcount = 0; 365 366 366 367 return EOK; -
uspace/lib/usb/src/pipesio.c
rd5ac90f ra546687 49 49 #include <assert.h> 50 50 #include <usbhc_iface.h> 51 52 /** Ensure exclusive access to the IPC phone of given pipe. 53 * 54 * @param pipe Pipe to be exclusively accessed. 55 */ 56 static void pipe_acquire(usb_pipe_t *pipe) 57 { 58 fibril_mutex_lock(&pipe->hc_phone_mutex); 59 } 60 61 /** Terminate exclusive access to the IPC phone of given pipe. 62 * 63 * @param pipe Pipe to be released from exclusive usage. 64 */ 65 static void pipe_release(usb_pipe_t *pipe) 66 { 67 fibril_mutex_unlock(&pipe->hc_phone_mutex); 68 } 69 70 51 #include "pipepriv.h" 71 52 72 53 /** Request an in transfer, no checking of input parameters. … … 176 157 177 158 if (buffer == NULL) { 178 159 return EINVAL; 179 160 } 180 161 181 162 if (size == 0) { 182 163 return EINVAL; 183 }184 185 if (!usb_pipe_is_session_started(pipe)) {186 return EBADF;187 164 } 188 165 … … 195 172 } 196 173 174 int rc; 175 rc = pipe_add_ref(pipe); 176 if (rc != EOK) { 177 return rc; 178 } 179 180 197 181 size_t act_size = 0; 198 int rc;199 182 200 183 rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size); 184 185 pipe_drop_ref(pipe); 186 201 187 if (rc != EOK) { 202 188 return rc; … … 301 287 } 302 288 303 if (!usb_pipe_is_session_started(pipe)) {304 return EBADF;305 }306 307 289 if (pipe->direction != USB_DIRECTION_OUT) { 308 290 return EBADF; … … 313 295 } 314 296 315 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); 316 307 317 308 return rc; … … 432 423 } 433 424 434 if (!usb_pipe_is_session_started(pipe)) {435 return EBADF;436 }437 438 425 if ((pipe->direction != USB_DIRECTION_BOTH) 439 426 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 441 428 } 442 429 430 int rc; 431 432 rc = pipe_add_ref(pipe); 433 if (rc != EOK) { 434 return rc; 435 } 436 443 437 size_t act_size = 0; 444 intrc = usb_pipe_control_read_no_check(pipe,438 rc = usb_pipe_control_read_no_check(pipe, 445 439 setup_buffer, setup_buffer_size, 446 440 data_buffer, data_buffer_size, &act_size); 441 442 pipe_drop_ref(pipe); 447 443 448 444 if (rc != EOK) { … … 556 552 } 557 553 558 if (!usb_pipe_is_session_started(pipe)) {559 return EBADF;560 }561 562 554 if ((pipe->direction != USB_DIRECTION_BOTH) 563 555 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { … … 565 557 } 566 558 567 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, 568 567 setup_buffer, setup_buffer_size, data_buffer, data_buffer_size); 568 569 pipe_drop_ref(pipe); 569 570 570 571 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.