128c4c6caSZhi Wang /* 228c4c6caSZhi Wang * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 328c4c6caSZhi Wang * 428c4c6caSZhi Wang * Permission is hereby granted, free of charge, to any person obtaining a 528c4c6caSZhi Wang * copy of this software and associated documentation files (the "Software"), 628c4c6caSZhi Wang * to deal in the Software without restriction, including without limitation 728c4c6caSZhi Wang * the rights to use, copy, modify, merge, publish, distribute, sublicense, 828c4c6caSZhi Wang * and/or sell copies of the Software, and to permit persons to whom the 928c4c6caSZhi Wang * Software is furnished to do so, subject to the following conditions: 1028c4c6caSZhi Wang * 1128c4c6caSZhi Wang * The above copyright notice and this permission notice (including the next 1228c4c6caSZhi Wang * paragraph) shall be included in all copies or substantial portions of the 1328c4c6caSZhi Wang * Software. 1428c4c6caSZhi Wang * 1528c4c6caSZhi Wang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1628c4c6caSZhi Wang * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1728c4c6caSZhi Wang * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1828c4c6caSZhi Wang * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1928c4c6caSZhi Wang * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2028c4c6caSZhi Wang * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2128c4c6caSZhi Wang * SOFTWARE. 22e4734057SZhi Wang * 23e4734057SZhi Wang * Authors: 24e4734057SZhi Wang * Zhi Wang <zhi.a.wang@intel.com> 25e4734057SZhi Wang * 26e4734057SZhi Wang * Contributors: 27e4734057SZhi Wang * Ping Gao <ping.a.gao@intel.com> 28e4734057SZhi Wang * Tina Zhang <tina.zhang@intel.com> 29e4734057SZhi Wang * Chanbin Du <changbin.du@intel.com> 30e4734057SZhi Wang * Min He <min.he@intel.com> 31e4734057SZhi Wang * Bing Niu <bing.niu@intel.com> 32e4734057SZhi Wang * Zhenyu Wang <zhenyuw@linux.intel.com> 33e4734057SZhi Wang * 3428c4c6caSZhi Wang */ 3528c4c6caSZhi Wang 3628c4c6caSZhi Wang #ifndef _GVT_SCHEDULER_H_ 3728c4c6caSZhi Wang #define _GVT_SCHEDULER_H_ 3828c4c6caSZhi Wang 3928c4c6caSZhi Wang struct intel_gvt_workload_scheduler { 40e4734057SZhi Wang struct intel_vgpu *current_vgpu; 41e4734057SZhi Wang struct intel_vgpu *next_vgpu; 42e4734057SZhi Wang struct intel_vgpu_workload *current_workload[I915_NUM_ENGINES]; 43e4734057SZhi Wang bool need_reschedule; 44e4734057SZhi Wang 450e86cc9cSChangbin Du spinlock_t mmio_context_lock; 460e86cc9cSChangbin Du /* can be null when owner is host */ 470e86cc9cSChangbin Du struct intel_vgpu *engine_owner[I915_NUM_ENGINES]; 480e86cc9cSChangbin Du 49e4734057SZhi Wang wait_queue_head_t workload_complete_wq; 50e4734057SZhi Wang struct task_struct *thread[I915_NUM_ENGINES]; 51e4734057SZhi Wang wait_queue_head_t waitq[I915_NUM_ENGINES]; 524b63960eSZhi Wang 534b63960eSZhi Wang void *sched_data; 544b63960eSZhi Wang struct intel_gvt_sched_policy_ops *sched_ops; 5528c4c6caSZhi Wang }; 5628c4c6caSZhi Wang 57be1da707SZhi Wang #define INDIRECT_CTX_ADDR_MASK 0xffffffc0 58be1da707SZhi Wang #define INDIRECT_CTX_SIZE_MASK 0x3f 59be1da707SZhi Wang struct shadow_indirect_ctx { 60be1da707SZhi Wang struct drm_i915_gem_object *obj; 61be1da707SZhi Wang unsigned long guest_gma; 62be1da707SZhi Wang unsigned long shadow_gma; 63be1da707SZhi Wang void *shadow_va; 64be1da707SZhi Wang uint32_t size; 65be1da707SZhi Wang }; 66be1da707SZhi Wang 67be1da707SZhi Wang #define PER_CTX_ADDR_MASK 0xfffff000 68be1da707SZhi Wang struct shadow_per_ctx { 69be1da707SZhi Wang unsigned long guest_gma; 70be1da707SZhi Wang unsigned long shadow_gma; 718f63fc2bSZhenyu Wang unsigned valid; 72be1da707SZhi Wang }; 73be1da707SZhi Wang 74be1da707SZhi Wang struct intel_shadow_wa_ctx { 75be1da707SZhi Wang struct shadow_indirect_ctx indirect_ctx; 76be1da707SZhi Wang struct shadow_per_ctx per_ctx; 77be1da707SZhi Wang 78be1da707SZhi Wang }; 79be1da707SZhi Wang 8028c4c6caSZhi Wang struct intel_vgpu_workload { 8128c4c6caSZhi Wang struct intel_vgpu *vgpu; 8228c4c6caSZhi Wang int ring_id; 8328c4c6caSZhi Wang struct drm_i915_gem_request *req; 8428c4c6caSZhi Wang /* if this workload has been dispatched to i915? */ 8528c4c6caSZhi Wang bool dispatched; 86d0302e74SPing Gao bool shadowed; 8728c4c6caSZhi Wang int status; 8828c4c6caSZhi Wang 8928c4c6caSZhi Wang struct intel_vgpu_mm *shadow_mm; 9028c4c6caSZhi Wang 9128c4c6caSZhi Wang /* different submission model may need different handler */ 9228c4c6caSZhi Wang int (*prepare)(struct intel_vgpu_workload *); 9328c4c6caSZhi Wang int (*complete)(struct intel_vgpu_workload *); 9428c4c6caSZhi Wang struct list_head list; 9528c4c6caSZhi Wang 96be1da707SZhi Wang DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX); 97be1da707SZhi Wang void *shadow_ring_buffer_va; 98be1da707SZhi Wang 9928c4c6caSZhi Wang /* execlist context information */ 10028c4c6caSZhi Wang struct execlist_ctx_descriptor_format ctx_desc; 10128c4c6caSZhi Wang struct execlist_ring_context *ring_context; 102be1da707SZhi Wang unsigned long rb_head, rb_tail, rb_ctl, rb_start, rb_len; 103e4734057SZhi Wang bool restore_inhibit; 10428c4c6caSZhi Wang struct intel_vgpu_elsp_dwords elsp_dwords; 10528c4c6caSZhi Wang bool emulate_schedule_in; 10628c4c6caSZhi Wang atomic_t shadow_ctx_active; 10728c4c6caSZhi Wang wait_queue_head_t shadow_ctx_status_wq; 10828c4c6caSZhi Wang u64 ring_context_gpa; 109be1da707SZhi Wang 110be1da707SZhi Wang /* shadow batch buffer */ 111be1da707SZhi Wang struct list_head shadow_bb; 112be1da707SZhi Wang struct intel_shadow_wa_ctx wa_ctx; 113be1da707SZhi Wang }; 114be1da707SZhi Wang 115be1da707SZhi Wang /* Intel shadow batch buffer is a i915 gem object */ 116be1da707SZhi Wang struct intel_shadow_bb_entry { 117be1da707SZhi Wang struct list_head list; 118be1da707SZhi Wang struct drm_i915_gem_object *obj; 119be1da707SZhi Wang void *va; 120be1da707SZhi Wang unsigned long len; 12162f0a11eSChris Wilson u32 *bb_start_cmd_va; 12228c4c6caSZhi Wang }; 12328c4c6caSZhi Wang 12428c4c6caSZhi Wang #define workload_q_head(vgpu, ring_id) \ 1251406a14bSZhi Wang (&(vgpu->submission.workload_q_head[ring_id])) 12628c4c6caSZhi Wang 127e4734057SZhi Wang #define queue_workload(workload) do { \ 12828c4c6caSZhi Wang list_add_tail(&workload->list, \ 129e4734057SZhi Wang workload_q_head(workload->vgpu, workload->ring_id)); \ 130e4734057SZhi Wang wake_up(&workload->vgpu->gvt-> \ 131e4734057SZhi Wang scheduler.waitq[workload->ring_id]); \ 132e4734057SZhi Wang } while (0) 133e4734057SZhi Wang 134e4734057SZhi Wang int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt); 135e4734057SZhi Wang 136e4734057SZhi Wang void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt); 137e4734057SZhi Wang 138e4734057SZhi Wang void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu); 139e4734057SZhi Wang 140874b6a91SZhi Wang int intel_vgpu_setup_submission(struct intel_vgpu *vgpu); 141e4734057SZhi Wang 142874b6a91SZhi Wang void intel_vgpu_clean_submission(struct intel_vgpu *vgpu); 14328c4c6caSZhi Wang 144*21527a8dSZhi Wang struct intel_vgpu_workload * 145*21527a8dSZhi Wang intel_vgpu_create_workload(struct intel_vgpu *vgpu); 146*21527a8dSZhi Wang 147*21527a8dSZhi Wang void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload); 148*21527a8dSZhi Wang 149a3cfdca9Sfred gao void release_shadow_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx); 15028c4c6caSZhi Wang #endif 151