drm/amdgpu: balance GFX IRQ get/put across init/suspend/fini
Subsystems (2)
cover drm/amdgpu: balance GFX IRQ get/put across init/suspend/fini
The current GFX IRQ handling acquires the priv_reg / priv_inst / bad_op and (on v9) cp_ecc_error_irq IRQ refs in late_init but releases them in hw_fini. hw_fini runs on paths that may not reach late_init (SR-IOV VF skips the cp_ecc_error_irq get, an earlier IP init failure short-circuits late_init, etc.), so the puts have to be defensively guarded with amdgpu_irq_enabled().
Pair the gets and puts properly:
- Patch 1 adds a per-block ras_suspend callback and uses it to move cp_ecc_error_irq's release into amdgpu_gfx_ras_suspend() / amdgpu_gfx_ras_fini().
- Patch 2 moves the remaining priv_reg / priv_inst / bad_op and userq EOP IRQs from late_init to hw_init across gfx9, gfx9_4_3, gfx10, gfx11, gfx12_0 and gfx12_1, and drops the now-unnecessary amdgpu_irq_enabled() guards. It also fixes a pre-existing partial-failure leak in set_userq_eop_interrupts().
Follow-up to https://patchwork.freedesktop.org/patch/728675/.
Yunxiang Li (2):
drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq drm/amdgpu/gfx: move fault and EOP IRQ get/put to hw_init/hw_fini
PATCH 1/2 drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq
cp_ecc_error_irq is acquired in amdgpu_gfx_ras_late_init() but released in gfx_v9_0_hw_fini(), so the put site has to query amdgpu_irq_enabled() because the get is skipped on SR-IOV VF.
ras_late_init / ras_fini have no suspend counterpart, so move the put to amdgpu_gfx_ras_suspend() / amdgpu_gfx_ras_fini() and add a matching ras_suspend callback that is invoked from amdgpu_ras_suspend() before disable_all_features(). The get and put now sit in the same place and check the same condition (not VF, funcs registered), no refcount querying needed.
An active flag gates ras_fini so the suspend-then-unload-without-resume path falls into amdgpu_ras_block_late_fini_default() instead of double-releasing what ras_suspend already cleaned up.
Drop the cp_ecc_error_irq put from gfx_v9_0_hw_fini(). gfx_v8_0 manages cp_ecc_error_irq locally and is unaffected; no other GFX generation has this IRQ.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 26 ++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 32 +++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 -- 5 files changed, 53 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +22 -4
@@ -983,38 +983,50 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *rif (!amdgpu_persistent_edc_harvesting_supported (adev)) { r =amdgpu_ras_reset_error_status (adev,AMDGPU_RAS_BLOCK__GFX );if (r)return r; } r =amdgpu_ras_block_late_init (adev, ras_block);if (r)return r; -if (amdgpu_sriov_vf (adev)) -return r; - -if (adev->gfx.cp_ecc_error_irq.funcs) { +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) { r =amdgpu_irq_get (adev, &adev->gfx.cp_ecc_error_irq,0 );if (r) goto late_fini; } }else {amdgpu_ras_feature_enable_on_boot (adev, ras_block,0 ); }return 0 ; late_fini:amdgpu_ras_block_late_fini (adev, ras_block);return r; } +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +} + +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +amdgpu_ras_block_late_fini (adev, ras_block); +} +int amdgpu_gfx_ras_sw_init (struct amdgpu_device *adev) {int err =0 ;struct amdgpu_gfx_ras *ras =NULL ;/* adev->gfx.ras is NULL, which means gfx does not * support ras function, then do nothing here. */ if (!adev->gfx.ras)return 0 ;
@@ -1029,20 +1041,26 @@ int amdgpu_gfx_ras_sw_init(struct amdgpu_device *adev)strcpy (ras->ras_block.ras_comm.name,"gfx" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__GFX ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; adev->gfx.ras_if = &ras->ras_block.ras_comm;/* If not define special ras_late_init function, use gfx default ras_late_init */ if (!ras->ras_block.ras_late_init) ras->ras_block.ras_late_init = amdgpu_gfx_ras_late_init; +if (!ras->ras_block.ras_suspend) + ras->ras_block.ras_suspend = amdgpu_gfx_ras_suspend; + +if (!ras->ras_block.ras_fini) + ras->ras_block.ras_fini = amdgpu_gfx_ras_fini; +/* If not defined special ras_cb function, use default ras_cb */ if (!ras->ras_block.ras_cb) ras->ras_block.ras_cb = amdgpu_gfx_process_ras_data_cb;return 0 ; }int amdgpu_gfx_poison_consumption_handler (struct amdgpu_device *adev,struct amdgpu_iv_entry *entry) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -1
@@ -608,21 +608,22 @@ bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int xcc_id,bool amdgpu_gfx_is_high_priority_compute_queue (struct amdgpu_device *adev,struct amdgpu_ring *ring);bool amdgpu_gfx_is_high_priority_graphics_queue (struct amdgpu_device *adev,struct amdgpu_ring *ring);bool amdgpu_gfx_is_me_queue_enabled (struct amdgpu_device *adev,int me,int pipe,int queue);void amdgpu_gfx_off_ctrl (struct amdgpu_device *adev,bool enable);void amdgpu_gfx_off_ctrl_immediate (struct amdgpu_device *adev,bool enable);int amdgpu_get_gfx_off_status (struct amdgpu_device *adev,uint32_t *value);int amdgpu_gfx_ras_late_init (struct amdgpu_device *adev,struct ras_common_if *ras_block); -void amdgpu_gfx_ras_fini (struct amdgpu_device *adev); +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev,struct ras_common_if *ras_block); +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev,struct ras_common_if *ras_block);int amdgpu_get_gfx_off_entrycount (struct amdgpu_device *adev,u64 *value);int amdgpu_get_gfx_off_residency (struct amdgpu_device *adev,u32 *residency);int amdgpu_set_gfx_off_residency (struct amdgpu_device *adev,bool value);int amdgpu_gfx_process_ras_data_cb (struct amdgpu_device *adev,void *err_data,struct amdgpu_iv_entry *entry);int amdgpu_gfx_cp_ecc_error_irq (struct amdgpu_device *adev,struct amdgpu_irq_src *source,struct amdgpu_iv_entry *entry);uint32_t amdgpu_kiq_rreg (struct amdgpu_device *adev,uint32_t reg,uint32_t xcc_id);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +28 -4
@@ -88,20 +88,23 @@ const char *ras_mca_block_string[] = {"mca_mp1" ,"mca_mpio" , "mca_iohc", };struct amdgpu_ras_block_list {/* ras block link */ struct list_head node;struct amdgpu_ras_block_object *ras_obj; + +/* set by ras_late_init, cleared by ras_suspend/ras_fini */ +bool active; };const char *get_ras_block_str (struct ras_common_if *ras_block) {if (!ras_block)return "NULL" ;if (ras_block->block >=AMDGPU_RAS_BLOCK_COUNT || ras_block->block >=ARRAY_SIZE (ras_block_string))return "OUT OF RANGE" ;
@@ -4607,24 +4610,37 @@ void amdgpu_ras_resume(struct amdgpu_device *adev)/* there should be no any reference. */ WARN_ON (alive_obj (obj)); } } } }void amdgpu_ras_suspend (struct amdgpu_device *adev) {struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct amdgpu_ras_block_list *node; +struct amdgpu_ras_block_object *obj;if (!adev->ras_enabled || !con)return ; +/* run per-block ras_suspend before tearing down the RAS context */ +list_for_each_entry (node, &adev->ras_list, node) { +if (!node->active) +continue ; + + obj = node->ras_obj; +if (obj && obj->ras_suspend) + obj->ras_suspend (adev, &obj->ras_comm); + node->active = false; + } +amdgpu_ras_disable_all_features (adev,0 );/* Make sure all ras objects are disabled. */ if (AMDGPU_RAS_GET_FEATURES (con->features))amdgpu_ras_disable_all_features (adev,1 ); }int amdgpu_ras_late_init (struct amdgpu_device *adev) {struct amdgpu_ras_block_list *node, *tmp;struct amdgpu_ras_block_object *obj;
@@ -4664,22 +4680,29 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev)if (!amdgpu_ras_is_supported (adev, obj->ras_comm.block))continue ;if (obj->ras_late_init) { r = obj->ras_late_init (adev, &obj->ras_comm);if (r) {dev_err (adev->dev,"%s failed to execute ras_late_init! ret:%d\n" , obj->ras_comm.name, r);return r; } - }else -amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); + }else { + r =amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); +if (r) { +dev_err (adev->dev,"%s failed to execute ras_block_late_init_default! ret:%d\n" , + obj->ras_comm.name, r); +return r; + } + } + node->active = true; }amdgpu_ras_check_bad_page_status (adev);return 0 ; }/* do some fini work before IP fini as dependence */ int amdgpu_ras_pre_fini (struct amdgpu_device *adev) {
@@ -4704,25 +4727,26 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)if (!adev->ras_enabled || !con)return 0 ;amdgpu_ras_critical_region_fini (adev);mutex_destroy (&con->critical_region_lock);list_for_each_entry_safe (ras_node, tmp, &adev->ras_list, node) {if (ras_node->ras_obj) { obj = ras_node->ras_obj; -if (amdgpu_ras_is_supported (adev, obj->ras_comm.block) && - obj->ras_fini) +/* fall back to default cleanup if ras_suspend already ran */ +if (ras_node->active && obj->ras_fini) obj->ras_fini (adev, &obj->ras_comm);else amdgpu_ras_block_late_fini_default (adev, &obj->ras_comm); + ras_node->active = false; }/* Clear ras blocks from ras_list and free ras block list node */ list_del (&ras_node->node);kfree (ras_node); }amdgpu_ras_fs_fini (adev);amdgpu_ras_interrupt_remove_all (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -755,20 +755,21 @@ struct ras_debug_if { };int op; };struct amdgpu_ras_block_object {struct ras_common_if ras_comm;int (*ras_block_match)(struct amdgpu_ras_block_object *block_obj,enum amdgpu_ras_block block,uint32_t sub_block_index);int (*ras_late_init)(struct amdgpu_device *adev,struct ras_common_if *ras_block); +void (*ras_suspend)(struct amdgpu_device *adev,struct ras_common_if *ras_block);void (*ras_fini)(struct amdgpu_device *adev,struct ras_common_if *ras_block);ras_ih_cb ras_cb;const struct amdgpu_ras_block_hw_ops *hw_ops; };struct amdgpu_ras_block_hw_ops {int (*ras_error_inject)(struct amdgpu_device *adev,void *inject_if,uint32_t instance_mask);void (*query_ras_error_count)(struct amdgpu_device *adev,void *ras_error_status);void (*query_ras_error_status)(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -2
@@ -4050,22 +4050,20 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block) !amdgpu_sriov_vf(adev))gfx_v9_4_2_set_power_brake_sequence (adev);return r; }static int gfx_v9_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_irq_enabled (adev, &adev->gfx.cp_ecc_error_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 );if (amdgpu_irq_enabled (adev, &adev->gfx.priv_reg_irq,0 ))amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );if (amdgpu_irq_enabled (adev, &adev->gfx.priv_inst_irq,0 ))amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );if (amdgpu_irq_enabled (adev, &adev->gfx.bad_op_irq,0 ))amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );/* DF freeze and kcq disable will fail */ if (!amdgpu_ras_intr_triggered ())/* disable KCQ to avoid CPC touch memory not valid anymore */
base-commit: e08f39913bfa3e8c6a61fc30ee3870d7d156c19f
prerequisite-patch-id: 61de2a725d655efda7db2b8f3e3c2f80f22c7e3e
Signature · 1 line
2.51.2
PATCH 2/2 drm/amdgpu/gfx: move fault and EOP IRQ get/put to hw_init/hw_fini
In reply to Yunxiang Lipriv_reg / priv_inst / bad_op and (on v11+) userq EOP IRQs are acquired in late_init but released in hw_fini. This split forced gfx_v9_0_hw_fini() to defensively guard each put with amdgpu_irq_enabled() because hw_fini runs on paths that may not reach late_init.
amdgpu_ip_block_hw_fini() only runs after hw_init returns success, and suspend / resume cycle the refs through the same path, so hw_init / hw_fini pair without any extra tracking. Move the gets there and drop the guards.
While here, fix the pre-existing partial-failure leak in set_userq_eop_interrupts() (gfx11 / 12_0 / 12_1). amdgpu_irq_get() increments the refcount before calling .set, so a failure partway through the loop leaves earlier successful gets stranded. Track the loop position and roll back on the enable path.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 43 +++---- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 162 ++++++++++++++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 162 ++++++++++++++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 114 +++++++++-------- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 39 +++--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 35 ++--- 6 files changed, 315 insertions(+), 240 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +20 -23
@@ -7523,32 +7523,50 @@ static int gfx_v10_0_hw_init(struct amdgpu_ip_block *ip_block) r =gfx_v10_0_cp_resume (adev);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (10 ,3 ,0 ))gfx_v10_3_program_pbb_mode (adev);if (amdgpu_ip_version (adev,GC_HWIP ,0 ) >=IP_VERSION (10 ,3 ,0 ) && !amdgpu_sriov_vf (adev))gfx_v10_3_set_power_brake_sequence (adev); + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v10_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;cancel_delayed_work_sync (&adev->gfx.idle_work); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );/* WA added for Vangogh asic fixing the SMU suspend failure * It needs to set power gating again during gfxoff control * otherwise the gfxoff disallowing will be failed to set. */ if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (10 ,3 ,1 ))gfx_v10_0_set_powergating_state (ip_block,AMD_PG_STATE_UNGATE );if (!adev->no_hw_access) {if (amdgpu_async_gfx_ring) {
@@ -7830,40 +7848,20 @@ static int gfx_v10_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v10_0_set_gds_init (adev);gfx_v10_0_set_rlc_funcs (adev);gfx_v10_0_set_mqd_funcs (adev);/* init rlcg reg access ctrl */ gfx_v10_0_init_rlcg_reg_access_ctrl (adev);return gfx_v10_0_init_microcode (adev); } -static int gfx_v10_0_late_init (struct amdgpu_ip_block *ip_block) -{ -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - -return 0 ; -} -static bool gfx_v10_0_is_rlc_enabled (struct amdgpu_device *adev) {uint32_t rlc_cntl;/* if RLC is not enabled, do nothing */ rlc_cntl =RREG32_SOC15 (GC ,0 , mmRLC_CNTL);return (REG_GET_FIELD (rlc_cntl,RLC_CNTL ,RLC_ENABLE_F32 )) ? true : false; }static void gfx_v10_0_set_safe_mode (struct amdgpu_device *adev,int xcc_id)
@@ -9798,21 +9796,20 @@ static void gfx_v10_0_ring_begin_use(struct amdgpu_ring *ring)static void gfx_v10_0_ring_end_use (struct amdgpu_ring *ring) {amdgpu_gfx_profile_ring_end_use (ring);amdgpu_gfx_enforce_isolation_ring_end_use (ring); }static const struct amd_ip_funcs gfx_v10_0_ip_funcs = { .name ="gfx_v10_0" , .early_init = gfx_v10_0_early_init, - .late_init = gfx_v10_0_late_init, .sw_init = gfx_v10_0_sw_init, .sw_fini = gfx_v10_0_sw_fini, .hw_init = gfx_v10_0_hw_init, .hw_fini = gfx_v10_0_hw_fini, .suspend = gfx_v10_0_suspend, .resume = gfx_v10_0_resume, .is_idle = gfx_v10_0_is_idle, .wait_for_idle = gfx_v10_0_wait_for_idle, .soft_reset = gfx_v10_0_soft_reset, .set_clockgating_state = gfx_v10_0_set_clockgating_state,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +98 -70
259 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +98 -70
260 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +64 -50
220 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +21 -18
@@ -4043,33 +4043,48 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block)return r; r =gfx_v9_0_cp_resume (adev);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ) && !amdgpu_sriov_vf (adev))gfx_v9_4_2_set_power_brake_sequence (adev); + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v9_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_irq_enabled (adev, &adev->gfx.priv_reg_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -if (amdgpu_irq_enabled (adev, &adev->gfx.priv_inst_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); -if (amdgpu_irq_enabled (adev, &adev->gfx.bad_op_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );/* DF freeze and kcq disable will fail */ if (!amdgpu_ras_intr_triggered ())/* disable KCQ to avoid CPC touch memory not valid anymore */ amdgpu_gfx_disable_kcq (adev,0 );if (amdgpu_sriov_vf (adev)) {gfx_v9_0_cp_gfx_enable (adev, false);/* must disable polling for SRIOV when hw finished, otherwise * CPC engine may still keep fetching WB address which is already
@@ -4856,32 +4871,20 @@ static int gfx_v9_0_ecc_late_init(struct amdgpu_ip_block *ip_block) adev->gfx.ras->enable_watchdog_timer (adev);return 0 ; }static int gfx_v9_0_late_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int r; - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - r =gfx_v9_0_ecc_late_init (ip_block);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ))gfx_v9_4_2_debug_trap_config_init (adev, adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID );else gfx_v9_0_debug_trap_config_init (adev, adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID );
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +20 -15
@@ -2364,20 +2364,38 @@ static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block)gfx_v9_4_3_constants_init (adev); r = adev->gfx.rlc.funcs->resume (adev);if (r)return r; r =gfx_v9_4_3_cp_resume (adev);if (r)return r; + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v9_4_3_perf_monitor_ptl_init (struct amdgpu_device *adev,bool enable) {struct amdgpu_ptl *ptl = &adev->psp.ptl;uint32_t ptl_state = enable ?1 :0 ;uint32_t fmt1, fmt2;int r;
@@ -2439,23 +2457,23 @@ static int gfx_v9_4_3_ptl_hw_init(struct amdgpu_device *adev) }static int gfx_v9_4_3_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int i, num_xcc;if (adev->psp.ptl.hw_supported && !amdgpu_in_reset (adev))gfx_v9_4_3_perf_monitor_ptl_init (adev, false); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); num_xcc =NUM_XCC (adev->gfx.xcc_mask);for (i =0 ; i < num_xcc; i++) {gfx_v9_4_3_xcc_fini (adev, i); }return 0 ; }static int gfx_v9_4_3_suspend (struct amdgpu_ip_block *ip_block)
@@ -2604,33 +2622,20 @@ static int gfx_v9_4_3_early_init(struct amdgpu_ip_block *ip_block)/* init rlcg reg access ctrl */ gfx_v9_4_3_init_rlcg_reg_access_ctrl (adev);return gfx_v9_4_3_init_microcode (adev); }static int gfx_v9_4_3_late_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r;if (adev->gfx.ras && adev->gfx.ras->enable_watchdog_timer) adev->gfx.ras->enable_watchdog_timer (adev);gfx_v9_4_3_ptl_hw_init (adev);return 0 ; }
Signature · 1 line
2.51.2
Re: [PATCH 2/2] drm/amdgpu/gfx: move fault and EOP IRQ get/put to hw_init/hw_fini
Quoted 104 lines · Yunxiang Li
priv_reg/priv_inst/bad_opand (on v11+) userq EOP IRQs are acquired inlate_initbut released inhw_fini. This split forcedgfx_v9_0_hw_fini()to defensively guard each put withamdgpu_irq_enabled()becausehw_finiruns on paths that may not reachlate_init.
amdgpu_ip_block_hw_fini()only runs afterhw_initreturns success, and suspend / resume cycle the refs through the same path, sohw_init/hw_finipair without any extra tracking. Move the gets there and drop the guards.While here, fix the pre-existing partial-failure leak in
set_userq_eop_interrupts()(gfx11 / 12_0 / 12_1).amdgpu_irq_get()increments the refcount before calling .set, so a failure partway through the loop leaves earlier successful gets stranded. Track the loop position and roll back on the enable path.Signed-off-by Yunxiang Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 43 +++---- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 162 ++++++++++++++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 162 ++++++++++++++---------- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 114 +++++++++-------- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 39 +++--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 35 ++--- 6 files changed, 315 insertions(+), 240 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +20
-10@@ -7523,32 +7523,50 @@ static int gfx_v10_0_hw_init(struct amdgpu_ip_block *ip_block) r =gfx_v10_0_cp_resume (adev);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (10 ,3 ,0 ))gfx_v10_3_program_pbb_mode (adev);if (amdgpu_ip_version (adev,GC_HWIP ,0 ) >=IP_VERSION (10 ,3 ,0 ) && !amdgpu_sriov_vf (adev))gfx_v10_3_set_power_brake_sequence (adev); + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v10_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;cancel_delayed_work_sync (&adev->gfx.idle_work); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );/* WA added for Vangogh asic fixing the SMU suspend failure * It needs to set power gating again during gfxoff control * otherwise the gfxoff disallowing will be failed to set. */ if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (10 ,3 ,1 ))gfx_v10_0_set_powergating_state (ip_block,AMD_PG_STATE_UNGATE );if (!adev->no_hw_access) {if (amdgpu_async_gfx_ring) {@@ -7830,40 +7848,20 @@ static int gfx_v10_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v10_0_set_gds_init (adev);gfx_v10_0_set_rlc_funcs (adev);gfx_v10_0_set_mqd_funcs (adev);/* init rlcg reg access ctrl */ gfx_v10_0_init_rlcg_reg_access_ctrl (adev);return gfx_v10_0_init_microcode (adev); } -static int gfx_v10_0_late_init (struct amdgpu_ip_block *ip_block) -{ -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_early_init(struct amdgpu_ip_block *ip_block) · line 7857
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-10- - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - -return 0 ;
Wasn't there a reason (sequencing maybe?) these were in late_init()? Are you sure it's ok to move them into hw_init()?
Alex
Quoted 996 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-3-} -static bool gfx_v10_0_is_rlc_enabled (struct amdgpu_device *adev) {uint32_t rlc_cntl;/* if RLC is not enabled, do nothing */ rlc_cntl =RREG32_SOC15 (GC ,0 , mmRLC_CNTL);return (REG_GET_FIELD (rlc_cntl,RLC_CNTL ,RLC_ENABLE_F32 )) ? true : false; }static void gfx_v10_0_set_safe_mode (struct amdgpu_device *adev,int xcc_id)@@ -9798,21 +9796,20 @@ static void gfx_v10_0_ring_begin_use(struct amdgpu_ring *ring)static void gfx_v10_0_ring_end_use (struct amdgpu_ring *ring) {amdgpu_gfx_profile_ring_end_use (ring);amdgpu_gfx_enforce_isolation_ring_end_use (ring); }static const struct amd_ip_funcs gfx_v10_0_ip_funcs = { .name ="gfx_v10_0" , .early_init = gfx_v10_0_early_init, - .late_init = gfx_v10_0_late_init, .sw_init = gfx_v10_0_sw_init, .sw_fini = gfx_v10_0_sw_fini, .hw_init = gfx_v10_0_hw_init, .hw_fini = gfx_v10_0_hw_fini, .suspend = gfx_v10_0_suspend, .resume = gfx_v10_0_resume, .is_idle = gfx_v10_0_is_idle, .wait_for_idle = gfx_v10_0_wait_for_idle, .soft_reset = gfx_v10_0_soft_reset, .set_clockgating_state = gfx_v10_0_set_clockgating_state,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +98
-70@@ -4800,20 +4800,92 @@ static void gfx_v11_0_disable_gpa_mode(struct amdgpu_device *adev) data =RREG32_SOC15 (GC ,0 , regCPC_PSP_DEBUG); data |=CPC_PSP_DEBUG__GPA_OVERRIDE_MASK ;WREG32_SOC15 (GC ,0 , regCPC_PSP_DEBUG, data); data =RREG32_SOC15 (GC ,0 , regCPG_PSP_DEBUG); data |=CPG_PSP_DEBUG__GPA_OVERRIDE_MASK ;WREG32_SOC15 (GC ,0 , regCPG_PSP_DEBUG, data); } +static int gfx_v11_0_set_userq_eop_interrupts (struct amdgpu_device *adev, +bool enable) +{ +unsigned int irq_type; +int m, p, r; + +if (adev->userq_funcs[AMDGPU_HW_IP_GFX ]) { +for (m =0 ; m < adev->gfx.me.num_me; m++) { +for (p =0 ; p < adev->gfx.me.num_pipe_per_me; p++) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +if (enable) + r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, irq_type); +else + r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); +if (r) { +if (!enable) +return r; + goto err_gfx; + } + } + } + } + +if (adev->userq_funcs[AMDGPU_HW_IP_COMPUTE ]) { +for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { +for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + + p; +if (enable) + r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, irq_type); +else + r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); +if (r) { +if (!enable) +return r; + goto err_compute; + } + } + } + } + +return 0 ; + +err_compute: +for (p--; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } +for (m--; m >=0 ; m--) { +for (p = adev->gfx.mec.num_pipe_per_mec -1 ; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } + } + m = adev->gfx.me.num_me; +err_gfx: +for (p--; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } +for (m--; m >=0 ; m--) { +for (p = adev->gfx.me.num_pipe_per_me -1 ; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } + } +return r; +} +static int gfx_v11_0_hw_init (struct amdgpu_ip_block *ip_block) {int r;struct amdgpu_device *adev = ip_block->adev;amdgpu_gfx_cleaner_shader_init (adev, adev->gfx.cleaner_shader_size, adev->gfx.cleaner_shader_ptr);if (adev->firmware.load_type ==AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO ) {if (adev->gfx.imu.funcs) {@@ -4897,76 +4969,57 @@ static int gfx_v11_0_hw_init(struct amdgpu_ip_block *ip_block)gfx_v11_0_tcp_harvest (adev); r =gfx_v11_0_cp_resume (adev);if (r)return r;/* get IMU version from HW if it's not set */ if (!adev->gfx.imu_fw_version) adev->gfx.imu_fw_version =RREG32_SOC15 (GC ,0 , regGFX_IMU_SCRATCH_0); -return r; -} - -static int gfx_v11_0_set_userq_eop_interrupts (struct amdgpu_device *adev, -bool enable) -{ -unsigned int irq_type; -int m, p, r; - -if (adev->userq_funcs[AMDGPU_HW_IP_GFX ]) { -for (m =0 ; m < adev->gfx.me.num_me; m++) { -for (p =0 ; p < adev->gfx.me.num_pipe_per_me; p++) { - irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; -if (enable) - r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, - irq_type); -else - r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, - irq_type); -if (r) -return r; - } - } - } - -if (adev->userq_funcs[AMDGPU_HW_IP_COMPUTE ]) { -for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { -for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { - irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP - + (m * adev->gfx.mec.num_pipe_per_mec) - + p; -if (enable) - r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, - irq_type); -else - r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, - irq_type); -if (r) -return r; - } - } - } + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + + r =gfx_v11_0_set_userq_eop_interrupts (adev, true); +if (r) + goto err_userq_eop;return 0 ; + +err_userq_eop: +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); +return r; }static int gfx_v11_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;cancel_delayed_work_sync (&adev->gfx.idle_work); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );gfx_v11_0_set_userq_eop_interrupts (adev, false); +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );if (!adev->no_hw_access) {if (amdgpu_async_gfx_ring && !adev->gfx.disable_kq) {if (amdgpu_gfx_disable_kgq (adev,0 ))DRM_ERROR ("KGQ disable failed\n" ); }if (amdgpu_gfx_disable_kcq (adev,0 ))DRM_ERROR ("KCQ disable failed\n" );@@ -5342,44 +5395,20 @@ static int gfx_v11_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v11_0_set_gds_init (adev);gfx_v11_0_set_rlc_funcs (adev);gfx_v11_0_set_mqd_funcs (adev);gfx_v11_0_set_imu_funcs (adev);gfx_v11_0_init_rlcg_reg_access_ctrl (adev);return gfx_v11_0_init_microcode (adev); } -static int gfx_v11_0_late_init (struct amdgpu_ip_block *ip_block) -{ -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - - r =gfx_v11_0_set_userq_eop_interrupts (adev, true); -if (r) -return r; - -return 0 ; -} -static bool gfx_v11_0_is_rlc_enabled (struct amdgpu_device *adev) {uint32_t rlc_cntl;/* if RLC is not enabled, do nothing */ rlc_cntl =RREG32_SOC15 (GC ,0 , regRLC_CNTL);return (REG_GET_FIELD (rlc_cntl,RLC_CNTL ,RLC_ENABLE_F32 )) ? true : false; }static void gfx_v11_0_set_safe_mode (struct amdgpu_device *adev,int xcc_id)@@ -7194,21 +7223,20 @@ static void gfx_v11_0_ring_begin_use(struct amdgpu_ring *ring)static void gfx_v11_0_ring_end_use (struct amdgpu_ring *ring) {amdgpu_gfx_profile_ring_end_use (ring);amdgpu_gfx_enforce_isolation_ring_end_use (ring); }static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .name ="gfx_v11_0" , .early_init = gfx_v11_0_early_init, - .late_init = gfx_v11_0_late_init, .sw_init = gfx_v11_0_sw_init, .sw_fini = gfx_v11_0_sw_fini, .hw_init = gfx_v11_0_hw_init, .hw_fini = gfx_v11_0_hw_fini, .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .is_idle = gfx_v11_0_is_idle, .wait_for_idle = gfx_v11_0_wait_for_idle, .soft_reset = gfx_v11_0_soft_reset, .check_soft_reset = gfx_v11_0_check_soft_reset,drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +98
-70@@ -3648,20 +3648,92 @@ static void gfx_v12_0_init_golden_registers(struct amdgpu_device *adev)if (adev->rev_id ==0 )soc15_program_register_sequence (adev, golden_settings_gc_12_0_rev0, (const u32 )ARRAY_SIZE (golden_settings_gc_12_0_rev0));break ;default :break ; } } +static int gfx_v12_0_set_userq_eop_interrupts (struct amdgpu_device *adev, +bool enable) +{ +unsigned int irq_type; +int m, p, r; + +if (adev->userq_funcs[AMDGPU_HW_IP_GFX ]) { +for (m =0 ; m < adev->gfx.me.num_me; m++) { +for (p =0 ; p < adev->gfx.me.num_pipe_per_me; p++) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +if (enable) + r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, irq_type); +else + r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); +if (r) { +if (!enable) +return r; + goto err_gfx; + } + } + } + } + +if (adev->userq_funcs[AMDGPU_HW_IP_COMPUTE ]) { +for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { +for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + + p; +if (enable) + r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, irq_type); +else + r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); +if (r) { +if (!enable) +return r; + goto err_compute; + } + } + } + } + +return 0 ; + +err_compute: +for (p--; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } +for (m--; m >=0 ; m--) { +for (p = adev->gfx.mec.num_pipe_per_mec -1 ; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } + } + m = adev->gfx.me.num_me; +err_gfx: +for (p--; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } +for (m--; m >=0 ; m--) { +for (p = adev->gfx.me.num_pipe_per_me -1 ; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } + } +return r; +} +static int gfx_v12_0_hw_init (struct amdgpu_ip_block *ip_block) {int r;struct amdgpu_device *adev = ip_block->adev;if (adev->firmware.load_type ==AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO ) {if (adev->gfx.imu.funcs && (amdgpu_dpm >0 )) {/* RLC autoload sequence 1: Program rlc ram */ if (adev->gfx.imu.funcs->program_rlc_ram) adev->gfx.imu.funcs->program_rlc_ram (adev);@@ -3735,77 +3807,58 @@ static int gfx_v12_0_hw_init(struct amdgpu_ip_block *ip_block)/* * init golden registers and rlc resume may override some registers, * reconfig them here */ gfx_v12_0_tcp_harvest (adev); r =gfx_v12_0_cp_resume (adev);if (r)return r; -return r; -} - -static int gfx_v12_0_set_userq_eop_interrupts (struct amdgpu_device *adev, -bool enable) -{ -unsigned int irq_type; -int m, p, r; - -if (adev->userq_funcs[AMDGPU_HW_IP_GFX ]) { -for (m =0 ; m < adev->gfx.me.num_me; m++) { -for (p =0 ; p < adev->gfx.me.num_pipe_per_me; p++) { - irq_type =AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + p; -if (enable) - r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, - irq_type); -else - r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, - irq_type); -if (r) -return r; - } - } - } - -if (adev->userq_funcs[AMDGPU_HW_IP_COMPUTE ]) { -for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { -for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { - irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP - + (m * adev->gfx.mec.num_pipe_per_mec) - + p; -if (enable) - r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, - irq_type); -else - r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, - irq_type); -if (r) -return r; - } - } - } + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + + r =gfx_v12_0_set_userq_eop_interrupts (adev, true); +if (r) + goto err_userq_eop;return 0 ; + +err_userq_eop: +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); +return r; }static int gfx_v12_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;uint32_t tmp;cancel_delayed_work_sync (&adev->gfx.idle_work); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );gfx_v12_0_set_userq_eop_interrupts (adev, false); +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );if (!adev->no_hw_access) {if (amdgpu_async_gfx_ring) {if (amdgpu_gfx_disable_kgq (adev,0 ))DRM_ERROR ("KGQ disable failed\n" ); }if (amdgpu_gfx_disable_kcq (adev,0 ))DRM_ERROR ("KCQ disable failed\n" );@@ -3920,44 +3973,20 @@ static int gfx_v12_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v12_0_set_irq_funcs (adev);gfx_v12_0_set_rlc_funcs (adev);gfx_v12_0_set_mqd_funcs (adev);gfx_v12_0_set_imu_funcs (adev);gfx_v12_0_init_rlcg_reg_access_ctrl (adev);return gfx_v12_0_init_microcode (adev); } -static int gfx_v12_0_late_init (struct amdgpu_ip_block *ip_block) -{ -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - - r =gfx_v12_0_set_userq_eop_interrupts (adev, true); -if (r) -return r; - -return 0 ; -} -static bool gfx_v12_0_is_rlc_enabled (struct amdgpu_device *adev) {uint32_t rlc_cntl;/* if RLC is not enabled, do nothing */ rlc_cntl =RREG32_SOC15 (GC ,0 , regRLC_CNTL);return (REG_GET_FIELD (rlc_cntl,RLC_CNTL ,RLC_ENABLE_F32 )) ? true : false; } static void gfx_v12_0_set_safe_mode(struct amdgpu_device *adev,@@ -5433,21 +5462,20 @@ static void gfx_v12_0_ring_begin_use(struct amdgpu_ring *ring)static void gfx_v12_0_ring_end_use (struct amdgpu_ring *ring) {amdgpu_gfx_profile_ring_end_use (ring);amdgpu_gfx_enforce_isolation_ring_end_use (ring); }static const struct amd_ip_funcs gfx_v12_0_ip_funcs = { .name ="gfx_v12_0" , .early_init = gfx_v12_0_early_init, - .late_init = gfx_v12_0_late_init, .sw_init = gfx_v12_0_sw_init, .sw_fini = gfx_v12_0_sw_fini, .hw_init = gfx_v12_0_hw_init, .hw_fini = gfx_v12_0_hw_fini, .suspend = gfx_v12_0_suspend, .resume = gfx_v12_0_resume, .is_idle = gfx_v12_0_is_idle, .wait_for_idle = gfx_v12_0_wait_for_idle, .set_clockgating_state = gfx_v12_0_set_clockgating_state, .set_powergating_state = gfx_v12_0_set_powergating_state,drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +64
-50@@ -2728,20 +2728,64 @@ static void gfx_v12_1_init_golden_registers(struct amdgpu_device *adev)int i;for (i =0 ; i <NUM_XCC (adev->gfx.xcc_mask); i++) {gfx_v12_1_xcc_disable_burst (adev, i);gfx_v12_1_xcc_enable_atomics (adev, i);gfx_v12_1_xcc_disable_early_write_ack (adev, i);gfx_v12_1_xcc_disable_tcp_spill_cache (adev, i); } } +static int gfx_v12_1_set_userq_eop_interrupts (struct amdgpu_device *adev, +bool enable) +{ +unsigned int irq_type; +int m, p, r; + +if (!adev->gfx.disable_kq) +return 0 ; + +for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { +for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + + p; +if (enable) + r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, irq_type); +else + r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); +if (r) { +if (!enable) +return r; + goto err_unwind; + } + } + } + +return 0 ; + +err_unwind: +for (p--; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } +for (m--; m >=0 ; m--) { +for (p = adev->gfx.mec.num_pipe_per_mec -1 ; p >=0 ; p--) { + irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP + + (m * adev->gfx.mec.num_pipe_per_mec) + p; +amdgpu_irq_put (adev, &adev->gfx.eop_irq, irq_type); + } + } +return r; +} +static int gfx_v12_1_hw_init (struct amdgpu_ip_block *ip_block) {int r, i, num_xcc;struct amdgpu_device *adev = ip_block->adev;if (adev->firmware.load_type ==AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO ) {/* rlc autoload firmware */ r =gfx_v12_1_rlc_backdoor_autoload_enable (adev);if (r)return r;@@ -2796,20 +2840,38 @@ static int gfx_v12_1_hw_init(struct amdgpu_ip_block *ip_block)/* * init golden registers and rlc resume may override some registers, * reconfig them here */ gfx_v12_1_tcp_harvest (adev); r =gfx_v12_1_cp_resume (adev);if (r)return r; + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =gfx_v12_1_set_userq_eop_interrupts (adev, true); +if (r) + goto err_userq_eop; + +return 0 ; + +err_userq_eop: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static void gfx_v12_1_xcc_fini (struct amdgpu_device *adev,int xcc_id) {uint32_t tmp;if (!adev->no_hw_access) {if (amdgpu_gfx_disable_kcq (adev, xcc_id))@@ -2821,55 +2883,28 @@ static void gfx_v12_1_xcc_fini(struct amdgpu_device *adev,if (amdgpu_sriov_vf (adev)) {/* Program KIQ position of RLC_CP_SCHEDULERS during destroy */ tmp =RREG32_SOC15 (GC ,GET_INST (GC , xcc_id), regRLC_CP_SCHEDULERS); tmp &=0xffffff00 ;WREG32_SOC15 (GC ,GET_INST (GC , xcc_id), regRLC_CP_SCHEDULERS, tmp); }gfx_v12_1_xcc_cp_compute_enable (adev, false, xcc_id);gfx_v12_1_xcc_enable_gui_idle_interrupt (adev, false, xcc_id); } -static int gfx_v12_1_set_userq_eop_interrupts (struct amdgpu_device *adev, -bool enable) -{ -unsigned int irq_type; -int m, p, r; - -if (adev->gfx.disable_kq) { -for (m =0 ; m < adev->gfx.mec.num_mec; ++m) { -for (p =0 ; p < adev->gfx.mec.num_pipe_per_mec; p++) { - irq_type =AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP - + (m * adev->gfx.mec.num_pipe_per_mec) - + p; -if (enable) - r =amdgpu_irq_get (adev, &adev->gfx.eop_irq, - irq_type); -else - r =amdgpu_irq_put (adev, &adev->gfx.eop_irq, - irq_type); -if (r) -return r; - } - } - } - -return 0 ; -} -static int gfx_v12_1_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );gfx_v12_1_set_userq_eop_interrupts (adev, false); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); num_xcc =NUM_XCC (adev->gfx.xcc_mask);for (i =0 ; i < num_xcc; i++) {gfx_v12_1_xcc_fini (adev, i); } adev->gfxhub.funcs->gart_disable (adev); adev->gfx.is_poweron = false;@@ -2956,40 +2991,20 @@ static int gfx_v12_1_early_init(struct amdgpu_ip_block *ip_block)gfx_v12_1_set_irq_funcs (adev);gfx_v12_1_set_rlc_funcs (adev);gfx_v12_1_set_mqd_funcs (adev);gfx_v12_1_set_imu_funcs (adev);gfx_v12_1_init_rlcg_reg_access_ctrl (adev);return gfx_v12_1_init_microcode (adev); } -static int gfx_v12_1_late_init (struct amdgpu_ip_block *ip_block) -{ -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =gfx_v12_1_set_userq_eop_interrupts (adev, true); -if (r) -return r; - -return 0 ; -} -static bool gfx_v12_1_is_rlc_enabled (struct amdgpu_device *adev) {uint32_t rlc_cntl;/* if RLC is not enabled, do nothing */ rlc_cntl =RREG32_SOC15 (GC ,GET_INST (GC ,0 ), regRLC_CNTL);return (REG_GET_FIELD (rlc_cntl,RLC_CNTL ,RLC_ENABLE_F32 )) ? true : false; } static void gfx_v12_1_xcc_set_safe_mode(struct amdgpu_device *adev,@@ -3869,21 +3884,20 @@ static void gfx_v12_1_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring,0xffffff );/* CP_COHER_SIZE_HI */ amdgpu_ring_write (ring,0 );/* CP_COHER_BASE */ amdgpu_ring_write (ring,0 );/* CP_COHER_BASE_HI */ amdgpu_ring_write (ring,0x0000000A );/* POLL_INTERVAL */ amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ }static const struct amd_ip_funcs gfx_v12_1_ip_funcs = { .name ="gfx_v12_1" , .early_init = gfx_v12_1_early_init, - .late_init = gfx_v12_1_late_init, .sw_init = gfx_v12_1_sw_init, .sw_fini = gfx_v12_1_sw_fini, .hw_init = gfx_v12_1_hw_init, .hw_fini = gfx_v12_1_hw_fini, .suspend = gfx_v12_1_suspend, .resume = gfx_v12_1_resume, .is_idle = gfx_v12_1_is_idle, .wait_for_idle = gfx_v12_1_wait_for_idle, .set_clockgating_state = gfx_v12_1_set_clockgating_state, .set_powergating_state = gfx_v12_1_set_powergating_state,drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +21
-18@@ -4043,33 +4043,48 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block)return r; r =gfx_v9_0_cp_resume (adev);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ) && !amdgpu_sriov_vf (adev))gfx_v9_4_2_set_power_brake_sequence (adev); + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v9_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_irq_enabled (adev, &adev->gfx.priv_reg_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -if (amdgpu_irq_enabled (adev, &adev->gfx.priv_inst_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); -if (amdgpu_irq_enabled (adev, &adev->gfx.bad_op_irq,0 )) -amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );/* DF freeze and kcq disable will fail */ if (!amdgpu_ras_intr_triggered ())/* disable KCQ to avoid CPC touch memory not valid anymore */ amdgpu_gfx_disable_kcq (adev,0 );if (amdgpu_sriov_vf (adev)) {gfx_v9_0_cp_gfx_enable (adev, false);/* must disable polling for SRIOV when hw finished, otherwise * CPC engine may still keep fetching WB address which is already @@ -4856,32 +4871,20 @@ static int gfx_v9_0_ecc_late_init(struct amdgpu_ip_block *ip_block) adev->gfx.ras->enable_watchdog_timer (adev);return 0 ; }static int gfx_v9_0_late_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int r; - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r; - r =gfx_v9_0_ecc_late_init (ip_block);if (r)return r;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ))gfx_v9_4_2_debug_trap_config_init (adev, adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID );else gfx_v9_0_debug_trap_config_init (adev, adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID );drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +20
-16@@ -2364,20 +2364,38 @@ static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block)gfx_v9_4_3_constants_init (adev); r = adev->gfx.rlc.funcs->resume (adev);if (r)return r; r =gfx_v9_4_3_cp_resume (adev);if (r)return r; + r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); +if (r) +return r; + + r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); +if (r) + goto err_priv_inst; + + r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); +if (r) + goto err_bad_op; + +return 0 ; + +err_bad_op: +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +err_priv_inst: +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );return r; }static int gfx_v9_4_3_perf_monitor_ptl_init (struct amdgpu_device *adev,bool enable) {struct amdgpu_ptl *ptl = &adev->psp.ptl;uint32_t ptl_state = enable ?1 :0 ;uint32_t fmt1, fmt2;int r;@@ -2439,23 +2457,23 @@ static int gfx_v9_4_3_ptl_hw_init(struct amdgpu_device *adev) }static int gfx_v9_4_3_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int i, num_xcc;if (adev->psp.ptl.hw_supported && !amdgpu_in_reset (adev))gfx_v9_4_3_perf_monitor_ptl_init (adev, false); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); -amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 ); num_xcc =NUM_XCC (adev->gfx.xcc_mask);for (i =0 ; i < num_xcc; i++) {gfx_v9_4_3_xcc_fini (adev, i); }return 0 ; }static int gfx_v9_4_3_suspend (struct amdgpu_ip_block *ip_block)@@ -2604,33 +2622,20 @@ static int gfx_v9_4_3_early_init(struct amdgpu_ip_block *ip_block)/* init rlcg reg access ctrl */ gfx_v9_4_3_init_rlcg_reg_access_ctrl (adev);return gfx_v9_4_3_init_microcode (adev); }static int gfx_v9_4_3_late_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -int r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_reg_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.priv_inst_irq,0 ); -if (r) -return r; - - r =amdgpu_irq_get (adev, &adev->gfx.bad_op_irq,0 ); -if (r) -return r;if (adev->gfx.ras && adev->gfx.ras->enable_watchdog_timer) adev->gfx.ras->enable_watchdog_timer (adev);gfx_v9_4_3_ptl_hw_init (adev);return 0 ; } --2.51.2
RE: [PATCH 2/2] drm/amdgpu/gfx: move fault and EOP IRQ get/put to hw_init/hw_fini
AMD General
Quoted 4 lines
From: Alex Deucher <[email protected]>
Wasn't there a reason (sequencing maybe?) these were in
late_init()? Are you sure it's ok to move them intohw_init()?
Not as far as I could tell, from the code all the dependencies are satisfied in hw_init by the IP block order, it was just put in late_init since the beginning of time. I did test this change on gfx9 as well.
The same pattern of late_init get hw_fini put seems to be used for other IPs as well though, so it could be that some hardware related reason exists at some point.
Teddy
Alex Deucher
Acked-byRe: [PATCH 2/2] drm/amdgpu/gfx: move fault and EOP IRQ get/put to hw_init/hw_fini
Quoted 11 lines · Yunxiang (Teddy)
AMD General
Quoted 4 lines
From: Alex Deucher <[email protected]>
Wasn't there a reason (sequencing maybe?) these were in
late_init()? Are you sure it's ok to move them intohw_init()?Not as far as I could tell, from the code all the dependencies are satisfied in
hw_initby the IP block order, it was just put inlate_initsince the beginning of time. I did test this change on gfx9 as well.The same pattern of
late_initgethw_finiput seems to be used for other IPs as well though, so it could be that some hardware related reason exists at some point.
Patches are:
Quoted 2 lines
Teddy