Changeset 04803bf in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2011-03-21T22:00:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 143932e3
- Parents:
- b50b5af2 (diff), 7308e84 (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. - File:
-
- 1 moved
-
uspace/srv/hid/console/console.c (moved) (moved from uspace/srv/console/console.c ) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
rb50b5af2 r04803bf 34 34 35 35 #include <libc.h> 36 #include <ipc/ipc.h>37 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 <ipc/ns.h> 41 42 #include <errno.h> 42 #include <keybuffer.h>43 43 #include <ipc/console.h> 44 44 #include <unistd.h> … … 47 47 #include <sys/mman.h> 48 48 #include <stdio.h> 49 #include <str ing.h>49 #include <str.h> 50 50 #include <sysinfo.h> 51 51 #include <event.h> 52 52 #include <devmap.h> 53 #include <fibril_sync.h> 53 #include <fcntl.h> 54 #include <vfs/vfs.h> 55 #include <fibril_synch.h> 56 #include <io/style.h> 57 #include <io/screenbuffer.h> 54 58 55 59 #include "console.h" 56 60 #include "gcons.h" 57 #include " screenbuffer.h"58 59 #define NAME "console" 60 61 #define MAX_DEVICE_NAME 3261 #include "keybuffer.h" 62 63 64 #define NAME "console" 65 #define NAMESPACE "term" 62 66 63 67 /** Phone to the keyboard driver. */ 64 68 static int kbd_phone; 65 69 70 /** Phone to the mouse driver. */ 71 static int mouse_phone; 72 66 73 /** Information about framebuffer */ 67 74 struct { 68 int phone; /**< Framebuffer phone */69 ipcarg_t cols;/**< Framebuffer columns */70 ipcarg_t rows;/**< Framebuffer rows */71 int color_cap;/**< Color capabilities (FB_CCAP_xxx) */75 int phone; /**< Framebuffer phone */ 76 sysarg_t cols; /**< Framebuffer columns */ 77 sysarg_t rows; /**< Framebuffer rows */ 78 sysarg_t color_cap; /**< Color capabilities (FB_CCAP_xxx) */ 72 79 } fb_info; 73 80 … … 75 82 size_t index; /**< Console index */ 76 83 size_t refcount; /**< Connection reference count */ 77 dev _handle_t dev_handle; /**< Device handle */84 devmap_handle_t devmap_handle; /**< Device handle */ 78 85 keybuffer_t keybuffer; /**< Buffer for incoming keys. */ 79 86 screenbuffer_t scr; /**< Screenbuffer for saving screen … … 94 101 /** Information on row-span yet unsent to FB driver. */ 95 102 struct { 96 s ize_t col; /**< Leftmost column of the span. */97 s ize_t row; /**< Row where the span lies. */98 s ize_t cnt; /**< Width of the span. */103 sysarg_t col; /**< Leftmost column of the span. */ 104 sysarg_t row; /**< Row where the span lies. */ 105 sysarg_t cnt; /**< Width of the span. */ 99 106 } fb_pending; 100 107 … … 109 116 static void curs_hide_sync(void) 110 117 { 111 ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);112 } 113 114 static void curs_goto(s ize_t x, size_t y)118 async_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 119 } 120 121 static void curs_goto(sysarg_t x, sysarg_t y) 115 122 { 116 123 async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); … … 124 131 static void screen_yield(void) 125 132 { 126 ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD);133 async_req_0_0(fb_info.phone, FB_SCREEN_YIELD); 127 134 } 128 135 129 136 static void screen_reclaim(void) 130 137 { 131 ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM);138 async_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 132 139 } 133 140 134 141 static void kbd_yield(void) 135 142 { 136 ipc_call_sync_0_0(kbd_phone, KBD_YIELD);143 async_req_0_0(kbd_phone, KBD_YIELD); 137 144 } 138 145 139 146 static void kbd_reclaim(void) 140 147 { 141 ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM);142 } 143 144 static void set_style( int style)148 async_req_0_0(kbd_phone, KBD_RECLAIM); 149 } 150 151 static void set_style(uint8_t style) 145 152 { 146 153 async_msg_1(fb_info.phone, FB_SET_STYLE, style); 147 154 } 148 155 149 static void set_color( int fgcolor, int bgcolor, int flags)156 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 150 157 { 151 158 async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); 152 159 } 153 160 154 static void set_rgb_color( int fgcolor, int bgcolor)161 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 155 162 { 156 163 async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); … … 173 180 } 174 181 175 static int ccap_fb_to_con( int ccap_fb, int *ccap_con)182 static int ccap_fb_to_con(sysarg_t ccap_fb, sysarg_t *ccap_con) 176 183 { 177 184 switch (ccap_fb) { 178 case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break; 179 case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break; 180 case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break; 181 case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break; 182 default: return EINVAL; 183 } 184 185 case FB_CCAP_NONE: 186 *ccap_con = CONSOLE_CCAP_NONE; 187 break; 188 case FB_CCAP_STYLE: 189 *ccap_con = CONSOLE_CCAP_STYLE; 190 break; 191 case FB_CCAP_INDEXED: 192 *ccap_con = CONSOLE_CCAP_INDEXED; 193 break; 194 case FB_CCAP_RGB: 195 *ccap_con = CONSOLE_CCAP_RGB; 196 break; 197 default: 198 return EINVAL; 199 } 200 185 201 return EOK; 186 202 } 187 203 188 204 /** Send an area of screenbuffer to the FB driver. */ 189 static void fb_update_area(console_t *cons, ipcarg_t x0, ipcarg_t y0, ipcarg_t width, ipcarg_t height)205 static void fb_update_area(console_t *cons, sysarg_t x0, sysarg_t y0, sysarg_t width, sysarg_t height) 190 206 { 191 207 if (interbuffer) { 192 ipcarg_t x;193 ipcarg_t y;208 sysarg_t x; 209 sysarg_t y; 194 210 195 211 for (y = 0; y < height; y++) { … … 221 237 * 222 238 */ 223 static void cell_mark_changed(s ize_t col, size_t row)239 static void cell_mark_changed(sysarg_t col, sysarg_t row) 224 240 { 225 241 if (fb_pending.cnt != 0) { … … 239 255 240 256 /** Print a character to the active VC with buffering. */ 241 static void fb_putchar(wchar_t c, ipcarg_t col, ipcarg_t row)257 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row) 242 258 { 243 259 async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); … … 248 264 { 249 265 bool flush_cursor = false; 250 266 251 267 switch (ch) { 252 268 case '\n': … … 292 308 async_msg_1(fb_info.phone, FB_SCROLL, 1); 293 309 } 294 310 295 311 if (cons == active_console && flush_cursor) 296 312 curs_goto(cons->scr.position_x, cons->scr.position_y); … … 322 338 323 339 if (cons != kernel_console) { 324 size_t x;325 size_t y;326 int rc = 0;327 328 340 async_serialize_start(); 329 341 … … 339 351 set_attrs(&cons->scr.attrs); 340 352 curs_visibility(false); 353 354 sysarg_t x; 355 sysarg_t y; 356 int rc = 0; 357 341 358 if (interbuffer) { 342 359 for (y = 0; y < cons->scr.size_y; y++) { … … 385 402 /* Ignore parameters, the connection is already opened */ 386 403 while (true) { 387 388 404 ipc_call_t call; 389 405 ipc_callid_t callid = async_get_call(&call); … … 392 408 console_event_t ev; 393 409 394 switch (IPC_GET_ METHOD(call)) {410 switch (IPC_GET_IMETHOD(call)) { 395 411 case IPC_M_PHONE_HUNGUP: 396 412 /* TODO: Handle hangup */ … … 421 437 retval = ENOENT; 422 438 } 423 ipc_answer_0(callid, retval); 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: 458 if (IPC_GET_ARG1(call) == 1) { 459 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call)); 460 if (newcon != -1) 461 change_console(&consoles[newcon]); 462 } 463 retval = 0; 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; 470 default: 471 retval = ENOENT; 472 } 473 474 async_answer_0(callid, retval); 424 475 } 425 476 } … … 427 478 static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 428 479 { 429 ipc_callid_t callid;480 void *buf; 430 481 size_t size; 431 if (!ipc_data_write_receive(&callid, &size)) { 432 ipc_answer_0(callid, EINVAL); 433 ipc_answer_0(rid, EINVAL); 482 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size); 483 484 if (rc != EOK) { 485 async_answer_0(rid, rc); 434 486 return; 435 487 } 436 437 char *buf = (char *) malloc(size);438 if (buf == NULL) {439 ipc_answer_0(callid, ENOMEM);440 ipc_answer_0(rid, ENOMEM);441 return;442 }443 444 (void) ipc_data_write_finalize(callid, buf, size);445 488 446 489 async_serialize_start(); … … 455 498 456 499 gcons_notify_char(cons->index); 457 ipc_answer_1(rid, EOK, size);500 async_answer_1(rid, EOK, size); 458 501 459 502 free(buf); … … 464 507 ipc_callid_t callid; 465 508 size_t size; 466 if (! ipc_data_read_receive(&callid, &size)) {467 ipc_answer_0(callid, EINVAL);468 ipc_answer_0(rid, EINVAL);509 if (!async_data_read_receive(&callid, &size)) { 510 async_answer_0(callid, EINVAL); 511 async_answer_0(rid, EINVAL); 469 512 return; 470 513 } … … 472 515 char *buf = (char *) malloc(size); 473 516 if (buf == NULL) { 474 ipc_answer_0(callid, ENOMEM);475 ipc_answer_0(rid, ENOMEM);517 async_answer_0(callid, ENOMEM); 518 async_answer_0(rid, ENOMEM); 476 519 return; 477 520 } … … 480 523 console_event_t ev; 481 524 fibril_mutex_lock(&input_mutex); 525 482 526 recheck: 483 527 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { … … 489 533 490 534 if (pos == size) { 491 (void) ipc_data_read_finalize(callid, buf, size);492 ipc_answer_1(rid, EOK, size);535 (void) async_data_read_finalize(callid, buf, size); 536 async_answer_1(rid, EOK, size); 493 537 free(buf); 494 538 } else { … … 496 540 goto recheck; 497 541 } 542 498 543 fibril_mutex_unlock(&input_mutex); 499 544 } … … 502 547 { 503 548 console_event_t ev; 504 549 505 550 fibril_mutex_lock(&input_mutex); 551 506 552 recheck: 507 553 if (keybuffer_pop(&cons->keybuffer, &ev)) { 508 ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);554 async_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c); 509 555 } else { 510 556 fibril_condvar_wait(&input_cv, &input_mutex); 511 557 goto recheck; 512 558 } 559 513 560 fibril_mutex_unlock(&input_mutex); 514 561 } … … 524 571 continue; 525 572 526 if (consoles[i].dev _handle == (dev_handle_t) IPC_GET_ARG1(*icall)) {573 if (consoles[i].devmap_handle == (devmap_handle_t) IPC_GET_ARG1(*icall)) { 527 574 cons = &consoles[i]; 528 575 break; … … 531 578 532 579 if (cons == NULL) { 533 ipc_answer_0(iid, ENOENT);580 async_answer_0(iid, ENOENT); 534 581 return; 535 582 } … … 537 584 ipc_callid_t callid; 538 585 ipc_call_t call; 539 ipcarg_t arg1; 540 ipcarg_t arg2; 541 ipcarg_t arg3; 542 543 int cons_ccap; 586 sysarg_t arg1; 587 sysarg_t arg2; 588 sysarg_t arg3; 589 544 590 int rc; 545 591 … … 551 597 552 598 /* Accept the connection */ 553 ipc_answer_0(iid, EOK);599 async_answer_0(iid, EOK); 554 600 555 601 while (true) { … … 562 608 arg3 = 0; 563 609 564 switch (IPC_GET_ METHOD(call)) {610 switch (IPC_GET_IMETHOD(call)) { 565 611 case IPC_M_PHONE_HUNGUP: 566 612 cons->refcount--; … … 582 628 if (cons == active_console) { 583 629 async_req_0_0(fb_info.phone, FB_FLUSH); 584 585 630 curs_goto(cons->scr.position_x, cons->scr.position_y); 586 631 } … … 601 646 IPC_GET_ARG2(call)); 602 647 break; 648 case CONSOLE_GET_POS: 649 arg1 = cons->scr.position_x; 650 arg2 = cons->scr.position_y; 651 break; 603 652 case CONSOLE_GET_SIZE: 604 653 arg1 = fb_info.cols; … … 606 655 break; 607 656 case CONSOLE_GET_COLOR_CAP: 608 rc = ccap_fb_to_con(fb_info.color_cap, & cons_ccap);657 rc = ccap_fb_to_con(fb_info.color_cap, &arg1); 609 658 if (rc != EOK) { 610 ipc_answer_0(callid, rc);659 async_answer_0(callid, rc); 611 660 continue; 612 661 } 613 arg1 = cons_ccap;614 662 break; 615 663 case CONSOLE_SET_STYLE: … … 653 701 break; 654 702 } 655 ipc_answer_3(callid, EOK, arg1, arg2, arg3);703 async_answer_3(callid, EOK, arg1, arg2, arg3); 656 704 } 657 705 } … … 662 710 } 663 711 664 static bool console_init(void) 665 { 666 ipcarg_t color_cap; 667 668 /* Connect to keyboard driver */ 669 kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); 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); 670 722 if (kbd_phone < 0) { 671 printf(NAME ": Failed to connect to keyboard service\n");723 printf(NAME ": Failed to connect to input device\n"); 672 724 return false; 673 725 } 674 726 675 ipcarg_t phonehash; 676 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 677 printf(NAME ": Failed to create callback from keyboard service\n"); 727 /* NB: The callback connection is slotted for removal */ 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"); 678 731 return false; 679 732 } 680 733 681 async_new_connection(phonehash, 0, NULL, keyboard_events); 682 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: 757 683 758 /* Connect to framebuffer driver */ 684 fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS,SERVICE_VIDEO, 0, 0);759 fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0); 685 760 if (fb_info.phone < 0) { 686 761 printf(NAME ": Failed to connect to video service\n"); … … 701 776 async_req_0_0(fb_info.phone, FB_FLUSH); 702 777 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); 703 async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap); 704 fb_info.color_cap = color_cap; 778 async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap); 705 779 706 780 /* Set up shared memory buffer. */ … … 713 787 714 788 if (interbuffer) { 715 if ( ipc_share_out_start(fb_info.phone, interbuffer,789 if (async_share_out_start(fb_info.phone, interbuffer, 716 790 AS_AREA_READ) != EOK) { 717 791 as_area_destroy(interbuffer); … … 728 802 if (screenbuffer_init(&consoles[i].scr, 729 803 fb_info.cols, fb_info.rows) == NULL) { 730 printf(NAME ": Unable to allocate screen buffer % u\n", i);804 printf(NAME ": Unable to allocate screen buffer %zu\n", i); 731 805 return false; 732 806 } … … 736 810 consoles[i].refcount = 0; 737 811 738 char vc[ MAX_DEVICE_NAME];739 snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);812 char vc[DEVMAP_NAME_MAXLEN + 1]; 813 snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); 740 814 741 if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) { 742 devmap_hangup_phone(DEVMAP_DRIVER); 815 if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) { 743 816 printf(NAME ": Unable to register device %s\n", vc); 744 817 return false; … … 753 826 async_serialize_start(); 754 827 gcons_redraw_console(); 755 set_ rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);828 set_style(STYLE_NORMAL); 756 829 screen_clear(); 757 830 curs_goto(0, 0); … … 760 833 761 834 /* Receive kernel notifications */ 835 async_set_interrupt_received(interrupt_received); 762 836 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) 763 837 printf(NAME ": Error registering kconsole notifications\n"); 764 838 765 async_set_interrupt_received(interrupt_received);766 767 839 return true; 768 840 } 769 841 842 static void usage(void) 843 { 844 printf("Usage: console <input>\n"); 845 } 846 770 847 int main(int argc, char *argv[]) 771 848 { 849 if (argc < 2) { 850 usage(); 851 return -1; 852 } 853 772 854 printf(NAME ": HelenOS Console service\n"); 773 855 774 if (!console_init( ))856 if (!console_init(argv[1])) 775 857 return -1; 776 858
Note:
See TracChangeset
for help on using the changeset viewer.
