From nobody Thu Mar 28 16:24:49 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1652501297; cv=none; d=zohomail.com; s=zohoarc; b=Din+FU6PxIn6707lLygU0RzicHEoOMcmyacdMKaUirce3hvqVLZ5AEIv9aXgVkZN1kdiGqbkN56QQuHicYoeohJTfmwYCLjDTEc51mDOaa5Q1Pl9rIiQ45pB1tDUG8sVUsHH05E6cuqy0WvdNymDodty4T7JLt+msF7dGnkDLXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652501297; h=Content-Type: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:Reply-To:References:Sender:Subject:To; bh=VI3ipqrtOWC1xZM58jW13SFE6I5Xww+IBsyBx6BF2ho=; b=W8mjFFtbvWfwoOQVWUlsPD6ZE+U3n6oUw7deNlvStm2nAb3Tvybu4hoxMylXw/IW+Eqj1598LoeV+lCxGJt1iijrtfR6fH/roUdR4DAOr2z7lX3xfFicaHpk8UHRfAOqcsyU1Re0ewHQ0v9UL9/IFCdDiVkS1rjZg/kFulln5H8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652501297534194.6380637323149; Fri, 13 May 2022 21:08:17 -0700 (PDT) Received: from localhost ([::1]:36306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npj4i-00048S-8i for importer2@patchew.org; Sat, 14 May 2022 00:08:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2H-00021V-Iv for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:47 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2F-0001V2-2E for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:45 -0400 Received: from kwepemi500025.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4L0X3G6Z1TzXddS; Sat, 14 May 2022 12:04:58 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi500025.china.huawei.com (7.221.188.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 14 May 2022 12:05:29 +0800 To: , , , CC: , , , , , , Subject: [PATCH v6 1/4] linux-headers: Update headers to Linux 5.18-rc6 Date: Sat, 14 May 2022 12:05:21 +0800 Message-ID: <20220514040524.1929-2-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20220514040524.1929-1-longpeng2@huawei.com> References: <20220514040524.1929-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500025.china.huawei.com (7.221.188.170) X-CFilter-Loop: Reflected 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.187; envelope-from=longpeng2@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via X-ZM-MESSAGEID: 1652501298245100001 Content-Type: text/plain; charset="utf-8" From: Longpeng Update headers to 5.18-rc6. I need latest vhost changes. Signed-off-by: Longpeng --- linux-headers/linux/vhost.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index c998860d7b..5d99e7c242 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -150,4 +150,11 @@ /* Get the valid iova range */ #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ struct vhost_vdpa_iova_range) + +/* Get the config size */ +#define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32) + +/* Get the count of all virtqueues */ +#define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) + #endif --=20 2.23.0 From nobody Thu Mar 28 16:24:49 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1652501422; cv=none; d=zohomail.com; s=zohoarc; b=atrChWZcTtcY2foutd+DKp10bcCYQyxppbf1K8oMMhbFcWYWr3bKmPyn91rAnHrmSje7UOZ3es16gNGHXK8A1z3tkwsWrck9S5kS7qZ55pBndRdgfl57Vkv6uREVSeuPnyvmY9p7Gf93Z4ZC98fS/dY11LpEZboYdN35XFhqx/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652501422; h=Content-Type: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:Reply-To:References:Sender:Subject:To; bh=CDGvTqjdnAUr4pNctbrDZCF/as2mg7HZuGNM1XN7QY0=; b=lDISnuCPV20jF/MD1NAHVRlhVLSFTkuZYeKeFyp4FIGLjpiqBb8ONsq0zexxyw1175kGwLXtPYvss1T/+5R9zlA2UMbzcCHNqV7BI/wBHmkoqqUb0yrug0zHA8npYEvCLiGRFFpqpqHTatj5zCey9WO1PNVKD0nKTmX/XG/WQwY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165250142257997.78527360424653; Fri, 13 May 2022 21:10:22 -0700 (PDT) Received: from localhost ([::1]:41134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npj6j-0007W4-Iw for importer2@patchew.org; Sat, 14 May 2022 00:10:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2J-00021Y-Mh for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:48 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2G-0001V4-Uw for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:46 -0400 Received: from kwepemi500025.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L0X336CkLzhYvS; Sat, 14 May 2022 12:04:47 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi500025.china.huawei.com (7.221.188.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 14 May 2022 12:05:30 +0800 To: , , , CC: , , , , , , Subject: [PATCH v6 2/4] virtio: get class_id and pci device id by the virtio id Date: Sat, 14 May 2022 12:05:22 +0800 Message-ID: <20220514040524.1929-3-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20220514040524.1929-1-longpeng2@huawei.com> References: <20220514040524.1929-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500025.china.huawei.com (7.221.188.170) X-CFilter-Loop: Reflected 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=longpeng2@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via X-ZM-MESSAGEID: 1652501422852100001 Content-Type: text/plain; charset="utf-8" From: Longpeng Add helpers to get the "Transitional PCI Device ID" and "class_id" of the device specified by the "Virtio Device ID". These helpers will be used to build the generic vDPA device later. Signed-off-by: Longpeng --- hw/virtio/virtio-pci.c | 101 +++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 5 ++ 2 files changed, 106 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 7cf1231c1c..204388b967 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -19,6 +19,7 @@ =20 #include "exec/memop.h" #include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_ids.h" #include "hw/boards.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h" @@ -212,6 +213,103 @@ static int virtio_pci_load_queue(DeviceState *d, int = n, QEMUFile *f) return 0; } =20 +typedef struct VirtIOPCIIDInfo { + /* virtio id */ + uint16_t vdev_id; + /* pci device id for the transitional device */ + uint16_t trans_devid; + uint16_t class_id; +} VirtIOPCIIDInfo; + +#define VIRTIO_TRANS_DEV_ID_INFO(name, class) \ + { \ + .vdev_id =3D VIRTIO_ID_##name, \ + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_##name, \ + .class_id =3D class, \ + } + +#define VIRTIO_MODERN_DEV_ID_NFO(name, class) \ + { \ + .vdev_id =3D VIRTIO_ID_##name, \ + .class_id =3D class, \ + } + +static const VirtIOPCIIDInfo virtio_pci_id_info[] =3D { + { + .vdev_id =3D VIRTIO_ID_CRYPTO, + .class_id =3D PCI_CLASS_OTHERS, + }, { + .vdev_id =3D VIRTIO_ID_FS, + .class_id =3D PCI_CLASS_STORAGE_OTHER, + }, { + .vdev_id =3D VIRTIO_ID_NET, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_NET, + .class_id =3D PCI_CLASS_NETWORK_ETHERNET, + }, { + .vdev_id =3D VIRTIO_ID_BLOCK, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_BLOCK, + .class_id =3D PCI_CLASS_STORAGE_SCSI, + }, { + .vdev_id =3D VIRTIO_ID_CONSOLE, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_CONSOLE, + .class_id =3D PCI_CLASS_COMMUNICATION_OTHER, + }, { + .vdev_id =3D VIRTIO_ID_SCSI, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_SCSI, + .class_id =3D PCI_CLASS_STORAGE_SCSI + }, { + .vdev_id =3D VIRTIO_ID_9P, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_9P, + .class_id =3D PCI_BASE_CLASS_NETWORK, + }, { + .vdev_id =3D VIRTIO_ID_BALLOON, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_BALLOON, + .class_id =3D PCI_CLASS_OTHERS, + }, { + .vdev_id =3D VIRTIO_ID_RNG, + .trans_devid =3D PCI_DEVICE_ID_VIRTIO_RNG, + .class_id =3D PCI_CLASS_OTHERS, + }, +}; + +static const VirtIOPCIIDInfo *virtio_pci_get_id_info(uint16_t vdev_id) +{ + const VirtIOPCIIDInfo *info =3D NULL; + int i; + + for (i =3D 0; i < ARRAY_SIZE(virtio_pci_id_info); i++) { + if (virtio_pci_id_info[i].vdev_id =3D=3D vdev_id) { + info =3D &virtio_pci_id_info[i]; + break; + } + } + + if (!info) { + /* The device id is invalid or not added to the id_info yet. */ + error_report("Invalid virtio device(id %u)", vdev_id); + abort(); + } + + return info; +} + +/* + * Get the Transitional Device ID for the specific device, return + * zero if the device is non-transitional. + */ +uint16_t virtio_pci_get_trans_devid(uint16_t device_id) +{ + return virtio_pci_get_id_info(device_id)->trans_devid; +} + +/* + * Get the Class ID for the specific device. + */ +uint16_t virtio_pci_get_class_id(uint16_t device_id) +{ + return virtio_pci_get_id_info(device_id)->class_id; +} + static bool virtio_pci_ioeventfd_enabled(DeviceState *d) { VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); @@ -1675,6 +1773,9 @@ static void virtio_pci_device_plugged(DeviceState *d,= Error **errp) * is set to PCI_SUBVENDOR_ID_REDHAT_QUMRANET by default. */ pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus= )); + if (proxy->trans_devid) { + pci_config_set_device_id(config, proxy->trans_devid); + } } else { /* pure virtio-1.0 */ pci_set_word(config + PCI_VENDOR_ID, diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 2446dcd9ae..f08665cd1b 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -146,6 +146,8 @@ struct VirtIOPCIProxy { bool disable_modern; bool ignore_backend_features; OnOffAuto disable_legacy; + /* Transitional device id */ + uint16_t trans_devid; uint32_t class_code; uint32_t nvectors; uint32_t dfselect; @@ -158,6 +160,9 @@ struct VirtIOPCIProxy { VirtioBusState bus; }; =20 +uint16_t virtio_pci_get_trans_devid(uint16_t device_id); +uint16_t virtio_pci_get_class_id(uint16_t device_id); + static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy) { return !proxy->disable_modern; --=20 2.23.0 From nobody Thu Mar 28 16:24:49 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1652501300; cv=none; d=zohomail.com; s=zohoarc; b=hmlZnxTDV8TR0ky2vmERxFjXdLiVOaaLDjlJ44a+/dpLeOPifnNTJr3/xcLXp18nqMr0N/7Y0pgG09qgmVPjVfYhjcMBv+t/Po5rf2c6ARgRlHD+QRAk1w8kw2UCuKzThsvQHGGpIj6cowiaCp9rUF2stXWuFkZHNrUmdwWAJ6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652501300; h=Content-Type: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:Reply-To:References:Sender:Subject:To; bh=beAK4uAyR1XrLtWVgtQ+aDeNmrmetwZo+mq+y4WcxNs=; b=hmqY4KLprPOxx3W/21hSS+/5XIZKMQN6hnb5G3szwcts9gq1tlpr7ICyL7YOZ+Sm41QJDGtV1HsA4FTvL1HJl8M92SgB0s3pZVpWR7zzH5R+ABcFOtH6uEU1xanGI2KKwVFISBf90Jr6yTpItDm7ZR/BZXZzZGAWVpkIyfvAJ10= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16525013004431023.3092511804703; Fri, 13 May 2022 21:08:20 -0700 (PDT) Received: from localhost ([::1]:36514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npj4l-0004Gw-CP for importer2@patchew.org; Sat, 14 May 2022 00:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2R-00024f-M0 for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:55 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:3866) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2O-0001WS-Mv for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:55 -0400 Received: from kwepemi500025.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L0X2S0Wjdz1JBc3; Sat, 14 May 2022 12:04:16 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi500025.china.huawei.com (7.221.188.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 14 May 2022 12:05:30 +0800 To: , , , CC: , , , , , , Subject: [PATCH v6 3/4] vdpa: add vdpa-dev support Date: Sat, 14 May 2022 12:05:23 +0800 Message-ID: <20220514040524.1929-4-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20220514040524.1929-1-longpeng2@huawei.com> References: <20220514040524.1929-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500025.china.huawei.com (7.221.188.170) X-CFilter-Loop: Reflected 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.255; envelope-from=longpeng2@huawei.com; helo=szxga08-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via X-ZM-MESSAGEID: 1652501302370100001 Content-Type: text/plain; charset="utf-8" From: Longpeng Supports vdpa-dev, we can use the deivce directly: -M microvm -m 512m -smp 2 -kernel ... -initrd ... -device \ vhost-vdpa-device,vhostdev=3D/dev/vhost-vdpa-x Signed-off-by: Longpeng --- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vdpa-dev.c | 377 +++++++++++++++++++++++++++++++++++ include/hw/virtio/vdpa-dev.h | 43 ++++ 4 files changed, 426 insertions(+) create mode 100644 hw/virtio/vdpa-dev.c create mode 100644 include/hw/virtio/vdpa-dev.h diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index c144d42f9b..724eb58a32 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -68,3 +68,8 @@ config VHOST_USER_RNG bool default y depends on VIRTIO && VHOST_USER + +config VHOST_VDPA_DEV + bool + default y + depends on VIRTIO && VHOST_VDPA && LINUX diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 67dc77e00f..8f6f86db71 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -29,6 +29,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: fil= es('vhost-user-i2c.c')) virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_tru= e: files('vhost-user-i2c-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) +virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.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/vdpa-dev.c b/hw/virtio/vdpa-dev.c new file mode 100644 index 0000000000..1840f0e450 --- /dev/null +++ b/hw/virtio/vdpa-dev.c @@ -0,0 +1,377 @@ +/* + * Vhost Vdpa Device + * + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved. + * + * Authors: + * Longpeng + * + * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c" + * implemented by: + * Changpeng Liu + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + */ +#include "qemu/osdep.h" +#include +#include +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/cutils.h" +#include "hw/qdev-core.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/vdpa-dev.h" +#include "sysemu/sysemu.h" +#include "sysemu/runstate.h" + +static void +vhost_vdpa_device_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* Nothing to do */ +} + +static uint32_t +vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp) +{ + uint32_t val =3D (uint32_t)-1; + + if (ioctl(fd, cmd, &val) < 0) { + error_setg(errp, "vhost-vdpa-device: cmd 0x%lx failed: %s", + cmd, strerror(errno)); + } + + return val; +} + +static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VhostVdpaDevice *v =3D VHOST_VDPA_DEVICE(vdev); + uint16_t max_queue_size; + struct vhost_virtqueue *vqs; + int i, ret; + + if (!v->vhostdev) { + error_setg(errp, "vhost-vdpa-device: vhostdev are missing"); + return; + } + + v->vhostfd =3D qemu_open(v->vhostdev, O_RDWR, errp); + if (*errp) { + return; + } + v->vdpa.device_fd =3D v->vhostfd; + + v->vdev_id =3D vhost_vdpa_device_get_u32(v->vhostfd, + VHOST_VDPA_GET_DEVICE_ID, errp); + if (*errp) { + goto out; + } + + max_queue_size =3D vhost_vdpa_device_get_u32(v->vhostfd, + VHOST_VDPA_GET_VRING_NUM, e= rrp); + if (*errp) { + goto out; + } + + if (v->queue_size > max_queue_size) { + error_setg(errp, "vhost-vdpa-device: invalid queue_size: %u (max:%= u)", + v->queue_size, max_queue_size); + goto out; + } else if (!v->queue_size) { + v->queue_size =3D max_queue_size; + } + + v->num_queues =3D vhost_vdpa_device_get_u32(v->vhostfd, + VHOST_VDPA_GET_VQS_COUNT, er= rp); + if (*errp) { + goto out; + } + + if (!v->num_queues || v->num_queues > VIRTIO_QUEUE_MAX) { + error_setg(errp, "invalid number of virtqueues: %u (max:%u)", + v->num_queues, VIRTIO_QUEUE_MAX); + goto out; + } + + v->dev.nvqs =3D v->num_queues; + vqs =3D g_new0(struct vhost_virtqueue, v->dev.nvqs); + v->dev.vqs =3D vqs; + v->dev.vq_index =3D 0; + v->dev.vq_index_end =3D v->dev.nvqs; + v->dev.backend_features =3D 0; + v->started =3D false; + + ret =3D vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, = NULL); + if (ret < 0) { + error_setg(errp, "vhost-vdpa-device: vhost initialization failed: = %s", + strerror(-ret)); + goto free_vqs; + } + + v->config_size =3D vhost_vdpa_device_get_u32(v->vhostfd, + VHOST_VDPA_GET_CONFIG_SIZE, + errp); + if (*errp) { + goto vhost_cleanup; + } + + /* + * Invoke .post_init() to initialize the transport-specific fields + * before calling virtio_init(). + */ + if (v->post_init && v->post_init(v, errp) < 0) { + goto vhost_cleanup; + } + + v->config =3D g_malloc0(v->config_size); + + ret =3D vhost_dev_get_config(&v->dev, v->config, v->config_size, NULL); + if (ret < 0) { + error_setg(errp, "vhost-vdpa-device: get config failed"); + goto free_config; + } + + virtio_init(vdev, "vhost-vdpa", v->vdev_id, v->config_size); + + v->virtqs =3D g_new0(VirtQueue *, v->dev.nvqs); + for (i =3D 0; i < v->dev.nvqs; i++) { + v->virtqs[i] =3D virtio_add_queue(vdev, v->queue_size, + vhost_vdpa_device_dummy_handle_out= put); + } + + return; + +free_config: + g_free(v->config); +vhost_cleanup: + vhost_dev_cleanup(&v->dev); +free_vqs: + g_free(vqs); +out: + qemu_close(v->vhostfd); + v->vhostfd =3D -1; +} + +static void vhost_vdpa_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + int i; + + virtio_set_status(vdev, 0); + + for (i =3D 0; i < s->num_queues; i++) { + virtio_delete_queue(s->virtqs[i]); + } + g_free(s->virtqs); + virtio_cleanup(vdev); + + g_free(s->config); + g_free(s->dev.vqs); + vhost_dev_cleanup(&s->dev); + qemu_close(s->vhostfd); + s->vhostfd =3D -1; +} + +static void +vhost_vdpa_device_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + + memcpy(config, s->config, s->config_size); +} + +static void +vhost_vdpa_device_set_config(VirtIODevice *vdev, const uint8_t *config) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + int ret; + + ret =3D vhost_dev_set_config(&s->dev, s->config, 0, s->config_size, + VHOST_SET_CONFIG_TYPE_MASTER); + if (ret) { + error_report("set device config space failed"); + return; + } +} + +static uint64_t vhost_vdpa_device_get_features(VirtIODevice *vdev, + uint64_t features, + Error **errp) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + uint64_t backend_features =3D s->dev.features; + + if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) { + virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM); + } + + return backend_features; +} + +static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int i, ret; + + if (!k->set_guest_notifiers) { + error_setg(errp, "binding does not support guest notifiers"); + return -ENOSYS; + } + + ret =3D vhost_dev_enable_notifiers(&s->dev, vdev); + if (ret < 0) { + error_setg_errno(errp, -ret, "Error enabling host notifiers"); + return ret; + } + + ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); + if (ret < 0) { + error_setg_errno(errp, -ret, "Error binding guest notifier"); + goto err_host_notifiers; + } + + s->dev.acked_features =3D vdev->guest_features; + + ret =3D vhost_dev_start(&s->dev, vdev); + if (ret < 0) { + error_setg_errno(errp, -ret, "Error starting vhost"); + goto err_guest_notifiers; + } + s->started =3D true; + + /* + * 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 < s->dev.nvqs; i++) { + vhost_virtqueue_mask(&s->dev, vdev, i, false); + } + + return ret; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&s->dev, vdev); + return ret; +} + +static void vhost_vdpa_device_stop(VirtIODevice *vdev) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!s->started) { + return; + } + s->started =3D false; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&s->dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&s->dev, vdev); +} + +static void vhost_vdpa_device_set_status(VirtIODevice *vdev, uint8_t statu= s) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + bool should_start =3D virtio_device_started(vdev, status); + Error *local_err =3D NULL; + int ret; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (s->started =3D=3D should_start) { + return; + } + + if (should_start) { + ret =3D vhost_vdpa_device_start(vdev, &local_err); + if (ret < 0) { + error_reportf_err(local_err, "vhost-vdpa-device: start failed:= "); + } + } else { + vhost_vdpa_device_stop(vdev); + } +} + +static Property vhost_vdpa_device_properties[] =3D { + DEFINE_PROP_STRING("vhostdev", VhostVdpaDevice, vhostdev), + DEFINE_PROP_UINT16("queue-size", VhostVdpaDevice, queue_size, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vmstate_vhost_vdpa_device =3D { + .name =3D "vhost-vdpa-device", + .unmigratable =3D 1, + .minimum_version_id =3D 1, + .version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, +}; + +static void vhost_vdpa_device_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vhost_vdpa_device_properties); + dc->desc =3D "VDPA-based generic device assignment"; + dc->vmsd =3D &vmstate_vhost_vdpa_device; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize =3D vhost_vdpa_device_realize; + vdc->unrealize =3D vhost_vdpa_device_unrealize; + vdc->get_config =3D vhost_vdpa_device_get_config; + vdc->set_config =3D vhost_vdpa_device_set_config; + vdc->get_features =3D vhost_vdpa_device_get_features; + vdc->set_status =3D vhost_vdpa_device_set_status; +} + +static void vhost_vdpa_device_instance_init(Object *obj) +{ + VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(obj); + + device_add_bootindex_property(obj, &s->bootindex, "bootindex", + NULL, DEVICE(obj)); +} + +static const TypeInfo vhost_vdpa_device_info =3D { + .name =3D TYPE_VHOST_VDPA_DEVICE, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VhostVdpaDevice), + .class_init =3D vhost_vdpa_device_class_init, + .instance_init =3D vhost_vdpa_device_instance_init, +}; + +static void register_vhost_vdpa_device_type(void) +{ + type_register_static(&vhost_vdpa_device_info); +} + +type_init(register_vhost_vdpa_device_type); diff --git a/include/hw/virtio/vdpa-dev.h b/include/hw/virtio/vdpa-dev.h new file mode 100644 index 0000000000..4dbf98195c --- /dev/null +++ b/include/hw/virtio/vdpa-dev.h @@ -0,0 +1,43 @@ +/* + * Vhost Vdpa Device + * + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved. + * + * Authors: + * Longpeng + * + * Largely based on the "vhost-user-blk.h" implemented by: + * Changpeng Liu + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + */ +#ifndef _VHOST_VDPA_DEVICE_H +#define _VHOST_VDPA_DEVICE_H + +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qom/object.h" + + +#define TYPE_VHOST_VDPA_DEVICE "vhost-vdpa-device" +OBJECT_DECLARE_SIMPLE_TYPE(VhostVdpaDevice, VHOST_VDPA_DEVICE) + +struct VhostVdpaDevice { + VirtIODevice parent_obj; + char *vhostdev; + int vhostfd; + int32_t bootindex; + uint32_t vdev_id; + uint32_t num_queues; + struct vhost_dev dev; + struct vhost_vdpa vdpa; + VirtQueue **virtqs; + uint8_t *config; + int config_size; + uint16_t queue_size; + bool started; + int (*post_init)(VhostVdpaDevice *v, Error **errp); +}; + +#endif --=20 2.23.0 From nobody Thu Mar 28 16:24:49 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1652501658; cv=none; d=zohomail.com; s=zohoarc; b=Ybv4COZG06xJ47tbCn6HP0tvjAC8Baw1bZ4ogpxHAcACjPHAZnRdHMUwAxP4z43odsA6WPHNwb/rONFHecdzTWGDaZoO9q335g/Ri8U3vqdRwr2wyW7zhTma/w06bCflMlvYExc4AGq0lAopGjYwmH/Ph6eSqtHrhzuDqw81BG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652501658; h=Content-Type: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:Reply-To:References:Sender:Subject:To; bh=hfXIwkXpciFCYSaTg3pWJC3eYsxO16jUPAS9DMwn4Io=; b=AjMVgl78ItpoFvREvpbkSgHSYHKL9X9Aoynm7rRiQLWcPxihhyLOMeOfV9VT/zs6CB5HMLe1MUyVoDuzfObHmIsFgcAVFc/uVFoMY/rv3T/90fBMfqv5XMVcCv1LrdyRmadYp/C7swWBSo/KVDX8BusnNpFYkEyGGSKgZkbjJ94= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652501658156808.2317472174082; Fri, 13 May 2022 21:14:18 -0700 (PDT) Received: from localhost ([::1]:44908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npjAW-0001n1-OZ for importer2@patchew.org; Sat, 14 May 2022 00:14:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2K-00021b-IL for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:50 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npj2G-0001VE-Ui for qemu-devel@nongnu.org; Sat, 14 May 2022 00:05:48 -0400 Received: from kwepemi500025.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4L0X3K3h04zgYfg; Sat, 14 May 2022 12:05:01 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi500025.china.huawei.com (7.221.188.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 14 May 2022 12:05:31 +0800 To: , , , CC: , , , , , , Subject: [PATCH v6 4/4] vdpa: add vdpa-dev-pci support Date: Sat, 14 May 2022 12:05:24 +0800 Message-ID: <20220514040524.1929-5-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20220514040524.1929-1-longpeng2@huawei.com> References: <20220514040524.1929-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500025.china.huawei.com (7.221.188.170) X-CFilter-Loop: Reflected 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.187; envelope-from=longpeng2@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: "Longpeng(Mike)" From: "Longpeng(Mike)" via X-ZM-MESSAGEID: 1652501660049100001 Content-Type: text/plain; charset="utf-8" From: Longpeng Supports vdpa-dev-pci, we can use the device as follow: -device vhost-vdpa-device-pci,vhostdev=3D/dev/vhost-vdpa-X Reviewed-by: Stefano Garzarella Signed-off-by: Longpeng --- hw/virtio/meson.build | 1 + hw/virtio/vdpa-dev-pci.c | 102 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 hw/virtio/vdpa-dev-pci.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 8f6f86db71..c2da69616f 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -50,6 +50,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: = files('virtio-serial-pc virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-= pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iomm= u-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pc= i.c')) +virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-= pci.c')) =20 virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss) =20 diff --git a/hw/virtio/vdpa-dev-pci.c b/hw/virtio/vdpa-dev-pci.c new file mode 100644 index 0000000000..fde35dfc92 --- /dev/null +++ b/hw/virtio/vdpa-dev-pci.c @@ -0,0 +1,102 @@ +/* + * Vhost Vdpa Device PCI Bindings + * + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved. + * + * Authors: + * Longpeng + * + * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c" + * implemented by: + * Changpeng Liu + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + */ +#include "qemu/osdep.h" +#include +#include +#include "hw/virtio/virtio.h" +#include "hw/virtio/vdpa-dev.h" +#include "hw/pci/pci.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "virtio-pci.h" +#include "qom/object.h" + + +typedef struct VhostVdpaDevicePCI VhostVdpaDevicePCI; + +#define TYPE_VHOST_VDPA_DEVICE_PCI "vhost-vdpa-device-pci-base" +DECLARE_INSTANCE_CHECKER(VhostVdpaDevicePCI, VHOST_VDPA_DEVICE_PCI, + TYPE_VHOST_VDPA_DEVICE_PCI) + +struct VhostVdpaDevicePCI { + VirtIOPCIProxy parent_obj; + VhostVdpaDevice vdev; +}; + +static void vhost_vdpa_device_pci_instance_init(Object *obj) +{ + VhostVdpaDevicePCI *dev =3D VHOST_VDPA_DEVICE_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_VDPA_DEVICE); + object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), + "bootindex"); +} + +static Property vhost_vdpa_device_pci_properties[] =3D { + DEFINE_PROP_END_OF_LIST(), +}; + +static int vhost_vdpa_device_pci_post_init(VhostVdpaDevice *v, Error **err= p) +{ + VhostVdpaDevicePCI *dev =3D container_of(v, VhostVdpaDevicePCI, vdev); + VirtIOPCIProxy *vpci_dev =3D &dev->parent_obj; + + vpci_dev->class_code =3D virtio_pci_get_class_id(v->vdev_id); + vpci_dev->trans_devid =3D virtio_pci_get_trans_devid(v->vdev_id); + /* one for config vector */ + vpci_dev->nvectors =3D v->num_queues + 1; + + return 0; +} + +static void +vhost_vdpa_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VhostVdpaDevicePCI *dev =3D VHOST_VDPA_DEVICE_PCI(vpci_dev); + + dev->vdev.post_init =3D vhost_vdpa_device_pci_post_init; + qdev_realize(DEVICE(&dev->vdev), BUS(&vpci_dev->bus), errp); +} + +static void vhost_vdpa_device_pci_class_init(ObjectClass *klass, void *dat= a) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, vhost_vdpa_device_pci_properties); + k->realize =3D vhost_vdpa_device_pci_realize; +} + +static const VirtioPCIDeviceTypeInfo vhost_vdpa_device_pci_info =3D { + .base_name =3D TYPE_VHOST_VDPA_DEVICE_PCI, + .generic_name =3D "vhost-vdpa-device-pci", + .transitional_name =3D "vhost-vdpa-device-pci-transitional", + .non_transitional_name =3D "vhost-vdpa-device-pci-non-transitional", + .instance_size =3D sizeof(VhostVdpaDevicePCI), + .instance_init =3D vhost_vdpa_device_pci_instance_init, + .class_init =3D vhost_vdpa_device_pci_class_init, +}; + +static void vhost_vdpa_device_pci_register(void) +{ + virtio_pci_types_register(&vhost_vdpa_device_pci_info); +} + +type_init(vhost_vdpa_device_pci_register); --=20 2.23.0