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