aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhi Wang <zhi.a.wang@intel.com>2016-06-16 08:07:00 -0400
committerChris Wilson <chris@chris-wilson.co.uk>2016-06-17 15:35:06 -0400
commit0ad35fed618cec78af8f40cc47702e13e5ba82b1 (patch)
tree69ae9a6a4499e8baf4bc2d808a4a026f778e9cf0
parentb02d22a399963926618949f794e8a13aebb42898 (diff)
drm/i915: gvt: Introduce the basic architecture of GVT-g
This patch introduces the very basic framework of GVT-g device model, includes basic prototypes, definitions, initialization. v12: - Call intel_gvt_init() in driver early initialization stage. (Chris) v8: - Remove the GVT idr and mutex in intel_gvt_host. (Joonas) v7: - Refine the URL link in Kconfig. (Joonas) - Refine the introduction of GVT-g host support in Kconfig. (Joonas) - Remove the macro GVT_ALIGN(), use round_down() instead. (Joonas) - Make "struct intel_gvt" a data member in struct drm_i915_private.(Joonas) - Remove {alloc, free}_gvt_device() - Rename intel_gvt_{create, destroy}_gvt_device() - Expost intel_gvt_init_host() - Remove the dummy "struct intel_gvt" declaration in intel_gvt.h (Joonas) v6: - Refine introduction in Kconfig. (Chris) - The exposed API functions will take struct intel_gvt * instead of void *. (Chris/Tvrtko) - Remove most memebers of strct intel_gvt_device_info. Will add them in the device model patches.(Chris) - Remove gvt_info() and gvt_err() in debug.h. (Chris) - Move GVT kernel parameter into i915_params. (Chris) - Remove include/drm/i915_gvt.h, as GVT-g will be built within i915. - Remove the redundant struct i915_gvt *, as the functions in i915 will directly take struct intel_gvt *. - Add more comments for reviewer. v5: Take Tvrtko's comments: - Fix the misspelled words in Kconfig - Let functions take drm_i915_private * instead of struct drm_device * - Remove redundant prints/local varible initialization v3: Take Joonas' comments: - Change file name i915_gvt.* to intel_gvt.* - Move GVT kernel parameter into intel_gvt.c - Remove redundant debug macros - Change error handling style - Add introductions for some stub functions - Introduce drm/i915_gvt.h. Take Kevin's comments: - Move GVT-g host/guest check into intel_vgt_balloon in i915_gem_gtt.c v2: - Introduce i915_gvt.c. It's necessary to introduce the stubs between i915 driver and GVT-g host, as GVT-g components is configurable in kernel config. When disabled, the stubs here do nothing. Take Joonas' comments: - Replace boolean return value with int. - Replace customized info/warn/debug macros with DRM macros. - Document all non-static functions like i915. - Remove empty and unused functions. - Replace magic number with marcos. - Set GVT-g in kernel config to "n" by default. Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> Cc: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Zhi Wang <zhi.a.wang@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1466078825-6662-5-git-send-email-zhi.a.wang@intel.com Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--drivers/gpu/drm/i915/Kconfig22
-rw-r--r--drivers/gpu/drm/i915/Makefile5
-rw-r--r--drivers/gpu/drm/i915/gvt/Makefile5
-rw-r--r--drivers/gpu/drm/i915/gvt/debug.h34
-rw-r--r--drivers/gpu/drm/i915/gvt/gvt.c145
-rw-r--r--drivers/gpu/drm/i915/gvt/gvt.h69
-rw-r--r--drivers/gpu/drm/i915/gvt/hypercall.h38
-rw-r--r--drivers/gpu/drm/i915/gvt/mpt.h49
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c10
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h10
-rw-r--r--drivers/gpu/drm/i915/i915_params.c5
-rw-r--r--drivers/gpu/drm/i915/i915_params.h1
-rw-r--r--drivers/gpu/drm/i915/intel_gvt.c100
-rw-r--r--drivers/gpu/drm/i915/intel_gvt.h45
14 files changed, 538 insertions, 0 deletions
diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig
index 29a32b11953b..7769e469118f 100644
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@ -57,6 +57,28 @@ config DRM_I915_USERPTR
57 57
58 If in doubt, say "Y". 58 If in doubt, say "Y".
59 59
60config DRM_I915_GVT
61 bool "Enable Intel GVT-g graphics virtualization host support"
62 depends on DRM_I915
63 default n
64 help
65 Choose this option if you want to enable Intel GVT-g graphics
66 virtualization technology host support with integrated graphics.
67 With GVT-g, it's possible to have one integrated graphics
68 device shared by multiple VMs under different hypervisors.
69
70 Note that at least one hypervisor like Xen or KVM is required for
71 this driver to work, and it only supports newer device from
72 Broadwell+. For further information and setup guide, you can
73 visit: http://01.org/igvt-g.
74
75 Now it's just a stub to support the modifications of i915 for
76 GVT device model. It requires at least one MPT modules for Xen/KVM
77 and other components of GVT device model to work. Use it under
78 you own risk.
79
80 If in doubt, say "N".
81
60menu "drm/i915 Debugging" 82menu "drm/i915 Debugging"
61depends on DRM_I915 83depends on DRM_I915
62depends on EXPERT 84depends on EXPERT
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 7e2944406b8f..276abf1cac2b 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -104,6 +104,11 @@ i915-y += i915_vgpu.o
104# legacy horrors 104# legacy horrors
105i915-y += i915_dma.o 105i915-y += i915_dma.o
106 106
107ifeq ($(CONFIG_DRM_I915_GVT),y)
108i915-y += intel_gvt.o
109include $(src)/gvt/Makefile
110endif
111
107obj-$(CONFIG_DRM_I915) += i915.o 112obj-$(CONFIG_DRM_I915) += i915.o
108 113
109CFLAGS_i915_trace_points.o := -I$(src) 114CFLAGS_i915_trace_points.o := -I$(src)
diff --git a/drivers/gpu/drm/i915/gvt/Makefile b/drivers/gpu/drm/i915/gvt/Makefile
new file mode 100644
index 000000000000..d0f21a6ad60d
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/Makefile
@@ -0,0 +1,5 @@
1GVT_DIR := gvt
2GVT_SOURCE := gvt.o
3
4ccflags-y += -I$(src) -I$(src)/$(GVT_DIR) -Wall
5i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))
diff --git a/drivers/gpu/drm/i915/gvt/debug.h b/drivers/gpu/drm/i915/gvt/debug.h
new file mode 100644
index 000000000000..7ef412be665f
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/debug.h
@@ -0,0 +1,34 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#ifndef __GVT_DEBUG_H__
25#define __GVT_DEBUG_H__
26
27#define gvt_dbg_core(fmt, args...) \
28 DRM_DEBUG_DRIVER("gvt: core: "fmt, ##args)
29
30/*
31 * Other GVT debug stuff will be introduced in the GVT device model patches.
32 */
33
34#endif
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
new file mode 100644
index 000000000000..927f4579f5b6
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -0,0 +1,145 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#include <linux/types.h>
25#include <xen/xen.h>
26
27#include "i915_drv.h"
28
29struct intel_gvt_host intel_gvt_host;
30
31static const char * const supported_hypervisors[] = {
32 [INTEL_GVT_HYPERVISOR_XEN] = "XEN",
33 [INTEL_GVT_HYPERVISOR_KVM] = "KVM",
34};
35
36/**
37 * intel_gvt_init_host - Load MPT modules and detect if we're running in host
38 * @gvt: intel gvt device
39 *
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
42 * will be disabled
43 *
44 * Returns:
45 * Zero on success, negative error code if failed.
46 *
47 */
48int intel_gvt_init_host(void)
49{
50 if (intel_gvt_host.initialized)
51 return 0;
52
53 /* Xen DOM U */
54 if (xen_domain() && !xen_initial_domain())
55 return -ENODEV;
56
57 /* Try to load MPT modules for hypervisors */
58 if (xen_initial_domain()) {
59 /* In Xen dom0 */
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;
63 } else {
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;
68 }
69
70 /* Fail to load MPT modules - bail out */
71 if (!intel_gvt_host.mpt)
72 return -EINVAL;
73
74 /* Try to detect if we're running in host instead of VM. */
75 if (!intel_gvt_hypervisor_detect_host())
76 return -ENODEV;
77
78 gvt_dbg_core("Running with hypervisor %s in host mode\n",
79 supported_hypervisors[intel_gvt_host.hypervisor_type]);
80
81 intel_gvt_host.initialized = true;
82 return 0;
83}
84
85static void init_device_info(struct intel_gvt *gvt)
86{
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. */
90}
91
92/**
93 * intel_gvt_clean_device - clean a GVT device
94 * @gvt: intel gvt device
95 *
96 * This function is called at the driver unloading stage, to free the
97 * resources owned by a GVT device.
98 *
99 */
100void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
101{
102 struct intel_gvt *gvt = &dev_priv->gvt;
103
104 if (WARN_ON(!gvt->initialized))
105 return;
106
107 /* Other de-initialization of GVT components will be introduced. */
108
109 gvt->initialized = false;
110}
111
112/**
113 * intel_gvt_init_device - initialize a GVT device
114 * @dev_priv: drm i915 private data
115 *
116 * This function is called at the initialization stage, to initialize
117 * necessary GVT components.
118 *
119 * Returns:
120 * Zero on success, negative error code if failed.
121 *
122 */
123int intel_gvt_init_device(struct drm_i915_private *dev_priv)
124{
125 struct intel_gvt *gvt = &dev_priv->gvt;
126 /*
127 * Cannot initialize GVT device without intel_gvt_host gets
128 * initialized first.
129 */
130 if (WARN_ON(!intel_gvt_host.initialized))
131 return -EINVAL;
132
133 if (WARN_ON(gvt->initialized))
134 return -EEXIST;
135
136 gvt_dbg_core("init gvt device\n");
137
138 init_device_info(gvt);
139 /*
140 * Other initialization of GVT components will be introduce here.
141 */
142 gvt_dbg_core("gvt device creation is done\n");
143 gvt->initialized = true;
144 return 0;
145}
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
new file mode 100644
index 000000000000..fb619a6e519d
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#ifndef _GVT_H_
25#define _GVT_H_
26
27#include "debug.h"
28#include "hypercall.h"
29
30#define GVT_MAX_VGPU 8
31
32enum {
33 INTEL_GVT_HYPERVISOR_XEN = 0,
34 INTEL_GVT_HYPERVISOR_KVM,
35};
36
37struct intel_gvt_host {
38 bool initialized;
39 int hypervisor_type;
40 struct intel_gvt_mpt *mpt;
41};
42
43extern struct intel_gvt_host intel_gvt_host;
44
45/* Describe per-platform limitations. */
46struct intel_gvt_device_info {
47 u32 max_support_vgpus;
48 /* This data structure will grow bigger in GVT device model patches */
49};
50
51struct intel_vgpu {
52 struct intel_gvt *gvt;
53 int id;
54 unsigned long handle; /* vGPU handle used by hypervisor MPT modules */
55};
56
57struct intel_gvt {
58 struct mutex lock;
59 bool initialized;
60
61 struct drm_i915_private *dev_priv;
62 struct idr vgpu_idr; /* vGPU IDR pool */
63
64 struct intel_gvt_device_info device_info;
65};
66
67#include "mpt.h"
68
69#endif
diff --git a/drivers/gpu/drm/i915/gvt/hypercall.h b/drivers/gpu/drm/i915/gvt/hypercall.h
new file mode 100644
index 000000000000..254df8bf1f35
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/hypercall.h
@@ -0,0 +1,38 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#ifndef _GVT_HYPERCALL_H_
25#define _GVT_HYPERCALL_H_
26
27/*
28 * Specific GVT-g MPT modules function collections. Currently GVT-g supports
29 * both Xen and KVM by providing dedicated hypervisor-related MPT modules.
30 */
31struct intel_gvt_mpt {
32 int (*detect_host)(void);
33};
34
35extern struct intel_gvt_mpt xengt_mpt;
36extern struct intel_gvt_mpt kvmgt_mpt;
37
38#endif /* _GVT_HYPERCALL_H_ */
diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h
new file mode 100644
index 000000000000..03601e3ffa7c
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/mpt.h
@@ -0,0 +1,49 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#ifndef _GVT_MPT_H_
25#define _GVT_MPT_H_
26
27/**
28 * DOC: Hypervisor Service APIs for GVT-g Core Logic
29 *
30 * This is the glue layer between specific hypervisor MPT modules and GVT-g core
31 * logic. Each kind of hypervisor MPT module provides a collection of function
32 * callbacks and will be attached to GVT host when the driver is loading.
33 * GVT-g core logic will call these APIs to request specific services from
34 * hypervisor.
35 */
36
37/**
38 * intel_gvt_hypervisor_detect_host - check if GVT-g is running within
39 * hypervisor host/privilged domain
40 *
41 * Returns:
42 * Zero on success, -ENODEV if current kernel is running inside a VM
43 */
44static inline int intel_gvt_hypervisor_detect_host(void)
45{
46 return intel_gvt_host.mpt->detect_host();
47}
48
49#endif /* _GVT_MPT_H_ */
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 24b670f72ed4..d15a461fa84a 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1120,6 +1120,10 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
1120 if (ret < 0) 1120 if (ret < 0)
1121 return ret; 1121 return ret;
1122 1122
1123 ret = intel_gvt_init(dev_priv);
1124 if (ret < 0)
1125 goto err_workqueues;
1126
1123 /* This must be called before any calls to HAS_PCH_* */ 1127 /* This must be called before any calls to HAS_PCH_* */
1124 intel_detect_pch(dev); 1128 intel_detect_pch(dev);
1125 1129
@@ -1145,6 +1149,10 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
1145 "It may not be fully functional.\n"); 1149 "It may not be fully functional.\n");
1146 1150
1147 return 0; 1151 return 0;
1152
1153err_workqueues:
1154 i915_workqueues_cleanup(dev_priv);
1155 return ret;
1148} 1156}
1149 1157
1150/** 1158/**
@@ -1516,6 +1524,8 @@ int i915_driver_unload(struct drm_device *dev)
1516 1524
1517 intel_fbdev_fini(dev); 1525 intel_fbdev_fini(dev);
1518 1526
1527 intel_gvt_cleanup(dev_priv);
1528
1519 ret = i915_gem_suspend(dev); 1529 ret = i915_gem_suspend(dev);
1520 if (ret) { 1530 if (ret) {
1521 DRM_ERROR("failed to idle hardware: %d\n", ret); 1531 DRM_ERROR("failed to idle hardware: %d\n", ret);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 9fa9698fe247..0cb908624bb3 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -61,6 +61,8 @@
61#include "i915_gem_gtt.h" 61#include "i915_gem_gtt.h"
62#include "i915_gem_render_state.h" 62#include "i915_gem_render_state.h"
63 63
64#include "intel_gvt.h"
65
64/* General customization: 66/* General customization:
65 */ 67 */
66 68
@@ -1741,6 +1743,8 @@ struct drm_i915_private {
1741 1743
1742 struct i915_virtual_gpu vgpu; 1744 struct i915_virtual_gpu vgpu;
1743 1745
1746 struct intel_gvt gvt;
1747
1744 struct intel_guc guc; 1748 struct intel_guc guc;
1745 1749
1746 struct intel_csr csr; 1750 struct intel_csr csr;
@@ -2953,6 +2957,12 @@ void intel_uncore_forcewake_put__locked(struct drm_i915_private *dev_priv,
2953u64 intel_uncore_edram_size(struct drm_i915_private *dev_priv); 2957u64 intel_uncore_edram_size(struct drm_i915_private *dev_priv);
2954 2958
2955void assert_forcewakes_inactive(struct drm_i915_private *dev_priv); 2959void assert_forcewakes_inactive(struct drm_i915_private *dev_priv);
2960
2961static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
2962{
2963 return dev_priv->gvt.initialized;
2964}
2965
2956static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv) 2966static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
2957{ 2967{
2958 return dev_priv->vgpu.active; 2968 return dev_priv->vgpu.active;
diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
index 573e78723fc5..7effe68d552c 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -60,6 +60,7 @@ struct i915_params i915 __read_mostly = {
60 .enable_dp_mst = true, 60 .enable_dp_mst = true,
61 .inject_load_failure = 0, 61 .inject_load_failure = 0,
62 .enable_dpcd_backlight = false, 62 .enable_dpcd_backlight = false,
63 .enable_gvt = false,
63}; 64};
64 65
65module_param_named(modeset, i915.modeset, int, 0400); 66module_param_named(modeset, i915.modeset, int, 0400);
@@ -222,3 +223,7 @@ MODULE_PARM_DESC(inject_load_failure,
222module_param_named(enable_dpcd_backlight, i915.enable_dpcd_backlight, bool, 0600); 223module_param_named(enable_dpcd_backlight, i915.enable_dpcd_backlight, bool, 0600);
223MODULE_PARM_DESC(enable_dpcd_backlight, 224MODULE_PARM_DESC(enable_dpcd_backlight,
224 "Enable support for DPCD backlight control (default:false)"); 225 "Enable support for DPCD backlight control (default:false)");
226
227module_param_named(enable_gvt, i915.enable_gvt, bool, 0600);
228MODULE_PARM_DESC(enable_gvt,
229 "Enable support for Intel GVT-g graphics virtualization host support(default:false)");
diff --git a/drivers/gpu/drm/i915/i915_params.h b/drivers/gpu/drm/i915/i915_params.h
index 1323261a0cdd..0ad020b4a925 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -63,6 +63,7 @@ struct i915_params {
63 bool nuclear_pageflip; 63 bool nuclear_pageflip;
64 bool enable_dp_mst; 64 bool enable_dp_mst;
65 bool enable_dpcd_backlight; 65 bool enable_dpcd_backlight;
66 bool enable_gvt;
66}; 67};
67 68
68extern struct i915_params i915 __read_mostly; 69extern struct i915_params i915 __read_mostly;
diff --git a/drivers/gpu/drm/i915/intel_gvt.c b/drivers/gpu/drm/i915/intel_gvt.c
new file mode 100644
index 000000000000..9fa458ce40a6
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_gvt.c
@@ -0,0 +1,100 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#include "i915_drv.h"
25#include "intel_gvt.h"
26
27/**
28 * DOC: Intel GVT-g host support
29 *
30 * Intel GVT-g is a graphics virtualization technology which shares the
31 * GPU among multiple virtual machines on a time-sharing basis. Each
32 * virtual machine is presented a virtual GPU (vGPU), which has equivalent
33 * features as the underlying physical GPU (pGPU), so i915 driver can run
34 * seamlessly in a virtual machine. This file provides the englightments
35 * of GVT and the necessary components used by GVT in i915 driver.
36 */
37
38static bool is_supported_device(struct drm_i915_private *dev_priv)
39{
40 if (IS_BROADWELL(dev_priv))
41 return true;
42 return false;
43}
44
45/**
46 * intel_gvt_init - initialize GVT components
47 * @dev_priv: drm i915 private data
48 *
49 * This function is called at the initialization stage to create a GVT device.
50 *
51 * Returns:
52 * Zero on success, negative error code if failed.
53 *
54 */
55int intel_gvt_init(struct drm_i915_private *dev_priv)
56{
57 int ret;
58
59 if (!i915.enable_gvt) {
60 DRM_DEBUG_DRIVER("GVT-g is disabled by kernel params\n");
61 return 0;
62 }
63
64 if (!is_supported_device(dev_priv)) {
65 DRM_DEBUG_DRIVER("Unsupported device. GVT-g is disabled\n");
66 return 0;
67 }
68
69 /*
70 * We're not in host or fail to find a MPT module, disable GVT-g
71 */
72 ret = intel_gvt_init_host();
73 if (ret) {
74 DRM_DEBUG_DRIVER("Not in host or MPT modules not found\n");
75 return 0;
76 }
77
78 ret = intel_gvt_init_device(dev_priv);
79 if (ret) {
80 DRM_DEBUG_DRIVER("Fail to init GVT device\n");
81 return 0;
82 }
83
84 return 0;
85}
86
87/**
88 * intel_gvt_cleanup - cleanup GVT components when i915 driver is unloading
89 * @dev_priv: drm i915 private *
90 *
91 * This function is called at the i915 driver unloading stage, to shutdown
92 * GVT components and release the related resources.
93 */
94void intel_gvt_cleanup(struct drm_i915_private *dev_priv)
95{
96 if (!intel_gvt_active(dev_priv))
97 return;
98
99 intel_gvt_clean_device(dev_priv);
100}
diff --git a/drivers/gpu/drm/i915/intel_gvt.h b/drivers/gpu/drm/i915/intel_gvt.h
new file mode 100644
index 000000000000..960211df74db
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_gvt.h
@@ -0,0 +1,45 @@
1/*
2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24#ifndef _INTEL_GVT_H_
25#define _INTEL_GVT_H_
26
27#include "gvt/gvt.h"
28
29#ifdef CONFIG_DRM_I915_GVT
30int intel_gvt_init(struct drm_i915_private *dev_priv);
31void intel_gvt_cleanup(struct drm_i915_private *dev_priv);
32int intel_gvt_init_device(struct drm_i915_private *dev_priv);
33void intel_gvt_clean_device(struct drm_i915_private *dev_priv);
34int intel_gvt_init_host(void);
35#else
36static inline int intel_gvt_init(struct drm_i915_private *dev_priv)
37{
38 return 0;
39}
40static inline void intel_gvt_cleanup(struct drm_i915_private *dev_priv)
41{
42}
43#endif
44
45#endif /* _INTEL_GVT_H_ */