18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 208c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 218c2ecf20Sopenharmony_ci * SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Authors: 248c2ecf20Sopenharmony_ci * Zhi Wang <zhi.a.wang@intel.com> 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * Contributors: 278c2ecf20Sopenharmony_ci * Ping Gao <ping.a.gao@intel.com> 288c2ecf20Sopenharmony_ci * Tina Zhang <tina.zhang@intel.com> 298c2ecf20Sopenharmony_ci * Chanbin Du <changbin.du@intel.com> 308c2ecf20Sopenharmony_ci * Min He <min.he@intel.com> 318c2ecf20Sopenharmony_ci * Bing Niu <bing.niu@intel.com> 328c2ecf20Sopenharmony_ci * Zhenyu Wang <zhenyuw@linux.intel.com> 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#ifndef _GVT_SCHEDULER_H_ 378c2ecf20Sopenharmony_ci#define _GVT_SCHEDULER_H_ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct intel_gvt_workload_scheduler { 408c2ecf20Sopenharmony_ci struct intel_vgpu *current_vgpu; 418c2ecf20Sopenharmony_ci struct intel_vgpu *next_vgpu; 428c2ecf20Sopenharmony_ci struct intel_vgpu_workload *current_workload[I915_NUM_ENGINES]; 438c2ecf20Sopenharmony_ci bool need_reschedule; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci spinlock_t mmio_context_lock; 468c2ecf20Sopenharmony_ci /* can be null when owner is host */ 478c2ecf20Sopenharmony_ci struct intel_vgpu *engine_owner[I915_NUM_ENGINES]; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci wait_queue_head_t workload_complete_wq; 508c2ecf20Sopenharmony_ci struct task_struct *thread[I915_NUM_ENGINES]; 518c2ecf20Sopenharmony_ci wait_queue_head_t waitq[I915_NUM_ENGINES]; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci void *sched_data; 548c2ecf20Sopenharmony_ci struct intel_gvt_sched_policy_ops *sched_ops; 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define INDIRECT_CTX_ADDR_MASK 0xffffffc0 588c2ecf20Sopenharmony_ci#define INDIRECT_CTX_SIZE_MASK 0x3f 598c2ecf20Sopenharmony_cistruct shadow_indirect_ctx { 608c2ecf20Sopenharmony_ci struct drm_i915_gem_object *obj; 618c2ecf20Sopenharmony_ci unsigned long guest_gma; 628c2ecf20Sopenharmony_ci unsigned long shadow_gma; 638c2ecf20Sopenharmony_ci void *shadow_va; 648c2ecf20Sopenharmony_ci u32 size; 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define PER_CTX_ADDR_MASK 0xfffff000 688c2ecf20Sopenharmony_cistruct shadow_per_ctx { 698c2ecf20Sopenharmony_ci unsigned long guest_gma; 708c2ecf20Sopenharmony_ci unsigned long shadow_gma; 718c2ecf20Sopenharmony_ci unsigned valid; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct intel_shadow_wa_ctx { 758c2ecf20Sopenharmony_ci struct shadow_indirect_ctx indirect_ctx; 768c2ecf20Sopenharmony_ci struct shadow_per_ctx per_ctx; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistruct intel_vgpu_workload { 818c2ecf20Sopenharmony_ci struct intel_vgpu *vgpu; 828c2ecf20Sopenharmony_ci const struct intel_engine_cs *engine; 838c2ecf20Sopenharmony_ci struct i915_request *req; 848c2ecf20Sopenharmony_ci /* if this workload has been dispatched to i915? */ 858c2ecf20Sopenharmony_ci bool dispatched; 868c2ecf20Sopenharmony_ci bool shadow; /* if workload has done shadow of guest request */ 878c2ecf20Sopenharmony_ci int status; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci struct intel_vgpu_mm *shadow_mm; 908c2ecf20Sopenharmony_ci struct list_head lri_shadow_mm; /* For PPGTT load cmd */ 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci /* different submission model may need different handler */ 938c2ecf20Sopenharmony_ci int (*prepare)(struct intel_vgpu_workload *); 948c2ecf20Sopenharmony_ci int (*complete)(struct intel_vgpu_workload *); 958c2ecf20Sopenharmony_ci struct list_head list; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX); 988c2ecf20Sopenharmony_ci void *shadow_ring_buffer_va; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci /* execlist context information */ 1018c2ecf20Sopenharmony_ci struct execlist_ctx_descriptor_format ctx_desc; 1028c2ecf20Sopenharmony_ci struct execlist_ring_context *ring_context; 1038c2ecf20Sopenharmony_ci unsigned long rb_head, rb_tail, rb_ctl, rb_start, rb_len; 1048c2ecf20Sopenharmony_ci unsigned long guest_rb_head; 1058c2ecf20Sopenharmony_ci bool restore_inhibit; 1068c2ecf20Sopenharmony_ci struct intel_vgpu_elsp_dwords elsp_dwords; 1078c2ecf20Sopenharmony_ci bool emulate_schedule_in; 1088c2ecf20Sopenharmony_ci atomic_t shadow_ctx_active; 1098c2ecf20Sopenharmony_ci wait_queue_head_t shadow_ctx_status_wq; 1108c2ecf20Sopenharmony_ci u64 ring_context_gpa; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci /* shadow batch buffer */ 1138c2ecf20Sopenharmony_ci struct list_head shadow_bb; 1148c2ecf20Sopenharmony_ci struct intel_shadow_wa_ctx wa_ctx; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci /* oa registers */ 1178c2ecf20Sopenharmony_ci u32 oactxctrl; 1188c2ecf20Sopenharmony_ci u32 flex_mmio[7]; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistruct intel_vgpu_shadow_bb { 1228c2ecf20Sopenharmony_ci struct list_head list; 1238c2ecf20Sopenharmony_ci struct drm_i915_gem_object *obj; 1248c2ecf20Sopenharmony_ci struct i915_vma *vma; 1258c2ecf20Sopenharmony_ci void *va; 1268c2ecf20Sopenharmony_ci u32 *bb_start_cmd_va; 1278c2ecf20Sopenharmony_ci unsigned long bb_offset; 1288c2ecf20Sopenharmony_ci bool ppgtt; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define workload_q_head(vgpu, e) \ 1328c2ecf20Sopenharmony_ci (&(vgpu)->submission.workload_q_head[(e)->id]) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_civoid intel_vgpu_queue_workload(struct intel_vgpu_workload *workload); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciint intel_gvt_init_workload_scheduler(struct intel_gvt *gvt); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_civoid intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_civoid intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ciint intel_vgpu_setup_submission(struct intel_vgpu *vgpu); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_civoid intel_vgpu_reset_submission(struct intel_vgpu *vgpu, 1458c2ecf20Sopenharmony_ci intel_engine_mask_t engine_mask); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_civoid intel_vgpu_clean_submission(struct intel_vgpu *vgpu); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ciint intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu, 1508c2ecf20Sopenharmony_ci intel_engine_mask_t engine_mask, 1518c2ecf20Sopenharmony_ci unsigned int interface); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ciextern const struct intel_vgpu_submission_ops 1548c2ecf20Sopenharmony_ciintel_vgpu_execlist_submission_ops; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistruct intel_vgpu_workload * 1578c2ecf20Sopenharmony_ciintel_vgpu_create_workload(struct intel_vgpu *vgpu, 1588c2ecf20Sopenharmony_ci const struct intel_engine_cs *engine, 1598c2ecf20Sopenharmony_ci struct execlist_ctx_descriptor_format *desc); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_civoid intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_civoid intel_vgpu_clean_workloads(struct intel_vgpu *vgpu, 1648c2ecf20Sopenharmony_ci intel_engine_mask_t engine_mask); 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#endif 167