scheduler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 <[email protected]>
  25. *
  26. * Contributors:
  27. * Ping Gao <[email protected]>
  28. * Tina Zhang <[email protected]>
  29. * Chanbin Du <[email protected]>
  30. * Min He <[email protected]>
  31. * Bing Niu <[email protected]>
  32. * Zhenyu Wang <[email protected]>
  33. *
  34. */
  35. #ifndef _GVT_SCHEDULER_H_
  36. #define _GVT_SCHEDULER_H_
  37. #include "gt/intel_engine_types.h"
  38. #include "execlist.h"
  39. #include "interrupt.h"
  40. struct intel_gvt_workload_scheduler {
  41. struct intel_vgpu *current_vgpu;
  42. struct intel_vgpu *next_vgpu;
  43. struct intel_vgpu_workload *current_workload[I915_NUM_ENGINES];
  44. bool need_reschedule;
  45. spinlock_t mmio_context_lock;
  46. /* can be null when owner is host */
  47. struct intel_vgpu *engine_owner[I915_NUM_ENGINES];
  48. wait_queue_head_t workload_complete_wq;
  49. struct task_struct *thread[I915_NUM_ENGINES];
  50. wait_queue_head_t waitq[I915_NUM_ENGINES];
  51. void *sched_data;
  52. const struct intel_gvt_sched_policy_ops *sched_ops;
  53. };
  54. #define INDIRECT_CTX_ADDR_MASK 0xffffffc0
  55. #define INDIRECT_CTX_SIZE_MASK 0x3f
  56. struct shadow_indirect_ctx {
  57. struct drm_i915_gem_object *obj;
  58. unsigned long guest_gma;
  59. unsigned long shadow_gma;
  60. void *shadow_va;
  61. u32 size;
  62. };
  63. #define PER_CTX_ADDR_MASK 0xfffff000
  64. struct shadow_per_ctx {
  65. unsigned long guest_gma;
  66. unsigned long shadow_gma;
  67. unsigned valid;
  68. };
  69. struct intel_shadow_wa_ctx {
  70. struct shadow_indirect_ctx indirect_ctx;
  71. struct shadow_per_ctx per_ctx;
  72. };
  73. struct intel_vgpu_workload {
  74. struct intel_vgpu *vgpu;
  75. const struct intel_engine_cs *engine;
  76. struct i915_request *req;
  77. /* if this workload has been dispatched to i915? */
  78. bool dispatched;
  79. bool shadow; /* if workload has done shadow of guest request */
  80. int status;
  81. struct intel_vgpu_mm *shadow_mm;
  82. struct list_head lri_shadow_mm; /* For PPGTT load cmd */
  83. /* different submission model may need different handler */
  84. int (*prepare)(struct intel_vgpu_workload *);
  85. int (*complete)(struct intel_vgpu_workload *);
  86. struct list_head list;
  87. DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX);
  88. void *shadow_ring_buffer_va;
  89. /* execlist context information */
  90. struct execlist_ctx_descriptor_format ctx_desc;
  91. struct execlist_ring_context *ring_context;
  92. unsigned long rb_head, rb_tail, rb_ctl, rb_start, rb_len;
  93. unsigned long guest_rb_head;
  94. bool restore_inhibit;
  95. struct intel_vgpu_elsp_dwords elsp_dwords;
  96. bool emulate_schedule_in;
  97. atomic_t shadow_ctx_active;
  98. wait_queue_head_t shadow_ctx_status_wq;
  99. u64 ring_context_gpa;
  100. /* shadow batch buffer */
  101. struct list_head shadow_bb;
  102. struct intel_shadow_wa_ctx wa_ctx;
  103. /* oa registers */
  104. u32 oactxctrl;
  105. u32 flex_mmio[7];
  106. };
  107. struct intel_vgpu_shadow_bb {
  108. struct list_head list;
  109. struct drm_i915_gem_object *obj;
  110. struct i915_vma *vma;
  111. void *va;
  112. u32 *bb_start_cmd_va;
  113. unsigned long bb_offset;
  114. bool ppgtt;
  115. };
  116. #define workload_q_head(vgpu, e) \
  117. (&(vgpu)->submission.workload_q_head[(e)->id])
  118. void intel_vgpu_queue_workload(struct intel_vgpu_workload *workload);
  119. int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt);
  120. void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt);
  121. void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu);
  122. int intel_vgpu_setup_submission(struct intel_vgpu *vgpu);
  123. void intel_vgpu_reset_submission(struct intel_vgpu *vgpu,
  124. intel_engine_mask_t engine_mask);
  125. void intel_vgpu_clean_submission(struct intel_vgpu *vgpu);
  126. int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
  127. intel_engine_mask_t engine_mask,
  128. unsigned int interface);
  129. extern const struct intel_vgpu_submission_ops
  130. intel_vgpu_execlist_submission_ops;
  131. struct intel_vgpu_workload *
  132. intel_vgpu_create_workload(struct intel_vgpu *vgpu,
  133. const struct intel_engine_cs *engine,
  134. struct execlist_ctx_descriptor_format *desc);
  135. void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload);
  136. void intel_vgpu_clean_workloads(struct intel_vgpu *vgpu,
  137. intel_engine_mask_t engine_mask);
  138. #endif