Skip to content

Commit 31a5dce

Browse files
hghimirarodrigovivi
authored andcommitted
drm/xe/guc: Update handling of xe_force_wake_get return
xe_force_wake_get() now returns the reference count-incremented domain mask. If it fails for individual domains, the return value will always be 0. However, for XE_FORCEWAKE_ALL, it may return a non-zero value even in the event of failure. Use helper xe_force_wake_ref_has_domain to verify all domains are initialized or not. Update the return handling of xe_force_wake_get() to reflect this behavior, and ensure that the return value is passed as input to xe_force_wake_put(). v3 - return xe_wakeref_t instead of int in xe_force_wake_get() - xe_force_wake_put() error doesn't need to be checked. It internally WARNS on domain ack failure. v5 - return unsigned int from xe_force_wake_get() - Remove redundant xe_gt_WARN_ON v6 - use helper xe_force_wake_ref_has_domain() v7 - Fix commit message v9 - Rebase Cc: Matthew Brost <[email protected]> Cc: Rodrigo Vivi <[email protected]> Cc: Lucas De Marchi <[email protected]> Signed-off-by: Himal Prasad Ghimiray <[email protected]> Reviewed-by: Nirmoy Das <[email protected]> Reviewed-by: Badal Nilawar <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 85d5476 commit 31a5dce

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

drivers/gpu/drm/xe/xe_guc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ static void guc_fini_hw(void *arg)
248248
{
249249
struct xe_guc *guc = arg;
250250
struct xe_gt *gt = guc_to_gt(guc);
251+
unsigned int fw_ref;
251252

252-
xe_gt_WARN_ON(gt, xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL));
253+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
253254
xe_uc_fini_hw(&guc_to_gt(guc)->uc);
254-
xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
255+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
255256
}
256257

257258
/**
@@ -1155,14 +1156,14 @@ int xe_guc_start(struct xe_guc *guc)
11551156
void xe_guc_print_info(struct xe_guc *guc, struct drm_printer *p)
11561157
{
11571158
struct xe_gt *gt = guc_to_gt(guc);
1159+
unsigned int fw_ref;
11581160
u32 status;
1159-
int err;
11601161
int i;
11611162

11621163
xe_uc_fw_print(&guc->fw, p);
11631164

1164-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
1165-
if (err)
1165+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
1166+
if (!fw_ref)
11661167
return;
11671168

11681169
status = xe_mmio_read32(&gt->mmio, GUC_STATUS);
@@ -1183,7 +1184,7 @@ void xe_guc_print_info(struct xe_guc *guc, struct drm_printer *p)
11831184
i, xe_mmio_read32(&gt->mmio, SOFT_SCRATCH(i)));
11841185
}
11851186

1186-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
1187+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
11871188

11881189
xe_guc_ct_print(&guc->ct, p);
11891190
xe_guc_submit_print(guc, p);

drivers/gpu/drm/xe/xe_guc_log.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ struct xe_guc_log_snapshot *xe_guc_log_snapshot_capture(struct xe_guc_log *log,
145145
struct xe_device *xe = log_to_xe(log);
146146
struct xe_guc *guc = log_to_guc(log);
147147
struct xe_gt *gt = log_to_gt(log);
148+
unsigned int fw_ref;
148149
size_t remain;
149-
int i, err;
150+
int i;
150151

151152
if (!log->bo) {
152153
xe_gt_err(gt, "GuC log buffer not allocated\n");
@@ -168,12 +169,12 @@ struct xe_guc_log_snapshot *xe_guc_log_snapshot_capture(struct xe_guc_log *log,
168169
remain -= size;
169170
}
170171

171-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
172-
if (err) {
172+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
173+
if (!fw_ref) {
173174
snapshot->stamp = ~0;
174175
} else {
175176
snapshot->stamp = xe_mmio_read32(&gt->mmio, GUC_PMTIMESTAMP);
176-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
177+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
177178
}
178179
snapshot->ktime = ktime_get_boottime_ns();
179180
snapshot->level = log->level;

drivers/gpu/drm/xe/xe_guc_pc.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,22 +415,24 @@ u32 xe_guc_pc_get_act_freq(struct xe_guc_pc *pc)
415415
int xe_guc_pc_get_cur_freq(struct xe_guc_pc *pc, u32 *freq)
416416
{
417417
struct xe_gt *gt = pc_to_gt(pc);
418-
int ret;
418+
unsigned int fw_ref;
419419

420420
/*
421421
* GuC SLPC plays with cur freq request when GuCRC is enabled
422422
* Block RC6 for a more reliable read.
423423
*/
424-
ret = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
425-
if (ret)
426-
return ret;
424+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
425+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
426+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
427+
return -ETIMEDOUT;
428+
}
427429

428430
*freq = xe_mmio_read32(&gt->mmio, RPNSWREQ);
429431

430432
*freq = REG_FIELD_GET(REQ_RATIO_MASK, *freq);
431433
*freq = decode_freq(*freq);
432434

433-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
435+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
434436
return 0;
435437
}
436438

@@ -480,6 +482,7 @@ u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc)
480482
int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
481483
{
482484
struct xe_gt *gt = pc_to_gt(pc);
485+
unsigned int fw_ref;
483486
int ret;
484487

485488
mutex_lock(&pc->freq_lock);
@@ -493,9 +496,11 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
493496
* GuC SLPC plays with min freq request when GuCRC is enabled
494497
* Block RC6 for a more reliable read.
495498
*/
496-
ret = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
497-
if (ret)
498-
goto out;
499+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
500+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
501+
ret = -ETIMEDOUT;
502+
goto fw;
503+
}
499504

500505
ret = pc_action_query_task_state(pc);
501506
if (ret)
@@ -504,7 +509,7 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
504509
*freq = pc_get_min_freq(pc);
505510

506511
fw:
507-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
512+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
508513
out:
509514
mutex_unlock(&pc->freq_lock);
510515
return ret;
@@ -855,6 +860,7 @@ int xe_guc_pc_gucrc_disable(struct xe_guc_pc *pc)
855860
{
856861
struct xe_device *xe = pc_to_xe(pc);
857862
struct xe_gt *gt = pc_to_gt(pc);
863+
unsigned int fw_ref;
858864
int ret = 0;
859865

860866
if (xe->info.skip_guc_pc)
@@ -864,13 +870,15 @@ int xe_guc_pc_gucrc_disable(struct xe_guc_pc *pc)
864870
if (ret)
865871
return ret;
866872

867-
ret = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
868-
if (ret)
869-
return ret;
873+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
874+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
875+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
876+
return -ETIMEDOUT;
877+
}
870878

871879
xe_gt_idle_disable_c6(gt);
872880

873-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
881+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
874882

875883
return 0;
876884
}
@@ -956,13 +964,16 @@ int xe_guc_pc_start(struct xe_guc_pc *pc)
956964
struct xe_device *xe = pc_to_xe(pc);
957965
struct xe_gt *gt = pc_to_gt(pc);
958966
u32 size = PAGE_ALIGN(sizeof(struct slpc_shared_data));
967+
unsigned int fw_ref;
959968
int ret;
960969

961970
xe_gt_assert(gt, xe_device_uc_enabled(xe));
962971

963-
ret = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
964-
if (ret)
965-
return ret;
972+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
973+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
974+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
975+
return -ETIMEDOUT;
976+
}
966977

967978
if (xe->info.skip_guc_pc) {
968979
if (xe->info.platform != XE_PVC)
@@ -1005,7 +1016,7 @@ int xe_guc_pc_start(struct xe_guc_pc *pc)
10051016
ret = pc_action_setup_gucrc(pc, GUCRC_FIRMWARE_CONTROL);
10061017

10071018
out:
1008-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
1019+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
10091020
return ret;
10101021
}
10111022

@@ -1037,18 +1048,19 @@ static void xe_guc_pc_fini_hw(void *arg)
10371048
{
10381049
struct xe_guc_pc *pc = arg;
10391050
struct xe_device *xe = pc_to_xe(pc);
1051+
unsigned int fw_ref;
10401052

10411053
if (xe_device_wedged(xe))
10421054
return;
10431055

1044-
XE_WARN_ON(xe_force_wake_get(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL));
1056+
fw_ref = xe_force_wake_get(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL);
10451057
xe_guc_pc_gucrc_disable(pc);
10461058
XE_WARN_ON(xe_guc_pc_stop(pc));
10471059

10481060
/* Bind requested freq to mert_freq_cap before unload */
10491061
pc_set_cur_freq(pc, min(pc_max_freq_cap(pc), pc->rpe_freq));
10501062

1051-
xe_force_wake_put(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL);
1063+
xe_force_wake_put(gt_to_fw(pc_to_gt(pc)), fw_ref);
10521064
}
10531065

10541066
/**

drivers/gpu/drm/xe/xe_guc_submit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
10981098
struct xe_guc *guc = exec_queue_to_guc(q);
10991099
const char *process_name = "no process";
11001100
struct xe_device *xe = guc_to_xe(guc);
1101+
unsigned int fw_ref;
11011102
int err = -ETIME;
11021103
pid_t pid = -1;
11031104
int i = 0;
@@ -1135,12 +1136,13 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
11351136
if (!exec_queue_killed(q) && !xe->devcoredump.captured &&
11361137
!xe_guc_capture_get_matching_and_lock(job)) {
11371138
/* take force wake before engine register manual capture */
1138-
if (xe_force_wake_get(gt_to_fw(q->gt), XE_FORCEWAKE_ALL))
1139+
fw_ref = xe_force_wake_get(gt_to_fw(q->gt), XE_FORCEWAKE_ALL);
1140+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
11391141
xe_gt_info(q->gt, "failed to get forcewake for coredump capture\n");
11401142

11411143
xe_engine_snapshot_capture_for_job(job);
11421144

1143-
xe_force_wake_put(gt_to_fw(q->gt), XE_FORCEWAKE_ALL);
1145+
xe_force_wake_put(gt_to_fw(q->gt), fw_ref);
11441146
}
11451147

11461148
/*

0 commit comments

Comments
 (0)