source: mainline/uspace/srv/hid/console/console.c@ 5203e256

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5203e256 was 854eddd6, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Route mouse input through input server. Remove device-handling code from
console server.

  • Property mode set to 100644
File size: 20.2 KB
Line 
1/*
2 * Copyright (c) 2006 Josef Cejka
3 * Copyright (c) 2011 Jiri Svoboda
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup console
31 * @{
32 */
33/** @file
34 */
35
36#include <libc.h>
37#include <ipc/input.h>
38#include <io/keycode.h>
39#include <ipc/fb.h>
40#include <ipc/services.h>
41#include <ns.h>
42#include <ns_obsolete.h>
43#include <errno.h>
44#include <str_error.h>
45#include <ipc/console.h>
46#include <unistd.h>
47#include <async.h>
48#include <async_obsolete.h>
49#include <adt/fifo.h>
50#include <sys/mman.h>
51#include <stdio.h>
52#include <str.h>
53#include <sysinfo.h>
54#include <event.h>
55#include <devmap.h>
56#include <devmap_obsolete.h>
57#include <fcntl.h>
58#include <vfs/vfs.h>
59#include <fibril_synch.h>
60#include <io/style.h>
61#include <io/screenbuffer.h>
62
63#include "console.h"
64#include "gcons.h"
65#include "keybuffer.h"
66
67#define NAME "console"
68#define NAMESPACE "term"
69
70/** Phone to the input server. */
71static int input_phone;
72
73/** Information about framebuffer */
74struct {
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) */
79} fb_info;
80
81typedef struct {
82 size_t index; /**< Console index */
83 size_t refcount; /**< Connection reference count */
84 devmap_handle_t devmap_handle; /**< Device handle */
85 keybuffer_t keybuffer; /**< Buffer for incoming keys. */
86 screenbuffer_t scr; /**< Screenbuffer for saving screen
87 contents and related settings. */
88} console_t;
89
90/** Array of data for virtual consoles */
91static console_t consoles[CONSOLE_COUNT];
92
93static console_t *active_console = &consoles[0];
94static console_t *prev_console = &consoles[0];
95static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
96
97/** Pointer to memory shared with framebufer used for
98 faster virtual console switching */
99static keyfield_t *interbuffer = NULL;
100
101/** Information on row-span yet unsent to FB driver. */
102struct {
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. */
106} fb_pending;
107
108static FIBRIL_MUTEX_INITIALIZE(input_mutex);
109static FIBRIL_CONDVAR_INITIALIZE(input_cv);
110
111static void curs_visibility(bool visible)
112{
113 async_obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
114}
115
116static void curs_hide_sync(void)
117{
118 async_obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
119}
120
121static void curs_goto(sysarg_t x, sysarg_t y)
122{
123 async_obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
124}
125
126static void screen_clear(void)
127{
128 async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
129}
130
131static void screen_yield(void)
132{
133 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD);
134}
135
136static void screen_reclaim(void)
137{
138 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
139}
140
141static void input_yield(void)
142{
143 async_obsolete_req_0_0(input_phone, INPUT_YIELD);
144}
145
146static void input_reclaim(void)
147{
148 async_obsolete_req_0_0(input_phone, INPUT_RECLAIM);
149}
150
151static void set_style(uint8_t style)
152{
153 async_obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style);
154}
155
156static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
157{
158 async_obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
159}
160
161static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
162{
163 async_obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
164}
165
166static void set_attrs(attrs_t *attrs)
167{
168 switch (attrs->t) {
169 case at_style:
170 set_style(attrs->a.s.style);
171 break;
172 case at_idx:
173 set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
174 attrs->a.i.flags);
175 break;
176 case at_rgb:
177 set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
178 break;
179 }
180}
181
182static int ccap_fb_to_con(sysarg_t ccap_fb, sysarg_t *ccap_con)
183{
184 switch (ccap_fb) {
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
201 return EOK;
202}
203
204/** Send an area of screenbuffer to the FB driver. */
205static void fb_update_area(console_t *cons, sysarg_t x0, sysarg_t y0, sysarg_t width, sysarg_t height)
206{
207 if (interbuffer) {
208 sysarg_t x;
209 sysarg_t y;
210
211 for (y = 0; y < height; y++) {
212 for (x = 0; x < width; x++) {
213 interbuffer[y * width + x] =
214 *get_field_at(&cons->scr, x0 + x, y0 + y);
215 }
216 }
217
218 async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
219 x0, y0, width, height);
220 }
221}
222
223/** Flush pending cells to FB. */
224static void fb_pending_flush(void)
225{
226 if (fb_pending.cnt > 0) {
227 fb_update_area(active_console, fb_pending.col,
228 fb_pending.row, fb_pending.cnt, 1);
229 fb_pending.cnt = 0;
230 }
231}
232
233/** Mark a character cell as changed.
234 *
235 * This adds the cell to the pending rowspan if possible. Otherwise
236 * the old span is flushed first.
237 *
238 */
239static void cell_mark_changed(sysarg_t col, sysarg_t row)
240{
241 if (fb_pending.cnt != 0) {
242 if ((col != fb_pending.col + fb_pending.cnt)
243 || (row != fb_pending.row)) {
244 fb_pending_flush();
245 }
246 }
247
248 if (fb_pending.cnt == 0) {
249 fb_pending.col = col;
250 fb_pending.row = row;
251 }
252
253 fb_pending.cnt++;
254}
255
256/** Print a character to the active VC with buffering. */
257static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row)
258{
259 async_obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
260}
261
262/** Process a character from the client (TTY emulation). */
263static void write_char(console_t *cons, wchar_t ch)
264{
265 bool flush_cursor = false;
266
267 switch (ch) {
268 case '\n':
269 fb_pending_flush();
270 flush_cursor = true;
271 cons->scr.position_y++;
272 cons->scr.position_x = 0;
273 break;
274 case '\r':
275 break;
276 case '\t':
277 cons->scr.position_x += 8;
278 cons->scr.position_x -= cons->scr.position_x % 8;
279 break;
280 case '\b':
281 if (cons->scr.position_x == 0)
282 break;
283 cons->scr.position_x--;
284 if (cons == active_console)
285 cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
286 screenbuffer_putchar(&cons->scr, ' ');
287 break;
288 default:
289 if (cons == active_console)
290 cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
291
292 screenbuffer_putchar(&cons->scr, ch);
293 cons->scr.position_x++;
294 }
295
296 if (cons->scr.position_x >= cons->scr.size_x) {
297 flush_cursor = true;
298 cons->scr.position_y++;
299 }
300
301 if (cons->scr.position_y >= cons->scr.size_y) {
302 fb_pending_flush();
303 cons->scr.position_y = cons->scr.size_y - 1;
304 screenbuffer_clear_line(&cons->scr, cons->scr.top_line);
305 cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y;
306
307 if (cons == active_console)
308 async_obsolete_msg_1(fb_info.phone, FB_SCROLL, 1);
309 }
310
311 if (cons == active_console && flush_cursor)
312 curs_goto(cons->scr.position_x, cons->scr.position_y);
313 cons->scr.position_x = cons->scr.position_x % cons->scr.size_x;
314}
315
316/** Switch to new console */
317static void change_console(console_t *cons)
318{
319 if (cons == active_console)
320 return;
321
322 fb_pending_flush();
323
324 if (cons == kernel_console) {
325 async_obsolete_serialize_start();
326 curs_hide_sync();
327 gcons_in_kernel();
328 screen_yield();
329 input_yield();
330 async_obsolete_serialize_end();
331
332 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
333 prev_console = active_console;
334 active_console = kernel_console;
335 } else
336 cons = active_console;
337 }
338
339 if (cons != kernel_console) {
340 async_obsolete_serialize_start();
341
342 if (active_console == kernel_console) {
343 screen_reclaim();
344 input_reclaim();
345 gcons_redraw_console();
346 }
347
348 active_console = cons;
349 gcons_change_console(cons->index);
350
351 set_attrs(&cons->scr.attrs);
352 curs_visibility(false);
353
354 sysarg_t x;
355 sysarg_t y;
356 int rc = 0;
357
358 if (interbuffer) {
359 for (y = 0; y < cons->scr.size_y; y++) {
360 for (x = 0; x < cons->scr.size_x; x++) {
361 interbuffer[y * cons->scr.size_x + x] =
362 *get_field_at(&cons->scr, x, y);
363 }
364 }
365
366 /* This call can preempt, but we are already at the end */
367 rc = async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
368 0, 0, cons->scr.size_x,
369 cons->scr.size_y);
370 }
371
372 if ((!interbuffer) || (rc != 0)) {
373 set_attrs(&cons->scr.attrs);
374 screen_clear();
375
376 for (y = 0; y < cons->scr.size_y; y++)
377 for (x = 0; x < cons->scr.size_x; x++) {
378 keyfield_t *field = get_field_at(&cons->scr, x, y);
379
380 if (!attrs_same(cons->scr.attrs, field->attrs))
381 set_attrs(&field->attrs);
382
383 cons->scr.attrs = field->attrs;
384 if ((field->character == ' ') &&
385 (attrs_same(field->attrs, cons->scr.attrs)))
386 continue;
387
388 fb_putchar(field->character, x, y);
389 }
390 }
391
392 curs_goto(cons->scr.position_x, cons->scr.position_y);
393 curs_visibility(cons->scr.is_cursor_visible);
394
395 async_obsolete_serialize_end();
396 }
397}
398
399/** Handler for input events */
400static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
401{
402 /* Ignore parameters, the connection is already opened */
403 while (true) {
404 ipc_call_t call;
405 ipc_callid_t callid = async_get_call(&call);
406
407 int retval;
408 kbd_event_t ev;
409
410 if (!IPC_GET_IMETHOD(call)) {
411 /* TODO: Handle hangup */
412 async_obsolete_hangup(input_phone);
413 return;
414 }
415
416 switch (IPC_GET_IMETHOD(call)) {
417 case INPUT_EVENT_KEY:
418 /* Got key press/release event */
419 retval = 0;
420 ev.type = IPC_GET_ARG1(call);
421 ev.key = IPC_GET_ARG2(call);
422 ev.mods = IPC_GET_ARG3(call);
423 ev.c = IPC_GET_ARG4(call);
424
425 if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
426 CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
427 if (ev.key == KC_F1 + KERNEL_CONSOLE)
428 change_console(kernel_console);
429 else
430 change_console(&consoles[ev.key - KC_F1]);
431 break;
432 }
433
434 fibril_mutex_lock(&input_mutex);
435 keybuffer_push(&active_console->keybuffer, &ev);
436 fibril_condvar_broadcast(&input_cv);
437 fibril_mutex_unlock(&input_mutex);
438 break;
439 case INPUT_EVENT_MOVE:
440 /* Got pointer move event */
441 gcons_mouse_move((int) IPC_GET_ARG1(call),
442 (int) IPC_GET_ARG2(call));
443 retval = 0;
444 break;
445 case INPUT_EVENT_BUTTON:
446 /* Got pointer button press/release event */
447 if (IPC_GET_ARG1(call) == 1) {
448 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
449 if (newcon != -1)
450 change_console(&consoles[newcon]);
451 }
452 retval = 0;
453 break;
454 default:
455 retval = ENOENT;
456 }
457 async_answer_0(callid, retval);
458 }
459}
460
461static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
462{
463 void *buf;
464 size_t size;
465 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
466
467 if (rc != EOK) {
468 async_answer_0(rid, rc);
469 return;
470 }
471
472 async_obsolete_serialize_start();
473
474 size_t off = 0;
475 while (off < size) {
476 wchar_t ch = str_decode(buf, &off, size);
477 write_char(cons, ch);
478 }
479
480 async_obsolete_serialize_end();
481
482 gcons_notify_char(cons->index);
483 async_answer_1(rid, EOK, size);
484
485 free(buf);
486}
487
488static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
489{
490 ipc_callid_t callid;
491 size_t size;
492 if (!async_data_read_receive(&callid, &size)) {
493 async_answer_0(callid, EINVAL);
494 async_answer_0(rid, EINVAL);
495 return;
496 }
497
498 char *buf = (char *) malloc(size);
499 if (buf == NULL) {
500 async_answer_0(callid, ENOMEM);
501 async_answer_0(rid, ENOMEM);
502 return;
503 }
504
505 size_t pos = 0;
506 kbd_event_t ev;
507 fibril_mutex_lock(&input_mutex);
508
509recheck:
510 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
511 if (ev.type == KEY_PRESS) {
512 buf[pos] = ev.c;
513 pos++;
514 }
515 }
516
517 if (pos == size) {
518 (void) async_data_read_finalize(callid, buf, size);
519 async_answer_1(rid, EOK, size);
520 free(buf);
521 } else {
522 fibril_condvar_wait(&input_cv, &input_mutex);
523 goto recheck;
524 }
525
526 fibril_mutex_unlock(&input_mutex);
527}
528
529static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
530{
531 kbd_event_t ev;
532
533 fibril_mutex_lock(&input_mutex);
534
535recheck:
536 if (keybuffer_pop(&cons->keybuffer, &ev)) {
537 async_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
538 } else {
539 fibril_condvar_wait(&input_cv, &input_mutex);
540 goto recheck;
541 }
542
543 fibril_mutex_unlock(&input_mutex);
544}
545
546/** Default thread for new connections */
547static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
548{
549 console_t *cons = NULL;
550
551 size_t i;
552 for (i = 0; i < CONSOLE_COUNT; i++) {
553 if (i == KERNEL_CONSOLE)
554 continue;
555
556 if (consoles[i].devmap_handle == (devmap_handle_t) IPC_GET_ARG1(*icall)) {
557 cons = &consoles[i];
558 break;
559 }
560 }
561
562 if (cons == NULL) {
563 async_answer_0(iid, ENOENT);
564 return;
565 }
566
567 ipc_callid_t callid;
568 ipc_call_t call;
569 sysarg_t arg1;
570 sysarg_t arg2;
571 sysarg_t arg3;
572
573 int rc;
574
575 async_obsolete_serialize_start();
576 if (cons->refcount == 0)
577 gcons_notify_connect(cons->index);
578
579 cons->refcount++;
580
581 /* Accept the connection */
582 async_answer_0(iid, EOK);
583
584 while (true) {
585 async_obsolete_serialize_end();
586 callid = async_get_call(&call);
587 async_obsolete_serialize_start();
588
589 arg1 = 0;
590 arg2 = 0;
591 arg3 = 0;
592
593 if (!IPC_GET_IMETHOD(call)) {
594 cons->refcount--;
595 if (cons->refcount == 0)
596 gcons_notify_disconnect(cons->index);
597 return;
598 }
599
600 switch (IPC_GET_IMETHOD(call)) {
601 case VFS_OUT_READ:
602 async_obsolete_serialize_end();
603 cons_read(cons, callid, &call);
604 async_obsolete_serialize_start();
605 continue;
606 case VFS_OUT_WRITE:
607 async_obsolete_serialize_end();
608 cons_write(cons, callid, &call);
609 async_obsolete_serialize_start();
610 continue;
611 case VFS_OUT_SYNC:
612 fb_pending_flush();
613 if (cons == active_console) {
614 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
615 curs_goto(cons->scr.position_x, cons->scr.position_y);
616 }
617 break;
618 case CONSOLE_CLEAR:
619 /* Send message to fb */
620 if (cons == active_console)
621 async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
622
623 screenbuffer_clear(&cons->scr);
624
625 break;
626 case CONSOLE_GOTO:
627 screenbuffer_goto(&cons->scr,
628 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
629 if (cons == active_console)
630 curs_goto(IPC_GET_ARG1(call),
631 IPC_GET_ARG2(call));
632 break;
633 case CONSOLE_GET_POS:
634 arg1 = cons->scr.position_x;
635 arg2 = cons->scr.position_y;
636 break;
637 case CONSOLE_GET_SIZE:
638 arg1 = fb_info.cols;
639 arg2 = fb_info.rows;
640 break;
641 case CONSOLE_GET_COLOR_CAP:
642 rc = ccap_fb_to_con(fb_info.color_cap, &arg1);
643 if (rc != EOK) {
644 async_answer_0(callid, rc);
645 continue;
646 }
647 break;
648 case CONSOLE_SET_STYLE:
649 fb_pending_flush();
650 arg1 = IPC_GET_ARG1(call);
651 screenbuffer_set_style(&cons->scr, arg1);
652 if (cons == active_console)
653 set_style(arg1);
654 break;
655 case CONSOLE_SET_COLOR:
656 fb_pending_flush();
657 arg1 = IPC_GET_ARG1(call);
658 arg2 = IPC_GET_ARG2(call);
659 arg3 = IPC_GET_ARG3(call);
660 screenbuffer_set_color(&cons->scr, arg1, arg2, arg3);
661 if (cons == active_console)
662 set_color(arg1, arg2, arg3);
663 break;
664 case CONSOLE_SET_RGB_COLOR:
665 fb_pending_flush();
666 arg1 = IPC_GET_ARG1(call);
667 arg2 = IPC_GET_ARG2(call);
668 screenbuffer_set_rgb_color(&cons->scr, arg1, arg2);
669 if (cons == active_console)
670 set_rgb_color(arg1, arg2);
671 break;
672 case CONSOLE_CURSOR_VISIBILITY:
673 fb_pending_flush();
674 arg1 = IPC_GET_ARG1(call);
675 cons->scr.is_cursor_visible = arg1;
676 if (cons == active_console)
677 curs_visibility(arg1);
678 break;
679 case CONSOLE_GET_EVENT:
680 async_obsolete_serialize_end();
681 cons_get_event(cons, callid, &call);
682 async_obsolete_serialize_start();
683 continue;
684 case CONSOLE_KCON_ENABLE:
685 change_console(kernel_console);
686 break;
687 }
688 async_answer_3(callid, EOK, arg1, arg2, arg3);
689 }
690}
691
692static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
693{
694 change_console(prev_console);
695}
696
697static int connect_input(const char *dev_path)
698{
699 int phone;
700 devmap_handle_t handle;
701
702 int rc = devmap_device_get_handle(dev_path, &handle, 0);
703 if (rc == EOK) {
704 phone = devmap_obsolete_device_connect(handle, 0);
705 if (phone < 0) {
706 printf("%s: Failed to connect to input device\n", NAME);
707 return phone;
708 }
709 } else {
710 return rc;
711 }
712
713 /* NB: The callback connection is slotted for removal */
714 rc = async_obsolete_connect_to_me(phone, SERVICE_CONSOLE, 0, 0,
715 input_events, NULL);
716
717 if (rc != EOK) {
718 async_obsolete_hangup(phone);
719 printf("%s: Failed to create callback from input device (%s).\n",
720 NAME, str_error(rc));
721 return rc;
722 }
723
724 return phone;
725}
726
727static bool console_srv_init(char *input_dev)
728{
729 /* Connect to input server */
730 input_phone = connect_input(input_dev);
731 if (input_phone < 0)
732 return false;
733
734 /* Connect to framebuffer driver */
735 fb_info.phone = service_obsolete_connect_blocking(SERVICE_VIDEO, 0, 0);
736 if (fb_info.phone < 0) {
737 printf("%s: Failed to connect to video service\n", NAME);
738 return false;
739 }
740
741 /* Register driver */
742 int rc = devmap_driver_register(NAME, client_connection);
743 if (rc < 0) {
744 printf("%s: Unable to register driver (%d)\n", NAME, rc);
745 return false;
746 }
747
748 /* Initialize gcons */
749 gcons_init(fb_info.phone);
750
751 /* Synchronize, the gcons could put something in queue */
752 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
753 async_obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
754 async_obsolete_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
755
756 /* Set up shared memory buffer. */
757 size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
758 interbuffer = as_get_mappable_page(ib_size);
759
760 if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
761 AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer)
762 interbuffer = NULL;
763
764 if (interbuffer) {
765 if (async_obsolete_share_out_start(fb_info.phone, interbuffer,
766 AS_AREA_READ) != EOK) {
767 as_area_destroy(interbuffer);
768 interbuffer = NULL;
769 }
770 }
771
772 fb_pending.cnt = 0;
773
774 /* Inititalize consoles */
775 size_t i;
776 for (i = 0; i < CONSOLE_COUNT; i++) {
777 if (i != KERNEL_CONSOLE) {
778 if (screenbuffer_init(&consoles[i].scr,
779 fb_info.cols, fb_info.rows) == NULL) {
780 printf("%s: Unable to allocate screen buffer %zu\n", NAME, i);
781 return false;
782 }
783 screenbuffer_clear(&consoles[i].scr);
784 keybuffer_init(&consoles[i].keybuffer);
785 consoles[i].index = i;
786 consoles[i].refcount = 0;
787
788 char vc[DEVMAP_NAME_MAXLEN + 1];
789 snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
790
791 if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) {
792 printf("%s: Unable to register device %s\n", NAME, vc);
793 return false;
794 }
795 }
796 }
797
798 /* Disable kernel output to the console */
799 __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
800
801 /* Initialize the screen */
802 async_obsolete_serialize_start();
803 gcons_redraw_console();
804 set_style(STYLE_NORMAL);
805 screen_clear();
806 curs_goto(0, 0);
807 curs_visibility(active_console->scr.is_cursor_visible);
808 async_obsolete_serialize_end();
809
810 /* Receive kernel notifications */
811 async_set_interrupt_received(interrupt_received);
812 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
813 printf("%s: Error registering kconsole notifications\n", NAME);
814
815 return true;
816}
817
818static void usage(void)
819{
820 printf("Usage: console <input_dev>\n");
821}
822
823int main(int argc, char *argv[])
824{
825 if (argc < 2) {
826 usage();
827 return -1;
828 }
829
830 printf(NAME ": HelenOS Console service\n");
831
832 if (!console_srv_init(argv[1]))
833 return -1;
834
835 printf(NAME ": Accepting connections\n");
836 async_manager();
837
838 return 0;
839}
840
841/** @}
842 */
Note: See TracBrowser for help on using the repository browser.