Skip to content

Commit d2de441

Browse files
vsbelgaumlucasdemarchi
authored andcommitted
drm/xe: Apply Wa_16023105232
The WA requires KMD to disable DOP clock gating during a semaphore wait and also ensure that idle delay for every CS is lower than the idle wait time in the PWRCTX_MAXCNT register. Default values for these registers already comply with this restriction. v2: Store timestamp_base in gt info and other comments (Daniele) v3: Skip WA check for VF v4: Review comments (Matt Roper) v5: Cleanup the clock functions and use reg_field_get (Matt Roper) v6: Fix checkpatch issue v7: Fix CI issue Cc: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com> Signed-off-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250320175123.3026754-1-vinay.belgaumkar@intel.com (cherry picked from commit 7c53ff0) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 4fa752a commit d2de441

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130
#define RING_EXECLIST_STATUS_LO(base) XE_REG((base) + 0x234)
131131
#define RING_EXECLIST_STATUS_HI(base) XE_REG((base) + 0x234 + 4)
132132

133+
#define RING_IDLEDLY(base) XE_REG((base) + 0x23c)
134+
#define INHIBIT_SWITCH_UNTIL_PREEMPTED REG_BIT(31)
135+
#define IDLE_DELAY REG_GENMASK(20, 0)
136+
133137
#define RING_CONTEXT_CONTROL(base) XE_REG((base) + 0x244, XE_REG_OPTION_MASKED)
134138
#define CTX_CTRL_PXP_ENABLE REG_BIT(10)
135139
#define CTX_CTRL_OAC_CONTEXT_ENABLE REG_BIT(8)

drivers/gpu/drm/xe/xe_gt_clock.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,42 @@
1616
#include "xe_macros.h"
1717
#include "xe_mmio.h"
1818

19-
static u32 get_crystal_clock_freq(u32 rpm_config_reg)
19+
#define f19_2_mhz 19200000
20+
#define f24_mhz 24000000
21+
#define f25_mhz 25000000
22+
#define f38_4_mhz 38400000
23+
#define ts_base_83 83333
24+
#define ts_base_52 52083
25+
#define ts_base_80 80000
26+
27+
static void read_crystal_clock(struct xe_gt *gt, u32 rpm_config_reg, u32 *freq,
28+
u32 *timestamp_base)
2029
{
21-
const u32 f19_2_mhz = 19200000;
22-
const u32 f24_mhz = 24000000;
23-
const u32 f25_mhz = 25000000;
24-
const u32 f38_4_mhz = 38400000;
2530
u32 crystal_clock = REG_FIELD_GET(RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_MASK,
2631
rpm_config_reg);
2732

2833
switch (crystal_clock) {
2934
case RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_24_MHZ:
30-
return f24_mhz;
35+
*freq = f24_mhz;
36+
*timestamp_base = ts_base_83;
37+
return;
3138
case RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_19_2_MHZ:
32-
return f19_2_mhz;
39+
*freq = f19_2_mhz;
40+
*timestamp_base = ts_base_52;
41+
return;
3342
case RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_38_4_MHZ:
34-
return f38_4_mhz;
43+
*freq = f38_4_mhz;
44+
*timestamp_base = ts_base_52;
45+
return;
3546
case RPM_CONFIG0_CRYSTAL_CLOCK_FREQ_25_MHZ:
36-
return f25_mhz;
47+
*freq = f25_mhz;
48+
*timestamp_base = ts_base_80;
49+
return;
3750
default:
38-
XE_WARN_ON("NOT_POSSIBLE");
39-
return 0;
51+
xe_gt_warn(gt, "Invalid crystal clock frequency: %u", crystal_clock);
52+
*freq = 0;
53+
*timestamp_base = 0;
54+
return;
4055
}
4156
}
4257

@@ -65,7 +80,7 @@ int xe_gt_clock_init(struct xe_gt *gt)
6580
check_ctc_mode(gt);
6681

6782
c0 = xe_mmio_read32(&gt->mmio, RPM_CONFIG0);
68-
freq = get_crystal_clock_freq(c0);
83+
read_crystal_clock(gt, c0, &freq, &gt->info.timestamp_base);
6984

7085
/*
7186
* Now figure out how the command stream's timestamp

drivers/gpu/drm/xe/xe_gt_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ struct xe_gt {
121121
enum xe_gt_type type;
122122
/** @info.reference_clock: clock frequency */
123123
u32 reference_clock;
124+
/** @info.timestamp_base: GT timestamp base */
125+
u32 timestamp_base;
124126
/**
125127
* @info.engine_mask: mask of engines present on GT. Some of
126128
* them may be reserved in runtime and not available for user.

drivers/gpu/drm/xe/xe_hw_engine.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <linux/nospec.h>
99

1010
#include <drm/drm_managed.h>
11+
#include <drm/drm_print.h>
1112
#include <uapi/drm/xe_drm.h>
13+
#include <generated/xe_wa_oob.h>
1214

1315
#include "regs/xe_engine_regs.h"
1416
#include "regs/xe_gt_regs.h"
@@ -21,6 +23,7 @@
2123
#include "xe_gsc.h"
2224
#include "xe_gt.h"
2325
#include "xe_gt_ccs_mode.h"
26+
#include "xe_gt_clock.h"
2427
#include "xe_gt_printk.h"
2528
#include "xe_gt_mcr.h"
2629
#include "xe_gt_topology.h"
@@ -564,6 +567,33 @@ static void hw_engine_init_early(struct xe_gt *gt, struct xe_hw_engine *hwe,
564567
xe_reg_whitelist_process_engine(hwe);
565568
}
566569

570+
static void adjust_idledly(struct xe_hw_engine *hwe)
571+
{
572+
struct xe_gt *gt = hwe->gt;
573+
u32 idledly, maxcnt;
574+
u32 idledly_units_ps = 8 * gt->info.timestamp_base;
575+
u32 maxcnt_units_ns = 640;
576+
bool inhibit_switch = 0;
577+
578+
if (!IS_SRIOV_VF(gt_to_xe(hwe->gt)) && XE_WA(gt, 16023105232)) {
579+
idledly = xe_mmio_read32(&gt->mmio, RING_IDLEDLY(hwe->mmio_base));
580+
maxcnt = xe_mmio_read32(&gt->mmio, RING_PWRCTX_MAXCNT(hwe->mmio_base));
581+
582+
inhibit_switch = idledly & INHIBIT_SWITCH_UNTIL_PREEMPTED;
583+
idledly = REG_FIELD_GET(IDLE_DELAY, idledly);
584+
idledly = DIV_ROUND_CLOSEST(idledly * idledly_units_ps, 1000);
585+
maxcnt = REG_FIELD_GET(IDLE_WAIT_TIME, maxcnt);
586+
maxcnt *= maxcnt_units_ns;
587+
588+
if (xe_gt_WARN_ON(gt, idledly >= maxcnt || inhibit_switch)) {
589+
idledly = DIV_ROUND_CLOSEST(((maxcnt - 1) * maxcnt_units_ns),
590+
idledly_units_ps);
591+
idledly = DIV_ROUND_CLOSEST(idledly, 1000);
592+
xe_mmio_write32(&gt->mmio, RING_IDLEDLY(hwe->mmio_base), idledly);
593+
}
594+
}
595+
}
596+
567597
static int hw_engine_init(struct xe_gt *gt, struct xe_hw_engine *hwe,
568598
enum xe_hw_engine_id id)
569599
{
@@ -604,6 +634,9 @@ static int hw_engine_init(struct xe_gt *gt, struct xe_hw_engine *hwe,
604634
if (xe->info.has_usm && hwe->class == XE_ENGINE_CLASS_COPY)
605635
gt->usm.reserved_bcs_instance = hwe->instance;
606636

637+
/* Ensure IDLEDLY is lower than MAXCNT */
638+
adjust_idledly(hwe);
639+
607640
return devm_add_action_or_reset(xe->drm.dev, hw_engine_fini, hwe);
608641

609642
err_hwsp:

drivers/gpu/drm/xe/xe_wa.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ static const struct xe_rtp_entry_sr engine_was[] = {
622622
FUNC(xe_rtp_match_first_render_or_compute)),
623623
XE_RTP_ACTIONS(SET(TDL_TSL_CHICKEN, RES_CHK_SPR_DIS))
624624
},
625+
{ XE_RTP_NAME("16023105232"),
626+
XE_RTP_RULES(MEDIA_VERSION_RANGE(1301, 3000), OR,
627+
GRAPHICS_VERSION_RANGE(2001, 3001)),
628+
XE_RTP_ACTIONS(SET(RING_PSMI_CTL(0), RC_SEMA_IDLE_MSG_DISABLE,
629+
XE_RTP_ACTION_FLAG(ENGINE_BASE)))
630+
},
625631
};
626632

627633
static const struct xe_rtp_entry_sr lrc_was[] = {

drivers/gpu/drm/xe/xe_wa_oob.rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ no_media_l3 MEDIA_VERSION(3000)
5353
GRAPHICS_VERSION_RANGE(1270, 1274)
5454
1508761755 GRAPHICS_VERSION(1255)
5555
GRAPHICS_VERSION(1260), GRAPHICS_STEP(A0, B0)
56+
16023105232 GRAPHICS_VERSION_RANGE(2001, 3001)
57+
MEDIA_VERSION_RANGE(1301, 3000)

0 commit comments

Comments
 (0)