Skip to content

Commit d42b447

Browse files
hghimiragregkh
authored andcommitted
drm/xe/gt: Update handling of xe_force_wake_get return
[ Upstream commit 30d1055 ] 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. v4 - Rebase fix v5 - return unsigned int for xe_force_wake_get() - remove redundant XE_WARN_ON() v6 - use helper for checking all initialized domains are awake or not. v7 - Fix commit message v9 - Remove redundant WARN_ON (Badal) Cc: Badal Nilawar <[email protected]> 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]> Stable-dep-of: 16c1241 ("drm/xe/bmg: Update Wa_16023588340") Signed-off-by: Sasha Levin <[email protected]>
1 parent abf32d8 commit d42b447

File tree

1 file changed

+58
-47
lines changed

1 file changed

+58
-47
lines changed

drivers/gpu/drm/xe/xe_gt.c

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ void xe_gt_sanitize(struct xe_gt *gt)
9898

9999
static void xe_gt_enable_host_l2_vram(struct xe_gt *gt)
100100
{
101+
unsigned int fw_ref;
101102
u32 reg;
102-
int err;
103103

104104
if (!XE_WA(gt, 16023588340))
105105
return;
106106

107-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
108-
if (WARN_ON(err))
107+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
108+
if (!fw_ref)
109109
return;
110110

111111
if (!xe_gt_is_media_type(gt)) {
@@ -115,29 +115,29 @@ static void xe_gt_enable_host_l2_vram(struct xe_gt *gt)
115115
}
116116

117117
xe_gt_mcr_multicast_write(gt, XEHPC_L3CLOS_MASK(3), 0x3);
118-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
118+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
119119
}
120120

121121
static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
122122
{
123+
unsigned int fw_ref;
123124
u32 reg;
124-
int err;
125125

126126
if (!XE_WA(gt, 16023588340))
127127
return;
128128

129129
if (xe_gt_is_media_type(gt))
130130
return;
131131

132-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
133-
if (WARN_ON(err))
132+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
133+
if (!fw_ref)
134134
return;
135135

136136
reg = xe_gt_mcr_unicast_read_any(gt, XE2_GAMREQSTRM_CTRL);
137137
reg &= ~CG_DIS_CNTLBUS;
138138
xe_gt_mcr_multicast_write(gt, XE2_GAMREQSTRM_CTRL, reg);
139139

140-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
140+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
141141
}
142142

143143
/**
@@ -405,11 +405,14 @@ static void dump_pat_on_error(struct xe_gt *gt)
405405

406406
static int gt_fw_domain_init(struct xe_gt *gt)
407407
{
408+
unsigned int fw_ref;
408409
int err, i;
409410

410-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
411-
if (err)
411+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
412+
if (!fw_ref) {
413+
err = -ETIMEDOUT;
412414
goto err_hw_fence_irq;
415+
}
413416

414417
if (!xe_gt_is_media_type(gt)) {
415418
err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt);
@@ -444,14 +447,12 @@ static int gt_fw_domain_init(struct xe_gt *gt)
444447
*/
445448
gt->info.gmdid = xe_mmio_read32(gt, GMD_ID);
446449

447-
err = xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
448-
XE_WARN_ON(err);
449-
450+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
450451
return 0;
451452

452453
err_force_wake:
453454
dump_pat_on_error(gt);
454-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
455+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
455456
err_hw_fence_irq:
456457
for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i)
457458
xe_hw_fence_irq_finish(&gt->fence_irq[i]);
@@ -461,11 +462,14 @@ static int gt_fw_domain_init(struct xe_gt *gt)
461462

462463
static int all_fw_domain_init(struct xe_gt *gt)
463464
{
465+
unsigned int fw_ref;
464466
int err, i;
465467

466-
err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
467-
if (err)
468-
goto err_hw_fence_irq;
468+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
469+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
470+
err = -ETIMEDOUT;
471+
goto err_force_wake;
472+
}
469473

470474
xe_gt_mcr_set_implicit_defaults(gt);
471475
xe_wa_process_gt(gt);
@@ -531,14 +535,12 @@ static int all_fw_domain_init(struct xe_gt *gt)
531535
if (IS_SRIOV_PF(gt_to_xe(gt)))
532536
xe_gt_sriov_pf_init_hw(gt);
533537

534-
err = xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
535-
XE_WARN_ON(err);
538+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
536539

537540
return 0;
538541

539542
err_force_wake:
540-
xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
541-
err_hw_fence_irq:
543+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
542544
for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i)
543545
xe_hw_fence_irq_finish(&gt->fence_irq[i]);
544546

@@ -551,11 +553,12 @@ static int all_fw_domain_init(struct xe_gt *gt)
551553
*/
552554
int xe_gt_init_hwconfig(struct xe_gt *gt)
553555
{
556+
unsigned int fw_ref;
554557
int err;
555558

556-
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
557-
if (err)
558-
goto out;
559+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
560+
if (!fw_ref)
561+
return -ETIMEDOUT;
559562

560563
xe_gt_mcr_init_early(gt);
561564
xe_pat_init(gt);
@@ -573,8 +576,7 @@ int xe_gt_init_hwconfig(struct xe_gt *gt)
573576
xe_gt_enable_host_l2_vram(gt);
574577

575578
out_fw:
576-
xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
577-
out:
579+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
578580
return err;
579581
}
580582

@@ -744,6 +746,7 @@ static int do_gt_restart(struct xe_gt *gt)
744746

745747
static int gt_reset(struct xe_gt *gt)
746748
{
749+
unsigned int fw_ref;
747750
int err;
748751

749752
if (xe_device_wedged(gt_to_xe(gt)))
@@ -764,9 +767,11 @@ static int gt_reset(struct xe_gt *gt)
764767

765768
xe_gt_sanitize(gt);
766769

767-
err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
768-
if (err)
769-
goto err_msg;
770+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
771+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
772+
err = -ETIMEDOUT;
773+
goto err_out;
774+
}
770775

771776
xe_uc_gucrc_disable(&gt->uc);
772777
xe_uc_stop_prepare(&gt->uc);
@@ -784,17 +789,15 @@ static int gt_reset(struct xe_gt *gt)
784789
if (err)
785790
goto err_out;
786791

787-
err = xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
788-
XE_WARN_ON(err);
792+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
789793
xe_pm_runtime_put(gt_to_xe(gt));
790794

791795
xe_gt_info(gt, "reset done\n");
792796

793797
return 0;
794798

795799
err_out:
796-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
797-
err_msg:
800+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
798801
XE_WARN_ON(xe_uc_start(&gt->uc));
799802
err_fail:
800803
xe_gt_err(gt, "reset failed (%pe)\n", ERR_PTR(err));
@@ -826,22 +829,25 @@ void xe_gt_reset_async(struct xe_gt *gt)
826829

827830
void xe_gt_suspend_prepare(struct xe_gt *gt)
828831
{
829-
XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL));
832+
unsigned int fw_ref;
833+
834+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
830835

831836
xe_uc_suspend_prepare(&gt->uc);
832837

833-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
838+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
834839
}
835840

836841
int xe_gt_suspend(struct xe_gt *gt)
837842
{
843+
unsigned int fw_ref;
838844
int err;
839845

840846
xe_gt_dbg(gt, "suspending\n");
841847
xe_gt_sanitize(gt);
842848

843-
err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
844-
if (err)
849+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
850+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
845851
goto err_msg;
846852

847853
err = xe_uc_suspend(&gt->uc);
@@ -852,24 +858,27 @@ int xe_gt_suspend(struct xe_gt *gt)
852858

853859
xe_gt_disable_host_l2_vram(gt);
854860

855-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
861+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
856862
xe_gt_dbg(gt, "suspended\n");
857863

858864
return 0;
859865

860-
err_force_wake:
861-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
862866
err_msg:
867+
err = -ETIMEDOUT;
868+
err_force_wake:
869+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
863870
xe_gt_err(gt, "suspend failed (%pe)\n", ERR_PTR(err));
864871

865872
return err;
866873
}
867874

868875
void xe_gt_shutdown(struct xe_gt *gt)
869876
{
870-
xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
877+
unsigned int fw_ref;
878+
879+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
871880
do_gt_reset(gt);
872-
xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
881+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
873882
}
874883

875884
/**
@@ -894,11 +903,12 @@ int xe_gt_sanitize_freq(struct xe_gt *gt)
894903

895904
int xe_gt_resume(struct xe_gt *gt)
896905
{
906+
unsigned int fw_ref;
897907
int err;
898908

899909
xe_gt_dbg(gt, "resuming\n");
900-
err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
901-
if (err)
910+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
911+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
902912
goto err_msg;
903913

904914
err = do_gt_restart(gt);
@@ -907,14 +917,15 @@ int xe_gt_resume(struct xe_gt *gt)
907917

908918
xe_gt_idle_enable_pg(gt);
909919

910-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
920+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
911921
xe_gt_dbg(gt, "resumed\n");
912922

913923
return 0;
914924

915-
err_force_wake:
916-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
917925
err_msg:
926+
err = -ETIMEDOUT;
927+
err_force_wake:
928+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
918929
xe_gt_err(gt, "resume failed (%pe)\n", ERR_PTR(err));
919930

920931
return err;

0 commit comments

Comments
 (0)