xref: /linux/drivers/gpu/drm/i915/gvt/scheduler.h (revision 8fde41076f6df53db84cb13051efed6482986ce3)
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;
642e679d48SJani Nikula 	u32 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;
82*8fde4107SChris Wilson 	const struct intel_engine_cs *engine;
83e61e0f51SChris Wilson 	struct i915_request *req;
8428c4c6caSZhi Wang 	/* if this workload has been dispatched to i915? */
8528c4c6caSZhi Wang 	bool dispatched;
86f0e99437SZhenyu Wang 	bool shadow;      /* if workload has done shadow of guest request */
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;
10315e7f52aSXiaolin Zhang 	unsigned long guest_rb_head;
104e4734057SZhi Wang 	bool restore_inhibit;
10528c4c6caSZhi Wang 	struct intel_vgpu_elsp_dwords elsp_dwords;
10628c4c6caSZhi Wang 	bool emulate_schedule_in;
10728c4c6caSZhi Wang 	atomic_t shadow_ctx_active;
10828c4c6caSZhi Wang 	wait_queue_head_t shadow_ctx_status_wq;
10928c4c6caSZhi Wang 	u64 ring_context_gpa;
110be1da707SZhi Wang 
111be1da707SZhi Wang 	/* shadow batch buffer */
112be1da707SZhi Wang 	struct list_head shadow_bb;
113be1da707SZhi Wang 	struct intel_shadow_wa_ctx wa_ctx;
114fa3dd623SMin He 
115fa3dd623SMin He 	/* oa registers */
116fa3dd623SMin He 	u32 oactxctrl;
117fa3dd623SMin He 	u32 flex_mmio[7];
118be1da707SZhi Wang };
119be1da707SZhi Wang 
120f52c380aSZhi Wang struct intel_vgpu_shadow_bb {
121be1da707SZhi Wang 	struct list_head list;
122be1da707SZhi Wang 	struct drm_i915_gem_object *obj;
123f52c380aSZhi Wang 	struct i915_vma *vma;
124be1da707SZhi Wang 	void *va;
12562f0a11eSChris Wilson 	u32 *bb_start_cmd_va;
126f52c380aSZhi Wang 	unsigned int clflush;
127f52c380aSZhi Wang 	bool accessing;
128ef75c685Sfred gao 	unsigned long bb_offset;
12996bebe39SZhao Yan 	bool ppgtt;
13028c4c6caSZhi Wang };
13128c4c6caSZhi Wang 
132*8fde4107SChris Wilson #define workload_q_head(vgpu, e) \
133*8fde4107SChris Wilson 	(&(vgpu)->submission.workload_q_head[(e)->id])
13428c4c6caSZhi Wang 
13559a716c6SChangbin Du void intel_vgpu_queue_workload(struct intel_vgpu_workload *workload);
136e4734057SZhi Wang 
137e4734057SZhi Wang int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt);
138e4734057SZhi Wang 
139e4734057SZhi Wang void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt);
140e4734057SZhi Wang 
141e4734057SZhi Wang void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu);
142e4734057SZhi Wang 
143874b6a91SZhi Wang int intel_vgpu_setup_submission(struct intel_vgpu *vgpu);
144e4734057SZhi Wang 
14506bb372fSZhi Wang void intel_vgpu_reset_submission(struct intel_vgpu *vgpu,
1463a891a62SChris Wilson 				 intel_engine_mask_t engine_mask);
14706bb372fSZhi Wang 
148874b6a91SZhi Wang void intel_vgpu_clean_submission(struct intel_vgpu *vgpu);
14928c4c6caSZhi Wang 
150ad1d3636SZhi Wang int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
1513a891a62SChris Wilson 				     intel_engine_mask_t engine_mask,
152ad1d3636SZhi Wang 				     unsigned int interface);
153ad1d3636SZhi Wang 
154ad1d3636SZhi Wang extern const struct intel_vgpu_submission_ops
155ad1d3636SZhi Wang intel_vgpu_execlist_submission_ops;
156ad1d3636SZhi Wang 
15721527a8dSZhi Wang struct intel_vgpu_workload *
158*8fde4107SChris Wilson intel_vgpu_create_workload(struct intel_vgpu *vgpu,
159*8fde4107SChris Wilson 			   const struct intel_engine_cs *engine,
1606d763035SZhi Wang 			   struct execlist_ctx_descriptor_format *desc);
16121527a8dSZhi Wang 
16221527a8dSZhi Wang void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload);
16321527a8dSZhi Wang 
164f9090d4cSHang Yuan void intel_vgpu_clean_workloads(struct intel_vgpu *vgpu,
1653a891a62SChris Wilson 				intel_engine_mask_t engine_mask);
166f9090d4cSHang Yuan 
16728c4c6caSZhi Wang #endif
168