From nobody Fri May 3 09:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616571445; cv=none; d=zohomail.com; s=zohoarc; b=SCF022l6+O1Dd+1KNYo4sAqN2js0BMblae7qTQn0jhyocFFlhgqG9aqSJyNz48qbpE2NnOf/Ttn0xomFbmYPWv/EJLTrsGEuEV1PKg7Qvf/tkpyIYvlzPeAzfPI4zGGyPnDTV9yCC062uO5OiMgerxbaFDKnw24Cjbrc/kZOJS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616571445; 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=MfxZENkQg4YSG+pEA3uFpgxp+x8LxQFP/roBiw/dz8U=; b=bVjHsTB2O3kGmhWO2WCNXc3ZJD/1S/h5NkPJGfnHFGYocBD+m4s6bfFwwNjLkjv/6hNh/MFGp2NCIIEOEeWEjoKT1hjRaMfRqaqialL6NSRhPGB08LwcSh+LgsJwbMiwCXt4C5eMkQ00WXQ0HegTCDpJTez33hc/xKL1pV8RCJY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616571445624947.770676047015; Wed, 24 Mar 2021 00:37:25 -0700 (PDT) Received: from localhost ([::1]:55938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy4y-0002Ag-Cl for importer@patchew.org; Wed, 24 Mar 2021 03:37:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOy1B-0005pY-GC for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:29 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:39440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOy19-0005km-76 for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:29 -0400 Received: by mail-pj1-x1031.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so678437pjb.4 for ; Wed, 24 Mar 2021 00:33:26 -0700 (PDT) Received: from localhost ([122.172.6.13]) by smtp.gmail.com with ESMTPSA id t18sm1509041pgg.33.2021.03.24.00.33.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 00:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MfxZENkQg4YSG+pEA3uFpgxp+x8LxQFP/roBiw/dz8U=; b=H5fC8bX9B7Uy0vhdszPiWfPHOQEQky11CwHhEYd51ZbhkjqQeIcU4sq9yxxnZxl8PM h1HIE+hmhq66cyGG5J8Hqatj/4TepQUTPGa6uDSSEyBVpAa4dnoWc7K900/Fp/rqo9Ds np3QDe7+uSSqg8rpcbrkRDquAZo8ZKU23ySiU+4IdygTQLiXoHsq37iHlf1zTw5TeYnk iCDUR7R30qn0Qv8LSXRa/BEEPSI5vllf/gzmLub/zSlCsTFzklIgZCJtrdL5Y4u9SHHb Fopo7wO+uqB4AM0gL8BXwLipFKxrkK9C5z+KrTJB5w9ViJpbjBSxgg4794HqZAgwwYkr 0vDg== 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:mime-version:content-transfer-encoding; bh=MfxZENkQg4YSG+pEA3uFpgxp+x8LxQFP/roBiw/dz8U=; b=igIivHNW+l4k9KIcDqs+4bEh71LVTlLyLv83Eis3mzuBsR9EFHOFpatCV8Ql/l/3Fr zh1bO/fvFOIDChEiGxyxa/bZ+pKGaTtaBkiE4zHu0shONdAseHMUMFRDLv3+OpMQfP9k iAAGaRmeOgPUxLlZZNvduEVxERR+MVW+i3u1i62k5zHGrA9jN/JxKkBvBbtoOxy4dAuN QQNJ4NaZBeNHGpGPzA15ohfS9PiMOkx9tzBlsq6/M9n8l0dgFDtQf4k4UDWLL7XMMLq/ AjXYw5Vwfg7fav4bUwUSQpo9F/vxl2ofRi7eC+9KKRfwxu/5KE8RVuTOlkKjCvO4oPzo LLxg== X-Gm-Message-State: AOAM531XQ3AWcyDilTNF99r0iTilgv2oMJw7CnASCwULNPMeobs9Ji6a bOkStyACH5MsDS9rCkfoAJNxJdzZcT7lZA== X-Google-Smtp-Source: ABdhPJzd+G3zkzuiIakYXJkqRhfH1Bf89hCZXQgWgYdEYP3WXLB3WZqa9yx5o6y556D/Jk0tvOVlrA== X-Received: by 2002:a17:90b:410d:: with SMTP id io13mr1991483pjb.112.1616571205723; Wed, 24 Mar 2021 00:33:25 -0700 (PDT) From: Viresh Kumar To: qemu-devel@nongnu.org Subject: [PATCH 1/5] hw/virtio: add boilerplate for vhost-user-i2c device Date: Wed, 24 Mar 2021 13:03:10 +0530 Message-Id: <680d46df15a19a7ccb05f79370cb03226c23d943.1616570702.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1031; envelope-from=viresh.kumar@linaro.org; helo=mail-pj1-x1031.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , Jie Deng , Viresh Kumar , Bill Mills , Arnd Bergmann , Mike Holmes , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This creates the QEMU side of the vhost-user-i2c device which connects to the remote daemon. It is based of vhost-user-fs code. Signed-off-by: Viresh Kumar --- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-i2c.c | 286 ++++++++++++++++++++ include/hw/virtio/vhost-user-i2c.h | 37 +++ include/standard-headers/linux/virtio_ids.h | 1 + 5 files changed, 330 insertions(+) create mode 100644 hw/virtio/vhost-user-i2c.c create mode 100644 include/hw/virtio/vhost-user-i2c.h diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 0eda25c4e1bf..35ab45e2095c 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -58,3 +58,8 @@ config VIRTIO_MEM depends on LINUX depends on VIRTIO_MEM_SUPPORTED select MEM_DEVICE + +config VHOST_USER_I2C + bool + default y + depends on VIRTIO && VHOST_USER diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fbff9bc9d4de..1a0d736a0db5 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -25,6 +25,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: f= iles('vhost-user-vsock. virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c'= )) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2= c.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c new file mode 100644 index 000000000000..7b0dc24412a4 --- /dev/null +++ b/hw/virtio/vhost-user-i2c.c @@ -0,0 +1,286 @@ +/* + * Vhost-user i2c virtio device + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-i2c.h" +#include "qemu/error-report.h" +#include "standard-headers/linux/virtio_ids.h" + +static void vu_i2c_start(VirtIODevice *vdev) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&i2c->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, true= ); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + i2c->vhost_dev.acked_features =3D vdev->guest_features; + ret =3D vhost_dev_start(&i2c->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost-user-i2c: %d", -ret); + 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 =3D 0; i < i2c->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&i2c->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); +} + +static void vu_i2c_stop(VirtIODevice *vdev) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&i2c->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, fals= e); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&i2c->vhost_dev, vdev); +} + +static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (i2c->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vu_i2c_start(vdev); + } else { + vu_i2c_stop(vdev); + } +} + +static uint64_t vu_i2c_get_features(VirtIODevice *vdev, + uint64_t requested_features, Error **e= rrp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vu_i2c_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool m= ask) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + vhost_virtqueue_mask(&i2c->vhost_dev, vdev, idx, mask); +} + +static bool vu_i2c_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + return vhost_virtqueue_pending(&i2c->vhost_dev, idx); +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c) +{ + vhost_user_cleanup(&i2c->vhost_user); + virtio_delete_queue(i2c->req_vq); + g_free(i2c->vhost_dev.vqs); + virtio_cleanup(vdev); + g_free(i2c->vhost_dev.vqs); + i2c->vhost_dev.vqs =3D NULL; +} + +static int vu_i2c_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + if (i2c->connected) { + return 0; + } + i2c->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_i2c_start(vdev); + } + + return 0; +} + +static void vu_i2c_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + if (!i2c->connected) { + return; + } + i2c->connected =3D false; + + if (i2c->vhost_dev.started) { + vu_i2c_stop(vdev); + } +} + +static void vu_i2c_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vu_i2c_connect(dev) < 0) { + qemu_chr_fe_disconnect(&i2c->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vu_i2c_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vu_i2c_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(dev); + int ret; + + if (!i2c->conf.chardev.chr) { + error_setg(errp, "missing chardev"); + return; + } + + if (!vhost_user_init(&i2c->vhost_user, &i2c->conf.chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-i2c", VIRTIO_ID_I2C, 0); + + i2c->req_vq =3D virtio_add_queue(vdev, 3, vu_i2c_handle_output); + i2c->vhost_dev.nvqs =3D 1; + i2c->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, i2c->vhost_dev.n= vqs); + ret =3D vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user, + VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_dev_init() failed"); + do_vhost_user_cleanup(vdev, i2c); + } + + qemu_chr_fe_set_handlers(&i2c->conf.chardev, NULL, NULL, vu_i2c_event,= NULL, + dev, NULL, true); +} + +static void vu_i2c_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserI2C *i2c =3D VHOST_USER_I2C(dev); + + /* This will stop vhost backend if appropriate. */ + vu_i2c_set_status(vdev, 0); + + vhost_dev_cleanup(&i2c->vhost_dev); + + do_vhost_user_cleanup(vdev, i2c); +} + +static const VMStateDescription vu_i2c_vmstate =3D { + .name =3D "vhost-user-i2c", + .unmigratable =3D 1, +}; + +static Property vu_i2c_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserI2C, conf.chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_i2c_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_i2c_properties); + dc->vmsd =3D &vu_i2c_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + vdc->realize =3D vu_i2c_device_realize; + vdc->unrealize =3D vu_i2c_device_unrealize; + vdc->get_features =3D vu_i2c_get_features; + vdc->set_status =3D vu_i2c_set_status; + vdc->guest_notifier_mask =3D vu_i2c_guest_notifier_mask; + vdc->guest_notifier_pending =3D vu_i2c_guest_notifier_pending; +} + +static const TypeInfo vu_i2c_info =3D { + .name =3D TYPE_VHOST_USER_I2C, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserI2C), + .class_init =3D vu_i2c_class_init, +}; + +static void vu_i2c_register_types(void) +{ + type_register_static(&vu_i2c_info); +} + +type_init(vu_i2c_register_types) diff --git a/include/hw/virtio/vhost-user-i2c.h b/include/hw/virtio/vhost-u= ser-i2c.h new file mode 100644 index 000000000000..a5fffcb6096c --- /dev/null +++ b/include/hw/virtio/vhost-user-i2c.h @@ -0,0 +1,37 @@ +/* + * Vhost-user i2c virtio device + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_I2C_H +#define _QEMU_VHOST_USER_I2C_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_I2C "vhost-user-i2c-device" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserI2C, VHOST_USER_I2C) + +typedef struct { + CharBackend chardev; +} VHostUserI2CConf; + +struct VHostUserI2C { + /*< private >*/ + VirtIODevice parent; + VHostUserI2CConf conf; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *req_vq; + bool connected; + + /*< public >*/ +}; + +#endif /* _QEMU_VHOST_USER_I2C_H */ diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index bc1c0621f5ed..aba00c54b9cd 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -54,5 +54,6 @@ #define VIRTIO_ID_FS 26 /* virtio filesystem */ #define VIRTIO_ID_PMEM 27 /* virtio pmem */ #define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */ +#define VIRTIO_ID_I2C 34 /* virtio i2c */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ --=20 2.25.0.rc1.19.g042ed3e048af From nobody Fri May 3 09:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616571317; cv=none; d=zohomail.com; s=zohoarc; b=R71eHH5HVJBMmu8pOprEfWXr8V4rcSRw6c1T3gPId9wQZXzWynzztHLVXg+/c/OQhwjgQzymihCfscaF5AtaYe0c7Ef3ferhXVAgkBEboLmxgEIdQZZ4e3M4rA8JaFsc5vXMYq1klEnuwtC/7f1dF9ylc6EztDxw/56RMtxhc10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616571317; 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=39/+0LJ0WNF4zm8Jo7cFRlR6uT3LdZ8Gs1InHlxe1es=; b=ap1NcAwyaNwkzgeiI8hbQYcvKyM6U3DG38yx3E+kQXl/1GHavATNoieeKYOCIUtfIJOTCkawd2sNs4Ils7Wndwc8wGTMsX/QePs59VcJz/u3O3ydboa/2nltub/XQ2xLbWwT35UJ2wFubAJi4T3Ywt7P1Pib9i9h/wkZEyezm/Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616571317876414.06405886323046; Wed, 24 Mar 2021 00:35:17 -0700 (PDT) Received: from localhost ([::1]:48428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy2t-0007Rx-CV for importer@patchew.org; Wed, 24 Mar 2021 03:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOy1I-0005wm-7l for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:36 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:54883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOy1G-0005pb-Eb for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:36 -0400 Received: by mail-pj1-x102e.google.com with SMTP id w8so11281640pjf.4 for ; Wed, 24 Mar 2021 00:33:34 -0700 (PDT) Received: from localhost ([122.172.6.13]) by smtp.gmail.com with ESMTPSA id 138sm1465299pfv.192.2021.03.24.00.33.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 00:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=39/+0LJ0WNF4zm8Jo7cFRlR6uT3LdZ8Gs1InHlxe1es=; b=oLBBdxHKbJJjJIsauj4M5wU95awk/RmT1jaRxnk4rQKs90beVtQzkYooj3qJFfMLIZ I2rPkGW9hqYnzNhKTOKlIzRf+H4QdMpEhFo27QRYhz9QMmzp/6gPyV0kJP8zL0WHB6Rf +kCvjdDHdPaLdysAsgXE79YBsYeIeUabZ0QRdIyikfXHk9PgNRvrUwqSmPGYaD/wUr1G 1rrOEtzU5rJsKHcP1hJAmkXWYt0jT1aL9TdaASTM8cHHALzNLBGzJYKtOCp+FumCvYgN cV9VqiXRm6faridxgskRgxZ40wp/iC10eu9hVrEVJwgKWZUfQdNyWTZJaG/Ccq4iWxL/ LWQQ== 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:mime-version:content-transfer-encoding; bh=39/+0LJ0WNF4zm8Jo7cFRlR6uT3LdZ8Gs1InHlxe1es=; b=Hujo/IYAajagKGFsqB5wYqCiDsaliLdNmhZIKi3T1ecXsf9TMProHdwpD7qL9yDXQY t2T0BNk4t+4vfMzgoI+Nr4Tz948Oa5B/iAj3vI/uAEA+Fq21MCXgoIb67A66BjylAKG3 ViyKetx/FgABNjsdawY2u5S5HbYY4xNdiLNCi3nBWeRjjwCckT11YgcX9UFJImx0A/K+ 7kgsE/ha9jRwZCDetn8ftExl31HAp+ACzNPDoy98tP6Wg8QQbdQQIhlBuor/uRVf32GI /s3bTwRAtVvMIKruy7rOGIuNhpdrhKi3ZVoCdzSmidaQ1cnx5dW45qgrpeMH+C2lhjGm MIcQ== X-Gm-Message-State: AOAM532q9kboVM5wfIeR7PA1R4OD/1s8TpDscej0Ux5wEfifwLdERwOO yyRk4Tou9h0Mj8OA1gGbfLMRsNqVOsfKtg== X-Google-Smtp-Source: ABdhPJxeTsQ2ryCEctBiySbZEMBlxS632jipG6llBfiqdlR3u1nOdo6cD1VW5LtGnO0asBMSLwr23g== X-Received: by 2002:a17:902:54e:b029:e7:1029:8ddb with SMTP id 72-20020a170902054eb02900e710298ddbmr1589540plf.29.1616571212347; Wed, 24 Mar 2021 00:33:32 -0700 (PDT) From: Viresh Kumar To: qemu-devel@nongnu.org Subject: [PATCH 2/5] hw/virtio: add vhost-user-i2c-pci boilerplate Date: Wed, 24 Mar 2021 13:03:11 +0530 Message-Id: <9fbb332cc66aa1df562ac0dd1f54166d68671681.1616570702.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::102e; envelope-from=viresh.kumar@linaro.org; helo=mail-pj1-x102e.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , Jie Deng , Viresh Kumar , Bill Mills , Arnd Bergmann , Mike Holmes , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows is to instantiate a vhost-user-i2c device as part of a PCI bus. It is mostly boilerplate which looks pretty similar to the vhost-user-fs-pci device. Signed-off-by: Viresh Kumar Reviewed-by: Alex Benn=C3=A9e --- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-i2c-pci.c | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 hw/virtio/vhost-user-i2c-pci.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 1a0d736a0db5..bc352a600911 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -26,6 +26,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('= virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c'= )) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2= c.c')) +virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_tru= e: files('vhost-user-i2c-pci.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) diff --git a/hw/virtio/vhost-user-i2c-pci.c b/hw/virtio/vhost-user-i2c-pci.c new file mode 100644 index 000000000000..4bcfeafcb632 --- /dev/null +++ b/hw/virtio/vhost-user-i2c-pci.c @@ -0,0 +1,79 @@ +/* + * Vhost-user i2c virtio device PCI glue + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-i2c.h" +#include "virtio-pci.h" + +struct VHostUserI2CPCI { + VirtIOPCIProxy parent_obj; + VHostUserI2C vdev; +}; + +typedef struct VHostUserI2CPCI VHostUserI2CPCI; + +#define TYPE_VHOST_USER_I2C_PCI "vhost-user-i2c-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserI2CPCI, VHOST_USER_I2C_PCI, + TYPE_VHOST_USER_I2C_PCI) + +static Property vhost_user_i2c_pci_properties[] =3D { + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_i2c_pci_realize(VirtIOPCIProxy *vpci_dev, Error **e= rrp) +{ + VHostUserI2CPCI *dev =3D VHOST_USER_I2C_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 1; + } + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_i2c_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_i2c_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + device_class_set_props(dc, vhost_user_i2c_pci_properties); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_i2c_pci_instance_init(Object *obj) +{ + VHostUserI2CPCI *dev =3D VHOST_USER_I2C_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_I2C); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_i2c_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_I2C_PCI, + .non_transitional_name =3D "vhost-user-i2c-pci", + .instance_size =3D sizeof(VHostUserI2CPCI), + .instance_init =3D vhost_user_i2c_pci_instance_init, + .class_init =3D vhost_user_i2c_pci_class_init, +}; + +static void vhost_user_i2c_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_i2c_pci_info); +} + +type_init(vhost_user_i2c_pci_register); --=20 2.25.0.rc1.19.g042ed3e048af From nobody Fri May 3 09:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616571337; cv=none; d=zohomail.com; s=zohoarc; b=kQjZ2P6eq/Jg/1z17RW2hUt2uFpgZ4k363Ehkd8LFISZDzkzoOIzIov4NQJbp3veNulYVumL/xvJrQTmCs+6n59UwkNw8ArgbdbenV18oAfyNsqPZeC3AGAu/iw545uZacnlE7/oaGHch7Yc+qcPLfddWMZK3gTj3zHLLIOlyuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616571337; 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=FkW7AkazAEBGbaNzW3HHMWo7BV53/N5vo98VBaNptrc=; b=O+h/ATeYXbxtUcaPpaqwJp64LQbli6JwDA4I1ZhFNhF1aMPSYSZphYZoIsl7/5wP+lV+RoUFeGaK8b/Z1eu2rqtzEROkMtQsEudvRpYbwfLqVWkBlGCTRly8qgRyXHOUY/ZkPw446ve1Dp+shk/fo/SMYx5luJQzeIfWYVUyjIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616571337748893.000400709686; Wed, 24 Mar 2021 00:35:37 -0700 (PDT) Received: from localhost ([::1]:49136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy3E-0007lA-LE for importer@patchew.org; Wed, 24 Mar 2021 03:35:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOy1M-000648-Li for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:40 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:35344) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOy1J-0005rQ-Fk for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:40 -0400 Received: by mail-pf1-x432.google.com with SMTP id j25so16692421pfe.2 for ; Wed, 24 Mar 2021 00:33:37 -0700 (PDT) Received: from localhost ([122.172.6.13]) by smtp.gmail.com with ESMTPSA id y24sm1382238pfn.213.2021.03.24.00.33.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 00:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FkW7AkazAEBGbaNzW3HHMWo7BV53/N5vo98VBaNptrc=; b=TdbjEPRGwW22wIlT1JZuRJ5R7H/c4DldifZhyDy01sk6A16+yWzEJ2ktGl4Q0jyVoj c9B6z+CWNkmAAI3Vep69ia7OA7EhQ3yJ9hHHbvst2tXr/5ggbcmq6O400pjAed7CruQL B5z7a11QbbsbKHkdXdYZU+80ZuAqcSITWSZd7wEucjeEfWdPTmOEZETR4Mtpnr+0IexC cItKny1XeNVgZV6qriZ5j9hAskLicHh+mHbwjfUIq337NHisqneujbAglOjFbmF+Kg9S 5LCOtdmhjnmdSKpG+h3Qrq6hWFvSbPKZXHF4j6T2sOqCog5AFe2vH1nfcwvysEMU6nI5 oCeQ== 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:mime-version:content-transfer-encoding; bh=FkW7AkazAEBGbaNzW3HHMWo7BV53/N5vo98VBaNptrc=; b=K0RZWCJU1Hi3flWw8Mu0c60UcLB5akdieJaowV5l+4tH5MbY9psHags/iwdaq19/Wh 6yNcDiI5Z5wuAG5RHMS2X/YLQqXqUvawDu8PJo/bVkWoWEvBCXj7iu1xF4MEob+hqlvh XtzltiD/XELQxBTJ/VE8ZDdO7EGs3tGmnBiIopECM/mHqM1cMS0B3bc5gE/XToKPkPrY h0MLJ1LeVhFZQalbrosOoV+lArHR/urIc4HCTcsFjE74DEKZlrvkUxsYwaCjS7CXMuGg /pxi48hBAA4R+oLqpx7tu+OpAsNxPQIummKHs37Qw/guLNVsxko7EytwVbM05dRlqAei 29Ig== X-Gm-Message-State: AOAM530YrQBr2VtdfqnPSO2bOUMMeS0TlIuOokCDlP+LLs0o7hla7TSo tgvXygp9V40NJdTlGl2P2t1sFrVMQNxAEw== X-Google-Smtp-Source: ABdhPJwZh+TZKjRL9uApt1C05gtwSR4y2FQSEHd7fTKFCBGCSXlehIcny8MgadY/pc+aMdNdpUD/0A== X-Received: by 2002:a63:fa52:: with SMTP id g18mr1895799pgk.193.1616571215857; Wed, 24 Mar 2021 00:33:35 -0700 (PDT) From: Viresh Kumar To: qemu-devel@nongnu.org Subject: [PATCH 3/5] tools/vhost-user-i2c: Add backend driver Date: Wed, 24 Mar 2021 13:03:12 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::432; envelope-from=viresh.kumar@linaro.org; helo=mail-pf1-x432.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , Jie Deng , Viresh Kumar , Bill Mills , Arnd Bergmann , Mike Holmes , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds the vhost-user backend driver to support virtio based I2C devices. vhost-user-i2c --help Signed-off-by: Viresh Kumar --- hw/virtio/vhost-user-i2c.c | 2 +- tools/meson.build | 8 + tools/vhost-user-i2c/50-qemu-i2c.json.in | 5 + tools/vhost-user-i2c/main.c | 652 +++++++++++++++++++++++ tools/vhost-user-i2c/meson.build | 10 + 5 files changed, 676 insertions(+), 1 deletion(-) create mode 100644 tools/vhost-user-i2c/50-qemu-i2c.json.in create mode 100644 tools/vhost-user-i2c/main.c create mode 100644 tools/vhost-user-i2c/meson.build diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 7b0dc24412a4..c67c18ca00fc 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -218,7 +218,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Err= or **errp) =20 virtio_init(vdev, "vhost-user-i2c", VIRTIO_ID_I2C, 0); =20 - i2c->req_vq =3D virtio_add_queue(vdev, 3, vu_i2c_handle_output); + i2c->req_vq =3D virtio_add_queue(vdev, 4, vu_i2c_handle_output); i2c->vhost_dev.nvqs =3D 1; i2c->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, i2c->vhost_dev.n= vqs); ret =3D vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user, diff --git a/tools/meson.build b/tools/meson.build index 3e5a0abfa29f..8271e110978b 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -24,3 +24,11 @@ endif if have_virtiofsd subdir('virtiofsd') endif + +have_virtioi2c=3D (have_system and + have_tools and + 'CONFIG_LINUX' in config_host) + +if have_virtioi2c + subdir('vhost-user-i2c') +endif diff --git a/tools/vhost-user-i2c/50-qemu-i2c.json.in b/tools/vhost-user-i2= c/50-qemu-i2c.json.in new file mode 100644 index 000000000000..dafd1337fa9c --- /dev/null +++ b/tools/vhost-user-i2c/50-qemu-i2c.json.in @@ -0,0 +1,5 @@ +{ + "description": "QEMU vhost-user-i2c", + "type": "bridge", + "binary": "@libexecdir@/vhost-user-i2c" +} diff --git a/tools/vhost-user-i2c/main.c b/tools/vhost-user-i2c/main.c new file mode 100644 index 000000000000..20942aeb189a --- /dev/null +++ b/tools/vhost-user-i2c/main.c @@ -0,0 +1,652 @@ +/* + * VIRTIO I2C Emulation via vhost-user + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#define G_LOG_DOMAIN "vhost-user-i2c" +#define G_LOG_USE_STRUCTURED 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/cutils.h" +#include "subprojects/libvhost-user/libvhost-user-glib.h" +#include "subprojects/libvhost-user/libvhost-user.h" + +/* Definitions from virtio-i2c specifications */ +#define VHOST_USER_I2C_MAX_QUEUES 1 + +/* Status */ +#define VIRTIO_I2C_MSG_OK 0 +#define VIRTIO_I2C_MSG_ERR 1 + +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the requests= */ +#define VIRTIO_I2C_FLAGS_FAIL_NEXT 0x00000001 + +/** + * struct virtio_i2c_out_hdr - the virtio I2C message OUT header + * @addr: the controlled device's address + * @padding: used to pad to full dword + * @flags: used for feature extensibility + */ +struct virtio_i2c_out_hdr { + uint16_t addr; + uint16_t padding; + uint32_t flags; +} __attribute__((packed)); + +/** + * struct virtio_i2c_in_hdr - the virtio I2C message IN header + * @status: the processing result from the backend + */ +struct virtio_i2c_in_hdr { + uint8_t status; +} __attribute__((packed)); + +/* vhost-user-i2c definitions */ + +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type *) 0)->member) *__mptr =3D (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member));}) +#endif + +#define MAX_I2C_VDEV (1 << 7) +#define MAX_I2C_ADAPTER 16 + +typedef struct { + int32_t fd; + int32_t bus; + bool clients[MAX_I2C_VDEV]; +} VI2cAdapter; + +typedef struct { + VugDev dev; + GMainLoop *loop; + VI2cAdapter *adapter[MAX_I2C_ADAPTER]; + uint16_t adapter_map[MAX_I2C_VDEV]; + uint32_t adapter_num; +} VuI2c; + +static gboolean print_cap, verbose; +static gchar *socket_path, *device_list; +static gint socket_fd =3D -1; + +static GOptionEntry options[] =3D { + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &socket_path, "Locatio= n of vhost-user Unix domain socket, incompatible with --fd", "PATH" }, + { "fd", 'f', 0, G_OPTION_ARG_INT, &socket_fd, "Specify the file-descri= ptor of the backend, incompatible with --socket-path", "FD" }, + { "device-list", 'l', 0, G_OPTION_ARG_STRING, &device_list, "List of i= 2c-dev bus and attached devices", "I2C Devices" }, + { "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &print_cap, "Output= to stdout the backend capabilities in JSON format and exit", NULL}, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be more verbose in = output", NULL}, + { NULL } +}; + + +/* I2c helpers */ +static void fmt_bytes(GString *s, uint8_t *bytes, int len) +{ + int32_t i; + for (i =3D 0; i < len; i++) { + if (i && i % 16 =3D=3D 0) { + g_string_append_c(s, '\n'); + } + g_string_append_printf(s, "%x ", bytes[i]); + } +} + +static void vi2c_dump_msg(struct i2c_msg *msg) +{ + g_autoptr(GString) s =3D g_string_new("\nI2c request: "); + + g_string_append_printf(s, "addr: %x\n", msg->addr); + g_string_append_printf(s, "transfer len: %x\n", msg->len); + + g_string_append_printf(s, "%s: ", msg->flags & I2C_M_RD ? "Data read" : + "Data Writte= n"); + fmt_bytes(s, (uint8_t *)msg->buf, msg->len); + g_string_append_printf(s, "\n"); + + g_debug("%s: %s", __func__, s->str); +} + +static int vi2c_map_adapters(VuI2c *i2c) +{ + VI2cAdapter *adapter; + int32_t i, client_addr; + + /* + * Flatten the map for client address and adapter to the array: + * + * adapter_map[MAX_I2C_VDEV]: + * + * Adapter | adapter2 | none | adapter1 | adapter3 | none | no= ne| (val) + * |----------|-------|----------|----------|------|---= --| + * Slave Address | addr 1 | none | addr 2 | addr 3 | none | no= ne| (idx) + * |<-----------------------MAX_I2C_VDEV---------------= ->| + */ + for (i =3D 0; i < i2c->adapter_num; i++) { + adapter =3D i2c->adapter[i]; + + for (client_addr =3D 0; client_addr < MAX_I2C_VDEV; client_addr++)= { + if (adapter->clients[client_addr]) { + if (i2c->adapter_map[client_addr]) { + g_printerr("client addr %x repeated, not supported!\n", + client_addr); + return -1; + } + + /* The array is initialized to 0, + 1 for index */ + i2c->adapter_map[client_addr] =3D i + 1; + if (verbose) { + g_print("client: 0x%x -> i2c adapter: %d\n", client_ad= dr, + adapter->bus); + } + } + } + } + return 0; +} + +static VI2cAdapter *vi2c_find_adapter(VuI2c *i2c, uint16_t addr) +{ + int32_t idx; + + if (addr < MAX_I2C_VDEV && ((idx =3D i2c->adapter_map[addr]) !=3D 0)) { + return i2c->adapter[idx - 1]; + } + + return NULL; +} + +static bool vi2c_client_access_ok(VI2cAdapter *adapter, uint16_t addr) +{ + if (ioctl(adapter->fd, I2C_SLAVE, addr) < 0) { + if (errno =3D=3D EBUSY) { + g_printerr("client device %x is busy!\n", addr); + } else { + g_printerr("client device %d does not exist!\n", addr); + } + return false; + } + return true; +} + +static void vi2c_remove_adapters(VuI2c *i2c) +{ + VI2cAdapter *adapter; + int32_t i; + + for (i =3D 0; i < i2c->adapter_num; i++) { + adapter =3D i2c->adapter[i]; + if (!adapter) { + break; + } + + if (adapter->fd > 0) { + close(adapter->fd); + } + + g_free(adapter); + i2c->adapter[i] =3D NULL; + } +} + +static VI2cAdapter *vi2c_create_adapter(int32_t bus, uint16_t client_addr[= ], + int32_t n_client) +{ + VI2cAdapter *adapter; + char path[20]; + int32_t fd, i; + + if (bus < 0) + return NULL; + + adapter =3D g_malloc0(sizeof(*adapter)); + if (!adapter) { + g_printerr("failed to alloc adapter"); + return NULL; + } + + snprintf(path, sizeof(path), "/dev/i2c-%d", bus); + path[sizeof(path) - 1] =3D '\0'; + + fd =3D open(path, O_RDWR); + if (fd < 0) { + g_printerr("virtio_i2c: failed to open %s\n", path); + goto fail; + } + + adapter->fd =3D fd; + adapter->bus =3D bus; + + for (i =3D 0; i < n_client; i++) { + if (client_addr[i]) { + if (!vi2c_client_access_ok(adapter, client_addr[i])) { + goto fail; + } + + if (adapter->clients[client_addr[i]]) { + g_printerr("client addr 0x%x repeat, not allowed.\n", clie= nt_addr[i]); + goto fail; + } + + adapter->clients[client_addr[i]] =3D true; + if (verbose) { + g_print("Added client 0x%x to bus %u\n", client_addr[i], b= us); + } + } + } + return adapter; + +fail: + g_free(adapter); + return NULL; +} + +/* + * Virtio I2C device list format. + * + * :[:], + * [:[:]] + * + * bus (dec): adatper bus number. + * e.g. 2 for /dev/i2c-2 + * client_addr (hex): address for client device + * e.g. 0x1C or 1C + * + * Example: --device-list=3D"2:0x1c:0x20,3:0x10:0x2c" + * + * Note: client address can not repeat. + */ +static int vi2c_parse(VuI2c *i2c) +{ + uint16_t client_addr[MAX_I2C_VDEV]; + int32_t n_adapter =3D 0, n_client; + int64_t addr, bus; + const char *cp, *t; + + while (device_list) { + /* Read :[:] entries one by one */ + cp =3D strsep(&device_list, ","); + + if (!cp || *cp =3D=3D'\0') { + break; + } + + if (n_adapter =3D=3D MAX_I2C_ADAPTER) { + g_printerr("too many adapter (%d), only support %d \n", n_adap= ter, + MAX_I2C_ADAPTER); + goto out; + } + + if (qemu_strtol(cp, &t, 10, &bus) || bus < 0) { + g_printerr("Invalid bus number %s\n", cp); + goto out; + } + + cp =3D t; + n_client =3D 0; + + /* Parse clients [:] entries one by one = */ + while (cp !=3D NULL && *cp !=3D'\0') { + if (*cp =3D=3D ':') + cp++; + + if (n_client =3D=3D MAX_I2C_VDEV) { + g_printerr("too many devices (%d), only support %d \n", + n_client, MAX_I2C_VDEV); + goto out; + } + + if (qemu_strtol(cp, &t, 16, &addr) || addr < 0 || addr > MAX_I= 2C_VDEV) { + g_printerr("Invalid address %s : %lx\n", cp, addr); + goto out; + } + + client_addr[n_client++] =3D addr; + cp =3D t; + if (verbose) { + g_print("i2c adapter %ld:0x%lx\n", bus, addr); + } + } + + i2c->adapter[n_adapter] =3D vi2c_create_adapter(bus, client_addr, = n_client); + if (!i2c->adapter[n_adapter]) + goto out; + n_adapter++; + } + + if (!n_adapter) { + g_printerr("Failed to add any adapters\n"); + return -1; + } + + i2c->adapter_num =3D n_adapter; + + if (!vi2c_map_adapters(i2c)) { + return 0; + } + +out: + vi2c_remove_adapters(i2c); + return -1; +} + +static uint8_t vi2c_xfer(VuDev *dev, struct i2c_msg *msg) +{ + VuI2c *i2c =3D container_of(dev, VuI2c, dev.parent); + struct i2c_rdwr_ioctl_data data; + VI2cAdapter *adapter; + + adapter =3D vi2c_find_adapter(i2c, msg->addr); + if (!adapter) { + g_printerr("Failed to find adapter for address: %x\n", msg->addr); + return VIRTIO_I2C_MSG_ERR; + } + + data.nmsgs =3D 1; + data.msgs =3D msg; + + if (ioctl(adapter->fd, I2C_RDWR, &data) < 0) { + g_printerr("Failed to transfer data to address %x : %d\n", msg->ad= dr, errno); + return VIRTIO_I2C_MSG_ERR; + } + + if (verbose) { + vi2c_dump_msg(msg); + } + + return VIRTIO_I2C_MSG_OK; +} + + +/* Virtio helpers */ +static uint64_t vi2c_get_features(VuDev *dev) +{ + if (verbose) { + g_info("%s: replying", __func__); + } + return 0; +} + +static void vi2c_set_features(VuDev *dev, uint64_t features) +{ + if (verbose && features) { + g_autoptr(GString) s =3D g_string_new("Requested un-handled featur= e"); + g_string_append_printf(s, " 0x%" PRIx64 "", features); + g_info("%s: %s", __func__, s->str); + } +} + +static void vi2c_handle_ctrl(VuDev *dev, int qidx) +{ + VuVirtq *vq =3D vu_get_queue(dev, qidx); + struct i2c_msg msg; + struct virtio_i2c_out_hdr *out_hdr; + struct virtio_i2c_in_hdr *in_hdr; + bool fail_next =3D false; + size_t len, in_hdr_len; + + for (;;) { + VuVirtqElement *elem; + + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + if (!elem) { + break; + } + + g_debug("%s: got queue (in %d, out %d)", __func__, elem->in_num, + elem->out_num); + + /* Validate size of out header */ + if (elem->out_sg[0].iov_len !=3D sizeof(*out_hdr)) { + g_warning("%s: Invalid out hdr %zu : %zu\n", __func__, + elem->out_sg[0].iov_len, sizeof(*out_hdr)); + continue; + } + + out_hdr =3D elem->out_sg[0].iov_base; + + /* Bit 0 is reserved in virtio spec */ + msg.addr =3D out_hdr->addr >> 1; + + /* Read Operation */ + if (elem->out_num =3D=3D 1 && elem->in_num =3D=3D 2) { + len =3D elem->in_sg[0].iov_len; + if (!len) { + g_warning("%s: Read buffer length can't be zero\n", __func= __); + continue; + } + + msg.buf =3D elem->in_sg[0].iov_base; + msg.flags =3D I2C_M_RD; + msg.len =3D len; + + in_hdr =3D elem->in_sg[1].iov_base; + in_hdr_len =3D elem->in_sg[1].iov_len; + } else if (elem->out_num =3D=3D 2 && elem->in_num =3D=3D 1) { + /* Write Operation */ + len =3D elem->out_sg[1].iov_len; + if (!len) { + g_warning("%s: Write buffer length can't be zero\n", __fun= c__); + continue; + } + + msg.buf =3D elem->out_sg[1].iov_base; + msg.flags =3D 0; + msg.len =3D len; + + in_hdr =3D elem->in_sg[0].iov_base; + in_hdr_len =3D elem->in_sg[0].iov_len; + len =3D 0; + } else { + g_warning("%s: Transfer type not supported (in %d, out %d)\n", + __func__, elem->in_num, elem->out_num); + continue; + } + + /* Validate size of in header */ + if (in_hdr_len !=3D sizeof(*in_hdr)) { + g_warning("%s: Invalid in hdr %zu : %zu\n", __func__, in_hdr_l= en, + sizeof(*in_hdr)); + continue; + } + + in_hdr->status =3D fail_next ? VIRTIO_I2C_MSG_ERR : vi2c_xfer(dev,= &msg); + if (in_hdr->status =3D=3D VIRTIO_I2C_MSG_ERR) { + /* We need to fail remaining transfers as well */ + fail_next =3D out_hdr->flags & VIRTIO_I2C_FLAGS_FAIL_NEXT; + } + + vu_queue_push(dev, vq, elem, len + sizeof(*in_hdr)); + } + + vu_queue_notify(dev, vq); +} + +static void +vi2c_queue_set_started(VuDev *dev, int qidx, bool started) +{ + VuVirtq *vq =3D vu_get_queue(dev, qidx); + + g_debug("queue started %d:%d\n", qidx, started); + + if (!qidx) { + vu_set_queue_handler(dev, vq, started ? vi2c_handle_ctrl : NULL); + } +} + +/* + * vi2c_process_msg: process messages of vhost-user interface + * + * Any that are not handled here are processed by the libvhost library + * itself. + */ +static int vi2c_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) +{ + VuI2c *i2c =3D container_of(dev, VuI2c, dev.parent); + + if (msg->request =3D=3D VHOST_USER_NONE) { + g_main_loop_quit(i2c->loop); + return 1; + } + + return 0; +} + +static const VuDevIface vuiface =3D { + .set_features =3D vi2c_set_features, + .get_features =3D vi2c_get_features, + .queue_set_started =3D vi2c_queue_set_started, + .process_msg =3D vi2c_process_msg, +}; + +static gboolean hangup(gpointer user_data) +{ + GMainLoop *loop =3D (GMainLoop *) user_data; + g_info("%s: caught hangup/quit signal, quitting main loop", __func__); + g_main_loop_quit(loop); + return true; +} + +static void vi2c_panic(VuDev *dev, const char *msg) +{ + g_critical("%s\n", msg); + exit(EXIT_FAILURE); +} + +/* Print vhost-user.json backend program capabilities */ +static void print_capabilities(void) +{ + printf("{\n"); + printf(" \"type\": \"i2c\"\n"); + printf(" \"device-list\"\n"); + printf("}\n"); +} + +static void vi2c_destroy(VuI2c *i2c) +{ + vi2c_remove_adapters(i2c); + vug_deinit(&i2c->dev); + if (socket_path) { + unlink(socket_path); + } +} + +int main(int argc, char *argv[]) +{ + GError *error =3D NULL; + GOptionContext *context; + g_autoptr(GSocket) socket =3D NULL; + VuI2c i2c =3D {0}; + + context =3D g_option_context_new("vhost-user emulation of I2C device"); + g_option_context_add_main_entries(context, options, "vhost-user-i2c"); + if (!g_option_context_parse(context, &argc, &argv, &error)) + { + g_printerr("option parsing failed: %s\n", error->message); + exit(1); + } + + if (print_cap) { + print_capabilities(); + exit(0); + } + + if (!socket_path && socket_fd < 0) { + g_printerr("Please specify either --fd or --socket-path\n"); + exit(EXIT_FAILURE); + } + + if (verbose) { + g_log_set_handler(NULL, G_LOG_LEVEL_MASK, g_log_default_handler, N= ULL); + g_setenv("G_MESSAGES_DEBUG", "all", true); + } else { + g_log_set_handler(NULL, + G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_L= OG_LEVEL_ERROR, + g_log_default_handler, NULL); + } + + /* + * Now create a vhost-user socket that we will receive messages + * on. Once we have our handler set up we can enter the glib main + * loop. + */ + if (socket_path) { + g_autoptr(GSocketAddress) addr =3D g_unix_socket_address_new(socke= t_path); + g_autoptr(GSocket) bind_socket =3D g_socket_new(G_SOCKET_FAMILY_UN= IX, G_SOCKET_TYPE_STREAM, + G_SOCKET_PROTOCOL_DE= FAULT, &error); + + if (!g_socket_bind(bind_socket, addr, false, &error)) { + g_printerr("Failed to bind to socket at %s (%s).\n", + socket_path, error->message); + exit(EXIT_FAILURE); + } + if (!g_socket_listen(bind_socket, &error)) { + g_printerr("Failed to listen on socket %s (%s).\n", + socket_path, error->message); + } + g_message("awaiting connection to %s", socket_path); + socket =3D g_socket_accept(bind_socket, NULL, &error); + if (!socket) { + g_printerr("Failed to accept on socket %s (%s).\n", + socket_path, error->message); + } + } else { + socket =3D g_socket_new_from_fd(socket_fd, &error); + if (!socket) { + g_printerr("Failed to connect to FD %d (%s).\n", + socket_fd, error->message); + exit(EXIT_FAILURE); + } + } + + if (vi2c_parse(&i2c)) { + exit(EXIT_FAILURE); + } + + /* + * Create the main loop first so all the various sources can be + * added. As well as catching signals we need to ensure vug_init + * can add it's GSource watches. + */ + + i2c.loop =3D g_main_loop_new(NULL, FALSE); + /* catch exit signals */ + g_unix_signal_add(SIGHUP, hangup, i2c.loop); + g_unix_signal_add(SIGINT, hangup, i2c.loop); + + if (!vug_init(&i2c.dev, VHOST_USER_I2C_MAX_QUEUES, g_socket_get_fd(soc= ket), + vi2c_panic, &vuiface)) { + g_printerr("Failed to initialize libvhost-user-glib.\n"); + exit(EXIT_FAILURE); + } + + + g_message("entering main loop, awaiting messages"); + g_main_loop_run(i2c.loop); + g_message("finished main loop, cleaning up"); + + g_main_loop_unref(i2c.loop); + vi2c_destroy(&i2c); +} diff --git a/tools/vhost-user-i2c/meson.build b/tools/vhost-user-i2c/meson.= build new file mode 100644 index 000000000000..f71e9fec7df6 --- /dev/null +++ b/tools/vhost-user-i2c/meson.build @@ -0,0 +1,10 @@ +executable('vhost-user-i2c', files( + 'main.c'), + dependencies: [qemuutil, glib, gio], + install: true, + install_dir: get_option('libexecdir')) + +configure_file(input: '50-qemu-i2c.json.in', + output: '50-qemu-i2c.json', + configuration: config_host, + install_dir: qemu_datadir / 'vhost-user') --=20 2.25.0.rc1.19.g042ed3e048af From nobody Fri May 3 09:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616571539; cv=none; d=zohomail.com; s=zohoarc; b=WqOm4DfJR/nqfi9hwFV+qCvhgg+RSStPQoPVsQt6k1QahZX1TrdcMYNUluzsUD5Jsa41fuZfiAo9svmhTgLTfIdc19k1i/eAgRZ/uxvZSauaaYMknheCV/Jm4PHZLog5hu4hppZL9qsLMnAt36aG5yogH/hD9XYPA0jhc5oulf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616571539; 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=3e5/TJsEm417t8ZisLCen2L7jNFH78ByxNrkmf3geT4=; b=EWBEnehtjPydcuSIhbu6IAkKSxIF9sw++S9YfgiEGypYY4ceA8V8kN0YX7I1zkpMcV3vzByaA7VcxaCz61klVE8AqiRCL0MSNcs+iMUBiNA9YdA3CIuRfaIGXD07NF9h9t1bfT9G3sEZ0WNDhuUDCt0pojWye5Lt9YVqNP+NDes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616571539910920.6599871558163; Wed, 24 Mar 2021 00:38:59 -0700 (PDT) Received: from localhost ([::1]:34120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy6U-0004ld-Ux for importer@patchew.org; Wed, 24 Mar 2021 03:38:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOy1R-0006EG-Ha for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:45 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:35732) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOy1P-0005vp-LV for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:45 -0400 Received: by mail-pl1-x62f.google.com with SMTP id e14so7456693plj.2 for ; Wed, 24 Mar 2021 00:33:43 -0700 (PDT) Received: from localhost ([122.172.6.13]) by smtp.gmail.com with ESMTPSA id j20sm5232054pji.3.2021.03.24.00.33.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 00:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3e5/TJsEm417t8ZisLCen2L7jNFH78ByxNrkmf3geT4=; b=tGVL8kCnx8Ik7KlFLnQsz71O2Q9CYB7I+vq9w9SL+cvGyWB3L0fW+m/Yx7LEUESWzr qXxu0NPXzpSoGyHLtgsZIpH0lOszLrxgUln3bFTutnhQ8ygr3qGCQSHhfHPKa212YJRc O1Qbtnb0A4495slzyfGNxDDzIxhmMNCCQzu8uqUUW3wE+LCT3JSnBV4XoDcx2LUfJ4uE V1TEAhjE3NQmuYYN4+CiAP63u0nEyN3JZbgawYT9ojrMSRKwXlmxiahjNPjX81BfTglX puHW01iR+VeE3op2cnPtVkn7HxelHOExHMVLMhCniIkeHrHjiOTo0yPme9rlQL0uDk9D oHVg== 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:mime-version:content-transfer-encoding; bh=3e5/TJsEm417t8ZisLCen2L7jNFH78ByxNrkmf3geT4=; b=YjQIWqvYk/aXXbA8GPIs98a/qlVF83ypZy+XdUHAyg5o94XbpcEh36hM7HnqVWzmdZ dkkr+5sMy/EAH3MF0TJ7UDFCi0LWoDKlKLKU1B2O5xMazWd5ZD/kXxt6Igs9g/SFRVhQ daodC83OARM9H1ws3100t3VB6cDDdzfy/GIX5J1ex4umb6BkHCbSJyKbDzf96s+6hEfa ZrTMPRkqCBD1z/fO+74mnQUkw1NYJj2Zbn4FWppk9iTSQKe7J1N9VwHxb52k4Wtc5N8B 1WTHExrx1wQu3uToZksGImEoOsr/+itVf4paoTQosjCCcZONV2EK5QoQPGoWnEuuFWii vu0Q== X-Gm-Message-State: AOAM532JIqJJL/wXXDsEO+4CRqoPA2teTGW1otZImbrXleHb7t2gO1XM lwxhvoJAtb3vP/qMsnamqlol+HryR5plmw== X-Google-Smtp-Source: ABdhPJw2ouRivK6PdxVH+Fasz0mBybCz1SxG0zytBqCwDZLhZRiTl4O3tAt9aYVjtXzpCRWsciY1Gw== X-Received: by 2002:a17:90a:f2d5:: with SMTP id gt21mr2219338pjb.197.1616571222446; Wed, 24 Mar 2021 00:33:42 -0700 (PDT) From: Viresh Kumar To: qemu-devel@nongnu.org Subject: [PATCH 4/5] docs: add a man page for vhost-user-i2c Date: Wed, 24 Mar 2021 13:03:13 +0530 Message-Id: <915600fab4a1ed54d4cdb54346406dff5e3032d6.1616570702.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62f; envelope-from=viresh.kumar@linaro.org; helo=mail-pl1-x62f.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , Jie Deng , Viresh Kumar , Bill Mills , Arnd Bergmann , Mike Holmes , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Basic usage and example invocation. Signed-off-by: Viresh Kumar --- docs/tools/index.rst | 1 + docs/tools/vhost-user-i2c.rst | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 docs/tools/vhost-user-i2c.rst diff --git a/docs/tools/index.rst b/docs/tools/index.rst index 3a5829c17a54..af2519406ddf 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -17,3 +17,4 @@ QEMU Tools Guide qemu-trace-stap virtfs-proxy-helper virtiofsd + vhost-user-i2c diff --git a/docs/tools/vhost-user-i2c.rst b/docs/tools/vhost-user-i2c.rst new file mode 100644 index 000000000000..8471b39d8b1d --- /dev/null +++ b/docs/tools/vhost-user-i2c.rst @@ -0,0 +1,75 @@ +QEMU vhost-user-i2c - I2C emulation backend +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Synopsis +-------- + +**vhost-user-i2c** [*OPTIONS*] + +Description +----------- + +This program is a vhost-user backend that emulates a VirtIO I2C bus. +This program takes the layout of the i2c bus and its devices on the host +OS and then talks to them via the /dev/i2c-X interface when a request +comes from the guest OS for an I2C device. + +This program is designed to work with QEMU's ``-device +vhost-user-i2c-pci`` but should work with any virtual machine monitor +(VMM) that supports vhost-user. See the Examples section below. + +Options +------- + +.. program:: vhost-user-i2c + +.. option:: -h, --help + + Print help. + +.. option:: -v, --verbose + + Increase verbosity of output + +.. option:: -s, --socket-path=3DPATH + + Listen on vhost-user UNIX domain socket at PATH. Incompatible with --fd. + +.. option:: -f, --fd=3DFDNUM + + Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. + The file descriptor must already be listening for connections. + Incompatible with --socket-path. + +.. option:: -l, --device-list=3DI2C-DEVICES + + I2c device list at the host OS in the format: + :[:],[:[:]] + + Example: --device-list "2:1c:20,3:10:2c" + + Here, + bus (decimal): adatper bus number. e.g. 2 for /dev/i2c-2, 3 for /dev= /i2c-3. + client_addr (hex): address for client device. e.g. 0x1C, 0x20, 0x10,= 0x2C. + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-user-i2c --socket-path=3Dvi2c.sock --device-list 0:20 + +The QEMU invocation needs to create a chardev socket the device can +use to communicate as well as share the guests memory over a memfd. + +:: + + host# qemu-system \ + -chardev socket,path=3Dvi2c.sock,id=3Dvi2c \ + -device vhost-user-i2c-pci,chardev=3Dvi2c,id=3Di2c \ + -m 4096 \ + -object memory-backend-file,id=3Dmem,size=3D4G,mem-path=3D/dev/shm,s= hare=3Don \ + -numa node,memdev=3Dmem \ + ... --=20 2.25.0.rc1.19.g042ed3e048af From nobody Fri May 3 09:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616571342; cv=none; d=zohomail.com; s=zohoarc; b=dxeeFmHwlBZfWxp/jGNuVWii7NNeMLaBUZTDtKy3zSqOqnVZ+zvJT2zoM+aGciS3vIqaFhjF+OWIiAp1V5rZj8v1SQVGS94GtJolKRhwHrRp7v0/rTjMTDG5HkKYlqPJxdEv9XU9iIqcSXVqIqjFBNxCaj7JroJHCa73HVTQh0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616571342; 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=LK0GmNGUPbPNBXEhJlF2QfVGhEIlr16Wq8o08kNLbaw=; b=KU7xJfGNvsUo1PBD5zLKyuIlbi8s/Q3sKOmFBaUYjT3rkFSeVxbU+qDHPZJ4jatexwt8CBPHKHKC5UUSu4JwwtkCUu3m+uX0wuh1bogR5lGWatMa0cBlLhhPhQLNMOglZ35CuGwx+lis8pMhfRFbr+GW8bH3rnki9Up/8YNGsLQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616571342257530.322176070005; Wed, 24 Mar 2021 00:35:42 -0700 (PDT) Received: from localhost ([::1]:49680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy3J-0007z7-7I for importer@patchew.org; Wed, 24 Mar 2021 03:35:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOy1T-0006J6-Tf for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:48 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:37446) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOy1S-0005ww-Dt for qemu-devel@nongnu.org; Wed, 24 Mar 2021 03:33:47 -0400 Received: by mail-pl1-x62d.google.com with SMTP id h20so7463542plr.4 for ; Wed, 24 Mar 2021 00:33:45 -0700 (PDT) Received: from localhost ([122.172.6.13]) by smtp.gmail.com with ESMTPSA id v2sm1368046pjg.34.2021.03.24.00.33.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 00:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LK0GmNGUPbPNBXEhJlF2QfVGhEIlr16Wq8o08kNLbaw=; b=mvWiGvGNwRzTq49Yn1sv2ztMWAq4quUNViMB/4rL9g6A7L73e/KQegnLq2q82nVEs4 LyS0RA6WKfnUgVwdsaeOfZbNudWO96A2ypF5ZMG+seCQxYFAT6z2l1HRO2UQN/iRTCdt jt/izgSmc/A+4XttSHDUj8yFoeuQ/Pk5XI2U2cuAS7ZdTosgvEdHrElw/uZOnw6Ab6O2 CxBmz/4DmQt6Ni69ytOLP1k3SdJsgKf+osyafeTg0fJ+8fYv8g/la/Qz6VA7d68ApyVP EVGVjYsr5j3rkmNAgT9usTFpgswdJGIV16HMizHggKqJNtD6RyZfw0Zrn3JTfVQrZvxp cgAg== 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:mime-version:content-transfer-encoding; bh=LK0GmNGUPbPNBXEhJlF2QfVGhEIlr16Wq8o08kNLbaw=; b=ljlhNjDOH6j5GQUfN3H5m53b0PIgiseBxXw8HyNbv0xwzdROsyOtXfNJ6ihKDLj+xu /02X9jMZ1q+y7H7cB/zbmg+X2oYCa67gXwiG9mkqiRbWXmLDKUWyqUI+TOCb5+Xn44pK JdJCeBUdkX3yQ7m46IUUAVyrWYDxrpz8HFa8x+g7IRcXllV3Rz2AavdBhjqaNAUt3Y91 G34hN0KxdLPXb6EUhBt2CHArU4FegkLsJBFCv0AQk0bEAZ9aHf9tWcuCrOWm0iVzP6OT /moQ9uKOFpfciNRFw499ntDI9qOvBpBxjLMcqif86KSxlHhvgBoK1TG7iNyQftFAXXaV T27Q== X-Gm-Message-State: AOAM531tmZG1Vy8qkapkhVMeEgqPriypvgW78MRitkaEJqnbUQ32dicj MuteDyq5naQOWNhJHDbaMJI+Blmj4uBYkQ== X-Google-Smtp-Source: ABdhPJw12sFx1s5fFTnN69zCx7U6CzU9p9cHwEhjXRUgXFdpgw/GPQXE40IuJX4k1RoknKalfcG37A== X-Received: by 2002:a17:90a:b293:: with SMTP id c19mr2103523pjr.193.1616571225004; Wed, 24 Mar 2021 00:33:45 -0700 (PDT) From: Viresh Kumar To: qemu-devel@nongnu.org Subject: [PATCH 5/5] MAINTAINERS: Add entry for virtio-i2c Date: Wed, 24 Mar 2021 13:03:14 +0530 Message-Id: <43b9fe06a6c23943fc6feab5c2340e38ef2359e9.1616570702.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62d; envelope-from=viresh.kumar@linaro.org; helo=mail-pl1-x62d.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Guittot , Jie Deng , Viresh Kumar , Bill Mills , Arnd Bergmann , Mike Holmes , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds entry for virtio-i2c related files in MAINTAINERS. Signed-off-by: Viresh Kumar --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9147e9a429a0..3a80352fc85b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1967,6 +1967,15 @@ F: hw/virtio/virtio-mem-pci.h F: hw/virtio/virtio-mem-pci.c F: include/hw/virtio/virtio-mem.h =20 +virtio-i2c +M: Viresh Kumar +S: Supported +F: docs/tools/vhost-user-i2c.rst +F: hw/virtio/vhost-user-i2c.c +F: hw/virtio/vhost-user-i2c-pci.c +F: include/hw/virtio/vhost-user-i2c.h +F: tools/vhost-user-i2c/* + nvme M: Keith Busch M: Klaus Jensen --=20 2.25.0.rc1.19.g042ed3e048af