From nobody Sat Dec 24 08:36:50 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NfHTb27Bfz1HSQF; Sat, 24 Dec 2022 08:36:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NfHTb1GJxz3NMj; Sat, 24 Dec 2022 08:36:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671871011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V25P3WP9VP9sxO5gmOPsUxmmjSxXDgk98yqUZXhe+p0=; b=Xxs6lILKGvBv1f4gp2h1ZMhc3x/ncJBMNIH3fv3PQN61aTR2Sd+axg6WQ1kOeSHAPbpgvN fbOlWWWnxNXdGo+pxiRDGlLnh8R6bSkIwszSZ7gIjgOhFzbeTpimQqO+qAOCPq610QZ5jl XmTMM+miBBRqqDAnFw/G4A7fgOI2JG0xAyFAtre95Mu8DjCseNBrD79rbt1RD76Iy2CXHi rUD+nW1UBIGyWxKlmwdbj2XY/fq8weFhKHX8dofY7kkHX683Y7u251D8wapiSfTYge0qZe xOkHBNfjVfYPRl5bvQi6BOsMjbom3FjTqTrFoIhsolDyfmJVZPaNV27ZAhcCTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671871011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V25P3WP9VP9sxO5gmOPsUxmmjSxXDgk98yqUZXhe+p0=; b=t3YSTyEwF0N01JGXbGrdwjOL2JDBMJTiq0X5rxnqNBkBSc73T7W6X5Zq1VZHnaA8nzdXX0 zgkkzGB+hvzneC8cyrSAMdD6zvxt2eYqjYZE5ISypJxJn61Cw3pGLzZpojQzW5JvpomD8c S4A36kWP/R4FwAn0QQ+XrkSH4j7FgcDkgSHcrrcqf7o3LkCL3s2mmN62Cr0ldbNjpnhjwi ioZ02M8jyG/vaTjuGWtdZvpcUNAqTikJoQKp8rgZBRJuyOj14cYUL/tyJW19TWuT9lTh0G 2b/e7oZW/lU7Ts6qNm/ZFee3C5E+Sx1+DnRgsAAFBLAjzsZnqhNhZkXzpA9iBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671871011; a=rsa-sha256; cv=none; b=W6Trp85nKMtKNO3mgaFpnONL4FqFid/eFctD/EQMVX6SGwzoc5PW06eEo8JKwfELYP/DUT nNaEIL9btatoz+PhenEdP1s0bGepZAp69VKxdyKI9X8Px1ihvQ10YzrE9ubQCFsuYqOVuc kDJK8CSnimsCnWmcYrE1qyhl3dlwXw+uk6U237i3TE2yDU1YgNdMag0+gRTrd8vLYyFrqO azLwhjDof/maFANelMYWHuCwbCMupKWFjEi3ydQmp5pUQQUD1VnpaxDOStEtnJOfd88QpD WEco5MViUAPyt6FQjp5kICyQGvJ64XPBa7ArcxHrAo5Ao5MN01RBrR/vPMrBlA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NfHTb0Kxsz16Qt; Sat, 24 Dec 2022 08:36:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BO8aoRY083222; Sat, 24 Dec 2022 08:36:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BO8aoAf083221; Sat, 24 Dec 2022 08:36:50 GMT (envelope-from git) Date: Sat, 24 Dec 2022 08:36:50 GMT Message-Id: <202212240836.2BO8aoAf083221@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: b048f6779408 - stable/13 - hv_kbd: Add evdev protocol support for gen 2 VMs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b048f6779408eabf87cfdca3e23eda75c1f4be22 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=b048f6779408eabf87cfdca3e23eda75c1f4be22 commit b048f6779408eabf87cfdca3e23eda75c1f4be22 Author: Vladimir Kondratyev AuthorDate: 2021-04-11 23:07:35 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-12-24 08:09:29 +0000 hv_kbd: Add evdev protocol support for gen 2 VMs (cherry picked from commit c2a159286c7694306fde8c161af47a220e1a76f2) --- sys/dev/hyperv/input/hv_kbd.c | 82 ++++++++++++++++++++++++++++++++++++++++++ sys/dev/hyperv/input/hv_kbdc.h | 13 ++++++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/sys/dev/hyperv/input/hv_kbd.c b/sys/dev/hyperv/input/hv_kbd.c index 3be18da0efef..b1b0760ba13c 100644 --- a/sys/dev/hyperv/input/hv_kbd.c +++ b/sys/dev/hyperv/input/hv_kbd.c @@ -27,6 +27,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_evdev.h" + #include #include #include @@ -56,6 +58,11 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef EVDEV_SUPPORT +#include +#include +#endif + #include "dev/hyperv/input/hv_kbdc.h" #define HVKBD_MTX_LOCK(_m) do { \ @@ -76,6 +83,14 @@ __FBSDID("$FreeBSD$"); #define HVKBD_FLAG_POLLING 0x00000002 +#ifdef EVDEV_SUPPORT +static evdev_event_t hvkbd_ev_event; + +static const struct evdev_methods hvkbd_evdev_methods = { + .ev_event = hvkbd_ev_event, +}; +#endif + /* early keyboard probe, not supported */ static int hvkbd_configure(int flags) @@ -249,6 +264,9 @@ hvkbd_read_char_locked(keyboard_t *kbd, int wait) uint32_t scancode = NOKEY; keystroke ks; hv_kbd_sc *sc = kbd->kb_data; +#ifdef EVDEV_SUPPORT + int keycode; +#endif HVKBD_LOCK_ASSERT(); if (!KBD_IS_ACTIVE(kbd) || !hv_kbd_prod_is_ready(sc)) @@ -293,6 +311,20 @@ hvkbd_read_char_locked(keyboard_t *kbd, int wait) } hv_kbd_remove_top(sc); } +#ifdef EVDEV_SUPPORT + /* push evdev event */ + if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && + sc->ks_evdev != NULL) { + keycode = evdev_scancode2key(&sc->ks_evdev_state, + scancode); + + if (keycode != KEY_RESERVED) { + evdev_push_event(sc->ks_evdev, EV_KEY, + (uint16_t)keycode, scancode & 0x80 ? 0 : 1); + evdev_sync(sc->ks_evdev); + } + } +#endif } else { if (bootverbose) device_printf(sc->dev, "Unsupported mode: %d\n", sc->sc_mode); @@ -413,6 +445,12 @@ hvkbd_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg) DEBUG_HVSC(sc, "setled 0x%x\n", *(int *)arg); } +#ifdef EVDEV_SUPPORT + /* push LED states to evdev */ + if (sc->ks_evdev != NULL && + evdev_rcpt_mask & EVDEV_RCPT_HW_KBD) + evdev_push_leds(sc->ks_evdev, *(int *)arg); +#endif KBD_LED_VAL(kbd) = *(int *)arg; break; default: @@ -445,6 +483,22 @@ hvkbd_read(keyboard_t *kbd, int wait) return hvkbd_read_char_locked(kbd, wait); } +#ifdef EVDEV_SUPPORT +static void +hvkbd_ev_event(struct evdev_dev *evdev, uint16_t type, uint16_t code, + int32_t value) +{ + keyboard_t *kbd = evdev_get_softc(evdev); + + if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && + (type == EV_LED || type == EV_REP)) { + mtx_lock(&Giant); + kbd_ev_event(kbd, type, code, value); + mtx_unlock(&Giant); + } +} +#endif + static keyboard_switch_t hvkbdsw = { .probe = hvkbd_probe, /* not used */ .init = hvkbd_init, @@ -508,6 +562,10 @@ hv_kbd_drv_attach(device_t dev) int unit = device_get_unit(dev); keyboard_t *kbd = &sc->sc_kbd; keyboard_switch_t *sw; +#ifdef EVDEV_SUPPORT + struct evdev_dev *evdev; +#endif + sw = kbd_get_switch(HVKBD_DRIVER_NAME); if (sw == NULL) { return (ENXIO); @@ -523,6 +581,27 @@ hv_kbd_drv_attach(device_t dev) sc->sc_mode = K_RAW; (*sw->enable)(kbd); +#ifdef EVDEV_SUPPORT + evdev = evdev_alloc(); + evdev_set_name(evdev, "Hyper-V keyboard"); + evdev_set_phys(evdev, device_get_nameunit(dev)); + evdev_set_id(evdev, BUS_VIRTUAL, 0, 0, 0); + evdev_set_methods(evdev, kbd, &hvkbd_evdev_methods); + evdev_support_event(evdev, EV_SYN); + evdev_support_event(evdev, EV_KEY); + evdev_support_event(evdev, EV_LED); + evdev_support_event(evdev, EV_REP); + evdev_support_all_known_keys(evdev); + evdev_support_led(evdev, LED_NUML); + evdev_support_led(evdev, LED_CAPSL); + evdev_support_led(evdev, LED_SCROLLL); + if (evdev_register_mtx(evdev, &Giant)) + evdev_free(evdev); + else + sc->ks_evdev = evdev; + sc->ks_evdev_state = 0; +#endif + if (kbd_register(kbd) < 0) { goto detach; } @@ -547,6 +626,9 @@ hv_kbd_drv_detach(device_t dev) int error = 0; hv_kbd_sc *sc = device_get_softc(dev); hvkbd_disable(&sc->sc_kbd); +#ifdef EVDEV_SUPPORT + evdev_free(sc->ks_evdev); +#endif if (KBD_IS_CONFIGURED(&sc->sc_kbd)) { error = kbd_unregister(&sc->sc_kbd); if (error) { diff --git a/sys/dev/hyperv/input/hv_kbdc.h b/sys/dev/hyperv/input/hv_kbdc.h index 3c7bd2a69de7..562009df9a94 100644 --- a/sys/dev/hyperv/input/hv_kbdc.h +++ b/sys/dev/hyperv/input/hv_kbdc.h @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/dev/hyperv/input/hv_kbdc.h 316515 2017-04-05 05:01:23Z sephe $ */ #ifndef _HV_KBD_H @@ -36,6 +36,12 @@ #include +#include "opt_evdev.h" +#ifdef EVDEV_SUPPORT +#include +#include +#endif + #define HVKBD_DRIVER_NAME "hvkbd" #define IS_UNICODE (1) #define IS_BREAK (2) @@ -87,6 +93,11 @@ typedef struct hv_kbd_sc_t { int sc_polling; /* polling recursion count */ uint32_t sc_flags; int debug; + +#ifdef EVDEV_SUPPORT + struct evdev_dev *ks_evdev; + int ks_evdev_state; +#endif } hv_kbd_sc; int hv_kbd_produce_ks(hv_kbd_sc *sc, const keystroke *ks);