source: mainline/uspace/srv/hid/input/input.c@ 71eff34

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 71eff34 was df1a019, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Switch to kernel console with F12.

  • Property mode set to 100644
File size: 19.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/**
31 * @addtogroup inputgen generic
32 * @brief HelenOS input server.
33 * @ingroup input
34 * @{
35 */
36/** @file
37 */
38
39#include <adt/fifo.h>
40#include <adt/list.h>
41#include <async.h>
42#include <config.h>
43#include <errno.h>
44#include <fibril.h>
45#include <fibril_synch.h>
46#include <io/chardev.h>
47#include <io/console.h>
48#include <io/keycode.h>
49#include <ipc/services.h>
50#include <ipc/input.h>
51#include <loc.h>
52#include <ns.h>
53#include <stdbool.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <str.h>
57#include <str_error.h>
58
59#include "input.h"
60#include "kbd.h"
61#include "kbd_port.h"
62#include "kbd_ctl.h"
63#include "layout.h"
64#include "mouse.h"
65#include "mouse_proto.h"
66#include "serial.h"
67
68#define NUM_LAYOUTS 5
69
70static layout_ops_t *layout[NUM_LAYOUTS] = {
71 &us_qwerty_ops,
72 &us_dvorak_ops,
73 &cz_ops,
74 &ar_ops,
75 &fr_azerty_ops
76};
77
78typedef struct {
79 /** Link into the list of clients */
80 link_t link;
81
82 /** Indicate whether the client is active */
83 bool active;
84
85 /** Client callback session */
86 async_sess_t *sess;
87} client_t;
88
89/** List of clients */
90static list_t clients;
91static client_t *active_client = NULL;
92
93/** Kernel override */
94static bool active = true;
95
96/** Serial console specified by the user */
97static char *serial_console;
98
99/** List of keyboard devices */
100static list_t kbd_devs;
101
102/** List of mouse devices */
103static list_t mouse_devs;
104
105/** List of serial devices */
106static list_t serial_devs;
107
108static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
109
110static void *client_data_create(void)
111{
112 client_t *client = (client_t *) calloc(1, sizeof(client_t));
113 if (client == NULL)
114 return NULL;
115
116 link_initialize(&client->link);
117 client->active = false;
118 client->sess = NULL;
119
120 list_append(&client->link, &clients);
121
122 return client;
123}
124
125static void client_data_destroy(void *data)
126{
127 client_t *client = (client_t *) data;
128
129 list_remove(&client->link);
130 free(client);
131}
132
133void kbd_push_data(kbd_dev_t *kdev, sysarg_t data)
134{
135 (*kdev->ctl_ops->parse)(data);
136}
137
138void mouse_push_data(mouse_dev_t *mdev, sysarg_t data)
139{
140 (*mdev->proto_ops->parse)(data);
141}
142
143void kbd_push_event(kbd_dev_t *kdev, int type, unsigned int key)
144{
145 kbd_event_t ev;
146 unsigned int mod_mask;
147
148 switch (key) {
149 case KC_LCTRL:
150 mod_mask = KM_LCTRL;
151 break;
152 case KC_RCTRL:
153 mod_mask = KM_RCTRL;
154 break;
155 case KC_LSHIFT:
156 mod_mask = KM_LSHIFT;
157 break;
158 case KC_RSHIFT:
159 mod_mask = KM_RSHIFT;
160 break;
161 case KC_LALT:
162 mod_mask = KM_LALT;
163 break;
164 case KC_RALT:
165 mod_mask = KM_RALT;
166 break;
167 default:
168 mod_mask = 0;
169 }
170
171 if (mod_mask != 0) {
172 if (type == KEY_PRESS)
173 kdev->mods = kdev->mods | mod_mask;
174 else
175 kdev->mods = kdev->mods & ~mod_mask;
176 }
177
178 switch (key) {
179 case KC_CAPS_LOCK:
180 mod_mask = KM_CAPS_LOCK;
181 break;
182 case KC_NUM_LOCK:
183 mod_mask = KM_NUM_LOCK;
184 break;
185 case KC_SCROLL_LOCK:
186 mod_mask = KM_SCROLL_LOCK;
187 break;
188 default:
189 mod_mask = 0;
190 }
191
192 if (mod_mask != 0) {
193 if (type == KEY_PRESS) {
194 /*
195 * Only change lock state on transition from released
196 * to pressed. This prevents autorepeat from messing
197 * up the lock state.
198 */
199 kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys);
200 kdev->lock_keys = kdev->lock_keys | mod_mask;
201
202 /* Update keyboard lock indicator lights. */
203 (*kdev->ctl_ops->set_ind)(kdev, kdev->mods);
204 } else {
205 kdev->lock_keys = kdev->lock_keys & ~mod_mask;
206 }
207 }
208
209 // TODO: More elegant layout switching
210
211 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL)) {
212 switch (key) {
213 case KC_F1:
214 layout_destroy(kdev->active_layout);
215 kdev->active_layout = layout_create(layout[0]);
216 break;
217 case KC_F2:
218 layout_destroy(kdev->active_layout);
219 kdev->active_layout = layout_create(layout[1]);
220 break;
221 case KC_F3:
222 layout_destroy(kdev->active_layout);
223 kdev->active_layout = layout_create(layout[2]);
224 break;
225 case KC_F4:
226 layout_destroy(kdev->active_layout);
227 kdev->active_layout = layout_create(layout[3]);
228 break;
229 case KC_F5:
230 layout_destroy(kdev->active_layout);
231 kdev->active_layout = layout_create(layout[4]);
232 break;
233 default: // default: is here to avoid compiler warning about unhandled cases
234 break;
235 }
236 }
237
238 if (type == KEY_PRESS) {
239 switch (key) {
240 case KC_F12:
241 console_kcon();
242 break;
243 }
244 }
245
246 ev.type = type;
247 ev.key = key;
248 ev.mods = kdev->mods;
249
250 ev.c = layout_parse_ev(kdev->active_layout, &ev);
251
252 list_foreach(clients, link, client_t, client) {
253 if (client->active) {
254 async_exch_t *exch = async_exchange_begin(client->sess);
255 async_msg_4(exch, INPUT_EVENT_KEY, ev.type, ev.key, ev.mods, ev.c);
256 async_exchange_end(exch);
257 }
258 }
259}
260
261/** Mouse pointer has moved (relative mode). */
262void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy, int dz)
263{
264 list_foreach(clients, link, client_t, client) {
265 if (client->active) {
266 async_exch_t *exch = async_exchange_begin(client->sess);
267
268 if ((dx) || (dy))
269 async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
270
271 if (dz) {
272 // TODO: Implement proper wheel support
273 keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
274
275 for (unsigned int i = 0; i < 3; i++)
276 async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
277
278 async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
279 }
280
281 async_exchange_end(exch);
282 }
283 }
284}
285
286/** Mouse pointer has moved (absolute mode). */
287void mouse_push_event_abs_move(mouse_dev_t *mdev, unsigned int x, unsigned int y,
288 unsigned int max_x, unsigned int max_y)
289{
290 list_foreach(clients, link, client_t, client) {
291 if (client->active) {
292 if ((max_x) && (max_y)) {
293 async_exch_t *exch = async_exchange_begin(client->sess);
294 async_msg_4(exch, INPUT_EVENT_ABS_MOVE, x, y, max_x, max_y);
295 async_exchange_end(exch);
296 }
297 }
298 }
299}
300
301/** Mouse button has been pressed. */
302void mouse_push_event_button(mouse_dev_t *mdev, int bnum, int press)
303{
304 list_foreach(clients, link, client_t, client) {
305 if (client->active) {
306 async_exch_t *exch = async_exchange_begin(client->sess);
307 async_msg_2(exch, INPUT_EVENT_BUTTON, bnum, press);
308 async_exchange_end(exch);
309 }
310 }
311}
312
313/** Arbitrate client actiovation */
314static void client_arbitration(void)
315{
316 /* Mutual exclusion of active clients */
317 list_foreach(clients, link, client_t, client)
318 client->active = ((active) && (client == active_client));
319
320 /* Notify clients about the arbitration */
321 list_foreach(clients, link, client_t, client) {
322 async_exch_t *exch = async_exchange_begin(client->sess);
323 async_msg_0(exch, client->active ?
324 INPUT_EVENT_ACTIVE : INPUT_EVENT_DEACTIVE);
325 async_exchange_end(exch);
326 }
327}
328
329/** New client connection */
330static void client_connection(ipc_call_t *icall, void *arg)
331{
332 client_t *client = (client_t *) async_get_client_data();
333 if (client == NULL) {
334 async_answer_0(icall, ENOMEM);
335 return;
336 }
337
338 async_accept_0(icall);
339
340 while (true) {
341 ipc_call_t call;
342 async_get_call(&call);
343
344 if (!ipc_get_imethod(&call)) {
345 if (client->sess != NULL) {
346 async_hangup(client->sess);
347 client->sess = NULL;
348 }
349
350 async_answer_0(&call, EOK);
351 return;
352 }
353
354 async_sess_t *sess =
355 async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
356 if (sess != NULL) {
357 if (client->sess == NULL) {
358 client->sess = sess;
359 async_answer_0(&call, EOK);
360 } else
361 async_answer_0(&call, ELIMIT);
362 } else {
363 switch (ipc_get_imethod(&call)) {
364 case INPUT_ACTIVATE:
365 active_client = client;
366 client_arbitration();
367 async_answer_0(&call, EOK);
368 break;
369 default:
370 async_answer_0(&call, EINVAL);
371 }
372 }
373 }
374}
375
376static void kconsole_event_handler(ipc_call_t *call, void *arg)
377{
378 if (ipc_get_arg1(call)) {
379 /* Kernel console activated */
380 active = false;
381 } else {
382 /* Kernel console deactivated */
383 active = true;
384 }
385
386 client_arbitration();
387}
388
389static kbd_dev_t *kbd_dev_new(void)
390{
391 kbd_dev_t *kdev = calloc(1, sizeof(kbd_dev_t));
392 if (kdev == NULL) {
393 printf("%s: Error allocating keyboard device. "
394 "Out of memory.\n", NAME);
395 return NULL;
396 }
397
398 link_initialize(&kdev->link);
399
400 kdev->mods = KM_NUM_LOCK;
401 kdev->lock_keys = 0;
402 kdev->active_layout = layout_create(layout[0]);
403
404 return kdev;
405}
406
407static mouse_dev_t *mouse_dev_new(void)
408{
409 mouse_dev_t *mdev = calloc(1, sizeof(mouse_dev_t));
410 if (mdev == NULL) {
411 printf("%s: Error allocating mouse device. "
412 "Out of memory.\n", NAME);
413 return NULL;
414 }
415
416 link_initialize(&mdev->link);
417
418 return mdev;
419}
420
421static serial_dev_t *serial_dev_new(void)
422{
423 serial_dev_t *sdev = calloc(1, sizeof(serial_dev_t));
424 if (sdev == NULL) {
425 printf("%s: Error allocating serial device. "
426 "Out of memory.\n", NAME);
427 return NULL;
428 }
429
430 sdev->kdev = kbd_dev_new();
431 if (sdev->kdev == NULL) {
432 free(sdev);
433 return NULL;
434 }
435
436 link_initialize(&sdev->link);
437
438 return sdev;
439}
440
441/** Add new legacy keyboard device. */
442static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl)
443{
444 kbd_dev_t *kdev = kbd_dev_new();
445 if (kdev == NULL)
446 return;
447
448 kdev->port_ops = port;
449 kdev->ctl_ops = ctl;
450 kdev->svc_id = 0;
451
452 /* Initialize port driver. */
453 if ((*kdev->port_ops->init)(kdev) != 0)
454 goto fail;
455
456 /* Initialize controller driver. */
457 if ((*kdev->ctl_ops->init)(kdev) != 0) {
458 /* XXX Uninit port */
459 goto fail;
460 }
461
462 list_append(&kdev->link, &kbd_devs);
463 return;
464
465fail:
466 free(kdev);
467}
468
469/** Add new kbdev device.
470 *
471 * @param service_id Service ID of the keyboard device
472 *
473 */
474static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp)
475{
476 kbd_dev_t *kdev = kbd_dev_new();
477 if (kdev == NULL)
478 return -1;
479
480 kdev->svc_id = service_id;
481 kdev->port_ops = NULL;
482 kdev->ctl_ops = &kbdev_ctl;
483
484 errno_t rc = loc_service_get_name(service_id, &kdev->svc_name);
485 if (rc != EOK) {
486 kdev->svc_name = NULL;
487 goto fail;
488 }
489
490 /* Initialize controller driver. */
491 if ((*kdev->ctl_ops->init)(kdev) != 0) {
492 goto fail;
493 }
494
495 list_append(&kdev->link, &kbd_devs);
496 *kdevp = kdev;
497 return 0;
498
499fail:
500 if (kdev->svc_name != NULL)
501 free(kdev->svc_name);
502 free(kdev);
503 return -1;
504}
505
506/** Add new mousedev device.
507 *
508 * @param service_id Service ID of the mouse device
509 *
510 */
511static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp)
512{
513 mouse_dev_t *mdev = mouse_dev_new();
514 if (mdev == NULL)
515 return -1;
516
517 mdev->svc_id = service_id;
518 mdev->port_ops = NULL;
519 mdev->proto_ops = &mousedev_proto;
520
521 errno_t rc = loc_service_get_name(service_id, &mdev->svc_name);
522 if (rc != EOK) {
523 mdev->svc_name = NULL;
524 goto fail;
525 }
526
527 /* Initialize controller driver. */
528 if ((*mdev->proto_ops->init)(mdev) != 0) {
529 goto fail;
530 }
531
532 list_append(&mdev->link, &mouse_devs);
533 *mdevp = mdev;
534 return 0;
535
536fail:
537 free(mdev);
538 return -1;
539}
540
541static errno_t serial_consumer(void *arg)
542{
543 serial_dev_t *sdev = (serial_dev_t *) arg;
544
545 while (true) {
546 uint8_t data;
547 size_t nread;
548
549 chardev_read(sdev->chardev, &data, sizeof(data), &nread,
550 chardev_f_none);
551 /* XXX Handle error */
552 kbd_push_data(sdev->kdev, data);
553 }
554
555 return EOK;
556}
557
558/** Add new serial console device.
559 *
560 * @param service_id Service ID of the chardev device
561 *
562 */
563static int serial_add_srldev(service_id_t service_id, serial_dev_t **sdevp)
564{
565 bool match = false;
566 errno_t rc;
567
568 serial_dev_t *sdev = serial_dev_new();
569 if (sdev == NULL)
570 return -1;
571
572 sdev->kdev->svc_id = service_id;
573
574 rc = loc_service_get_name(service_id, &sdev->kdev->svc_name);
575 if (rc != EOK)
576 goto fail;
577
578 list_append(&sdev->link, &serial_devs);
579
580 /*
581 * Is this the device the user wants to use as a serial console?
582 */
583 match = (serial_console != NULL) &&
584 !str_cmp(serial_console, sdev->kdev->svc_name);
585
586 if (match) {
587 sdev->kdev->ctl_ops = &stty_ctl;
588
589 /* Initialize controller driver. */
590 if ((*sdev->kdev->ctl_ops->init)(sdev->kdev) != 0) {
591 list_remove(&sdev->link);
592 goto fail;
593 }
594
595 sdev->sess = loc_service_connect(service_id, INTERFACE_DDF,
596 IPC_FLAG_BLOCKING);
597
598 rc = chardev_open(sdev->sess, &sdev->chardev);
599 if (rc != EOK) {
600 async_hangup(sdev->sess);
601 sdev->sess = NULL;
602 list_remove(&sdev->link);
603 goto fail;
604 }
605
606 fid_t fid = fibril_create(serial_consumer, sdev);
607 fibril_add_ready(fid);
608 }
609
610 *sdevp = sdev;
611 return 0;
612
613fail:
614 if (sdev->kdev->svc_name != NULL)
615 free(sdev->kdev->svc_name);
616 free(sdev->kdev);
617 free(sdev);
618 return -1;
619}
620
621/** Add legacy drivers/devices. */
622static void kbd_add_legacy_devs(void)
623{
624 /*
625 * Need to add these drivers based on config unless we can probe
626 * them automatically.
627 */
628#if defined(UARCH_arm32) && defined(MACHINE_gta02)
629 kbd_add_dev(&chardev_port, &stty_ctl);
630#endif
631#if defined(UARCH_ia64) && defined(MACHINE_ski)
632 kbd_add_dev(&chardev_port, &stty_ctl);
633#endif
634#if defined(MACHINE_msim)
635 kbd_add_dev(&chardev_port, &stty_ctl);
636#endif
637#if defined(UARCH_sparc64) && defined(PROCESSOR_sun4v)
638 kbd_add_dev(&chardev_port, &stty_ctl);
639#endif
640#if defined(UARCH_arm64) && defined(MACHINE_virt)
641 kbd_add_dev(&chardev_port, &stty_ctl);
642#endif
643 /* Silence warning on abs32le about kbd_add_dev() being unused */
644 (void) kbd_add_dev;
645}
646
647static errno_t dev_check_new_kbdevs(void)
648{
649 category_id_t keyboard_cat;
650 service_id_t *svcs;
651 size_t count, i;
652 bool already_known;
653 errno_t rc;
654
655 rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
656 if (rc != EOK) {
657 printf("%s: Failed resolving category 'keyboard'.\n", NAME);
658 return ENOENT;
659 }
660
661 /*
662 * Check for new keyboard devices
663 */
664 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
665 if (rc != EOK) {
666 printf("%s: Failed getting list of keyboard devices.\n",
667 NAME);
668 return EIO;
669 }
670
671 for (i = 0; i < count; i++) {
672 already_known = false;
673
674 /* Determine whether we already know this device. */
675 list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
676 if (kdev->svc_id == svcs[i]) {
677 already_known = true;
678 break;
679 }
680 }
681
682 if (!already_known) {
683 kbd_dev_t *kdev;
684 if (kbd_add_kbdev(svcs[i], &kdev) == 0) {
685 printf("%s: Connected keyboard device '%s'\n",
686 NAME, kdev->svc_name);
687 }
688 }
689 }
690
691 free(svcs);
692
693 /* XXX Handle device removal */
694
695 return EOK;
696}
697
698static errno_t dev_check_new_mousedevs(void)
699{
700 category_id_t mouse_cat;
701 service_id_t *svcs;
702 size_t count, i;
703 bool already_known;
704 errno_t rc;
705
706 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
707 if (rc != EOK) {
708 printf("%s: Failed resolving category 'mouse'.\n", NAME);
709 return ENOENT;
710 }
711
712 /*
713 * Check for new mouse devices
714 */
715 rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
716 if (rc != EOK) {
717 printf("%s: Failed getting list of mouse devices.\n",
718 NAME);
719 return EIO;
720 }
721
722 for (i = 0; i < count; i++) {
723 already_known = false;
724
725 /* Determine whether we already know this device. */
726 list_foreach(mouse_devs, link, mouse_dev_t, mdev) {
727 if (mdev->svc_id == svcs[i]) {
728 already_known = true;
729 break;
730 }
731 }
732
733 if (!already_known) {
734 mouse_dev_t *mdev;
735 if (mouse_add_mousedev(svcs[i], &mdev) == 0) {
736 printf("%s: Connected mouse device '%s'\n",
737 NAME, mdev->svc_name);
738 }
739 }
740 }
741
742 free(svcs);
743
744 /* XXX Handle device removal */
745
746 return EOK;
747}
748
749static errno_t dev_check_new_serialdevs(void)
750{
751 category_id_t serial_cat;
752 service_id_t *svcs;
753 size_t count, i;
754 bool already_known;
755 errno_t rc;
756
757 rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING);
758 if (rc != EOK) {
759 printf("%s: Failed resolving category 'serial'.\n", NAME);
760 return ENOENT;
761 }
762
763 /*
764 * Check for new serial devices
765 */
766 rc = loc_category_get_svcs(serial_cat, &svcs, &count);
767 if (rc != EOK) {
768 printf("%s: Failed getting list of serial devices.\n",
769 NAME);
770 return EIO;
771 }
772
773 for (i = 0; i < count; i++) {
774 already_known = false;
775
776 /* Determine whether we already know this device. */
777 list_foreach(serial_devs, link, serial_dev_t, sdev) {
778 if (sdev->kdev->svc_id == svcs[i]) {
779 already_known = true;
780 break;
781 }
782 }
783
784 if (!already_known) {
785 serial_dev_t *sdev;
786 if (serial_add_srldev(svcs[i], &sdev) == 0) {
787 printf("%s: Connected serial device '%s'\n",
788 NAME, sdev->kdev->svc_name);
789 }
790 }
791 }
792
793 free(svcs);
794
795 /* XXX Handle device removal */
796
797 return EOK;
798}
799
800static errno_t dev_check_new(void)
801{
802 errno_t rc;
803
804 fibril_mutex_lock(&discovery_lock);
805
806 if (!serial_console) {
807 rc = dev_check_new_kbdevs();
808 if (rc != EOK) {
809 fibril_mutex_unlock(&discovery_lock);
810 return rc;
811 }
812
813 rc = dev_check_new_mousedevs();
814 if (rc != EOK) {
815 fibril_mutex_unlock(&discovery_lock);
816 return rc;
817 }
818 } else {
819 rc = dev_check_new_serialdevs();
820 if (rc != EOK) {
821 fibril_mutex_unlock(&discovery_lock);
822 return rc;
823 }
824 }
825
826 fibril_mutex_unlock(&discovery_lock);
827
828 return EOK;
829}
830
831static void cat_change_cb(void *arg)
832{
833 dev_check_new();
834}
835
836/** Start listening for new devices. */
837static errno_t input_start_dev_discovery(void)
838{
839 errno_t rc = loc_register_cat_change_cb(cat_change_cb, NULL);
840 if (rc != EOK) {
841 printf("%s: Failed registering callback for device discovery: "
842 "%s\n", NAME, str_error(rc));
843 return rc;
844 }
845
846 return dev_check_new();
847}
848
849static void usage(char *name)
850{
851 printf("Usage: %s <service_name>\n", name);
852}
853
854int main(int argc, char **argv)
855{
856 errno_t rc;
857
858 if (argc < 2) {
859 usage(argv[0]);
860 return 1;
861 }
862
863 printf("%s: HelenOS input service\n", NAME);
864
865 list_initialize(&clients);
866 list_initialize(&kbd_devs);
867 list_initialize(&mouse_devs);
868 list_initialize(&serial_devs);
869
870 serial_console = config_get_value("console");
871
872 /* Add legacy keyboard devices. */
873 kbd_add_legacy_devs();
874
875 /* Register driver */
876 async_set_client_data_constructor(client_data_create);
877 async_set_client_data_destructor(client_data_destroy);
878 async_set_fallback_port_handler(client_connection, NULL);
879
880 rc = loc_server_register(NAME);
881 if (rc != EOK) {
882 printf("%s: Unable to register server\n", NAME);
883 return rc;
884 }
885
886 service_id_t service_id;
887 rc = loc_service_register(argv[1], &service_id);
888 if (rc != EOK) {
889 printf("%s: Unable to register service %s\n", NAME, argv[1]);
890 return rc;
891 }
892
893 /* Receive kernel notifications */
894 rc = async_event_subscribe(EVENT_KCONSOLE, kconsole_event_handler, NULL);
895 if (rc != EOK)
896 printf("%s: Failed to register kconsole notifications (%s)\n",
897 NAME, str_error(rc));
898
899 /* Start looking for new input devices */
900 input_start_dev_discovery();
901
902 printf("%s: Accepting connections\n", NAME);
903 task_retval(0);
904 async_manager();
905
906 /* Not reached. */
907 return 0;
908}
909
910/**
911 * @}
912 */
Note: See TracBrowser for help on using the repository browser.