mirror of https://github.com/xemu-project/xemu.git
input: add vhost-user-input, virtio-input fixes.
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABAgAGBQJc2RQ3AAoJEEy22O7T6HE4tx8P/2R7vgiCF95O89FjMzgFMUt1 L/rYOWnH2lfbPIKWEzgGRs+1tQecO1PfQigKgPENEy3OhBdkfP6Tqy9Vjyrg9j4G lnn3a4a2UkRIjjcXapCPhzcMSdBMrTopXniXt7EhvWICVaE0+SPtqnbNMXoKK/zy WPLf+ffD/xwI+kGM0tLLQQJrcYV2Nq4kOd3E6IiMlrOPbKbVk8RnVoDIa7rpI9c5 zucTDt0pc2pi7LW6w15W67cA1AZKikixa9v2TD/8J8VSV4ylBk62scFvMit0DLIv mMs5BDWYYdBVJpljMizt+cx7ptU9n6eSkqs6s4R6MF+RqhA9jdu7YnwKXMZe1PDx TvQqS1VK1QKgqswolaKVAXn5XKdi61Ikfw1QM0L8RMy3c3a/gVmIUUAdPPuDGtsA 3KHEztij0wtJuxRF7Dj3OzeKJqwUBZssyHBo+dVt37ge4j/1xinTCLYmtEmvYVvQ Lv3bcRJOm8WlEB4KYiJ/lo0L90vWxTdDEg5pBNKRWPppjqabJnvNHWdwAknSV7P8 MHSoMuY6Ww+e1/8IzhkdJbiTIU1NnkPTgAxBcaQIaAKAk91AINzRVuJNzMDrxlLz z2ztlduFr6vr5xHBf9buE17+WUXB0sPwkUFcWep5XBLgvM6WWzlbxu3uH92wf6H3 LIUd+6TdEHPbuMjf2OXc =Y8xB -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/kraxel/tags/input-20190513-v2-pull-request' into staging input: add vhost-user-input, virtio-input fixes. # gpg: Signature made Mon 13 May 2019 07:52:39 BST # gpg: using RSA key 4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full] # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" [full] # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/input-20190513-v2-pull-request: virtio-input: fix Kconfig dependency and Makefile virtio-input-host-pci: cleanup types util: simplify unix_listen() Add vhost-user-input-pci Add vhost-user-backend libvhost-user: add PROTOCOL_F_CONFIG if {set, get}_config libvhost-user: fix -Waddress-of-packed-member Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
082b4061a4
|
@ -1485,6 +1485,8 @@ F: hw/*/*vhost*
|
||||||
F: docs/interop/vhost-user.json
|
F: docs/interop/vhost-user.json
|
||||||
F: docs/interop/vhost-user.txt
|
F: docs/interop/vhost-user.txt
|
||||||
F: contrib/vhost-user-*/
|
F: contrib/vhost-user-*/
|
||||||
|
F: backends/vhost-user.c
|
||||||
|
F: include/sysemu/vhost-user-backend.h
|
||||||
|
|
||||||
virtio
|
virtio
|
||||||
M: Michael S. Tsirkin <mst@redhat.com>
|
M: Michael S. Tsirkin <mst@redhat.com>
|
||||||
|
@ -1526,6 +1528,7 @@ L: qemu-s390x@nongnu.org
|
||||||
virtio-input
|
virtio-input
|
||||||
M: Gerd Hoffmann <kraxel@redhat.com>
|
M: Gerd Hoffmann <kraxel@redhat.com>
|
||||||
S: Maintained
|
S: Maintained
|
||||||
|
F: hw/input/vhost-user-input.c
|
||||||
F: hw/input/virtio-input*.c
|
F: hw/input/virtio-input*.c
|
||||||
F: include/hw/virtio/virtio-input.h
|
F: include/hw/virtio/virtio-input.h
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,6 @@ common-obj-y += cryptodev-vhost.o
|
||||||
common-obj-$(CONFIG_VHOST_CRYPTO) += cryptodev-vhost-user.o
|
common-obj-$(CONFIG_VHOST_CRYPTO) += cryptodev-vhost-user.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO)) += vhost-user.o
|
||||||
|
|
||||||
common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
|
common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
|
||||||
|
|
|
@ -0,0 +1,209 @@
|
||||||
|
/*
|
||||||
|
* QEMU vhost-user backend
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Red Hat Inc
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Marc-André Lureau <marcandre.lureau@redhat.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "hw/qdev.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qapi/qmp/qerror.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
|
#include "qom/object_interfaces.h"
|
||||||
|
#include "sysemu/vhost-user-backend.h"
|
||||||
|
#include "sysemu/kvm.h"
|
||||||
|
#include "io/channel-command.h"
|
||||||
|
#include "hw/virtio/virtio-bus.h"
|
||||||
|
|
||||||
|
static bool
|
||||||
|
ioeventfd_enabled(void)
|
||||||
|
{
|
||||||
|
return kvm_enabled() && kvm_eventfds_enabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev,
|
||||||
|
unsigned nvqs, Error **errp)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
assert(!b->vdev && vdev);
|
||||||
|
|
||||||
|
if (!ioeventfd_enabled()) {
|
||||||
|
error_setg(errp, "vhost initialization failed: requires kvm");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vhost_user_init(&b->vhost_user, &b->chr, errp)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->vdev = vdev;
|
||||||
|
b->dev.nvqs = nvqs;
|
||||||
|
b->dev.vqs = g_new(struct vhost_virtqueue, nvqs);
|
||||||
|
|
||||||
|
ret = vhost_dev_init(&b->dev, &b->vhost_user, VHOST_BACKEND_TYPE_USER, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret, "vhost initialization failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vhost_user_backend_start(VhostUserBackend *b)
|
||||||
|
{
|
||||||
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
|
||||||
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||||
|
int ret, i ;
|
||||||
|
|
||||||
|
if (b->started) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!k->set_guest_notifiers) {
|
||||||
|
error_report("binding does not support guest notifiers");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = vhost_dev_enable_notifiers(&b->dev, b->vdev);
|
||||||
|
if (ret < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = k->set_guest_notifiers(qbus->parent, b->dev.nvqs, true);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_report("Error binding guest notifier");
|
||||||
|
goto err_host_notifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->dev.acked_features = b->vdev->guest_features;
|
||||||
|
ret = vhost_dev_start(&b->dev, b->vdev);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_report("Error start vhost dev");
|
||||||
|
goto err_guest_notifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* guest_notifier_mask/pending not used yet, so just unmask
|
||||||
|
* everything here. virtio-pci will do the right thing by
|
||||||
|
* enabling/disabling irqfd.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < b->dev.nvqs; i++) {
|
||||||
|
vhost_virtqueue_mask(&b->dev, b->vdev,
|
||||||
|
b->dev.vq_index + i, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
b->started = true;
|
||||||
|
return;
|
||||||
|
|
||||||
|
err_guest_notifiers:
|
||||||
|
k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false);
|
||||||
|
err_host_notifiers:
|
||||||
|
vhost_dev_disable_notifiers(&b->dev, b->vdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vhost_user_backend_stop(VhostUserBackend *b)
|
||||||
|
{
|
||||||
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
|
||||||
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!b->started) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vhost_dev_stop(&b->dev, b->vdev);
|
||||||
|
|
||||||
|
if (k->set_guest_notifiers) {
|
||||||
|
ret = k->set_guest_notifiers(qbus->parent,
|
||||||
|
b->dev.nvqs, false);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_report("vhost guest notifier cleanup failed: %d", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(ret >= 0);
|
||||||
|
|
||||||
|
vhost_dev_disable_notifiers(&b->dev, b->vdev);
|
||||||
|
b->started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_chardev(Object *obj, const char *value, Error **errp)
|
||||||
|
{
|
||||||
|
VhostUserBackend *b = VHOST_USER_BACKEND(obj);
|
||||||
|
Chardev *chr;
|
||||||
|
|
||||||
|
if (b->completed) {
|
||||||
|
error_setg(errp, QERR_PERMISSION_DENIED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(b->chr_name);
|
||||||
|
b->chr_name = g_strdup(value);
|
||||||
|
|
||||||
|
chr = qemu_chr_find(b->chr_name);
|
||||||
|
if (chr == NULL) {
|
||||||
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
||||||
|
"Chardev '%s' not found", b->chr_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!qemu_chr_fe_init(&b->chr, chr, errp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->completed = true;
|
||||||
|
/* could call vhost_dev_init() so early message can be exchanged */
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *get_chardev(Object *obj, Error **errp)
|
||||||
|
{
|
||||||
|
VhostUserBackend *b = VHOST_USER_BACKEND(obj);
|
||||||
|
Chardev *chr = qemu_chr_fe_get_driver(&b->chr);
|
||||||
|
|
||||||
|
if (chr && chr->label) {
|
||||||
|
return g_strdup(chr->label);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_user_backend_init(Object *obj)
|
||||||
|
{
|
||||||
|
object_property_add_str(obj, "chardev", get_chardev, set_chardev, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_user_backend_finalize(Object *obj)
|
||||||
|
{
|
||||||
|
VhostUserBackend *b = VHOST_USER_BACKEND(obj);
|
||||||
|
|
||||||
|
g_free(b->dev.vqs);
|
||||||
|
g_free(b->chr_name);
|
||||||
|
|
||||||
|
vhost_user_cleanup(&b->vhost_user);
|
||||||
|
qemu_chr_fe_deinit(&b->chr, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const TypeInfo vhost_user_backend_info = {
|
||||||
|
.name = TYPE_VHOST_USER_BACKEND,
|
||||||
|
.parent = TYPE_OBJECT,
|
||||||
|
.instance_size = sizeof(VhostUserBackend),
|
||||||
|
.instance_init = vhost_user_backend_init,
|
||||||
|
.instance_finalize = vhost_user_backend_finalize,
|
||||||
|
.class_size = sizeof(VhostUserBackendClass),
|
||||||
|
};
|
||||||
|
|
||||||
|
static void register_types(void)
|
||||||
|
{
|
||||||
|
type_register_static(&vhost_user_backend_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
type_init(register_types);
|
|
@ -542,7 +542,7 @@ static bool
|
||||||
vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
|
vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
VhostUserMemory *memory = &vmsg->payload.memory;
|
VhostUserMemory m = vmsg->payload.memory, *memory = &m;
|
||||||
dev->nregions = memory->nregions;
|
dev->nregions = memory->nregions;
|
||||||
|
|
||||||
DPRINT("Nregions: %d\n", memory->nregions);
|
DPRINT("Nregions: %d\n", memory->nregions);
|
||||||
|
@ -684,7 +684,7 @@ static bool
|
||||||
vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg)
|
vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
VhostUserMemory *memory = &vmsg->payload.memory;
|
VhostUserMemory m = vmsg->payload.memory, *memory = &m;
|
||||||
|
|
||||||
for (i = 0; i < dev->nregions; i++) {
|
for (i = 0; i < dev->nregions; i++) {
|
||||||
VuDevRegion *r = &dev->regions[i];
|
VuDevRegion *r = &dev->regions[i];
|
||||||
|
@ -813,7 +813,7 @@ vu_set_vring_num_exec(VuDev *dev, VhostUserMsg *vmsg)
|
||||||
static bool
|
static bool
|
||||||
vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
|
vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
|
||||||
{
|
{
|
||||||
struct vhost_vring_addr *vra = &vmsg->payload.addr;
|
struct vhost_vring_addr addr = vmsg->payload.addr, *vra = &addr;
|
||||||
unsigned int index = vra->index;
|
unsigned int index = vra->index;
|
||||||
VuVirtq *vq = &dev->vq[index];
|
VuVirtq *vq = &dev->vq[index];
|
||||||
|
|
||||||
|
@ -1157,6 +1157,10 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
|
||||||
features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT;
|
features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dev->iface->get_config && dev->iface->set_config) {
|
||||||
|
features |= 1ULL << VHOST_USER_PROTOCOL_F_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
if (dev->iface->get_protocol_features) {
|
if (dev->iface->get_protocol_features) {
|
||||||
features |= dev->iface->get_protocol_features(dev);
|
features |= dev->iface->get_protocol_features(dev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,12 @@ config VIRTIO_INPUT
|
||||||
config VIRTIO_INPUT_HOST
|
config VIRTIO_INPUT_HOST
|
||||||
bool
|
bool
|
||||||
default y
|
default y
|
||||||
depends on VIRTIO && LINUX
|
depends on VIRTIO_INPUT && LINUX
|
||||||
|
|
||||||
|
config VHOST_USER_INPUT
|
||||||
|
bool
|
||||||
|
default y
|
||||||
|
depends on VIRTIO_INPUT && VHOST_USER
|
||||||
|
|
||||||
config TSC210X
|
config TSC210X
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -9,9 +9,8 @@ common-obj-$(CONFIG_TSC2005) += tsc2005.o
|
||||||
|
|
||||||
common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input.o
|
common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input.o
|
||||||
common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-hid.o
|
common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-hid.o
|
||||||
ifeq ($(CONFIG_LINUX),y)
|
common-obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host.o
|
||||||
common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-host.o
|
common-obj-$(CONFIG_VHOST_USER_INPUT) += vhost-user-input.o
|
||||||
endif
|
|
||||||
|
|
||||||
obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
|
obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
|
||||||
obj-$(CONFIG_PXA2XX) += pxa2xx_keypad.o
|
obj-$(CONFIG_PXA2XX) += pxa2xx_keypad.o
|
||||||
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||||
|
* (at your option) any later version. See the COPYING file in the
|
||||||
|
* top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qemu-common.h"
|
||||||
|
|
||||||
|
#include "hw/qdev.h"
|
||||||
|
#include "hw/virtio/virtio-input.h"
|
||||||
|
|
||||||
|
static int vhost_input_config_change(struct vhost_dev *dev)
|
||||||
|
{
|
||||||
|
error_report("vhost-user-input: unhandled backend config change");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const VhostDevConfigOps config_ops = {
|
||||||
|
.vhost_dev_config_notifier = vhost_input_config_change,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void vhost_input_realize(DeviceState *dev, Error **errp)
|
||||||
|
{
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(dev);
|
||||||
|
VirtIOInput *vinput = VIRTIO_INPUT(dev);
|
||||||
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||||
|
|
||||||
|
vhost_dev_set_config_notifier(&vhi->vhost->dev, &config_ops);
|
||||||
|
vinput->cfg_size = sizeof_field(virtio_input_config, u);
|
||||||
|
if (vhost_user_backend_dev_init(vhi->vhost, vdev, 2, errp) == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_input_change_active(VirtIOInput *vinput)
|
||||||
|
{
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(vinput);
|
||||||
|
|
||||||
|
if (vinput->active) {
|
||||||
|
vhost_user_backend_start(vhi->vhost);
|
||||||
|
} else {
|
||||||
|
vhost_user_backend_stop(vhi->vhost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_input_get_config(VirtIODevice *vdev, uint8_t *config_data)
|
||||||
|
{
|
||||||
|
VirtIOInput *vinput = VIRTIO_INPUT(vdev);
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(vdev);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
memset(config_data, 0, vinput->cfg_size);
|
||||||
|
|
||||||
|
ret = vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cfg_size);
|
||||||
|
if (ret) {
|
||||||
|
error_report("vhost-user-input: get device config space failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_input_set_config(VirtIODevice *vdev,
|
||||||
|
const uint8_t *config_data)
|
||||||
|
{
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(vdev);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = vhost_dev_set_config(&vhi->vhost->dev, config_data,
|
||||||
|
0, sizeof(virtio_input_config),
|
||||||
|
VHOST_SET_CONFIG_TYPE_MASTER);
|
||||||
|
if (ret) {
|
||||||
|
error_report("vhost-user-input: set device config space failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtio_notify_config(vdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const VMStateDescription vmstate_vhost_input = {
|
||||||
|
.name = "vhost-user-input",
|
||||||
|
.unmigratable = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void vhost_input_class_init(ObjectClass *klass, void *data)
|
||||||
|
{
|
||||||
|
VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
|
||||||
|
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
|
||||||
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
|
|
||||||
|
dc->vmsd = &vmstate_vhost_input;
|
||||||
|
vdc->get_config = vhost_input_get_config;
|
||||||
|
vdc->set_config = vhost_input_set_config;
|
||||||
|
vic->realize = vhost_input_realize;
|
||||||
|
vic->change_active = vhost_input_change_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_input_init(Object *obj)
|
||||||
|
{
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(obj);
|
||||||
|
|
||||||
|
vhi->vhost = VHOST_USER_BACKEND(object_new(TYPE_VHOST_USER_BACKEND));
|
||||||
|
object_property_add_alias(obj, "chardev",
|
||||||
|
OBJECT(vhi->vhost), "chardev", &error_abort);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vhost_input_finalize(Object *obj)
|
||||||
|
{
|
||||||
|
VHostUserInput *vhi = VHOST_USER_INPUT(obj);
|
||||||
|
|
||||||
|
object_unref(OBJECT(vhi->vhost));
|
||||||
|
}
|
||||||
|
|
||||||
|
static const TypeInfo vhost_input_info = {
|
||||||
|
.name = TYPE_VHOST_USER_INPUT,
|
||||||
|
.parent = TYPE_VIRTIO_INPUT,
|
||||||
|
.instance_size = sizeof(VHostUserInput),
|
||||||
|
.instance_init = vhost_input_init,
|
||||||
|
.instance_finalize = vhost_input_finalize,
|
||||||
|
.class_init = vhost_input_class_init,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void vhost_input_register_types(void)
|
||||||
|
{
|
||||||
|
type_register_static(&vhost_input_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
type_init(vhost_input_register_types)
|
|
@ -17,6 +17,7 @@ obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
|
||||||
ifeq ($(CONFIG_VIRTIO_PCI),y)
|
ifeq ($(CONFIG_VIRTIO_PCI),y)
|
||||||
obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
|
obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
|
||||||
obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
|
obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
|
||||||
|
obj-$(CONFIG_VHOST_USER_INPUT) += vhost-user-input-pci.o
|
||||||
obj-$(CONFIG_VHOST_USER_SCSI) += vhost-user-scsi-pci.o
|
obj-$(CONFIG_VHOST_USER_SCSI) += vhost-user-scsi-pci.o
|
||||||
obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-pci.o
|
obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-pci.o
|
||||||
obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
|
obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* This work is licensed under the terms of the GNU LGPL, version 2 or
|
||||||
|
* later. See the COPYING.LIB file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
|
#include "hw/virtio/virtio.h"
|
||||||
|
#include "hw/virtio/virtio-input.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
|
#include "virtio-pci.h"
|
||||||
|
|
||||||
|
typedef struct VHostUserInputPCI VHostUserInputPCI;
|
||||||
|
|
||||||
|
#define TYPE_VHOST_USER_INPUT_PCI "vhost-user-input-pci"
|
||||||
|
|
||||||
|
#define VHOST_USER_INPUT_PCI(obj) \
|
||||||
|
OBJECT_CHECK(VHostUserInputPCI, (obj), TYPE_VHOST_USER_INPUT_PCI)
|
||||||
|
|
||||||
|
struct VHostUserInputPCI {
|
||||||
|
VirtIOPCIProxy parent_obj;
|
||||||
|
VHostUserInput vhi;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void vhost_user_input_pci_instance_init(Object *obj)
|
||||||
|
{
|
||||||
|
VHostUserInputPCI *dev = VHOST_USER_INPUT_PCI(obj);
|
||||||
|
|
||||||
|
virtio_instance_init_common(obj, &dev->vhi, sizeof(dev->vhi),
|
||||||
|
TYPE_VHOST_USER_INPUT);
|
||||||
|
|
||||||
|
object_property_add_alias(obj, "chardev",
|
||||||
|
OBJECT(&dev->vhi), "chardev",
|
||||||
|
&error_abort);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const VirtioPCIDeviceTypeInfo vhost_user_input_pci_info = {
|
||||||
|
.generic_name = TYPE_VHOST_USER_INPUT_PCI,
|
||||||
|
.parent = TYPE_VIRTIO_INPUT_PCI,
|
||||||
|
.instance_size = sizeof(VHostUserInputPCI),
|
||||||
|
.instance_init = vhost_user_input_pci_instance_init,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void vhost_user_input_pci_register(void)
|
||||||
|
{
|
||||||
|
virtio_pci_types_register(&vhost_user_input_pci_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
type_init(vhost_user_input_pci_register)
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
|
typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
|
||||||
|
|
||||||
#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci-base"
|
#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
|
||||||
#define VIRTIO_INPUT_HOST_PCI(obj) \
|
#define VIRTIO_INPUT_HOST_PCI(obj) \
|
||||||
OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
|
OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
|
||||||
|
|
||||||
|
@ -31,10 +31,7 @@ static void virtio_host_initfn(Object *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const VirtioPCIDeviceTypeInfo virtio_input_host_pci_info = {
|
static const VirtioPCIDeviceTypeInfo virtio_input_host_pci_info = {
|
||||||
.base_name = TYPE_VIRTIO_INPUT_HOST_PCI,
|
.generic_name = TYPE_VIRTIO_INPUT_HOST_PCI,
|
||||||
.generic_name = "virtio-input-host-pci",
|
|
||||||
.transitional_name = "virtio-input-host-pci-transitional",
|
|
||||||
.non_transitional_name = "virtio-input-host-pci-non-transitional",
|
|
||||||
.parent = TYPE_VIRTIO_INPUT_PCI,
|
.parent = TYPE_VIRTIO_INPUT_PCI,
|
||||||
.instance_size = sizeof(VirtIOInputHostPCI),
|
.instance_size = sizeof(VirtIOInputHostPCI),
|
||||||
.instance_init = virtio_host_initfn,
|
.instance_init = virtio_host_initfn,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define QEMU_VIRTIO_INPUT_H
|
#define QEMU_VIRTIO_INPUT_H
|
||||||
|
|
||||||
#include "ui/input.h"
|
#include "ui/input.h"
|
||||||
|
#include "sysemu/vhost-user-backend.h"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/* virtio input protocol */
|
/* virtio input protocol */
|
||||||
|
@ -42,11 +43,18 @@ typedef struct virtio_input_event virtio_input_event;
|
||||||
#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
|
#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
|
||||||
OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
|
OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
|
||||||
|
|
||||||
|
#define TYPE_VHOST_USER_INPUT "vhost-user-input"
|
||||||
|
#define VHOST_USER_INPUT(obj) \
|
||||||
|
OBJECT_CHECK(VHostUserInput, (obj), TYPE_VHOST_USER_INPUT)
|
||||||
|
#define VHOST_USER_INPUT_GET_PARENT_CLASS(obj) \
|
||||||
|
OBJECT_GET_PARENT_CLASS(obj, TYPE_VHOST_USER_INPUT)
|
||||||
|
|
||||||
typedef struct VirtIOInput VirtIOInput;
|
typedef struct VirtIOInput VirtIOInput;
|
||||||
typedef struct VirtIOInputClass VirtIOInputClass;
|
typedef struct VirtIOInputClass VirtIOInputClass;
|
||||||
typedef struct VirtIOInputConfig VirtIOInputConfig;
|
typedef struct VirtIOInputConfig VirtIOInputConfig;
|
||||||
typedef struct VirtIOInputHID VirtIOInputHID;
|
typedef struct VirtIOInputHID VirtIOInputHID;
|
||||||
typedef struct VirtIOInputHost VirtIOInputHost;
|
typedef struct VirtIOInputHost VirtIOInputHost;
|
||||||
|
typedef struct VHostUserInput VHostUserInput;
|
||||||
|
|
||||||
struct VirtIOInputConfig {
|
struct VirtIOInputConfig {
|
||||||
virtio_input_config config;
|
virtio_input_config config;
|
||||||
|
@ -98,6 +106,12 @@ struct VirtIOInputHost {
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct VHostUserInput {
|
||||||
|
VirtIOInput parent_obj;
|
||||||
|
|
||||||
|
VhostUserBackend *vhost;
|
||||||
|
};
|
||||||
|
|
||||||
void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
|
void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
|
||||||
void virtio_input_init_config(VirtIOInput *vinput,
|
void virtio_input_init_config(VirtIOInput *vinput,
|
||||||
virtio_input_config *config);
|
virtio_input_config *config);
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* QEMU vhost-user backend
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Red Hat Inc
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Marc-André Lureau <marcandre.lureau@redhat.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
#ifndef QEMU_VHOST_USER_BACKEND_H
|
||||||
|
#define QEMU_VHOST_USER_BACKEND_H
|
||||||
|
|
||||||
|
#include "qom/object.h"
|
||||||
|
#include "exec/memory.h"
|
||||||
|
#include "qemu/option.h"
|
||||||
|
#include "qemu/bitmap.h"
|
||||||
|
#include "hw/virtio/vhost.h"
|
||||||
|
#include "hw/virtio/vhost-user.h"
|
||||||
|
#include "chardev/char-fe.h"
|
||||||
|
#include "io/channel.h"
|
||||||
|
|
||||||
|
#define TYPE_VHOST_USER_BACKEND "vhost-user-backend"
|
||||||
|
#define VHOST_USER_BACKEND(obj) \
|
||||||
|
OBJECT_CHECK(VhostUserBackend, (obj), TYPE_VHOST_USER_BACKEND)
|
||||||
|
#define VHOST_USER_BACKEND_GET_CLASS(obj) \
|
||||||
|
OBJECT_GET_CLASS(VhostUserBackendClass, (obj), TYPE_VHOST_USER_BACKEND)
|
||||||
|
#define VHOST_USER_BACKEND_CLASS(klass) \
|
||||||
|
OBJECT_CLASS_CHECK(VhostUserBackendClass, (klass), TYPE_VHOST_USER_BACKEND)
|
||||||
|
|
||||||
|
typedef struct VhostUserBackend VhostUserBackend;
|
||||||
|
typedef struct VhostUserBackendClass VhostUserBackendClass;
|
||||||
|
|
||||||
|
struct VhostUserBackendClass {
|
||||||
|
ObjectClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VhostUserBackend {
|
||||||
|
/* private */
|
||||||
|
Object parent;
|
||||||
|
|
||||||
|
char *chr_name;
|
||||||
|
CharBackend chr;
|
||||||
|
VhostUserState vhost_user;
|
||||||
|
struct vhost_dev dev;
|
||||||
|
VirtIODevice *vdev;
|
||||||
|
bool started;
|
||||||
|
bool completed;
|
||||||
|
};
|
||||||
|
|
||||||
|
int vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev,
|
||||||
|
unsigned nvqs, Error **errp);
|
||||||
|
void vhost_user_backend_start(VhostUserBackend *b);
|
||||||
|
void vhost_user_backend_stop(VhostUserBackend *b);
|
||||||
|
|
||||||
|
#endif
|
|
@ -970,26 +970,12 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
|
||||||
/* compatibility wrapper */
|
/* compatibility wrapper */
|
||||||
int unix_listen(const char *str, Error **errp)
|
int unix_listen(const char *str, Error **errp)
|
||||||
{
|
{
|
||||||
char *path, *optstr;
|
|
||||||
int sock, len;
|
|
||||||
UnixSocketAddress *saddr;
|
UnixSocketAddress *saddr;
|
||||||
|
int sock;
|
||||||
|
|
||||||
saddr = g_new0(UnixSocketAddress, 1);
|
saddr = g_new0(UnixSocketAddress, 1);
|
||||||
|
saddr->path = g_strdup(str);
|
||||||
optstr = strchr(str, ',');
|
|
||||||
if (optstr) {
|
|
||||||
len = optstr - str;
|
|
||||||
if (len) {
|
|
||||||
path = g_malloc(len+1);
|
|
||||||
snprintf(path, len+1, "%.*s", len, str);
|
|
||||||
saddr->path = path;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
saddr->path = g_strdup(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
sock = unix_listen_saddr(saddr, errp);
|
sock = unix_listen_saddr(saddr, errp);
|
||||||
|
|
||||||
qapi_free_UnixSocketAddress(saddr);
|
qapi_free_UnixSocketAddress(saddr);
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue