Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5016459imm; Tue, 12 Jun 2018 00:50:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL2prg4nzWMo4pXJecXbQGtvTuZSGOalXyikpqug8TQIqcDK+nuR6jbKiE+ghBt9cve2sH3 X-Received: by 2002:a17:902:6802:: with SMTP id h2-v6mr2799100plk.113.1528789822713; Tue, 12 Jun 2018 00:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528789822; cv=none; d=google.com; s=arc-20160816; b=PB1qKjvvwwW7Yz7Xbca8JJH1KPx1gRfswkUaBHfsN9D2JYsJWs4mbXP8Nxx12yoDcu scK8kg8Qwcku3cvdaNKofugMjOM+FHKk4c+7cZbPVUTdUmVfdGjhmI821re8pEwpc3t5 qDu/h4kGeu8DN456+sY9gos89CY2IFKNZnWJg1rHrIHDCu6MU9zl60cNBLU7+VDGxJFk Cwz4mHEbUfltjYnQtEidh4mTJgblQDDlMRqqk1UKnzV1Uj09PFOYCE2BJC7ckSohZTMX lOPjgNwW2WHh0IfttPxEc+II+2aQlRbtW16sMghaEFnHoNxW7mCoHPKZDW3Mh9T7unoS wIKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=p6D7/5BidEe3XpfScupYNsNQdCy1j4id8nWIUcSG2MQ=; b=Y7XOX4piPXXlgl1xhN62S3Zos3fWt1H40wLIXs5/jKELzq9UiB1BRN1qbEg59UlnKU ry6TIEkeTGRQZaZb4sZKyf7SRgnF+nJ/8JSMW1GpkyYiqm41kuETr2JOKL40UT7klu0z qjdk6jNNP+Ge5waV7TFQGEyM/yKLaHDMJwYZGFR9lKg5A6IWiFQ9dE8Yy3PDzeK7nF6k 3MIaN4FCfPKnv98KjSdcZudT229ysRTKXD0AF8dXrlKxLmNp1Athj+PUW0LHmk6d/N7S hjoYiuRGLmr16vq/VPxmztRoa4zjsPaskwlz7t49aVE6iqVkFwAAvpzONMLW/nP4CQZk SZdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HLsEJBaA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si37455pgs.139.2018.06.12.00.50.08; Tue, 12 Jun 2018 00:50:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HLsEJBaA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933571AbeFLHta (ORCPT + 99 others); Tue, 12 Jun 2018 03:49:30 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:39806 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933526AbeFLHtQ (ORCPT ); Tue, 12 Jun 2018 03:49:16 -0400 Received: by mail-lf0-f68.google.com with SMTP id t134-v6so34509044lff.6; Tue, 12 Jun 2018 00:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p6D7/5BidEe3XpfScupYNsNQdCy1j4id8nWIUcSG2MQ=; b=HLsEJBaAolDWUEaHyFdXd0t8YN3WZiXkDkHSAjufL8YY+XND/Xfmu71+rvo41XGfpR F1HfvRRhqqutSgAwXpHxxGM36EcTVpP8IzPfdpzxAqI3X+dNdf3eFo+zr9M1m4nXos0F knruo8/cqxOTe1c9y2eP4SA5FctsOc6XEisaLLzkrXtNjIjfqJb/lTQVKzDKXYuOoXMW k8Ys5CB9Nf/leERFw2+d1k3X5boe2upES47lKH2r7t2NHeFfhmKp2pKs37FY/pxD0NeN Q0HxIG2e+ENEGzNLrcZZK0RY0SmUqIM9ZGqEaTiQRcOTKqi4JTemz6UptbxpBbqwqg01 5DwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p6D7/5BidEe3XpfScupYNsNQdCy1j4id8nWIUcSG2MQ=; b=ES57yc8sxDrxXwfm4NKLLcPblTjuxLWHFccAZPzPqSSMH328zSL+HE8kQgDVpsKXqv hFyF6BnHBty6fAdWCD74e9N6PKBsnoPnltRuHasJtmIiR+V81z0xGEfihAJNC3qTm0IH 5hrDWW7zJhalKTrP3kOvxA8XIIRLfeCGI4ajdMAWhi5MYgOHzkSMQzBqSJInpmVwq0+n 3gv+SJbBX6SmTmN+/bTAgVTt0ZVeEgMiZQNRpHVEXIz6F/YAnGkyFrYDofzvp7XcEicV mguPyAQJAx/zvdZtde5Zpp2kw9C6fSgj0P83aJTpQsVq90M7gRulPtiX8V6yYAUSslb6 5pbA== X-Gm-Message-State: APt69E19wYb9OCC0yzFjlmQghU7kS9NKMod/CR7VJGRq9EZbAqWluUyT VjWfv1DFpJN6kSrngJcId/I= X-Received: by 2002:a19:c452:: with SMTP id u79-v6mr1358667lff.5.1528789754536; Tue, 12 Jun 2018 00:49:14 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id b65-v6sm62657lfe.80.2018.06.12.00.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Jun 2018 00:49:13 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com, jgross@suse.com, lyan@suse.com, boris.ostrovsky@oracle.com Cc: konrad.wilk@oracle.com, andr2000@gmail.com, andrii_chepurnyi@epam.com, Oleksandr Andrushchenko Subject: [PATCH v5 3/3] Input: xen-kbdfront - allow better run-time configuration Date: Tue, 12 Jun 2018 10:48:56 +0300 Message-Id: <20180612074856.28451-4-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612074856.28451-1-andr2000@gmail.com> References: <20180612074856.28451-1-andr2000@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Andrushchenko It is now only possible to control if multi-touch virtual device is created or not (via the corresponding XenStore entries), but keyboard and pointer devices are always created. In some cases this is not desirable. For example, if virtual keyboard device is exposed to Android then the latter won't automatically show on-screen keyboard as it expects that a physical keyboard device can be used for typing. Utilize keyboard and pointer device XenStore feature fields to configure which virtual devices are created: - set "feature-disable-keyboard" to 1 if no keyboard device needs to be created - set "feature-disable-pointer" to 1 if no pointer device needs to be created Keep old behavior by default. Signed-off-by: Oleksandr Andrushchenko Suggested-by: Andrii Chepurnyi Tested-by: Andrii Chepurnyi --- drivers/input/misc/xen-kbdfront.c | 177 ++++++++++++++++++------------ 1 file changed, 106 insertions(+), 71 deletions(-) diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c index 92d739649022..f50fba1962ec 100644 --- a/drivers/input/misc/xen-kbdfront.c +++ b/drivers/input/misc/xen-kbdfront.c @@ -63,6 +63,9 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *); static void xenkbd_handle_motion_event(struct xenkbd_info *info, struct xenkbd_motion *motion) { + if (unlikely(!info->ptr)) + return; + input_report_rel(info->ptr, REL_X, motion->rel_x); input_report_rel(info->ptr, REL_Y, motion->rel_y); if (motion->rel_z) @@ -73,6 +76,9 @@ static void xenkbd_handle_motion_event(struct xenkbd_info *info, static void xenkbd_handle_position_event(struct xenkbd_info *info, struct xenkbd_position *pos) { + if (unlikely(!info->ptr)) + return; + input_report_abs(info->ptr, ABS_X, pos->abs_x); input_report_abs(info->ptr, ABS_Y, pos->abs_y); if (pos->rel_z) @@ -97,6 +103,9 @@ static void xenkbd_handle_key_event(struct xenkbd_info *info, return; } + if (unlikely(!dev)) + return; + input_event(dev, EV_KEY, key->keycode, value); input_sync(dev); } @@ -192,7 +201,7 @@ static int xenkbd_probe(struct xenbus_device *dev, const struct xenbus_device_id *id) { int ret, i; - unsigned int abs, touch; + bool with_mtouch, with_kbd, with_ptr; struct xenkbd_info *info; struct input_dev *kbd, *ptr, *mtouch; @@ -211,93 +220,114 @@ static int xenkbd_probe(struct xenbus_device *dev, if (!info->page) goto error_nomem; - /* Set input abs params to match backend screen res */ - abs = xenbus_read_unsigned(dev->otherend, - XENKBD_FIELD_FEAT_ABS_POINTER, 0); - ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend, - XENKBD_FIELD_WIDTH, - ptr_size[KPARAM_X]); - ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend, - XENKBD_FIELD_HEIGHT, - ptr_size[KPARAM_Y]); - if (abs) { - ret = xenbus_write(XBT_NIL, dev->nodename, - XENKBD_FIELD_REQ_ABS_POINTER, "1"); - if (ret) { - pr_warn("xenkbd: can't request abs-pointer\n"); - abs = 0; - } - } + /* + * The below are reverse logic, e.g. if the feature is set, then + * do not expose the corresponding virtual device. + */ + with_kbd = !xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_FEAT_DSBL_KEYBRD, 0); + + with_ptr = !xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_FEAT_DSBL_POINTER, 0); - touch = xenbus_read_unsigned(dev->otherend, - XENKBD_FIELD_FEAT_MTOUCH, 0); - if (touch) { + /* Direct logic: if set, then create multi-touch device. */ + with_mtouch = xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_FEAT_MTOUCH, 0); + if (with_mtouch) { ret = xenbus_write(XBT_NIL, dev->nodename, XENKBD_FIELD_REQ_MTOUCH, "1"); if (ret) { pr_warn("xenkbd: can't request multi-touch"); - touch = 0; + with_mtouch = 0; } } /* keyboard */ - kbd = input_allocate_device(); - if (!kbd) - goto error_nomem; - kbd->name = "Xen Virtual Keyboard"; - kbd->phys = info->phys; - kbd->id.bustype = BUS_PCI; - kbd->id.vendor = 0x5853; - kbd->id.product = 0xffff; - - __set_bit(EV_KEY, kbd->evbit); - for (i = KEY_ESC; i < KEY_UNKNOWN; i++) - __set_bit(i, kbd->keybit); - for (i = KEY_OK; i < KEY_MAX; i++) - __set_bit(i, kbd->keybit); - - ret = input_register_device(kbd); - if (ret) { - input_free_device(kbd); - xenbus_dev_fatal(dev, ret, "input_register_device(kbd)"); - goto error; + if (with_kbd) { + kbd = input_allocate_device(); + if (!kbd) + goto error_nomem; + kbd->name = "Xen Virtual Keyboard"; + kbd->phys = info->phys; + kbd->id.bustype = BUS_PCI; + kbd->id.vendor = 0x5853; + kbd->id.product = 0xffff; + + __set_bit(EV_KEY, kbd->evbit); + for (i = KEY_ESC; i < KEY_UNKNOWN; i++) + __set_bit(i, kbd->keybit); + for (i = KEY_OK; i < KEY_MAX; i++) + __set_bit(i, kbd->keybit); + + ret = input_register_device(kbd); + if (ret) { + input_free_device(kbd); + xenbus_dev_fatal(dev, ret, + "input_register_device(kbd)"); + goto error; + } + info->kbd = kbd; } - info->kbd = kbd; /* pointing device */ - ptr = input_allocate_device(); - if (!ptr) - goto error_nomem; - ptr->name = "Xen Virtual Pointer"; - ptr->phys = info->phys; - ptr->id.bustype = BUS_PCI; - ptr->id.vendor = 0x5853; - ptr->id.product = 0xfffe; - - if (abs) { - __set_bit(EV_ABS, ptr->evbit); - input_set_abs_params(ptr, ABS_X, 0, ptr_size[KPARAM_X], 0, 0); - input_set_abs_params(ptr, ABS_Y, 0, ptr_size[KPARAM_Y], 0, 0); - } else { - input_set_capability(ptr, EV_REL, REL_X); - input_set_capability(ptr, EV_REL, REL_Y); - } - input_set_capability(ptr, EV_REL, REL_WHEEL); + if (with_ptr) { + unsigned int abs; + + /* Set input abs params to match backend screen res */ + abs = xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_FEAT_ABS_POINTER, 0); + ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_WIDTH, + ptr_size[KPARAM_X]); + ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend, + XENKBD_FIELD_HEIGHT, + ptr_size[KPARAM_Y]); + if (abs) { + ret = xenbus_write(XBT_NIL, dev->nodename, + XENKBD_FIELD_REQ_ABS_POINTER, "1"); + if (ret) { + pr_warn("xenkbd: can't request abs-pointer\n"); + abs = 0; + } + } - __set_bit(EV_KEY, ptr->evbit); - for (i = BTN_LEFT; i <= BTN_TASK; i++) - __set_bit(i, ptr->keybit); + ptr = input_allocate_device(); + if (!ptr) + goto error_nomem; + ptr->name = "Xen Virtual Pointer"; + ptr->phys = info->phys; + ptr->id.bustype = BUS_PCI; + ptr->id.vendor = 0x5853; + ptr->id.product = 0xfffe; + + if (abs) { + __set_bit(EV_ABS, ptr->evbit); + input_set_abs_params(ptr, ABS_X, 0, + ptr_size[KPARAM_X], 0, 0); + input_set_abs_params(ptr, ABS_Y, 0, + ptr_size[KPARAM_Y], 0, 0); + } else { + input_set_capability(ptr, EV_REL, REL_X); + input_set_capability(ptr, EV_REL, REL_Y); + } + input_set_capability(ptr, EV_REL, REL_WHEEL); - ret = input_register_device(ptr); - if (ret) { - input_free_device(ptr); - xenbus_dev_fatal(dev, ret, "input_register_device(ptr)"); - goto error; + __set_bit(EV_KEY, ptr->evbit); + for (i = BTN_LEFT; i <= BTN_TASK; i++) + __set_bit(i, ptr->keybit); + + ret = input_register_device(ptr); + if (ret) { + input_free_device(ptr); + xenbus_dev_fatal(dev, ret, + "input_register_device(ptr)"); + goto error; + } + info->ptr = ptr; } - info->ptr = ptr; /* multi-touch device */ - if (touch) { + if (with_mtouch) { int num_cont, width, height; mtouch = input_allocate_device(); @@ -346,6 +376,11 @@ static int xenkbd_probe(struct xenbus_device *dev, info->mtouch = mtouch; } + if (!(with_kbd | with_ptr | with_mtouch)) { + ret = -ENXIO; + goto error; + } + ret = xenkbd_connect_backend(dev, info); if (ret < 0) goto error; -- 2.17.1