Changeset 74d6e90 in mainline for uspace/lib
- Timestamp:
- 2011-02-04T13:07:32Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 97e87de
- Parents:
- 621afdb (diff), ff244e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 4 added
- 9 edited
-
drv/generic/remote_usbhc.c (modified) (15 diffs)
-
drv/include/usbhc_iface.h (modified) (2 diffs)
-
usb/Makefile (modified) (1 diff)
-
usb/include/usb/classes/hid.h (modified) (2 diffs)
-
usb/include/usb/debug.h (modified) (1 diff)
-
usb/include/usb/pipes.h (added)
-
usb/include/usb/request.h (added)
-
usb/include/usb/usb.h (modified) (2 diffs)
-
usb/include/usb/usbdrv.h (modified) (3 diffs)
-
usb/src/debug.c (modified) (4 diffs)
-
usb/src/pipes.c (added)
-
usb/src/request.c (added)
-
usb/src/usbdrv.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usbhc.c
r621afdb r74d6e90 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 52 52 static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 56 static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 57 static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 81 83 remote_usbhc_control_read_setup, 82 84 remote_usbhc_control_read_data, 83 remote_usbhc_control_read_status 85 remote_usbhc_control_read_status, 86 87 remote_usbhc_control_write, 88 remote_usbhc_control_read 84 89 }; 85 90 … … 95 100 ipc_callid_t caller; 96 101 void *buffer; 102 void *setup_packet; 97 103 size_t size; 98 104 } async_transaction_t; 99 105 106 static void async_transaction_destroy(async_transaction_t *trans) 107 { 108 if (trans == NULL) { 109 return; 110 } 111 112 if (trans->setup_packet != NULL) { 113 free(trans->setup_packet); 114 } 115 if (trans->buffer != NULL) { 116 free(trans->buffer); 117 } 118 119 free(trans); 120 } 121 122 static async_transaction_t *async_transaction_create(ipc_callid_t caller) 123 { 124 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 125 if (trans == NULL) { 126 return NULL; 127 } 128 129 trans->caller = caller; 130 trans->buffer = NULL; 131 trans->setup_packet = NULL; 132 trans->size = 0; 133 134 return trans; 135 } 136 100 137 void remote_usbhc_get_address(device_t *device, void *iface, 101 138 ipc_callid_t callid, ipc_call_t *call) … … 130 167 if (trans->buffer == NULL) { 131 168 ipc_answer_0(callid, EINVAL); 132 free(trans);169 async_transaction_destroy(trans); 133 170 return; 134 171 } … … 138 175 if (!async_data_read_receive(&cid, &accepted_size)) { 139 176 ipc_answer_0(callid, EINVAL); 177 async_transaction_destroy(trans); 140 178 return; 141 179 } … … 148 186 ipc_answer_1(callid, EOK, accepted_size); 149 187 150 free(trans->buffer); 151 free(trans); 188 async_transaction_destroy(trans); 152 189 } 153 190 … … 242 279 async_transaction_t *trans = (async_transaction_t *)arg; 243 280 244 // FIXME - answer according to outcome245 281 ipc_answer_0(trans->caller, outcome); 246 282 247 free(trans);283 async_transaction_destroy(trans); 248 284 } 249 285 … … 253 289 async_transaction_t *trans = (async_transaction_t *)arg; 254 290 255 // FIXME - answer according to outcome 256 ipc_answer_1(trans->caller, outcome, (sysarg_t)trans); 291 if (outcome != USB_OUTCOME_OK) { 292 ipc_answer_0(trans->caller, outcome); 293 async_transaction_destroy(trans); 294 return; 295 } 257 296 258 297 trans->size = actual_size; 298 ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans); 259 299 } 260 300 … … 294 334 } 295 335 296 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 297 trans->caller = callid; 298 trans->buffer = buffer; 299 trans->size = len; 300 301 int rc = transfer_func(device, target, buffer, len, 302 callback_out, trans); 303 304 if (rc != EOK) { 305 ipc_answer_0(callid, rc); 336 async_transaction_t *trans = async_transaction_create(callid); 337 if (trans == NULL) { 306 338 if (buffer != NULL) { 307 339 free(buffer); 308 340 } 309 free(trans); 341 ipc_answer_0(callid, ENOMEM); 342 return; 343 } 344 345 trans->buffer = buffer; 346 trans->size = len; 347 348 int rc = transfer_func(device, target, buffer, len, 349 callback_out, trans); 350 351 if (rc != EOK) { 352 ipc_answer_0(callid, rc); 353 async_transaction_destroy(trans); 310 354 } 311 355 } … … 333 377 }; 334 378 335 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 336 trans->caller = callid; 379 async_transaction_t *trans = async_transaction_create(callid); 380 if (trans == NULL) { 381 ipc_answer_0(callid, ENOMEM); 382 return; 383 } 337 384 trans->buffer = malloc(len); 338 385 trans->size = len; … … 343 390 if (rc != EOK) { 344 391 ipc_answer_0(callid, rc); 345 free(trans->buffer); 346 free(trans); 392 async_transaction_destroy(trans); 347 393 } 348 394 } … … 388 434 }; 389 435 390 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 391 trans->caller = callid; 392 trans->buffer = NULL; 393 trans->size = 0; 436 async_transaction_t *trans = async_transaction_create(callid); 437 if (trans == NULL) { 438 ipc_answer_0(callid, ENOMEM); 439 return; 440 } 394 441 395 442 int rc; … … 410 457 if (rc != EOK) { 411 458 ipc_answer_0(callid, rc); 412 free(trans); 413 } 414 return; 459 async_transaction_destroy(trans); 460 } 415 461 } 416 462 … … 496 542 } 497 543 544 void remote_usbhc_control_write(device_t *device, void *iface, 545 ipc_callid_t callid, ipc_call_t *call) 546 { 547 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 548 assert(usb_iface != NULL); 549 550 if (!usb_iface->control_write) { 551 ipc_answer_0(callid, ENOTSUP); 552 return; 553 } 554 555 usb_target_t target = { 556 .address = DEV_IPC_GET_ARG1(*call), 557 .endpoint = DEV_IPC_GET_ARG2(*call) 558 }; 559 560 int rc; 561 562 void *setup_packet = NULL; 563 void *data_buffer = NULL; 564 size_t setup_packet_len = 0; 565 size_t data_buffer_len = 0; 566 567 rc = async_data_write_accept(&setup_packet, false, 568 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 569 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; 579 } 580 581 async_transaction_t *trans = async_transaction_create(callid); 582 if (trans == NULL) { 583 ipc_answer_0(callid, ENOMEM); 584 free(setup_packet); 585 free(data_buffer); 586 return; 587 } 588 trans->setup_packet = setup_packet; 589 trans->buffer = data_buffer; 590 trans->size = data_buffer_len; 591 592 rc = usb_iface->control_write(device, target, 593 setup_packet, setup_packet_len, 594 data_buffer, data_buffer_len, 595 callback_out, trans); 596 597 if (rc != EOK) { 598 ipc_answer_0(callid, rc); 599 async_transaction_destroy(trans); 600 } 601 } 602 603 604 void remote_usbhc_control_read(device_t *device, void *iface, 605 ipc_callid_t callid, ipc_call_t *call) 606 { 607 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 608 assert(usb_iface != NULL); 609 610 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); 616 usb_target_t target = { 617 .address = DEV_IPC_GET_ARG1(*call), 618 .endpoint = DEV_IPC_GET_ARG2(*call) 619 }; 620 621 int rc; 622 623 void *setup_packet = NULL; 624 size_t setup_packet_len = 0; 625 626 rc = async_data_write_accept(&setup_packet, false, 627 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 628 if (rc != EOK) { 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); 636 free(setup_packet); 637 return; 638 } 639 trans->setup_packet = setup_packet; 640 trans->size = data_len; 641 trans->buffer = malloc(data_len); 642 if (trans->buffer == NULL) { 643 ipc_answer_0(callid, ENOMEM); 644 async_transaction_destroy(trans); 645 return; 646 } 647 648 rc = usb_iface->control_read(device, target, 649 setup_packet, setup_packet_len, 650 trans->buffer, trans->size, 651 callback_in, trans); 652 653 if (rc != EOK) { 654 ipc_answer_0(callid, rc); 655 async_transaction_destroy(trans); 656 } 657 } 658 498 659 499 660 -
uspace/lib/drv/include/usbhc_iface.h
r621afdb r74d6e90 201 201 IPC_M_USBHC_CONTROL_READ_STATUS, 202 202 203 /** Issue control WRITE transfer. 204 * See explanation at usb_iface_funcs_t (OUT transaction) for 205 * call parameters. 206 * This call is immediately followed by two IPC data writes 207 * from the caller (setup packet and actual data). 208 */ 209 IPC_M_USBHC_CONTROL_WRITE, 210 211 /** Issue control WRITE transfer. 212 * See explanation at usb_iface_funcs_t (IN transaction) for 213 * call parameters. 214 * This call is immediately followed by IPC data read from the caller 215 * (setup packet). 216 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER. 217 */ 218 IPC_M_USBHC_CONTROL_READ, 203 219 204 220 /* IPC_M_USB_ */ … … 249 265 int (*control_read_status)(device_t *, usb_target_t, 250 266 usbhc_iface_transfer_out_callback_t, void *); 267 268 int (*control_write)(device_t *, usb_target_t, 269 void *, size_t, void *, size_t, 270 usbhc_iface_transfer_out_callback_t, void *); 271 272 int (*control_read)(device_t *, usb_target_t, 273 void *, size_t, void *, size_t, 274 usbhc_iface_transfer_in_callback_t, void *); 251 275 } usbhc_iface_t; 252 276 -
uspace/lib/usb/Makefile
r621afdb r74d6e90 43 43 src/hidparser.c \ 44 44 src/localdrv.c \ 45 src/pipes.c \ 45 46 src/recognise.c \ 46 47 src/remotedrv.c \ 48 src/request.c \ 47 49 src/usb.c \ 48 50 src/usbdrvreq.c \ -
uspace/lib/usb/include/usb/classes/hid.h
r621afdb r74d6e90 37 37 38 38 #include <usb/usb.h> 39 #include <driver.h>40 39 #include <usb/classes/hidparser.h> 41 40 #include <usb/descriptor.h> … … 101 100 } __attribute__ ((packed)) usb_standard_hid_descriptor_t; 102 101 103 /**104 *105 */106 typedef struct {107 usb_standard_interface_descriptor_t iface_desc;108 usb_standard_endpoint_descriptor_t *endpoints;109 usb_standard_hid_descriptor_t hid_desc;110 uint8_t *report_desc;111 //usb_standard_hid_class_descriptor_info_t *class_desc_info;112 //uint8_t **class_descs;113 } usb_hid_iface_t;114 115 /**116 *117 */118 typedef struct {119 usb_standard_configuration_descriptor_t config_descriptor;120 usb_hid_iface_t *interfaces;121 } usb_hid_configuration_t;122 123 /**124 * @brief USB/HID keyboard device type.125 *126 * Quite dummy right now.127 */128 typedef struct {129 device_t *device;130 usb_hid_configuration_t *conf;131 usb_address_t address;132 usb_endpoint_t poll_endpoint;133 usb_hid_report_parser_t *parser;134 } usb_hid_dev_kbd_t;135 136 // TODO: more configurations!137 102 138 103 #endif -
uspace/lib/usb/include/usb/debug.h
r621afdb r74d6e90 47 47 /** Logging level. */ 48 48 typedef enum { 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2, 55 USB_LOG_LEVEL_MAX 55 56 } usb_log_level_t; 56 57 -
uspace/lib/usb/include/usb/usb.h
r621afdb r74d6e90 37 37 38 38 #include <sys/types.h> 39 #include <byteorder.h> 39 40 #include <ipc/ipc.h> 41 42 /** Convert 16bit value from native (host) endianness to USB endianness. */ 43 #define uint16_host2usb(n) host2uint16_t_le((n)) 44 45 /** Convert 32bit value from native (host) endianness to USB endianness. */ 46 #define uint32_host2usb(n) host2uint32_t_le((n)) 47 48 /** Convert 16bit value from USB endianness into native (host) one. */ 49 #define uint16_usb2host(n) uint16_t_le2host((n)) 50 51 /** Convert 32bit value from USB endianness into native (host) one. */ 52 #define uint32_usb2host(n) uint32_t_le2host((n)) 53 40 54 41 55 /** USB transfer type. */ … … 52 66 typedef enum { 53 67 USB_DIRECTION_IN, 54 USB_DIRECTION_OUT 68 USB_DIRECTION_OUT, 69 USB_DIRECTION_BOTH 55 70 } usb_direction_t; 56 71 -
uspace/lib/usb/include/usb/usbdrv.h
r621afdb r74d6e90 70 70 usb_handle_t *); 71 71 72 int usb_drv_async_control_write(int, usb_target_t, 73 void *, size_t, void *, size_t, usb_handle_t *); 74 72 75 int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t); 73 76 int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t); … … 77 80 void *, size_t, void *, size_t); 78 81 79 80 82 int usb_drv_async_control_read_setup(int, usb_target_t, 81 83 void *, size_t, usb_handle_t *); … … 84 86 int usb_drv_async_control_read_status(int, usb_target_t, 85 87 usb_handle_t *); 88 89 int usb_drv_async_control_read(int, usb_target_t, 90 void *, size_t, void *, size_t, size_t *, usb_handle_t *); 86 91 87 92 int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t); -
uspace/lib/usb/src/debug.c
r621afdb r74d6e90 67 67 /** Serialization mutex for logging functions. */ 68 68 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 69 static FILE *log_stream = NULL; 69 70 70 71 /** Find or create new tag with given name. … … 171 172 log_prefix = message_prefix; 172 173 log_level = level; 174 if (log_stream == NULL) { 175 char *fname; 176 int rc = asprintf(&fname, "/log/%s", message_prefix); 177 if (rc > 0) { 178 log_stream = fopen(fname, "w"); 179 free(fname); 180 } 181 } 173 182 } 174 183 … … 197 206 void usb_log_printf(usb_log_level_t level, const char *format, ...) 198 207 { 199 if (level > log_level) {200 return;201 }202 203 208 FILE *stream = NULL; 204 209 switch (level) { … … 216 221 va_start(args, format); 217 222 223 /* 224 * Serialize access to log files. 225 * Always print to log file, to screen print only when the enabled 226 * log level is high enough. 227 */ 218 228 fibril_mutex_lock(&log_serializer); 219 fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level)); 220 vfprintf(stream, format, args); 229 230 const char *level_name = log_level_name(level); 231 232 if (log_stream != NULL) { 233 fprintf(log_stream, "[%s]%s: ", log_prefix, level_name); 234 vfprintf(log_stream, format, args); 235 } 236 237 if (level <= log_level) { 238 fprintf(stream, "[%s]%s: ", log_prefix, level_name); 239 vfprintf(stream, format, args); 240 } 241 221 242 fibril_mutex_unlock(&log_serializer); 222 243 -
uspace/lib/usb/src/usbdrv.c
r621afdb r74d6e90 495 495 } 496 496 497 /** Issue whole control write transfer. */ 498 int usb_drv_async_control_write(int phone, usb_target_t target, 499 void *setup_packet, size_t setup_packet_size, 500 void *buffer, size_t buffer_size, 501 usb_handle_t *handle) 502 { 503 // FIXME - check input parameters instead of asserting them 504 assert(phone > 0); 505 assert(setup_packet != NULL); 506 assert(setup_packet_size > 0); 507 assert(buffer != NULL); 508 assert(buffer_size > 0); 509 assert(handle != NULL); 510 511 transfer_info_t *transfer 512 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 513 if (transfer == NULL) { 514 return ENOMEM; 515 } 516 517 transfer->size_transferred = NULL; 518 transfer->buffer = NULL; 519 transfer->size = 0; 520 transfer->phone = phone; 521 522 int rc; 523 524 transfer->request = async_send_3(phone, 525 DEV_IFACE_ID(USBHC_DEV_IFACE), 526 IPC_M_USBHC_CONTROL_WRITE, 527 target.address, target.endpoint, 528 &transfer->reply); 529 530 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 531 if (rc != EOK) { 532 async_wait_for(transfer->request, NULL); 533 return rc; 534 } 535 536 rc = async_data_write_start(phone, buffer, buffer_size); 537 if (rc != EOK) { 538 async_wait_for(transfer->request, NULL); 539 return rc; 540 } 541 542 *handle = (usb_handle_t) transfer; 543 544 return EOK; 545 } 546 497 547 /** Start control read transfer. */ 498 548 int usb_drv_async_control_read_setup(int phone, usb_target_t target, … … 530 580 } 531 581 582 /** Issue whole control read transfer. */ 583 int usb_drv_async_control_read(int phone, usb_target_t target, 584 void *setup_packet, size_t setup_packet_size, 585 void *buffer, size_t buffer_size, size_t *actual_size, 586 usb_handle_t *handle) 587 { 588 // FIXME - check input parameters instead of asserting them 589 assert(phone > 0); 590 assert(setup_packet != NULL); 591 assert(setup_packet_size > 0); 592 assert(buffer != NULL); 593 assert(buffer_size > 0); 594 assert(handle != NULL); 595 596 transfer_info_t *transfer 597 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 598 if (transfer == NULL) { 599 return ENOMEM; 600 } 601 602 transfer->size_transferred = actual_size; 603 transfer->buffer = buffer; 604 transfer->size = buffer_size; 605 transfer->phone = phone; 606 607 int rc; 608 609 transfer->request = async_send_4(phone, 610 DEV_IFACE_ID(USBHC_DEV_IFACE), 611 IPC_M_USBHC_CONTROL_READ, 612 target.address, target.endpoint, 613 buffer_size, 614 &transfer->reply); 615 616 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 617 if (rc != EOK) { 618 async_wait_for(transfer->request, NULL); 619 return rc; 620 } 621 622 *handle = (usb_handle_t) transfer; 623 624 return EOK; 625 } 626 532 627 /** 533 628 * @}
Note:
See TracChangeset
for help on using the changeset viewer.
