From nobody Fri Dec 19 06:17:48 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678968375; cv=none; d=zohomail.com; s=zohoarc; b=Y5W74LOcduToTHa03Pq7cVXTEJiD/uuiS494yjvS/0uO21TT6CMKTuUBWHpuCLRRNF5+qYjYJjY59TcvbwVMrprj96syVyQp8aVkpVQ884Fhpzq8awadJZwajz7HrWJ50jucxkwM+B+SAjqckB1B05QDvWbhG1Mit6vfGTVxM4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678968375; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U7IkFMqg212H5O5pqypIqnLu5f0vym6RzCwLYnidtQA=; b=cu7PTFnd+uAMOJvxB6rZqEIREKjH8Vy3I669L5Gs6CcnbL88flowyICVcQqq6ZUnl3GbtP6jwjDhT9l6WDi/H9/euptREsIeCyqS7zUFt9KpEd3H6SquMZcLKVlU0MQ+2Noj2igotO9YLWz8QVKWLRlJWUBdEcG2PWrfI/iIyFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678968375689939.9046103430542; Thu, 16 Mar 2023 05:06:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcmMB-0002iG-Sn; Thu, 16 Mar 2023 08:05:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcmMA-0002hq-2h for qemu-devel@nongnu.org; Thu, 16 Mar 2023 08:05:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcmM8-0002m9-6C for qemu-devel@nongnu.org; Thu, 16 Mar 2023 08:05:17 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-t-3Kq0OINyiCfX5kPFeqYg-1; Thu, 16 Mar 2023 08:05:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D49E496DC98; Thu, 16 Mar 2023 12:05:13 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C1C6140EBF4; Thu, 16 Mar 2023 12:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678968315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U7IkFMqg212H5O5pqypIqnLu5f0vym6RzCwLYnidtQA=; b=Cgo2KNVrcstDtiSo68gMMCXSUdq1VI11L211EMAKI46pxvcN/isijyFuSl+eCkoMdts2pL S0REYZS1JRqY/iTcuvw3DM47lh/ftXFlkDJkKwtWzz6FLRhFCaNf/PER3TXYTP60RSmFDF xk0QF/F63xwDemqXytHGvTfHscrax7w= X-MC-Unique: t-3Kq0OINyiCfX5kPFeqYg-1 From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Pavel Dovgalyuk , "Michael S. Tsirkin" , Markus Armbruster , Gerd Hoffmann , Paolo Bonzini , Sergio Lopez Subject: [PATCH v2 3/6] virtio-input: add a virtio-mulitouch device Date: Thu, 16 Mar 2023 13:06:21 +0100 Message-Id: <20230316120624.46410-4-slp@redhat.com> In-Reply-To: <20230316120624.46410-1-slp@redhat.com> References: <20230316120624.46410-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678968377993100007 Content-Type: text/plain; charset="utf-8" Add a virtio-multitouch device to the family of devices emulated by virtio-input implementing the Multi-touch protocol as descripted here: https://www.kernel.org/doc/html/latest/input/multi-touch-protocol.html?high= light=3Dmulti+touch This patch just add the device itself, without connecting it to any backends. The following patches will add a PCI-based multitouch device, some helpers in "ui" and will enable the GTK3 backend to transpose multi-touch events from the host to the guest. Signed-off-by: Sergio Lopez Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/input/virtio-input-hid.c | 118 ++++++++++++++++++++++++++++++- include/hw/virtio/virtio-input.h | 9 +-- 2 files changed, 120 insertions(+), 7 deletions(-) diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index d28dab69ba..742235d3fa 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -16,9 +16,10 @@ =20 #include "standard-headers/linux/input.h" =20 -#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard" -#define VIRTIO_ID_NAME_MOUSE "QEMU Virtio Mouse" -#define VIRTIO_ID_NAME_TABLET "QEMU Virtio Tablet" +#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard" +#define VIRTIO_ID_NAME_MOUSE "QEMU Virtio Mouse" +#define VIRTIO_ID_NAME_TABLET "QEMU Virtio Tablet" +#define VIRTIO_ID_NAME_MULTITOUCH "QEMU Virtio Multitouch" =20 /* ----------------------------------------------------------------- */ =20 @@ -30,6 +31,7 @@ static const unsigned short keymap_button[INPUT_BUTTON__M= AX] =3D { [INPUT_BUTTON_WHEEL_DOWN] =3D BTN_GEAR_DOWN, [INPUT_BUTTON_SIDE] =3D BTN_SIDE, [INPUT_BUTTON_EXTRA] =3D BTN_EXTRA, + [INPUT_BUTTON_TOUCH] =3D BTN_TOUCH, }; =20 static const unsigned short axismap_rel[INPUT_AXIS__MAX] =3D { @@ -42,6 +44,11 @@ static const unsigned short axismap_abs[INPUT_AXIS__MAX]= =3D { [INPUT_AXIS_Y] =3D ABS_Y, }; =20 +static const unsigned short axismap_tch[INPUT_AXIS__MAX] =3D { + [INPUT_AXIS_X] =3D ABS_MT_POSITION_X, + [INPUT_AXIS_Y] =3D ABS_MT_POSITION_Y, +}; + /* ----------------------------------------------------------------- */ =20 static void virtio_input_extend_config(VirtIOInput *vinput, @@ -81,6 +88,7 @@ static void virtio_input_handle_event(DeviceState *dev, Q= emuConsole *src, InputKeyEvent *key; InputMoveEvent *move; InputBtnEvent *btn; + InputMultitouchEvent *mtt; =20 switch (evt->type) { case INPUT_EVENT_KIND_KEY: @@ -137,6 +145,24 @@ static void virtio_input_handle_event(DeviceState *dev= , QemuConsole *src, event.value =3D cpu_to_le32(move->value); virtio_input_send(vinput, &event); break; + case INPUT_EVENT_KIND_MTT: + mtt =3D evt->u.mtt.data; + if (mtt->type =3D=3D INPUT_MULTITOUCH_TYPE_DATA) { + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(axismap_tch[mtt->axis]); + event.value =3D cpu_to_le32(mtt->value); + virtio_input_send(vinput, &event); + } else { + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(ABS_MT_SLOT); + event.value =3D cpu_to_le32(mtt->slot); + virtio_input_send(vinput, &event); + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(ABS_MT_TRACKING_ID); + event.value =3D cpu_to_le32(mtt->tracking_id); + virtio_input_send(vinput, &event); + } + break; default: /* keep gcc happy */ break; @@ -515,12 +541,98 @@ static const TypeInfo virtio_tablet_info =3D { =20 /* ----------------------------------------------------------------- */ =20 +static QemuInputHandler virtio_multitouch_handler =3D { + .name =3D VIRTIO_ID_NAME_MULTITOUCH, + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_MTT, + .event =3D virtio_input_handle_event, + .sync =3D virtio_input_handle_sync, +}; + +static struct virtio_input_config virtio_multitouch_config[] =3D { + { + .select =3D VIRTIO_INPUT_CFG_ID_NAME, + .size =3D sizeof(VIRTIO_ID_NAME_MULTITOUCH), + .u.string =3D VIRTIO_ID_NAME_MULTITOUCH, + },{ + .select =3D VIRTIO_INPUT_CFG_ID_DEVIDS, + .size =3D sizeof(struct virtio_input_devids), + .u.ids =3D { + .bustype =3D const_le16(BUS_VIRTUAL), + .vendor =3D const_le16(0x0627), /* same we use for usb hid de= vices */ + .product =3D const_le16(0x0003), + .version =3D const_le16(0x0001), + }, + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_SLOT, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_SLOTS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_SLOTS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_TRACKING_ID, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_SLOTS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_SLOTS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_POSITION_X, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_POSITION_Y, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), + }, + { /* end of list */ }, +}; + +static void virtio_multitouch_init(Object *obj) +{ + VirtIOInputHID *vhid =3D VIRTIO_INPUT_HID(obj); + VirtIOInput *vinput =3D VIRTIO_INPUT(obj); + unsigned short abs_props[] =3D { + INPUT_PROP_DIRECT, + }; + unsigned short abs_bits[] =3D { + ABS_MT_SLOT, + ABS_MT_TRACKING_ID, + ABS_MT_POSITION_X, + ABS_MT_POSITION_Y, + }; + + vhid->handler =3D &virtio_multitouch_handler; + virtio_input_init_config(vinput, virtio_multitouch_config); + virtio_input_extend_config(vinput, keymap_button, + ARRAY_SIZE(keymap_button), + VIRTIO_INPUT_CFG_EV_BITS, EV_KEY); + virtio_input_extend_config(vinput, abs_props, + ARRAY_SIZE(abs_props), + VIRTIO_INPUT_CFG_PROP_BITS, 0); + virtio_input_extend_config(vinput, abs_bits, + ARRAY_SIZE(abs_bits), + VIRTIO_INPUT_CFG_EV_BITS, EV_ABS); +} + +static const TypeInfo virtio_multitouch_info =3D { + .name =3D TYPE_VIRTIO_MULTITOUCH, + .parent =3D TYPE_VIRTIO_INPUT_HID, + .instance_size =3D sizeof(VirtIOInputHID), + .instance_init =3D virtio_multitouch_init, +}; + +/* ----------------------------------------------------------------- */ + static void virtio_register_types(void) { type_register_static(&virtio_input_hid_info); type_register_static(&virtio_keyboard_info); type_register_static(&virtio_mouse_info); type_register_static(&virtio_tablet_info); + type_register_static(&virtio_multitouch_info); } =20 type_init(virtio_register_types) diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-in= put.h index f2da63d309..08f1591424 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -24,10 +24,11 @@ OBJECT_DECLARE_TYPE(VirtIOInput, VirtIOInputClass, #define VIRTIO_INPUT_GET_PARENT_CLASS(obj) \ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT) =20 -#define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device" -#define TYPE_VIRTIO_KEYBOARD "virtio-keyboard-device" -#define TYPE_VIRTIO_MOUSE "virtio-mouse-device" -#define TYPE_VIRTIO_TABLET "virtio-tablet-device" +#define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device" +#define TYPE_VIRTIO_KEYBOARD "virtio-keyboard-device" +#define TYPE_VIRTIO_MOUSE "virtio-mouse-device" +#define TYPE_VIRTIO_TABLET "virtio-tablet-device" +#define TYPE_VIRTIO_MULTITOUCH "virtio-multitouch-device" =20 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHID, VIRTIO_INPUT_HID) #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \ --=20 2.38.1