Skip to content

Commit 6c6988c

Browse files
author
Lucas De Marchi
committed
drm/xe/lrc: Allow to add user commands on context switch
During validation it's useful to allows additional commands to be executed on context switch. Fetch the commands from configfs (to be added) and add them to the WA BB. Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://lore.kernel.org/r/20250916-wa-bb-cmds-v5-3-306bddbc15da@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent e2a9854 commit 6c6988c

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_configfs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,19 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)
633633
return ret;
634634
}
635635

636+
/**
637+
* xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting
638+
* @pdev: pci device
639+
*
640+
* Return: post_ctx_restore setting in configfs
641+
*/
642+
u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,
643+
enum xe_engine_class class,
644+
const u32 **cs)
645+
{
646+
return 0;
647+
}
648+
636649
int __init xe_configfs_init(void)
637650
{
638651
int ret;

drivers/gpu/drm/xe/xe_configfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <linux/limits.h>
99
#include <linux/types.h>
1010

11+
#include <xe_hw_engine_types.h>
12+
1113
struct pci_dev;
1214

1315
#if IS_ENABLED(CONFIG_CONFIGFS_FS)
@@ -17,13 +19,17 @@ void xe_configfs_check_device(struct pci_dev *pdev);
1719
bool xe_configfs_get_survivability_mode(struct pci_dev *pdev);
1820
u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev);
1921
bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev);
22+
u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
23+
const u32 **cs);
2024
#else
2125
static inline int xe_configfs_init(void) { return 0; }
2226
static inline void xe_configfs_exit(void) { }
2327
static inline void xe_configfs_check_device(struct pci_dev *pdev) { }
2428
static inline bool xe_configfs_get_survivability_mode(struct pci_dev *pdev) { return false; }
2529
static inline u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev) { return U64_MAX; }
2630
static inline bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev) { return false; }
31+
static inline u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
32+
const u32 **cs) { return 0; }
2733
#endif
2834

2935
#endif

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <generated/xe_wa_oob.h>
99

1010
#include <linux/ascii85.h>
11+
#include <linux/panic.h>
1112

1213
#include "instructions/xe_mi_commands.h"
1314
#include "instructions/xe_gfxpipe_commands.h"
@@ -16,6 +17,7 @@
1617
#include "regs/xe_lrc_layout.h"
1718
#include "xe_bb.h"
1819
#include "xe_bo.h"
20+
#include "xe_configfs.h"
1921
#include "xe_device.h"
2022
#include "xe_drm_client.h"
2123
#include "xe_exec_queue_types.h"
@@ -1102,6 +1104,35 @@ static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
11021104
return cmd - batch;
11031105
}
11041106

1107+
static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc,
1108+
struct xe_hw_engine *hwe,
1109+
u32 *batch, size_t max_len)
1110+
{
1111+
struct xe_device *xe = gt_to_xe(lrc->gt);
1112+
const u32 *user_batch;
1113+
u32 *cmd = batch;
1114+
u32 count;
1115+
1116+
count = xe_configfs_get_ctx_restore_post_bb(to_pci_dev(xe->drm.dev),
1117+
hwe->class, &user_batch);
1118+
if (!count)
1119+
return 0;
1120+
1121+
if (count > max_len)
1122+
return -ENOSPC;
1123+
1124+
/*
1125+
* This should be used only for tests and validation. Taint the kernel
1126+
* as anything could be submitted directly in context switches
1127+
*/
1128+
add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
1129+
1130+
memcpy(cmd, user_batch, count * sizeof(u32));
1131+
cmd += count;
1132+
1133+
return cmd - batch;
1134+
}
1135+
11051136
static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc,
11061137
struct xe_hw_engine *hwe,
11071138
u32 *batch, size_t max_len)
@@ -1203,6 +1234,7 @@ int xe_lrc_setup_wa_bb_with_scratch(struct xe_lrc *lrc, struct xe_hw_engine *hwe
12031234
{ .setup = setup_timestamp_wa },
12041235
{ .setup = setup_invalidate_state_cache_wa },
12051236
{ .setup = setup_utilization_wa },
1237+
{ .setup = setup_configfs_post_ctx_restore_bb },
12061238
};
12071239
struct bo_setup_state state = {
12081240
.lrc = lrc,

0 commit comments

Comments
 (0)