Skip to content

Commit 7a4756b

Browse files
author
Lucas De Marchi
committed
drm/xe/lrc: Allow to add user commands mid context switch
Like done for post-context-restore commands, allow to add commands from configfs in the middle of context restore. Since currently the indirect ctx hardcodes the offset to CTX_INDIRECT_CTX_OFFSET_DEFAULT, this is executed in the very beginning of engine context restore. Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://lore.kernel.org/r/20250916-wa-bb-cmds-v5-6-306bddbc15da@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent c9dfd66 commit 7a4756b

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_configfs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,21 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)
897897
return ret;
898898
}
899899

900+
/**
901+
* xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting
902+
* @pdev: pci device
903+
* @class: hw engine class
904+
* @cs: pointer to the bb to use - only valid during probe
905+
*
906+
* Return: Number of dwords used in the mid_ctx_restore setting in configfs
907+
*/
908+
u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev,
909+
enum xe_engine_class class,
910+
const u32 **cs)
911+
{
912+
return 0;
913+
}
914+
900915
/**
901916
* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting
902917
* @pdev: pci device

drivers/gpu/drm/xe/xe_configfs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void xe_configfs_check_device(struct pci_dev *pdev);
1919
bool xe_configfs_get_survivability_mode(struct pci_dev *pdev);
2020
u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev);
2121
bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev);
22+
u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, enum xe_engine_class,
23+
const u32 **cs);
2224
u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
2325
const u32 **cs);
2426
#else
@@ -28,6 +30,8 @@ static inline void xe_configfs_check_device(struct pci_dev *pdev) { }
2830
static inline bool xe_configfs_get_survivability_mode(struct pci_dev *pdev) { return false; }
2931
static inline u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev) { return U64_MAX; }
3032
static inline bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev) { return false; }
33+
static inline u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, enum xe_engine_class,
34+
const u32 **cs) { return 0; }
3135
static inline u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
3236
const u32 **cs) { return 0; }
3337
#endif

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ lrc_to_xe(struct xe_lrc *lrc)
7777
static bool
7878
gt_engine_needs_indirect_ctx(struct xe_gt *gt, enum xe_engine_class class)
7979
{
80+
struct xe_device *xe = gt_to_xe(gt);
81+
8082
if (XE_GT_WA(gt, 16010904313) &&
8183
(class == XE_ENGINE_CLASS_RENDER ||
8284
class == XE_ENGINE_CLASS_COMPUTE))
8385
return true;
8486

87+
if (xe_configfs_get_ctx_restore_mid_bb(to_pci_dev(xe->drm.dev),
88+
class, NULL))
89+
return true;
90+
8591
return false;
8692
}
8793

@@ -1133,6 +1139,35 @@ static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc,
11331139
return cmd - batch;
11341140
}
11351141

1142+
static ssize_t setup_configfs_mid_ctx_restore_bb(struct xe_lrc *lrc,
1143+
struct xe_hw_engine *hwe,
1144+
u32 *batch, size_t max_len)
1145+
{
1146+
struct xe_device *xe = gt_to_xe(lrc->gt);
1147+
const u32 *user_batch;
1148+
u32 *cmd = batch;
1149+
u32 count;
1150+
1151+
count = xe_configfs_get_ctx_restore_mid_bb(to_pci_dev(xe->drm.dev),
1152+
hwe->class, &user_batch);
1153+
if (!count)
1154+
return 0;
1155+
1156+
if (count > max_len)
1157+
return -ENOSPC;
1158+
1159+
/*
1160+
* This should be used only for tests and validation. Taint the kernel
1161+
* as anything could be submitted directly in context switches
1162+
*/
1163+
add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
1164+
1165+
memcpy(cmd, user_batch, count * sizeof(u32));
1166+
cmd += count;
1167+
1168+
return cmd - batch;
1169+
}
1170+
11361171
static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc,
11371172
struct xe_hw_engine *hwe,
11381173
u32 *batch, size_t max_len)
@@ -1283,8 +1318,10 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
12831318
{
12841319
static const struct bo_setup rcs_funcs[] = {
12851320
{ .setup = setup_timestamp_wa },
1321+
{ .setup = setup_configfs_mid_ctx_restore_bb },
12861322
};
12871323
static const struct bo_setup xcs_funcs[] = {
1324+
{ .setup = setup_configfs_mid_ctx_restore_bb },
12881325
};
12891326
struct bo_setup_state state = {
12901327
.lrc = lrc,

0 commit comments

Comments
 (0)