Changes in uspace/srv/hid/console/console.c [b366a6f4:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
rb366a6f4 rffa2c8ef 1 1 /* 2 2 * Copyright (c) 2006 Josef Cejka 3 * Copyright (c) 2011 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 35 34 36 35 #include <libc.h> 37 #include <ipc/ input.h>36 #include <ipc/kbd.h> 38 37 #include <io/keycode.h> 38 #include <ipc/mouse.h> 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> … … 64 61 #include "keybuffer.h" 65 62 63 66 64 #define NAME "console" 67 65 #define NAMESPACE "term" 68 66 69 /** Session with the input server. */ 70 static async_sess_t *input_sess; 67 /** Phone to the keyboard driver. */ 68 static int kbd_phone; 69 70 /** Phone to the mouse driver. */ 71 static int mouse_phone; 71 72 72 73 /** Information about framebuffer */ … … 108 109 static FIBRIL_CONDVAR_INITIALIZE(input_cv); 109 110 110 static FIBRIL_MUTEX_INITIALIZE(big_console_lock);111 112 static void console_serialize_start(void)113 {114 fibril_mutex_lock(&big_console_lock);115 }116 117 static void console_serialize_end(void)118 {119 fibril_mutex_unlock(&big_console_lock);120 }121 122 111 static void curs_visibility(bool visible) 123 112 { 124 async_ obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);113 async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 125 114 } 126 115 127 116 static void curs_hide_sync(void) 128 117 { 129 async_ obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);118 async_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 130 119 } 131 120 132 121 static void curs_goto(sysarg_t x, sysarg_t y) 133 122 { 134 async_ obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);123 async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); 135 124 } 136 125 137 126 static void screen_clear(void) 138 127 { 139 async_ obsolete_msg_0(fb_info.phone, FB_CLEAR);128 async_msg_0(fb_info.phone, FB_CLEAR); 140 129 } 141 130 142 131 static void screen_yield(void) 143 132 { 144 async_ obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD);133 async_req_0_0(fb_info.phone, FB_SCREEN_YIELD); 145 134 } 146 135 147 136 static void screen_reclaim(void) 148 137 { 149 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 150 } 151 152 static void input_yield(void) 153 { 154 async_exch_t *exch = async_exchange_begin(input_sess); 155 if (exch == NULL) { 156 printf("%s: Failed starting exchange with input device.\n", 157 NAME); 158 return; 159 } 160 161 async_req_0_0(exch, INPUT_YIELD); 162 async_exchange_end(exch); 163 } 164 165 static void input_reclaim(void) 166 { 167 async_exch_t *exch = async_exchange_begin(input_sess); 168 if (exch == NULL) { 169 printf("%s: Failed starting exchange with input device.\n", 170 NAME); 171 return; 172 } 173 174 async_req_0_0(exch, INPUT_RECLAIM); 175 async_exchange_end(exch); 138 async_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 139 } 140 141 static void kbd_yield(void) 142 { 143 async_req_0_0(kbd_phone, KBD_YIELD); 144 } 145 146 static void kbd_reclaim(void) 147 { 148 async_req_0_0(kbd_phone, KBD_RECLAIM); 176 149 } 177 150 178 151 static void set_style(uint8_t style) 179 152 { 180 async_ obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style);153 async_msg_1(fb_info.phone, FB_SET_STYLE, style); 181 154 } 182 155 183 156 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 184 157 { 185 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); 186 159 } 187 160 188 161 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 189 162 { 190 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); 191 164 } 192 165 … … 243 216 } 244 217 245 async_ obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,218 async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 246 219 x0, y0, width, height); 247 220 } … … 284 257 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row) 285 258 { 286 async_ obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);259 async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); 287 260 } 288 261 … … 333 306 334 307 if (cons == active_console) 335 async_ obsolete_msg_1(fb_info.phone, FB_SCROLL, 1);308 async_msg_1(fb_info.phone, FB_SCROLL, 1); 336 309 } 337 310 … … 350 323 351 324 if (cons == kernel_console) { 352 console_serialize_start();325 async_serialize_start(); 353 326 curs_hide_sync(); 354 327 gcons_in_kernel(); 355 328 screen_yield(); 356 input_yield();357 console_serialize_end();358 359 if ( console_kcon()) {329 kbd_yield(); 330 async_serialize_end(); 331 332 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { 360 333 prev_console = active_console; 361 334 active_console = kernel_console; … … 365 338 366 339 if (cons != kernel_console) { 367 console_serialize_start();340 async_serialize_start(); 368 341 369 342 if (active_console == kernel_console) { 370 343 screen_reclaim(); 371 input_reclaim();344 kbd_reclaim(); 372 345 gcons_redraw_console(); 373 346 } … … 392 365 393 366 /* This call can preempt, but we are already at the end */ 394 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, 395 368 0, 0, cons->scr.size_x, 396 369 cons->scr.size_y); … … 420 393 curs_visibility(cons->scr.is_cursor_visible); 421 394 422 console_serialize_end();423 } 424 } 425 426 /** Handler for input events*/427 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)395 async_serialize_end(); 396 } 397 } 398 399 /** Handler for keyboard */ 400 static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) 428 401 { 429 402 /* Ignore parameters, the connection is already opened */ … … 433 406 434 407 int retval; 435 kbd_event_t ev; 436 437 if (!IPC_GET_IMETHOD(call)) { 408 console_event_t ev; 409 410 switch (IPC_GET_IMETHOD(call)) { 411 case IPC_M_PHONE_HUNGUP: 438 412 /* TODO: Handle hangup */ 439 async_hangup(input_sess);440 413 return; 441 } 442 443 switch (IPC_GET_IMETHOD(call)) { 444 case INPUT_EVENT_KEY: 445 /* Got key press/release event */ 414 case KBD_EVENT: 415 /* Got event from keyboard driver. */ 446 416 retval = 0; 447 417 ev.type = IPC_GET_ARG1(call); … … 464 434 fibril_mutex_unlock(&input_mutex); 465 435 break; 466 case INPUT_EVENT_MOVE: 467 /* Got pointer move event */ 468 gcons_mouse_move((int) IPC_GET_ARG1(call), 469 (int) IPC_GET_ARG2(call)); 470 retval = 0; 471 break; 472 case INPUT_EVENT_BUTTON: 473 /* Got pointer button press/release event */ 436 default: 437 retval = ENOENT; 438 } 439 async_answer_0(callid, retval); 440 } 441 } 442 443 /** Handler for mouse events */ 444 static void mouse_events(ipc_callid_t iid, ipc_call_t *icall) 445 { 446 /* Ignore parameters, the connection is already opened */ 447 while (true) { 448 ipc_call_t call; 449 ipc_callid_t callid = async_get_call(&call); 450 451 int retval; 452 453 switch (IPC_GET_IMETHOD(call)) { 454 case IPC_M_PHONE_HUNGUP: 455 /* TODO: Handle hangup */ 456 return; 457 case MEVENT_BUTTON: 474 458 if (IPC_GET_ARG1(call) == 1) { 475 459 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call)); … … 479 463 retval = 0; 480 464 break; 465 case MEVENT_MOVE: 466 gcons_mouse_move((int) IPC_GET_ARG1(call), 467 (int) IPC_GET_ARG2(call)); 468 retval = 0; 469 break; 481 470 default: 482 471 retval = ENOENT; … … 498 487 } 499 488 500 console_serialize_start();489 async_serialize_start(); 501 490 502 491 size_t off = 0; … … 506 495 } 507 496 508 console_serialize_end();497 async_serialize_end(); 509 498 510 499 gcons_notify_char(cons->index); … … 532 521 533 522 size_t pos = 0; 534 kbd_event_t ev;523 console_event_t ev; 535 524 fibril_mutex_lock(&input_mutex); 536 525 … … 557 546 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 558 547 { 559 kbd_event_t ev;548 console_event_t ev; 560 549 561 550 fibril_mutex_lock(&input_mutex); … … 573 562 574 563 /** Default thread for new connections */ 575 static void client_connection(ipc_callid_t iid, ipc_call_t *icall , void *arg)564 static void client_connection(ipc_callid_t iid, ipc_call_t *icall) 576 565 { 577 566 console_t *cons = NULL; … … 601 590 int rc; 602 591 603 console_serialize_start();592 async_serialize_start(); 604 593 if (cons->refcount == 0) 605 594 gcons_notify_connect(cons->index); … … 611 600 612 601 while (true) { 613 console_serialize_end();602 async_serialize_end(); 614 603 callid = async_get_call(&call); 615 console_serialize_start();604 async_serialize_start(); 616 605 617 606 arg1 = 0; … … 619 608 arg3 = 0; 620 609 621 if (!IPC_GET_IMETHOD(call)) { 610 switch (IPC_GET_IMETHOD(call)) { 611 case IPC_M_PHONE_HUNGUP: 622 612 cons->refcount--; 623 613 if (cons->refcount == 0) 624 614 gcons_notify_disconnect(cons->index); 625 console_serialize_end();626 615 return; 627 }628 629 switch (IPC_GET_IMETHOD(call)) {630 616 case VFS_OUT_READ: 631 console_serialize_end();617 async_serialize_end(); 632 618 cons_read(cons, callid, &call); 633 console_serialize_start();619 async_serialize_start(); 634 620 continue; 635 621 case VFS_OUT_WRITE: 636 console_serialize_end();622 async_serialize_end(); 637 623 cons_write(cons, callid, &call); 638 console_serialize_start();624 async_serialize_start(); 639 625 continue; 640 626 case VFS_OUT_SYNC: 641 627 fb_pending_flush(); 642 628 if (cons == active_console) { 643 async_ obsolete_req_0_0(fb_info.phone, FB_FLUSH);629 async_req_0_0(fb_info.phone, FB_FLUSH); 644 630 curs_goto(cons->scr.position_x, cons->scr.position_y); 645 631 } … … 648 634 /* Send message to fb */ 649 635 if (cons == active_console) 650 async_ obsolete_msg_0(fb_info.phone, FB_CLEAR);636 async_msg_0(fb_info.phone, FB_CLEAR); 651 637 652 638 screenbuffer_clear(&cons->scr); … … 707 693 break; 708 694 case CONSOLE_GET_EVENT: 709 console_serialize_end();695 async_serialize_end(); 710 696 cons_get_event(cons, callid, &call); 711 console_serialize_start();697 async_serialize_start(); 712 698 continue; 699 case CONSOLE_KCON_ENABLE: 700 change_console(kernel_console); 701 break; 713 702 } 714 703 async_answer_3(callid, EOK, arg1, arg2, arg3); … … 721 710 } 722 711 723 static async_sess_t *connect_input(const char *dev_path) 724 { 725 async_sess_t *sess; 726 async_exch_t *exch; 727 devmap_handle_t handle; 728 729 int rc = devmap_device_get_handle(dev_path, &handle, 0); 730 if (rc == EOK) { 731 sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0); 732 if (sess == NULL) { 733 printf("%s: Failed to connect to input server\n", NAME); 734 return NULL; 735 } 736 } else { 737 return NULL; 738 } 739 740 exch = async_exchange_begin(sess); 741 if (exch == NULL) { 742 printf("%s: Failed to create callback from input server.\n", NAME); 743 return NULL; 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; 744 725 } 745 726 746 727 /* NB: The callback connection is slotted for removal */ 747 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 748 749 async_exchange_end(exch); 750 751 if (rc != EOK) { 752 async_hangup(sess); 753 printf("%s: Failed to create callback from input server (%s).\n", 754 NAME, str_error(rc)); 755 return NULL; 756 } 757 758 return sess; 759 } 760 761 static bool console_srv_init(char *input_dev) 762 { 763 /* Connect to input server */ 764 input_sess = connect_input(input_dev); 765 if (input_sess == NULL) 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"); 766 731 return false; 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); 744 if (mouse_phone < 0) { 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: 767 757 768 758 /* Connect to framebuffer driver */ 769 fb_info.phone = service_ obsolete_connect_blocking(SERVICE_VIDEO, 0, 0);759 fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0); 770 760 if (fb_info.phone < 0) { 771 printf( "%s: Failed to connect to video service\n", NAME);772 return false;761 printf(NAME ": Failed to connect to video service\n"); 762 return -1; 773 763 } 774 764 … … 776 766 int rc = devmap_driver_register(NAME, client_connection); 777 767 if (rc < 0) { 778 printf( "%s: Unable to register driver (%d)\n", NAME, rc);768 printf(NAME ": Unable to register driver (%d)\n", rc); 779 769 return false; 780 770 } … … 784 774 785 775 /* Synchronize, the gcons could put something in queue */ 786 async_ obsolete_req_0_0(fb_info.phone, FB_FLUSH);787 async_ obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);788 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); 789 779 790 780 /* Set up shared memory buffer. */ … … 797 787 798 788 if (interbuffer) { 799 if (async_ obsolete_share_out_start(fb_info.phone, interbuffer,789 if (async_share_out_start(fb_info.phone, interbuffer, 800 790 AS_AREA_READ) != EOK) { 801 791 as_area_destroy(interbuffer); … … 812 802 if (screenbuffer_init(&consoles[i].scr, 813 803 fb_info.cols, fb_info.rows) == NULL) { 814 printf( "%s: Unable to allocate screen buffer %zu\n", NAME, i);804 printf(NAME ": Unable to allocate screen buffer %zu\n", i); 815 805 return false; 816 806 } … … 824 814 825 815 if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) { 826 printf( "%s: Unable to register device %s\n", NAME, vc);816 printf(NAME ": Unable to register device %s\n", vc); 827 817 return false; 828 818 } … … 830 820 } 831 821 822 /* Disable kernel output to the console */ 823 __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); 824 832 825 /* Initialize the screen */ 833 console_serialize_start();826 async_serialize_start(); 834 827 gcons_redraw_console(); 835 828 set_style(STYLE_NORMAL); … … 837 830 curs_goto(0, 0); 838 831 curs_visibility(active_console->scr.is_cursor_visible); 839 console_serialize_end();832 async_serialize_end(); 840 833 841 834 /* Receive kernel notifications */ 842 835 async_set_interrupt_received(interrupt_received); 843 836 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) 844 printf( "%s: Error registering kconsole notifications\n", NAME);837 printf(NAME ": Error registering kconsole notifications\n"); 845 838 846 839 return true; … … 849 842 static void usage(void) 850 843 { 851 printf("Usage: console <input _dev>\n");844 printf("Usage: console <input>\n"); 852 845 } 853 846 … … 861 854 printf(NAME ": HelenOS Console service\n"); 862 855 863 if (!console_ srv_init(argv[1]))856 if (!console_init(argv[1])) 864 857 return -1; 865 858
Note:
See TracChangeset
for help on using the changeset viewer.