Skip to content

Commit fe13fd6

Browse files
mattroperodrigovivi
authored andcommitted
drm/xe/pcode: Treat pcode as per-tile rather than per-GT
There's only one instance of the pcode per tile, and for GT-related accesses both the primary and media GT share the same register interface. Since Xe was using per-GT locking, the pcode mutex wasn't actually protecting everything that it should since concurrent accesses related to a tile's primary GT and media GT were possible. Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Signed-off-by: Matt Roper <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 3034cc8) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 529bf8d commit fe13fd6

File tree

11 files changed

+85
-79
lines changed

11 files changed

+85
-79
lines changed

drivers/gpu/drm/xe/compat-i915-headers/intel_pcode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ static inline int
1313
snb_pcode_write_timeout(struct intel_uncore *uncore, u32 mbox, u32 val,
1414
int fast_timeout_us, int slow_timeout_ms)
1515
{
16-
return xe_pcode_write_timeout(__compat_uncore_to_gt(uncore), mbox, val,
16+
return xe_pcode_write_timeout(__compat_uncore_to_tile(uncore), mbox, val,
1717
slow_timeout_ms ?: 1);
1818
}
1919

2020
static inline int
2121
snb_pcode_write(struct intel_uncore *uncore, u32 mbox, u32 val)
2222
{
2323

24-
return xe_pcode_write(__compat_uncore_to_gt(uncore), mbox, val);
24+
return xe_pcode_write(__compat_uncore_to_tile(uncore), mbox, val);
2525
}
2626

2727
static inline int
2828
snb_pcode_read(struct intel_uncore *uncore, u32 mbox, u32 *val, u32 *val1)
2929
{
30-
return xe_pcode_read(__compat_uncore_to_gt(uncore), mbox, val, val1);
30+
return xe_pcode_read(__compat_uncore_to_tile(uncore), mbox, val, val1);
3131
}
3232

3333
static inline int
3434
skl_pcode_request(struct intel_uncore *uncore, u32 mbox,
3535
u32 request, u32 reply_mask, u32 reply,
3636
int timeout_base_ms)
3737
{
38-
return xe_pcode_request(__compat_uncore_to_gt(uncore), mbox, request, reply_mask, reply,
38+
return xe_pcode_request(__compat_uncore_to_tile(uncore), mbox, request, reply_mask, reply,
3939
timeout_base_ms);
4040
}
4141

drivers/gpu/drm/xe/compat-i915-headers/intel_uncore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ static inline struct xe_gt *__compat_uncore_to_gt(struct intel_uncore *uncore)
1717
return xe_root_mmio_gt(xe);
1818
}
1919

20+
static inline struct xe_tile *__compat_uncore_to_tile(struct intel_uncore *uncore)
21+
{
22+
struct xe_device *xe = container_of(uncore, struct xe_device, uncore);
23+
24+
return xe_device_get_root_tile(xe);
25+
}
26+
2027
static inline u32 intel_uncore_read(struct intel_uncore *uncore,
2128
i915_reg_t i915_reg)
2229
{

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ struct xe_tile {
203203
} vf;
204204
} sriov;
205205

206+
/** @pcode: tile's PCODE */
207+
struct {
208+
/** @pcode.lock: protecting tile's PCODE mailbox data */
209+
struct mutex lock;
210+
} pcode;
211+
206212
/** @migrate: Migration helper for vram blits and clearing */
207213
struct xe_migrate *migrate;
208214

drivers/gpu/drm/xe/xe_gt.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "xe_migrate.h"
4848
#include "xe_mmio.h"
4949
#include "xe_pat.h"
50-
#include "xe_pcode.h"
5150
#include "xe_pm.h"
5251
#include "xe_mocs.h"
5352
#include "xe_reg_sr.h"
@@ -387,7 +386,6 @@ int xe_gt_init_early(struct xe_gt *gt)
387386
xe_tuning_process_gt(gt);
388387

389388
xe_force_wake_init_gt(gt, gt_to_fw(gt));
390-
xe_pcode_init(gt);
391389
spin_lock_init(&gt->global_invl_lock);
392390

393391
return 0;

drivers/gpu/drm/xe/xe_gt_types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,6 @@ struct xe_gt {
310310
/** @eclass: per hardware engine class interface on the GT */
311311
struct xe_hw_engine_class_intf eclass[XE_ENGINE_CLASS_MAX];
312312

313-
/** @pcode: GT's PCODE */
314-
struct {
315-
/** @pcode.lock: protecting GT's PCODE mailbox data */
316-
struct mutex lock;
317-
} pcode;
318-
319313
/** @sysfs: sysfs' kobj used by xe_gt_sysfs */
320314
struct kobject *sysfs;
321315

drivers/gpu/drm/xe/xe_guc_pc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static void pc_init_pcode_freq(struct xe_guc_pc *pc)
915915
u32 min = DIV_ROUND_CLOSEST(pc->rpn_freq, GT_FREQUENCY_MULTIPLIER);
916916
u32 max = DIV_ROUND_CLOSEST(pc->rp0_freq, GT_FREQUENCY_MULTIPLIER);
917917

918-
XE_WARN_ON(xe_pcode_init_min_freq_table(pc_to_gt(pc), min, max));
918+
XE_WARN_ON(xe_pcode_init_min_freq_table(gt_to_tile(pc_to_gt(pc)), min, max));
919919
}
920920

921921
static int pc_init_freqs(struct xe_guc_pc *pc)

drivers/gpu/drm/xe/xe_hwmon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,14 @@ static int xe_hwmon_pcode_read_i1(struct xe_gt *gt, u32 *uval)
441441
if (gt_to_xe(gt)->info.platform == XE_DG2)
442442
return -ENXIO;
443443

444-
return xe_pcode_read(gt, PCODE_MBOX(PCODE_POWER_SETUP,
444+
return xe_pcode_read(gt_to_tile(gt), PCODE_MBOX(PCODE_POWER_SETUP,
445445
POWER_SETUP_SUBCOMMAND_READ_I1, 0),
446446
uval, NULL);
447447
}
448448

449449
static int xe_hwmon_pcode_write_i1(struct xe_gt *gt, u32 uval)
450450
{
451-
return xe_pcode_write(gt, PCODE_MBOX(PCODE_POWER_SETUP,
451+
return xe_pcode_write(gt_to_tile(gt), PCODE_MBOX(PCODE_POWER_SETUP,
452452
POWER_SETUP_SUBCOMMAND_WRITE_I1, 0),
453453
(uval & POWER_SETUP_I1_DATA_MASK));
454454
}

drivers/gpu/drm/xe/xe_pcode.c

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "xe_assert.h"
1414
#include "xe_device.h"
15-
#include "xe_gt.h"
1615
#include "xe_mmio.h"
1716
#include "xe_pcode_api.h"
1817

@@ -30,7 +29,7 @@
3029
* - PCODE for display operations
3130
*/
3231

33-
static int pcode_mailbox_status(struct xe_gt *gt)
32+
static int pcode_mailbox_status(struct xe_tile *tile)
3433
{
3534
u32 err;
3635
static const struct pcode_err_decode err_decode[] = {
@@ -45,94 +44,95 @@ static int pcode_mailbox_status(struct xe_gt *gt)
4544
[PCODE_ERROR_MASK] = {-EPROTO, "Unknown"},
4645
};
4746

48-
err = xe_mmio_read32(gt, PCODE_MAILBOX) & PCODE_ERROR_MASK;
47+
err = xe_mmio_read32(tile->primary_gt, PCODE_MAILBOX) & PCODE_ERROR_MASK;
4948
if (err) {
50-
drm_err(&gt_to_xe(gt)->drm, "PCODE Mailbox failed: %d %s", err,
49+
drm_err(&tile_to_xe(tile)->drm, "PCODE Mailbox failed: %d %s", err,
5150
err_decode[err].str ?: "Unknown");
5251
return err_decode[err].errno ?: -EPROTO;
5352
}
5453

5554
return 0;
5655
}
5756

58-
static int __pcode_mailbox_rw(struct xe_gt *gt, u32 mbox, u32 *data0, u32 *data1,
57+
static int __pcode_mailbox_rw(struct xe_tile *tile, u32 mbox, u32 *data0, u32 *data1,
5958
unsigned int timeout_ms, bool return_data,
6059
bool atomic)
6160
{
61+
struct xe_gt *mmio = tile->primary_gt;
6262
int err;
6363

64-
if (gt_to_xe(gt)->info.skip_pcode)
64+
if (tile_to_xe(tile)->info.skip_pcode)
6565
return 0;
6666

67-
if ((xe_mmio_read32(gt, PCODE_MAILBOX) & PCODE_READY) != 0)
67+
if ((xe_mmio_read32(mmio, PCODE_MAILBOX) & PCODE_READY) != 0)
6868
return -EAGAIN;
6969

70-
xe_mmio_write32(gt, PCODE_DATA0, *data0);
71-
xe_mmio_write32(gt, PCODE_DATA1, data1 ? *data1 : 0);
72-
xe_mmio_write32(gt, PCODE_MAILBOX, PCODE_READY | mbox);
70+
xe_mmio_write32(mmio, PCODE_DATA0, *data0);
71+
xe_mmio_write32(mmio, PCODE_DATA1, data1 ? *data1 : 0);
72+
xe_mmio_write32(mmio, PCODE_MAILBOX, PCODE_READY | mbox);
7373

74-
err = xe_mmio_wait32(gt, PCODE_MAILBOX, PCODE_READY, 0,
74+
err = xe_mmio_wait32(mmio, PCODE_MAILBOX, PCODE_READY, 0,
7575
timeout_ms * USEC_PER_MSEC, NULL, atomic);
7676
if (err)
7777
return err;
7878

7979
if (return_data) {
80-
*data0 = xe_mmio_read32(gt, PCODE_DATA0);
80+
*data0 = xe_mmio_read32(mmio, PCODE_DATA0);
8181
if (data1)
82-
*data1 = xe_mmio_read32(gt, PCODE_DATA1);
82+
*data1 = xe_mmio_read32(mmio, PCODE_DATA1);
8383
}
8484

85-
return pcode_mailbox_status(gt);
85+
return pcode_mailbox_status(tile);
8686
}
8787

88-
static int pcode_mailbox_rw(struct xe_gt *gt, u32 mbox, u32 *data0, u32 *data1,
88+
static int pcode_mailbox_rw(struct xe_tile *tile, u32 mbox, u32 *data0, u32 *data1,
8989
unsigned int timeout_ms, bool return_data,
9090
bool atomic)
9191
{
92-
if (gt_to_xe(gt)->info.skip_pcode)
92+
if (tile_to_xe(tile)->info.skip_pcode)
9393
return 0;
9494

95-
lockdep_assert_held(&gt->pcode.lock);
95+
lockdep_assert_held(&tile->pcode.lock);
9696

97-
return __pcode_mailbox_rw(gt, mbox, data0, data1, timeout_ms, return_data, atomic);
97+
return __pcode_mailbox_rw(tile, mbox, data0, data1, timeout_ms, return_data, atomic);
9898
}
9999

100-
int xe_pcode_write_timeout(struct xe_gt *gt, u32 mbox, u32 data, int timeout)
100+
int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeout)
101101
{
102102
int err;
103103

104-
mutex_lock(&gt->pcode.lock);
105-
err = pcode_mailbox_rw(gt, mbox, &data, NULL, timeout, false, false);
106-
mutex_unlock(&gt->pcode.lock);
104+
mutex_lock(&tile->pcode.lock);
105+
err = pcode_mailbox_rw(tile, mbox, &data, NULL, timeout, false, false);
106+
mutex_unlock(&tile->pcode.lock);
107107

108108
return err;
109109
}
110110

111-
int xe_pcode_read(struct xe_gt *gt, u32 mbox, u32 *val, u32 *val1)
111+
int xe_pcode_read(struct xe_tile *tile, u32 mbox, u32 *val, u32 *val1)
112112
{
113113
int err;
114114

115-
mutex_lock(&gt->pcode.lock);
116-
err = pcode_mailbox_rw(gt, mbox, val, val1, 1, true, false);
117-
mutex_unlock(&gt->pcode.lock);
115+
mutex_lock(&tile->pcode.lock);
116+
err = pcode_mailbox_rw(tile, mbox, val, val1, 1, true, false);
117+
mutex_unlock(&tile->pcode.lock);
118118

119119
return err;
120120
}
121121

122-
static int pcode_try_request(struct xe_gt *gt, u32 mbox,
122+
static int pcode_try_request(struct xe_tile *tile, u32 mbox,
123123
u32 request, u32 reply_mask, u32 reply,
124124
u32 *status, bool atomic, int timeout_us, bool locked)
125125
{
126126
int slept, wait = 10;
127127

128-
xe_gt_assert(gt, timeout_us > 0);
128+
xe_tile_assert(tile, timeout_us > 0);
129129

130130
for (slept = 0; slept < timeout_us; slept += wait) {
131131
if (locked)
132-
*status = pcode_mailbox_rw(gt, mbox, &request, NULL, 1, true,
132+
*status = pcode_mailbox_rw(tile, mbox, &request, NULL, 1, true,
133133
atomic);
134134
else
135-
*status = __pcode_mailbox_rw(gt, mbox, &request, NULL, 1, true,
135+
*status = __pcode_mailbox_rw(tile, mbox, &request, NULL, 1, true,
136136
atomic);
137137
if ((*status == 0) && ((request & reply_mask) == reply))
138138
return 0;
@@ -149,7 +149,7 @@ static int pcode_try_request(struct xe_gt *gt, u32 mbox,
149149

150150
/**
151151
* xe_pcode_request - send PCODE request until acknowledgment
152-
* @gt: gt
152+
* @tile: tile
153153
* @mbox: PCODE mailbox ID the request is targeted for
154154
* @request: request ID
155155
* @reply_mask: mask used to check for request acknowledgment
@@ -166,17 +166,17 @@ static int pcode_try_request(struct xe_gt *gt, u32 mbox,
166166
* Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some
167167
* other error as reported by PCODE.
168168
*/
169-
int xe_pcode_request(struct xe_gt *gt, u32 mbox, u32 request,
170-
u32 reply_mask, u32 reply, int timeout_base_ms)
169+
int xe_pcode_request(struct xe_tile *tile, u32 mbox, u32 request,
170+
u32 reply_mask, u32 reply, int timeout_base_ms)
171171
{
172172
u32 status;
173173
int ret;
174174

175-
xe_gt_assert(gt, timeout_base_ms <= 3);
175+
xe_tile_assert(tile, timeout_base_ms <= 3);
176176

177-
mutex_lock(&gt->pcode.lock);
177+
mutex_lock(&tile->pcode.lock);
178178

179-
ret = pcode_try_request(gt, mbox, request, reply_mask, reply, &status,
179+
ret = pcode_try_request(tile, mbox, request, reply_mask, reply, &status,
180180
false, timeout_base_ms * 1000, true);
181181
if (!ret)
182182
goto out;
@@ -191,20 +191,20 @@ int xe_pcode_request(struct xe_gt *gt, u32 mbox, u32 request,
191191
* requests, and for any quirks of the PCODE firmware that delays
192192
* the request completion.
193193
*/
194-
drm_err(&gt_to_xe(gt)->drm,
194+
drm_err(&tile_to_xe(tile)->drm,
195195
"PCODE timeout, retrying with preemption disabled\n");
196196
preempt_disable();
197-
ret = pcode_try_request(gt, mbox, request, reply_mask, reply, &status,
197+
ret = pcode_try_request(tile, mbox, request, reply_mask, reply, &status,
198198
true, 50 * 1000, true);
199199
preempt_enable();
200200

201201
out:
202-
mutex_unlock(&gt->pcode.lock);
202+
mutex_unlock(&tile->pcode.lock);
203203
return status ? status : ret;
204204
}
205205
/**
206206
* xe_pcode_init_min_freq_table - Initialize PCODE's QOS frequency table
207-
* @gt: gt instance
207+
* @tile: tile instance
208208
* @min_gt_freq: Minimal (RPn) GT frequency in units of 50MHz.
209209
* @max_gt_freq: Maximal (RP0) GT frequency in units of 50MHz.
210210
*
@@ -227,30 +227,30 @@ int xe_pcode_request(struct xe_gt *gt, u32 mbox, u32 request,
227227
* - -EACCES, "PCODE Rejected"
228228
* - -EPROTO, "Unknown"
229229
*/
230-
int xe_pcode_init_min_freq_table(struct xe_gt *gt, u32 min_gt_freq,
230+
int xe_pcode_init_min_freq_table(struct xe_tile *tile, u32 min_gt_freq,
231231
u32 max_gt_freq)
232232
{
233233
int ret;
234234
u32 freq;
235235

236-
if (!gt_to_xe(gt)->info.has_llc)
236+
if (!tile_to_xe(tile)->info.has_llc)
237237
return 0;
238238

239239
if (max_gt_freq <= min_gt_freq)
240240
return -EINVAL;
241241

242-
mutex_lock(&gt->pcode.lock);
242+
mutex_lock(&tile->pcode.lock);
243243
for (freq = min_gt_freq; freq <= max_gt_freq; freq++) {
244244
u32 data = freq << PCODE_FREQ_RING_RATIO_SHIFT | freq;
245245

246-
ret = pcode_mailbox_rw(gt, PCODE_WRITE_MIN_FREQ_TABLE,
246+
ret = pcode_mailbox_rw(tile, PCODE_WRITE_MIN_FREQ_TABLE,
247247
&data, NULL, 1, false, false);
248248
if (ret)
249249
goto unlock;
250250
}
251251

252252
unlock:
253-
mutex_unlock(&gt->pcode.lock);
253+
mutex_unlock(&tile->pcode.lock);
254254
return ret;
255255
}
256256

@@ -270,7 +270,7 @@ int xe_pcode_init_min_freq_table(struct xe_gt *gt, u32 min_gt_freq,
270270
int xe_pcode_ready(struct xe_device *xe, bool locked)
271271
{
272272
u32 status, request = DGFX_GET_INIT_STATUS;
273-
struct xe_gt *gt = xe_root_mmio_gt(xe);
273+
struct xe_tile *tile = xe_device_get_root_tile(xe);
274274
int timeout_us = 180000000; /* 3 min */
275275
int ret;
276276

@@ -281,15 +281,15 @@ int xe_pcode_ready(struct xe_device *xe, bool locked)
281281
return 0;
282282

283283
if (locked)
284-
mutex_lock(&gt->pcode.lock);
284+
mutex_lock(&tile->pcode.lock);
285285

286-
ret = pcode_try_request(gt, DGFX_PCODE_STATUS, request,
286+
ret = pcode_try_request(tile, DGFX_PCODE_STATUS, request,
287287
DGFX_INIT_STATUS_COMPLETE,
288288
DGFX_INIT_STATUS_COMPLETE,
289289
&status, false, timeout_us, locked);
290290

291291
if (locked)
292-
mutex_unlock(&gt->pcode.lock);
292+
mutex_unlock(&tile->pcode.lock);
293293

294294
if (ret)
295295
drm_err(&xe->drm,
@@ -300,14 +300,14 @@ int xe_pcode_ready(struct xe_device *xe, bool locked)
300300

301301
/**
302302
* xe_pcode_init: initialize components of PCODE
303-
* @gt: gt instance
303+
* @tile: tile instance
304304
*
305305
* This function initializes the xe_pcode component.
306306
* To be called once only during probe.
307307
*/
308-
void xe_pcode_init(struct xe_gt *gt)
308+
void xe_pcode_init(struct xe_tile *tile)
309309
{
310-
drmm_mutex_init(&gt_to_xe(gt)->drm, &gt->pcode.lock);
310+
drmm_mutex_init(&tile_to_xe(tile)->drm, &tile->pcode.lock);
311311
}
312312

313313
/**

0 commit comments

Comments
 (0)