From patchwork Sat Jun 4 21:33:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9154983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07C6B60574 for ; Sat, 4 Jun 2016 21:43:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED72827F2B for ; Sat, 4 Jun 2016 21:43:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E23EE28327; Sat, 4 Jun 2016 21:43:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA3712824A for ; Sat, 4 Jun 2016 21:43:05 +0000 (UTC) Received: from localhost ([::1]:34241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JLU-0005xv-TE for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Jun 2016 17:43:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCX-0005zN-Ie for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9JCN-0005oA-HE for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:48 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCM-0005mC-Ok for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:39 -0400 Received: by mail-wm0-x244.google.com with SMTP id k184so894653wme.2 for ; Sat, 04 Jun 2016 14:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UyLwGAF9USf4qduW+KiTRgEmkm1wg0a1H1w3qN6RFp4=; b=Rhy15N8/IHly3uTOXgD4HKLgUFvaOK/+4SKFkGr93FX3C5HFB18YxqI06qk8bMz9Gw po2JzwjMiYRiB12Xp9/iDmNfyXO5YCkWihZq+r7raoQk9BaenfTWt2Ew4w7n6eKA8rVg MZLcBME45xVS/iXMDjF0s9mUSlXnemx9Wg/JTfEnf3XN1rE/VOShbJz1uKxULlexOuyc wl6NngtwHdURQu3qyrni/Yqd90fFDUASP6IL6QZHjOsbOBevcOLfgIqFea/knEYxqqYL zsOu18LK8wSrwRWuViHvThiAWHG1l970PzbURnteT2mkcogpFgxa37ZnHBq9cWoC69eV uSfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=UyLwGAF9USf4qduW+KiTRgEmkm1wg0a1H1w3qN6RFp4=; b=gVIodry+IgjyLNfitF/Qn0G4zCBlXm4GwSvSQ6VX+SLlOalKClBiasKhSqPv/VMyy0 8bZNjXdihGcHU0g2Z1P290oqdbH0htXAIz+wjXg75UMbyPq6cMVbUFHRlvsXlqD85iLw SpD64YOocWBHV1gXCPNKrHcD4BmXWyfOQb0iW08kHw+CetVKGScuTPE9ImeoLfR9pmPb 7rylbc54e8DIyKHSXXnefNqqZJtgqA4HgYj5oiD4OMkcwr13CeG/+iRUmlCtaVMgsC+r l/4EqTEx2ODhulw9aZ8+M8kC7IcEl3FZLDMoQQ/z4CVgpeJhe7Zs6XgBncfFhb8KIt5q EbMw== X-Gm-Message-State: ALyK8tIFlNwN1lv6QZCKAydOSUvEKkYX4ikfk7gezDMgnCdcMwkOL8BJeD/1uWCF9gBfCA== X-Received: by 10.194.223.41 with SMTP id qr9mr8812928wjc.61.1465076018133; Sat, 04 Jun 2016 14:33:38 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-235.w193-248.abo.wanadoo.fr. [193.248.103.235]) by smtp.gmail.com with ESMTPSA id r19sm1346719wmd.3.2016.06.04.14.33.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 14:33:37 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Sat, 4 Jun 2016 23:33:14 +0200 Message-Id: <1465076003-26291-6-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> References: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [RFC 05/14] Add vhost-user backend to virtio-input-host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Learn to use a vhost-user as a virtio-input backend. Usage: -object vhost-user-backend,id=vuid -device virtio-input-host-pci,vhost-user=vuid Signed-off-by: Marc-André Lureau --- hw/input/virtio-input-host.c | 67 ++++++++++++++++++++++++++++++++++------ hw/input/virtio-input.c | 4 +++ hw/virtio/virtio-pci.c | 5 +++ include/hw/virtio/virtio-input.h | 2 ++ 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c index cb79e80..c2c48bd 100644 --- a/hw/input/virtio-input-host.c +++ b/hw/input/virtio-input-host.c @@ -95,20 +95,14 @@ static void virtio_input_abs_config(VirtIOInputHost *vih, int axis) virtio_input_add_config(VIRTIO_INPUT(vih), &config); } -static void virtio_input_host_realize(DeviceState *dev, Error **errp) +static void virtio_input_evdev_init(VirtIOInputHost *vih, Error **errp) { - VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev); - VirtIOInput *vinput = VIRTIO_INPUT(dev); + VirtIOInput *vinput = VIRTIO_INPUT(vih); virtio_input_config id, *abs; struct input_id ids; int rc, ver, i, axis; uint8_t byte; - if (!vih->evdev) { - error_setg(errp, "evdev property is required"); - return; - } - vih->fd = open(vih->evdev, O_RDWR); if (vih->fd < 0) { error_setg_file_open(errp, errno, vih->evdev); @@ -175,7 +169,34 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp) err_close: close(vih->fd); vih->fd = -1; - return; +} + +static void virtio_input_host_realize(DeviceState *dev, Error **errp) +{ + VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev); + VirtIOInput *vinput = VIRTIO_INPUT(vih); + + if (!!vih->evdev + !!vinput->vhost != 1) { + error_setg(errp, "'evdev' or 'vhost-user' property is required"); + return; + } + + if (vih->evdev) { + virtio_input_evdev_init(vih, errp); + } else { + virtio_input_config *config; + int i, ret; + + ret = vhost_user_input_get_config(&vinput->vhost->dev, &config); + if (ret < 0) { + error_setg(errp, "failed to get input config"); + return; + } + for (i = 0; i < ret; i++) { + virtio_input_add_config(vinput, &config[i]); + } + g_free(config); + } } static void virtio_input_host_unrealize(DeviceState *dev, Error **errp) @@ -210,6 +231,15 @@ static void virtio_input_host_handle_status(VirtIOInput *vinput, } } +static void virtio_input_host_change_active(VirtIOInput *vinput) +{ + if (vinput->active) { + vhost_user_backend_start(vinput->vhost); + } else { + vhost_user_backend_stop(vinput->vhost); + } +} + static const VMStateDescription vmstate_virtio_input_host = { .name = "virtio-input-host", .unmigratable = 1, @@ -230,6 +260,19 @@ static void virtio_input_host_class_init(ObjectClass *klass, void *data) vic->realize = virtio_input_host_realize; vic->unrealize = virtio_input_host_unrealize; vic->handle_status = virtio_input_host_handle_status; + vic->change_active = virtio_input_host_change_active; +} + +static void virtio_input_host_user_is_busy(Object *obj, const char *name, + Object *val, Error **errp) +{ + VirtIOInput *vinput = VIRTIO_INPUT(obj); + + if (vinput->vhost) { + error_setg(errp, "can't use already busy vhost-user"); + } else { + qdev_prop_allow_set_link_before_realize(obj, name, val, errp); + } } static void virtio_input_host_init(Object *obj) @@ -237,6 +280,12 @@ static void virtio_input_host_init(Object *obj) VirtIOInput *vinput = VIRTIO_INPUT(obj); virtio_input_init_config(vinput, virtio_input_host_config); + + object_property_add_link(obj, "vhost-user", TYPE_VHOST_USER_BACKEND, + (Object **)&vinput->vhost, + virtio_input_host_user_is_busy, + OBJ_PROP_LINK_UNREF_ON_RELEASE, + &error_abort); } static const TypeInfo virtio_input_host_info = { diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index f59749a..3c9ac46 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -280,6 +280,10 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp) vinput->evt = virtio_add_queue(vdev, 64, virtio_input_handle_evt); vinput->sts = virtio_add_queue(vdev, 64, virtio_input_handle_sts); + if (vinput->vhost) { + vhost_user_backend_dev_init(vinput->vhost, vdev, 2, errp); + } + register_savevm(dev, "virtio-input", -1, VIRTIO_INPUT_VM_VERSION, virtio_input_save, virtio_input_load, vinput); } diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index bfedbbf..0a14fd4 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2454,6 +2454,11 @@ static void virtio_host_initfn(Object *obj) virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_INPUT_HOST); + + /* could eventually be included in qdev_alias_all_properties? */ + object_property_add_alias(obj, "vhost-user", + OBJECT(&dev->vdev), "vhost-user", + &error_abort); } static const TypeInfo virtio_host_pci_info = { diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h index bddbd4b..05694b1 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -2,6 +2,7 @@ #define _QEMU_VIRTIO_INPUT_H #include "ui/input.h" +#include "sysemu/vhost-user-backend.h" /* ----------------------------------------------------------------- */ /* virtio input protocol */ @@ -66,6 +67,7 @@ struct VirtIOInput { uint32_t qindex, qsize; bool active; + VhostUserBackend *vhost; }; struct VirtIOInputClass {