Commit 8b750bf7 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Zhi Wang
Browse files

drm/i915/gvt: move the gvt code into kvmgt.ko



Instead of having an option to build the gvt code into the main i915
module, just move it into the kvmgt.ko module.  This only requires
a new struct with three entries that the KVMGT modules needs to register
with the main i915 module, and a proper list of GVT-enabled devices
instead of global device pointer.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarZhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-7-hch@lst.de


Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarZhi Wang <zhi.a.wang@intel.com>
parent f49fc357
Loading
Loading
Loading
Loading
+13 −23
Original line number Diff line number Diff line
@@ -102,40 +102,30 @@ config DRM_I915_USERPTR
	  If in doubt, say "Y".

config DRM_I915_GVT
	bool "Enable Intel GVT-g graphics virtualization host support"
	bool

config DRM_I915_GVT_KVMGT
	tristate "Enable KVM host support Intel GVT-g graphics virtualization"
	depends on DRM_I915
	depends on X86
	depends on 64BIT
	default n
	depends on KVM
	depends on VFIO_MDEV
	select DRM_I915_GVT
	select KVM_EXTERNAL_WRITE_TRACKING

	help
	  Choose this option if you want to enable Intel GVT-g graphics
	  virtualization technology host support with integrated graphics.
	  With GVT-g, it's possible to have one integrated graphics
	  device shared by multiple VMs under different hypervisors.

	  Note that at least one hypervisor like Xen or KVM is required for
	  this driver to work, and it only supports newer device from
	  Broadwell+. For further information and setup guide, you can
	  visit: http://01.org/igvt-g.
	  device shared by multiple VMs under KVM.

	  Now it's just a stub to support the modifications of i915 for
	  GVT device model. It requires at least one MPT modules for Xen/KVM
	  and other components of GVT device model to work. Use it under
	  you own risk.
	  Note that this driver only supports newer device from Broadwell on.
	  For further information and setup guide, you can visit:
	  http://01.org/igvt-g.

	  If in doubt, say "N".

config DRM_I915_GVT_KVMGT
	tristate "Enable KVM/VFIO support for Intel GVT-g"
	depends on DRM_I915_GVT
	depends on KVM
	depends on VFIO_MDEV
	select KVM_EXTERNAL_WRITE_TRACKING
	default n
	help
	  Choose this option if you want to enable KVMGT support for
	  Intel GVT-g.

config DRM_I915_PXP
	bool "Enable Intel PXP support"
	depends on DRM_I915
+1 −1
Original line number Diff line number Diff line
@@ -326,7 +326,7 @@ i915-$(CONFIG_DRM_I915_GVT) += \
include $(src)/gvt/Makefile

obj-$(CONFIG_DRM_I915) += i915.o
obj-$(CONFIG_DRM_I915_GVT_KVMGT) += gvt/kvmgt.o
obj-$(CONFIG_DRM_I915_GVT_KVMGT) += kvmgt.o

# header test

+2 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0

i915-$(CONFIG_DRM_I915_GVT) += \
kvmgt-$(CONFIG_DRM_I915_GVT) += \
	gvt/aperture_gm.o \
	gvt/cfg_space.o \
	gvt/cmd_parser.o \
@@ -15,6 +15,7 @@ i915-$(CONFIG_DRM_I915_GVT) += \
	gvt/gvt.o \
	gvt/handlers.o \
	gvt/interrupt.o \
	gvt/kvmgt.o \
	gvt/mmio.o \
	gvt/mmio_context.o \
	gvt/opregion.o \
+19 −36
Original line number Diff line number Diff line
@@ -39,8 +39,6 @@
#include <linux/vfio.h>
#include <linux/mdev.h>

struct intel_gvt_host intel_gvt_host;

static const struct intel_gvt_ops intel_gvt_ops = {
	.emulate_cfg_read = intel_vgpu_emulate_cfg_read,
	.emulate_cfg_write = intel_vgpu_emulate_cfg_write,
@@ -147,13 +145,14 @@ static int init_service_thread(struct intel_gvt *gvt)
 * resources owned by a GVT device.
 *
 */
void intel_gvt_clean_device(struct drm_i915_private *i915)
static void intel_gvt_clean_device(struct drm_i915_private *i915)
{
	struct intel_gvt *gvt = fetch_and_zero(&i915->gvt);

	if (drm_WARN_ON(&i915->drm, !gvt))
		return;

	intel_gvt_hypervisor_host_exit(i915->drm.dev, gvt);
	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
	intel_gvt_clean_vgpu_types(gvt);

@@ -181,7 +180,7 @@ void intel_gvt_clean_device(struct drm_i915_private *i915)
 * Zero on success, negative error code if failed.
 *
 */
int intel_gvt_init_device(struct drm_i915_private *i915)
static int intel_gvt_init_device(struct drm_i915_private *i915)
{
	struct intel_gvt *gvt;
	struct intel_vgpu *vgpu;
@@ -253,11 +252,17 @@ int intel_gvt_init_device(struct drm_i915_private *i915)

	intel_gvt_debugfs_init(gvt);

	ret = intel_gvt_hypervisor_host_init(i915->drm.dev, gvt,
					     &intel_gvt_ops);
	if (ret)
		goto out_destroy_idle_vgpu;

	gvt_dbg_core("gvt device initialization is done\n");
	intel_gvt_host.dev = i915->drm.dev;
	intel_gvt_host.initialized = true;
	return 0;

out_destroy_idle_vgpu:
	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
	intel_gvt_debugfs_clean(gvt);
out_clean_types:
	intel_gvt_clean_vgpu_types(gvt);
out_clean_thread:
@@ -281,39 +286,17 @@ int intel_gvt_init_device(struct drm_i915_private *i915)
	return ret;
}

int
intel_gvt_pm_resume(struct intel_gvt *gvt)
static void intel_gvt_pm_resume(struct drm_i915_private *i915)
{
	struct intel_gvt *gvt = i915->gvt;

	intel_gvt_restore_fence(gvt);
	intel_gvt_restore_mmio(gvt);
	intel_gvt_restore_ggtt(gvt);
	return 0;
}

int
intel_gvt_register_hypervisor(const struct intel_gvt_mpt *m)
{
	int ret;
	void *gvt;

	if (!intel_gvt_host.initialized)
		return -ENODEV;

	intel_gvt_host.mpt = m;
	gvt = (void *)kdev_to_i915(intel_gvt_host.dev)->gvt;

	ret = intel_gvt_hypervisor_host_init(intel_gvt_host.dev, gvt,
					     &intel_gvt_ops);
	if (ret < 0)
		return -ENODEV;
	return 0;
}
EXPORT_SYMBOL_GPL(intel_gvt_register_hypervisor);

void
intel_gvt_unregister_hypervisor(void)
{
	void *gvt = (void *)kdev_to_i915(intel_gvt_host.dev)->gvt;
	intel_gvt_hypervisor_host_exit(intel_gvt_host.dev, gvt);
}
EXPORT_SYMBOL_GPL(intel_gvt_unregister_hypervisor);
const struct intel_vgpu_ops intel_gvt_vgpu_ops = {
	.init_device	= intel_gvt_init_device,
	.clean_device	= intel_gvt_clean_device,
	.pm_resume	= intel_gvt_pm_resume,
};
+2 −4
Original line number Diff line number Diff line
@@ -58,8 +58,6 @@
#define GVT_MAX_VGPU 8

struct intel_gvt_host {
	struct device *dev;
	bool initialized;
	const struct intel_gvt_mpt *mpt;
};

@@ -728,9 +726,9 @@ void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu);
void intel_gvt_debugfs_init(struct intel_gvt *gvt);
void intel_gvt_debugfs_clean(struct intel_gvt *gvt);

int intel_gvt_pm_resume(struct intel_gvt *gvt);

#include "trace.h"
#include "mpt.h"

extern const struct intel_vgpu_ops intel_gvt_vgpu_ops;

#endif
Loading