[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/10] vdpa: add the infrastructure of vdpa-dev
From: |
Longpeng(Mike) |
Subject: |
[PATCH v3 03/10] vdpa: add the infrastructure of vdpa-dev |
Date: |
Sat, 19 Mar 2022 15:20:05 +0800 |
From: Longpeng <longpeng2@huawei.com>
Add the infrastructure of vdpa-dev (the generic vDPA device), we
can add a generic vDPA device as follow:
-device vhost-vdpa-device-pci,vdpa-dev=/dev/vhost-vdpa-X
Signed-off-by: Longpeng <longpeng2@huawei.com>
---
hw/virtio/Kconfig | 5 +++
hw/virtio/meson.build | 2 ++
hw/virtio/vdpa-dev-pci.c | 65 ++++++++++++++++++++++++++++++++++++
hw/virtio/vdpa-dev.c | 55 ++++++++++++++++++++++++++++++
include/hw/virtio/vdpa-dev.h | 30 +++++++++++++++++
5 files changed, 157 insertions(+)
create mode 100644 hw/virtio/vdpa-dev-pci.c
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..2723283382 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 if VIRTIO_PCI
+ depends on VIRTIO && VHOST_VDPA && LINUX
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index 521f7d64a8..8e8943e20b 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:
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_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true:
files('vhost-user-rng.c'))
virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_true:
files('vhost-user-rng-pci.c'))
+virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c'))
virtio_pci_ss = ss.source_set()
virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true:
files('vhost-vsock-pci.c'))
@@ -49,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-iommu-pci.c'))
virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true:
files('virtio-mem-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true:
files('vdpa-dev-pci.c'))
virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
diff --git a/hw/virtio/vdpa-dev-pci.c b/hw/virtio/vdpa-dev-pci.c
new file mode 100644
index 0000000000..9c0f25a02d
--- /dev/null
+++ b/hw/virtio/vdpa-dev-pci.c
@@ -0,0 +1,65 @@
+/*
+ * Vhost Vdpa Device PCI Bindings
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
+ *
+ * Authors:
+ * Longpeng <longpeng2@huawei.com>
+ *
+ * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
implemented by:
+ * Changpeng Liu <changpeng.liu@intel.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+#include <linux/vhost.h>
+#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)
+{
+ return;
+}
+
+static void vhost_vdpa_device_pci_class_init(ObjectClass *klass, void *data)
+{
+ return;
+}
+
+static const VirtioPCIDeviceTypeInfo vhost_vdpa_device_pci_info = {
+ .base_name = TYPE_VHOST_VDPA_DEVICE_PCI,
+ .generic_name = "vhost-vdpa-device-pci",
+ .transitional_name = "vhost-vdpa-device-pci-transitional",
+ .non_transitional_name = "vhost-vdpa-device-pci-non-transitional",
+ .instance_size = sizeof(VhostVdpaDevicePCI),
+ .instance_init = vhost_vdpa_device_pci_instance_init,
+ .class_init = 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);
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
new file mode 100644
index 0000000000..5c506ff304
--- /dev/null
+++ b/hw/virtio/vdpa-dev.c
@@ -0,0 +1,55 @@
+/*
+ * Vhost Vdpa Device
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
+ *
+ * Authors:
+ * Longpeng <longpeng2@huawei.com>
+ *
+ * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
implemented by:
+ * Changpeng Liu <changpeng.liu@intel.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+#include <linux/vhost.h>
+#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_class_init(ObjectClass *klass, void *data)
+{
+ return;
+}
+
+static void vhost_vdpa_device_instance_init(Object *obj)
+{
+ return;
+}
+
+static const TypeInfo vhost_vdpa_device_info = {
+ .name = TYPE_VHOST_VDPA_DEVICE,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(VhostVdpaDevice),
+ .class_init = vhost_vdpa_device_class_init,
+ .instance_init = 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..bd60367793
--- /dev/null
+++ b/include/hw/virtio/vdpa-dev.h
@@ -0,0 +1,30 @@
+/*
+ * Vhost Vdpa Device
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
+ *
+ * Authors:
+ * Longpeng <longpeng2@huawei.com>
+ *
+ * Largely based on the "vhost-user-blk.h" implemented by:
+ * Changpeng Liu <changpeng.liu@intel.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#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;
+};
+
+#endif
--
2.23.0
- [PATCH v3 00/10] add generic vDPA device support, Longpeng(Mike), 2022/03/19
- [PATCH v3 01/10] virtio: get class_id and pci device id by the virtio id, Longpeng(Mike), 2022/03/19
- [PATCH v3 05/10] vdpa-dev: implement the realize interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 04/10] vdpa-dev: implement the instance_init/class_init interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 02/10] update linux headers, Longpeng(Mike), 2022/03/19
- [PATCH v3 08/10] vdpa-dev: implement the get_features interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 06/10] vdpa-dev: implement the unrealize interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 03/10] vdpa: add the infrastructure of vdpa-dev,
Longpeng(Mike) <=
- [PATCH v3 10/10] vdpa-dev: mark the device as unmigratable, Longpeng(Mike), 2022/03/19
- [PATCH v3 07/10] vdpa-dev: implement the get_config/set_config interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 09/10] vdpa-dev: implement the set_status interface, Longpeng(Mike), 2022/03/19
- Re: [PATCH v3 00/10] add generic vDPA device support, Stefano Garzarella, 2022/03/28