mirror of
https://github.com/torvalds/linux.git
synced 2026-05-27 00:22:00 +02:00
drm/xe/gt: Use scope-based cleanup
Using scope-based cleanup for forcewake and runtime PM allows us to reduce or eliminate some of the goto-based error handling and simplify several functions. v2: - Drop changes to do_gt_restart(). This function still has goto-based logic, making scope-based cleanup unsafe for now. (Gustavo) Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com> Link: https://patch.msgid.link/20251118164338.3572146-32-matthew.d.roper@intel.com Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
This commit is contained in:
parent
59e7528dbf
commit
83d2ea17d5
|
|
@ -103,14 +103,13 @@ void xe_gt_sanitize(struct xe_gt *gt)
|
|||
|
||||
static void xe_gt_enable_host_l2_vram(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
u32 reg;
|
||||
|
||||
if (!XE_GT_WA(gt, 16023588340))
|
||||
return;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref)
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref.domains)
|
||||
return;
|
||||
|
||||
if (xe_gt_is_main_type(gt)) {
|
||||
|
|
@ -120,12 +119,10 @@ static void xe_gt_enable_host_l2_vram(struct xe_gt *gt)
|
|||
}
|
||||
|
||||
xe_gt_mcr_multicast_write(gt, XEHPC_L3CLOS_MASK(3), 0xF);
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
}
|
||||
|
||||
static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
u32 reg;
|
||||
|
||||
if (!XE_GT_WA(gt, 16023588340))
|
||||
|
|
@ -134,15 +131,13 @@ static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
|
|||
if (xe_gt_is_media_type(gt))
|
||||
return;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref)
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref.domains)
|
||||
return;
|
||||
|
||||
reg = xe_gt_mcr_unicast_read_any(gt, XE2_GAMREQSTRM_CTRL);
|
||||
reg &= ~CG_DIS_CNTLBUS;
|
||||
xe_gt_mcr_multicast_write(gt, XE2_GAMREQSTRM_CTRL, reg);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
}
|
||||
|
||||
static void gt_reset_worker(struct work_struct *w);
|
||||
|
|
@ -389,7 +384,6 @@ int xe_gt_record_default_lrcs(struct xe_gt *gt)
|
|||
|
||||
int xe_gt_init_early(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
int err;
|
||||
|
||||
if (IS_SRIOV_PF(gt_to_xe(gt))) {
|
||||
|
|
@ -436,13 +430,12 @@ int xe_gt_init_early(struct xe_gt *gt)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref)
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref.domains)
|
||||
return -ETIMEDOUT;
|
||||
|
||||
xe_gt_mcr_init_early(gt);
|
||||
xe_pat_init(gt);
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -460,16 +453,15 @@ static void dump_pat_on_error(struct xe_gt *gt)
|
|||
|
||||
static int gt_init_with_gt_forcewake(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
int err;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref)
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
|
||||
if (!fw_ref.domains)
|
||||
return -ETIMEDOUT;
|
||||
|
||||
err = xe_uc_init(>->uc);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
xe_gt_topology_init(gt);
|
||||
xe_gt_mcr_init(gt);
|
||||
|
|
@ -478,7 +470,7 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)
|
|||
if (xe_gt_is_main_type(gt)) {
|
||||
err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
if (IS_SRIOV_PF(gt_to_xe(gt)))
|
||||
xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt);
|
||||
}
|
||||
|
|
@ -492,17 +484,17 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)
|
|||
err = xe_hw_engines_init_early(gt);
|
||||
if (err) {
|
||||
dump_pat_on_error(gt);
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
}
|
||||
|
||||
err = xe_hw_engine_class_sysfs_init(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
/* Initialize CCS mode sysfs after early initialization of HW engines */
|
||||
err = xe_gt_ccs_mode_sysfs_init(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
/*
|
||||
* Stash hardware-reported version. Since this register does not exist
|
||||
|
|
@ -510,25 +502,16 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)
|
|||
*/
|
||||
gt->info.gmdid = xe_mmio_read32(>->mmio, GMD_ID);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
return 0;
|
||||
|
||||
err_force_wake:
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int gt_init_with_all_forcewake(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
int err;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
|
||||
err = -ETIMEDOUT;
|
||||
goto err_force_wake;
|
||||
}
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL))
|
||||
return -ETIMEDOUT;
|
||||
|
||||
xe_gt_mcr_set_implicit_defaults(gt);
|
||||
xe_wa_process_gt(gt);
|
||||
|
|
@ -537,20 +520,20 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
|
|||
|
||||
err = xe_gt_clock_init(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
xe_mocs_init(gt);
|
||||
err = xe_execlist_init(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
err = xe_hw_engines_init(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
err = xe_uc_init_post_hwconfig(>->uc);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
if (xe_gt_is_main_type(gt)) {
|
||||
/*
|
||||
|
|
@ -561,10 +544,8 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
|
|||
|
||||
gt->usm.bb_pool = xe_sa_bo_manager_init(gt_to_tile(gt),
|
||||
IS_DGFX(xe) ? SZ_1M : SZ_512K, 16);
|
||||
if (IS_ERR(gt->usm.bb_pool)) {
|
||||
err = PTR_ERR(gt->usm.bb_pool);
|
||||
goto err_force_wake;
|
||||
}
|
||||
if (IS_ERR(gt->usm.bb_pool))
|
||||
return PTR_ERR(gt->usm.bb_pool);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -573,12 +554,12 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
|
|||
|
||||
err = xe_migrate_init(tile->migrate);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
}
|
||||
|
||||
err = xe_uc_load_hw(>->uc);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
/* Configure default CCS mode of 1 engine with all resources */
|
||||
if (xe_gt_ccs_mode_enabled(gt)) {
|
||||
|
|
@ -592,14 +573,7 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
|
|||
if (IS_SRIOV_PF(gt_to_xe(gt)))
|
||||
xe_gt_sriov_pf_init_hw(gt);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
|
||||
return 0;
|
||||
|
||||
err_force_wake:
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static void xe_gt_fini(void *arg)
|
||||
|
|
@ -902,56 +876,42 @@ void xe_gt_reset_async(struct xe_gt *gt)
|
|||
|
||||
void xe_gt_suspend_prepare(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
xe_uc_suspend_prepare(>->uc);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
}
|
||||
|
||||
int xe_gt_suspend(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
int err;
|
||||
|
||||
xe_gt_dbg(gt, "suspending\n");
|
||||
xe_gt_sanitize(gt);
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
|
||||
goto err_msg;
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL)) {
|
||||
xe_gt_err(gt, "suspend failed (%pe)\n", ERR_PTR(-ETIMEDOUT));
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
err = xe_uc_suspend(>->uc);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
if (err) {
|
||||
xe_gt_err(gt, "suspend failed (%pe)\n", ERR_PTR(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
xe_gt_idle_disable_pg(gt);
|
||||
|
||||
xe_gt_disable_host_l2_vram(gt);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
xe_gt_dbg(gt, "suspended\n");
|
||||
|
||||
return 0;
|
||||
|
||||
err_msg:
|
||||
err = -ETIMEDOUT;
|
||||
err_force_wake:
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
xe_gt_err(gt, "suspend failed (%pe)\n", ERR_PTR(err));
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void xe_gt_shutdown(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
do_gt_reset(gt);
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -976,32 +936,24 @@ int xe_gt_sanitize_freq(struct xe_gt *gt)
|
|||
|
||||
int xe_gt_resume(struct xe_gt *gt)
|
||||
{
|
||||
unsigned int fw_ref;
|
||||
int err;
|
||||
|
||||
xe_gt_dbg(gt, "resuming\n");
|
||||
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
|
||||
goto err_msg;
|
||||
CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
|
||||
if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL)) {
|
||||
xe_gt_err(gt, "resume failed (%pe)\n", ERR_PTR(-ETIMEDOUT));
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
err = do_gt_restart(gt);
|
||||
if (err)
|
||||
goto err_force_wake;
|
||||
return err;
|
||||
|
||||
xe_gt_idle_enable_pg(gt);
|
||||
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
xe_gt_dbg(gt, "resumed\n");
|
||||
|
||||
return 0;
|
||||
|
||||
err_msg:
|
||||
err = -ETIMEDOUT;
|
||||
err_force_wake:
|
||||
xe_force_wake_put(gt_to_fw(gt), fw_ref);
|
||||
xe_gt_err(gt, "resume failed (%pe)\n", ERR_PTR(err));
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
struct xe_hw_engine *xe_gt_hw_engine(struct xe_gt *gt,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user