2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include <linux/types.h>
29 struct intel_gvt_host intel_gvt_host;
31 static const char * const supported_hypervisors[] = {
32 [INTEL_GVT_HYPERVISOR_XEN] = "XEN",
33 [INTEL_GVT_HYPERVISOR_KVM] = "KVM",
37 * intel_gvt_init_host - Load MPT modules and detect if we're running in host
38 * @gvt: intel gvt device
40 * This function is called at the driver loading stage. If failed to find a
41 * loadable MPT module or detect currently we're running in a VM, then GVT-g
45 * Zero on success, negative error code if failed.
48 int intel_gvt_init_host(void)
50 if (intel_gvt_host.initialized)
54 if (xen_domain() && !xen_initial_domain())
57 /* Try to load MPT modules for hypervisors */
58 if (xen_initial_domain()) {
60 intel_gvt_host.mpt = try_then_request_module(
61 symbol_get(xengt_mpt), "xengt");
62 intel_gvt_host.hypervisor_type = INTEL_GVT_HYPERVISOR_XEN;
64 /* not in Xen. Try KVMGT */
65 intel_gvt_host.mpt = try_then_request_module(
66 symbol_get(kvmgt_mpt), "kvm");
67 intel_gvt_host.hypervisor_type = INTEL_GVT_HYPERVISOR_KVM;
70 /* Fail to load MPT modules - bail out */
71 if (!intel_gvt_host.mpt)
74 /* Try to detect if we're running in host instead of VM. */
75 if (!intel_gvt_hypervisor_detect_host())
78 gvt_dbg_core("Running with hypervisor %s in host mode\n",
79 supported_hypervisors[intel_gvt_host.hypervisor_type]);
81 intel_gvt_host.initialized = true;
85 static void init_device_info(struct intel_gvt *gvt)
87 if (IS_BROADWELL(gvt->dev_priv))
88 gvt->device_info.max_support_vgpus = 8;
89 /* This function will grow large in GVT device model patches. */
93 * intel_gvt_clean_device - clean a GVT device
94 * @gvt: intel gvt device
96 * This function is called at the driver unloading stage, to free the
97 * resources owned by a GVT device.
100 void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
102 struct intel_gvt *gvt = &dev_priv->gvt;
104 if (WARN_ON(!gvt->initialized))
107 /* Other de-initialization of GVT components will be introduced. */
109 gvt->initialized = false;
113 * intel_gvt_init_device - initialize a GVT device
114 * @dev_priv: drm i915 private data
116 * This function is called at the initialization stage, to initialize
117 * necessary GVT components.
120 * Zero on success, negative error code if failed.
123 int intel_gvt_init_device(struct drm_i915_private *dev_priv)
125 struct intel_gvt *gvt = &dev_priv->gvt;
127 * Cannot initialize GVT device without intel_gvt_host gets
130 if (WARN_ON(!intel_gvt_host.initialized))
133 if (WARN_ON(gvt->initialized))
136 gvt_dbg_core("init gvt device\n");
138 init_device_info(gvt);
140 * Other initialization of GVT components will be introduce here.
142 gvt_dbg_core("gvt device creation is done\n");
143 gvt->initialized = true;