xref: /dflybsd-src/sys/dev/drm/i915/intel_gvt.c (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
11487f786SFrançois Tigeot /*
21487f786SFrançois Tigeot  * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
31487f786SFrançois Tigeot  *
41487f786SFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
51487f786SFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
61487f786SFrançois Tigeot  * to deal in the Software without restriction, including without limitation
71487f786SFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81487f786SFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
91487f786SFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
101487f786SFrançois Tigeot  *
111487f786SFrançois Tigeot  * The above copyright notice and this permission notice (including the next
121487f786SFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
131487f786SFrançois Tigeot  * Software.
141487f786SFrançois Tigeot  *
151487f786SFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161487f786SFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171487f786SFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181487f786SFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191487f786SFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
201487f786SFrançois Tigeot  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
211487f786SFrançois Tigeot  * SOFTWARE.
221487f786SFrançois Tigeot  */
231487f786SFrançois Tigeot 
241487f786SFrançois Tigeot #include "i915_drv.h"
251487f786SFrançois Tigeot #include "intel_gvt.h"
261487f786SFrançois Tigeot 
271487f786SFrançois Tigeot /**
281487f786SFrançois Tigeot  * DOC: Intel GVT-g host support
291487f786SFrançois Tigeot  *
301487f786SFrançois Tigeot  * Intel GVT-g is a graphics virtualization technology which shares the
311487f786SFrançois Tigeot  * GPU among multiple virtual machines on a time-sharing basis. Each
321487f786SFrançois Tigeot  * virtual machine is presented a virtual GPU (vGPU), which has equivalent
331487f786SFrançois Tigeot  * features as the underlying physical GPU (pGPU), so i915 driver can run
341e12ee3bSFrançois Tigeot  * seamlessly in a virtual machine.
351e12ee3bSFrançois Tigeot  *
361e12ee3bSFrançois Tigeot  * To virtualize GPU resources GVT-g driver depends on hypervisor technology
371e12ee3bSFrançois Tigeot  * e.g KVM/VFIO/mdev, Xen, etc. to provide resource access trapping capability
381e12ee3bSFrançois Tigeot  * and be virtualized within GVT-g device module. More architectural design
391e12ee3bSFrançois Tigeot  * doc is available on https://01.org/group/2230/documentation-list.
401487f786SFrançois Tigeot  */
411487f786SFrançois Tigeot 
is_supported_device(struct drm_i915_private * dev_priv)421487f786SFrançois Tigeot static bool is_supported_device(struct drm_i915_private *dev_priv)
431487f786SFrançois Tigeot {
441487f786SFrançois Tigeot 	if (IS_BROADWELL(dev_priv))
451487f786SFrançois Tigeot 		return true;
461e12ee3bSFrançois Tigeot 	if (IS_SKYLAKE(dev_priv))
471e12ee3bSFrançois Tigeot 		return true;
48a85cb24fSFrançois Tigeot 	if (IS_KABYLAKE(dev_priv) && INTEL_DEVID(dev_priv) == 0x591D)
49a85cb24fSFrançois Tigeot 		return true;
501487f786SFrançois Tigeot 	return false;
511487f786SFrançois Tigeot }
521487f786SFrançois Tigeot 
531487f786SFrançois Tigeot /**
54*3f2dd94aSFrançois Tigeot  * intel_gvt_sanitize_options - sanitize GVT related options
55*3f2dd94aSFrançois Tigeot  * @dev_priv: drm i915 private data
56*3f2dd94aSFrançois Tigeot  *
57*3f2dd94aSFrançois Tigeot  * This function is called at the i915 options sanitize stage.
58*3f2dd94aSFrançois Tigeot  */
intel_gvt_sanitize_options(struct drm_i915_private * dev_priv)59*3f2dd94aSFrançois Tigeot void intel_gvt_sanitize_options(struct drm_i915_private *dev_priv)
60*3f2dd94aSFrançois Tigeot {
61*3f2dd94aSFrançois Tigeot 	if (!i915_modparams.enable_gvt)
62*3f2dd94aSFrançois Tigeot 		return;
63*3f2dd94aSFrançois Tigeot 
64*3f2dd94aSFrançois Tigeot 	if (intel_vgpu_active(dev_priv)) {
65*3f2dd94aSFrançois Tigeot 		DRM_INFO("GVT-g is disabled for guest\n");
66*3f2dd94aSFrançois Tigeot 		goto bail;
67*3f2dd94aSFrançois Tigeot 	}
68*3f2dd94aSFrançois Tigeot 
69*3f2dd94aSFrançois Tigeot 	if (!is_supported_device(dev_priv)) {
70*3f2dd94aSFrançois Tigeot 		DRM_INFO("Unsupported device. GVT-g is disabled\n");
71*3f2dd94aSFrançois Tigeot 		goto bail;
72*3f2dd94aSFrançois Tigeot 	}
73*3f2dd94aSFrançois Tigeot 
74*3f2dd94aSFrançois Tigeot 	return;
75*3f2dd94aSFrançois Tigeot bail:
76*3f2dd94aSFrançois Tigeot 	i915_modparams.enable_gvt = 0;
77*3f2dd94aSFrançois Tigeot }
78*3f2dd94aSFrançois Tigeot 
79*3f2dd94aSFrançois Tigeot /**
801487f786SFrançois Tigeot  * intel_gvt_init - initialize GVT components
811487f786SFrançois Tigeot  * @dev_priv: drm i915 private data
821487f786SFrançois Tigeot  *
831487f786SFrançois Tigeot  * This function is called at the initialization stage to create a GVT device.
841487f786SFrançois Tigeot  *
851487f786SFrançois Tigeot  * Returns:
861487f786SFrançois Tigeot  * Zero on success, negative error code if failed.
871487f786SFrançois Tigeot  *
881487f786SFrançois Tigeot  */
intel_gvt_init(struct drm_i915_private * dev_priv)891487f786SFrançois Tigeot int intel_gvt_init(struct drm_i915_private *dev_priv)
901487f786SFrançois Tigeot {
911487f786SFrançois Tigeot 	int ret;
921487f786SFrançois Tigeot 
93*3f2dd94aSFrançois Tigeot 	if (!i915_modparams.enable_gvt) {
941487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("GVT-g is disabled by kernel params\n");
951487f786SFrançois Tigeot 		return 0;
961487f786SFrançois Tigeot 	}
971487f786SFrançois Tigeot 
98*3f2dd94aSFrançois Tigeot 	if (!i915_modparams.enable_execlists) {
99*3f2dd94aSFrançois Tigeot 		DRM_ERROR("i915 GVT-g loading failed due to disabled execlists mode\n");
100*3f2dd94aSFrançois Tigeot 		return -EIO;
101a85cb24fSFrançois Tigeot 	}
102a85cb24fSFrançois Tigeot 
103*3f2dd94aSFrançois Tigeot 	if (i915_modparams.enable_guc_submission) {
104*3f2dd94aSFrançois Tigeot 		DRM_ERROR("i915 GVT-g loading failed due to Graphics virtualization is not yet supported with GuC submission\n");
105*3f2dd94aSFrançois Tigeot 		return -EIO;
106a85cb24fSFrançois Tigeot 	}
107a85cb24fSFrançois Tigeot 
1081487f786SFrançois Tigeot 	/*
1091487f786SFrançois Tigeot 	 * We're not in host or fail to find a MPT module, disable GVT-g
1101487f786SFrançois Tigeot 	 */
1111487f786SFrançois Tigeot 	ret = intel_gvt_init_host();
1121487f786SFrançois Tigeot 	if (ret) {
1131487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("Not in host or MPT modules not found\n");
1141487f786SFrançois Tigeot 		goto bail;
1151487f786SFrançois Tigeot 	}
1161487f786SFrançois Tigeot 
1171487f786SFrançois Tigeot 	ret = intel_gvt_init_device(dev_priv);
1181487f786SFrançois Tigeot 	if (ret) {
1191487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("Fail to init GVT device\n");
1201487f786SFrançois Tigeot 		goto bail;
1211487f786SFrançois Tigeot 	}
1221487f786SFrançois Tigeot 
1231487f786SFrançois Tigeot 	return 0;
1241487f786SFrançois Tigeot 
1251487f786SFrançois Tigeot bail:
126*3f2dd94aSFrançois Tigeot 	i915_modparams.enable_gvt = 0;
1271487f786SFrançois Tigeot 	return 0;
1281487f786SFrançois Tigeot }
1291487f786SFrançois Tigeot 
1301487f786SFrançois Tigeot /**
1311487f786SFrançois Tigeot  * intel_gvt_cleanup - cleanup GVT components when i915 driver is unloading
1321487f786SFrançois Tigeot  * @dev_priv: drm i915 private *
1331487f786SFrançois Tigeot  *
1341487f786SFrançois Tigeot  * This function is called at the i915 driver unloading stage, to shutdown
1351487f786SFrançois Tigeot  * GVT components and release the related resources.
1361487f786SFrançois Tigeot  */
intel_gvt_cleanup(struct drm_i915_private * dev_priv)1371487f786SFrançois Tigeot void intel_gvt_cleanup(struct drm_i915_private *dev_priv)
1381487f786SFrançois Tigeot {
1391487f786SFrançois Tigeot 	if (!intel_gvt_active(dev_priv))
1401487f786SFrançois Tigeot 		return;
1411487f786SFrançois Tigeot 
1421487f786SFrançois Tigeot 	intel_gvt_clean_device(dev_priv);
1431487f786SFrançois Tigeot }
144