.. | .. |
---|
21 | 21 | * SOFTWARE. |
---|
22 | 22 | */ |
---|
23 | 23 | |
---|
24 | | -#include "intel_drv.h" |
---|
| 24 | +#include "i915_drv.h" |
---|
| 25 | +#include "i915_pvinfo.h" |
---|
25 | 26 | #include "i915_vgpu.h" |
---|
26 | 27 | |
---|
27 | 28 | /** |
---|
.. | .. |
---|
52 | 53 | */ |
---|
53 | 54 | |
---|
54 | 55 | /** |
---|
55 | | - * i915_check_vgpu - detect virtual GPU |
---|
| 56 | + * intel_vgpu_detect - detect virtual GPU |
---|
56 | 57 | * @dev_priv: i915 device private |
---|
57 | 58 | * |
---|
58 | 59 | * This function is called at the initialization stage, to detect whether |
---|
59 | 60 | * running on a vGPU. |
---|
60 | 61 | */ |
---|
61 | | -void i915_check_vgpu(struct drm_i915_private *dev_priv) |
---|
| 62 | +void intel_vgpu_detect(struct drm_i915_private *dev_priv) |
---|
62 | 63 | { |
---|
| 64 | + struct pci_dev *pdev = dev_priv->drm.pdev; |
---|
63 | 65 | u64 magic; |
---|
64 | 66 | u16 version_major; |
---|
| 67 | + void __iomem *shared_area; |
---|
65 | 68 | |
---|
66 | 69 | BUILD_BUG_ON(sizeof(struct vgt_if) != VGT_PVINFO_SIZE); |
---|
67 | 70 | |
---|
68 | | - magic = __raw_i915_read64(dev_priv, vgtif_reg(magic)); |
---|
69 | | - if (magic != VGT_MAGIC) |
---|
| 71 | + /* |
---|
| 72 | + * This is called before we setup the main MMIO BAR mappings used via |
---|
| 73 | + * the uncore structure, so we need to access the BAR directly. Since |
---|
| 74 | + * we do not support VGT on older gens, return early so we don't have |
---|
| 75 | + * to consider differently numbered or sized MMIO bars |
---|
| 76 | + */ |
---|
| 77 | + if (INTEL_GEN(dev_priv) < 6) |
---|
70 | 78 | return; |
---|
71 | 79 | |
---|
72 | | - version_major = __raw_i915_read16(dev_priv, vgtif_reg(version_major)); |
---|
73 | | - if (version_major < VGT_VERSION_MAJOR) { |
---|
74 | | - DRM_INFO("VGT interface version mismatch!\n"); |
---|
| 80 | + shared_area = pci_iomap_range(pdev, 0, VGT_PVINFO_PAGE, VGT_PVINFO_SIZE); |
---|
| 81 | + if (!shared_area) { |
---|
| 82 | + drm_err(&dev_priv->drm, |
---|
| 83 | + "failed to map MMIO bar to check for VGT\n"); |
---|
75 | 84 | return; |
---|
76 | 85 | } |
---|
77 | 86 | |
---|
78 | | - dev_priv->vgpu.caps = __raw_i915_read32(dev_priv, vgtif_reg(vgt_caps)); |
---|
| 87 | + magic = readq(shared_area + vgtif_offset(magic)); |
---|
| 88 | + if (magic != VGT_MAGIC) |
---|
| 89 | + goto out; |
---|
| 90 | + |
---|
| 91 | + version_major = readw(shared_area + vgtif_offset(version_major)); |
---|
| 92 | + if (version_major < VGT_VERSION_MAJOR) { |
---|
| 93 | + drm_info(&dev_priv->drm, "VGT interface version mismatch!\n"); |
---|
| 94 | + goto out; |
---|
| 95 | + } |
---|
| 96 | + |
---|
| 97 | + dev_priv->vgpu.caps = readl(shared_area + vgtif_offset(vgt_caps)); |
---|
79 | 98 | |
---|
80 | 99 | dev_priv->vgpu.active = true; |
---|
81 | | - DRM_INFO("Virtual GPU for Intel GVT-g detected.\n"); |
---|
| 100 | + mutex_init(&dev_priv->vgpu.lock); |
---|
| 101 | + drm_info(&dev_priv->drm, "Virtual GPU for Intel GVT-g detected.\n"); |
---|
| 102 | + |
---|
| 103 | +out: |
---|
| 104 | + pci_iounmap(pdev, shared_area); |
---|
82 | 105 | } |
---|
83 | 106 | |
---|
84 | | -bool intel_vgpu_has_full_48bit_ppgtt(struct drm_i915_private *dev_priv) |
---|
| 107 | +void intel_vgpu_register(struct drm_i915_private *i915) |
---|
85 | 108 | { |
---|
86 | | - return dev_priv->vgpu.caps & VGT_CAPS_FULL_48BIT_PPGTT; |
---|
| 109 | + /* |
---|
| 110 | + * Notify a valid surface after modesetting, when running inside a VM. |
---|
| 111 | + */ |
---|
| 112 | + if (intel_vgpu_active(i915)) |
---|
| 113 | + intel_uncore_write(&i915->uncore, vgtif_reg(display_ready), |
---|
| 114 | + VGT_DRV_DISPLAY_READY); |
---|
| 115 | +} |
---|
| 116 | + |
---|
| 117 | +bool intel_vgpu_active(struct drm_i915_private *dev_priv) |
---|
| 118 | +{ |
---|
| 119 | + return dev_priv->vgpu.active; |
---|
| 120 | +} |
---|
| 121 | + |
---|
| 122 | +bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv) |
---|
| 123 | +{ |
---|
| 124 | + return dev_priv->vgpu.caps & VGT_CAPS_FULL_PPGTT; |
---|
| 125 | +} |
---|
| 126 | + |
---|
| 127 | +bool intel_vgpu_has_hwsp_emulation(struct drm_i915_private *dev_priv) |
---|
| 128 | +{ |
---|
| 129 | + return dev_priv->vgpu.caps & VGT_CAPS_HWSP_EMULATION; |
---|
| 130 | +} |
---|
| 131 | + |
---|
| 132 | +bool intel_vgpu_has_huge_gtt(struct drm_i915_private *dev_priv) |
---|
| 133 | +{ |
---|
| 134 | + return dev_priv->vgpu.caps & VGT_CAPS_HUGE_GTT; |
---|
87 | 135 | } |
---|
88 | 136 | |
---|
89 | 137 | struct _balloon_info_ { |
---|
.. | .. |
---|
100 | 148 | static void vgt_deballoon_space(struct i915_ggtt *ggtt, |
---|
101 | 149 | struct drm_mm_node *node) |
---|
102 | 150 | { |
---|
| 151 | + struct drm_i915_private *dev_priv = ggtt->vm.i915; |
---|
103 | 152 | if (!drm_mm_node_allocated(node)) |
---|
104 | 153 | return; |
---|
105 | 154 | |
---|
106 | | - DRM_DEBUG_DRIVER("deballoon space: range [0x%llx - 0x%llx] %llu KiB.\n", |
---|
107 | | - node->start, |
---|
108 | | - node->start + node->size, |
---|
109 | | - node->size / 1024); |
---|
| 155 | + drm_dbg(&dev_priv->drm, |
---|
| 156 | + "deballoon space: range [0x%llx - 0x%llx] %llu KiB.\n", |
---|
| 157 | + node->start, |
---|
| 158 | + node->start + node->size, |
---|
| 159 | + node->size / 1024); |
---|
110 | 160 | |
---|
111 | 161 | ggtt->vm.reserved -= node->size; |
---|
112 | 162 | drm_mm_remove_node(node); |
---|
.. | .. |
---|
114 | 164 | |
---|
115 | 165 | /** |
---|
116 | 166 | * intel_vgt_deballoon - deballoon reserved graphics address trunks |
---|
117 | | - * @dev_priv: i915 device private data |
---|
| 167 | + * @ggtt: the global GGTT from which we reserved earlier |
---|
118 | 168 | * |
---|
119 | 169 | * This function is called to deallocate the ballooned-out graphic memory, when |
---|
120 | 170 | * driver is unloaded or when ballooning fails. |
---|
121 | 171 | */ |
---|
122 | | -void intel_vgt_deballoon(struct drm_i915_private *dev_priv) |
---|
| 172 | +void intel_vgt_deballoon(struct i915_ggtt *ggtt) |
---|
123 | 173 | { |
---|
| 174 | + struct drm_i915_private *dev_priv = ggtt->vm.i915; |
---|
124 | 175 | int i; |
---|
125 | 176 | |
---|
126 | | - if (!intel_vgpu_active(dev_priv)) |
---|
| 177 | + if (!intel_vgpu_active(ggtt->vm.i915)) |
---|
127 | 178 | return; |
---|
128 | 179 | |
---|
129 | | - DRM_DEBUG("VGT deballoon.\n"); |
---|
| 180 | + drm_dbg(&dev_priv->drm, "VGT deballoon.\n"); |
---|
130 | 181 | |
---|
131 | 182 | for (i = 0; i < 4; i++) |
---|
132 | | - vgt_deballoon_space(&dev_priv->ggtt, &bl_info.space[i]); |
---|
| 183 | + vgt_deballoon_space(ggtt, &bl_info.space[i]); |
---|
133 | 184 | } |
---|
134 | 185 | |
---|
135 | 186 | static int vgt_balloon_space(struct i915_ggtt *ggtt, |
---|
136 | 187 | struct drm_mm_node *node, |
---|
137 | 188 | unsigned long start, unsigned long end) |
---|
138 | 189 | { |
---|
| 190 | + struct drm_i915_private *dev_priv = ggtt->vm.i915; |
---|
139 | 191 | unsigned long size = end - start; |
---|
140 | 192 | int ret; |
---|
141 | 193 | |
---|
142 | 194 | if (start >= end) |
---|
143 | 195 | return -EINVAL; |
---|
144 | 196 | |
---|
145 | | - DRM_INFO("balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n", |
---|
| 197 | + drm_info(&dev_priv->drm, |
---|
| 198 | + "balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n", |
---|
146 | 199 | start, end, size / 1024); |
---|
147 | 200 | ret = i915_gem_gtt_reserve(&ggtt->vm, node, |
---|
148 | 201 | size, start, I915_COLOR_UNEVICTABLE, |
---|
.. | .. |
---|
155 | 208 | |
---|
156 | 209 | /** |
---|
157 | 210 | * intel_vgt_balloon - balloon out reserved graphics address trunks |
---|
158 | | - * @dev_priv: i915 device private data |
---|
| 211 | + * @ggtt: the global GGTT from which to reserve |
---|
159 | 212 | * |
---|
160 | 213 | * This function is called at the initialization stage, to balloon out the |
---|
161 | 214 | * graphic address space allocated to other vGPUs, by marking these spaces as |
---|
.. | .. |
---|
197 | 250 | * Returns: |
---|
198 | 251 | * zero on success, non-zero if configuration invalid or ballooning failed |
---|
199 | 252 | */ |
---|
200 | | -int intel_vgt_balloon(struct drm_i915_private *dev_priv) |
---|
| 253 | +int intel_vgt_balloon(struct i915_ggtt *ggtt) |
---|
201 | 254 | { |
---|
202 | | - struct i915_ggtt *ggtt = &dev_priv->ggtt; |
---|
| 255 | + struct drm_i915_private *dev_priv = ggtt->vm.i915; |
---|
| 256 | + struct intel_uncore *uncore = &dev_priv->uncore; |
---|
203 | 257 | unsigned long ggtt_end = ggtt->vm.total; |
---|
204 | 258 | |
---|
205 | 259 | unsigned long mappable_base, mappable_size, mappable_end; |
---|
206 | 260 | unsigned long unmappable_base, unmappable_size, unmappable_end; |
---|
207 | 261 | int ret; |
---|
208 | 262 | |
---|
209 | | - if (!intel_vgpu_active(dev_priv)) |
---|
| 263 | + if (!intel_vgpu_active(ggtt->vm.i915)) |
---|
210 | 264 | return 0; |
---|
211 | 265 | |
---|
212 | | - mappable_base = I915_READ(vgtif_reg(avail_rs.mappable_gmadr.base)); |
---|
213 | | - mappable_size = I915_READ(vgtif_reg(avail_rs.mappable_gmadr.size)); |
---|
214 | | - unmappable_base = I915_READ(vgtif_reg(avail_rs.nonmappable_gmadr.base)); |
---|
215 | | - unmappable_size = I915_READ(vgtif_reg(avail_rs.nonmappable_gmadr.size)); |
---|
| 266 | + mappable_base = |
---|
| 267 | + intel_uncore_read(uncore, vgtif_reg(avail_rs.mappable_gmadr.base)); |
---|
| 268 | + mappable_size = |
---|
| 269 | + intel_uncore_read(uncore, vgtif_reg(avail_rs.mappable_gmadr.size)); |
---|
| 270 | + unmappable_base = |
---|
| 271 | + intel_uncore_read(uncore, vgtif_reg(avail_rs.nonmappable_gmadr.base)); |
---|
| 272 | + unmappable_size = |
---|
| 273 | + intel_uncore_read(uncore, vgtif_reg(avail_rs.nonmappable_gmadr.size)); |
---|
216 | 274 | |
---|
217 | 275 | mappable_end = mappable_base + mappable_size; |
---|
218 | 276 | unmappable_end = unmappable_base + unmappable_size; |
---|
219 | 277 | |
---|
220 | | - DRM_INFO("VGT ballooning configuration:\n"); |
---|
221 | | - DRM_INFO("Mappable graphic memory: base 0x%lx size %ldKiB\n", |
---|
| 278 | + drm_info(&dev_priv->drm, "VGT ballooning configuration:\n"); |
---|
| 279 | + drm_info(&dev_priv->drm, |
---|
| 280 | + "Mappable graphic memory: base 0x%lx size %ldKiB\n", |
---|
222 | 281 | mappable_base, mappable_size / 1024); |
---|
223 | | - DRM_INFO("Unmappable graphic memory: base 0x%lx size %ldKiB\n", |
---|
| 282 | + drm_info(&dev_priv->drm, |
---|
| 283 | + "Unmappable graphic memory: base 0x%lx size %ldKiB\n", |
---|
224 | 284 | unmappable_base, unmappable_size / 1024); |
---|
225 | 285 | |
---|
226 | 286 | if (mappable_end > ggtt->mappable_end || |
---|
227 | 287 | unmappable_base < ggtt->mappable_end || |
---|
228 | 288 | unmappable_end > ggtt_end) { |
---|
229 | | - DRM_ERROR("Invalid ballooning configuration!\n"); |
---|
| 289 | + drm_err(&dev_priv->drm, "Invalid ballooning configuration!\n"); |
---|
230 | 290 | return -EINVAL; |
---|
231 | 291 | } |
---|
232 | 292 | |
---|
.. | .. |
---|
263 | 323 | goto err_below_mappable; |
---|
264 | 324 | } |
---|
265 | 325 | |
---|
266 | | - DRM_INFO("VGT balloon successfully\n"); |
---|
| 326 | + drm_info(&dev_priv->drm, "VGT balloon successfully\n"); |
---|
267 | 327 | return 0; |
---|
268 | 328 | |
---|
269 | 329 | err_below_mappable: |
---|
.. | .. |
---|
273 | 333 | err_upon_mappable: |
---|
274 | 334 | vgt_deballoon_space(ggtt, &bl_info.space[2]); |
---|
275 | 335 | err: |
---|
276 | | - DRM_ERROR("VGT balloon fail\n"); |
---|
| 336 | + drm_err(&dev_priv->drm, "VGT balloon fail\n"); |
---|
277 | 337 | return ret; |
---|
278 | 338 | } |
---|