xref: /dflybsd-src/sys/dev/drm/i915/intel_gvt.c (revision 1e12ee3baa16120663cde9c6c4c8e92b69b00794)
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
34*1e12ee3bSFrançois Tigeot  * seamlessly in a virtual machine.
35*1e12ee3bSFrançois Tigeot  *
36*1e12ee3bSFrançois Tigeot  * To virtualize GPU resources GVT-g driver depends on hypervisor technology
37*1e12ee3bSFrançois Tigeot  * e.g KVM/VFIO/mdev, Xen, etc. to provide resource access trapping capability
38*1e12ee3bSFrançois Tigeot  * and be virtualized within GVT-g device module. More architectural design
39*1e12ee3bSFrançois Tigeot  * doc is available on https://01.org/group/2230/documentation-list.
401487f786SFrançois Tigeot  */
411487f786SFrançois Tigeot 
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;
46*1e12ee3bSFrançois Tigeot 	if (IS_SKYLAKE(dev_priv))
47*1e12ee3bSFrançois Tigeot 		return true;
481487f786SFrançois Tigeot 	return false;
491487f786SFrançois Tigeot }
501487f786SFrançois Tigeot 
511487f786SFrançois Tigeot /**
521487f786SFrançois Tigeot  * intel_gvt_init - initialize GVT components
531487f786SFrançois Tigeot  * @dev_priv: drm i915 private data
541487f786SFrançois Tigeot  *
551487f786SFrançois Tigeot  * This function is called at the initialization stage to create a GVT device.
561487f786SFrançois Tigeot  *
571487f786SFrançois Tigeot  * Returns:
581487f786SFrançois Tigeot  * Zero on success, negative error code if failed.
591487f786SFrançois Tigeot  *
601487f786SFrançois Tigeot  */
611487f786SFrançois Tigeot int intel_gvt_init(struct drm_i915_private *dev_priv)
621487f786SFrançois Tigeot {
631487f786SFrançois Tigeot 	int ret;
641487f786SFrançois Tigeot 
651487f786SFrançois Tigeot 	if (!i915.enable_gvt) {
661487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("GVT-g is disabled by kernel params\n");
671487f786SFrançois Tigeot 		return 0;
681487f786SFrançois Tigeot 	}
691487f786SFrançois Tigeot 
701487f786SFrançois Tigeot 	if (!is_supported_device(dev_priv)) {
711487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("Unsupported device. GVT-g is disabled\n");
721487f786SFrançois Tigeot 		goto bail;
731487f786SFrançois Tigeot 	}
741487f786SFrançois Tigeot 
751487f786SFrançois Tigeot 	/*
761487f786SFrançois Tigeot 	 * We're not in host or fail to find a MPT module, disable GVT-g
771487f786SFrançois Tigeot 	 */
781487f786SFrançois Tigeot 	ret = intel_gvt_init_host();
791487f786SFrançois Tigeot 	if (ret) {
801487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("Not in host or MPT modules not found\n");
811487f786SFrançois Tigeot 		goto bail;
821487f786SFrançois Tigeot 	}
831487f786SFrançois Tigeot 
841487f786SFrançois Tigeot 	ret = intel_gvt_init_device(dev_priv);
851487f786SFrançois Tigeot 	if (ret) {
861487f786SFrançois Tigeot 		DRM_DEBUG_DRIVER("Fail to init GVT device\n");
871487f786SFrançois Tigeot 		goto bail;
881487f786SFrançois Tigeot 	}
891487f786SFrançois Tigeot 
901487f786SFrançois Tigeot 	return 0;
911487f786SFrançois Tigeot 
921487f786SFrançois Tigeot bail:
931487f786SFrançois Tigeot 	i915.enable_gvt = 0;
941487f786SFrançois Tigeot 	return 0;
951487f786SFrançois Tigeot }
961487f786SFrançois Tigeot 
971487f786SFrançois Tigeot /**
981487f786SFrançois Tigeot  * intel_gvt_cleanup - cleanup GVT components when i915 driver is unloading
991487f786SFrançois Tigeot  * @dev_priv: drm i915 private *
1001487f786SFrançois Tigeot  *
1011487f786SFrançois Tigeot  * This function is called at the i915 driver unloading stage, to shutdown
1021487f786SFrançois Tigeot  * GVT components and release the related resources.
1031487f786SFrançois Tigeot  */
1041487f786SFrançois Tigeot void intel_gvt_cleanup(struct drm_i915_private *dev_priv)
1051487f786SFrançois Tigeot {
1061487f786SFrançois Tigeot 	if (!intel_gvt_active(dev_priv))
1071487f786SFrançois Tigeot 		return;
1081487f786SFrançois Tigeot 
1091487f786SFrançois Tigeot 	intel_gvt_clean_device(dev_priv);
1101487f786SFrançois Tigeot }
111