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 45e4734057SZhi Wang wait_queue_head_t workload_complete_wq; 46e4734057SZhi Wang struct task_struct *thread[I915_NUM_ENGINES]; 47e4734057SZhi Wang wait_queue_head_t waitq[I915_NUM_ENGINES]; 484b63960eSZhi Wang 494b63960eSZhi Wang void *sched_data; 504b63960eSZhi Wang struct intel_gvt_sched_policy_ops *sched_ops; 5128c4c6caSZhi Wang }; 5228c4c6caSZhi Wang 53be1da707SZhi Wang #define INDIRECT_CTX_ADDR_MASK 0xffffffc0 54be1da707SZhi Wang #define INDIRECT_CTX_SIZE_MASK 0x3f 55be1da707SZhi Wang struct shadow_indirect_ctx { 56be1da707SZhi Wang struct drm_i915_gem_object *obj; 57be1da707SZhi Wang unsigned long guest_gma; 58be1da707SZhi Wang unsigned long shadow_gma; 59be1da707SZhi Wang void *shadow_va; 60be1da707SZhi Wang uint32_t size; 61be1da707SZhi Wang }; 62be1da707SZhi Wang 63be1da707SZhi Wang #define PER_CTX_ADDR_MASK 0xfffff000 64be1da707SZhi Wang struct shadow_per_ctx { 65be1da707SZhi Wang unsigned long guest_gma; 66be1da707SZhi Wang unsigned long shadow_gma; 67be1da707SZhi Wang }; 68be1da707SZhi Wang 69be1da707SZhi Wang struct intel_shadow_wa_ctx { 70be1da707SZhi Wang struct intel_vgpu_workload *workload; 71be1da707SZhi Wang struct shadow_indirect_ctx indirect_ctx; 72be1da707SZhi Wang struct shadow_per_ctx per_ctx; 73be1da707SZhi Wang 74be1da707SZhi Wang }; 75be1da707SZhi Wang 7628c4c6caSZhi Wang struct intel_vgpu_workload { 7728c4c6caSZhi Wang struct intel_vgpu *vgpu; 7828c4c6caSZhi Wang int ring_id; 7928c4c6caSZhi Wang struct drm_i915_gem_request *req; 8028c4c6caSZhi Wang /* if this workload has been dispatched to i915? */ 8128c4c6caSZhi Wang bool dispatched; 8228c4c6caSZhi Wang int status; 8328c4c6caSZhi Wang 8428c4c6caSZhi Wang struct intel_vgpu_mm *shadow_mm; 8528c4c6caSZhi Wang 8628c4c6caSZhi Wang /* different submission model may need different handler */ 8728c4c6caSZhi Wang int (*prepare)(struct intel_vgpu_workload *); 8828c4c6caSZhi Wang int (*complete)(struct intel_vgpu_workload *); 8928c4c6caSZhi Wang struct list_head list; 9028c4c6caSZhi Wang 91be1da707SZhi Wang DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX); 92be1da707SZhi Wang void *shadow_ring_buffer_va; 93be1da707SZhi Wang 9428c4c6caSZhi Wang /* execlist context information */ 9528c4c6caSZhi Wang struct execlist_ctx_descriptor_format ctx_desc; 9628c4c6caSZhi Wang struct execlist_ring_context *ring_context; 97be1da707SZhi Wang unsigned long rb_head, rb_tail, rb_ctl, rb_start, rb_len; 98e4734057SZhi Wang bool restore_inhibit; 9928c4c6caSZhi Wang struct intel_vgpu_elsp_dwords elsp_dwords; 10028c4c6caSZhi Wang bool emulate_schedule_in; 10128c4c6caSZhi Wang atomic_t shadow_ctx_active; 10228c4c6caSZhi Wang wait_queue_head_t shadow_ctx_status_wq; 10328c4c6caSZhi Wang u64 ring_context_gpa; 104be1da707SZhi Wang 105be1da707SZhi Wang /* shadow batch buffer */ 106be1da707SZhi Wang struct list_head shadow_bb; 107be1da707SZhi Wang struct intel_shadow_wa_ctx wa_ctx; 108be1da707SZhi Wang }; 109be1da707SZhi Wang 110be1da707SZhi Wang /* Intel shadow batch buffer is a i915 gem object */ 111be1da707SZhi Wang struct intel_shadow_bb_entry { 112be1da707SZhi Wang struct list_head list; 113be1da707SZhi Wang struct drm_i915_gem_object *obj; 114be1da707SZhi Wang void *va; 115be1da707SZhi Wang unsigned long len; 116*62f0a11eSChris Wilson u32 *bb_start_cmd_va; 11728c4c6caSZhi Wang }; 11828c4c6caSZhi Wang 11928c4c6caSZhi Wang #define workload_q_head(vgpu, ring_id) \ 12028c4c6caSZhi Wang (&(vgpu->workload_q_head[ring_id])) 12128c4c6caSZhi Wang 122e4734057SZhi Wang #define queue_workload(workload) do { \ 12328c4c6caSZhi Wang list_add_tail(&workload->list, \ 124e4734057SZhi Wang workload_q_head(workload->vgpu, workload->ring_id)); \ 125e4734057SZhi Wang wake_up(&workload->vgpu->gvt-> \ 126e4734057SZhi Wang scheduler.waitq[workload->ring_id]); \ 127e4734057SZhi Wang } while (0) 128e4734057SZhi Wang 129e4734057SZhi Wang int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt); 130e4734057SZhi Wang 131e4734057SZhi Wang void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt); 132e4734057SZhi Wang 133e4734057SZhi Wang void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu); 134e4734057SZhi Wang 135e4734057SZhi Wang int intel_vgpu_init_gvt_context(struct intel_vgpu *vgpu); 136e4734057SZhi Wang 137e4734057SZhi Wang void intel_vgpu_clean_gvt_context(struct intel_vgpu *vgpu); 13828c4c6caSZhi Wang 13928c4c6caSZhi Wang #endif 140