Changes in uspace/lib/drv/generic/remote_usbhc.c [93f8da1:6427cf67] in mainline
- File:
-
- 1 edited
-
uspace/lib/drv/generic/remote_usbhc.c (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usbhc.c
r93f8da1 r6427cf67 33 33 */ 34 34 35 #include <ipc/ipc.h>36 35 #include <async.h> 37 36 #include <errno.h> … … 43 42 44 43 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 static void remote_usbhc_get_buffer(device_t *, void *, ipc_callid_t, ipc_call_t *);46 44 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *); 47 45 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 65 63 remote_usbhc_get_address, 66 64 67 remote_usbhc_get_buffer,68 69 65 remote_usbhc_reserve_default_address, 70 66 remote_usbhc_release_default_address, … … 99 95 typedef struct { 100 96 ipc_callid_t caller; 97 ipc_callid_t data_caller; 101 98 void *buffer; 102 99 void *setup_packet; … … 128 125 129 126 trans->caller = caller; 127 trans->data_caller = 0; 130 128 trans->buffer = NULL; 131 129 trans->setup_packet = NULL; … … 141 139 142 140 if (!usb_iface->tell_address) { 143 ipc_answer_0(callid, ENOTSUP);141 async_answer_0(callid, ENOTSUP); 144 142 return; 145 143 } … … 150 148 int rc = usb_iface->tell_address(device, handle, &address); 151 149 if (rc != EOK) { 152 ipc_answer_0(callid, rc);150 async_answer_0(callid, rc); 153 151 } else { 154 ipc_answer_1(callid, EOK, address); 155 } 156 } 157 158 void remote_usbhc_get_buffer(device_t *device, void *iface, 159 ipc_callid_t callid, ipc_call_t *call) 160 { 161 sysarg_t buffer_hash = DEV_IPC_GET_ARG1(*call); 162 async_transaction_t * trans = (async_transaction_t *)buffer_hash; 163 if (trans == NULL) { 164 ipc_answer_0(callid, ENOENT); 165 return; 166 } 167 if (trans->buffer == NULL) { 168 ipc_answer_0(callid, EINVAL); 169 async_transaction_destroy(trans); 170 return; 171 } 172 173 ipc_callid_t cid; 174 size_t accepted_size; 175 if (!async_data_read_receive(&cid, &accepted_size)) { 176 ipc_answer_0(callid, EINVAL); 177 async_transaction_destroy(trans); 178 return; 179 } 180 181 if (accepted_size > trans->size) { 182 accepted_size = trans->size; 183 } 184 async_data_read_finalize(cid, trans->buffer, accepted_size); 185 186 ipc_answer_1(callid, EOK, accepted_size); 187 188 async_transaction_destroy(trans); 152 async_answer_1(callid, EOK, address); 153 } 189 154 } 190 155 … … 195 160 196 161 if (!usb_iface->reserve_default_address) { 197 ipc_answer_0(callid, ENOTSUP); 198 return; 199 } 200 201 int rc = usb_iface->reserve_default_address(device); 202 203 ipc_answer_0(callid, rc); 162 async_answer_0(callid, ENOTSUP); 163 return; 164 } 165 166 bool full_speed = DEV_IPC_GET_ARG1(*call); 167 168 int rc = usb_iface->reserve_default_address(device, full_speed); 169 170 async_answer_0(callid, rc); 204 171 } 205 172 … … 210 177 211 178 if (!usb_iface->release_default_address) { 212 ipc_answer_0(callid, ENOTSUP);179 async_answer_0(callid, ENOTSUP); 213 180 return; 214 181 } … … 216 183 int rc = usb_iface->release_default_address(device); 217 184 218 ipc_answer_0(callid, rc);185 async_answer_0(callid, rc); 219 186 } 220 187 … … 225 192 226 193 if (!usb_iface->request_address) { 227 ipc_answer_0(callid, ENOTSUP); 228 return; 229 } 194 async_answer_0(callid, ENOTSUP); 195 return; 196 } 197 198 bool full_speed = DEV_IPC_GET_ARG1(*call); 230 199 231 200 usb_address_t address; 232 int rc = usb_iface->request_address(device, &address);233 if (rc != EOK) { 234 ipc_answer_0(callid, rc);201 int rc = usb_iface->request_address(device, full_speed, &address); 202 if (rc != EOK) { 203 async_answer_0(callid, rc); 235 204 } else { 236 ipc_answer_1(callid, EOK, (sysarg_t) address);205 async_answer_1(callid, EOK, (sysarg_t) address); 237 206 } 238 207 } … … 244 213 245 214 if (!usb_iface->bind_address) { 246 ipc_answer_0(callid, ENOTSUP);215 async_answer_0(callid, ENOTSUP); 247 216 return; 248 217 } … … 253 222 int rc = usb_iface->bind_address(device, address, handle); 254 223 255 ipc_answer_0(callid, rc);224 async_answer_0(callid, rc); 256 225 } 257 226 … … 262 231 263 232 if (!usb_iface->release_address) { 264 ipc_answer_0(callid, ENOTSUP);233 async_answer_0(callid, ENOTSUP); 265 234 return; 266 235 } … … 270 239 int rc = usb_iface->release_address(device, address); 271 240 272 ipc_answer_0(callid, rc);241 async_answer_0(callid, rc); 273 242 } 274 243 275 244 276 245 static void callback_out(device_t *device, 277 usb_transaction_outcome_t outcome, void *arg)246 int outcome, void *arg) 278 247 { 279 248 async_transaction_t *trans = (async_transaction_t *)arg; 280 249 281 ipc_answer_0(trans->caller, outcome);250 async_answer_0(trans->caller, outcome); 282 251 283 252 async_transaction_destroy(trans); … … 285 254 286 255 static void callback_in(device_t *device, 287 usb_transaction_outcome_t outcome, size_t actual_size, void *arg)256 int outcome, size_t actual_size, void *arg) 288 257 { 289 258 async_transaction_t *trans = (async_transaction_t *)arg; 290 259 291 if (outcome != USB_OUTCOME_OK) { 292 ipc_answer_0(trans->caller, outcome); 260 if (outcome != EOK) { 261 async_answer_0(trans->caller, outcome); 262 if (trans->data_caller) { 263 async_answer_0(trans->data_caller, EINTR); 264 } 293 265 async_transaction_destroy(trans); 294 266 return; … … 296 268 297 269 trans->size = actual_size; 298 ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans); 270 271 if (trans->data_caller) { 272 async_data_read_finalize(trans->data_caller, 273 trans->buffer, actual_size); 274 } 275 276 async_answer_0(trans->caller, EOK); 277 278 async_transaction_destroy(trans); 299 279 } 300 280 … … 311 291 { 312 292 if (!transfer_func) { 313 ipc_answer_0(callid, ENOTSUP);293 async_answer_0(callid, ENOTSUP); 314 294 return; 315 295 } … … 329 309 330 310 if (rc != EOK) { 331 ipc_answer_0(callid, rc);311 async_answer_0(callid, rc); 332 312 return; 333 313 } … … 339 319 free(buffer); 340 320 } 341 ipc_answer_0(callid, ENOMEM);321 async_answer_0(callid, ENOMEM); 342 322 return; 343 323 } … … 350 330 351 331 if (rc != EOK) { 352 ipc_answer_0(callid, rc);332 async_answer_0(callid, rc); 353 333 async_transaction_destroy(trans); 354 334 } … … 367 347 { 368 348 if (!transfer_func) { 369 ipc_answer_0(callid, ENOTSUP);349 async_answer_0(callid, ENOTSUP); 370 350 return; 371 351 } … … 377 357 }; 378 358 359 ipc_callid_t data_callid; 360 if (!async_data_read_receive(&data_callid, &len)) { 361 async_answer_0(callid, EPARTY); 362 return; 363 } 364 379 365 async_transaction_t *trans = async_transaction_create(callid); 380 366 if (trans == NULL) { 381 ipc_answer_0(callid, ENOMEM); 382 return; 383 } 367 async_answer_0(callid, ENOMEM); 368 return; 369 } 370 trans->data_caller = data_callid; 384 371 trans->buffer = malloc(len); 385 372 trans->size = len; … … 389 376 390 377 if (rc != EOK) { 391 ipc_answer_0(callid, rc);378 async_answer_0(callid, rc); 392 379 async_transaction_destroy(trans); 393 380 } … … 414 401 case USB_DIRECTION_IN: 415 402 if (!transfer_in_func) { 416 ipc_answer_0(callid, ENOTSUP);403 async_answer_0(callid, ENOTSUP); 417 404 return; 418 405 } … … 420 407 case USB_DIRECTION_OUT: 421 408 if (!transfer_out_func) { 422 ipc_answer_0(callid, ENOTSUP);409 async_answer_0(callid, ENOTSUP); 423 410 return; 424 411 } … … 436 423 async_transaction_t *trans = async_transaction_create(callid); 437 424 if (trans == NULL) { 438 ipc_answer_0(callid, ENOMEM);425 async_answer_0(callid, ENOMEM); 439 426 return; 440 427 } … … 456 443 457 444 if (rc != EOK) { 458 ipc_answer_0(callid, rc);445 async_answer_0(callid, rc); 459 446 async_transaction_destroy(trans); 460 447 } … … 549 536 550 537 if (!usb_iface->control_write) { 551 ipc_answer_0(callid, ENOTSUP);538 async_answer_0(callid, ENOTSUP); 552 539 return; 553 540 } … … 557 544 .endpoint = DEV_IPC_GET_ARG2(*call) 558 545 }; 546 size_t data_buffer_len = DEV_IPC_GET_ARG3(*call); 559 547 560 548 int rc; … … 563 551 void *data_buffer = NULL; 564 552 size_t setup_packet_len = 0; 565 size_t data_buffer_len = 0;566 553 567 554 rc = async_data_write_accept(&setup_packet, false, 568 555 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 569 556 if (rc != EOK) { 570 ipc_answer_0(callid, rc); 571 return; 572 } 573 rc = async_data_write_accept(&data_buffer, false, 574 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len); 575 if (rc != EOK) { 576 ipc_answer_0(callid, rc); 577 free(setup_packet); 578 return; 557 async_answer_0(callid, rc); 558 return; 559 } 560 561 if (data_buffer_len > 0) { 562 rc = async_data_write_accept(&data_buffer, false, 563 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len); 564 if (rc != EOK) { 565 async_answer_0(callid, rc); 566 free(setup_packet); 567 return; 568 } 579 569 } 580 570 581 571 async_transaction_t *trans = async_transaction_create(callid); 582 572 if (trans == NULL) { 583 ipc_answer_0(callid, ENOMEM);573 async_answer_0(callid, ENOMEM); 584 574 free(setup_packet); 585 575 free(data_buffer); … … 596 586 597 587 if (rc != EOK) { 598 ipc_answer_0(callid, rc);588 async_answer_0(callid, rc); 599 589 async_transaction_destroy(trans); 600 590 } … … 609 599 610 600 if (!usb_iface->control_read) { 611 ipc_answer_0(callid, ENOTSUP); 612 return; 613 } 614 615 size_t data_len = DEV_IPC_GET_ARG3(*call); 601 async_answer_0(callid, ENOTSUP); 602 return; 603 } 604 616 605 usb_target_t target = { 617 606 .address = DEV_IPC_GET_ARG1(*call), … … 623 612 void *setup_packet = NULL; 624 613 size_t setup_packet_len = 0; 614 size_t data_len = 0; 625 615 626 616 rc = async_data_write_accept(&setup_packet, false, 627 617 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 628 618 if (rc != EOK) { 629 ipc_answer_0(callid, rc); 619 async_answer_0(callid, rc); 620 return; 621 } 622 623 ipc_callid_t data_callid; 624 if (!async_data_read_receive(&data_callid, &data_len)) { 625 async_answer_0(callid, EPARTY); 626 free(setup_packet); 630 627 return; 631 628 } … … 633 630 async_transaction_t *trans = async_transaction_create(callid); 634 631 if (trans == NULL) { 635 ipc_answer_0(callid, ENOMEM);632 async_answer_0(callid, ENOMEM); 636 633 free(setup_packet); 637 634 return; 638 635 } 636 trans->data_caller = data_callid; 639 637 trans->setup_packet = setup_packet; 640 638 trans->size = data_len; 641 639 trans->buffer = malloc(data_len); 642 640 if (trans->buffer == NULL) { 643 ipc_answer_0(callid, ENOMEM);641 async_answer_0(callid, ENOMEM); 644 642 async_transaction_destroy(trans); 645 643 return; … … 652 650 653 651 if (rc != EOK) { 654 ipc_answer_0(callid, rc);652 async_answer_0(callid, rc); 655 653 async_transaction_destroy(trans); 656 654 }
Note:
See TracChangeset
for help on using the changeset viewer.
