39
39
#define LRC_ENGINE_INSTANCE GENMASK_ULL(53, 48)
40
40
41
41
#define LRC_PPHWSP_SIZE SZ_4K
42
+ #define LRC_INDIRECT_CTX_BO_SIZE SZ_4K
42
43
#define LRC_INDIRECT_RING_STATE_SIZE SZ_4K
43
44
#define LRC_WA_BB_SIZE SZ_4K
44
45
@@ -48,6 +49,12 @@ lrc_to_xe(struct xe_lrc *lrc)
48
49
return gt_to_xe (lrc -> fence_ctx .gt );
49
50
}
50
51
52
+ static bool
53
+ gt_engine_needs_indirect_ctx (struct xe_gt * gt , enum xe_engine_class class )
54
+ {
55
+ return false;
56
+ }
57
+
51
58
size_t xe_gt_lrc_size (struct xe_gt * gt , enum xe_engine_class class )
52
59
{
53
60
struct xe_device * xe = gt_to_xe (gt );
@@ -717,7 +724,18 @@ static u32 __xe_lrc_ctx_timestamp_udw_offset(struct xe_lrc *lrc)
717
724
718
725
static inline u32 __xe_lrc_indirect_ring_offset (struct xe_lrc * lrc )
719
726
{
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 ;
721
739
}
722
740
723
741
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)
1077
1095
return 0 ;
1078
1096
}
1079
1097
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
+
1080
1150
#define PVC_CTX_ASID (0x2e + 1)
1081
1151
#define PVC_CTX_ACC_CTR_THOLD (0x2a + 1)
1082
1152
@@ -1086,7 +1156,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1086
1156
{
1087
1157
struct xe_gt * gt = hwe -> gt ;
1088
1158
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 ;
1090
1160
struct xe_tile * tile = gt_to_tile (gt );
1091
1161
struct xe_device * xe = gt_to_xe (gt );
1092
1162
struct iosys_map map ;
@@ -1101,6 +1171,12 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1101
1171
lrc -> flags = 0 ;
1102
1172
lrc -> ring .size = ring_size ;
1103
1173
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
+
1104
1180
if (xe_gt_has_indirect_ring_state (gt ))
1105
1181
lrc -> flags |= XE_LRC_FLAG_INDIRECT_RING_STATE ;
1106
1182
@@ -1225,6 +1301,10 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1225
1301
if (err )
1226
1302
goto err_lrc_finish ;
1227
1303
1304
+ err = setup_indirect_ctx (lrc , hwe );
1305
+ if (err )
1306
+ goto err_lrc_finish ;
1307
+
1228
1308
return 0 ;
1229
1309
1230
1310
err_lrc_finish :
0 commit comments