[AMD Official Use Only - General] > -----Original Message----- > From: Zhang, Yifan <Yifan1.Zhang@xxxxxxx> > Sent: Thursday, August 31, 2023 2:10 PM > To: amd-gfx@xxxxxxxxxxxxxxxxxxxxx > Cc: Quan, Evan <Evan.Quan@xxxxxxx>; Ma, Li <Li.Ma@xxxxxxx>; Zhang, > Yifan <Yifan1.Zhang@xxxxxxx> > Subject: [PATCH] drm/amd/pm: only poweron/off vcn/jpeg when they are > valid. > > If vcn is disabled in kernel parameters, don't touch vcn, > otherwise it may cause vcn hang. > > Signed-off-by: Yifan Zhang <yifan1.zhang@xxxxxxx> > --- > drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 31 > ++++++++++++++++++++--- > 1 file changed, 27 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c > b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c > index f005a90c35af..f5e7ce011cab 100644 > --- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c > +++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c > @@ -1454,6 +1454,21 @@ static int smu_start_smc_engine(struct > smu_context *smu) > return ret; > } > > +static bool is_vcn_enabled(struct amdgpu_device *adev) > +{ > + int i; > + > + for (i = 0; i < adev->num_ip_blocks; i++) { > + if ((adev->ip_blocks[i].version->type == > AMD_IP_BLOCK_TYPE_VCN || > + adev->ip_blocks[i].version->type == > AMD_IP_BLOCK_TYPE_JPEG) && > + !adev->ip_blocks[i].status.valid) > + > + return false; > + } > + > + return true; > +} > + > static int smu_hw_init(void *handle) > { > int ret; > @@ -1475,8 +1490,14 @@ static int smu_hw_init(void *handle) > ret = smu_set_gfx_imu_enable(smu); > if (ret) > return ret; > - smu_dpm_set_vcn_enable(smu, true); > - smu_dpm_set_jpeg_enable(smu, true); > + /* > + * don't poweron vcn/jpeg when they are skipped. > + */ > + if (is_vcn_enabled(adev)) { > + dev_info(adev->dev, "yep, vcn are valid\n"); > + smu_dpm_set_vcn_enable(smu, true); > + smu_dpm_set_jpeg_enable(smu, true); > + } Better to move the "is_vcn_enabled" check into `smu_dpm_set_vcn/jpeg_enable`. That will make code more tidy. Also, the "dev_info" here is obviously not needed. Evan > smu_set_gfx_cgpg(smu, true); > } > > @@ -1651,8 +1672,10 @@ static int smu_hw_fini(void *handle) > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev)) > return 0; > > - smu_dpm_set_vcn_enable(smu, false); > - smu_dpm_set_jpeg_enable(smu, false); > + if (is_vcn_enabled(adev)) { > + smu_dpm_set_vcn_enable(smu, false); > + smu_dpm_set_jpeg_enable(smu, false); > + } > > adev->vcn.cur_state = AMD_PG_STATE_GATE; > adev->jpeg.cur_state = AMD_PG_STATE_GATE; > -- > 2.37.3