Changeset 8969f46 in mainline
- Timestamp:
- 2011-11-26T13:33:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3f0ad85a
- Parents:
- b4292e7
- Location:
- uspace/lib/usbdev/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipepriv.c
rb4292e7 r8969f46 87 87 88 88 if (pipe->refcount == 0) { 89 assert(pipe->hc_sess == NULL); 89 90 /* Need to open the phone by ourselves. */ 90 91 async_sess_t *sess = -
uspace/lib/usbdev/src/pipesio.c
rb4292e7 r8969f46 65 65 void *buffer, size_t size, size_t *size_transfered) 66 66 { 67 /* Isochronous transfer are not supported (yet) */ 68 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 69 pipe->transfer_type != USB_TRANSFER_BULK && 70 pipe->transfer_type != USB_TRANSFER_CONTROL) 71 return ENOTSUP; 72 73 int ret = pipe_add_ref(pipe, false); 74 if (ret != EOK) { 75 return ret; 76 } 77 78 /* Ensure serialization over the phone. */ 79 pipe_start_transaction(pipe); 80 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 81 if (!exch) { 82 pipe_end_transaction(pipe); 83 pipe_drop_ref(pipe); 84 return ENOMEM; 85 } 86 87 ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no, 88 setup, buffer, size, size_transfered); 89 async_exchange_end(exch); 90 pipe_end_transaction(pipe); 91 pipe_drop_ref(pipe); 92 return ret; 93 } 94 95 /** Request a read (in) transfer on an endpoint pipe. 96 * 97 * @param[in] pipe Pipe used for the transfer. 98 * @param[out] buffer Buffer where to store the data. 99 * @param[in] size Size of the buffer (in bytes). 100 * @param[out] size_transfered Number of bytes that were actually transfered. 101 * @return Error code. 102 */ 103 int usb_pipe_read(usb_pipe_t *pipe, 104 void *buffer, size_t size, size_t *size_transfered) 105 { 106 assert(pipe); 107 108 if (buffer == NULL) { 109 return EINVAL; 110 } 111 112 if (size == 0) { 113 return EINVAL; 114 } 115 116 if (pipe->direction != USB_DIRECTION_IN) { 117 return EBADF; 118 } 119 120 if (pipe->transfer_type == USB_TRANSFER_CONTROL) { 121 return EBADF; 122 } 123 124 size_t act_size = 0; 125 const int rc = usb_pipe_read_no_check(pipe, 0, buffer, size, &act_size); 126 127 128 if (rc == EOK && size_transfered != NULL) { 129 *size_transfered = act_size; 130 } 131 132 return rc; 133 } 134 135 /** Request an out transfer, no checking of input parameters. 136 * 137 * @param[in] pipe Pipe used for the transfer. 138 * @param[in] buffer Buffer with data to transfer. 139 * @param[in] size Size of the buffer (in bytes). 140 * @return Error code. 141 */ 142 static int usb_pipe_write_no_check(usb_pipe_t *pipe, uint64_t setup, 143 const void *buffer, size_t size) 144 { 67 145 /* Only interrupt and bulk transfers are supported */ 68 146 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && … … 71 149 return ENOTSUP; 72 150 151 int ret = pipe_add_ref(pipe, false); 152 if (ret != EOK) { 153 return ret; 154 } 155 73 156 /* Ensure serialization over the phone. */ 74 157 pipe_start_transaction(pipe); … … 76 159 if (!exch) { 77 160 pipe_end_transaction(pipe); 161 pipe_drop_ref(pipe); 78 162 return ENOMEM; 79 163 } 80 81 const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no, 82 setup, buffer, size, size_transfered); 83 async_exchange_end(exch); 84 pipe_end_transaction(pipe); 85 return ret; 86 } 87 88 /** Request a read (in) transfer on an endpoint pipe. 89 * 90 * @param[in] pipe Pipe used for the transfer. 91 * @param[out] buffer Buffer where to store the data. 92 * @param[in] size Size of the buffer (in bytes). 93 * @param[out] size_transfered Number of bytes that were actually transfered. 94 * @return Error code. 95 */ 96 int usb_pipe_read(usb_pipe_t *pipe, 97 void *buffer, size_t size, size_t *size_transfered) 98 { 99 assert(pipe); 100 101 if (buffer == NULL) { 102 return EINVAL; 103 } 104 105 if (size == 0) { 106 return EINVAL; 107 } 108 109 if (pipe->direction != USB_DIRECTION_IN) { 110 return EBADF; 111 } 112 113 if (pipe->transfer_type == USB_TRANSFER_CONTROL) { 114 return EBADF; 115 } 116 117 int rc; 118 rc = pipe_add_ref(pipe, false); 119 if (rc != EOK) { 120 return rc; 121 } 122 123 124 size_t act_size = 0; 125 126 rc = usb_pipe_read_no_check(pipe, 0, buffer, size, &act_size); 127 128 pipe_drop_ref(pipe); 129 130 if (rc != EOK) { 131 return rc; 132 } 133 134 if (size_transfered != NULL) { 135 *size_transfered = act_size; 136 } 137 138 return EOK; 139 } 140 141 /** Request an out transfer, no checking of input parameters. 142 * 143 * @param[in] pipe Pipe used for the transfer. 144 * @param[in] buffer Buffer with data to transfer. 145 * @param[in] size Size of the buffer (in bytes). 146 * @return Error code. 147 */ 148 static int usb_pipe_write_no_check(usb_pipe_t *pipe, uint64_t setup, 149 const void *buffer, size_t size) 150 { 151 /* Only interrupt and bulk transfers are supported */ 152 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 153 pipe->transfer_type != USB_TRANSFER_BULK && 154 pipe->transfer_type != USB_TRANSFER_CONTROL) 155 return ENOTSUP; 156 157 /* Ensure serialization over the phone. */ 158 pipe_start_transaction(pipe); 159 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 160 if (!exch) { 161 pipe_end_transaction(pipe); 162 return ENOMEM; 163 } 164 const int ret = 165 usbhc_write(exch, pipe->wire->address, pipe->endpoint_no, 164 ret = usbhc_write(exch, pipe->wire->address, pipe->endpoint_no, 166 165 setup, buffer, size); 167 166 async_exchange_end(exch); 168 167 pipe_end_transaction(pipe); 168 pipe_drop_ref(pipe); 169 169 return ret; 170 170 } … … 193 193 } 194 194 195 int rc; 196 rc = pipe_add_ref(pipe, false); 197 if (rc != EOK) { 198 return rc; 199 } 200 201 rc = usb_pipe_write_no_check(pipe, 0, buffer, size); 202 203 pipe_drop_ref(pipe); 204 205 return rc; 195 return usb_pipe_write_no_check(pipe, 0, buffer, size); 206 196 } 207 197 … … 260 250 memcpy(&setup_packet, setup_buffer, 8); 261 251 262 int rc;263 264 rc = pipe_add_ref(pipe, false);265 if (rc != EOK) {266 return rc;267 }268 269 252 size_t act_size = 0; 270 rc = usb_pipe_read_no_check(pipe, setup_packet,253 const int rc = usb_pipe_read_no_check(pipe, setup_packet, 271 254 data_buffer, data_buffer_size, &act_size); 272 255 … … 275 258 } 276 259 277 pipe_drop_ref(pipe); 278 279 if (rc != EOK) { 280 return rc; 281 } 282 283 if (data_transfered_size != NULL) { 260 if (rc == EOK && data_transfered_size != NULL) { 284 261 *data_transfered_size = act_size; 285 262 } 286 263 287 return EOK;264 return rc; 288 265 } 289 266 … … 325 302 memcpy(&setup_packet, setup_buffer, 8); 326 303 327 int rc; 328 rc = pipe_add_ref(pipe, false); 329 if (rc != EOK) { 330 return rc; 331 } 332 333 rc = usb_pipe_write_no_check(pipe, setup_packet, 304 const int rc = usb_pipe_write_no_check(pipe, setup_packet, 334 305 data_buffer, data_buffer_size); 335 306 … … 338 309 } 339 310 340 pipe_drop_ref(pipe);341 342 311 return rc; 343 312 } 344 345 346 313 /** 347 314 * @}
Note:
See TracChangeset
for help on using the changeset viewer.