1 1.1 riastrad /* $NetBSD: intel_gvt.c,v 1.2 2021/12/18 23:45:28 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 1.1 riastrad * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 1.1 riastrad * SOFTWARE. 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #include <sys/cdefs.h> 27 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: intel_gvt.c,v 1.2 2021/12/18 23:45:28 riastradh Exp $"); 28 1.1 riastrad 29 1.1 riastrad #include "i915_drv.h" 30 1.1 riastrad #include "intel_gvt.h" 31 1.1 riastrad 32 1.1 riastrad /** 33 1.1 riastrad * DOC: Intel GVT-g host support 34 1.1 riastrad * 35 1.1 riastrad * Intel GVT-g is a graphics virtualization technology which shares the 36 1.1 riastrad * GPU among multiple virtual machines on a time-sharing basis. Each 37 1.1 riastrad * virtual machine is presented a virtual GPU (vGPU), which has equivalent 38 1.1 riastrad * features as the underlying physical GPU (pGPU), so i915 driver can run 39 1.1 riastrad * seamlessly in a virtual machine. 40 1.1 riastrad * 41 1.1 riastrad * To virtualize GPU resources GVT-g driver depends on hypervisor technology 42 1.1 riastrad * e.g KVM/VFIO/mdev, Xen, etc. to provide resource access trapping capability 43 1.1 riastrad * and be virtualized within GVT-g device module. More architectural design 44 1.1 riastrad * doc is available on https://01.org/group/2230/documentation-list. 45 1.1 riastrad */ 46 1.1 riastrad 47 1.1 riastrad static bool is_supported_device(struct drm_i915_private *dev_priv) 48 1.1 riastrad { 49 1.1 riastrad if (IS_BROADWELL(dev_priv)) 50 1.1 riastrad return true; 51 1.1 riastrad if (IS_SKYLAKE(dev_priv)) 52 1.1 riastrad return true; 53 1.1 riastrad if (IS_KABYLAKE(dev_priv)) 54 1.1 riastrad return true; 55 1.1 riastrad if (IS_BROXTON(dev_priv)) 56 1.1 riastrad return true; 57 1.1 riastrad if (IS_COFFEELAKE(dev_priv)) 58 1.1 riastrad return true; 59 1.1 riastrad 60 1.1 riastrad return false; 61 1.1 riastrad } 62 1.1 riastrad 63 1.1 riastrad /** 64 1.1 riastrad * intel_gvt_sanitize_options - sanitize GVT related options 65 1.1 riastrad * @dev_priv: drm i915 private data 66 1.1 riastrad * 67 1.1 riastrad * This function is called at the i915 options sanitize stage. 68 1.1 riastrad */ 69 1.1 riastrad void intel_gvt_sanitize_options(struct drm_i915_private *dev_priv) 70 1.1 riastrad { 71 1.1 riastrad if (!i915_modparams.enable_gvt) 72 1.1 riastrad return; 73 1.1 riastrad 74 1.1 riastrad if (intel_vgpu_active(dev_priv)) { 75 1.1 riastrad DRM_INFO("GVT-g is disabled for guest\n"); 76 1.1 riastrad goto bail; 77 1.1 riastrad } 78 1.1 riastrad 79 1.1 riastrad if (!is_supported_device(dev_priv)) { 80 1.1 riastrad DRM_INFO("Unsupported device. GVT-g is disabled\n"); 81 1.1 riastrad goto bail; 82 1.1 riastrad } 83 1.1 riastrad 84 1.1 riastrad return; 85 1.1 riastrad bail: 86 1.1 riastrad i915_modparams.enable_gvt = 0; 87 1.1 riastrad } 88 1.1 riastrad 89 1.1 riastrad /** 90 1.1 riastrad * intel_gvt_init - initialize GVT components 91 1.1 riastrad * @dev_priv: drm i915 private data 92 1.1 riastrad * 93 1.1 riastrad * This function is called at the initialization stage to create a GVT device. 94 1.1 riastrad * 95 1.1 riastrad * Returns: 96 1.1 riastrad * Zero on success, negative error code if failed. 97 1.1 riastrad * 98 1.1 riastrad */ 99 1.1 riastrad int intel_gvt_init(struct drm_i915_private *dev_priv) 100 1.1 riastrad { 101 1.1 riastrad int ret; 102 1.1 riastrad 103 1.1 riastrad if (i915_inject_probe_failure(dev_priv)) 104 1.1 riastrad return -ENODEV; 105 1.1 riastrad 106 1.1 riastrad if (!i915_modparams.enable_gvt) { 107 1.1 riastrad DRM_DEBUG_DRIVER("GVT-g is disabled by kernel params\n"); 108 1.1 riastrad return 0; 109 1.1 riastrad } 110 1.1 riastrad 111 1.1 riastrad if (USES_GUC_SUBMISSION(dev_priv)) { 112 1.1 riastrad DRM_ERROR("i915 GVT-g loading failed due to Graphics virtualization is not yet supported with GuC submission\n"); 113 1.1 riastrad return -EIO; 114 1.1 riastrad } 115 1.1 riastrad 116 1.1 riastrad ret = intel_gvt_init_device(dev_priv); 117 1.1 riastrad if (ret) { 118 1.1 riastrad DRM_DEBUG_DRIVER("Fail to init GVT device\n"); 119 1.1 riastrad goto bail; 120 1.1 riastrad } 121 1.1 riastrad 122 1.1 riastrad return 0; 123 1.1 riastrad 124 1.1 riastrad bail: 125 1.1 riastrad i915_modparams.enable_gvt = 0; 126 1.1 riastrad return 0; 127 1.1 riastrad } 128 1.1 riastrad 129 1.1 riastrad /** 130 1.1 riastrad * intel_gvt_driver_remove - cleanup GVT components when i915 driver is 131 1.1 riastrad * unbinding 132 1.1 riastrad * @dev_priv: drm i915 private * 133 1.1 riastrad * 134 1.1 riastrad * This function is called at the i915 driver unloading stage, to shutdown 135 1.1 riastrad * GVT components and release the related resources. 136 1.1 riastrad */ 137 1.1 riastrad void intel_gvt_driver_remove(struct drm_i915_private *dev_priv) 138 1.1 riastrad { 139 1.1 riastrad if (!intel_gvt_active(dev_priv)) 140 1.1 riastrad return; 141 1.1 riastrad 142 1.1 riastrad intel_gvt_clean_device(dev_priv); 143 1.1 riastrad } 144