Changes in uspace/srv/hid/console/console.c [79ae36dd:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r79ae36dd rffa2c8ef 39 39 #include <ipc/fb.h> 40 40 #include <ipc/services.h> 41 #include <ns.h> 42 #include <ns_obsolete.h> 41 #include <ipc/ns.h> 43 42 #include <errno.h> 44 #include <str_error.h>45 43 #include <ipc/console.h> 46 44 #include <unistd.h> 47 45 #include <async.h> 48 #include <async_obsolete.h>49 46 #include <adt/fifo.h> 50 47 #include <sys/mman.h> … … 54 51 #include <event.h> 55 52 #include <devmap.h> 56 #include <devmap_obsolete.h>57 53 #include <fcntl.h> 58 54 #include <vfs/vfs.h> … … 60 56 #include <io/style.h> 61 57 #include <io/screenbuffer.h> 62 #include <inttypes.h>63 58 64 59 #include "console.h" … … 66 61 #include "keybuffer.h" 67 62 68 // FIXME: remove this header69 #include <kernel/ipc/ipc_methods.h>70 63 71 64 #define NAME "console" 72 65 #define NAMESPACE "term" 73 74 /** Interval for checking for new keyboard (1/4s). */75 #define HOTPLUG_WATCH_INTERVAL (1000 * 250)76 77 /* Kernel defines 32 but does not export it. */78 #define MAX_IPC_OUTGOING_PHONES 12879 80 /** To allow proper phone closing. */81 static ipc_callid_t driver_phones[MAX_IPC_OUTGOING_PHONES] = { 0 };82 66 83 67 /** Phone to the keyboard driver. */ … … 127 111 static void curs_visibility(bool visible) 128 112 { 129 async_ obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);113 async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 130 114 } 131 115 132 116 static void curs_hide_sync(void) 133 117 { 134 async_ obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);118 async_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 135 119 } 136 120 137 121 static void curs_goto(sysarg_t x, sysarg_t y) 138 122 { 139 async_ obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);123 async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); 140 124 } 141 125 142 126 static void screen_clear(void) 143 127 { 144 async_ obsolete_msg_0(fb_info.phone, FB_CLEAR);128 async_msg_0(fb_info.phone, FB_CLEAR); 145 129 } 146 130 147 131 static void screen_yield(void) 148 132 { 149 async_ obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD);133 async_req_0_0(fb_info.phone, FB_SCREEN_YIELD); 150 134 } 151 135 152 136 static void screen_reclaim(void) 153 137 { 154 async_ obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);138 async_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 155 139 } 156 140 157 141 static void kbd_yield(void) 158 142 { 159 async_ obsolete_req_0_0(kbd_phone, KBD_YIELD);143 async_req_0_0(kbd_phone, KBD_YIELD); 160 144 } 161 145 162 146 static void kbd_reclaim(void) 163 147 { 164 async_ obsolete_req_0_0(kbd_phone, KBD_RECLAIM);148 async_req_0_0(kbd_phone, KBD_RECLAIM); 165 149 } 166 150 167 151 static void set_style(uint8_t style) 168 152 { 169 async_ obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style);153 async_msg_1(fb_info.phone, FB_SET_STYLE, style); 170 154 } 171 155 172 156 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 173 157 { 174 async_ obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);158 async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); 175 159 } 176 160 177 161 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 178 162 { 179 async_ obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);163 async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 180 164 } 181 165 … … 232 216 } 233 217 234 async_ obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,218 async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 235 219 x0, y0, width, height); 236 220 } … … 273 257 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row) 274 258 { 275 async_ obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);259 async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); 276 260 } 277 261 … … 322 306 323 307 if (cons == active_console) 324 async_ obsolete_msg_1(fb_info.phone, FB_SCROLL, 1);308 async_msg_1(fb_info.phone, FB_SCROLL, 1); 325 309 } 326 310 … … 339 323 340 324 if (cons == kernel_console) { 341 async_ obsolete_serialize_start();325 async_serialize_start(); 342 326 curs_hide_sync(); 343 327 gcons_in_kernel(); 344 328 screen_yield(); 345 329 kbd_yield(); 346 async_ obsolete_serialize_end();330 async_serialize_end(); 347 331 348 332 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { … … 354 338 355 339 if (cons != kernel_console) { 356 async_ obsolete_serialize_start();340 async_serialize_start(); 357 341 358 342 if (active_console == kernel_console) { … … 381 365 382 366 /* This call can preempt, but we are already at the end */ 383 rc = async_ obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,367 rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 384 368 0, 0, cons->scr.size_x, 385 369 cons->scr.size_y); … … 409 393 curs_visibility(cons->scr.is_cursor_visible); 410 394 411 async_obsolete_serialize_end(); 412 } 413 } 414 415 static void close_driver_phone(ipc_callid_t hash) 416 { 417 int i; 418 for (i = 0; i < MAX_IPC_OUTGOING_PHONES; i++) { 419 if (driver_phones[i] == hash) { 420 printf("Device %" PRIxn " gone.\n", hash); 421 driver_phones[i] = 0; 422 async_obsolete_hangup(i); 423 return; 424 } 395 async_serialize_end(); 425 396 } 426 397 } … … 435 406 436 407 int retval; 437 kbd_event_t ev; 438 439 if (!IPC_GET_IMETHOD(call)) { 408 console_event_t ev; 409 410 switch (IPC_GET_IMETHOD(call)) { 411 case IPC_M_PHONE_HUNGUP: 440 412 /* TODO: Handle hangup */ 441 close_driver_phone(iid);442 413 return; 443 }444 445 switch (IPC_GET_IMETHOD(call)) {446 414 case KBD_EVENT: 447 415 /* Got event from keyboard driver. */ … … 483 451 int retval; 484 452 485 if (!IPC_GET_IMETHOD(call)) { 453 switch (IPC_GET_IMETHOD(call)) { 454 case IPC_M_PHONE_HUNGUP: 486 455 /* TODO: Handle hangup */ 487 close_driver_phone(iid);488 456 return; 489 }490 491 switch (IPC_GET_IMETHOD(call)) {492 457 case MEVENT_BUTTON: 493 458 if (IPC_GET_ARG1(call) == 1) { … … 522 487 } 523 488 524 async_ obsolete_serialize_start();489 async_serialize_start(); 525 490 526 491 size_t off = 0; … … 530 495 } 531 496 532 async_ obsolete_serialize_end();497 async_serialize_end(); 533 498 534 499 gcons_notify_char(cons->index); … … 556 521 557 522 size_t pos = 0; 558 kbd_event_t ev;523 console_event_t ev; 559 524 fibril_mutex_lock(&input_mutex); 560 525 … … 581 546 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 582 547 { 583 kbd_event_t ev;548 console_event_t ev; 584 549 585 550 fibril_mutex_lock(&input_mutex); … … 625 590 int rc; 626 591 627 async_ obsolete_serialize_start();592 async_serialize_start(); 628 593 if (cons->refcount == 0) 629 594 gcons_notify_connect(cons->index); … … 635 600 636 601 while (true) { 637 async_ obsolete_serialize_end();602 async_serialize_end(); 638 603 callid = async_get_call(&call); 639 async_ obsolete_serialize_start();604 async_serialize_start(); 640 605 641 606 arg1 = 0; … … 643 608 arg3 = 0; 644 609 645 if (!IPC_GET_IMETHOD(call)) { 610 switch (IPC_GET_IMETHOD(call)) { 611 case IPC_M_PHONE_HUNGUP: 646 612 cons->refcount--; 647 613 if (cons->refcount == 0) 648 614 gcons_notify_disconnect(cons->index); 649 615 return; 650 }651 652 switch (IPC_GET_IMETHOD(call)) {653 616 case VFS_OUT_READ: 654 async_ obsolete_serialize_end();617 async_serialize_end(); 655 618 cons_read(cons, callid, &call); 656 async_ obsolete_serialize_start();619 async_serialize_start(); 657 620 continue; 658 621 case VFS_OUT_WRITE: 659 async_ obsolete_serialize_end();622 async_serialize_end(); 660 623 cons_write(cons, callid, &call); 661 async_ obsolete_serialize_start();624 async_serialize_start(); 662 625 continue; 663 626 case VFS_OUT_SYNC: 664 627 fb_pending_flush(); 665 628 if (cons == active_console) { 666 async_ obsolete_req_0_0(fb_info.phone, FB_FLUSH);629 async_req_0_0(fb_info.phone, FB_FLUSH); 667 630 curs_goto(cons->scr.position_x, cons->scr.position_y); 668 631 } … … 671 634 /* Send message to fb */ 672 635 if (cons == active_console) 673 async_ obsolete_msg_0(fb_info.phone, FB_CLEAR);636 async_msg_0(fb_info.phone, FB_CLEAR); 674 637 675 638 screenbuffer_clear(&cons->scr); … … 730 693 break; 731 694 case CONSOLE_GET_EVENT: 732 async_ obsolete_serialize_end();695 async_serialize_end(); 733 696 cons_get_event(cons, callid, &call); 734 async_ obsolete_serialize_start();697 async_serialize_start(); 735 698 continue; 736 699 case CONSOLE_KCON_ENABLE: … … 747 710 } 748 711 749 static int async_connect_to_me_hack(int phone, sysarg_t arg1, sysarg_t arg2, 750 sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash) 751 { 752 sysarg_t task_hash; 753 sysarg_t phone_hash; 754 int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 755 NULL, NULL, NULL, &task_hash, &phone_hash); 756 if (rc != EOK) 757 return rc; 758 759 if (client_receiver != NULL) 760 async_new_connection(task_hash, phone_hash, phone_hash, NULL, 761 client_receiver); 762 763 if (hash != NULL) 764 *hash = phone_hash; 765 766 return EOK; 767 } 768 769 static int connect_keyboard_or_mouse(const char *devname, 770 async_client_conn_t handler, const char *dev) 771 { 772 int phone; 773 devmap_handle_t handle; 774 775 int rc = devmap_device_get_handle(dev, &handle, 0); 776 if (rc == EOK) { 777 phone = devmap_obsolete_device_connect(handle, 0); 778 if (phone < 0) { 779 printf("%s: Failed to connect to input device\n", NAME); 780 return phone; 781 } 782 } else 783 return rc; 712 static bool console_init(char *input) 713 { 714 /* Connect to input device */ 715 int input_fd = open(input, O_RDONLY); 716 if (input_fd < 0) { 717 printf(NAME ": Failed opening %s\n", input); 718 return false; 719 } 720 721 kbd_phone = fd_phone(input_fd); 722 if (kbd_phone < 0) { 723 printf(NAME ": Failed to connect to input device\n"); 724 return false; 725 } 784 726 785 727 /* NB: The callback connection is slotted for removal */ 786 ipc_callid_t hash; 787 rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone, 788 handler, &hash); 789 if (rc != EOK) { 790 async_obsolete_hangup(phone); 791 printf("%s: Failed to create callback from input device (%s).\n", 792 NAME, str_error(rc)); 793 return rc; 794 } 795 796 driver_phones[phone] = hash; 797 printf("%s: found %s \"%s\" (%" PRIxn ").\n", NAME, devname, dev, hash); 798 return phone; 799 } 800 801 static int connect_keyboard(const char *dev) 802 { 803 return connect_keyboard_or_mouse("keyboard", keyboard_events, dev); 804 } 805 806 static int connect_mouse(const char *dev) 807 { 808 return connect_keyboard_or_mouse("mouse", mouse_events, dev); 809 } 810 811 struct hid_class_info { 812 char *classname; 813 int (*connection_func)(const char *); 814 }; 815 816 /** Periodically check for new keyboards in /dev/class/. 817 * 818 * @param arg Class name. 819 * 820 * @return This function should never exit. 821 * 822 */ 823 static int check_new_device_fibril(void *arg) 824 { 825 struct hid_class_info *dev_info = (struct hid_class_info *) arg; 826 827 size_t index = 1; 828 829 while (true) { 830 async_usleep(HOTPLUG_WATCH_INTERVAL); 831 832 char *dev; 833 int rc = asprintf(&dev, "class/%s\\%zu", 834 dev_info->classname, index); 835 if (rc < 0) 836 continue; 837 838 rc = dev_info->connection_func(dev); 839 if (rc > 0) { 840 /* We do not allow unplug. */ 841 index++; 842 } 843 844 free(dev); 845 } 846 847 return EOK; 848 } 849 850 /** Start a fibril monitoring hot-plugged keyboards. 851 */ 852 static void check_new_devices_in_background(int (*connection_func)(const char *), 853 const char *classname) 854 { 855 struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info)); 856 if (dev_info == NULL) { 857 printf("%s: Out of memory, no hot-plug support.\n", NAME); 858 return; 859 } 860 861 int rc = asprintf(&dev_info->classname, "%s", classname); 862 if (rc < 0) { 863 printf("%s: Failed to format classname: %s.\n", NAME, 864 str_error(rc)); 865 return; 866 } 867 868 dev_info->connection_func = connection_func; 869 870 fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info); 871 if (!fid) { 872 printf("%s: Failed to create hot-plug fibril for %s.\n", NAME, 873 classname); 874 return; 875 } 876 877 fibril_add_ready(fid); 878 } 879 880 static bool console_srv_init(char *kdev) 881 { 882 /* Connect to input device */ 883 kbd_phone = connect_keyboard(kdev); 884 if (kbd_phone < 0) 728 if (async_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, keyboard_events) 729 != 0) { 730 printf(NAME ": Failed to create callback from input device\n"); 885 731 return false; 886 887 mouse_phone = connect_mouse("hid_in/mouse"); 732 } 733 734 /* Connect to mouse device */ 735 mouse_phone = -1; 736 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 737 738 if (mouse_fd < 0) { 739 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 740 goto skip_mouse; 741 } 742 743 mouse_phone = fd_phone(mouse_fd); 888 744 if (mouse_phone < 0) { 889 printf("%s: Failed to connect to mouse device %s\n", NAME, 890 str_error(mouse_phone)); 891 } 745 printf(NAME ": Failed to connect to mouse device\n"); 746 goto skip_mouse; 747 } 748 749 if (async_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, mouse_events) 750 != 0) { 751 printf(NAME ": Failed to create callback from mouse device\n"); 752 mouse_phone = -1; 753 goto skip_mouse; 754 } 755 756 skip_mouse: 892 757 893 758 /* Connect to framebuffer driver */ 894 fb_info.phone = service_ obsolete_connect_blocking(SERVICE_VIDEO, 0, 0);759 fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0); 895 760 if (fb_info.phone < 0) { 896 printf( "%s: Failed to connect to video service\n", NAME);897 return false;761 printf(NAME ": Failed to connect to video service\n"); 762 return -1; 898 763 } 899 764 … … 901 766 int rc = devmap_driver_register(NAME, client_connection); 902 767 if (rc < 0) { 903 printf( "%s: Unable to register driver (%d)\n", NAME, rc);768 printf(NAME ": Unable to register driver (%d)\n", rc); 904 769 return false; 905 770 } … … 909 774 910 775 /* Synchronize, the gcons could put something in queue */ 911 async_ obsolete_req_0_0(fb_info.phone, FB_FLUSH);912 async_ obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);913 async_ obsolete_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);776 async_req_0_0(fb_info.phone, FB_FLUSH); 777 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); 778 async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap); 914 779 915 780 /* Set up shared memory buffer. */ … … 922 787 923 788 if (interbuffer) { 924 if (async_ obsolete_share_out_start(fb_info.phone, interbuffer,789 if (async_share_out_start(fb_info.phone, interbuffer, 925 790 AS_AREA_READ) != EOK) { 926 791 as_area_destroy(interbuffer); … … 937 802 if (screenbuffer_init(&consoles[i].scr, 938 803 fb_info.cols, fb_info.rows) == NULL) { 939 printf( "%s: Unable to allocate screen buffer %zu\n", NAME, i);804 printf(NAME ": Unable to allocate screen buffer %zu\n", i); 940 805 return false; 941 806 } … … 949 814 950 815 if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) { 951 printf( "%s: Unable to register device %s\n", NAME, vc);816 printf(NAME ": Unable to register device %s\n", vc); 952 817 return false; 953 818 } … … 959 824 960 825 /* Initialize the screen */ 961 async_ obsolete_serialize_start();826 async_serialize_start(); 962 827 gcons_redraw_console(); 963 828 set_style(STYLE_NORMAL); … … 965 830 curs_goto(0, 0); 966 831 curs_visibility(active_console->scr.is_cursor_visible); 967 async_ obsolete_serialize_end();832 async_serialize_end(); 968 833 969 834 /* Receive kernel notifications */ 970 835 async_set_interrupt_received(interrupt_received); 971 836 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) 972 printf("%s: Error registering kconsole notifications\n", NAME); 973 974 /* Start fibril for checking on hot-plugged keyboards. */ 975 check_new_devices_in_background(connect_keyboard, "keyboard"); 976 check_new_devices_in_background(connect_mouse, "mouse"); 837 printf(NAME ": Error registering kconsole notifications\n"); 977 838 978 839 return true; … … 993 854 printf(NAME ": HelenOS Console service\n"); 994 855 995 if (!console_ srv_init(argv[1]))856 if (!console_init(argv[1])) 996 857 return -1; 997 858
Note:
See TracChangeset
for help on using the changeset viewer.