Changeset 1d1f894 in mainline for uspace/lib
- Timestamp:
- 2010-11-03T15:05:41Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d70a463
- Parents:
- af894a21
- Location:
- uspace/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/hcd.c
raf894a21 r1d1f894 90 90 } 91 91 92 /** Create necessary phones for com unicating with HCD.92 /** Create necessary phones for communicating with HCD. 93 93 * This function wraps following calls: 94 94 * -# open <code>/dev/usb/<i>hcd_path</i></code> for reading 95 95 * -# access phone of file opened in previous step 96 * -# create callback through just opened phone97 * -# set handler for this callback98 96 * -# return the (outgoing) phone 99 97 * 100 98 * @warning This function is wrapper for several actions and therefore 101 99 * it is not possible - in case of error - to determine at which point 102 * error occur ed.100 * error occurred. 103 101 * 104 102 * @param hcd_path HCD identification under devfs 105 103 * (without <code>/dev/usb/</code>). 106 * @param callback_connection Handler for callbacks from HCD. 107 * @return Phone for comunicating with HCD or error code from errno.h. 108 */ 109 int usb_hcd_create_phones(const char * hcd_path, 110 async_client_conn_t callback_connection) 104 * @return Phone for communicating with HCD or error code from errno.h. 105 */ 106 int usb_hcd_connect(const char * hcd_path) 111 107 { 112 108 char dev_path[DEVMAP_NAME_MAXLEN + 1]; … … 124 120 return hcd_phone; 125 121 } 126 127 ipcarg_t phonehash; 128 int rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash); 129 if (rc != EOK) { 130 return rc; 131 } 132 async_new_connection(phonehash, 0, NULL, callback_connection); 133 122 134 123 return hcd_phone; 135 124 } 136 137 /** Send data from USB host to a function.138 *139 * @param hcd_phone Connected phone to HCD.140 * @param target USB function address.141 * @param transfer_type USB transfer type.142 * @param buffer Buffer with data to be sent.143 * @param len Buffer @p buffer size.144 * @param[out] transaction_handle Handle of created transaction (NULL to ignore).145 * @return Error status.146 * @retval EOK Everything OK, buffer transfered to HCD and queued there.147 * @retval EINVAL Invalid phone.148 * @retval EINVAL @p buffer is NULL.149 */150 int usb_hcd_send_data_to_function(int hcd_phone,151 usb_target_t target, usb_transfer_type_t transfer_type,152 void * buffer, size_t len,153 usb_transaction_handle_t * transaction_handle)154 {155 if (hcd_phone < 0) {156 return EINVAL;157 }158 if (buffer == NULL) {159 return EINVAL;160 }161 162 ipc_call_t answer_data;163 ipcarg_t answer_rc;164 aid_t req;165 int rc;166 167 req = async_send_4(hcd_phone,168 IPC_M_USB_HCD_SEND_DATA,169 target.address, target.endpoint,170 transfer_type, 0,171 &answer_data);172 173 rc = async_data_write_start(hcd_phone, buffer, len);174 if (rc != EOK) {175 async_wait_for(req, NULL);176 return rc;177 }178 179 async_wait_for(req, &answer_rc);180 rc = (int)answer_rc;181 if (rc != EOK) {182 return rc;183 }184 185 if (transaction_handle != NULL) {186 *transaction_handle = IPC_GET_ARG1(answer_data);187 }188 189 return EOK;190 }191 192 193 /** Inform HCD about data reception.194 * The actual reception is handled in callback.195 *196 * @param hcd_phone Connected phone to HCD.197 * @param target USB function address.198 * @param transfer_type USB transfer type.199 * @param len Maximum accepted packet size.200 * @param[out] transaction_handle Handle of created transaction (NULL to ignore).201 * @return Error status.202 */203 int usb_hcd_prepare_data_reception(int hcd_phone,204 usb_target_t target, usb_transfer_type_t transfer_type,205 size_t len,206 usb_transaction_handle_t * transaction_handle)207 {208 if (hcd_phone < 0) {209 return EINVAL;210 }211 212 usb_transaction_handle_t handle;213 214 int rc = ipc_call_sync_5_1(hcd_phone, IPC_M_USB_HCD_RECEIVE_DATA,215 target.address, target.endpoint,216 transfer_type, len, 0, &handle);217 218 if (rc != EOK) {219 return rc;220 }221 222 if (transaction_handle != NULL) {223 *transaction_handle = handle;224 }225 226 return EOK;227 }228 229 230 static int send_buffer(int phone, ipcarg_t method, usb_target_t target,231 void *buffer, size_t size, usb_transaction_handle_t * transaction_handle)232 {233 if (phone < 0) {234 return EINVAL;235 }236 237 if ((buffer == NULL) && (size > 0)) {238 return EINVAL;239 }240 241 ipc_call_t answer_data;242 ipcarg_t answer_rc;243 aid_t req;244 int rc;245 246 req = async_send_3(phone,247 method,248 target.address, target.endpoint,249 size,250 &answer_data);251 252 if (size > 0) {253 rc = async_data_write_start(phone, buffer, size);254 if (rc != EOK) {255 async_wait_for(req, NULL);256 return rc;257 }258 }259 260 async_wait_for(req, &answer_rc);261 rc = (int)answer_rc;262 if (rc != EOK) {263 return rc;264 }265 266 if (transaction_handle != NULL) {267 *transaction_handle = IPC_GET_ARG1(answer_data);268 }269 270 return EOK;271 }272 273 274 static int prep_receive_data(int phone, ipcarg_t method, usb_target_t target,275 size_t size, usb_transaction_handle_t * transaction_handle)276 {277 if (phone < 0) {278 return EINVAL;279 }280 281 usb_transaction_handle_t handle;282 283 int rc = ipc_call_sync_3_1(phone,284 method,285 target.address, target.endpoint,286 size,287 &handle);288 289 if (rc != EOK) {290 return rc;291 }292 293 if (transaction_handle != NULL) {294 *transaction_handle = handle;295 }296 297 return EOK;298 }299 300 301 int usb_hcd_transfer_interrupt_out(int hcd_phone, usb_target_t target,302 void *buffer, size_t size, usb_transaction_handle_t *handle)303 {304 return send_buffer(hcd_phone, IPC_M_USB_HCD_INTERRUPT_OUT,305 target, buffer, size, handle);306 }307 308 int usb_hcd_transfer_interrupt_in(int hcd_phone, usb_target_t target,309 size_t size, usb_transaction_handle_t *handle)310 {311 return prep_receive_data(hcd_phone, IPC_M_USB_HCD_INTERRUPT_IN,312 target, size, handle);313 }314 315 int usb_hcd_transfer_control_write_setup(int hcd_phone, usb_target_t target,316 void *buffer, size_t size, usb_transaction_handle_t *handle)317 {318 return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_SETUP,319 target, buffer, size, handle);320 }321 322 int usb_hcd_transfer_control_write_data(int hcd_phone, usb_target_t target,323 void *buffer, size_t size, usb_transaction_handle_t *handle)324 {325 return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_DATA,326 target, buffer, size, handle);327 328 }329 int usb_hcd_transfer_control_write_status(int hcd_phone, usb_target_t target,330 usb_transaction_handle_t *handle)331 {332 return prep_receive_data(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_STATUS,333 target, 0, handle);334 }335 336 int usb_hcd_transfer_control_read_setup(int hcd_phone, usb_target_t target,337 void *buffer, size_t size, usb_transaction_handle_t *handle)338 {339 return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_SETUP,340 target, buffer, size, handle);341 }342 int usb_hcd_transfer_control_read_data(int hcd_phone, usb_target_t target,343 size_t size, usb_transaction_handle_t *handle)344 {345 return prep_receive_data(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_DATA,346 target, size, handle);347 }348 int usb_hcd_transfer_control_read_status(int hcd_phone, usb_target_t target,349 usb_transaction_handle_t *handle)350 {351 return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_STATUS,352 target, NULL, 0, handle);353 }354 355 356 357 358 359 /*360 * =================361 * async versions of the above functions362 * =================363 */364 125 365 126 /** Send data to HCD. -
uspace/lib/usb/hcd.h
raf894a21 r1d1f894 133 133 * OUT transactions buffers can be freed immediatelly after call is dispatched 134 134 * (i.e. after return from wrapping function). 135 * 136 * Async methods for retrieving data from device: 137 */ 138 typedef enum { 139 /** Send data over USB to a function. 140 * This method initializes large data transfer that must follow 141 * immediatelly. 142 * The recipient of this method must issue immediately data reception 143 * and answer this call after data buffer was transfered. 144 * 145 * Arguments of the call: 146 * - USB address of the function 147 * - endpoint of the function 148 * - transfer type 149 * - flags (not used) 150 * 151 * Answer: 152 * - EOK - ready to accept the data buffer 153 * - ELIMIT - too many transactions for current connection 154 * - ENOENT - callback connection does not exist 155 * - EINVAL - other kind of error 156 * 157 * Arguments of the answer: 158 * - opaque transaction handle (used in callbacks) 159 */ 160 IPC_M_USB_HCD_SEND_DATA = IPC_FIRST_USER_METHOD, 161 162 /** Initiate data receive from a function. 163 * This method announces the HCD that some data will come. 164 * When this data arrives, the HCD will call back with 165 * IPC_M_USB_HCD_DATA_RECEIVED. 166 * 167 * Arguments of the call: 168 * - USB address of the function 169 * - endpoint of the function 170 * - transfer type 171 * - buffer size 172 * - flags (not used) 173 * 174 * Answer: 175 * - EOK - HCD accepted the request 176 * - ELIMIT - too many transactions for current connection 177 * - ENOENT - callback connection does not exist 178 * 179 * Arguments of the answer: 180 * - opaque transaction handle (used in callbacks) 181 */ 182 IPC_M_USB_HCD_RECEIVE_DATA, 183 135 * 136 */ 137 typedef enum { 184 138 /** Tell maximum size of the transaction buffer (payload). 185 139 * … … 193 147 * - buffer size (in bytes): 194 148 */ 195 IPC_M_USB_HCD_TRANSACTION_SIZE, 196 197 198 IPC_M_USB_HCD_INTERRUPT_OUT, 199 IPC_M_USB_HCD_INTERRUPT_IN, 200 201 IPC_M_USB_HCD_CONTROL_WRITE_SETUP, 202 IPC_M_USB_HCD_CONTROL_WRITE_DATA, 203 IPC_M_USB_HCD_CONTROL_WRITE_STATUS, 204 205 IPC_M_USB_HCD_CONTROL_READ_SETUP, 206 IPC_M_USB_HCD_CONTROL_READ_DATA, 207 IPC_M_USB_HCD_CONTROL_READ_STATUS, 208 209 /* async methods */ 149 IPC_M_USB_HCD_TRANSACTION_SIZE = IPC_FIRST_USER_METHOD, 210 150 211 151 /** Asks for data buffer. … … 293 233 294 234 295 int usb_hcd_create_phones(const char *, async_client_conn_t); 296 int usb_hcd_send_data_to_function(int, usb_target_t, usb_transfer_type_t, 297 void *, size_t, usb_transaction_handle_t *); 298 int usb_hcd_prepare_data_reception(int, usb_target_t, usb_transfer_type_t, 299 size_t, usb_transaction_handle_t *); 300 301 302 int usb_hcd_transfer_interrupt_out(int, usb_target_t, 303 void *, size_t, usb_transaction_handle_t *); 304 int usb_hcd_transfer_interrupt_in(int, usb_target_t, 305 size_t, usb_transaction_handle_t *); 306 307 int usb_hcd_transfer_control_write_setup(int, usb_target_t, 308 void *, size_t, usb_transaction_handle_t *); 309 int usb_hcd_transfer_control_write_data(int, usb_target_t, 310 void *, size_t, usb_transaction_handle_t *); 311 int usb_hcd_transfer_control_write_status(int, usb_target_t, 312 usb_transaction_handle_t *); 313 314 int usb_hcd_transfer_control_read_setup(int, usb_target_t, 315 void *, size_t, usb_transaction_handle_t *); 316 int usb_hcd_transfer_control_read_data(int, usb_target_t, 317 size_t, usb_transaction_handle_t *); 318 int usb_hcd_transfer_control_read_status(int, usb_target_t, 319 usb_transaction_handle_t *); 235 int usb_hcd_connect(const char *); 320 236 321 237 int usb_hcd_async_transfer_interrupt_out(int, usb_target_t, -
uspace/lib/usbvirt/main.c
raf894a21 r1d1f894 225 225 226 226 ipcarg_t phonehash; 227 int rc = ipc_connect_to_me(hcd_phone, 1, 0, 0, &phonehash);227 int rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash); 228 228 if (rc != EOK) { 229 229 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.