Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 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 | * Authors: |
| 24 | * Zhi Wang <zhi.a.wang@intel.com> |
| 25 | * |
| 26 | * Contributors: |
| 27 | * Ping Gao <ping.a.gao@intel.com> |
| 28 | * Tina Zhang <tina.zhang@intel.com> |
| 29 | * Chanbin Du <changbin.du@intel.com> |
| 30 | * Min He <min.he@intel.com> |
| 31 | * Bing Niu <bing.niu@intel.com> |
| 32 | * Zhenyu Wang <zhenyuw@linux.intel.com> |
| 33 | * |
| 34 | */ |
| 35 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 36 | #include <linux/kthread.h> |
| 37 | |
Zhenyu Wang | feddf6e | 2016-10-20 17:15:03 +0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
| 39 | #include "gvt.h" |
| 40 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 41 | #define RING_CTX_OFF(x) \ |
| 42 | offsetof(struct execlist_ring_context, x) |
| 43 | |
Du, Changbin | 999ccb4 | 2016-10-20 14:08:47 +0800 | [diff] [blame] | 44 | static void set_context_pdp_root_pointer( |
| 45 | struct execlist_ring_context *ring_context, |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 46 | u32 pdp[8]) |
| 47 | { |
| 48 | struct execlist_mmio_pair *pdp_pair = &ring_context->pdp3_UDW; |
| 49 | int i; |
| 50 | |
| 51 | for (i = 0; i < 8; i++) |
| 52 | pdp_pair[i].val = pdp[7 - i]; |
| 53 | } |
| 54 | |
| 55 | static int populate_shadow_context(struct intel_vgpu_workload *workload) |
| 56 | { |
| 57 | struct intel_vgpu *vgpu = workload->vgpu; |
| 58 | struct intel_gvt *gvt = vgpu->gvt; |
| 59 | int ring_id = workload->ring_id; |
| 60 | struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx; |
| 61 | struct drm_i915_gem_object *ctx_obj = |
| 62 | shadow_ctx->engine[ring_id].state->obj; |
| 63 | struct execlist_ring_context *shadow_ring_context; |
| 64 | struct page *page; |
| 65 | void *dst; |
| 66 | unsigned long context_gpa, context_page_num; |
| 67 | int i; |
| 68 | |
| 69 | gvt_dbg_sched("ring id %d workload lrca %x", ring_id, |
| 70 | workload->ctx_desc.lrca); |
| 71 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 72 | context_page_num = gvt->dev_priv->engine[ring_id]->context_size; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 73 | |
| 74 | context_page_num = context_page_num >> PAGE_SHIFT; |
| 75 | |
| 76 | if (IS_BROADWELL(gvt->dev_priv) && ring_id == RCS) |
| 77 | context_page_num = 19; |
| 78 | |
| 79 | i = 2; |
| 80 | |
| 81 | while (i < context_page_num) { |
| 82 | context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm, |
| 83 | (u32)((workload->ctx_desc.lrca + i) << |
| 84 | GTT_PAGE_SHIFT)); |
| 85 | if (context_gpa == INTEL_GVT_INVALID_ADDR) { |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 86 | gvt_vgpu_err("Invalid guest context descriptor\n"); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 87 | return -EINVAL; |
| 88 | } |
| 89 | |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame^] | 90 | page = i915_gem_object_get_page(ctx_obj, LRC_HEADER_PAGES + i); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 91 | dst = kmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 92 | intel_gvt_hypervisor_read_gpa(vgpu, context_gpa, dst, |
| 93 | GTT_PAGE_SIZE); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 94 | kunmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 95 | i++; |
| 96 | } |
| 97 | |
| 98 | page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 99 | shadow_ring_context = kmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 100 | |
| 101 | #define COPY_REG(name) \ |
| 102 | intel_gvt_hypervisor_read_gpa(vgpu, workload->ring_context_gpa \ |
| 103 | + RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4) |
| 104 | |
| 105 | COPY_REG(ctx_ctrl); |
| 106 | COPY_REG(ctx_timestamp); |
| 107 | |
| 108 | if (ring_id == RCS) { |
| 109 | COPY_REG(bb_per_ctx_ptr); |
| 110 | COPY_REG(rcs_indirect_ctx); |
| 111 | COPY_REG(rcs_indirect_ctx_offset); |
| 112 | } |
| 113 | #undef COPY_REG |
| 114 | |
| 115 | set_context_pdp_root_pointer(shadow_ring_context, |
| 116 | workload->shadow_mm->shadow_page_table); |
| 117 | |
| 118 | intel_gvt_hypervisor_read_gpa(vgpu, |
| 119 | workload->ring_context_gpa + |
| 120 | sizeof(*shadow_ring_context), |
| 121 | (void *)shadow_ring_context + |
| 122 | sizeof(*shadow_ring_context), |
| 123 | GTT_PAGE_SIZE - sizeof(*shadow_ring_context)); |
| 124 | |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 125 | kunmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Changbin Du | bc2d4b6 | 2017-03-22 12:35:31 +0800 | [diff] [blame] | 129 | static inline bool is_gvt_request(struct drm_i915_gem_request *req) |
| 130 | { |
| 131 | return i915_gem_context_force_single_submission(req->ctx); |
| 132 | } |
| 133 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 134 | static int shadow_context_status_change(struct notifier_block *nb, |
| 135 | unsigned long action, void *data) |
| 136 | { |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 137 | struct drm_i915_gem_request *req = (struct drm_i915_gem_request *)data; |
| 138 | struct intel_gvt *gvt = container_of(nb, struct intel_gvt, |
| 139 | shadow_ctx_notifier_block[req->engine->id]); |
| 140 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 141 | enum intel_engine_id ring_id = req->engine->id; |
| 142 | struct intel_vgpu_workload *workload; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 143 | |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 144 | if (!is_gvt_request(req)) { |
| 145 | spin_lock_bh(&scheduler->mmio_context_lock); |
| 146 | if (action == INTEL_CONTEXT_SCHEDULE_IN && |
| 147 | scheduler->engine_owner[ring_id]) { |
| 148 | /* Switch ring from vGPU to host. */ |
| 149 | intel_gvt_switch_mmio(scheduler->engine_owner[ring_id], |
| 150 | NULL, ring_id); |
| 151 | scheduler->engine_owner[ring_id] = NULL; |
| 152 | } |
| 153 | spin_unlock_bh(&scheduler->mmio_context_lock); |
| 154 | |
| 155 | return NOTIFY_OK; |
| 156 | } |
| 157 | |
| 158 | workload = scheduler->current_workload[ring_id]; |
| 159 | if (unlikely(!workload)) |
Chuanxiao Dong | 9272f73 | 2017-02-17 19:29:52 +0800 | [diff] [blame] | 160 | return NOTIFY_OK; |
| 161 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 162 | switch (action) { |
| 163 | case INTEL_CONTEXT_SCHEDULE_IN: |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 164 | spin_lock_bh(&scheduler->mmio_context_lock); |
| 165 | if (workload->vgpu != scheduler->engine_owner[ring_id]) { |
| 166 | /* Switch ring from host to vGPU or vGPU to vGPU. */ |
| 167 | intel_gvt_switch_mmio(scheduler->engine_owner[ring_id], |
| 168 | workload->vgpu, ring_id); |
| 169 | scheduler->engine_owner[ring_id] = workload->vgpu; |
| 170 | } else |
| 171 | gvt_dbg_sched("skip ring %d mmio switch for vgpu%d\n", |
| 172 | ring_id, workload->vgpu->id); |
| 173 | spin_unlock_bh(&scheduler->mmio_context_lock); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 174 | atomic_set(&workload->shadow_ctx_active, 1); |
| 175 | break; |
| 176 | case INTEL_CONTEXT_SCHEDULE_OUT: |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 177 | atomic_set(&workload->shadow_ctx_active, 0); |
| 178 | break; |
| 179 | default: |
| 180 | WARN_ON(1); |
| 181 | return NOTIFY_OK; |
| 182 | } |
| 183 | wake_up(&workload->shadow_ctx_status_wq); |
| 184 | return NOTIFY_OK; |
| 185 | } |
| 186 | |
Kechen Lu | 9dfb8e5 | 2017-08-10 07:41:36 +0800 | [diff] [blame] | 187 | static void shadow_context_descriptor_update(struct i915_gem_context *ctx, |
| 188 | struct intel_engine_cs *engine) |
| 189 | { |
| 190 | struct intel_context *ce = &ctx->engine[engine->id]; |
| 191 | u64 desc = 0; |
| 192 | |
| 193 | desc = ce->lrc_desc; |
| 194 | |
| 195 | /* Update bits 0-11 of the context descriptor which includes flags |
| 196 | * like GEN8_CTX_* cached in desc_template |
| 197 | */ |
| 198 | desc &= U64_MAX << 12; |
| 199 | desc |= ctx->desc_template & ((1ULL << 12) - 1); |
| 200 | |
| 201 | ce->lrc_desc = desc; |
| 202 | } |
| 203 | |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 204 | static int copy_workload_to_ring_buffer(struct intel_vgpu_workload *workload) |
| 205 | { |
| 206 | struct intel_vgpu *vgpu = workload->vgpu; |
| 207 | void *shadow_ring_buffer_va; |
| 208 | u32 *cs; |
| 209 | |
| 210 | /* allocate shadow ring buffer */ |
| 211 | cs = intel_ring_begin(workload->req, workload->rb_len / sizeof(u32)); |
| 212 | if (IS_ERR(cs)) { |
| 213 | gvt_vgpu_err("fail to alloc size =%ld shadow ring buffer\n", |
| 214 | workload->rb_len); |
| 215 | return PTR_ERR(cs); |
| 216 | } |
| 217 | |
| 218 | shadow_ring_buffer_va = workload->shadow_ring_buffer_va; |
| 219 | |
| 220 | /* get shadow ring buffer va */ |
| 221 | workload->shadow_ring_buffer_va = cs; |
| 222 | |
| 223 | memcpy(cs, shadow_ring_buffer_va, |
| 224 | workload->rb_len); |
| 225 | |
| 226 | cs += workload->rb_len / sizeof(u32); |
| 227 | intel_ring_advance(workload->req, cs); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 232 | void release_shadow_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx) |
| 233 | { |
| 234 | if (!wa_ctx->indirect_ctx.obj) |
| 235 | return; |
| 236 | |
| 237 | i915_gem_object_unpin_map(wa_ctx->indirect_ctx.obj); |
| 238 | i915_gem_object_put(wa_ctx->indirect_ctx.obj); |
| 239 | } |
| 240 | |
Ping Gao | 89ea20b | 2017-06-29 12:22:42 +0800 | [diff] [blame] | 241 | /** |
| 242 | * intel_gvt_scan_and_shadow_workload - audit the workload by scanning and |
| 243 | * shadow it as well, include ringbuffer,wa_ctx and ctx. |
| 244 | * @workload: an abstract entity for each execlist submission. |
| 245 | * |
| 246 | * This function is called before the workload submitting to i915, to make |
| 247 | * sure the content of the workload is valid. |
| 248 | */ |
| 249 | int intel_gvt_scan_and_shadow_workload(struct intel_vgpu_workload *workload) |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 250 | { |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 251 | int ring_id = workload->ring_id; |
| 252 | struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx; |
| 253 | struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 254 | struct intel_engine_cs *engine = dev_priv->engine[ring_id]; |
Chris Wilson | 0eb742d | 2016-10-20 17:29:36 +0800 | [diff] [blame] | 255 | struct drm_i915_gem_request *rq; |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 256 | struct intel_vgpu *vgpu = workload->vgpu; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 257 | struct intel_ring *ring; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 258 | int ret; |
| 259 | |
Ping Gao | 87e919d | 2017-07-04 14:53:03 +0800 | [diff] [blame] | 260 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 261 | |
Ping Gao | d0302e7 | 2017-06-29 12:22:43 +0800 | [diff] [blame] | 262 | if (workload->shadowed) |
| 263 | return 0; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 264 | |
Zhenyu Wang | 03806ed | 2017-02-13 17:07:19 +0800 | [diff] [blame] | 265 | shadow_ctx->desc_template &= ~(0x3 << GEN8_CTX_ADDRESSING_MODE_SHIFT); |
| 266 | shadow_ctx->desc_template |= workload->ctx_desc.addressing_mode << |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 267 | GEN8_CTX_ADDRESSING_MODE_SHIFT; |
| 268 | |
Kechen Lu | 9dfb8e5 | 2017-08-10 07:41:36 +0800 | [diff] [blame] | 269 | if (!test_and_set_bit(ring_id, vgpu->shadow_ctx_desc_updated)) |
| 270 | shadow_context_descriptor_update(shadow_ctx, |
| 271 | dev_priv->engine[ring_id]); |
Chuanxiao Dong | 3cd23b8 | 2017-03-16 09:47:58 +0800 | [diff] [blame] | 272 | |
Ping Gao | 89ea20b | 2017-06-29 12:22:42 +0800 | [diff] [blame] | 273 | ret = intel_gvt_scan_and_shadow_ringbuffer(workload); |
Zhi Wang | be1da70 | 2016-05-03 18:26:57 -0400 | [diff] [blame] | 274 | if (ret) |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 275 | goto err_scan; |
Zhi Wang | be1da70 | 2016-05-03 18:26:57 -0400 | [diff] [blame] | 276 | |
Tina Zhang | 17f1b1a | 2017-03-15 23:16:01 -0400 | [diff] [blame] | 277 | if ((workload->ring_id == RCS) && |
| 278 | (workload->wa_ctx.indirect_ctx.size != 0)) { |
| 279 | ret = intel_gvt_scan_and_shadow_wa_ctx(&workload->wa_ctx); |
| 280 | if (ret) |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 281 | goto err_scan; |
Tina Zhang | 17f1b1a | 2017-03-15 23:16:01 -0400 | [diff] [blame] | 282 | } |
Zhi Wang | be1da70 | 2016-05-03 18:26:57 -0400 | [diff] [blame] | 283 | |
Ping Gao | 89ea20b | 2017-06-29 12:22:42 +0800 | [diff] [blame] | 284 | /* pin shadow context by gvt even the shadow context will be pinned |
| 285 | * when i915 alloc request. That is because gvt will update the guest |
| 286 | * context from shadow context when workload is completed, and at that |
| 287 | * moment, i915 may already unpined the shadow context to make the |
| 288 | * shadow_ctx pages invalid. So gvt need to pin itself. After update |
| 289 | * the guest context, gvt can unpin the shadow_ctx safely. |
| 290 | */ |
| 291 | ring = engine->context_pin(engine, shadow_ctx); |
| 292 | if (IS_ERR(ring)) { |
| 293 | ret = PTR_ERR(ring); |
| 294 | gvt_vgpu_err("fail to pin shadow context\n"); |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 295 | goto err_shadow; |
Ping Gao | 89ea20b | 2017-06-29 12:22:42 +0800 | [diff] [blame] | 296 | } |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 297 | |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 298 | ret = populate_shadow_context(workload); |
| 299 | if (ret) |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 300 | goto err_unpin; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 301 | |
| 302 | rq = i915_gem_request_alloc(dev_priv->engine[ring_id], shadow_ctx); |
| 303 | if (IS_ERR(rq)) { |
| 304 | gvt_vgpu_err("fail to allocate gem request\n"); |
| 305 | ret = PTR_ERR(rq); |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 306 | goto err_unpin; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | gvt_dbg_sched("ring id %d get i915 gem request %p\n", ring_id, rq); |
| 310 | |
| 311 | workload->req = i915_gem_request_get(rq); |
| 312 | ret = copy_workload_to_ring_buffer(workload); |
| 313 | if (ret) |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 314 | goto err_unpin; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 315 | workload->shadowed = true; |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 316 | return 0; |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 317 | |
fred gao | a3cfdca | 2017-08-18 15:41:07 +0800 | [diff] [blame] | 318 | err_unpin: |
| 319 | engine->context_unpin(engine, shadow_ctx); |
| 320 | err_shadow: |
| 321 | release_shadow_wa_ctx(&workload->wa_ctx); |
| 322 | err_scan: |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | static int dispatch_workload(struct intel_vgpu_workload *workload) |
| 327 | { |
| 328 | int ring_id = workload->ring_id; |
| 329 | struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx; |
| 330 | struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv; |
| 331 | struct intel_engine_cs *engine = dev_priv->engine[ring_id]; |
| 332 | int ret = 0; |
| 333 | |
| 334 | gvt_dbg_sched("ring id %d prepare to dispatch workload %p\n", |
| 335 | ring_id, workload); |
| 336 | |
| 337 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 338 | |
| 339 | ret = intel_gvt_scan_and_shadow_workload(workload); |
| 340 | if (ret) |
| 341 | goto out; |
| 342 | |
| 343 | if (workload->prepare) { |
| 344 | ret = workload->prepare(workload); |
fred gao | 0f43702 | 2017-08-18 15:41:10 +0800 | [diff] [blame] | 345 | if (ret) { |
| 346 | engine->context_unpin(engine, shadow_ctx); |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 347 | goto out; |
fred gao | 0f43702 | 2017-08-18 15:41:10 +0800 | [diff] [blame] | 348 | } |
fred gao | 0a53bc0 | 2017-08-18 15:41:06 +0800 | [diff] [blame] | 349 | } |
| 350 | |
Pei Zhang | 90d27a1 | 2016-11-14 18:02:57 +0800 | [diff] [blame] | 351 | out: |
| 352 | if (ret) |
| 353 | workload->status = ret; |
Chris Wilson | 0eb742d | 2016-10-20 17:29:36 +0800 | [diff] [blame] | 354 | |
Ping Gao | 89ea20b | 2017-06-29 12:22:42 +0800 | [diff] [blame] | 355 | if (!IS_ERR_OR_NULL(workload->req)) { |
| 356 | gvt_dbg_sched("ring id %d submit workload to i915 %p\n", |
| 357 | ring_id, workload->req); |
| 358 | i915_add_request(workload->req); |
| 359 | workload->dispatched = true; |
| 360 | } |
Chuanxiao Dong | 3cd23b8 | 2017-03-16 09:47:58 +0800 | [diff] [blame] | 361 | |
Pei Zhang | 90d27a1 | 2016-11-14 18:02:57 +0800 | [diff] [blame] | 362 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | static struct intel_vgpu_workload *pick_next_workload( |
| 367 | struct intel_gvt *gvt, int ring_id) |
| 368 | { |
| 369 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
| 370 | struct intel_vgpu_workload *workload = NULL; |
| 371 | |
| 372 | mutex_lock(&gvt->lock); |
| 373 | |
| 374 | /* |
| 375 | * no current vgpu / will be scheduled out / no workload |
| 376 | * bail out |
| 377 | */ |
| 378 | if (!scheduler->current_vgpu) { |
| 379 | gvt_dbg_sched("ring id %d stop - no current vgpu\n", ring_id); |
| 380 | goto out; |
| 381 | } |
| 382 | |
| 383 | if (scheduler->need_reschedule) { |
| 384 | gvt_dbg_sched("ring id %d stop - will reschedule\n", ring_id); |
| 385 | goto out; |
| 386 | } |
| 387 | |
Zhenyu Wang | 954180a | 2017-04-12 14:22:50 +0800 | [diff] [blame] | 388 | if (list_empty(workload_q_head(scheduler->current_vgpu, ring_id))) |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 389 | goto out; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * still have current workload, maybe the workload disptacher |
| 393 | * fail to submit it for some reason, resubmit it. |
| 394 | */ |
| 395 | if (scheduler->current_workload[ring_id]) { |
| 396 | workload = scheduler->current_workload[ring_id]; |
| 397 | gvt_dbg_sched("ring id %d still have current workload %p\n", |
| 398 | ring_id, workload); |
| 399 | goto out; |
| 400 | } |
| 401 | |
| 402 | /* |
| 403 | * pick a workload as current workload |
| 404 | * once current workload is set, schedule policy routines |
| 405 | * will wait the current workload is finished when trying to |
| 406 | * schedule out a vgpu. |
| 407 | */ |
| 408 | scheduler->current_workload[ring_id] = container_of( |
| 409 | workload_q_head(scheduler->current_vgpu, ring_id)->next, |
| 410 | struct intel_vgpu_workload, list); |
| 411 | |
| 412 | workload = scheduler->current_workload[ring_id]; |
| 413 | |
| 414 | gvt_dbg_sched("ring id %d pick new workload %p\n", ring_id, workload); |
| 415 | |
| 416 | atomic_inc(&workload->vgpu->running_workload_num); |
| 417 | out: |
| 418 | mutex_unlock(&gvt->lock); |
| 419 | return workload; |
| 420 | } |
| 421 | |
| 422 | static void update_guest_context(struct intel_vgpu_workload *workload) |
| 423 | { |
| 424 | struct intel_vgpu *vgpu = workload->vgpu; |
| 425 | struct intel_gvt *gvt = vgpu->gvt; |
| 426 | int ring_id = workload->ring_id; |
| 427 | struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx; |
| 428 | struct drm_i915_gem_object *ctx_obj = |
| 429 | shadow_ctx->engine[ring_id].state->obj; |
| 430 | struct execlist_ring_context *shadow_ring_context; |
| 431 | struct page *page; |
| 432 | void *src; |
| 433 | unsigned long context_gpa, context_page_num; |
| 434 | int i; |
| 435 | |
| 436 | gvt_dbg_sched("ring id %d workload lrca %x\n", ring_id, |
| 437 | workload->ctx_desc.lrca); |
| 438 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 439 | context_page_num = gvt->dev_priv->engine[ring_id]->context_size; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 440 | |
| 441 | context_page_num = context_page_num >> PAGE_SHIFT; |
| 442 | |
| 443 | if (IS_BROADWELL(gvt->dev_priv) && ring_id == RCS) |
| 444 | context_page_num = 19; |
| 445 | |
| 446 | i = 2; |
| 447 | |
| 448 | while (i < context_page_num) { |
| 449 | context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm, |
| 450 | (u32)((workload->ctx_desc.lrca + i) << |
| 451 | GTT_PAGE_SHIFT)); |
| 452 | if (context_gpa == INTEL_GVT_INVALID_ADDR) { |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 453 | gvt_vgpu_err("invalid guest context descriptor\n"); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 454 | return; |
| 455 | } |
| 456 | |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame^] | 457 | page = i915_gem_object_get_page(ctx_obj, LRC_HEADER_PAGES + i); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 458 | src = kmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 459 | intel_gvt_hypervisor_write_gpa(vgpu, context_gpa, src, |
| 460 | GTT_PAGE_SIZE); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 461 | kunmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 462 | i++; |
| 463 | } |
| 464 | |
| 465 | intel_gvt_hypervisor_write_gpa(vgpu, workload->ring_context_gpa + |
| 466 | RING_CTX_OFF(ring_header.val), &workload->rb_tail, 4); |
| 467 | |
| 468 | page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN); |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 469 | shadow_ring_context = kmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 470 | |
| 471 | #define COPY_REG(name) \ |
| 472 | intel_gvt_hypervisor_write_gpa(vgpu, workload->ring_context_gpa + \ |
| 473 | RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4) |
| 474 | |
| 475 | COPY_REG(ctx_ctrl); |
| 476 | COPY_REG(ctx_timestamp); |
| 477 | |
| 478 | #undef COPY_REG |
| 479 | |
| 480 | intel_gvt_hypervisor_write_gpa(vgpu, |
| 481 | workload->ring_context_gpa + |
| 482 | sizeof(*shadow_ring_context), |
| 483 | (void *)shadow_ring_context + |
| 484 | sizeof(*shadow_ring_context), |
| 485 | GTT_PAGE_SIZE - sizeof(*shadow_ring_context)); |
| 486 | |
Xiaoguang Chen | c754936 | 2016-11-03 18:38:30 +0800 | [diff] [blame] | 487 | kunmap(page); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static void complete_current_workload(struct intel_gvt *gvt, int ring_id) |
| 491 | { |
| 492 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
| 493 | struct intel_vgpu_workload *workload; |
Changbin Du | 440a9b9 | 2017-01-05 16:49:03 +0800 | [diff] [blame] | 494 | struct intel_vgpu *vgpu; |
Zhi Wang | be1da70 | 2016-05-03 18:26:57 -0400 | [diff] [blame] | 495 | int event; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 496 | |
| 497 | mutex_lock(&gvt->lock); |
| 498 | |
| 499 | workload = scheduler->current_workload[ring_id]; |
Changbin Du | 440a9b9 | 2017-01-05 16:49:03 +0800 | [diff] [blame] | 500 | vgpu = workload->vgpu; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 501 | |
Chuanxiao Dong | 8f1117a | 2017-03-06 13:05:24 +0800 | [diff] [blame] | 502 | /* For the workload w/ request, needs to wait for the context |
| 503 | * switch to make sure request is completed. |
| 504 | * For the workload w/o request, directly complete the workload. |
| 505 | */ |
| 506 | if (workload->req) { |
Chuanxiao Dong | 3cd23b8 | 2017-03-16 09:47:58 +0800 | [diff] [blame] | 507 | struct drm_i915_private *dev_priv = |
| 508 | workload->vgpu->gvt->dev_priv; |
| 509 | struct intel_engine_cs *engine = |
| 510 | dev_priv->engine[workload->ring_id]; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 511 | wait_event(workload->shadow_ctx_status_wq, |
| 512 | !atomic_read(&workload->shadow_ctx_active)); |
| 513 | |
Chuanxiao Dong | 0cf5ec4 | 2017-06-23 13:01:11 +0800 | [diff] [blame] | 514 | /* If this request caused GPU hang, req->fence.error will |
| 515 | * be set to -EIO. Use -EIO to set workload status so |
| 516 | * that when this request caused GPU hang, didn't trigger |
| 517 | * context switch interrupt to guest. |
| 518 | */ |
| 519 | if (likely(workload->status == -EINPROGRESS)) { |
| 520 | if (workload->req->fence.error == -EIO) |
| 521 | workload->status = -EIO; |
| 522 | else |
| 523 | workload->status = 0; |
| 524 | } |
| 525 | |
Chuanxiao Dong | 8f1117a | 2017-03-06 13:05:24 +0800 | [diff] [blame] | 526 | i915_gem_request_put(fetch_and_zero(&workload->req)); |
Zhi Wang | be1da70 | 2016-05-03 18:26:57 -0400 | [diff] [blame] | 527 | |
Chuanxiao Dong | 6184cc8 | 2017-08-01 17:47:25 +0800 | [diff] [blame] | 528 | if (!workload->status && !(vgpu->resetting_eng & |
| 529 | ENGINE_MASK(ring_id))) { |
Chuanxiao Dong | 8f1117a | 2017-03-06 13:05:24 +0800 | [diff] [blame] | 530 | update_guest_context(workload); |
| 531 | |
| 532 | for_each_set_bit(event, workload->pending_events, |
| 533 | INTEL_GVT_EVENT_MAX) |
| 534 | intel_vgpu_trigger_virtual_event(vgpu, event); |
| 535 | } |
Chuanxiao Dong | 3cd23b8 | 2017-03-16 09:47:58 +0800 | [diff] [blame] | 536 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 537 | /* unpin shadow ctx as the shadow_ctx update is done */ |
| 538 | engine->context_unpin(engine, workload->vgpu->shadow_ctx); |
| 539 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | gvt_dbg_sched("ring id %d complete workload %p status %d\n", |
| 543 | ring_id, workload, workload->status); |
| 544 | |
| 545 | scheduler->current_workload[ring_id] = NULL; |
| 546 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 547 | list_del_init(&workload->list); |
| 548 | workload->complete(workload); |
| 549 | |
Changbin Du | 440a9b9 | 2017-01-05 16:49:03 +0800 | [diff] [blame] | 550 | atomic_dec(&vgpu->running_workload_num); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 551 | wake_up(&scheduler->workload_complete_wq); |
Ping Gao | f100dae | 2017-05-24 09:14:11 +0800 | [diff] [blame] | 552 | |
| 553 | if (gvt->scheduler.need_reschedule) |
| 554 | intel_gvt_request_service(gvt, INTEL_GVT_REQUEST_EVENT_SCHED); |
| 555 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 556 | mutex_unlock(&gvt->lock); |
| 557 | } |
| 558 | |
| 559 | struct workload_thread_param { |
| 560 | struct intel_gvt *gvt; |
| 561 | int ring_id; |
| 562 | }; |
| 563 | |
| 564 | static int workload_thread(void *priv) |
| 565 | { |
| 566 | struct workload_thread_param *p = (struct workload_thread_param *)priv; |
| 567 | struct intel_gvt *gvt = p->gvt; |
| 568 | int ring_id = p->ring_id; |
| 569 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
| 570 | struct intel_vgpu_workload *workload = NULL; |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 571 | struct intel_vgpu *vgpu = NULL; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 572 | int ret; |
Xu Han | e3476c0 | 2017-03-29 10:13:59 +0800 | [diff] [blame] | 573 | bool need_force_wake = IS_SKYLAKE(gvt->dev_priv) |
| 574 | || IS_KABYLAKE(gvt->dev_priv); |
Du, Changbin | e45d7b7 | 2016-10-27 11:10:31 +0800 | [diff] [blame] | 575 | DEFINE_WAIT_FUNC(wait, woken_wake_function); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 576 | |
| 577 | kfree(p); |
| 578 | |
| 579 | gvt_dbg_core("workload thread for ring %d started\n", ring_id); |
| 580 | |
| 581 | while (!kthread_should_stop()) { |
Du, Changbin | e45d7b7 | 2016-10-27 11:10:31 +0800 | [diff] [blame] | 582 | add_wait_queue(&scheduler->waitq[ring_id], &wait); |
| 583 | do { |
| 584 | workload = pick_next_workload(gvt, ring_id); |
| 585 | if (workload) |
| 586 | break; |
| 587 | wait_woken(&wait, TASK_INTERRUPTIBLE, |
| 588 | MAX_SCHEDULE_TIMEOUT); |
| 589 | } while (!kthread_should_stop()); |
| 590 | remove_wait_queue(&scheduler->waitq[ring_id], &wait); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 591 | |
Du, Changbin | e45d7b7 | 2016-10-27 11:10:31 +0800 | [diff] [blame] | 592 | if (!workload) |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | gvt_dbg_sched("ring id %d next workload %p vgpu %d\n", |
| 596 | workload->ring_id, workload, |
| 597 | workload->vgpu->id); |
| 598 | |
| 599 | intel_runtime_pm_get(gvt->dev_priv); |
| 600 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 601 | gvt_dbg_sched("ring id %d will dispatch workload %p\n", |
| 602 | workload->ring_id, workload); |
| 603 | |
| 604 | if (need_force_wake) |
| 605 | intel_uncore_forcewake_get(gvt->dev_priv, |
| 606 | FORCEWAKE_ALL); |
| 607 | |
Pei Zhang | 90d27a1 | 2016-11-14 18:02:57 +0800 | [diff] [blame] | 608 | mutex_lock(&gvt->lock); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 609 | ret = dispatch_workload(workload); |
Pei Zhang | 90d27a1 | 2016-11-14 18:02:57 +0800 | [diff] [blame] | 610 | mutex_unlock(&gvt->lock); |
Chris Wilson | 66bbc3b | 2016-10-19 11:11:44 +0100 | [diff] [blame] | 611 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 612 | if (ret) { |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 613 | vgpu = workload->vgpu; |
| 614 | gvt_vgpu_err("fail to dispatch workload, skip\n"); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 615 | goto complete; |
| 616 | } |
| 617 | |
| 618 | gvt_dbg_sched("ring id %d wait workload %p\n", |
| 619 | workload->ring_id, workload); |
Chris Wilson | 3dce2ac | 2017-03-08 22:08:08 +0000 | [diff] [blame] | 620 | i915_wait_request(workload->req, 0, MAX_SCHEDULE_TIMEOUT); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 621 | |
| 622 | complete: |
Changbin Du | 3ce3274 | 2017-02-09 10:13:16 +0800 | [diff] [blame] | 623 | gvt_dbg_sched("will complete workload %p, status: %d\n", |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 624 | workload, workload->status); |
| 625 | |
Changbin Du | 2e51ef3 | 2017-01-05 13:28:05 +0800 | [diff] [blame] | 626 | complete_current_workload(gvt, ring_id); |
| 627 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 628 | if (need_force_wake) |
| 629 | intel_uncore_forcewake_put(gvt->dev_priv, |
| 630 | FORCEWAKE_ALL); |
| 631 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 632 | intel_runtime_pm_put(gvt->dev_priv); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 633 | } |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu) |
| 638 | { |
| 639 | struct intel_gvt *gvt = vgpu->gvt; |
| 640 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
| 641 | |
| 642 | if (atomic_read(&vgpu->running_workload_num)) { |
| 643 | gvt_dbg_sched("wait vgpu idle\n"); |
| 644 | |
| 645 | wait_event(scheduler->workload_complete_wq, |
| 646 | !atomic_read(&vgpu->running_workload_num)); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt) |
| 651 | { |
| 652 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 653 | struct intel_engine_cs *engine; |
| 654 | enum intel_engine_id i; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 655 | |
| 656 | gvt_dbg_core("clean workload scheduler\n"); |
| 657 | |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 658 | for_each_engine(engine, gvt->dev_priv, i) { |
| 659 | atomic_notifier_chain_unregister( |
| 660 | &engine->context_status_notifier, |
| 661 | &gvt->shadow_ctx_notifier_block[i]); |
| 662 | kthread_stop(scheduler->thread[i]); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt) |
| 667 | { |
| 668 | struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; |
| 669 | struct workload_thread_param *param = NULL; |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 670 | struct intel_engine_cs *engine; |
| 671 | enum intel_engine_id i; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 672 | int ret; |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 673 | |
| 674 | gvt_dbg_core("init workload scheduler\n"); |
| 675 | |
| 676 | init_waitqueue_head(&scheduler->workload_complete_wq); |
| 677 | |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 678 | for_each_engine(engine, gvt->dev_priv, i) { |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 679 | init_waitqueue_head(&scheduler->waitq[i]); |
| 680 | |
| 681 | param = kzalloc(sizeof(*param), GFP_KERNEL); |
| 682 | if (!param) { |
| 683 | ret = -ENOMEM; |
| 684 | goto err; |
| 685 | } |
| 686 | |
| 687 | param->gvt = gvt; |
| 688 | param->ring_id = i; |
| 689 | |
| 690 | scheduler->thread[i] = kthread_run(workload_thread, param, |
| 691 | "gvt workload %d", i); |
| 692 | if (IS_ERR(scheduler->thread[i])) { |
| 693 | gvt_err("fail to create workload thread\n"); |
| 694 | ret = PTR_ERR(scheduler->thread[i]); |
| 695 | goto err; |
| 696 | } |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 697 | |
| 698 | gvt->shadow_ctx_notifier_block[i].notifier_call = |
| 699 | shadow_context_status_change; |
| 700 | atomic_notifier_chain_register(&engine->context_status_notifier, |
| 701 | &gvt->shadow_ctx_notifier_block[i]); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 702 | } |
| 703 | return 0; |
| 704 | err: |
| 705 | intel_gvt_clean_workload_scheduler(gvt); |
| 706 | kfree(param); |
| 707 | param = NULL; |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | void intel_vgpu_clean_gvt_context(struct intel_vgpu *vgpu) |
| 712 | { |
Chris Wilson | 5f09a9c | 2017-06-20 12:05:46 +0100 | [diff] [blame] | 713 | i915_gem_context_put(vgpu->shadow_ctx); |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | int intel_vgpu_init_gvt_context(struct intel_vgpu *vgpu) |
| 717 | { |
| 718 | atomic_set(&vgpu->running_workload_num, 0); |
| 719 | |
| 720 | vgpu->shadow_ctx = i915_gem_context_create_gvt( |
| 721 | &vgpu->gvt->dev_priv->drm); |
| 722 | if (IS_ERR(vgpu->shadow_ctx)) |
| 723 | return PTR_ERR(vgpu->shadow_ctx); |
| 724 | |
| 725 | vgpu->shadow_ctx->engine[RCS].initialised = true; |
| 726 | |
Kechen Lu | 9dfb8e5 | 2017-08-10 07:41:36 +0800 | [diff] [blame] | 727 | bitmap_zero(vgpu->shadow_ctx_desc_updated, I915_NUM_ENGINES); |
| 728 | |
Zhi Wang | e473405 | 2016-05-01 07:42:16 -0400 | [diff] [blame] | 729 | return 0; |
| 730 | } |