All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	Zhi Wang <zhi.a.wang@intel.com>
Cc: intel-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, Jason Gunthorpe <jgg@nvidia.com>,
	linux-kernel@vger.kernel.org
Subject: [Intel-gfx] [PATCH 29/34] drm/i915/gvt: merge gvt.c into kvmgvt.c
Date: Mon, 11 Apr 2022 16:13:58 +0200	[thread overview]
Message-ID: <20220411141403.86980-30-hch@lst.de> (raw)
In-Reply-To: <20220411141403.86980-1-hch@lst.de>

The code in both files is deeply interconnected, so merge it and
keep a bunch of structures and functions static.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/gpu/drm/i915/gvt/Makefile |   1 -
 drivers/gpu/drm/i915/gvt/gvt.c    | 291 ------------------------------
 drivers/gpu/drm/i915/gvt/gvt.h    |   6 -
 drivers/gpu/drm/i915/gvt/kvmgt.c  | 264 ++++++++++++++++++++++++++-
 4 files changed, 260 insertions(+), 302 deletions(-)
 delete mode 100644 drivers/gpu/drm/i915/gvt/gvt.c

diff --git a/drivers/gpu/drm/i915/gvt/Makefile b/drivers/gpu/drm/i915/gvt/Makefile
index cecedd9830f7c..2b08192930c18 100644
--- a/drivers/gpu/drm/i915/gvt/Makefile
+++ b/drivers/gpu/drm/i915/gvt/Makefile
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
 kvmgt-y += \
-	gvt/gvt.o \
 	gvt/aperture_gm.o \
 	gvt/handlers.o \
 	gvt/vgpu.o \
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
deleted file mode 100644
index 047fb6c41788b..0000000000000
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Authors:
- *    Kevin Tian <kevin.tian@intel.com>
- *    Eddie Dong <eddie.dong@intel.com>
- *
- * Contributors:
- *    Niu Bing <bing.niu@intel.com>
- *    Zhi Wang <zhi.a.wang@intel.com>
- *
- */
-
-#include <linux/types.h>
-#include <linux/kthread.h>
-
-#include "i915_drv.h"
-#include "intel_gvt.h"
-#include "gvt.h"
-#include <linux/vfio.h>
-#include <linux/mdev.h>
-
-static void init_device_info(struct intel_gvt *gvt)
-{
-	struct intel_gvt_device_info *info = &gvt->device_info;
-	struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
-
-	info->max_support_vgpus = 8;
-	info->cfg_space_size = PCI_CFG_SPACE_EXP_SIZE;
-	info->mmio_size = 2 * 1024 * 1024;
-	info->mmio_bar = 0;
-	info->gtt_start_offset = 8 * 1024 * 1024;
-	info->gtt_entry_size = 8;
-	info->gtt_entry_size_shift = 3;
-	info->gmadr_bytes_in_cmd = 8;
-	info->max_surface_size = 36 * 1024 * 1024;
-	info->msi_cap_offset = pdev->msi_cap;
-}
-
-static void intel_gvt_test_and_emulate_vblank(struct intel_gvt *gvt)
-{
-	struct intel_vgpu *vgpu;
-	int id;
-
-	mutex_lock(&gvt->lock);
-	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) {
-		if (test_and_clear_bit(INTEL_GVT_REQUEST_EMULATE_VBLANK + id,
-				       (void *)&gvt->service_request)) {
-			if (vgpu->active)
-				intel_vgpu_emulate_vblank(vgpu);
-		}
-	}
-	mutex_unlock(&gvt->lock);
-}
-
-static int gvt_service_thread(void *data)
-{
-	struct intel_gvt *gvt = (struct intel_gvt *)data;
-	int ret;
-
-	gvt_dbg_core("service thread start\n");
-
-	while (!kthread_should_stop()) {
-		ret = wait_event_interruptible(gvt->service_thread_wq,
-				kthread_should_stop() || gvt->service_request);
-
-		if (kthread_should_stop())
-			break;
-
-		if (WARN_ONCE(ret, "service thread is waken up by signal.\n"))
-			continue;
-
-		intel_gvt_test_and_emulate_vblank(gvt);
-
-		if (test_bit(INTEL_GVT_REQUEST_SCHED,
-				(void *)&gvt->service_request) ||
-			test_bit(INTEL_GVT_REQUEST_EVENT_SCHED,
-					(void *)&gvt->service_request)) {
-			intel_gvt_schedule(gvt);
-		}
-	}
-
-	return 0;
-}
-
-static void clean_service_thread(struct intel_gvt *gvt)
-{
-	kthread_stop(gvt->service_thread);
-}
-
-static int init_service_thread(struct intel_gvt *gvt)
-{
-	init_waitqueue_head(&gvt->service_thread_wq);
-
-	gvt->service_thread = kthread_run(gvt_service_thread,
-			gvt, "gvt_service_thread");
-	if (IS_ERR(gvt->service_thread)) {
-		gvt_err("fail to start service thread.\n");
-		return PTR_ERR(gvt->service_thread);
-	}
-	return 0;
-}
-
-/**
- * intel_gvt_clean_device - clean a GVT device
- * @i915: i915 private
- *
- * This function is called at the driver unloading stage, to free the
- * resources owned by a GVT device.
- *
- */
-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;
-
-	mdev_unregister_device(i915->drm.dev);
-	intel_gvt_cleanup_vgpu_type_groups(gvt);
-	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
-	intel_gvt_clean_vgpu_types(gvt);
-
-	intel_gvt_debugfs_clean(gvt);
-	clean_service_thread(gvt);
-	intel_gvt_clean_cmd_parser(gvt);
-	intel_gvt_clean_sched_policy(gvt);
-	intel_gvt_clean_workload_scheduler(gvt);
-	intel_gvt_clean_gtt(gvt);
-	intel_gvt_free_firmware(gvt);
-	intel_gvt_clean_mmio_info(gvt);
-	idr_destroy(&gvt->vgpu_idr);
-
-	kfree(i915->gvt);
-}
-
-/**
- * intel_gvt_init_device - initialize a GVT device
- * @i915: drm i915 private data
- *
- * This function is called at the initialization stage, to initialize
- * necessary GVT components.
- *
- * Returns:
- * Zero on success, negative error code if failed.
- *
- */
-static int intel_gvt_init_device(struct drm_i915_private *i915)
-{
-	struct intel_gvt *gvt;
-	struct intel_vgpu *vgpu;
-	int ret;
-
-	if (drm_WARN_ON(&i915->drm, i915->gvt))
-		return -EEXIST;
-
-	gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
-	if (!gvt)
-		return -ENOMEM;
-
-	gvt_dbg_core("init gvt device\n");
-
-	idr_init_base(&gvt->vgpu_idr, 1);
-	spin_lock_init(&gvt->scheduler.mmio_context_lock);
-	mutex_init(&gvt->lock);
-	mutex_init(&gvt->sched_lock);
-	gvt->gt = to_gt(i915);
-	i915->gvt = gvt;
-
-	init_device_info(gvt);
-
-	ret = intel_gvt_setup_mmio_info(gvt);
-	if (ret)
-		goto out_clean_idr;
-
-	intel_gvt_init_engine_mmio_context(gvt);
-
-	ret = intel_gvt_load_firmware(gvt);
-	if (ret)
-		goto out_clean_mmio_info;
-
-	ret = intel_gvt_init_irq(gvt);
-	if (ret)
-		goto out_free_firmware;
-
-	ret = intel_gvt_init_gtt(gvt);
-	if (ret)
-		goto out_free_firmware;
-
-	ret = intel_gvt_init_workload_scheduler(gvt);
-	if (ret)
-		goto out_clean_gtt;
-
-	ret = intel_gvt_init_sched_policy(gvt);
-	if (ret)
-		goto out_clean_workload_scheduler;
-
-	ret = intel_gvt_init_cmd_parser(gvt);
-	if (ret)
-		goto out_clean_sched_policy;
-
-	ret = init_service_thread(gvt);
-	if (ret)
-		goto out_clean_cmd_parser;
-
-	ret = intel_gvt_init_vgpu_types(gvt);
-	if (ret)
-		goto out_clean_thread;
-
-	vgpu = intel_gvt_create_idle_vgpu(gvt);
-	if (IS_ERR(vgpu)) {
-		ret = PTR_ERR(vgpu);
-		gvt_err("failed to create idle vgpu\n");
-		goto out_clean_types;
-	}
-	gvt->idle_vgpu = vgpu;
-
-	intel_gvt_debugfs_init(gvt);
-
-	ret = intel_gvt_init_vgpu_type_groups(gvt);
-	if (ret)
-		goto out_destroy_idle_vgpu;
-
-	ret = mdev_register_device(i915->drm.dev, &intel_vgpu_mdev_ops);
-	if (ret)
-		goto out_cleanup_vgpu_type_groups;
-
-	gvt_dbg_core("gvt device initialization is done\n");
-	return 0;
-
-out_cleanup_vgpu_type_groups:
-	intel_gvt_cleanup_vgpu_type_groups(gvt);
-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:
-	clean_service_thread(gvt);
-out_clean_cmd_parser:
-	intel_gvt_clean_cmd_parser(gvt);
-out_clean_sched_policy:
-	intel_gvt_clean_sched_policy(gvt);
-out_clean_workload_scheduler:
-	intel_gvt_clean_workload_scheduler(gvt);
-out_clean_gtt:
-	intel_gvt_clean_gtt(gvt);
-out_free_firmware:
-	intel_gvt_free_firmware(gvt);
-out_clean_mmio_info:
-	intel_gvt_clean_mmio_info(gvt);
-out_clean_idr:
-	idr_destroy(&gvt->vgpu_idr);
-	kfree(gvt);
-	i915->gvt = NULL;
-	return ret;
-}
-
-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);
-}
-
-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,
-};
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index c32e8eb199f10..03ecffc2ba56a 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -765,12 +765,6 @@ int intel_gvt_dma_map_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
 void intel_gvt_dma_unmap_guest_page(struct intel_vgpu *vgpu,
 		dma_addr_t dma_addr);
 
-int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt);
-void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt);
-
 #include "trace.h"
 
-extern const struct intel_vgpu_ops intel_gvt_vgpu_ops;
-extern const struct mdev_parent_ops intel_vgpu_mdev_ops;
-
 #endif
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 4113f850bf92d..f033031c676da 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1,7 +1,7 @@
 /*
  * KVMGT - the implementation of Intel mediated pass-through framework for KVM
  *
- * Copyright(c) 2014-2016 Intel Corporation. All rights reserved.
+ * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,11 @@
  *    Kevin Tian <kevin.tian@intel.com>
  *    Jike Song <jike.song@intel.com>
  *    Xiaoguang Chen <xiaoguang.chen@intel.com>
+ *    Eddie Dong <eddie.dong@intel.com>
+ *
+ * Contributors:
+ *    Niu Bing <bing.niu@intel.com>
+ *    Zhi Wang <zhi.a.wang@intel.com>
  */
 
 #include <linux/init.h>
@@ -182,7 +187,7 @@ static struct attribute_group *gvt_vgpu_type_groups[] = {
 	[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
 };
 
-int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
+static int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
 {
 	int i, j;
 	struct intel_vgpu_type *type;
@@ -211,7 +216,7 @@ int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
 	return -ENOMEM;
 }
 
-void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
+static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
 {
 	int i;
 	struct attribute_group *group;
@@ -1720,7 +1725,7 @@ static struct mdev_driver intel_vgpu_mdev_driver = {
 	.remove		= intel_vgpu_remove,
 };
 
-const struct mdev_parent_ops intel_vgpu_mdev_ops = {
+static const struct mdev_parent_ops intel_vgpu_mdev_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= gvt_vgpu_type_groups,
 	.device_driver		= &intel_vgpu_mdev_driver,
@@ -1925,6 +1930,257 @@ void intel_gvt_dma_unmap_guest_page(struct intel_vgpu *vgpu,
 	mutex_unlock(&vgpu->cache_lock);
 }
 
+static void init_device_info(struct intel_gvt *gvt)
+{
+	struct intel_gvt_device_info *info = &gvt->device_info;
+	struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
+
+	info->max_support_vgpus = 8;
+	info->cfg_space_size = PCI_CFG_SPACE_EXP_SIZE;
+	info->mmio_size = 2 * 1024 * 1024;
+	info->mmio_bar = 0;
+	info->gtt_start_offset = 8 * 1024 * 1024;
+	info->gtt_entry_size = 8;
+	info->gtt_entry_size_shift = 3;
+	info->gmadr_bytes_in_cmd = 8;
+	info->max_surface_size = 36 * 1024 * 1024;
+	info->msi_cap_offset = pdev->msi_cap;
+}
+
+static void intel_gvt_test_and_emulate_vblank(struct intel_gvt *gvt)
+{
+	struct intel_vgpu *vgpu;
+	int id;
+
+	mutex_lock(&gvt->lock);
+	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) {
+		if (test_and_clear_bit(INTEL_GVT_REQUEST_EMULATE_VBLANK + id,
+				       (void *)&gvt->service_request)) {
+			if (vgpu->active)
+				intel_vgpu_emulate_vblank(vgpu);
+		}
+	}
+	mutex_unlock(&gvt->lock);
+}
+
+static int gvt_service_thread(void *data)
+{
+	struct intel_gvt *gvt = (struct intel_gvt *)data;
+	int ret;
+
+	gvt_dbg_core("service thread start\n");
+
+	while (!kthread_should_stop()) {
+		ret = wait_event_interruptible(gvt->service_thread_wq,
+				kthread_should_stop() || gvt->service_request);
+
+		if (kthread_should_stop())
+			break;
+
+		if (WARN_ONCE(ret, "service thread is waken up by signal.\n"))
+			continue;
+
+		intel_gvt_test_and_emulate_vblank(gvt);
+
+		if (test_bit(INTEL_GVT_REQUEST_SCHED,
+				(void *)&gvt->service_request) ||
+			test_bit(INTEL_GVT_REQUEST_EVENT_SCHED,
+					(void *)&gvt->service_request)) {
+			intel_gvt_schedule(gvt);
+		}
+	}
+
+	return 0;
+}
+
+static void clean_service_thread(struct intel_gvt *gvt)
+{
+	kthread_stop(gvt->service_thread);
+}
+
+static int init_service_thread(struct intel_gvt *gvt)
+{
+	init_waitqueue_head(&gvt->service_thread_wq);
+
+	gvt->service_thread = kthread_run(gvt_service_thread,
+			gvt, "gvt_service_thread");
+	if (IS_ERR(gvt->service_thread)) {
+		gvt_err("fail to start service thread.\n");
+		return PTR_ERR(gvt->service_thread);
+	}
+	return 0;
+}
+
+/**
+ * intel_gvt_clean_device - clean a GVT device
+ * @i915: i915 private
+ *
+ * This function is called at the driver unloading stage, to free the
+ * resources owned by a GVT device.
+ *
+ */
+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;
+
+	mdev_unregister_device(i915->drm.dev);
+	intel_gvt_cleanup_vgpu_type_groups(gvt);
+	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
+	intel_gvt_clean_vgpu_types(gvt);
+
+	intel_gvt_debugfs_clean(gvt);
+	clean_service_thread(gvt);
+	intel_gvt_clean_cmd_parser(gvt);
+	intel_gvt_clean_sched_policy(gvt);
+	intel_gvt_clean_workload_scheduler(gvt);
+	intel_gvt_clean_gtt(gvt);
+	intel_gvt_free_firmware(gvt);
+	intel_gvt_clean_mmio_info(gvt);
+	idr_destroy(&gvt->vgpu_idr);
+
+	kfree(i915->gvt);
+}
+
+/**
+ * intel_gvt_init_device - initialize a GVT device
+ * @i915: drm i915 private data
+ *
+ * This function is called at the initialization stage, to initialize
+ * necessary GVT components.
+ *
+ * Returns:
+ * Zero on success, negative error code if failed.
+ *
+ */
+static int intel_gvt_init_device(struct drm_i915_private *i915)
+{
+	struct intel_gvt *gvt;
+	struct intel_vgpu *vgpu;
+	int ret;
+
+	if (drm_WARN_ON(&i915->drm, i915->gvt))
+		return -EEXIST;
+
+	gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
+	if (!gvt)
+		return -ENOMEM;
+
+	gvt_dbg_core("init gvt device\n");
+
+	idr_init_base(&gvt->vgpu_idr, 1);
+	spin_lock_init(&gvt->scheduler.mmio_context_lock);
+	mutex_init(&gvt->lock);
+	mutex_init(&gvt->sched_lock);
+	gvt->gt = to_gt(i915);
+	i915->gvt = gvt;
+
+	init_device_info(gvt);
+
+	ret = intel_gvt_setup_mmio_info(gvt);
+	if (ret)
+		goto out_clean_idr;
+
+	intel_gvt_init_engine_mmio_context(gvt);
+
+	ret = intel_gvt_load_firmware(gvt);
+	if (ret)
+		goto out_clean_mmio_info;
+
+	ret = intel_gvt_init_irq(gvt);
+	if (ret)
+		goto out_free_firmware;
+
+	ret = intel_gvt_init_gtt(gvt);
+	if (ret)
+		goto out_free_firmware;
+
+	ret = intel_gvt_init_workload_scheduler(gvt);
+	if (ret)
+		goto out_clean_gtt;
+
+	ret = intel_gvt_init_sched_policy(gvt);
+	if (ret)
+		goto out_clean_workload_scheduler;
+
+	ret = intel_gvt_init_cmd_parser(gvt);
+	if (ret)
+		goto out_clean_sched_policy;
+
+	ret = init_service_thread(gvt);
+	if (ret)
+		goto out_clean_cmd_parser;
+
+	ret = intel_gvt_init_vgpu_types(gvt);
+	if (ret)
+		goto out_clean_thread;
+
+	vgpu = intel_gvt_create_idle_vgpu(gvt);
+	if (IS_ERR(vgpu)) {
+		ret = PTR_ERR(vgpu);
+		gvt_err("failed to create idle vgpu\n");
+		goto out_clean_types;
+	}
+	gvt->idle_vgpu = vgpu;
+
+	intel_gvt_debugfs_init(gvt);
+
+	ret = intel_gvt_init_vgpu_type_groups(gvt);
+	if (ret)
+		goto out_destroy_idle_vgpu;
+
+	ret = mdev_register_device(i915->drm.dev, &intel_vgpu_mdev_ops);
+	if (ret)
+		goto out_cleanup_vgpu_type_groups;
+
+	gvt_dbg_core("gvt device initialization is done\n");
+	return 0;
+
+out_cleanup_vgpu_type_groups:
+	intel_gvt_cleanup_vgpu_type_groups(gvt);
+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:
+	clean_service_thread(gvt);
+out_clean_cmd_parser:
+	intel_gvt_clean_cmd_parser(gvt);
+out_clean_sched_policy:
+	intel_gvt_clean_sched_policy(gvt);
+out_clean_workload_scheduler:
+	intel_gvt_clean_workload_scheduler(gvt);
+out_clean_gtt:
+	intel_gvt_clean_gtt(gvt);
+out_free_firmware:
+	intel_gvt_free_firmware(gvt);
+out_clean_mmio_info:
+	intel_gvt_clean_mmio_info(gvt);
+out_clean_idr:
+	idr_destroy(&gvt->vgpu_idr);
+	kfree(gvt);
+	i915->gvt = NULL;
+	return ret;
+}
+
+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);
+}
+
+static 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,
+};
+
 static int __init kvmgt_init(void)
 {
 	int ret;
-- 
2.30.2


WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	Zhi Wang <zhi.a.wang@intel.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
	intel-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 29/34] drm/i915/gvt: merge gvt.c into kvmgvt.c
Date: Mon, 11 Apr 2022 16:13:58 +0200	[thread overview]
Message-ID: <20220411141403.86980-30-hch@lst.de> (raw)
In-Reply-To: <20220411141403.86980-1-hch@lst.de>

The code in both files is deeply interconnected, so merge it and
keep a bunch of structures and functions static.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/gpu/drm/i915/gvt/Makefile |   1 -
 drivers/gpu/drm/i915/gvt/gvt.c    | 291 ------------------------------
 drivers/gpu/drm/i915/gvt/gvt.h    |   6 -
 drivers/gpu/drm/i915/gvt/kvmgt.c  | 264 ++++++++++++++++++++++++++-
 4 files changed, 260 insertions(+), 302 deletions(-)
 delete mode 100644 drivers/gpu/drm/i915/gvt/gvt.c

diff --git a/drivers/gpu/drm/i915/gvt/Makefile b/drivers/gpu/drm/i915/gvt/Makefile
index cecedd9830f7c..2b08192930c18 100644
--- a/drivers/gpu/drm/i915/gvt/Makefile
+++ b/drivers/gpu/drm/i915/gvt/Makefile
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
 kvmgt-y += \
-	gvt/gvt.o \
 	gvt/aperture_gm.o \
 	gvt/handlers.o \
 	gvt/vgpu.o \
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
deleted file mode 100644
index 047fb6c41788b..0000000000000
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Authors:
- *    Kevin Tian <kevin.tian@intel.com>
- *    Eddie Dong <eddie.dong@intel.com>
- *
- * Contributors:
- *    Niu Bing <bing.niu@intel.com>
- *    Zhi Wang <zhi.a.wang@intel.com>
- *
- */
-
-#include <linux/types.h>
-#include <linux/kthread.h>
-
-#include "i915_drv.h"
-#include "intel_gvt.h"
-#include "gvt.h"
-#include <linux/vfio.h>
-#include <linux/mdev.h>
-
-static void init_device_info(struct intel_gvt *gvt)
-{
-	struct intel_gvt_device_info *info = &gvt->device_info;
-	struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
-
-	info->max_support_vgpus = 8;
-	info->cfg_space_size = PCI_CFG_SPACE_EXP_SIZE;
-	info->mmio_size = 2 * 1024 * 1024;
-	info->mmio_bar = 0;
-	info->gtt_start_offset = 8 * 1024 * 1024;
-	info->gtt_entry_size = 8;
-	info->gtt_entry_size_shift = 3;
-	info->gmadr_bytes_in_cmd = 8;
-	info->max_surface_size = 36 * 1024 * 1024;
-	info->msi_cap_offset = pdev->msi_cap;
-}
-
-static void intel_gvt_test_and_emulate_vblank(struct intel_gvt *gvt)
-{
-	struct intel_vgpu *vgpu;
-	int id;
-
-	mutex_lock(&gvt->lock);
-	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) {
-		if (test_and_clear_bit(INTEL_GVT_REQUEST_EMULATE_VBLANK + id,
-				       (void *)&gvt->service_request)) {
-			if (vgpu->active)
-				intel_vgpu_emulate_vblank(vgpu);
-		}
-	}
-	mutex_unlock(&gvt->lock);
-}
-
-static int gvt_service_thread(void *data)
-{
-	struct intel_gvt *gvt = (struct intel_gvt *)data;
-	int ret;
-
-	gvt_dbg_core("service thread start\n");
-
-	while (!kthread_should_stop()) {
-		ret = wait_event_interruptible(gvt->service_thread_wq,
-				kthread_should_stop() || gvt->service_request);
-
-		if (kthread_should_stop())
-			break;
-
-		if (WARN_ONCE(ret, "service thread is waken up by signal.\n"))
-			continue;
-
-		intel_gvt_test_and_emulate_vblank(gvt);
-
-		if (test_bit(INTEL_GVT_REQUEST_SCHED,
-				(void *)&gvt->service_request) ||
-			test_bit(INTEL_GVT_REQUEST_EVENT_SCHED,
-					(void *)&gvt->service_request)) {
-			intel_gvt_schedule(gvt);
-		}
-	}
-
-	return 0;
-}
-
-static void clean_service_thread(struct intel_gvt *gvt)
-{
-	kthread_stop(gvt->service_thread);
-}
-
-static int init_service_thread(struct intel_gvt *gvt)
-{
-	init_waitqueue_head(&gvt->service_thread_wq);
-
-	gvt->service_thread = kthread_run(gvt_service_thread,
-			gvt, "gvt_service_thread");
-	if (IS_ERR(gvt->service_thread)) {
-		gvt_err("fail to start service thread.\n");
-		return PTR_ERR(gvt->service_thread);
-	}
-	return 0;
-}
-
-/**
- * intel_gvt_clean_device - clean a GVT device
- * @i915: i915 private
- *
- * This function is called at the driver unloading stage, to free the
- * resources owned by a GVT device.
- *
- */
-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;
-
-	mdev_unregister_device(i915->drm.dev);
-	intel_gvt_cleanup_vgpu_type_groups(gvt);
-	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
-	intel_gvt_clean_vgpu_types(gvt);
-
-	intel_gvt_debugfs_clean(gvt);
-	clean_service_thread(gvt);
-	intel_gvt_clean_cmd_parser(gvt);
-	intel_gvt_clean_sched_policy(gvt);
-	intel_gvt_clean_workload_scheduler(gvt);
-	intel_gvt_clean_gtt(gvt);
-	intel_gvt_free_firmware(gvt);
-	intel_gvt_clean_mmio_info(gvt);
-	idr_destroy(&gvt->vgpu_idr);
-
-	kfree(i915->gvt);
-}
-
-/**
- * intel_gvt_init_device - initialize a GVT device
- * @i915: drm i915 private data
- *
- * This function is called at the initialization stage, to initialize
- * necessary GVT components.
- *
- * Returns:
- * Zero on success, negative error code if failed.
- *
- */
-static int intel_gvt_init_device(struct drm_i915_private *i915)
-{
-	struct intel_gvt *gvt;
-	struct intel_vgpu *vgpu;
-	int ret;
-
-	if (drm_WARN_ON(&i915->drm, i915->gvt))
-		return -EEXIST;
-
-	gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
-	if (!gvt)
-		return -ENOMEM;
-
-	gvt_dbg_core("init gvt device\n");
-
-	idr_init_base(&gvt->vgpu_idr, 1);
-	spin_lock_init(&gvt->scheduler.mmio_context_lock);
-	mutex_init(&gvt->lock);
-	mutex_init(&gvt->sched_lock);
-	gvt->gt = to_gt(i915);
-	i915->gvt = gvt;
-
-	init_device_info(gvt);
-
-	ret = intel_gvt_setup_mmio_info(gvt);
-	if (ret)
-		goto out_clean_idr;
-
-	intel_gvt_init_engine_mmio_context(gvt);
-
-	ret = intel_gvt_load_firmware(gvt);
-	if (ret)
-		goto out_clean_mmio_info;
-
-	ret = intel_gvt_init_irq(gvt);
-	if (ret)
-		goto out_free_firmware;
-
-	ret = intel_gvt_init_gtt(gvt);
-	if (ret)
-		goto out_free_firmware;
-
-	ret = intel_gvt_init_workload_scheduler(gvt);
-	if (ret)
-		goto out_clean_gtt;
-
-	ret = intel_gvt_init_sched_policy(gvt);
-	if (ret)
-		goto out_clean_workload_scheduler;
-
-	ret = intel_gvt_init_cmd_parser(gvt);
-	if (ret)
-		goto out_clean_sched_policy;
-
-	ret = init_service_thread(gvt);
-	if (ret)
-		goto out_clean_cmd_parser;
-
-	ret = intel_gvt_init_vgpu_types(gvt);
-	if (ret)
-		goto out_clean_thread;
-
-	vgpu = intel_gvt_create_idle_vgpu(gvt);
-	if (IS_ERR(vgpu)) {
-		ret = PTR_ERR(vgpu);
-		gvt_err("failed to create idle vgpu\n");
-		goto out_clean_types;
-	}
-	gvt->idle_vgpu = vgpu;
-
-	intel_gvt_debugfs_init(gvt);
-
-	ret = intel_gvt_init_vgpu_type_groups(gvt);
-	if (ret)
-		goto out_destroy_idle_vgpu;
-
-	ret = mdev_register_device(i915->drm.dev, &intel_vgpu_mdev_ops);
-	if (ret)
-		goto out_cleanup_vgpu_type_groups;
-
-	gvt_dbg_core("gvt device initialization is done\n");
-	return 0;
-
-out_cleanup_vgpu_type_groups:
-	intel_gvt_cleanup_vgpu_type_groups(gvt);
-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:
-	clean_service_thread(gvt);
-out_clean_cmd_parser:
-	intel_gvt_clean_cmd_parser(gvt);
-out_clean_sched_policy:
-	intel_gvt_clean_sched_policy(gvt);
-out_clean_workload_scheduler:
-	intel_gvt_clean_workload_scheduler(gvt);
-out_clean_gtt:
-	intel_gvt_clean_gtt(gvt);
-out_free_firmware:
-	intel_gvt_free_firmware(gvt);
-out_clean_mmio_info:
-	intel_gvt_clean_mmio_info(gvt);
-out_clean_idr:
-	idr_destroy(&gvt->vgpu_idr);
-	kfree(gvt);
-	i915->gvt = NULL;
-	return ret;
-}
-
-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);
-}
-
-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,
-};
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index c32e8eb199f10..03ecffc2ba56a 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -765,12 +765,6 @@ int intel_gvt_dma_map_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
 void intel_gvt_dma_unmap_guest_page(struct intel_vgpu *vgpu,
 		dma_addr_t dma_addr);
 
-int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt);
-void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt);
-
 #include "trace.h"
 
-extern const struct intel_vgpu_ops intel_gvt_vgpu_ops;
-extern const struct mdev_parent_ops intel_vgpu_mdev_ops;
-
 #endif
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 4113f850bf92d..f033031c676da 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1,7 +1,7 @@
 /*
  * KVMGT - the implementation of Intel mediated pass-through framework for KVM
  *
- * Copyright(c) 2014-2016 Intel Corporation. All rights reserved.
+ * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,11 @@
  *    Kevin Tian <kevin.tian@intel.com>
  *    Jike Song <jike.song@intel.com>
  *    Xiaoguang Chen <xiaoguang.chen@intel.com>
+ *    Eddie Dong <eddie.dong@intel.com>
+ *
+ * Contributors:
+ *    Niu Bing <bing.niu@intel.com>
+ *    Zhi Wang <zhi.a.wang@intel.com>
  */
 
 #include <linux/init.h>
@@ -182,7 +187,7 @@ static struct attribute_group *gvt_vgpu_type_groups[] = {
 	[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
 };
 
-int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
+static int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
 {
 	int i, j;
 	struct intel_vgpu_type *type;
@@ -211,7 +216,7 @@ int intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
 	return -ENOMEM;
 }
 
-void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
+static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
 {
 	int i;
 	struct attribute_group *group;
@@ -1720,7 +1725,7 @@ static struct mdev_driver intel_vgpu_mdev_driver = {
 	.remove		= intel_vgpu_remove,
 };
 
-const struct mdev_parent_ops intel_vgpu_mdev_ops = {
+static const struct mdev_parent_ops intel_vgpu_mdev_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= gvt_vgpu_type_groups,
 	.device_driver		= &intel_vgpu_mdev_driver,
@@ -1925,6 +1930,257 @@ void intel_gvt_dma_unmap_guest_page(struct intel_vgpu *vgpu,
 	mutex_unlock(&vgpu->cache_lock);
 }
 
+static void init_device_info(struct intel_gvt *gvt)
+{
+	struct intel_gvt_device_info *info = &gvt->device_info;
+	struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
+
+	info->max_support_vgpus = 8;
+	info->cfg_space_size = PCI_CFG_SPACE_EXP_SIZE;
+	info->mmio_size = 2 * 1024 * 1024;
+	info->mmio_bar = 0;
+	info->gtt_start_offset = 8 * 1024 * 1024;
+	info->gtt_entry_size = 8;
+	info->gtt_entry_size_shift = 3;
+	info->gmadr_bytes_in_cmd = 8;
+	info->max_surface_size = 36 * 1024 * 1024;
+	info->msi_cap_offset = pdev->msi_cap;
+}
+
+static void intel_gvt_test_and_emulate_vblank(struct intel_gvt *gvt)
+{
+	struct intel_vgpu *vgpu;
+	int id;
+
+	mutex_lock(&gvt->lock);
+	idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) {
+		if (test_and_clear_bit(INTEL_GVT_REQUEST_EMULATE_VBLANK + id,
+				       (void *)&gvt->service_request)) {
+			if (vgpu->active)
+				intel_vgpu_emulate_vblank(vgpu);
+		}
+	}
+	mutex_unlock(&gvt->lock);
+}
+
+static int gvt_service_thread(void *data)
+{
+	struct intel_gvt *gvt = (struct intel_gvt *)data;
+	int ret;
+
+	gvt_dbg_core("service thread start\n");
+
+	while (!kthread_should_stop()) {
+		ret = wait_event_interruptible(gvt->service_thread_wq,
+				kthread_should_stop() || gvt->service_request);
+
+		if (kthread_should_stop())
+			break;
+
+		if (WARN_ONCE(ret, "service thread is waken up by signal.\n"))
+			continue;
+
+		intel_gvt_test_and_emulate_vblank(gvt);
+
+		if (test_bit(INTEL_GVT_REQUEST_SCHED,
+				(void *)&gvt->service_request) ||
+			test_bit(INTEL_GVT_REQUEST_EVENT_SCHED,
+					(void *)&gvt->service_request)) {
+			intel_gvt_schedule(gvt);
+		}
+	}
+
+	return 0;
+}
+
+static void clean_service_thread(struct intel_gvt *gvt)
+{
+	kthread_stop(gvt->service_thread);
+}
+
+static int init_service_thread(struct intel_gvt *gvt)
+{
+	init_waitqueue_head(&gvt->service_thread_wq);
+
+	gvt->service_thread = kthread_run(gvt_service_thread,
+			gvt, "gvt_service_thread");
+	if (IS_ERR(gvt->service_thread)) {
+		gvt_err("fail to start service thread.\n");
+		return PTR_ERR(gvt->service_thread);
+	}
+	return 0;
+}
+
+/**
+ * intel_gvt_clean_device - clean a GVT device
+ * @i915: i915 private
+ *
+ * This function is called at the driver unloading stage, to free the
+ * resources owned by a GVT device.
+ *
+ */
+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;
+
+	mdev_unregister_device(i915->drm.dev);
+	intel_gvt_cleanup_vgpu_type_groups(gvt);
+	intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
+	intel_gvt_clean_vgpu_types(gvt);
+
+	intel_gvt_debugfs_clean(gvt);
+	clean_service_thread(gvt);
+	intel_gvt_clean_cmd_parser(gvt);
+	intel_gvt_clean_sched_policy(gvt);
+	intel_gvt_clean_workload_scheduler(gvt);
+	intel_gvt_clean_gtt(gvt);
+	intel_gvt_free_firmware(gvt);
+	intel_gvt_clean_mmio_info(gvt);
+	idr_destroy(&gvt->vgpu_idr);
+
+	kfree(i915->gvt);
+}
+
+/**
+ * intel_gvt_init_device - initialize a GVT device
+ * @i915: drm i915 private data
+ *
+ * This function is called at the initialization stage, to initialize
+ * necessary GVT components.
+ *
+ * Returns:
+ * Zero on success, negative error code if failed.
+ *
+ */
+static int intel_gvt_init_device(struct drm_i915_private *i915)
+{
+	struct intel_gvt *gvt;
+	struct intel_vgpu *vgpu;
+	int ret;
+
+	if (drm_WARN_ON(&i915->drm, i915->gvt))
+		return -EEXIST;
+
+	gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
+	if (!gvt)
+		return -ENOMEM;
+
+	gvt_dbg_core("init gvt device\n");
+
+	idr_init_base(&gvt->vgpu_idr, 1);
+	spin_lock_init(&gvt->scheduler.mmio_context_lock);
+	mutex_init(&gvt->lock);
+	mutex_init(&gvt->sched_lock);
+	gvt->gt = to_gt(i915);
+	i915->gvt = gvt;
+
+	init_device_info(gvt);
+
+	ret = intel_gvt_setup_mmio_info(gvt);
+	if (ret)
+		goto out_clean_idr;
+
+	intel_gvt_init_engine_mmio_context(gvt);
+
+	ret = intel_gvt_load_firmware(gvt);
+	if (ret)
+		goto out_clean_mmio_info;
+
+	ret = intel_gvt_init_irq(gvt);
+	if (ret)
+		goto out_free_firmware;
+
+	ret = intel_gvt_init_gtt(gvt);
+	if (ret)
+		goto out_free_firmware;
+
+	ret = intel_gvt_init_workload_scheduler(gvt);
+	if (ret)
+		goto out_clean_gtt;
+
+	ret = intel_gvt_init_sched_policy(gvt);
+	if (ret)
+		goto out_clean_workload_scheduler;
+
+	ret = intel_gvt_init_cmd_parser(gvt);
+	if (ret)
+		goto out_clean_sched_policy;
+
+	ret = init_service_thread(gvt);
+	if (ret)
+		goto out_clean_cmd_parser;
+
+	ret = intel_gvt_init_vgpu_types(gvt);
+	if (ret)
+		goto out_clean_thread;
+
+	vgpu = intel_gvt_create_idle_vgpu(gvt);
+	if (IS_ERR(vgpu)) {
+		ret = PTR_ERR(vgpu);
+		gvt_err("failed to create idle vgpu\n");
+		goto out_clean_types;
+	}
+	gvt->idle_vgpu = vgpu;
+
+	intel_gvt_debugfs_init(gvt);
+
+	ret = intel_gvt_init_vgpu_type_groups(gvt);
+	if (ret)
+		goto out_destroy_idle_vgpu;
+
+	ret = mdev_register_device(i915->drm.dev, &intel_vgpu_mdev_ops);
+	if (ret)
+		goto out_cleanup_vgpu_type_groups;
+
+	gvt_dbg_core("gvt device initialization is done\n");
+	return 0;
+
+out_cleanup_vgpu_type_groups:
+	intel_gvt_cleanup_vgpu_type_groups(gvt);
+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:
+	clean_service_thread(gvt);
+out_clean_cmd_parser:
+	intel_gvt_clean_cmd_parser(gvt);
+out_clean_sched_policy:
+	intel_gvt_clean_sched_policy(gvt);
+out_clean_workload_scheduler:
+	intel_gvt_clean_workload_scheduler(gvt);
+out_clean_gtt:
+	intel_gvt_clean_gtt(gvt);
+out_free_firmware:
+	intel_gvt_free_firmware(gvt);
+out_clean_mmio_info:
+	intel_gvt_clean_mmio_info(gvt);
+out_clean_idr:
+	idr_destroy(&gvt->vgpu_idr);
+	kfree(gvt);
+	i915->gvt = NULL;
+	return ret;
+}
+
+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);
+}
+
+static 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,
+};
+
 static int __init kvmgt_init(void)
 {
 	int ret;
-- 
2.30.2


  parent reply	other threads:[~2022-04-11 14:15 UTC|newest]

Thread overview: 243+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 14:13 refactor the i915 GVT support and move to the modern mdev API v3 Christoph Hellwig
2022-04-11 14:13 ` [Intel-gfx] " Christoph Hellwig
2022-04-11 14:13 ` [PATCH 01/34] drm/i915/gvt: remove module refcounting in intel_gvt_{,un}register_hypervisor Christoph Hellwig
2022-04-11 14:13   ` [Intel-gfx] [PATCH 01/34] drm/i915/gvt: remove module refcounting in intel_gvt_{, un}register_hypervisor Christoph Hellwig
2022-04-11 14:13 ` [PATCH 02/34] drm/i915/gvt: remove enum hypervisor_type Christoph Hellwig
2022-04-11 14:13   ` [Intel-gfx] " Christoph Hellwig
2022-04-11 15:23   ` Jason Gunthorpe
2022-04-11 15:23     ` Jason Gunthorpe
2022-04-11 15:23     ` Jason Gunthorpe
2022-04-11 14:13 ` [PATCH 03/34] drm/i915/gvt: rename intel_vgpu_ops to intel_vgpu_mdev_ops Christoph Hellwig
2022-04-11 14:13   ` [Intel-gfx] " Christoph Hellwig
2022-04-11 15:23   ` Jason Gunthorpe
2022-04-11 15:23     ` Jason Gunthorpe
2022-04-11 15:23     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 14:13 ` [PATCH 04/34] drm/i915/gvt: don't override the include path Christoph Hellwig
2022-04-11 14:13   ` [Intel-gfx] " Christoph Hellwig
2022-04-11 15:24   ` Jason Gunthorpe
2022-04-11 15:24     ` Jason Gunthorpe
2022-04-11 15:24     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:09   ` Jani Nikula
2022-04-11 16:09     ` Jani Nikula
2022-04-11 16:09     ` [Intel-gfx] " Jani Nikula
2022-04-11 14:13 ` [PATCH 05/34] drm/i915/gvt: cleanup the Makefile Christoph Hellwig
2022-04-11 14:13   ` [Intel-gfx] " Christoph Hellwig
2022-04-11 15:25   ` Jason Gunthorpe
2022-04-11 15:25     ` Jason Gunthorpe
2022-04-11 15:25     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:11     ` Jani Nikula
2022-04-11 16:11       ` Jani Nikula
2022-04-11 16:11       ` [Intel-gfx] " Jani Nikula
2022-04-11 16:51       ` Christoph Hellwig
2022-04-11 16:51         ` [Intel-gfx] " Christoph Hellwig
2022-04-13 12:33         ` Jani Nikula
2022-04-13 12:33           ` [Intel-gfx] " Jani Nikula
2022-04-13 12:33           ` Jani Nikula
2022-04-13 13:39           ` Wang, Zhi A
2022-04-13 13:39             ` [Intel-gfx] " Wang, Zhi A
2022-04-13 13:39             ` Wang, Zhi A
2022-04-13 13:43             ` Jason Gunthorpe
2022-04-13 13:43               ` [Intel-gfx] " Jason Gunthorpe
2022-04-13 13:43               ` Jason Gunthorpe
2022-04-13 14:26               ` Wang, Zhi A
2022-04-13 14:26                 ` [Intel-gfx] " Wang, Zhi A
2022-04-13 14:26                 ` Wang, Zhi A
2022-04-13 14:45                 ` Jason Gunthorpe
2022-04-13 14:45                   ` [Intel-gfx] " Jason Gunthorpe
2022-04-13 14:45                   ` Jason Gunthorpe
2022-04-21  6:40                   ` Joonas Lahtinen
2022-04-21  6:40                     ` [Intel-gfx] " Joonas Lahtinen
2022-04-21  6:40                     ` Joonas Lahtinen
2022-04-11 14:13 ` [Intel-gfx] [PATCH 06/34] drm/i915/gvt: move the gvt code into kvmgt.ko Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:43   ` Jason Gunthorpe
2022-04-11 18:43     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:43     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 07/34] drm/i915/gvt: remove intel_gvt_ops Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 15:32   ` Jason Gunthorpe
2022-04-11 15:32     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 15:32     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 08/34] drm/i915/gvt: remove the map_gfn_to_mfn and set_trap_area ops Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:00   ` Jason Gunthorpe
2022-04-11 16:00     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:00     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 09/34] drm/i915/gvt: remove the unused from_virt_to_mfn op Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:00   ` Jason Gunthorpe
2022-04-11 16:00     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:00     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 10/34] drm/i915/gvt: merge struct kvmgt_vdev into struct intel_vgpu Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:12   ` Jason Gunthorpe
2022-04-11 16:12     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:12     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 11/34] drm/i915/gvt: merge struct kvmgt_guest_info into strut intel_vgpu Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:13   ` Jason Gunthorpe
2022-04-11 16:13     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:13     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 12/34] drm/i915/gvt: remove vgpu->handle Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:14   ` Jason Gunthorpe
2022-04-11 16:14     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:14     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 13/34] drm/i915/gvt: devirtualize ->{read, write}_gpa Christoph Hellwig
2022-04-11 14:13   ` [PATCH 13/34] drm/i915/gvt: devirtualize ->{read,write}_gpa Christoph Hellwig
2022-04-11 16:15   ` Jason Gunthorpe
2022-04-11 16:15     ` [Intel-gfx] [PATCH 13/34] drm/i915/gvt: devirtualize ->{read, write}_gpa Jason Gunthorpe
2022-04-11 16:15     ` [PATCH 13/34] drm/i915/gvt: devirtualize ->{read,write}_gpa Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 14/34] drm/i915/gvt: devirtualize ->{get, put}_vfio_device Christoph Hellwig
2022-04-11 14:13   ` [PATCH 14/34] drm/i915/gvt: devirtualize ->{get,put}_vfio_device Christoph Hellwig
2022-04-11 16:26   ` Jason Gunthorpe
2022-04-11 16:26     ` Jason Gunthorpe
2022-04-11 16:26     ` [Intel-gfx] [PATCH 14/34] drm/i915/gvt: devirtualize ->{get, put}_vfio_device Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 15/34] drm/i915/gvt: devirtualize ->set_edid and ->set_opregion Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:27   ` Jason Gunthorpe
2022-04-11 16:27     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:27     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 16/34] drm/i915/gvt: devirtualize ->detach_vgpu Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:27   ` Jason Gunthorpe
2022-04-11 16:27     ` Jason Gunthorpe
2022-04-11 16:27     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 17/34] drm/i915/gvt: devirtualize ->inject_msi Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:28   ` Jason Gunthorpe
2022-04-11 16:28     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:28     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 18/34] drm/i915/gvt: devirtualize ->is_valid_gfn Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:29   ` Jason Gunthorpe
2022-04-11 16:29     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 16:29     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 19/34] drm/i915/gvt: devirtualize ->gfn_to_mfn Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 16:29   ` Jason Gunthorpe
2022-04-11 16:29     ` Jason Gunthorpe
2022-04-11 16:29     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 20/34] drm/i915/gvt: devirtualize ->{enable, disable}_page_track Christoph Hellwig
2022-04-11 14:13   ` [PATCH 20/34] drm/i915/gvt: devirtualize ->{enable,disable}_page_track Christoph Hellwig
2022-04-11 16:31   ` Jason Gunthorpe
2022-04-11 16:31     ` [Intel-gfx] [PATCH 20/34] drm/i915/gvt: devirtualize ->{enable, disable}_page_track Jason Gunthorpe
2022-04-11 16:31     ` [PATCH 20/34] drm/i915/gvt: devirtualize ->{enable,disable}_page_track Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 21/34] drm/i915/gvt: devirtualize ->dma_{, un}map_guest_page Christoph Hellwig
2022-04-11 14:13   ` [PATCH 21/34] drm/i915/gvt: devirtualize ->dma_{,un}map_guest_page Christoph Hellwig
2022-04-11 18:08   ` Jason Gunthorpe
2022-04-11 18:08     ` [Intel-gfx] [PATCH 21/34] drm/i915/gvt: devirtualize ->dma_{, un}map_guest_page Jason Gunthorpe
2022-04-11 18:08     ` [PATCH 21/34] drm/i915/gvt: devirtualize ->dma_{,un}map_guest_page Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 22/34] drm/i915/gvt: devirtualize dma_pin_guest_page Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:09   ` Jason Gunthorpe
2022-04-11 18:09     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:09     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 23/34] drm/i915/gvt: remove struct intel_gvt_mpt Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:13   ` Jason Gunthorpe
2022-04-11 18:13     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:13     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 24/34] drm/i915/gvt: remove the extra vfio_device refcounting for dmabufs Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:33   ` Jason Gunthorpe
2022-04-11 18:33     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:33     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 25/34] drm/i915/gvt: streamline intel_vgpu_create Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:37   ` Jason Gunthorpe
2022-04-11 18:37     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:37     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 26/34] drm/i915/gvt: pass a struct intel_vgpu to the vfio read/write helpers Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:38   ` Jason Gunthorpe
2022-04-11 18:38     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:38     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 27/34] drm/i915/gvt: remove kvmgt_guest_{init, exit} Christoph Hellwig
2022-04-11 14:13   ` [PATCH 27/34] drm/i915/gvt: remove kvmgt_guest_{init,exit} Christoph Hellwig
2022-04-11 18:41   ` Jason Gunthorpe
2022-04-11 18:41     ` [Intel-gfx] [PATCH 27/34] drm/i915/gvt: remove kvmgt_guest_{init, exit} Jason Gunthorpe
2022-04-11 18:41     ` [PATCH 27/34] drm/i915/gvt: remove kvmgt_guest_{init,exit} Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 28/34] drm/i915/gvt: convert to use vfio_register_emulated_iommu_dev Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-11 18:36   ` Jason Gunthorpe
2022-04-11 18:36     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:36     ` Jason Gunthorpe
2022-04-11 14:13 ` Christoph Hellwig [this message]
2022-04-11 14:13   ` [PATCH 29/34] drm/i915/gvt: merge gvt.c into kvmgvt.c Christoph Hellwig
2022-04-11 18:42   ` Jason Gunthorpe
2022-04-11 18:42     ` [Intel-gfx] " Jason Gunthorpe
2022-04-11 18:42     ` Jason Gunthorpe
2022-04-11 14:13 ` [Intel-gfx] [PATCH 30/34] vfio/mdev: Remove vfio_mdev.c Christoph Hellwig
2022-04-11 14:13   ` Christoph Hellwig
2022-04-12 20:51   ` Kirti Wankhede
2022-04-12 20:51     ` Kirti Wankhede
2022-04-12 20:51     ` [Intel-gfx] " Kirti Wankhede
2022-04-11 14:14 ` [Intel-gfx] [PATCH 31/34] vfio/mdev: Remove mdev_parent_ops dev_attr_groups Christoph Hellwig
2022-04-11 14:14   ` Christoph Hellwig
2022-04-12 20:51   ` Kirti Wankhede
2022-04-12 20:51     ` Kirti Wankhede
2022-04-12 20:51     ` [Intel-gfx] " Kirti Wankhede
2022-04-11 14:14 ` [Intel-gfx] [PATCH 32/34] vfio/mdev: Remove mdev_parent_ops Christoph Hellwig
2022-04-11 14:14   ` Christoph Hellwig
2022-04-12 20:51   ` Kirti Wankhede
2022-04-12 20:51     ` Kirti Wankhede
2022-04-12 20:51     ` [Intel-gfx] " Kirti Wankhede
2022-04-11 14:14 ` [Intel-gfx] [PATCH 33/34] vfio/mdev: Use the driver core to create the 'remove' file Christoph Hellwig
2022-04-11 14:14   ` Christoph Hellwig
2022-04-12 20:52   ` Kirti Wankhede
2022-04-12 20:52     ` Kirti Wankhede
2022-04-12 20:52     ` [Intel-gfx] " Kirti Wankhede
2022-04-11 14:14 ` [Intel-gfx] [PATCH 34/34] vfio/mdev: Remove mdev drvdata Christoph Hellwig
2022-04-11 14:14   ` Christoph Hellwig
2022-04-12 20:52   ` Kirti Wankhede
2022-04-12 20:52     ` Kirti Wankhede
2022-04-12 20:52     ` [Intel-gfx] " Kirti Wankhede
2022-04-13 13:47 ` refactor the i915 GVT support and move to the modern mdev API v3 Wang, Zhi A
2022-04-13 13:47   ` [Intel-gfx] " Wang, Zhi A
2022-04-13 13:47   ` Wang, Zhi A
2022-04-13 15:46   ` Christoph Hellwig
2022-04-13 15:46     ` [Intel-gfx] " Christoph Hellwig
2022-04-13 15:58     ` Jani Nikula
2022-04-13 15:58       ` [Intel-gfx] " Jani Nikula
2022-04-13 15:58       ` Jani Nikula
2022-04-13 16:27       ` Christoph Hellwig
2022-04-13 16:27         ` [Intel-gfx] " Christoph Hellwig
2022-04-13 23:13       ` Wang, Zhi A
2022-04-13 23:13         ` [Intel-gfx] " Wang, Zhi A
2022-04-13 23:13         ` Wang, Zhi A
2022-04-13 23:20         ` Jason Gunthorpe
2022-04-13 23:20           ` [Intel-gfx] " Jason Gunthorpe
2022-04-13 23:20           ` Jason Gunthorpe
2022-04-14 12:20           ` Wang, Zhi A
2022-04-14 12:20             ` Wang, Zhi A
2022-04-14 12:20             ` [Intel-gfx] " Wang, Zhi A
2022-04-14 13:34             ` Jason Gunthorpe
2022-04-14 13:34               ` Jason Gunthorpe
2022-04-14 13:34               ` [Intel-gfx] " Jason Gunthorpe
2022-04-14 13:39               ` Wang, Zhi A
2022-04-14 13:39                 ` Wang, Zhi A
2022-04-14 13:39                 ` [Intel-gfx] " Wang, Zhi A
2022-04-14 13:41                 ` Jason Gunthorpe
2022-04-14 13:41                   ` Jason Gunthorpe
2022-04-14 13:41                   ` [Intel-gfx] " Jason Gunthorpe
2022-04-14 13:44                   ` Jani Nikula
2022-04-14 13:44                     ` Jani Nikula
2022-04-14 13:44                     ` [Intel-gfx] " Jani Nikula
2022-04-14 13:40               ` Jani Nikula
2022-04-14 13:40                 ` Jani Nikula
2022-04-14 13:40                 ` [Intel-gfx] " Jani Nikula
2022-04-14 13:43                 ` Jason Gunthorpe
2022-04-14 13:43                   ` Jason Gunthorpe
2022-04-14 13:43                   ` [Intel-gfx] " Jason Gunthorpe
2022-04-14 14:25                   ` Wang, Zhi A
2022-04-14 14:25                     ` Wang, Zhi A
2022-04-14 14:25                     ` [Intel-gfx] " Wang, Zhi A
2022-04-14 14:38                     ` Jason Gunthorpe
2022-04-14 14:38                       ` Jason Gunthorpe
2022-04-14 14:38                       ` [Intel-gfx] " Jason Gunthorpe
2022-04-20  7:08                       ` Christoph Hellwig
2022-04-20  7:08                         ` [Intel-gfx] " Christoph Hellwig
2022-04-20  7:12                         ` Wang, Zhi A
2022-04-20  7:12                           ` [Intel-gfx] " Wang, Zhi A
2022-04-20  7:12                           ` Wang, Zhi A

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220411141403.86980-30-hch@lst.de \
    --to=hch@lst.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jgg@nvidia.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=zhenyuw@linux.intel.com \
    --cc=zhi.a.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.