xref: /linux/drivers/gpu/drm/i915/gvt/scheduler.h (revision 96bebe39b2f4533af14c509061cd2b551ca81e8d)
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;
83e61e0f51SChris Wilson 	struct i915_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;
113fa3dd623SMin He 
114fa3dd623SMin He 	/* oa registers */
115fa3dd623SMin He 	u32 oactxctrl;
116fa3dd623SMin He 	u32 flex_mmio[7];
117be1da707SZhi Wang };
118be1da707SZhi Wang 
119f52c380aSZhi Wang struct intel_vgpu_shadow_bb {
120be1da707SZhi Wang 	struct list_head list;
121be1da707SZhi Wang 	struct drm_i915_gem_object *obj;
122f52c380aSZhi Wang 	struct i915_vma *vma;
123be1da707SZhi Wang 	void *va;
12462f0a11eSChris Wilson 	u32 *bb_start_cmd_va;
125f52c380aSZhi Wang 	unsigned int clflush;
126f52c380aSZhi Wang 	bool accessing;
127ef75c685Sfred gao 	unsigned long bb_offset;
128*96bebe39SZhao Yan 	bool ppgtt;
12928c4c6caSZhi Wang };
13028c4c6caSZhi Wang 
13128c4c6caSZhi Wang #define workload_q_head(vgpu, ring_id) \
1321406a14bSZhi Wang 	(&(vgpu->submission.workload_q_head[ring_id]))
13328c4c6caSZhi Wang 
13459a716c6SChangbin Du void intel_vgpu_queue_workload(struct intel_vgpu_workload *workload);
135e4734057SZhi Wang 
136e4734057SZhi Wang int intel_gvt_init_workload_scheduler(struct intel_gvt *gvt);
137e4734057SZhi Wang 
138e4734057SZhi Wang void intel_gvt_clean_workload_scheduler(struct intel_gvt *gvt);
139e4734057SZhi Wang 
140e4734057SZhi Wang void intel_gvt_wait_vgpu_idle(struct intel_vgpu *vgpu);
141e4734057SZhi Wang 
142874b6a91SZhi Wang int intel_vgpu_setup_submission(struct intel_vgpu *vgpu);
143e4734057SZhi Wang 
14406bb372fSZhi Wang void intel_vgpu_reset_submission(struct intel_vgpu *vgpu,
14506bb372fSZhi Wang 				 unsigned long engine_mask);
14606bb372fSZhi Wang 
147874b6a91SZhi Wang void intel_vgpu_clean_submission(struct intel_vgpu *vgpu);
14828c4c6caSZhi Wang 
149ad1d3636SZhi Wang int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
1507569a06dSWeinan Li 				     unsigned long engine_mask,
151ad1d3636SZhi Wang 				     unsigned int interface);
152ad1d3636SZhi Wang 
153ad1d3636SZhi Wang extern const struct intel_vgpu_submission_ops
154ad1d3636SZhi Wang intel_vgpu_execlist_submission_ops;
155ad1d3636SZhi Wang 
15621527a8dSZhi Wang struct intel_vgpu_workload *
1576d763035SZhi Wang intel_vgpu_create_workload(struct intel_vgpu *vgpu, int ring_id,
1586d763035SZhi Wang 			   struct execlist_ctx_descriptor_format *desc);
15921527a8dSZhi Wang 
16021527a8dSZhi Wang void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload);
16121527a8dSZhi Wang 
16228c4c6caSZhi Wang #endif
163