Changeset 79ae36dd in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2011-06-08T19:01:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eff68e
- Parents:
- 764d71e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r764d71e r79ae36dd 39 39 #include <ipc/fb.h> 40 40 #include <ipc/services.h> 41 #include <ipc/ns.h> 41 #include <ns.h> 42 #include <ns_obsolete.h> 42 43 #include <errno.h> 43 44 #include <str_error.h> … … 45 46 #include <unistd.h> 46 47 #include <async.h> 48 #include <async_obsolete.h> 47 49 #include <adt/fifo.h> 48 50 #include <sys/mman.h> … … 52 54 #include <event.h> 53 55 #include <devmap.h> 56 #include <devmap_obsolete.h> 54 57 #include <fcntl.h> 55 58 #include <vfs/vfs.h> … … 63 66 #include "keybuffer.h" 64 67 68 // FIXME: remove this header 69 #include <kernel/ipc/ipc_methods.h> 65 70 66 71 #define NAME "console" 67 72 #define NAMESPACE "term" 73 68 74 /** Interval for checking for new keyboard (1/4s). */ 69 75 #define HOTPLUG_WATCH_INTERVAL (1000 * 250) … … 71 77 /* Kernel defines 32 but does not export it. */ 72 78 #define MAX_IPC_OUTGOING_PHONES 128 79 73 80 /** To allow proper phone closing. */ 74 81 static ipc_callid_t driver_phones[MAX_IPC_OUTGOING_PHONES] = { 0 }; … … 97 104 } console_t; 98 105 99 100 101 106 /** Array of data for virtual consoles */ 102 107 static console_t consoles[CONSOLE_COUNT]; … … 122 127 static void curs_visibility(bool visible) 123 128 { 124 async_ msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);129 async_obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 125 130 } 126 131 127 132 static void curs_hide_sync(void) 128 133 { 129 async_ req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);134 async_obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 130 135 } 131 136 132 137 static void curs_goto(sysarg_t x, sysarg_t y) 133 138 { 134 async_ msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);139 async_obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); 135 140 } 136 141 137 142 static void screen_clear(void) 138 143 { 139 async_ msg_0(fb_info.phone, FB_CLEAR);144 async_obsolete_msg_0(fb_info.phone, FB_CLEAR); 140 145 } 141 146 142 147 static void screen_yield(void) 143 148 { 144 async_ req_0_0(fb_info.phone, FB_SCREEN_YIELD);149 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD); 145 150 } 146 151 147 152 static void screen_reclaim(void) 148 153 { 149 async_ req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);154 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 150 155 } 151 156 152 157 static void kbd_yield(void) 153 158 { 154 async_ req_0_0(kbd_phone, KBD_YIELD);159 async_obsolete_req_0_0(kbd_phone, KBD_YIELD); 155 160 } 156 161 157 162 static void kbd_reclaim(void) 158 163 { 159 async_ req_0_0(kbd_phone, KBD_RECLAIM);164 async_obsolete_req_0_0(kbd_phone, KBD_RECLAIM); 160 165 } 161 166 162 167 static void set_style(uint8_t style) 163 168 { 164 async_ msg_1(fb_info.phone, FB_SET_STYLE, style);169 async_obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style); 165 170 } 166 171 167 172 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 168 173 { 169 async_ msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);174 async_obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); 170 175 } 171 176 172 177 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 173 178 { 174 async_ msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);179 async_obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 175 180 } 176 181 … … 227 232 } 228 233 229 async_ req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,234 async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 230 235 x0, y0, width, height); 231 236 } … … 268 273 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row) 269 274 { 270 async_ msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);275 async_obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); 271 276 } 272 277 … … 317 322 318 323 if (cons == active_console) 319 async_ msg_1(fb_info.phone, FB_SCROLL, 1);324 async_obsolete_msg_1(fb_info.phone, FB_SCROLL, 1); 320 325 } 321 326 … … 328 333 static void change_console(console_t *cons) 329 334 { 330 if (cons == active_console) {335 if (cons == active_console) 331 336 return; 332 }333 337 334 338 fb_pending_flush(); 335 339 336 340 if (cons == kernel_console) { 337 async_ serialize_start();341 async_obsolete_serialize_start(); 338 342 curs_hide_sync(); 339 343 gcons_in_kernel(); 340 344 screen_yield(); 341 345 kbd_yield(); 342 async_ serialize_end();346 async_obsolete_serialize_end(); 343 347 344 348 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { … … 350 354 351 355 if (cons != kernel_console) { 352 async_ serialize_start();356 async_obsolete_serialize_start(); 353 357 354 358 if (active_console == kernel_console) { … … 377 381 378 382 /* This call can preempt, but we are already at the end */ 379 rc = async_ req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,383 rc = async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 380 384 0, 0, cons->scr.size_x, 381 385 cons->scr.size_y); … … 405 409 curs_visibility(cons->scr.is_cursor_visible); 406 410 407 async_ serialize_end();411 async_obsolete_serialize_end(); 408 412 } 409 413 } … … 416 420 printf("Device %" PRIxn " gone.\n", hash); 417 421 driver_phones[i] = 0; 418 async_ hangup(i);422 async_obsolete_hangup(i); 419 423 return; 420 424 } … … 431 435 432 436 int retval; 433 console_event_t ev; 434 435 switch (IPC_GET_IMETHOD(call)) { 436 case IPC_M_PHONE_HUNGUP: 437 kbd_event_t ev; 438 439 if (!IPC_GET_IMETHOD(call)) { 437 440 /* TODO: Handle hangup */ 438 441 close_driver_phone(iid); 439 442 return; 443 } 444 445 switch (IPC_GET_IMETHOD(call)) { 440 446 case KBD_EVENT: 441 447 /* Got event from keyboard driver. */ … … 477 483 int retval; 478 484 479 switch (IPC_GET_IMETHOD(call)) { 480 case IPC_M_PHONE_HUNGUP: 485 if (!IPC_GET_IMETHOD(call)) { 481 486 /* TODO: Handle hangup */ 482 487 close_driver_phone(iid); 483 488 return; 489 } 490 491 switch (IPC_GET_IMETHOD(call)) { 484 492 case MEVENT_BUTTON: 485 493 if (IPC_GET_ARG1(call) == 1) { 486 494 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call)); 487 if (newcon != -1) {495 if (newcon != -1) 488 496 change_console(&consoles[newcon]); 489 }490 497 } 491 498 retval = 0; … … 515 522 } 516 523 517 async_ serialize_start();524 async_obsolete_serialize_start(); 518 525 519 526 size_t off = 0; … … 523 530 } 524 531 525 async_ serialize_end();532 async_obsolete_serialize_end(); 526 533 527 534 gcons_notify_char(cons->index); … … 549 556 550 557 size_t pos = 0; 551 console_event_t ev;558 kbd_event_t ev; 552 559 fibril_mutex_lock(&input_mutex); 553 560 … … 574 581 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 575 582 { 576 console_event_t ev;583 kbd_event_t ev; 577 584 578 585 fibril_mutex_lock(&input_mutex); … … 618 625 int rc; 619 626 620 async_ serialize_start();627 async_obsolete_serialize_start(); 621 628 if (cons->refcount == 0) 622 629 gcons_notify_connect(cons->index); … … 628 635 629 636 while (true) { 630 async_ serialize_end();637 async_obsolete_serialize_end(); 631 638 callid = async_get_call(&call); 632 async_ serialize_start();639 async_obsolete_serialize_start(); 633 640 634 641 arg1 = 0; … … 636 643 arg3 = 0; 637 644 638 switch (IPC_GET_IMETHOD(call)) { 639 case IPC_M_PHONE_HUNGUP: 645 if (!IPC_GET_IMETHOD(call)) { 640 646 cons->refcount--; 641 647 if (cons->refcount == 0) 642 648 gcons_notify_disconnect(cons->index); 643 649 return; 650 } 651 652 switch (IPC_GET_IMETHOD(call)) { 644 653 case VFS_OUT_READ: 645 async_ serialize_end();654 async_obsolete_serialize_end(); 646 655 cons_read(cons, callid, &call); 647 async_ serialize_start();656 async_obsolete_serialize_start(); 648 657 continue; 649 658 case VFS_OUT_WRITE: 650 async_ serialize_end();659 async_obsolete_serialize_end(); 651 660 cons_write(cons, callid, &call); 652 async_ serialize_start();661 async_obsolete_serialize_start(); 653 662 continue; 654 663 case VFS_OUT_SYNC: 655 664 fb_pending_flush(); 656 665 if (cons == active_console) { 657 async_ req_0_0(fb_info.phone, FB_FLUSH);666 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH); 658 667 curs_goto(cons->scr.position_x, cons->scr.position_y); 659 668 } … … 662 671 /* Send message to fb */ 663 672 if (cons == active_console) 664 async_ msg_0(fb_info.phone, FB_CLEAR);673 async_obsolete_msg_0(fb_info.phone, FB_CLEAR); 665 674 666 675 screenbuffer_clear(&cons->scr); … … 721 730 break; 722 731 case CONSOLE_GET_EVENT: 723 async_ serialize_end();732 async_obsolete_serialize_end(); 724 733 cons_get_event(cons, callid, &call); 725 async_ serialize_start();734 async_obsolete_serialize_start(); 726 735 continue; 727 736 case CONSOLE_KCON_ENABLE: … … 739 748 740 749 static int async_connect_to_me_hack(int phone, sysarg_t arg1, sysarg_t arg2, 741 sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash)750 sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash) 742 751 { 743 752 sysarg_t task_hash; 744 753 sysarg_t phone_hash; 745 int rc = async_ req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,754 int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 746 755 NULL, NULL, NULL, &task_hash, &phone_hash); 747 756 if (rc != EOK) 748 757 return rc; 749 758 750 759 if (client_receiver != NULL) 751 760 async_new_connection(task_hash, phone_hash, phone_hash, NULL, 752 761 client_receiver); 753 754 if (hash != NULL) {762 763 if (hash != NULL) 755 764 *hash = phone_hash; 756 } 757 765 758 766 return EOK; 759 767 } 760 768 761 769 static int connect_keyboard_or_mouse(const char *devname, 762 async_client_conn_t handler, const char *path) 763 { 764 int fd = open(path, O_RDONLY); 765 if (fd < 0) { 766 return fd; 767 } 768 769 int phone = fd_phone(fd); 770 close(fd); 771 if (phone < 0) { 772 printf(NAME ": Failed to connect to input device\n"); 773 return phone; 774 } 775 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; 784 785 /* NB: The callback connection is slotted for removal */ 776 786 ipc_callid_t hash; 777 intrc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,787 rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone, 778 788 handler, &hash); 779 789 if (rc != EOK) { 780 async_hangup(phone); 781 printf(NAME ": " \ 782 "Failed to create callback from input device: %s.\n", 783 str_error(rc)); 790 async_obsolete_hangup(phone); 791 printf("%s: Failed to create callback from input device (%s).\n", 792 NAME, str_error(rc)); 784 793 return rc; 785 794 } 786 795 787 796 driver_phones[phone] = hash; 788 789 printf(NAME ": found %s \"%s\" (%" PRIxn ").\n", devname, path, hash); 790 797 printf("%s: found %s \"%s\" (%" PRIxn ").\n", NAME, devname, dev, hash); 791 798 return phone; 792 799 } 793 800 794 static int connect_keyboard(const char * path)795 { 796 return connect_keyboard_or_mouse("keyboard", keyboard_events, path);797 } 798 799 static int connect_mouse(const char * path)800 { 801 return connect_keyboard_or_mouse("mouse", mouse_events, path);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); 802 809 } 803 810 … … 810 817 * 811 818 * @param arg Class name. 819 * 812 820 * @return This function should never exit. 821 * 813 822 */ 814 823 static int check_new_device_fibril(void *arg) 815 824 { 816 struct hid_class_info *dev_info = arg;817 825 struct hid_class_info *dev_info = (struct hid_class_info *) arg; 826 818 827 size_t index = 1; 819 828 820 829 while (true) { 821 830 async_usleep(HOTPLUG_WATCH_INTERVAL); 822 char *path; 823 int rc = asprintf(&path, "/dev/class/%s\\%zu", 831 832 char *dev; 833 int rc = asprintf(&dev, "class/%s\\%zu", 824 834 dev_info->classname, index); 825 if (rc < 0) {835 if (rc < 0) 826 836 continue; 827 } 828 rc = 0; 829 rc = dev_info->connection_func(path); 837 838 rc = dev_info->connection_func(dev); 830 839 if (rc > 0) { 831 840 /* We do not allow unplug. */ 832 841 index++; 833 842 } 834 835 free( path);836 } 837 843 844 free(dev); 845 } 846 838 847 return EOK; 839 848 } 840 841 849 842 850 /** Start a fibril monitoring hot-plugged keyboards. … … 847 855 struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info)); 848 856 if (dev_info == NULL) { 849 printf(NAME ": " \ 850 "out of memory, will not start hot-plug-watch fibril.\n"); 857 printf("%s: Out of memory, no hot-plug support.\n", NAME); 851 858 return; 852 859 } 853 int rc; 854 855 rc = asprintf(&dev_info->classname, "%s", classname); 860 861 int rc = asprintf(&dev_info->classname, "%s", classname); 856 862 if (rc < 0) { 857 printf( NAME ": failed to format classname: %s.\n",863 printf("%s: Failed to format classname: %s.\n", NAME, 858 864 str_error(rc)); 859 865 return; 860 866 } 867 861 868 dev_info->connection_func = connection_func; 862 863 fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info);869 870 fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info); 864 871 if (!fid) { 865 printf(NAME 866 ": failed to create hot-plug-watch fibril for %s.\n", 872 printf("%s: Failed to create hot-plug fibril for %s.\n", NAME, 867 873 classname); 868 874 return; 869 875 } 876 870 877 fibril_add_ready(fid); 871 878 } 872 879 873 static bool console_ init(char *input)880 static bool console_srv_init(char *kdev) 874 881 { 875 882 /* Connect to input device */ 876 kbd_phone = connect_keyboard( input);877 if (kbd_phone < 0) {883 kbd_phone = connect_keyboard(kdev); 884 if (kbd_phone < 0) 878 885 return false; 879 } 880 881 mouse_phone = connect_mouse("/dev/hid_in/mouse"); 886 887 mouse_phone = connect_mouse("hid_in/mouse"); 882 888 if (mouse_phone < 0) { 883 printf( NAME ": Failed to connect to mouse device: %s.\n",889 printf("%s: Failed to connect to mouse device %s\n", NAME, 884 890 str_error(mouse_phone)); 885 891 } 886 892 887 893 /* Connect to framebuffer driver */ 888 fb_info.phone = service_ connect_blocking(SERVICE_VIDEO, 0, 0);894 fb_info.phone = service_obsolete_connect_blocking(SERVICE_VIDEO, 0, 0); 889 895 if (fb_info.phone < 0) { 890 printf( NAME ": Failed to connect to video service\n");891 return -1;896 printf("%s: Failed to connect to video service\n", NAME); 897 return false; 892 898 } 893 899 … … 895 901 int rc = devmap_driver_register(NAME, client_connection); 896 902 if (rc < 0) { 897 printf( NAME ": Unable to register driver (%d)\n", rc);903 printf("%s: Unable to register driver (%d)\n", NAME, rc); 898 904 return false; 899 905 } … … 903 909 904 910 /* Synchronize, the gcons could put something in queue */ 905 async_ req_0_0(fb_info.phone, FB_FLUSH);906 async_ req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);907 async_ req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);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); 908 914 909 915 /* Set up shared memory buffer. */ … … 916 922 917 923 if (interbuffer) { 918 if (async_ share_out_start(fb_info.phone, interbuffer,924 if (async_obsolete_share_out_start(fb_info.phone, interbuffer, 919 925 AS_AREA_READ) != EOK) { 920 926 as_area_destroy(interbuffer); … … 931 937 if (screenbuffer_init(&consoles[i].scr, 932 938 fb_info.cols, fb_info.rows) == NULL) { 933 printf( NAME ": Unable to allocate screen buffer %zu\n", i);939 printf("%s: Unable to allocate screen buffer %zu\n", NAME, i); 934 940 return false; 935 941 } … … 943 949 944 950 if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) { 945 printf( NAME ": Unable to register device %s\n", vc);951 printf("%s: Unable to register device %s\n", NAME, vc); 946 952 return false; 947 953 } … … 953 959 954 960 /* Initialize the screen */ 955 async_ serialize_start();961 async_obsolete_serialize_start(); 956 962 gcons_redraw_console(); 957 963 set_style(STYLE_NORMAL); … … 959 965 curs_goto(0, 0); 960 966 curs_visibility(active_console->scr.is_cursor_visible); 961 async_ serialize_end();967 async_obsolete_serialize_end(); 962 968 963 969 /* Receive kernel notifications */ 964 970 async_set_interrupt_received(interrupt_received); 965 971 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) 966 printf( NAME ": Error registering kconsole notifications\n");972 printf("%s: Error registering kconsole notifications\n", NAME); 967 973 968 974 /* Start fibril for checking on hot-plugged keyboards. */ 969 975 check_new_devices_in_background(connect_keyboard, "keyboard"); 970 976 check_new_devices_in_background(connect_mouse, "mouse"); 971 977 972 978 return true; 973 979 } … … 987 993 printf(NAME ": HelenOS Console service\n"); 988 994 989 if (!console_ init(argv[1]))995 if (!console_srv_init(argv[1])) 990 996 return -1; 991 997 992 998 printf(NAME ": Accepting connections\n"); 993 999 async_manager();
Note:
See TracChangeset
for help on using the changeset viewer.