Skip to content

Commit fba1230

Browse files
Tvrtko Ursulinlucasdemarchi
authored andcommitted
drm/xe: Add plumbing for indirect context workarounds
Some upcoming workarounds need to be emitted from the indirect workaround context so lets add some plumbing where they will be able to easily slot in. No functional changes for now since everything is still deactivated. Signed-off-by: Tvrtko Ursulin <[email protected]> Bspec: 45954 Cc: Lucas De Marchi <[email protected]> Cc: Matt Roper <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent a3397b2 commit fba1230

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

drivers/gpu/drm/xe/regs/xe_lrc_layout.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define CTX_RING_START (0x08 + 1)
1313
#define CTX_RING_CTL (0x0a + 1)
1414
#define CTX_BB_PER_CTX_PTR (0x12 + 1)
15+
#define CTX_CS_INDIRECT_CTX (0x14 + 1)
16+
#define CTX_CS_INDIRECT_CTX_OFFSET (0x16 + 1)
1517
#define CTX_TIMESTAMP (0x22 + 1)
1618
#define CTX_TIMESTAMP_UDW (0x24 + 1)
1719
#define CTX_INDIRECT_RING_STATE (0x26 + 1)
@@ -36,4 +38,7 @@
3638
#define INDIRECT_CTX_RING_START_UDW (0x08 + 1)
3739
#define INDIRECT_CTX_RING_CTL (0x0a + 1)
3840

41+
#define CTX_INDIRECT_CTX_OFFSET_MASK REG_GENMASK(15, 6)
42+
#define CTX_INDIRECT_CTX_OFFSET_DEFAULT REG_FIELD_PREP(CTX_INDIRECT_CTX_OFFSET_MASK, 0xd)
43+
3944
#endif

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define LRC_ENGINE_INSTANCE GENMASK_ULL(53, 48)
4040

4141
#define LRC_PPHWSP_SIZE SZ_4K
42+
#define LRC_INDIRECT_CTX_BO_SIZE SZ_4K
4243
#define LRC_INDIRECT_RING_STATE_SIZE SZ_4K
4344
#define LRC_WA_BB_SIZE SZ_4K
4445

@@ -48,6 +49,12 @@ lrc_to_xe(struct xe_lrc *lrc)
4849
return gt_to_xe(lrc->fence_ctx.gt);
4950
}
5051

52+
static bool
53+
gt_engine_needs_indirect_ctx(struct xe_gt *gt, enum xe_engine_class class)
54+
{
55+
return false;
56+
}
57+
5158
size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class)
5259
{
5360
struct xe_device *xe = gt_to_xe(gt);
@@ -717,7 +724,18 @@ static u32 __xe_lrc_ctx_timestamp_udw_offset(struct xe_lrc *lrc)
717724

718725
static inline u32 __xe_lrc_indirect_ring_offset(struct xe_lrc *lrc)
719726
{
720-
return xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE - LRC_INDIRECT_RING_STATE_SIZE;
727+
u32 offset = xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE -
728+
LRC_INDIRECT_RING_STATE_SIZE;
729+
730+
if (lrc->flags & XE_LRC_FLAG_INDIRECT_CTX)
731+
offset -= LRC_INDIRECT_CTX_BO_SIZE;
732+
733+
return offset;
734+
}
735+
736+
static inline u32 __xe_lrc_indirect_ctx_offset(struct xe_lrc *lrc)
737+
{
738+
return xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE - LRC_INDIRECT_CTX_BO_SIZE;
721739
}
722740

723741
static inline u32 __xe_lrc_wa_bb_offset(struct xe_lrc *lrc)
@@ -1077,6 +1095,58 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
10771095
return 0;
10781096
}
10791097

1098+
static int
1099+
setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
1100+
{
1101+
static struct bo_setup rcs_funcs[] = {
1102+
};
1103+
struct bo_setup_state state = {
1104+
.lrc = lrc,
1105+
.hwe = hwe,
1106+
.max_size = (63 * 64) /* max 63 cachelines */,
1107+
.offset = __xe_lrc_indirect_ctx_offset(lrc),
1108+
};
1109+
int ret;
1110+
1111+
if (!(lrc->flags & XE_LRC_FLAG_INDIRECT_CTX))
1112+
return 0;
1113+
1114+
if (hwe->class == XE_ENGINE_CLASS_RENDER ||
1115+
hwe->class == XE_ENGINE_CLASS_COMPUTE) {
1116+
state.funcs = rcs_funcs;
1117+
state.num_funcs = ARRAY_SIZE(rcs_funcs);
1118+
}
1119+
1120+
if (xe_gt_WARN_ON(lrc->gt, !state.funcs))
1121+
return 0;
1122+
1123+
ret = setup_bo(&state);
1124+
if (ret)
1125+
return ret;
1126+
1127+
/*
1128+
* Align to 64B cacheline so there's no garbage at the end for CS to
1129+
* execute: size for indirect ctx must be a multiple of 64.
1130+
*/
1131+
while (state.written & 0xf) {
1132+
*state.ptr++ = MI_NOOP;
1133+
state.written++;
1134+
}
1135+
1136+
finish_bo(&state);
1137+
1138+
xe_lrc_write_ctx_reg(lrc,
1139+
CTX_CS_INDIRECT_CTX,
1140+
(xe_bo_ggtt_addr(lrc->bo) + state.offset) |
1141+
/* Size in CLs. */
1142+
(state.written * sizeof(u32) / 64));
1143+
xe_lrc_write_ctx_reg(lrc,
1144+
CTX_CS_INDIRECT_CTX_OFFSET,
1145+
CTX_INDIRECT_CTX_OFFSET_DEFAULT);
1146+
1147+
return 0;
1148+
}
1149+
10801150
#define PVC_CTX_ASID (0x2e + 1)
10811151
#define PVC_CTX_ACC_CTR_THOLD (0x2a + 1)
10821152

@@ -1086,7 +1156,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10861156
{
10871157
struct xe_gt *gt = hwe->gt;
10881158
const u32 lrc_size = xe_gt_lrc_size(gt, hwe->class);
1089-
const u32 bo_size = ring_size + lrc_size + LRC_WA_BB_SIZE;
1159+
u32 bo_size = ring_size + lrc_size + LRC_WA_BB_SIZE;
10901160
struct xe_tile *tile = gt_to_tile(gt);
10911161
struct xe_device *xe = gt_to_xe(gt);
10921162
struct iosys_map map;
@@ -1101,6 +1171,12 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
11011171
lrc->flags = 0;
11021172
lrc->ring.size = ring_size;
11031173
lrc->ring.tail = 0;
1174+
1175+
if (gt_engine_needs_indirect_ctx(gt, hwe->class)) {
1176+
lrc->flags |= XE_LRC_FLAG_INDIRECT_CTX;
1177+
bo_size += LRC_INDIRECT_CTX_BO_SIZE;
1178+
}
1179+
11041180
if (xe_gt_has_indirect_ring_state(gt))
11051181
lrc->flags |= XE_LRC_FLAG_INDIRECT_RING_STATE;
11061182

@@ -1225,6 +1301,10 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
12251301
if (err)
12261302
goto err_lrc_finish;
12271303

1304+
err = setup_indirect_ctx(lrc, hwe);
1305+
if (err)
1306+
goto err_lrc_finish;
1307+
12281308
return 0;
12291309

12301310
err_lrc_finish:

drivers/gpu/drm/xe/xe_lrc_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct xe_lrc {
2929
struct xe_gt *gt;
3030

3131
/** @flags: LRC flags */
32-
#define XE_LRC_FLAG_INDIRECT_RING_STATE 0x1
32+
#define XE_LRC_FLAG_INDIRECT_CTX 0x1
33+
#define XE_LRC_FLAG_INDIRECT_RING_STATE 0x2
3334
u32 flags;
3435

3536
/** @refcount: ref count of this lrc */

0 commit comments

Comments
 (0)