From owner-freebsd-current@FreeBSD.ORG Tue Feb 28 20:37:23 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2637716A42B for ; Tue, 28 Feb 2006 20:37:23 +0000 (GMT) (envelope-from maksim.yevmenkin@savvis.net) Received: from ismybrain.com (ismybrain.com [64.246.42.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0816943D95 for ; Tue, 28 Feb 2006 20:36:52 +0000 (GMT) (envelope-from maksim.yevmenkin@savvis.net) Received: from [10.254.186.111] (localhost.localdomain [127.0.0.1]) by ismybrain.com (8.11.6/8.11.6) with ESMTP id k1SKaqM21531 for ; Tue, 28 Feb 2006 15:36:52 -0500 Message-ID: <4404B461.8000104@savvis.net> Date: Tue, 28 Feb 2006 12:36:49 -0800 From: Maksim Yevmenkin User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-current@freebsd.org Content-Type: multipart/mixed; boundary="------------010707090002070904080507" Subject: [PATCH] HEADSUP: kbdmux(4)/syscons(4) patch is about to hit the tree X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2006 20:37:23 -0000 This is a multi-part message in MIME format. --------------010707090002070904080507 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Dear Hackers, i'm about to commit the attached patch to -current. if you have any objections please speak up now. the patch can also be found at http://people.freebsd.org/~emax/kbdmux-current.diff.txt (freefall:~emax/kbdmux-current.diff.txt) thanks, max --------------010707090002070904080507 Content-Type: text/plain; name="kbdmux-current.diff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kbdmux-current.diff.txt" Index: sys/dev/kbd/kbd.c =================================================================== RCS file: /home/ncvs/src/sys/dev/kbd/kbd.c,v retrieving revision 1.44 diff -u -r1.44 kbd.c --- sys/dev/kbd/kbd.c 13 Jul 2005 23:58:57 -0000 1.44 +++ sys/dev/kbd/kbd.c 28 Feb 2006 19:02:43 -0000 @@ -185,8 +185,12 @@ { const keyboard_driver_t **list; const keyboard_driver_t *p; + keyboard_t *mux; + keyboard_info_t ki; int index; + mux = kbd_get_keyboard(kbd_find_keyboard("kbdmux", -1)); + for (index = 0; index < keyboards; ++index) { if (keyboard[index] == NULL) break; @@ -208,6 +212,16 @@ if (strcmp(p->name, kbd->kb_name) == 0) { keyboard[index] = kbd; kbdsw[index] = p->kbdsw; + + if (mux != NULL) { + bzero(&ki, sizeof(ki)); + strcpy(ki.kb_name, kbd->kb_name); + ki.kb_unit = kbd->kb_unit; + + (*kbdsw[mux->kb_index]->ioctl) + (mux, KBADDKBD, (caddr_t) &ki); + } + return (index); } } @@ -216,6 +230,16 @@ if (strcmp(p->name, kbd->kb_name) == 0) { keyboard[index] = kbd; kbdsw[index] = p->kbdsw; + + if (mux != NULL) { + bzero(&ki, sizeof(ki)); + strcpy(ki.kb_name, kbd->kb_name); + ki.kb_unit = kbd->kb_unit; + + (*kbdsw[mux->kb_index]->ioctl) + (mux, KBADDKBD, (caddr_t) &ki); + } + return (index); } } Index: sys/dev/syscons/syscons.c =================================================================== RCS file: /home/ncvs/src/sys/dev/syscons/syscons.c,v retrieving revision 1.441 diff -u -r1.441 syscons.c --- sys/dev/syscons/syscons.c 14 Jan 2006 17:57:16 -0000 1.441 +++ sys/dev/syscons/syscons.c 28 Feb 2006 19:02:44 -0000 @@ -165,6 +165,7 @@ static int debugger; /* prototypes */ +static int sc_allocate_keyboard(sc_softc_t *sc, int unit); static struct tty *sc_alloc_tty(struct cdev *dev); static int scvidprobe(int unit, int flags, int cons); static int sckbdprobe(int unit, int flags, int cons); @@ -1676,8 +1677,7 @@ if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) { /* try to allocate a keyboard automatically */ if (++kbd_interval >= 25) { - sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard, - sckbdevent, sc); + sc->keyboard = sc_allocate_keyboard(sc, -1); if (sc->keyboard >= 0) { sc->kbd = kbd_get_keyboard(sc->keyboard); kbd_ioctl(sc->kbd, KDSKBMODE, @@ -2663,9 +2663,10 @@ sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter); sc->adp = vid_get_adapter(sc->adapter); /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */ - sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard, - sckbdevent, sc); + + sc->keyboard = sc_allocate_keyboard(sc, unit); DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard)); + sc->kbd = kbd_get_keyboard(sc->keyboard); if (sc->kbd != NULL) { DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n", @@ -3610,3 +3611,40 @@ return (&main_console); return (SC_STAT(devptr)); } + +/* + * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and, + * if found, add all non-busy keyboards to "kbdmux". Otherwise look for + * any keyboard. + */ + +static int +sc_allocate_keyboard(sc_softc_t *sc, int unit) +{ + int idx0, idx; + keyboard_t *k0, *k; + keyboard_info_t ki; + + idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc); + if (idx0 != -1) { + k0 = kbd_get_keyboard(idx0); + + for (idx = kbd_find_keyboard2("*", -1, 0); + idx != -1; + idx = kbd_find_keyboard2("*", -1, idx + 1)) { + k = kbd_get_keyboard(idx); + + if (idx == idx0 || KBD_IS_BUSY(k)) + continue; + + bzero(&ki, sizeof(ki)); + strcpy(ki.kb_name, k->kb_name); + ki.kb_unit = k->kb_unit; + + kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki); + } + } else + idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc); + + return (idx0); +} --------------010707090002070904080507--