From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 26 04:19:16 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A5CB216A400 for ; Mon, 26 Mar 2007 04:19:16 +0000 (UTC) (envelope-from tbourke@triptrop.cse.unsw.edu.au) Received: from fallbackmx03.syd.optusnet.com.au (fallbackmx03.syd.optusnet.com.au [211.29.133.136]) by mx1.freebsd.org (Postfix) with ESMTP id 32F2E13C46E for ; Mon, 26 Mar 2007 04:19:15 +0000 (UTC) (envelope-from tbourke@triptrop.cse.unsw.edu.au) Received: from mail02.syd.optusnet.com.au (mail02.syd.optusnet.com.au [211.29.132.183]) by fallbackmx03.syd.optusnet.com.au (8.12.11.20060308/8.12.11) with ESMTP id l2P1wxBW023977 for ; Sun, 25 Mar 2007 11:58:59 +1000 Received: from triptrop.cse.unsw.edu.au (blaax9-a118.dialup.optusnet.com.au [203.164.126.118]) by mail02.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l2P1wqMK020256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 25 Mar 2007 11:58:54 +1000 Received: from triptrop.cse.unsw.edu.au (localhost [127.0.0.1]) by triptrop.cse.unsw.edu.au (8.13.8/8.13.6) with ESMTP id l2P1vIFx000902 for ; Sun, 25 Mar 2007 11:57:19 +1000 (EST) (envelope-from tbourke@triptrop.cse.unsw.edu.au) Received: (from tbourke@localhost) by triptrop.cse.unsw.edu.au (8.13.8/8.13.6/Submit) id l2P1vHlA000901 for hackers@freebsd.org; Sun, 25 Mar 2007 11:57:17 +1000 (EST) (envelope-from tbourke) Date: Sun, 25 Mar 2007 11:57:17 +1000 From: Timothy Bourke To: hackers@freebsd.org Message-ID: <20070325015717.GA797@triptrop> Mail-Followup-To: hackers@freebsd.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5I6of5zJg18YgZEa" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-PGP-Key: http://www.cse.unsw.edu.au/~tbourke/pubkey.txt Cc: Subject: enable/disable in kbd drivers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2007 04:19:16 -0000 --5I6of5zJg18YgZEa Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I have almost finished a ppbus-based driver for Super Nintendo controllers. It presents itself as a keyboard to the operating system. I wanted to start and stop the polling thread via, respectively, the kbd_enable_t and kbd_disable_t hooks, but these do not seem to be called properly. Hence this post. The enable and disable functions are identical across the keyboard drivers (atkbd, ukbd, vkbd, kbdmux). Enable calls the KBD_ACTIVATE macro which increments the kb_active count. Disable calls the KBD_DEACTIVATE macro which decrements the kb_active count. It seems reasonable to assume that the two functions should be called in pairs. However, enable is called too many times and disable is never called. In the kbdmux_ioctl routine: KBADDKBD: enable is called via the KBDMUX_ENABLE macro. KBRELKBD: does NOT call disable Taking dev/usb/ukbd.c as an example, the effect can be seen by adding this line to the ukbd_enable function (after the call to KBD_ACTIVATE): printf("ukbd_enable: %d\n", KBD_IS_ACTIVE(kbd)); And similarly for ukbd_disable and then running dmesg or kbdcontrol. Additionally, each kbd driver calls its own enable function when attached. For example, in USB_ATTACH(ukbd): (*sw->enable)(kbd); This would appear to be unnecessary for keyboards connected via kbdmux. I am less certain about those connected directly, but the syscons sccngetch routine does seems to call enable and disable. Perhaps it should also call enable when it first starts? Does the attached patch seem reasonable? It would fix my immediate problem. I could write a patch to remove the calls to enable in the driver init routines but tI don't really understand how syscons works. Tim. --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="kbdmux.patch" Content-Transfer-Encoding: quoted-printable --- sys/dev/kbdmux/kbdmux.c.orig Sun Mar 25 11:33:57 2007 +++ sys/dev/kbdmux/kbdmux.c Sun Mar 25 11:36:46 2007 @@ -132,6 +132,9 @@ #define KBDMUX_ENABLE(kbd) \ (*kbdsw[(kbd)->kb_index]->enable)((kbd)) =20 +#define KBDMUX_DISABLE(kbd) \ + (*kbdsw[(kbd)->kb_index]->disable)((kbd)) + #define KBDMUX_POLL(kbd, on) \ (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on)) =20 @@ -1029,6 +1032,7 @@ break; =20 if (k !=3D NULL) { + KBDMUX_DISABLE(k->kbd); error =3D kbd_release(k->kbd, &k->kbd); if (error =3D=3D 0) { SLIST_REMOVE(&state->ks_kbds, k, kbdmux_kbd, next); --DocE+STaALJfprDB-- --5I6of5zJg18YgZEa Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.4 (FreeBSD) iD8DBQFGBdb9tKVK1sFb0ecRAoAfAJ4jPcRes/YX2/vRszKrTrcF0qCgPwCfaCUr VL6Gbe+4v06Rhjr+LRFZLtQ= =MJce -----END PGP SIGNATURE----- --5I6of5zJg18YgZEa--