xref: /linux/drivers/gpu/drm/i915/gvt/scheduler.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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 
39e6a14b10SJani Nikula #include "gt/intel_engine_types.h"
40e6a14b10SJani Nikula 
41e6a14b10SJani Nikula #include "execlist.h"
42e6a14b10SJani Nikula #include "interrupt.h"
43e6a14b10SJani Nikula 
4428c4c6caSZhi Wang struct intel_gvt_workload_scheduler {
45e4734057SZhi Wang 	struct intel_vgpu *current_vgpu;
46e4734057SZhi Wang 	struct intel_vgpu *next_vgpu;
47e4734057SZhi Wang 	struct intel_vgpu_workload *current_workload[I915_NUM_ENGINES];
48e4734057SZhi Wang 	bool need_reschedule;
49e4734057SZhi Wang 
500e86cc9cSChangbin Du 	spinlock_t mmio_context_lock;
510e86cc9cSChangbin Du 	/* can be null when owner is host */
520e86cc9cSChangbin Du 	struct intel_vgpu *engine_owner[I915_NUM_ENGINES];
530e86cc9cSChangbin Du 
54e4734057SZhi Wang 	wait_queue_head_t workload_complete_wq;
55e4734057SZhi Wang 	struct task_struct *thread[I915_NUM_ENGINES];
56e4734057SZhi Wang 	wait_queue_head_t waitq[I915_NUM_ENGINES];
574b63960eSZhi Wang 
584b63960eSZhi Wang 	void *sched_data;
59*46420777SRikard Falkeborn 	const struct intel_gvt_sched_policy_ops *sched_ops;
6028c4c6caSZhi Wang };
6128c4c6caSZhi Wang 
62be1da707SZhi Wang #define INDIRECT_CTX_ADDR_MASK 0xffffffc0
63be1da707SZhi Wang #define INDIRECT_CTX_SIZE_MASK 0x3f
64be1da707SZhi Wang struct shadow_indirect_ctx {
65be1da707SZhi Wang 	struct drm_i915_gem_object *obj;
66be1da707SZhi Wang 	unsigned long guest_gma;
67be1da707SZhi Wang 	unsigned long shadow_gma;
68be1da707SZhi Wang 	void *shadow_va;
692e679d48SJani Nikula 	u32 size;
70be1da707SZhi Wang };
71be1da707SZhi Wang 
72be1da707SZhi Wang #define PER_CTX_ADDR_MASK 0xfffff000
73be1da707SZhi Wang struct shadow_per_ctx {
74be1da707SZhi Wang 	unsigned long guest_gma;
75be1da707SZhi Wang 	unsigned long shadow_gma;
768f63fc2bSZhenyu Wang 	unsigned valid;
77be1da707SZhi Wang };
78be1da707SZhi Wang 
79be1da707SZhi Wang struct intel_shadow_wa_ctx {
80be1da707SZhi Wang 	struct shadow_indirect_ctx indirect_ctx;
81be1da707SZhi Wang 	struct shadow_per_ctx per_ctx;
82be1da707SZhi Wang 
83be1da707SZhi Wang };
84be1da707SZhi Wang 
8528c4c6caSZhi Wang struct intel_vgpu_workload {
8628c4c6caSZhi Wang 	struct intel_vgpu *vgpu;
878fde4107SChris Wilson 	const struct intel_engine_cs *engine;
88e61e0f51SChris Wilson 	struct i915_request *req;
8928c4c6caSZhi Wang 	/* if this workload has been dispatched to i915? */
9028c4c6caSZhi Wang 	bool dispatched;
91f0e99437SZhenyu Wang 	bool shadow;      /* if workload has done shadow of guest request */
9228c4c6caSZhi Wang 	int status;
9328c4c6caSZhi Wang 
9428c4c6caSZhi Wang 	struct intel_vgpu_mm *shadow_mm;
95bec3df93SZhenyu Wang 	struct list_head lri_shadow_mm; /* For PPGTT load cmd */
9628c4c6caSZhi Wang 
9728c4c6caSZhi Wang 	/* different submission model may need different handler */
9828c4c6caSZhi Wang 	int (*prepare)(struct intel_vgpu_workload *);
9928c4c6caSZhi Wang 	int (*complete)(struct intel_vgpu_workload *);
10028c4c6caSZhi Wang 	struct list_head list;
10128c4c6caSZhi Wang 
102be1da707SZhi Wang 	DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX);
103be1da707SZhi Wang 	void *shadow_ring_buffer_va;
104be1da707SZhi Wang 
10528c4c6caSZhi Wang 	/* execlist context information */
10628c4c6caSZhi Wang 	struct execlist_ctx_descriptor_format ctx_desc;
107be1da707SZhi Wang 	unsigned long rb_head, rb_tail, rb_ctl, rb_start, rb_len;
10815e7f52aSXiaolin Zhang 	unsigned long guest_rb_head;
10928c4c6caSZhi Wang 	struct intel_vgpu_elsp_dwords elsp_dwords;
11028c4c6caSZhi Wang 	bool emulate_schedule_in;
11128c4c6caSZhi Wang 	atomic_t shadow_ctx_active;
11228c4c6caSZhi Wang 	wait_queue_head_t shadow_ctx_status_wq;
11328c4c6caSZhi Wang 	u64 ring_context_gpa;
114be1da707SZhi Wang 
115be1da707SZhi Wang 	/* shadow batch buffer */
116be1da707SZhi Wang 	struct list_head shadow_bb;
117be1da707SZhi Wang 	struct intel_shadow_wa_ctx wa_ctx;
118fa3dd623SMin He 
119fa3dd623SMin He 	/* oa registers */
120fa3dd623SMin He 	u32 oactxctrl;
121fa3dd623SMin He 	u32 flex_mmio[7];
122be1da707SZhi Wang };
123be1da707SZhi Wang 
124f52c380aSZhi Wang struct intel_vgpu_shadow_bb {
125be1da707SZhi Wang 	struct list_head list;
126be1da707SZhi Wang 	struct drm_i915_gem_object *obj;
127f52c380aSZhi Wang 	struct i915_vma *vma;
128be1da707SZhi Wang 	void *va;
12962f0a11eSChris Wilson 	u32 *bb_start_cmd_va;
130ef75c685Sfred gao 	unsigned long bb_offset;
13196bebe39SZhao Yan 	bool ppgtt;
13228c4c6caSZhi Wang };
13328c4c6caSZhi Wang 
1348fde4107SChris Wilson #define workload_q_head(vgpu, e) \
1358fde4107SChris Wilson 	(&(vgpu)->submission.workload_q_head[(e)->id])
13628c4c6caSZhi Wang 
13759a716c6SChangbin Du void intel_vgpu_queue_workload(struct intel_vgpu_workload *workload);
138e4734057SZhi Wang 
139e4734057SZhi Wang int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt);
140e4734057SZhi Wang 
141e4734057SZhi Wang void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt);
142e4734057SZhi Wang 
143e4734057SZhi Wang void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu);
144e4734057SZhi Wang 
145874b6a91SZhi Wang int intel_vgpu_setup_submission(struct intel_vgpu *vgpu);
146e4734057SZhi Wang 
14706bb372fSZhi Wang void intel_vgpu_reset_submission(struct intel_vgpu *vgpu,
1483a891a62SChris Wilson 				 intel_engine_mask_t engine_mask);
14906bb372fSZhi Wang 
150874b6a91SZhi Wang void intel_vgpu_clean_submission(struct intel_vgpu *vgpu);
15128c4c6caSZhi Wang 
152ad1d3636SZhi Wang int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
1533a891a62SChris Wilson 				     intel_engine_mask_t engine_mask,
154ad1d3636SZhi Wang 				     unsigned int interface);
155ad1d3636SZhi Wang 
156ad1d3636SZhi Wang extern const struct intel_vgpu_submission_ops
157ad1d3636SZhi Wang intel_vgpu_execlist_submission_ops;
158ad1d3636SZhi Wang 
15921527a8dSZhi Wang struct intel_vgpu_workload *
1608fde4107SChris Wilson intel_vgpu_create_workload(struct intel_vgpu *vgpu,
1618fde4107SChris Wilson 			   const struct intel_engine_cs *engine,
1626d763035SZhi Wang 			   struct execlist_ctx_descriptor_format *desc);
16321527a8dSZhi Wang 
16421527a8dSZhi Wang void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload);
16521527a8dSZhi Wang 
166f9090d4cSHang Yuan void intel_vgpu_clean_workloads(struct intel_vgpu *vgpu,
1673a891a62SChris Wilson 				intel_engine_mask_t engine_mask);
168f9090d4cSHang Yuan 
16928c4c6caSZhi Wang #endif
170