scheduler.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. #include <linux/kthread.h>
  36. #include "i915_drv.h"
  37. #include "gvt.h"
  38. #define RING_CTX_OFF(x) \
  39. offsetof(struct execlist_ring_context, x)
  40. static void set_context_pdp_root_pointer(
  41. struct execlist_ring_context *ring_context,
  42. u32 pdp[8])
  43. {
  44. struct execlist_mmio_pair *pdp_pair = &ring_context->pdp3_UDW;
  45. int i;
  46. for (i = 0; i < 8; i++)
  47. pdp_pair[i].val = pdp[7 - i];
  48. }
  49. static int populate_shadow_context(struct intel_vgpu_workload *workload)
  50. {
  51. struct intel_vgpu *vgpu = workload->vgpu;
  52. struct intel_gvt *gvt = vgpu->gvt;
  53. int ring_id = workload->ring_id;
  54. struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx;
  55. struct drm_i915_gem_object *ctx_obj =
  56. shadow_ctx->engine[ring_id].state->obj;
  57. struct execlist_ring_context *shadow_ring_context;
  58. struct page *page;
  59. void *dst;
  60. unsigned long context_gpa, context_page_num;
  61. int i;
  62. gvt_dbg_sched("ring id %d workload lrca %x", ring_id,
  63. workload->ctx_desc.lrca);
  64. context_page_num = intel_lr_context_size(
  65. gvt->dev_priv->engine[ring_id]);
  66. context_page_num = context_page_num >> PAGE_SHIFT;
  67. if (IS_BROADWELL(gvt->dev_priv) && ring_id == RCS)
  68. context_page_num = 19;
  69. i = 2;
  70. while (i < context_page_num) {
  71. context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm,
  72. (u32)((workload->ctx_desc.lrca + i) <<
  73. GTT_PAGE_SHIFT));
  74. if (context_gpa == INTEL_GVT_INVALID_ADDR) {
  75. gvt_vgpu_err("Invalid guest context descriptor\n");
  76. return -EINVAL;
  77. }
  78. page = i915_gem_object_get_page(ctx_obj, LRC_PPHWSP_PN + i);
  79. dst = kmap(page);
  80. intel_gvt_hypervisor_read_gpa(vgpu, context_gpa, dst,
  81. GTT_PAGE_SIZE);
  82. kunmap(page);
  83. i++;
  84. }
  85. page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
  86. shadow_ring_context = kmap(page);
  87. #define COPY_REG(name) \
  88. intel_gvt_hypervisor_read_gpa(vgpu, workload->ring_context_gpa \
  89. + RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4)
  90. COPY_REG(ctx_ctrl);
  91. COPY_REG(ctx_timestamp);
  92. if (ring_id == RCS) {
  93. COPY_REG(bb_per_ctx_ptr);
  94. COPY_REG(rcs_indirect_ctx);
  95. COPY_REG(rcs_indirect_ctx_offset);
  96. }
  97. #undef COPY_REG
  98. set_context_pdp_root_pointer(shadow_ring_context,
  99. workload->shadow_mm->shadow_page_table);
  100. intel_gvt_hypervisor_read_gpa(vgpu,
  101. workload->ring_context_gpa +
  102. sizeof(*shadow_ring_context),
  103. (void *)shadow_ring_context +
  104. sizeof(*shadow_ring_context),
  105. GTT_PAGE_SIZE - sizeof(*shadow_ring_context));
  106. kunmap(page);
  107. return 0;
  108. }
  109. static inline bool is_gvt_request(struct drm_i915_gem_request *req)
  110. {
  111. return i915_gem_context_force_single_submission(req->ctx);
  112. }
  113. static int shadow_context_status_change(struct notifier_block *nb,
  114. unsigned long action, void *data)
  115. {
  116. struct drm_i915_gem_request *req = (struct drm_i915_gem_request *)data;
  117. struct intel_gvt *gvt = container_of(nb, struct intel_gvt,
  118. shadow_ctx_notifier_block[req->engine->id]);
  119. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  120. struct intel_vgpu_workload *workload =
  121. scheduler->current_workload[req->engine->id];
  122. if (!is_gvt_request(req) || unlikely(!workload))
  123. return NOTIFY_OK;
  124. switch (action) {
  125. case INTEL_CONTEXT_SCHEDULE_IN:
  126. intel_gvt_load_render_mmio(workload->vgpu,
  127. workload->ring_id);
  128. atomic_set(&workload->shadow_ctx_active, 1);
  129. break;
  130. case INTEL_CONTEXT_SCHEDULE_OUT:
  131. intel_gvt_restore_render_mmio(workload->vgpu,
  132. workload->ring_id);
  133. /* If the status is -EINPROGRESS means this workload
  134. * doesn't meet any issue during dispatching so when
  135. * get the SCHEDULE_OUT set the status to be zero for
  136. * good. If the status is NOT -EINPROGRESS means there
  137. * is something wrong happened during dispatching and
  138. * the status should not be set to zero
  139. */
  140. if (workload->status == -EINPROGRESS)
  141. workload->status = 0;
  142. atomic_set(&workload->shadow_ctx_active, 0);
  143. break;
  144. default:
  145. WARN_ON(1);
  146. return NOTIFY_OK;
  147. }
  148. wake_up(&workload->shadow_ctx_status_wq);
  149. return NOTIFY_OK;
  150. }
  151. static int dispatch_workload(struct intel_vgpu_workload *workload)
  152. {
  153. int ring_id = workload->ring_id;
  154. struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx;
  155. struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv;
  156. struct intel_engine_cs *engine = dev_priv->engine[ring_id];
  157. struct drm_i915_gem_request *rq;
  158. struct intel_vgpu *vgpu = workload->vgpu;
  159. int ret;
  160. gvt_dbg_sched("ring id %d prepare to dispatch workload %p\n",
  161. ring_id, workload);
  162. shadow_ctx->desc_template &= ~(0x3 << GEN8_CTX_ADDRESSING_MODE_SHIFT);
  163. shadow_ctx->desc_template |= workload->ctx_desc.addressing_mode <<
  164. GEN8_CTX_ADDRESSING_MODE_SHIFT;
  165. mutex_lock(&dev_priv->drm.struct_mutex);
  166. /* pin shadow context by gvt even the shadow context will be pinned
  167. * when i915 alloc request. That is because gvt will update the guest
  168. * context from shadow context when workload is completed, and at that
  169. * moment, i915 may already unpined the shadow context to make the
  170. * shadow_ctx pages invalid. So gvt need to pin itself. After update
  171. * the guest context, gvt can unpin the shadow_ctx safely.
  172. */
  173. ret = engine->context_pin(engine, shadow_ctx);
  174. if (ret) {
  175. gvt_vgpu_err("fail to pin shadow context\n");
  176. workload->status = ret;
  177. mutex_unlock(&dev_priv->drm.struct_mutex);
  178. return ret;
  179. }
  180. rq = i915_gem_request_alloc(dev_priv->engine[ring_id], shadow_ctx);
  181. if (IS_ERR(rq)) {
  182. gvt_vgpu_err("fail to allocate gem request\n");
  183. ret = PTR_ERR(rq);
  184. goto out;
  185. }
  186. gvt_dbg_sched("ring id %d get i915 gem request %p\n", ring_id, rq);
  187. workload->req = i915_gem_request_get(rq);
  188. ret = intel_gvt_scan_and_shadow_workload(workload);
  189. if (ret)
  190. goto out;
  191. if ((workload->ring_id == RCS) &&
  192. (workload->wa_ctx.indirect_ctx.size != 0)) {
  193. ret = intel_gvt_scan_and_shadow_wa_ctx(&workload->wa_ctx);
  194. if (ret)
  195. goto out;
  196. }
  197. ret = populate_shadow_context(workload);
  198. if (ret)
  199. goto out;
  200. if (workload->prepare) {
  201. ret = workload->prepare(workload);
  202. if (ret)
  203. goto out;
  204. }
  205. gvt_dbg_sched("ring id %d submit workload to i915 %p\n",
  206. ring_id, workload->req);
  207. ret = 0;
  208. workload->dispatched = true;
  209. out:
  210. if (ret)
  211. workload->status = ret;
  212. if (!IS_ERR_OR_NULL(rq))
  213. i915_add_request_no_flush(rq);
  214. else
  215. engine->context_unpin(engine, shadow_ctx);
  216. mutex_unlock(&dev_priv->drm.struct_mutex);
  217. return ret;
  218. }
  219. static struct intel_vgpu_workload *pick_next_workload(
  220. struct intel_gvt *gvt, int ring_id)
  221. {
  222. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  223. struct intel_vgpu_workload *workload = NULL;
  224. mutex_lock(&gvt->lock);
  225. /*
  226. * no current vgpu / will be scheduled out / no workload
  227. * bail out
  228. */
  229. if (!scheduler->current_vgpu) {
  230. gvt_dbg_sched("ring id %d stop - no current vgpu\n", ring_id);
  231. goto out;
  232. }
  233. if (scheduler->need_reschedule) {
  234. gvt_dbg_sched("ring id %d stop - will reschedule\n", ring_id);
  235. goto out;
  236. }
  237. if (list_empty(workload_q_head(scheduler->current_vgpu, ring_id))) {
  238. gvt_dbg_sched("ring id %d stop - no available workload\n",
  239. ring_id);
  240. goto out;
  241. }
  242. /*
  243. * still have current workload, maybe the workload disptacher
  244. * fail to submit it for some reason, resubmit it.
  245. */
  246. if (scheduler->current_workload[ring_id]) {
  247. workload = scheduler->current_workload[ring_id];
  248. gvt_dbg_sched("ring id %d still have current workload %p\n",
  249. ring_id, workload);
  250. goto out;
  251. }
  252. /*
  253. * pick a workload as current workload
  254. * once current workload is set, schedule policy routines
  255. * will wait the current workload is finished when trying to
  256. * schedule out a vgpu.
  257. */
  258. scheduler->current_workload[ring_id] = container_of(
  259. workload_q_head(scheduler->current_vgpu, ring_id)->next,
  260. struct intel_vgpu_workload, list);
  261. workload = scheduler->current_workload[ring_id];
  262. gvt_dbg_sched("ring id %d pick new workload %p\n", ring_id, workload);
  263. atomic_inc(&workload->vgpu->running_workload_num);
  264. out:
  265. mutex_unlock(&gvt->lock);
  266. return workload;
  267. }
  268. static void update_guest_context(struct intel_vgpu_workload *workload)
  269. {
  270. struct intel_vgpu *vgpu = workload->vgpu;
  271. struct intel_gvt *gvt = vgpu->gvt;
  272. int ring_id = workload->ring_id;
  273. struct i915_gem_context *shadow_ctx = workload->vgpu->shadow_ctx;
  274. struct drm_i915_gem_object *ctx_obj =
  275. shadow_ctx->engine[ring_id].state->obj;
  276. struct execlist_ring_context *shadow_ring_context;
  277. struct page *page;
  278. void *src;
  279. unsigned long context_gpa, context_page_num;
  280. int i;
  281. gvt_dbg_sched("ring id %d workload lrca %x\n", ring_id,
  282. workload->ctx_desc.lrca);
  283. context_page_num = intel_lr_context_size(
  284. gvt->dev_priv->engine[ring_id]);
  285. context_page_num = context_page_num >> PAGE_SHIFT;
  286. if (IS_BROADWELL(gvt->dev_priv) && ring_id == RCS)
  287. context_page_num = 19;
  288. i = 2;
  289. while (i < context_page_num) {
  290. context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm,
  291. (u32)((workload->ctx_desc.lrca + i) <<
  292. GTT_PAGE_SHIFT));
  293. if (context_gpa == INTEL_GVT_INVALID_ADDR) {
  294. gvt_vgpu_err("invalid guest context descriptor\n");
  295. return;
  296. }
  297. page = i915_gem_object_get_page(ctx_obj, LRC_PPHWSP_PN + i);
  298. src = kmap(page);
  299. intel_gvt_hypervisor_write_gpa(vgpu, context_gpa, src,
  300. GTT_PAGE_SIZE);
  301. kunmap(page);
  302. i++;
  303. }
  304. intel_gvt_hypervisor_write_gpa(vgpu, workload->ring_context_gpa +
  305. RING_CTX_OFF(ring_header.val), &workload->rb_tail, 4);
  306. page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
  307. shadow_ring_context = kmap(page);
  308. #define COPY_REG(name) \
  309. intel_gvt_hypervisor_write_gpa(vgpu, workload->ring_context_gpa + \
  310. RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4)
  311. COPY_REG(ctx_ctrl);
  312. COPY_REG(ctx_timestamp);
  313. #undef COPY_REG
  314. intel_gvt_hypervisor_write_gpa(vgpu,
  315. workload->ring_context_gpa +
  316. sizeof(*shadow_ring_context),
  317. (void *)shadow_ring_context +
  318. sizeof(*shadow_ring_context),
  319. GTT_PAGE_SIZE - sizeof(*shadow_ring_context));
  320. kunmap(page);
  321. }
  322. static void complete_current_workload(struct intel_gvt *gvt, int ring_id)
  323. {
  324. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  325. struct intel_vgpu_workload *workload;
  326. struct intel_vgpu *vgpu;
  327. int event;
  328. mutex_lock(&gvt->lock);
  329. workload = scheduler->current_workload[ring_id];
  330. vgpu = workload->vgpu;
  331. /* For the workload w/ request, needs to wait for the context
  332. * switch to make sure request is completed.
  333. * For the workload w/o request, directly complete the workload.
  334. */
  335. if (workload->req) {
  336. struct drm_i915_private *dev_priv =
  337. workload->vgpu->gvt->dev_priv;
  338. struct intel_engine_cs *engine =
  339. dev_priv->engine[workload->ring_id];
  340. wait_event(workload->shadow_ctx_status_wq,
  341. !atomic_read(&workload->shadow_ctx_active));
  342. i915_gem_request_put(fetch_and_zero(&workload->req));
  343. if (!workload->status && !vgpu->resetting) {
  344. update_guest_context(workload);
  345. for_each_set_bit(event, workload->pending_events,
  346. INTEL_GVT_EVENT_MAX)
  347. intel_vgpu_trigger_virtual_event(vgpu, event);
  348. }
  349. mutex_lock(&dev_priv->drm.struct_mutex);
  350. /* unpin shadow ctx as the shadow_ctx update is done */
  351. engine->context_unpin(engine, workload->vgpu->shadow_ctx);
  352. mutex_unlock(&dev_priv->drm.struct_mutex);
  353. }
  354. gvt_dbg_sched("ring id %d complete workload %p status %d\n",
  355. ring_id, workload, workload->status);
  356. scheduler->current_workload[ring_id] = NULL;
  357. list_del_init(&workload->list);
  358. workload->complete(workload);
  359. atomic_dec(&vgpu->running_workload_num);
  360. wake_up(&scheduler->workload_complete_wq);
  361. mutex_unlock(&gvt->lock);
  362. }
  363. struct workload_thread_param {
  364. struct intel_gvt *gvt;
  365. int ring_id;
  366. };
  367. static DEFINE_MUTEX(scheduler_mutex);
  368. static int workload_thread(void *priv)
  369. {
  370. struct workload_thread_param *p = (struct workload_thread_param *)priv;
  371. struct intel_gvt *gvt = p->gvt;
  372. int ring_id = p->ring_id;
  373. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  374. struct intel_vgpu_workload *workload = NULL;
  375. struct intel_vgpu *vgpu = NULL;
  376. int ret;
  377. bool need_force_wake = IS_SKYLAKE(gvt->dev_priv);
  378. DEFINE_WAIT_FUNC(wait, woken_wake_function);
  379. kfree(p);
  380. gvt_dbg_core("workload thread for ring %d started\n", ring_id);
  381. while (!kthread_should_stop()) {
  382. add_wait_queue(&scheduler->waitq[ring_id], &wait);
  383. do {
  384. workload = pick_next_workload(gvt, ring_id);
  385. if (workload)
  386. break;
  387. wait_woken(&wait, TASK_INTERRUPTIBLE,
  388. MAX_SCHEDULE_TIMEOUT);
  389. } while (!kthread_should_stop());
  390. remove_wait_queue(&scheduler->waitq[ring_id], &wait);
  391. if (!workload)
  392. break;
  393. mutex_lock(&scheduler_mutex);
  394. gvt_dbg_sched("ring id %d next workload %p vgpu %d\n",
  395. workload->ring_id, workload,
  396. workload->vgpu->id);
  397. intel_runtime_pm_get(gvt->dev_priv);
  398. gvt_dbg_sched("ring id %d will dispatch workload %p\n",
  399. workload->ring_id, workload);
  400. if (need_force_wake)
  401. intel_uncore_forcewake_get(gvt->dev_priv,
  402. FORCEWAKE_ALL);
  403. mutex_lock(&gvt->lock);
  404. ret = dispatch_workload(workload);
  405. mutex_unlock(&gvt->lock);
  406. if (ret) {
  407. vgpu = workload->vgpu;
  408. gvt_vgpu_err("fail to dispatch workload, skip\n");
  409. goto complete;
  410. }
  411. gvt_dbg_sched("ring id %d wait workload %p\n",
  412. workload->ring_id, workload);
  413. i915_wait_request(workload->req, 0, MAX_SCHEDULE_TIMEOUT);
  414. complete:
  415. gvt_dbg_sched("will complete workload %p, status: %d\n",
  416. workload, workload->status);
  417. complete_current_workload(gvt, ring_id);
  418. if (need_force_wake)
  419. intel_uncore_forcewake_put(gvt->dev_priv,
  420. FORCEWAKE_ALL);
  421. intel_runtime_pm_put(gvt->dev_priv);
  422. mutex_unlock(&scheduler_mutex);
  423. }
  424. return 0;
  425. }
  426. void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu)
  427. {
  428. struct intel_gvt *gvt = vgpu->gvt;
  429. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  430. if (atomic_read(&vgpu->running_workload_num)) {
  431. gvt_dbg_sched("wait vgpu idle\n");
  432. wait_event(scheduler->workload_complete_wq,
  433. !atomic_read(&vgpu->running_workload_num));
  434. }
  435. }
  436. void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt)
  437. {
  438. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  439. struct intel_engine_cs *engine;
  440. enum intel_engine_id i;
  441. gvt_dbg_core("clean workload scheduler\n");
  442. for_each_engine(engine, gvt->dev_priv, i) {
  443. atomic_notifier_chain_unregister(
  444. &engine->context_status_notifier,
  445. &gvt->shadow_ctx_notifier_block[i]);
  446. kthread_stop(scheduler->thread[i]);
  447. }
  448. }
  449. int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt)
  450. {
  451. struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
  452. struct workload_thread_param *param = NULL;
  453. struct intel_engine_cs *engine;
  454. enum intel_engine_id i;
  455. int ret;
  456. gvt_dbg_core("init workload scheduler\n");
  457. init_waitqueue_head(&scheduler->workload_complete_wq);
  458. for_each_engine(engine, gvt->dev_priv, i) {
  459. init_waitqueue_head(&scheduler->waitq[i]);
  460. param = kzalloc(sizeof(*param), GFP_KERNEL);
  461. if (!param) {
  462. ret = -ENOMEM;
  463. goto err;
  464. }
  465. param->gvt = gvt;
  466. param->ring_id = i;
  467. scheduler->thread[i] = kthread_run(workload_thread, param,
  468. "gvt workload %d", i);
  469. if (IS_ERR(scheduler->thread[i])) {
  470. gvt_err("fail to create workload thread\n");
  471. ret = PTR_ERR(scheduler->thread[i]);
  472. goto err;
  473. }
  474. gvt->shadow_ctx_notifier_block[i].notifier_call =
  475. shadow_context_status_change;
  476. atomic_notifier_chain_register(&engine->context_status_notifier,
  477. &gvt->shadow_ctx_notifier_block[i]);
  478. }
  479. return 0;
  480. err:
  481. intel_gvt_clean_workload_scheduler(gvt);
  482. kfree(param);
  483. param = NULL;
  484. return ret;
  485. }
  486. void intel_vgpu_clean_gvt_context(struct intel_vgpu *vgpu)
  487. {
  488. i915_gem_context_put_unlocked(vgpu->shadow_ctx);
  489. }
  490. int intel_vgpu_init_gvt_context(struct intel_vgpu *vgpu)
  491. {
  492. atomic_set(&vgpu->running_workload_num, 0);
  493. vgpu->shadow_ctx = i915_gem_context_create_gvt(
  494. &vgpu->gvt->dev_priv->drm);
  495. if (IS_ERR(vgpu->shadow_ctx))
  496. return PTR_ERR(vgpu->shadow_ctx);
  497. vgpu->shadow_ctx->engine[RCS].initialised = true;
  498. return 0;
  499. }