1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Copyright © 2021 Intel Corporation
4 */
5 #ifndef _XE_LRC_H_
6 #define _XE_LRC_H_
7
8 #include <linux/types.h>
9
10 #include "xe_lrc_types.h"
11
12 struct drm_printer;
13 struct xe_bb;
14 struct xe_device;
15 struct xe_exec_queue;
16 enum xe_multi_queue_priority;
17 enum xe_engine_class;
18 struct xe_gt;
19 struct xe_hw_engine;
20 struct xe_lrc;
21 struct xe_vm;
22
23 struct xe_lrc_snapshot {
24 struct xe_bo *lrc_bo;
25 void *lrc_snapshot;
26 unsigned long lrc_size, lrc_offset;
27 unsigned long replay_size, replay_offset;
28
29 u32 context_desc;
30 u32 ring_addr;
31 u32 indirect_context_desc;
32 u32 head;
33 u32 start;
34 struct {
35 u32 internal;
36 u32 memory;
37 } tail;
38 u32 start_seqno;
39 u32 seqno;
40 u32 ctx_timestamp;
41 u32 ctx_job_timestamp;
42 };
43
44 #define LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR (0x34 * 4)
45 #define LRC_PPHWSP_PXP_INVAL_SCRATCH_ADDR (0x40 * 4)
46
47 #define LRC_WA_BB_SIZE SZ_4K
48
49 #define XE_LRC_CREATE_RUNALONE BIT(0)
50 #define XE_LRC_CREATE_PXP BIT(1)
51 #define XE_LRC_CREATE_USER_CTX BIT(2)
52
53 struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
54 void *replay_state, u32 ring_size, u16 msix_vec, u32 flags);
55 void xe_lrc_destroy(struct kref *ref);
56
57 /**
58 * xe_lrc_get - Get reference to the LRC
59 * @lrc: Logical Ring Context
60 *
61 * Increment reference count of @lrc
62 */
xe_lrc_get(struct xe_lrc * lrc)63 static inline struct xe_lrc *xe_lrc_get(struct xe_lrc *lrc)
64 {
65 kref_get(&lrc->refcount);
66 return lrc;
67 }
68
69 /**
70 * xe_lrc_put - Put reference of the LRC
71 * @lrc: Logical Ring Context
72 *
73 * Decrement reference count of @lrc, call xe_lrc_destroy when
74 * reference count reaches 0.
75 */
xe_lrc_put(struct xe_lrc * lrc)76 static inline void xe_lrc_put(struct xe_lrc *lrc)
77 {
78 if (lrc)
79 kref_put(&lrc->refcount, xe_lrc_destroy);
80 }
81
82 /**
83 * xe_lrc_ring_size() - Xe LRC ring size
84 *
85 * Return: Size of LRC ring buffer
86 */
xe_lrc_ring_size(void)87 static inline size_t xe_lrc_ring_size(void)
88 {
89 return SZ_16K;
90 }
91
92 size_t xe_gt_lrc_hang_replay_size(struct xe_gt *gt, enum xe_engine_class class);
93 size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class);
94 u32 xe_lrc_pphwsp_offset(struct xe_lrc *lrc);
95 u32 xe_lrc_regs_offset(struct xe_lrc *lrc);
96
97 void xe_lrc_set_ring_tail(struct xe_lrc *lrc, u32 tail);
98 u32 xe_lrc_ring_tail(struct xe_lrc *lrc);
99 void xe_lrc_set_ring_head(struct xe_lrc *lrc, u32 head);
100 u32 xe_lrc_ring_head(struct xe_lrc *lrc);
101 u32 xe_lrc_ring_space(struct xe_lrc *lrc);
102 void xe_lrc_write_ring(struct xe_lrc *lrc, const void *data, size_t size);
103
104 bool xe_lrc_ring_is_idle(struct xe_lrc *lrc);
105
106 u32 xe_lrc_indirect_ring_ggtt_addr(struct xe_lrc *lrc);
107 u32 xe_lrc_ggtt_addr(struct xe_lrc *lrc);
108 u32 *xe_lrc_regs(struct xe_lrc *lrc);
109 void xe_lrc_update_hwctx_regs_with_address(struct xe_lrc *lrc);
110 void xe_default_lrc_update_memirq_regs_with_address(struct xe_hw_engine *hwe);
111 void xe_lrc_update_memirq_regs_with_address(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
112 u32 *regs);
113
114 u32 xe_lrc_read_ctx_reg(struct xe_lrc *lrc, int reg_nr);
115 void xe_lrc_write_ctx_reg(struct xe_lrc *lrc, int reg_nr, u32 val);
116
117 u64 xe_lrc_descriptor(struct xe_lrc *lrc);
118
119 u32 xe_lrc_seqno_ggtt_addr(struct xe_lrc *lrc);
120 struct dma_fence *xe_lrc_alloc_seqno_fence(void);
121 void xe_lrc_free_seqno_fence(struct dma_fence *fence);
122 void xe_lrc_init_seqno_fence(struct xe_lrc *lrc, struct dma_fence *fence);
123 s32 xe_lrc_seqno(struct xe_lrc *lrc);
124
125 u32 xe_lrc_start_seqno_ggtt_addr(struct xe_lrc *lrc);
126 s32 xe_lrc_start_seqno(struct xe_lrc *lrc);
127
128 u32 xe_lrc_parallel_ggtt_addr(struct xe_lrc *lrc);
129 struct iosys_map xe_lrc_parallel_map(struct xe_lrc *lrc);
130
131 size_t xe_lrc_reg_size(struct xe_device *xe);
132 size_t xe_lrc_skip_size(struct xe_device *xe);
133
134 void xe_lrc_dump_default(struct drm_printer *p,
135 struct xe_gt *gt,
136 enum xe_engine_class);
137
138 u32 *xe_lrc_emit_hwe_state_instructions(struct xe_exec_queue *q, u32 *cs);
139
140 void xe_lrc_set_multi_queue_priority(struct xe_lrc *lrc, enum xe_multi_queue_priority priority);
141
142 struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc);
143 void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot);
144 void xe_lrc_snapshot_print(struct xe_lrc_snapshot *snapshot, struct drm_printer *p);
145 void xe_lrc_snapshot_free(struct xe_lrc_snapshot *snapshot);
146
147 u32 xe_lrc_ctx_timestamp_ggtt_addr(struct xe_lrc *lrc);
148 u32 xe_lrc_ctx_timestamp_udw_ggtt_addr(struct xe_lrc *lrc);
149 u32 xe_lrc_ctx_job_timestamp_ggtt_addr(struct xe_lrc *lrc);
150 u32 xe_lrc_ctx_job_timestamp(struct xe_lrc *lrc);
151 int xe_lrc_setup_wa_bb_with_scratch(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
152 u32 *scratch);
153
154 /**
155 * xe_lrc_update_timestamp - readout LRC timestamp and update cached value
156 * @lrc: logical ring context for this exec queue
157 * @old_ts: pointer where to save the previous timestamp
158 *
159 * Read the current timestamp for this LRC and update the cached value. The
160 * previous cached value is also returned in @old_ts so the caller can calculate
161 * the delta between 2 updates. Note that this is not intended to be called from
162 * any place, but just by the paths updating the drm client utilization.
163 *
164 * Returns the current LRC timestamp
165 */
166 u64 xe_lrc_update_timestamp(struct xe_lrc *lrc, u64 *old_ts);
167
168 u64 xe_lrc_timestamp(struct xe_lrc *lrc);
169
170 #endif
171