From patchwork Wed Mar 24 07:33:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 407793 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp182049jai; Wed, 24 Mar 2021 00:33:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUuaOB043AQmy3fduZD+BQ0LJoygmb664wxgPm6rw4PVsGOjOCzxkMo79T8txd6ytZYHSX X-Received: by 2002:a5d:9e18:: with SMTP id h24mr1493938ioh.80.1616571228227; Wed, 24 Mar 2021 00:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616571228; cv=none; d=google.com; s=arc-20160816; b=hnfkbP+7eorkXWmb2lSBbm7OBDLrUbXgmqcuCgviCZgT5fkKPQ2Qzf45f15bLA12OO eC7AHKpehRRGcu1o1+2GUsVpl6DvQiDzRsn3Tz/562x2Bhpg2+nC3nO5KNj+tTuB/UXm w+8zVvuZcjZZiPPby2BOhFk/cSVrk3Iqn1gL34i6MKfL8cni21JyBCzR1h6q+pw9g+N0 XfIXqjJADAbDpBO/GBq8aU8+eBPCa2DY/jGweZKv8ArxrqBw4XbiAvypFfsSF88spbpU GeuixY+70M2xMM7shmjoVFF21qYOzvzZxZ24fQ4Gkywmfw+sNITtPUi3GqHyxeVC64wB V8eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=39/+0LJ0WNF4zm8Jo7cFRlR6uT3LdZ8Gs1InHlxe1es=; b=RdcXoHsj9xSTBM6lGBpjU1D1XUuRuWfVNfdRpJtWw7c4i0a9rgfTV6SrZIoJdUElHJ oisD2NCclwG8E2VNvDexpAuTmvSPYW6/xn9oOyo/D+CqXpCxK9vqZVSq6u5/CEYAUygg f+qVRSAf7e0efUyc1Y90PZoz2cbqe5MVwZt64DO65o1vCs49lxkJTdBAs8xfFk2z1H08 AwUyOOXqCNnmhLROxtx5AR+b5wFyKa8ObKQNwlw3f9otj2cbcZnNTbSz6J+0u0oQJEnQ mFaLcqve6e0dA196IXBabCGYSWuDUUhmcVvy/A8kYpEDpDPG/x2HhDZJw/YSgU0wP8pb 3vwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oLBBdxHK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l14si1170202ilv.92.2021.03.24.00.33.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Mar 2021 00:33:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oLBBdxHK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOy1T-0005xt-KE for patch@linaro.org; Wed, 24 Mar 2021 03:33:47 -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) 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-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) 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) 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 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_Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 -- 2.25.0.rc1.19.g042ed3e048af Reviewed-by: Alex Bennée 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-i2c.c')) +virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_true: files('vhost-user-i2c-pci.c')) virtio_pci_ss = 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[] = { + 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 **errp) +{ + VHostUserI2CPCI *dev = VHOST_USER_I2C_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors = 1; + } + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_i2c_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + k->realize = 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 = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision = 0x00; + pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_i2c_pci_instance_init(Object *obj) +{ + VHostUserI2CPCI *dev = 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 = { + .base_name = TYPE_VHOST_USER_I2C_PCI, + .non_transitional_name = "vhost-user-i2c-pci", + .instance_size = sizeof(VHostUserI2CPCI), + .instance_init = vhost_user_i2c_pci_instance_init, + .class_init = 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);