Changeset 2a72d9f in mainline
- Timestamp:
- 2016-11-25T17:17:20Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6da5a6b
- Parents:
- 405b67c
- Location:
- uspace/srv/hid/input
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/Makefile
r405b67c r2a72d9f 30 30 USPACE_PREFIX = ../../.. 31 31 BINARY = input 32 LIBS = $(LIBDRV_PREFIX)/libdrv.a 33 EXTRA_CFLAGS = -I$(LIBDRV_PREFIX)/include 32 34 33 35 SOURCES = \ -
uspace/srv/hid/input/input.c
r405b67c r2a72d9f 54 54 #include <loc.h> 55 55 #include <str_error.h> 56 #include <char_dev_iface.h> 57 #include <fibril.h> 56 58 #include "layout.h" 57 59 #include "kbd.h" … … 60 62 #include "mouse.h" 61 63 #include "mouse_proto.h" 64 #include "serial.h" 62 65 #include "input.h" 63 66 … … 97 100 /** List of mouse devices */ 98 101 static list_t mouse_devs; 102 103 /** List of serial devices */ 104 static list_t serial_devs; 99 105 100 106 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); … … 395 401 mouse_dev_t *mdev = calloc(1, sizeof(mouse_dev_t)); 396 402 if (mdev == NULL) { 397 printf("%s: Error allocating keyboarddevice. "403 printf("%s: Error allocating mouse device. " 398 404 "Out of memory.\n", NAME); 399 405 return NULL; … … 403 409 404 410 return mdev; 411 } 412 413 static serial_dev_t *serial_dev_new(void) 414 { 415 serial_dev_t *sdev = calloc(1, sizeof(serial_dev_t)); 416 if (sdev == NULL) { 417 printf("%s: Error allocating serial device. " 418 "Out of memory.\n", NAME); 419 return NULL; 420 } 421 422 sdev->kdev = kbd_dev_new(); 423 if (sdev->kdev == NULL) { 424 free(sdev); 425 return NULL; 426 } 427 428 link_initialize(&sdev->link); 429 430 return sdev; 405 431 } 406 432 … … 532 558 return -1; 533 559 } 560 561 static int serial_consumer(void *arg) 562 { 563 serial_dev_t *sdev = (serial_dev_t *) arg; 564 565 while (true) { 566 uint8_t data; 567 568 char_dev_read(sdev->sess, &data, sizeof(data)); 569 kbd_push_data(sdev->kdev, data); 570 } 571 572 return EOK; 573 } 574 575 /** Add new serial console device. 576 * 577 * @param service_id Service ID of the chardev device 578 * 579 */ 580 static int serial_add_srldev(service_id_t service_id, serial_dev_t **sdevp) 581 { 582 serial_dev_t *sdev = serial_dev_new(); 583 if (sdev == NULL) 584 return -1; 585 586 sdev->kdev->svc_id = service_id; 587 sdev->kdev->port_ops = NULL; 588 sdev->kdev->ctl_ops = &stty_ctl; 589 590 sdev->sess = loc_service_connect(service_id, INTERFACE_DDF, 591 IPC_FLAG_BLOCKING); 592 593 int rc = loc_service_get_name(service_id, &sdev->kdev->svc_name); 594 if (rc != EOK) { 595 sdev->kdev->svc_name = NULL; 596 goto fail; 597 } 598 599 /* Initialize controller driver. */ 600 if ((*sdev->kdev->ctl_ops->init)(sdev->kdev) != 0) { 601 goto fail; 602 } 603 604 list_append(&sdev->link, &serial_devs); 605 606 fid_t fid = fibril_create(serial_consumer, sdev); 607 fibril_add_ready(fid); 608 609 *sdevp = sdev; 610 return EOK; 611 612 fail: 613 if (sdev->kdev->svc_name != NULL) 614 free(sdev->kdev->svc_name); 615 free(sdev->kdev); 616 free(sdev); 617 return -1; 618 } 619 534 620 535 621 /** Add legacy drivers/devices. */ … … 555 641 kbd_add_dev(&niagara_port, &stty_ctl); 556 642 #endif 557 #if defined(UARCH_sparc64) && defined(MACHINE_generic)558 kbd_add_dev(&ns16550_port, &sun_ctl);559 #endif560 643 /* Silence warning on abs32le about kbd_add_dev() being unused */ 561 644 (void) kbd_add_dev; … … 678 761 } 679 762 763 static int dev_check_new_serialdevs(void) 764 { 765 category_id_t serial_cat; 766 service_id_t *svcs; 767 size_t count, i; 768 bool already_known; 769 int rc; 770 771 rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING); 772 if (rc != EOK) { 773 printf("%s: Failed resolving category 'serial'.\n", NAME); 774 return ENOENT; 775 } 776 777 /* 778 * Check for new serial devices 779 */ 780 rc = loc_category_get_svcs(serial_cat, &svcs, &count); 781 if (rc != EOK) { 782 printf("%s: Failed getting list of serial devices.\n", 783 NAME); 784 return EIO; 785 } 786 787 for (i = 0; i < count; i++) { 788 already_known = false; 789 790 /* Determine whether we already know this device. */ 791 list_foreach(serial_devs, link, serial_dev_t, sdev) { 792 if (sdev->kdev->svc_id == svcs[i]) { 793 already_known = true; 794 break; 795 } 796 } 797 798 if (!already_known) { 799 serial_dev_t *sdev; 800 if (serial_add_srldev(svcs[i], &sdev) == EOK) { 801 printf("%s: Connected serial device '%s'\n", 802 NAME, sdev->kdev->svc_name); 803 } 804 } 805 } 806 807 free(svcs); 808 809 /* XXX Handle device removal */ 810 811 return EOK; 812 } 813 680 814 static int dev_check_new(void) 681 815 { … … 691 825 692 826 rc = dev_check_new_mousedevs(); 827 if (rc != EOK) { 828 fibril_mutex_unlock(&discovery_lock); 829 return rc; 830 } 831 832 rc = dev_check_new_serialdevs(); 693 833 if (rc != EOK) { 694 834 fibril_mutex_unlock(&discovery_lock); … … 738 878 list_initialize(&kbd_devs); 739 879 list_initialize(&mouse_devs); 880 list_initialize(&serial_devs); 740 881 741 882 if ((sysinfo_get_value("kbd.cir.obio", &obio) == EOK) && (obio))
Note:
See TracChangeset
for help on using the changeset viewer.