1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #ifndef _XE_EXEC_QUEUE_TYPES_H_ 7 #define _XE_EXEC_QUEUE_TYPES_H_ 8 9 #include <linux/kref.h> 10 11 #include <drm/gpu_scheduler.h> 12 13 #include "xe_gpu_scheduler_types.h" 14 #include "xe_hw_engine_types.h" 15 #include "xe_hw_fence_types.h" 16 #include "xe_lrc_types.h" 17 18 struct drm_syncobj; 19 struct xe_execlist_exec_queue; 20 struct xe_gt; 21 struct xe_guc_exec_queue; 22 struct xe_hw_engine; 23 struct xe_vm; 24 25 enum xe_exec_queue_priority { 26 XE_EXEC_QUEUE_PRIORITY_UNSET = -2, /* For execlist usage only */ 27 XE_EXEC_QUEUE_PRIORITY_LOW = 0, 28 XE_EXEC_QUEUE_PRIORITY_NORMAL, 29 XE_EXEC_QUEUE_PRIORITY_HIGH, 30 XE_EXEC_QUEUE_PRIORITY_KERNEL, 31 32 XE_EXEC_QUEUE_PRIORITY_COUNT 33 }; 34 35 /** 36 * enum xe_multi_queue_priority - Multi Queue priority values 37 * 38 * The priority values of the queues within the multi queue group. 39 */ 40 enum xe_multi_queue_priority { 41 /** @XE_MULTI_QUEUE_PRIORITY_LOW: Priority low */ 42 XE_MULTI_QUEUE_PRIORITY_LOW = 0, 43 /** @XE_MULTI_QUEUE_PRIORITY_NORMAL: Priority normal */ 44 XE_MULTI_QUEUE_PRIORITY_NORMAL, 45 /** @XE_MULTI_QUEUE_PRIORITY_HIGH: Priority high */ 46 XE_MULTI_QUEUE_PRIORITY_HIGH, 47 }; 48 49 /** 50 * struct xe_exec_queue_group - Execution multi queue group 51 * 52 * Contains multi queue group information. 53 */ 54 struct xe_exec_queue_group { 55 /** @primary: Primary queue of this group */ 56 struct xe_exec_queue *primary; 57 /** @cgp_bo: BO for the Context Group Page */ 58 struct xe_bo *cgp_bo; 59 /** @xa: xarray to store LRCs */ 60 struct xarray xa; 61 /** @list: List of all secondary queues in the group */ 62 struct list_head list; 63 /** @list_lock: Secondary queue list lock */ 64 struct mutex list_lock; 65 /** @sync_pending: CGP_SYNC_DONE g2h response pending */ 66 bool sync_pending; 67 /** @banned: Group banned */ 68 bool banned; 69 }; 70 71 /** 72 * struct xe_exec_queue - Execution queue 73 * 74 * Contains all state necessary for submissions. Can either be a user object or 75 * a kernel object. 76 */ 77 struct xe_exec_queue { 78 /** @xef: Back pointer to xe file if this is user created exec queue */ 79 struct xe_file *xef; 80 81 /** @gt: GT structure this exec queue can submit to */ 82 struct xe_gt *gt; 83 /** 84 * @hwe: A hardware of the same class. May (physical engine) or may not 85 * (virtual engine) be where jobs actual engine up running. Should never 86 * really be used for submissions. 87 */ 88 struct xe_hw_engine *hwe; 89 /** @refcount: ref count of this exec queue */ 90 struct kref refcount; 91 /** @vm: VM (address space) for this exec queue */ 92 struct xe_vm *vm; 93 /** 94 * @user_vm: User VM (address space) for this exec queue (bind queues 95 * only) 96 */ 97 struct xe_vm *user_vm; 98 99 /** @class: class of this exec queue */ 100 enum xe_engine_class class; 101 /** 102 * @logical_mask: logical mask of where job submitted to exec queue can run 103 */ 104 u32 logical_mask; 105 /** @name: name of this exec queue */ 106 char name[MAX_FENCE_NAME_LEN]; 107 /** @width: width (number BB submitted per exec) of this exec queue */ 108 u16 width; 109 /** @msix_vec: MSI-X vector (for platforms that support it) */ 110 u16 msix_vec; 111 /** @fence_irq: fence IRQ used to signal job completion */ 112 struct xe_hw_fence_irq *fence_irq; 113 114 /** 115 * @last_fence: last fence on exec queue, protected by vm->lock in write 116 * mode if bind exec queue, protected by dma resv lock if non-bind exec 117 * queue 118 */ 119 struct dma_fence *last_fence; 120 121 /* queue used for kernel submission only */ 122 #define EXEC_QUEUE_FLAG_KERNEL BIT(0) 123 /* kernel engine only destroyed at driver unload */ 124 #define EXEC_QUEUE_FLAG_PERMANENT BIT(1) 125 /* for VM jobs. Caller needs to hold rpm ref when creating queue with this flag */ 126 #define EXEC_QUEUE_FLAG_VM BIT(2) 127 /* child of VM queue for multi-tile VM jobs */ 128 #define EXEC_QUEUE_FLAG_BIND_ENGINE_CHILD BIT(3) 129 /* kernel exec_queue only, set priority to highest level */ 130 #define EXEC_QUEUE_FLAG_HIGH_PRIORITY BIT(4) 131 /* flag to indicate low latency hint to guc */ 132 #define EXEC_QUEUE_FLAG_LOW_LATENCY BIT(5) 133 /* for migration (kernel copy, clear, bind) jobs */ 134 #define EXEC_QUEUE_FLAG_MIGRATE BIT(6) 135 136 /** 137 * @flags: flags for this exec queue, should statically setup aside from ban 138 * bit 139 */ 140 unsigned long flags; 141 142 union { 143 /** @multi_gt_list: list head for VM bind engines if multi-GT */ 144 struct list_head multi_gt_list; 145 /** @multi_gt_link: link for VM bind engines if multi-GT */ 146 struct list_head multi_gt_link; 147 }; 148 149 union { 150 /** @execlist: execlist backend specific state for exec queue */ 151 struct xe_execlist_exec_queue *execlist; 152 /** @guc: GuC backend specific state for exec queue */ 153 struct xe_guc_exec_queue *guc; 154 }; 155 156 /** @multi_queue: Multi queue information */ 157 struct { 158 /** @multi_queue.group: Queue group information */ 159 struct xe_exec_queue_group *group; 160 /** @multi_queue.link: Link into group's secondary queues list */ 161 struct list_head link; 162 /** @multi_queue.priority: Queue priority within the multi-queue group */ 163 enum xe_multi_queue_priority priority; 164 /** @multi_queue.pos: Position of queue within the multi-queue group */ 165 u8 pos; 166 /** @multi_queue.valid: Queue belongs to a multi queue group */ 167 u8 valid:1; 168 /** @multi_queue.is_primary: Is primary queue (Q0) of the group */ 169 u8 is_primary:1; 170 } multi_queue; 171 172 /** @sched_props: scheduling properties */ 173 struct { 174 /** @sched_props.timeslice_us: timeslice period in micro-seconds */ 175 u32 timeslice_us; 176 /** @sched_props.preempt_timeout_us: preemption timeout in micro-seconds */ 177 u32 preempt_timeout_us; 178 /** @sched_props.job_timeout_ms: job timeout in milliseconds */ 179 u32 job_timeout_ms; 180 /** @sched_props.priority: priority of this exec queue */ 181 enum xe_exec_queue_priority priority; 182 } sched_props; 183 184 /** @lr: long-running exec queue state */ 185 struct { 186 /** @lr.pfence: preemption fence */ 187 struct dma_fence *pfence; 188 /** @lr.context: preemption fence context */ 189 u64 context; 190 /** @lr.seqno: preemption fence seqno */ 191 u32 seqno; 192 /** @lr.link: link into VM's list of exec queues */ 193 struct list_head link; 194 } lr; 195 196 #define XE_EXEC_QUEUE_TLB_INVAL_PRIMARY_GT 0 197 #define XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT 1 198 #define XE_EXEC_QUEUE_TLB_INVAL_COUNT (XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT + 1) 199 200 /** @tlb_inval: TLB invalidations exec queue state */ 201 struct { 202 /** 203 * @tlb_inval.dep_scheduler: The TLB invalidation 204 * dependency scheduler 205 */ 206 struct xe_dep_scheduler *dep_scheduler; 207 /** 208 * @last_fence: last fence for tlb invalidation, protected by 209 * vm->lock in write mode 210 */ 211 struct dma_fence *last_fence; 212 } tlb_inval[XE_EXEC_QUEUE_TLB_INVAL_COUNT]; 213 214 /** @pxp: PXP info tracking */ 215 struct { 216 /** @pxp.type: PXP session type used by this queue */ 217 u8 type; 218 /** @pxp.link: link into the list of PXP exec queues */ 219 struct list_head link; 220 } pxp; 221 222 /** @ufence_syncobj: User fence syncobj */ 223 struct drm_syncobj *ufence_syncobj; 224 225 /** @ufence_timeline_value: User fence timeline value */ 226 u64 ufence_timeline_value; 227 228 /** @replay_state: GPU hang replay state */ 229 void *replay_state; 230 231 /** @ops: submission backend exec queue operations */ 232 const struct xe_exec_queue_ops *ops; 233 234 /** @ring_ops: ring operations for this exec queue */ 235 const struct xe_ring_ops *ring_ops; 236 /** @entity: DRM sched entity for this exec queue (1 to 1 relationship) */ 237 struct drm_sched_entity *entity; 238 239 #define XE_MAX_JOB_COUNT_PER_EXEC_QUEUE 1000 240 /** @job_cnt: number of drm jobs in this exec queue */ 241 atomic_t job_cnt; 242 243 /** 244 * @tlb_flush_seqno: The seqno of the last rebind tlb flush performed 245 * Protected by @vm's resv. Unused if @vm == NULL. 246 */ 247 u64 tlb_flush_seqno; 248 /** @hw_engine_group_link: link into exec queues in the same hw engine group */ 249 struct list_head hw_engine_group_link; 250 /** @lrc: logical ring context for this exec queue */ 251 struct xe_lrc *lrc[] __counted_by(width); 252 }; 253 254 /** 255 * struct xe_exec_queue_ops - Submission backend exec queue operations 256 */ 257 struct xe_exec_queue_ops { 258 /** @init: Initialize exec queue for submission backend */ 259 int (*init)(struct xe_exec_queue *q); 260 /** @kill: Kill inflight submissions for backend */ 261 void (*kill)(struct xe_exec_queue *q); 262 /** @fini: Undoes the init() for submission backend */ 263 void (*fini)(struct xe_exec_queue *q); 264 /** 265 * @destroy: Destroy exec queue for submission backend. The backend 266 * function must call xe_exec_queue_fini() (which will in turn call the 267 * fini() backend function) to ensure the queue is properly cleaned up. 268 */ 269 void (*destroy)(struct xe_exec_queue *q); 270 /** @set_priority: Set priority for exec queue */ 271 int (*set_priority)(struct xe_exec_queue *q, 272 enum xe_exec_queue_priority priority); 273 /** @set_timeslice: Set timeslice for exec queue */ 274 int (*set_timeslice)(struct xe_exec_queue *q, u32 timeslice_us); 275 /** @set_preempt_timeout: Set preemption timeout for exec queue */ 276 int (*set_preempt_timeout)(struct xe_exec_queue *q, u32 preempt_timeout_us); 277 /** @set_multi_queue_priority: Set multi queue priority */ 278 int (*set_multi_queue_priority)(struct xe_exec_queue *q, 279 enum xe_multi_queue_priority priority); 280 /** 281 * @suspend: Suspend exec queue from executing, allowed to be called 282 * multiple times in a row before resume with the caveat that 283 * suspend_wait returns before calling suspend again. 284 */ 285 int (*suspend)(struct xe_exec_queue *q); 286 /** 287 * @suspend_wait: Wait for an exec queue to suspend executing, should be 288 * call after suspend. In dma-fencing path thus must return within a 289 * reasonable amount of time. -ETIME return shall indicate an error 290 * waiting for suspend resulting in associated VM getting killed. 291 * -EAGAIN return indicates the wait should be tried again, if the wait 292 * is within a work item, the work item should be requeued as deadlock 293 * avoidance mechanism. 294 */ 295 int (*suspend_wait)(struct xe_exec_queue *q); 296 /** 297 * @resume: Resume exec queue execution, exec queue must be in a suspended 298 * state and dma fence returned from most recent suspend call must be 299 * signalled when this function is called. 300 */ 301 void (*resume)(struct xe_exec_queue *q); 302 /** @reset_status: check exec queue reset status */ 303 bool (*reset_status)(struct xe_exec_queue *q); 304 }; 305 306 #endif 307